All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Wei Liu" <wei.liu2@citrix.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH RFC 39/55] x86: switch root_pgt to mfn_t and use new APIs
Date: Thu, 7 Feb 2019 16:44:40 +0000	[thread overview]
Message-ID: <20190207164456.9260-40-wei.liu2@citrix.com> (raw)
In-Reply-To: <20190207164456.9260-1-wei.liu2@citrix.com>

This then requires moving declaration of root page table mfn into mm.h
and modify setup_cpu_root_pgt to have a single exit path.

We also need to force map_domain_page to use direct map when switching
per-domain mappings. This is contrary to our end goal of removing
direct map, but this will be removed once we make map_domain_page
context-switch safe in another (large) patch series.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 xen/arch/x86/domain.c           | 15 ++++++++++++---
 xen/arch/x86/domain_page.c      |  2 +-
 xen/arch/x86/mm.c               |  2 +-
 xen/arch/x86/pv/domain.c        |  2 +-
 xen/arch/x86/smpboot.c          | 40 +++++++++++++++++++++++++++-------------
 xen/include/asm-x86/mm.h        |  2 ++
 xen/include/asm-x86/processor.h |  1 -
 7 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 32dc4253ff..603495e55a 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -68,6 +68,7 @@
 #include <asm/pv/domain.h>
 #include <asm/pv/mm.h>
 #include <asm/spec_ctrl.h>
+#include <asm/setup.h>
 
 DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
 
@@ -1589,12 +1590,20 @@ void paravirt_ctxt_switch_from(struct vcpu *v)
 
 void paravirt_ctxt_switch_to(struct vcpu *v)
 {
-    root_pgentry_t *root_pgt = this_cpu(root_pgt);
+    mfn_t rpt_mfn = this_cpu(root_pgt_mfn);
 
-    if ( root_pgt )
-        root_pgt[root_table_offset(PERDOMAIN_VIRT_START)] =
+    if ( !mfn_eq(rpt_mfn, INVALID_MFN) )
+    {
+        root_pgentry_t *rpt;
+
+        mapcache_override_current(INVALID_VCPU);
+        rpt = map_xen_pagetable_new(rpt_mfn);
+        rpt[root_table_offset(PERDOMAIN_VIRT_START)] =
             l4e_from_page(v->domain->arch.perdomain_l3_pg,
                           __PAGE_HYPERVISOR_RW);
+        UNMAP_XEN_PAGETABLE_NEW(rpt);
+        mapcache_override_current(NULL);
+    }
 
     if ( unlikely(v->arch.dr7 & DR7_ACTIVE_MASK) )
         activate_debugregs(v);
diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c
index 24083e9a86..cfcffd35f3 100644
--- a/xen/arch/x86/domain_page.c
+++ b/xen/arch/x86/domain_page.c
@@ -57,7 +57,7 @@ static inline struct vcpu *mapcache_current_vcpu(void)
     return v;
 }
 
-void __init mapcache_override_current(struct vcpu *v)
+void mapcache_override_current(struct vcpu *v)
 {
     this_cpu(override) = v;
 }
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 9e115ef0b8..44c9df5c9e 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -564,7 +564,7 @@ void write_ptbase(struct vcpu *v)
     if ( is_pv_vcpu(v) && v->domain->arch.pv.xpti )
     {
         cpu_info->root_pgt_changed = true;
-        cpu_info->pv_cr3 = __pa(this_cpu(root_pgt));
+        cpu_info->pv_cr3 = mfn_to_maddr(this_cpu(root_pgt_mfn));
         if ( new_cr4 & X86_CR4_PCIDE )
             cpu_info->pv_cr3 |= get_pcid_bits(v, true);
         switch_cr3_cr4(v->arch.cr3, new_cr4);
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 7e84b04082..2fd944b7e3 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -303,7 +303,7 @@ static void _toggle_guest_pt(struct vcpu *v)
         struct cpu_info *cpu_info = get_cpu_info();
 
         cpu_info->root_pgt_changed = true;
-        cpu_info->pv_cr3 = __pa(this_cpu(root_pgt)) |
+        cpu_info->pv_cr3 = mfn_to_maddr(this_cpu(root_pgt_mfn)) |
                            (d->arch.pv.pcid ? get_pcid_bits(v, true) : 0);
     }
 
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index a9a39cea6e..32dce00d10 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -819,7 +819,7 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)
     return rc;
 }
 
-DEFINE_PER_CPU(root_pgentry_t *, root_pgt);
+DEFINE_PER_CPU(mfn_t, root_pgt_mfn);
 
 static root_pgentry_t common_pgt;
 
@@ -827,19 +827,27 @@ extern const char _stextentry[], _etextentry[];
 
 static int setup_cpu_root_pgt(unsigned int cpu)
 {
-    root_pgentry_t *rpt;
+    root_pgentry_t *rpt = NULL;
+    mfn_t rpt_mfn;
     unsigned int off;
     int rc;
 
     if ( !opt_xpti_hwdom && !opt_xpti_domu )
-        return 0;
+    {
+        rc = 0;
+        goto out;
+    }
 
-    rpt = alloc_xen_pagetable();
-    if ( !rpt )
-        return -ENOMEM;
+    rpt_mfn = alloc_xen_pagetable_new();
+    if ( mfn_eq(rpt_mfn, INVALID_MFN) )
+    {
+        rc = -ENOMEM;
+        goto out;
+    }
 
+    rpt = map_xen_pagetable_new(rpt_mfn);
     clear_page(rpt);
-    per_cpu(root_pgt, cpu) = rpt;
+    per_cpu(root_pgt_mfn, cpu) = rpt_mfn;
 
     rpt[root_table_offset(RO_MPT_VIRT_START)] =
         idle_pg_table[root_table_offset(RO_MPT_VIRT_START)];
@@ -856,7 +864,7 @@ static int setup_cpu_root_pgt(unsigned int cpu)
             rc = clone_mapping(ptr, rpt);
 
         if ( rc )
-            return rc;
+            goto out;
 
         common_pgt = rpt[root_table_offset(XEN_VIRT_START)];
     }
@@ -875,19 +883,24 @@ static int setup_cpu_root_pgt(unsigned int cpu)
     if ( !rc )
         rc = clone_mapping((void *)per_cpu(stubs.addr, cpu), rpt);
 
+ out:
+    UNMAP_XEN_PAGETABLE_NEW(rpt);
     return rc;
 }
 
 static void cleanup_cpu_root_pgt(unsigned int cpu)
 {
-    root_pgentry_t *rpt = per_cpu(root_pgt, cpu);
+    mfn_t rpt_mfn = per_cpu(root_pgt_mfn, cpu);
+    root_pgentry_t *rpt;
     unsigned int r;
     unsigned long stub_linear = per_cpu(stubs.addr, cpu);
 
-    if ( !rpt )
+    if ( mfn_eq(rpt_mfn, INVALID_MFN) )
         return;
 
-    per_cpu(root_pgt, cpu) = NULL;
+    per_cpu(root_pgt_mfn, cpu) = INVALID_MFN;
+
+    rpt = map_xen_pagetable_new(rpt_mfn);
 
     for ( r = root_table_offset(DIRECTMAP_VIRT_START);
           r < root_table_offset(HYPERVISOR_VIRT_END); ++r )
@@ -932,7 +945,8 @@ static void cleanup_cpu_root_pgt(unsigned int cpu)
         free_xen_pagetable_new(l3t_mfn);
     }
 
-    free_xen_pagetable(rpt);
+    UNMAP_XEN_PAGETABLE_NEW(rpt);
+    free_xen_pagetable_new(rpt_mfn);
 
     /* Also zap the stub mapping for this CPU. */
     if ( stub_linear )
@@ -1138,7 +1152,7 @@ void __init smp_prepare_cpus(void)
     rc = setup_cpu_root_pgt(0);
     if ( rc )
         panic("Error %d setting up PV root page table\n", rc);
-    if ( per_cpu(root_pgt, 0) )
+    if ( !mfn_eq(per_cpu(root_pgt_mfn, 0), INVALID_MFN) )
     {
         get_cpu_info()->pv_cr3 = 0;
 
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 4378d9f815..708b84bb89 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -657,4 +657,6 @@ void free_xen_pagetable_new(mfn_t mfn);
 
 l1_pgentry_t *virt_to_xen_l1e(unsigned long v);
 
+DECLARE_PER_CPU(mfn_t, root_pgt_mfn);
+
 #endif /* __ASM_X86_MM_H__ */
diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h
index df01ae30d7..9f98ac96f5 100644
--- a/xen/include/asm-x86/processor.h
+++ b/xen/include/asm-x86/processor.h
@@ -449,7 +449,6 @@ extern idt_entry_t idt_table[];
 extern idt_entry_t *idt_tables[];
 
 DECLARE_PER_CPU(struct tss_struct, init_tss);
-DECLARE_PER_CPU(root_pgentry_t *, root_pgt);
 
 extern void write_ptbase(struct vcpu *v);
 
-- 
2.11.0


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

  parent reply	other threads:[~2019-02-07 17:00 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-07 16:44 [PATCH RFC 00/55] x86: use domheap page for xen page tables Wei Liu
2019-02-07 16:44 ` [PATCH RFC 01/55] x86/mm: defer clearing page in virt_to_xen_lXe Wei Liu
2019-03-15 14:38   ` Jan Beulich
2019-04-09 12:21     ` Wei Liu
2019-04-09 12:21       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 02/55] x86: move some xen mm function declarations Wei Liu
2019-03-15 14:42   ` Jan Beulich
2019-02-07 16:44 ` [PATCH RFC 03/55] x86: introduce a new set of APIs to manage Xen page tables Wei Liu
2019-02-07 16:44 ` [PATCH RFC 04/55] x86/mm: introduce l{1, 2}t local variables to map_pages_to_xen Wei Liu
2019-03-15 15:36   ` Jan Beulich
2019-04-09 12:22     ` Wei Liu
2019-04-09 12:22       ` [Xen-devel] " Wei Liu
2019-04-09 12:49       ` Jan Beulich
2019-04-09 12:49         ` [Xen-devel] " Jan Beulich
2019-04-09 12:59         ` Wei Liu
2019-04-09 12:59           ` [Xen-devel] " Wei Liu
2019-04-09 13:20           ` Jan Beulich
2019-04-09 13:20             ` [Xen-devel] " Jan Beulich
2019-02-07 16:44 ` [PATCH RFC 05/55] x86/mm: introduce l{1, 2}t local variables to modify_xen_mappings Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 06/55] x86/mm: map_pages_to_xen should have one exit path Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:22     ` Wei Liu
2019-04-09 12:22       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 07/55] x86/mm: add an end_of_loop label in map_pages_to_xen Wei Liu
2019-03-15 15:40   ` Jan Beulich
2019-04-09 12:22     ` Wei Liu
2019-04-09 12:22       ` [Xen-devel] " Wei Liu
2019-04-09 12:50       ` Jan Beulich
2019-04-09 12:50         ` [Xen-devel] " Jan Beulich
2019-03-18 21:14   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 08/55] x86/mm: make sure there is one exit path for modify_xen_mappings Wei Liu
2019-02-07 16:44 ` [PATCH RFC 09/55] x86/mm: add an end_of_loop label in modify_xen_mappings Wei Liu
2019-02-07 16:44 ` [PATCH RFC 10/55] x86/mm: change pl2e to l2t in virt_to_xen_l2e Wei Liu
2019-02-07 16:44 ` [PATCH RFC 11/55] x86/mm: change pl1e to l1t in virt_to_xen_l1e Wei Liu
2019-02-07 16:44 ` [PATCH RFC 12/55] x86/mm: change pl3e to l3t in virt_to_xen_l3e Wei Liu
2019-02-07 16:44 ` [PATCH RFC 13/55] x86/mm: rewrite virt_to_xen_l3e Wei Liu
2019-04-08 15:55   ` Jan Beulich
2019-04-08 15:55     ` [Xen-devel] " Jan Beulich
2019-04-09 12:27     ` Wei Liu
2019-04-09 12:27       ` [Xen-devel] " Wei Liu
2019-04-09 12:52       ` Jan Beulich
2019-04-09 12:52         ` [Xen-devel] " Jan Beulich
2019-02-07 16:44 ` [PATCH RFC 14/55] x86/mm: rewrite xen_to_virt_l2e Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:27     ` Wei Liu
2019-04-09 12:27       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 15/55] x86/mm: rewrite virt_to_xen_l1e Wei Liu
2019-02-07 16:44 ` [PATCH RFC 16/55] x86/mm: switch to new APIs in map_pages_to_xen Wei Liu
2019-02-08 17:58   ` Wei Liu
2019-03-18 21:14     ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 17/55] x86/mm: drop lXe_to_lYe invocations " Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 18/55] x86/mm: switch to new APIs in modify_xen_mappings Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:22     ` Wei Liu
2019-04-09 12:22       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 19/55] x86/mm: drop lXe_to_lYe invocations from modify_xen_mappings Wei Liu
2019-02-07 16:44 ` [PATCH RFC 20/55] x86/mm: switch to new APIs in arch_init_memory Wei Liu
2019-02-07 16:44 ` [PATCH RFC 21/55] x86_64/mm: introduce pl2e in paging_init Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 22/55] x86_64/mm: switch to new APIs " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 23/55] x86_64/mm: drop l4e_to_l3e invocation from paging_init Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:22     ` Wei Liu
2019-04-09 12:22       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 24/55] x86_64/mm.c: remove code that serves no purpose in setup_m2p_table Wei Liu
2019-02-07 16:44 ` [PATCH RFC 25/55] x86_64/mm: introduce pl2e " Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 26/55] x86_64/mm: switch to new APIs " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 27/55] x86_64/mm: drop lXe_to_lYe invocations from setup_m2p_table Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:30     ` Wei Liu
2019-04-09 12:30       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 28/55] efi: use new page table APIs in copy_mapping Wei Liu
2019-02-07 16:44 ` [PATCH RFC 29/55] efi: avoid using global variable " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 30/55] efi: use new page table APIs in efi_init_memory Wei Liu
2019-02-07 16:44 ` [PATCH RFC 31/55] efi: add emacs block to boot.c Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:23     ` Wei Liu
2019-04-09 12:23       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 32/55] efi: switch EFI L4 table to use new APIs Wei Liu
2019-03-18 21:14   ` Nuernberger, Stefan
2019-04-09 12:23     ` Wei Liu
2019-04-09 12:23       ` [Xen-devel] " Wei Liu
2019-04-09 12:56       ` Jan Beulich
2019-04-09 12:56         ` [Xen-devel] " Jan Beulich
2019-04-09 13:00         ` Wei Liu
2019-04-09 13:00           ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 33/55] x86/smpboot: add emacs block Wei Liu
2019-02-07 16:44 ` [PATCH RFC 34/55] x86/smpboot: clone_mapping should have one exit path Wei Liu
2019-02-07 16:44 ` [PATCH RFC 35/55] x86/smpboot: switch pl3e to use new APIs in clone_mapping Wei Liu
2019-02-07 16:44 ` [PATCH RFC 36/55] x86/smpboot: switch pl2e " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 37/55] x86/smpboot: switch pl1e " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 38/55] x86/smpboot: drop lXe_to_lYe invocations from cleanup_cpu_root_pgt Wei Liu
2019-02-07 16:44 ` Wei Liu [this message]
2019-03-19 16:45   ` [PATCH RFC 39/55] x86: switch root_pgt to mfn_t and use new APIs Nuernberger, Stefan
2019-04-09 12:23     ` Wei Liu
2019-04-09 12:23       ` [Xen-devel] " Wei Liu
2019-02-07 16:44 ` [PATCH RFC 40/55] x86/shim: map and unmap page tables in replace_va_mapping Wei Liu
2019-02-07 16:44 ` [PATCH RFC 41/55] x86_64/mm: map and unmap page tables in m2p_mapped Wei Liu
2019-03-19 16:45   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 42/55] x86_64/mm: map and unmap page tables in share_hotadd_m2p_table Wei Liu
2019-03-19 16:45   ` Nuernberger, Stefan
2019-02-07 16:44 ` [PATCH RFC 43/55] x86_64/mm: map and unmap page tables in destroy_compat_m2p_mapping Wei Liu
2019-02-07 16:44 ` [PATCH RFC 44/55] x86_64/mm: map and unmap page tables in destroy_m2p_mapping Wei Liu
2019-02-07 16:44 ` [PATCH RFC 45/55] x86_64/mm: map and unmap page tables in setup_compat_m2p_table Wei Liu
2019-02-07 16:44 ` [PATCH RFC 46/55] x86_64/mm: map and unmap page tables in cleanup_frame_table Wei Liu
2019-02-07 16:44 ` [PATCH RFC 47/55] x86_64/mm: map and unmap page tables in subarch_init_memory Wei Liu
2019-02-07 16:44 ` [PATCH RFC 48/55] x86_64/mm: map and unmap page tables in subarch_memory_op Wei Liu
2019-02-07 16:44 ` [PATCH RFC 49/55] x86/smpboot: remove lXe_to_lYe in cleanup_cpu_root_pgt Wei Liu
2019-02-07 16:44 ` [PATCH RFC 50/55] x86/pv: properly map and unmap page tables in mark_pv_pt_pages_rdonly Wei Liu
2019-02-07 16:44 ` [PATCH RFC 51/55] x86/pv: properly map and unmap page table in dom0_construct_pv Wei Liu
2019-02-07 16:44 ` [PATCH RFC 52/55] x86: remove lXe_to_lYe in __start_xen Wei Liu
2019-02-07 16:44 ` [PATCH RFC 53/55] x86/mm: drop old page table APIs Wei Liu
2019-02-07 16:44 ` [PATCH RFC 54/55] x86: switch to use domheap page for page tables Wei Liu
2019-02-07 16:44 ` [PATCH RFC 55/55] x86/mm: drop _new suffix from page table APIs Wei Liu
2019-03-18 21:14 ` [PATCH RFC 00/55] x86: use domheap page for xen page tables Nuernberger, Stefan
2019-03-28 12:52 ` Nuernberger, Stefan

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=20190207164456.9260-40-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.