]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
x86: add Persistent Map (PMAP) infrastructure
authorWei Liu <wei.liu2@citrix.com>
Fri, 11 Jan 2019 17:20:21 +0000 (17:20 +0000)
committerWei Liu <wei.liu2@citrix.com>
Mon, 21 Jan 2019 15:34:00 +0000 (15:34 +0000)
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@citrix.com>
xen/arch/x86/Makefile
xen/arch/x86/pmap.c [new file with mode: 0644]
xen/include/asm-x86/fixmap.h
xen/include/asm-x86/pmap.h [new file with mode: 0644]

index ef099398bff222e79239358b05c42b762e365172..586ebc5d51dfc6e570de3434897af23f32b2c99b 100644 (file)
@@ -54,6 +54,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 (file)
index 0000000..4ae16b0
--- /dev/null
@@ -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:
+ */
index 16ccaa2c771f7aaa86922249b9e3eb86b187cc84..dcc1e6a6708f18e444bd33c5ade436c2aec99304 100644 (file)
@@ -25,6 +25,7 @@
 #include <asm/apicdef.h>
 #include <asm/amd-iommu.h>
 #include <asm/msi.h>
+#include <asm/pmap.h>
 #include <acpi/apei.h>
 
 /*
@@ -50,6 +51,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 (file)
index 0000000..42cd4c7
--- /dev/null
@@ -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__ */