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

[Xen-devel] [PATCH RFC 10/44] x86/pt-shadow: Initial infrastructure for L4 PV pagetable shadowing



Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
v3:
 * Switch to using a single structure per cpu, rather than multiple fields.
---
 xen/arch/x86/pv/Makefile           |  1 +
 xen/arch/x86/pv/pt-shadow.c        | 86 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/smpboot.c             |  7 ++++
 xen/include/asm-x86/pv/pt-shadow.h | 50 ++++++++++++++++++++++
 4 files changed, 144 insertions(+)
 create mode 100644 xen/arch/x86/pv/pt-shadow.c
 create mode 100644 xen/include/asm-x86/pv/pt-shadow.h

diff --git a/xen/arch/x86/pv/Makefile b/xen/arch/x86/pv/Makefile
index bac2792..acff2bc 100644
--- a/xen/arch/x86/pv/Makefile
+++ b/xen/arch/x86/pv/Makefile
@@ -10,6 +10,7 @@ obj-y += hypercall.o
 obj-y += iret.o
 obj-y += misc-hypercalls.o
 obj-y += mm.o
+obj-y += pt-shadow.o
 obj-y += ro-page-fault.o
 obj-y += traps.o
 
diff --git a/xen/arch/x86/pv/pt-shadow.c b/xen/arch/x86/pv/pt-shadow.c
new file mode 100644
index 0000000..7db8efb
--- /dev/null
+++ b/xen/arch/x86/pv/pt-shadow.c
@@ -0,0 +1,86 @@
+/*
+ * arch/x86/pv/pt-shadow.c
+ *
+ * PV Pagetable shadowing logic to allow Xen to run with per-pcpu pagetables.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2017 Citrix Systems Ltd.
+ */
+#include <xen/domain_page.h>
+#include <xen/mm.h>
+#include <xen/numa.h>
+
+#include <asm/pv/pt-shadow.h>
+
+struct pt_shadow {
+    /*
+     * A frame used to shadow a vcpus intended pagetable.  When shadowing,
+     * this frame is the one actually referenced by %cr3.
+     */
+    paddr_t shadow_l4;
+    l4_pgentry_t *shadow_l4_va;
+};
+
+static DEFINE_PER_CPU(struct pt_shadow, ptsh);
+
+int pt_shadow_alloc(unsigned int cpu)
+{
+    struct pt_shadow *ptsh = &per_cpu(ptsh, cpu);
+    unsigned int memflags = 0;
+    nodeid_t node = cpu_to_node(cpu);
+    struct page_info *pg;
+
+    if ( node != NUMA_NO_NODE )
+        memflags = MEMF_node(node);
+
+    pg = alloc_domheap_page(NULL, memflags);
+    if ( !pg )
+        return -ENOMEM;
+
+    ptsh->shadow_l4 = page_to_maddr(pg);
+
+    ptsh->shadow_l4_va = __map_domain_page_global(pg);
+    if ( !ptsh->shadow_l4_va )
+        return -ENOMEM;
+
+    return 0;
+}
+
+void pt_shadow_free(unsigned int cpu)
+{
+    struct pt_shadow *ptsh = &per_cpu(ptsh, cpu);
+
+    if ( ptsh->shadow_l4_va )
+    {
+        unmap_domain_page_global(ptsh->shadow_l4_va);
+        ptsh->shadow_l4_va = NULL;
+    }
+
+    if ( ptsh->shadow_l4 )
+    {
+        free_domheap_page(maddr_to_page(ptsh->shadow_l4));
+        ptsh->shadow_l4 = 0;
+    }
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index ae39b48..a855301 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -40,6 +40,7 @@
 #include <asm/flushtlb.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
+#include <asm/pv/pt-shadow.h>
 #include <asm/time.h>
 #include <asm/tboot.h>
 #include <mach_apic.h>
@@ -658,6 +659,10 @@ static int cpu_smpboot_alloc_common(unsigned int cpu)
     clear_page(l4t);
     init_xen_l4_slots(l4t, page_to_mfn(pg), NULL, INVALID_MFN, false);
 
+    rc = pt_shadow_alloc(cpu);
+    if ( rc )
+        goto out;
+
     rc = 0; /* Success */
 
  out:
@@ -726,6 +731,8 @@ static void cpu_smpboot_free(unsigned int cpu)
         free_domheap_page(maddr_to_page(per_cpu(percpu_idle_pt, cpu)));
         per_cpu(percpu_idle_pt, cpu) = 0;
     }
+
+    pt_shadow_free(cpu);
 }
 
 static int cpu_smpboot_alloc(unsigned int cpu)
diff --git a/xen/include/asm-x86/pv/pt-shadow.h 
b/xen/include/asm-x86/pv/pt-shadow.h
new file mode 100644
index 0000000..ff99c85
--- /dev/null
+++ b/xen/include/asm-x86/pv/pt-shadow.h
@@ -0,0 +1,50 @@
+/*
+ * include/asm-x86/pv/pt-shadow.h
+ *
+ * PV Pagetable shadowing logic to allow Xen to run with per-pcpu pagetables.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2017 Citrix Systems Ltd.
+ */
+#ifndef __X86_PV_PT_SHADOW_H__
+#define __X86_PV_PT_SHADOW_H__
+
+#ifdef CONFIG_PV
+
+/*
+ * Allocate an free per-pcpu resources for pagetable shadowing.  If alloc()
+ * returns nonzero, it is the callers responsibility to call free().
+ */
+int pt_shadow_alloc(unsigned int cpu);
+void pt_shadow_free(unsigned int cpu);
+
+#else /* !CONFIG_PV */
+
+static inline int pt_shadow_alloc(unsigned int cpu) { return 0; }
+static inline void pt_shadow_free(unsigned int cpu) { }
+
+#endif /* CONFIG_PV */
+
+#endif /* __X86_PV_PT_SHADOW_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.1.4


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

 


Rackspace

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