]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
Introduce GFN terminology to memory management
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 2 Aug 2016 15:09:00 +0000 (16:09 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 2 Aug 2016 15:29:27 +0000 (16:29 +0100)
which allows for common code to use gfn_to_virt()/virt_to_gfn() without
needing to worry whether it is a PV or HVM guest.

Add a pte_from_virt() helper to construct a pagetable entry pointing at a data
item linked into the test microkernel.  To avoid inclusion problems, split the
independent pagetable modification functions out into a separate header file.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/pv/traps.c
include/arch/x86/mm.h
include/arch/x86/page.h
include/arch/x86/pagetable.h [new file with mode: 0644]

index f38e3f06a30882daddaa87d2fe20cdc620b57a56..5b50eed9f1a912367bc9a87d62dfe6fa6f3aeec8 100644 (file)
@@ -6,7 +6,7 @@
 #include <arch/x86/lib.h>
 #include <arch/x86/processor.h>
 #include <arch/x86/segment.h>
-#include <arch/x86/mm.h>
+#include <arch/x86/pagetable.h>
 #include <arch/x86/symbolic-const.h>
 
 /* Real entry points */
index d2a65d04e0f774caf60a8d968e005727d45e95e2..a5cdce64400ffc8b4886ab6df680d9b5be85a8cf 100644 (file)
@@ -8,6 +8,18 @@
 #include <xen/xen.h>
 
 /*
+ * Terminology (inherited from Xen):
+ *
+ *   GFN - Guest Frame Number
+ *           What a guest writes into its pagetables.
+ *   MFN - Machine Frame Number
+ *           What Xen writes into its pagetables.
+ *   PFN - Pseudophysical Frame Number
+ *           A linear idea of a guests physical address space.
+ *
+ * For HVM, PFN == GFN, and MFN is strictly irrelevent.
+ * For PV,  MFN == GFN != PFN.
+ *
  * XTF memory layout.
  *
  * Wherever possible, identity layout for simplicity.
@@ -60,6 +72,24 @@ static inline unsigned long virt_to_mfn(const void *va)
 
 #endif /* CONFIG_PV */
 
+static inline void *gfn_to_virt(unsigned long gfn)
+{
+#if defined(CONFIG_PV)
+    return mfn_to_virt(gfn);
+#else
+    return pfn_to_virt(gfn);
+#endif
+}
+
+static inline unsigned long virt_to_gfn(const void *va)
+{
+#if defined(CONFIG_PV)
+    return virt_to_mfn(va);
+#else
+    return virt_to_pfn(va);
+#endif
+}
+
 #endif /* XTF_X86_MM_H */
 
 /*
index 3a7f1eb486642c177e03a097d0b0e823838202d4..d8d070eb8ff88f1bb887ccdf9bc19710a5b6948c 100644 (file)
@@ -144,25 +144,6 @@ static inline unsigned int l4_table_offset(unsigned long va)
 
 #endif /* CONFIG_PAGING_LEVELS >= 4 */
 
-#if CONFIG_PAGING_LEVELS > 0
-
-static inline paddr_t pte_to_paddr(intpte_t pte)
-{
-    return pte & PADDR_MASK & PAGE_MASK;
-}
-
-static inline intpte_t pte_from_paddr(paddr_t paddr, uint64_t flags)
-{
-    return paddr | flags;
-}
-
-static inline intpte_t pte_from_gfn(unsigned long gfn, uint64_t flags)
-{
-    return pte_from_paddr((paddr_t)gfn << PAGE_SHIFT, flags);
-}
-
-#endif /* CONFIG_PAGING_LEVELS > 0 */
-
 #ifdef CONFIG_HVM
 
 extern pae_intpte_t pae_l1_identmap[PAE_L1_PT_ENTRIES];
diff --git a/include/arch/x86/pagetable.h b/include/arch/x86/pagetable.h
new file mode 100644 (file)
index 0000000..24789fe
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef XTF_X86_PAGETABLE_H
+#define XTF_X86_PAGETABLE_H
+
+#include <arch/x86/mm.h>
+
+#if CONFIG_PAGING_LEVELS > 0
+
+static inline paddr_t pte_to_paddr(intpte_t pte)
+{
+    return pte & PADDR_MASK & PAGE_MASK;
+}
+
+static inline intpte_t pte_from_paddr(paddr_t paddr, uint64_t flags)
+{
+    return paddr | flags;
+}
+
+static inline intpte_t pte_from_gfn(unsigned long gfn, uint64_t flags)
+{
+    return pte_from_paddr((paddr_t)gfn << PAGE_SHIFT, flags);
+}
+
+static inline intpte_t pte_from_virt(const void *va, uint64_t flags)
+{
+    return pte_from_paddr((paddr_t)virt_to_gfn(va) << PAGE_SHIFT, flags);
+}
+
+#endif /* CONFIG_PAGING_LEVELS > 0 */
+
+#endif /* XTF_X86_PAGETABLE_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */