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

[Xen-devel] [RFC PATCH 57/84] x86: add Persistent Map (PMAP) infrastructure



From: Wei Liu <wei.liu2@xxxxxxxxxx>

The basic idea is like Persistent Kernel Map (PKMAP) in linux. We
pre-populate all the relevant page tables before system is fully set
up.

It is needed to bootstrap map domain page infrastructure -- we need
some way to map pages to set up per-cpu region without a direct map.

In order to keep the number of entries minimal, this infrastructure
can only be used by one CPU at a time.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/x86/Makefile        |  1 +
 xen/arch/x86/pmap.c          | 82 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/fixmap.h |  3 ++
 xen/include/asm-x86/pmap.h   | 12 ++++++
 4 files changed, 98 insertions(+)
 create mode 100644 xen/arch/x86/pmap.c
 create mode 100644 xen/include/asm-x86/pmap.h

diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 2443fd2cc5..7508219686 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -55,6 +55,7 @@ obj-y += pci.o
 obj-y += percpu.o
 obj-y += physdev.o x86_64/physdev.o
 obj-y += platform_hypercall.o x86_64/platform_hypercall.o
+obj-y += pmap.o
 obj-y += psr.o
 obj-y += setup.o
 obj-y += shutdown.o
diff --git a/xen/arch/x86/pmap.c b/xen/arch/x86/pmap.c
new file mode 100644
index 0000000000..4ae16b0212
--- /dev/null
+++ b/xen/arch/x86/pmap.c
@@ -0,0 +1,82 @@
+#include <xen/init.h>
+#include <xen/mm.h>
+#include <xen/spinlock.h>
+
+#include <asm/bitops.h>
+#include <asm/fixmap.h>
+
+/*
+ * Simple mapping infrastructure to map / unmap pages in fixed map.
+ * This is used to set up percpu page table for mapcache, which is
+ * used by map domain page infrastructure.
+ *
+ * There is a restriction that only one CPU can use this
+ * infrastructure at a time. So this infrastructure _should not_ be
+ * used anywhere else other than the stated purpose above.
+ */
+
+static DEFINE_SPINLOCK(lock);
+/* Bitmap to track which slot is used */
+static unsigned long inuse;
+
+void pmap_lock(void)
+{
+    spin_lock(&lock);
+}
+
+void pmap_unlock(void)
+{
+    spin_unlock(&lock);
+}
+
+void *pmap_map(struct page_info *page)
+{
+    unsigned int idx;
+    void *linear = NULL;
+    enum fixed_addresses slot;
+
+    ASSERT(!in_irq());
+    ASSERT(spin_is_locked(&lock));
+
+    idx = find_first_zero_bit(&inuse, NUM_FIX_PMAP);
+    if ( idx == NUM_FIX_PMAP )
+        panic("Out of PMAP slots\n");
+
+    __set_bit(idx, &inuse);
+
+    slot = idx + FIX_PMAP_BEGIN;
+    ASSERT(slot >= FIX_PMAP_BEGIN && slot <= FIX_PMAP_END);
+
+    set_fixmap(slot, mfn_x(page_to_mfn(page)));
+    linear = (void *)__fix_to_virt(slot);
+
+    return linear;
+}
+
+void pmap_unmap(void *p)
+{
+    unsigned int idx;
+    enum fixed_addresses slot = __virt_to_fix((unsigned long)p);
+
+    ASSERT(!in_irq());
+    ASSERT(slot >= FIX_PMAP_BEGIN && slot <= FIX_PMAP_END);
+    ASSERT(spin_is_locked(&lock));
+
+    idx = slot - FIX_PMAP_BEGIN;
+    __clear_bit(idx, &inuse);
+    clear_fixmap(slot);
+}
+
+static void __maybe_unused build_assertions(void)
+{
+    BUILD_BUG_ON(sizeof(inuse) * BITS_PER_LONG < NUM_FIX_PMAP);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h
index 9fb2f47946..85885f8950 100644
--- a/xen/include/asm-x86/fixmap.h
+++ b/xen/include/asm-x86/fixmap.h
@@ -23,6 +23,7 @@
 #include <xen/kexec.h>
 #include <asm/apicdef.h>
 #include <asm/msi.h>
+#include <asm/pmap.h>
 #include <acpi/apei.h>
 
 /*
@@ -48,6 +49,8 @@ enum fixed_addresses {
     FIX_XEN_SHARED_INFO,
 #endif /* CONFIG_XEN_GUEST */
     /* Everything else should go further down. */
+    FIX_PMAP_BEGIN,
+    FIX_PMAP_END = FIX_PMAP_BEGIN + NUM_FIX_PMAP - 1,
     FIX_APIC_BASE,
     FIX_IO_APIC_BASE_0,
     FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
diff --git a/xen/include/asm-x86/pmap.h b/xen/include/asm-x86/pmap.h
new file mode 100644
index 0000000000..42cd4c7793
--- /dev/null
+++ b/xen/include/asm-x86/pmap.h
@@ -0,0 +1,12 @@
+#ifndef __X86_PMAP_H__
+#define __X86_PMAP_H__
+
+/* Large enough for mapping 5 levels of page tables */
+#define NUM_FIX_PMAP 5
+
+void pmap_lock(void);
+void pmap_unlock(void);
+void *pmap_map(struct page_info *page);
+void pmap_unmap(void *p);
+
+#endif /* __X86_PMAP_H__ */
-- 
2.17.1


_______________________________________________
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®.