From a19bb9fd0ef8da6962605636eaf1184d5fc05f22 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Tue, 2 Aug 2016 16:09:00 +0100 Subject: [PATCH] Introduce GFN terminology to memory management 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 --- arch/x86/pv/traps.c | 2 +- include/arch/x86/mm.h | 30 +++++++++++++++++++++++++++ include/arch/x86/page.h | 19 ----------------- include/arch/x86/pagetable.h | 40 ++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 include/arch/x86/pagetable.h diff --git a/arch/x86/pv/traps.c b/arch/x86/pv/traps.c index f38e3f0..5b50eed 100644 --- a/arch/x86/pv/traps.c +++ b/arch/x86/pv/traps.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include /* Real entry points */ diff --git a/include/arch/x86/mm.h b/include/arch/x86/mm.h index d2a65d0..a5cdce6 100644 --- a/include/arch/x86/mm.h +++ b/include/arch/x86/mm.h @@ -8,6 +8,18 @@ #include /* + * 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 */ /* diff --git a/include/arch/x86/page.h b/include/arch/x86/page.h index 3a7f1eb..d8d070e 100644 --- a/include/arch/x86/page.h +++ b/include/arch/x86/page.h @@ -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 index 0000000..24789fe --- /dev/null +++ b/include/arch/x86/pagetable.h @@ -0,0 +1,40 @@ +#ifndef XTF_X86_PAGETABLE_H +#define XTF_X86_PAGETABLE_H + +#include + +#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: + */ -- 2.39.5