[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v5 08/45] x86/mm: have init_xen_l4_slots() take a vCPU in place of the domain



A later change gives the vCPUs of some domains per-domain areas of their
own, and slot 260 of a table private to one vCPU must then hold that
vCPU's L3.  init_xen_l4_slots(), which fills slot 260, needs the vCPU
for that.

Have it take a vCPU in place of the domain.  A table private to one vCPU
passes that vCPU; tables that the domain's vCPUs share -- promoted PV
guest L4s, PV shadow L4s, and the PV dom0 L4 under construction -- pass
any of them.  promote_l4_table() passes vCPU 0, so it now also refuses
an L4 while the domain has no vCPU 0, as it already does while the
domain has no per-domain L3; its call is reflowed.

Otherwise no functional change: slot 260 still gets the domain's
per-domain L3.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: George Dunlap <gwd@xxxxxxxxxxxxxx>
---
Changes in v5:
- promote_l4_table() checks for vCPU 0 itself, now that "x86/mm: refuse
  to promote an L4 while the domain has no per-domain L3" tests for the
  L3 instead.

Changes in v4:
- New in this version, split out of "x86/hvm: introduce per-vCPU L3
  page-table": init_xen_l4_slots() takes a vCPU in place of the domain
  (Roger, Jan).
- Reflow promote_l4_table()'s call to init_xen_l4_slots() (Jan).
---
 xen/arch/x86/include/asm/mm.h  |  2 +-
 xen/arch/x86/mm.c              | 21 ++++++++++++++-------
 xen/arch/x86/mm/hap/hap.c      |  2 +-
 xen/arch/x86/mm/shadow/hvm.c   |  2 +-
 xen/arch/x86/mm/shadow/multi.c |  2 +-
 xen/arch/x86/pv/dom0_build.c   |  2 +-
 xen/arch/x86/pv/domain.c       |  2 +-
 7 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/include/asm/mm.h b/xen/arch/x86/include/asm/mm.h
index c9085214fd..de45a111f3 100644
--- a/xen/arch/x86/include/asm/mm.h
+++ b/xen/arch/x86/include/asm/mm.h
@@ -370,7 +370,7 @@ int devalidate_page(struct page_info *page, unsigned long 
type,
 
 void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d);
 void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,
-                       const struct domain *d, mfn_t sl4mfn, bool ro_mpt);
+                       const struct vcpu *v, mfn_t sl4mfn, bool ro_mpt);
 bool fill_ro_mpt(mfn_t mfn);
 void zap_ro_mpt(mfn_t mfn);
 
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 8153683a0c..f2122a68ce 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -1687,14 +1687,18 @@ static int promote_l3_table(struct page_info *page)
  * This function must write all ROOT_PAGETABLE_PV_XEN_SLOTS, to clobber any
  * values a guest may have left there from promote_l4_table().
  *
- * l4t, l4mfn, and d are mandatory, but l4mfn doesn't need to be the mfn under
+ * l4t, l4mfn, and v are mandatory, but l4mfn doesn't need to be the mfn under
  * *l4t.  All other parameters are optional and will either fill or zero the
  * appropriate slots.  Pagetables not shared with guests will gain the
  * extended directmap.
+ *
+ * v is the vCPU the table is private to or, for a table the domain's vCPUs
+ * share, any of them.
  */
 void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn,
-                       const struct domain *d, mfn_t sl4mfn, bool ro_mpt)
+                       const struct vcpu *v, mfn_t sl4mfn, bool ro_mpt)
 {
+    const struct domain *d = v->domain;
     /*
      * PV vcpus need a shortened directmap.  HVM and Idle vcpus get the full
      * directmap.
@@ -1798,6 +1802,8 @@ void zap_ro_mpt(mfn_t mfn)
 static int promote_l4_table(struct page_info *page)
 {
     struct domain *d = page_get_owner(page);
+    /* Any vCPU will do: a PV domain's vCPUs all use the domain-wide L3. */
+    const struct vcpu *v = domain_vcpu(d, 0);
     mfn_t          l4mfn = page_to_mfn(page);
     l4_pgentry_t  *pl4e;
     unsigned int   i;
@@ -1805,10 +1811,11 @@ static int promote_l4_table(struct page_info *page)
     unsigned int   partial_flags = page->partial_flags;
 
     /*
-     * init_xen_l4_slots() puts the domain's per-domain L3 in slot 260, and a
-     * PV domain may get that only with its first vCPU.
+     * init_xen_l4_slots() needs a vCPU, and puts the domain's per-domain L3
+     * in slot 260.  A PV domain has no vCPUs before XEN_DOMCTL_max_vcpus,
+     * and may get the L3 only with its first vCPU.
      */
-    if ( !d->arch.perdomain_l3_pg )
+    if ( !v || !d->arch.perdomain_l3_pg )
         return -EINVAL;
 
     pl4e = map_domain_page(l4mfn);
@@ -1887,8 +1894,8 @@ static int promote_l4_table(struct page_info *page)
 
     if ( !rc )
     {
-        init_xen_l4_slots(pl4e, l4mfn,
-                          d, INVALID_MFN, VM_ASSIST(d, m2p_strict));
+        init_xen_l4_slots(pl4e, l4mfn, v, INVALID_MFN,
+                          VM_ASSIST(d, m2p_strict));
         atomic_inc(&d->arch.pv.nr_l4_pages);
     }
     unmap_domain_page(pl4e);
diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c
index 0ede4181a0..aba4f77df9 100644
--- a/xen/arch/x86/mm/hap/hap.c
+++ b/xen/arch/x86/mm/hap/hap.c
@@ -407,7 +407,7 @@ static mfn_t hap_make_monitor_table(struct vcpu *v)
     m4mfn = page_to_mfn(pg);
     l4e = map_domain_page(m4mfn);
 
-    init_xen_l4_slots(l4e, m4mfn, d, INVALID_MFN, false);
+    init_xen_l4_slots(l4e, m4mfn, v, INVALID_MFN, false);
     unmap_domain_page(l4e);
 
     return m4mfn;
diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c
index e6fb97c4b6..0b23326214 100644
--- a/xen/arch/x86/mm/shadow/hvm.c
+++ b/xen/arch/x86/mm/shadow/hvm.c
@@ -760,7 +760,7 @@ mfn_t sh_make_monitor_table(const struct vcpu *v, unsigned 
int shadow_levels)
      * shadow-linear mapping will either be inserted below when creating
      * lower level monitor tables, or later in sh_update_cr3().
      */
-    init_xen_l4_slots(l4e, m4mfn, d, INVALID_MFN, false);
+    init_xen_l4_slots(l4e, m4mfn, v, INVALID_MFN, false);
 
     if ( shadow_levels < 4 )
     {
diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c
index 7f72b4b7b2..ebbf4a12ce 100644
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -974,7 +974,7 @@ sh_make_shadow(struct vcpu *v, mfn_t gmfn, u32 shadow_type)
 
             BUILD_BUG_ON(sizeof(l4_pgentry_t) != sizeof(shadow_l4e_t));
 
-            init_xen_l4_slots(l4t, gmfn, d, smfn, (!is_pv_32bit_domain(d) &&
+            init_xen_l4_slots(l4t, gmfn, v, smfn, (!is_pv_32bit_domain(d) &&
                                                    VM_ASSIST(d, m2p_strict)));
             unmap_domain_page(l4t);
         }
diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c
index 24f2fa0b7f..dcb1d407ec 100644
--- a/xen/arch/x86/pv/dom0_build.c
+++ b/xen/arch/x86/pv/dom0_build.c
@@ -725,7 +725,7 @@ static int __init dom0_construct(const struct boot_domain 
*bd)
         l4start = l4tab = __va(mpt_alloc); mpt_alloc += PAGE_SIZE;
         clear_page(l4tab);
         init_xen_l4_slots(l4tab, _mfn(virt_to_mfn(l4start)),
-                          d, INVALID_MFN, true);
+                          v, INVALID_MFN, true);
         v->arch.guest_table = pagetable_from_paddr(__pa(l4start));
     }
     else
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index f3c711b85b..f139d8f83c 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -127,7 +127,7 @@ static int setup_compat_l4(struct vcpu *v)
     mfn = page_to_mfn(pg);
     l4tab = map_domain_page(mfn);
     clear_page(l4tab);
-    init_xen_l4_slots(l4tab, mfn, v->domain, INVALID_MFN, false);
+    init_xen_l4_slots(l4tab, mfn, v, INVALID_MFN, false);
     unmap_domain_page(l4tab);
 
     /* This page needs to look like a pagetable so that it can be shadowed */
-- 
2.56.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.