xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>,
	George Dunlap <george.dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Tim Deegan <tim@xen.org>, Julien Grall <julien.grall@arm.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 2/3] x86/mm: Consolidate all Xen L2 slot writing into init_xen_pae_l2_slots()
Date: Thu, 12 Oct 2017 14:54:21 +0100	[thread overview]
Message-ID: <1507816462-15881-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1507816462-15881-1-git-send-email-andrew.cooper3@citrix.com>

Having all of this logic together makes it easier to follow Xen's virtual
setup across the whole system.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: George Dunlap <george.dunlap@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Julien Grall <julien.grall@arm.com>
---
 xen/arch/x86/mm.c              | 16 +++++++++-------
 xen/arch/x86/mm/shadow/multi.c | 42 +++++++++++++++---------------------------
 xen/include/asm-x86/mm.h       |  1 +
 3 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index f90a42a..ea4af16 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -1433,13 +1433,7 @@ static int alloc_l2_table(struct page_info *page, unsigned long type,
     }
 
     if ( rc >= 0 && (type & PGT_pae_xen_l2) )
-    {
-        /* Xen private mappings. */
-        memcpy(&pl2e[COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(d)],
-               &compat_idle_pg_table_l2[
-                   l2_table_offset(HIRO_COMPAT_MPT_VIRT_START)],
-               COMPAT_L2_PAGETABLE_XEN_SLOTS(d) * sizeof(*pl2e));
-    }
+        init_xen_pae_l2_slots(pl2e, d);
 
     unmap_domain_page(pl2e);
     return rc > 0 ? 0 : rc;
@@ -1518,6 +1512,14 @@ static int alloc_l3_table(struct page_info *page)
     return rc > 0 ? 0 : rc;
 }
 
+void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d)
+{
+    memcpy(&l2t[COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(d)],
+           &compat_idle_pg_table_l2[
+               l2_table_offset(HIRO_COMPAT_MPT_VIRT_START)],
+           COMPAT_L2_PAGETABLE_XEN_SLOTS(d) * sizeof(*l2t));
+}
+
 /*
  * This function must write all ROOT_PAGETABLE_PV_XEN_SLOTS, to clobber any
  * values a guest may have left there from alloc_l4_table().
diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c
index d540af1..1b76e0c 100644
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -1521,31 +1521,6 @@ void sh_install_xen_entries_in_l4(struct domain *d, mfn_t gl4mfn, mfn_t sl4mfn)
 }
 #endif
 
-#if GUEST_PAGING_LEVELS >= 3
-// For 3-on-3 PV guests, we need to make sure the xen mappings are in
-// place, which means that we need to populate the l2h entry in the l3
-// table.
-
-static void sh_install_xen_entries_in_l2h(struct domain *d, mfn_t sl2hmfn)
-{
-    shadow_l2e_t *sl2e;
-
-    if ( !is_pv_32bit_domain(d) )
-        return;
-
-    sl2e = map_domain_page(sl2hmfn);
-    BUILD_BUG_ON(sizeof (l2_pgentry_t) != sizeof (shadow_l2e_t));
-
-    /* Copy the common Xen mappings from the idle domain */
-    memcpy(
-        &sl2e[COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(d)],
-        &compat_idle_pg_table_l2[l2_table_offset(HIRO_COMPAT_MPT_VIRT_START)],
-        COMPAT_L2_PAGETABLE_XEN_SLOTS(d) * sizeof(*sl2e));
-
-    unmap_domain_page(sl2e);
-}
-#endif
-
 
 /**************************************************************************/
 /* Create a shadow of a given guest page.
@@ -1610,7 +1585,14 @@ sh_make_shadow(struct vcpu *v, mfn_t gmfn, u32 shadow_type)
 #endif
 #if GUEST_PAGING_LEVELS >= 3
         case SH_type_l2h_shadow:
-            sh_install_xen_entries_in_l2h(v->domain, smfn);
+            BUILD_BUG_ON(sizeof(l2_pgentry_t) != sizeof(shadow_l2e_t));
+            if ( is_pv_32bit_domain(d) )
+            {
+                shadow_l2e_t *l2t = map_domain_page(smfn);
+
+                init_xen_pae_l2_slots(l2t, d);
+                unmap_domain_page(l2t);
+            }
             break;
 #endif
         default: /* Do nothing */ break;
@@ -1677,6 +1659,8 @@ sh_make_monitor_table(struct vcpu *v)
 
             if ( is_pv_32bit_domain(d) )
             {
+                l2_pgentry_t *l2t;
+
                 /* For 32-bit PV guests, we need to map the 32-bit Xen
                  * area into its usual VAs in the monitor tables */
                 m3mfn = shadow_alloc(d, SH_type_monitor_table, 0);
@@ -1687,7 +1671,11 @@ sh_make_monitor_table(struct vcpu *v)
                 mfn_to_page(m2mfn)->shadow_flags = 2;
                 l3e = map_domain_page(m3mfn);
                 l3e[3] = l3e_from_mfn(m2mfn, _PAGE_PRESENT);
-                sh_install_xen_entries_in_l2h(d, m2mfn);
+
+                l2t = map_domain_page(m2mfn);
+                init_xen_pae_l2_slots(l2t, d);
+                unmap_domain_page(l2t);
+
                 unmap_domain_page(l3e);
             }
 
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index eeac4d7..da3c5e2 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -340,6 +340,7 @@ static inline void *__page_to_virt(const struct page_info *pg)
 int free_page_type(struct page_info *page, unsigned long type,
                    int preemptible);
 
+void init_xen_pae_l2_slots(l2_pgentry_t *l2t, const struct domain *d);
 void init_guest_l4_table(l4_pgentry_t[], const struct domain *,
                          bool_t zap_ro_mpt);
 bool fill_ro_mpt(mfn_t mfn);
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-10-12 13:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12 13:54 [PATCH for 4.10 0/3] XSA-243 followup Andrew Cooper
2017-10-12 13:54 ` [PATCH 1/3] Revert "x86/mm: move PV l4 table setup code" and "x86/mm: factor out pv_arch_init_memory" Andrew Cooper
2017-10-12 14:46   ` Wei Liu
2017-10-12 14:55   ` Jan Beulich
2017-10-12 13:54 ` Andrew Cooper [this message]
2017-10-12 14:57   ` [PATCH 2/3] x86/mm: Consolidate all Xen L2 slot writing into init_xen_pae_l2_slots() Jan Beulich
2017-10-12 14:59   ` Wei Liu
2017-10-18 11:38   ` George Dunlap
2017-10-12 13:54 ` [PATCH 3/3] x86/mm: Consolidate all Xen L4 slot writing into init_xen_l4_slots() Andrew Cooper
2017-10-12 15:08   ` Jan Beulich
2017-10-12 15:24     ` Andrew Cooper
2017-10-12 15:41       ` Jan Beulich
2017-10-12 15:13   ` Wei Liu
2017-10-18 11:35   ` George Dunlap
2017-10-13  9:47 ` [PATCH for 4.10 0/3] XSA-243 followup Julien Grall
2017-10-14 17:45 ` Tim Deegan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507816462-15881-3-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=julien.grall@arm.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).