# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1233918928 0
# Node ID 3c44c7dcf48204d847a0fc50ac2d93cfc3a327f3
# Parent a5bd5722360cd6c0a2e8b7e85208e05e7cb3f6cf
x86: Clean up page-mfn conversion macros to allow better override by shadow
code.
Also fix is_xen_heap_mfn() to deal with invalid MFNs.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
xen/arch/x86/mm/hap/hap.c | 6 +++---
xen/arch/x86/mm/p2m.c | 6 +++---
xen/arch/x86/mm/paging.c | 6 +++---
xen/arch/x86/mm/shadow/private.h | 17 +++++------------
xen/include/asm-x86/mm.h | 3 ++-
xen/include/asm-x86/page.h | 38 +++++++++++++++++++++++++++-----------
6 files changed, 43 insertions(+), 33 deletions(-)
diff -r a5bd5722360c -r 3c44c7dcf482 xen/arch/x86/mm/hap/hap.c
--- a/xen/arch/x86/mm/hap/hap.c Fri Feb 06 10:43:58 2009 +0000
+++ b/xen/arch/x86/mm/hap/hap.c Fri Feb 06 11:15:28 2009 +0000
@@ -45,11 +45,11 @@
/* Override macros from asm/page.h to make them work with mfn_t */
#undef mfn_to_page
-#define mfn_to_page(_m) (frame_table + mfn_x(_m))
+#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
#undef mfn_valid
-#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
+#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
#undef page_to_mfn
-#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
+#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
/************************************************/
/* HAP LOG DIRTY SUPPORT */
diff -r a5bd5722360c -r 3c44c7dcf482 xen/arch/x86/mm/p2m.c
--- a/xen/arch/x86/mm/p2m.c Fri Feb 06 10:43:58 2009 +0000
+++ b/xen/arch/x86/mm/p2m.c Fri Feb 06 11:15:28 2009 +0000
@@ -89,11 +89,11 @@
/* Override macros from asm/page.h to make them work with mfn_t */
#undef mfn_to_page
-#define mfn_to_page(_m) (frame_table + mfn_x(_m))
+#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
#undef mfn_valid
-#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
+#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
#undef page_to_mfn
-#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
+#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
/* PTE flags for the various types of p2m entry */
diff -r a5bd5722360c -r 3c44c7dcf482 xen/arch/x86/mm/paging.c
--- a/xen/arch/x86/mm/paging.c Fri Feb 06 10:43:58 2009 +0000
+++ b/xen/arch/x86/mm/paging.c Fri Feb 06 11:15:28 2009 +0000
@@ -47,11 +47,11 @@
/************************************************/
/* Override macros from asm/page.h to make them work with mfn_t */
#undef mfn_to_page
-#define mfn_to_page(_m) (frame_table + mfn_x(_m))
+#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
#undef mfn_valid
-#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
+#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
#undef page_to_mfn
-#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
+#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
/* The log-dirty lock. This protects the log-dirty bitmap from
* concurrent accesses (and teardowns, etc).
diff -r a5bd5722360c -r 3c44c7dcf482 xen/arch/x86/mm/shadow/private.h
--- a/xen/arch/x86/mm/shadow/private.h Fri Feb 06 10:43:58 2009 +0000
+++ b/xen/arch/x86/mm/shadow/private.h Fri Feb 06 11:15:28 2009 +0000
@@ -474,20 +474,13 @@ mfn_t oos_snapshot_lookup(struct vcpu *v
* MFN/page-info handling
*/
-// Override mfn_to_page from asm/page.h, which was #include'd above,
-// in order to make it work with our mfn type.
+/* Override macros from asm/page.h to make them work with mfn_t */
#undef mfn_to_page
-#define mfn_to_page(_m) (frame_table + mfn_x(_m))
-
-// Override page_to_mfn from asm/page.h, which was #include'd above,
-// in order to make it work with our mfn type.
+#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
+#undef mfn_valid
+#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
#undef page_to_mfn
-#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
-
-// Override mfn_valid from asm/page.h, which was #include'd above,
-// in order to make it work with our mfn type.
-#undef mfn_valid
-#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
+#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
/* Override pagetable_t <-> struct page_info conversions to work with mfn_t */
#undef pagetable_get_page
diff -r a5bd5722360c -r 3c44c7dcf482 xen/include/asm-x86/mm.h
--- a/xen/include/asm-x86/mm.h Fri Feb 06 10:43:58 2009 +0000
+++ b/xen/include/asm-x86/mm.h Fri Feb 06 11:15:28 2009 +0000
@@ -210,7 +210,8 @@ struct page_info
})
#else
#define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
-#define is_xen_heap_mfn(mfn) is_xen_heap_page(&frame_table[mfn])
+#define is_xen_heap_mfn(mfn) \
+ (__mfn_valid(mfn) && is_xen_heap_page(__mfn_to_page(mfn)))
#endif
#if defined(__i386__)
diff -r a5bd5722360c -r 3c44c7dcf482 xen/include/asm-x86/page.h
--- a/xen/include/asm-x86/page.h Fri Feb 06 10:43:58 2009 +0000
+++ b/xen/include/asm-x86/page.h Fri Feb 06 11:15:28 2009 +0000
@@ -220,31 +220,47 @@ void copy_page_sse2(void *, const void *
copy_page_sse2(_t, _f) : \
(void)memcpy(_t, _f, PAGE_SIZE))
-#define mfn_valid(mfn) ((mfn) < max_page)
+#define __mfn_valid(mfn) ((mfn) < max_page)
/* Convert between Xen-heap virtual addresses and machine addresses. */
#define __pa(x) (virt_to_maddr(x))
#define __va(x) (maddr_to_virt(x))
/* Convert between Xen-heap virtual addresses and machine frame numbers. */
-#define virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT)
-#define mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
+#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT)
+#define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
/* Convert between machine frame numbers and page-info structures. */
-#define mfn_to_page(mfn) (frame_table + (mfn))
-#define page_to_mfn(pg) ((unsigned long)((pg) - frame_table))
+#define __mfn_to_page(mfn) (frame_table + (mfn))
+#define __page_to_mfn(pg) ((unsigned long)((pg) - frame_table))
/* Convert between machine addresses and page-info structures. */
-#define maddr_to_page(ma) (frame_table + ((ma) >> PAGE_SHIFT))
-#define page_to_maddr(pg) ((paddr_t)((pg) - frame_table) << PAGE_SHIFT)
+#define __maddr_to_page(ma) (frame_table + ((ma) >> PAGE_SHIFT))
+#define __page_to_maddr(pg) ((paddr_t)((pg) - frame_table) << PAGE_SHIFT)
/* Convert between Xen-heap virtual addresses and page-info structures. */
-#define virt_to_page(va) (frame_table + (__pa(va) >> PAGE_SHIFT))
-#define page_to_virt(pg) (maddr_to_virt(page_to_maddr(pg)))
+#define __virt_to_page(va) (frame_table + (__pa(va) >> PAGE_SHIFT))
+#define __page_to_virt(pg) (maddr_to_virt(page_to_maddr(pg)))
/* Convert between frame number and address formats. */
-#define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
-#define paddr_to_pfn(pa) ((unsigned long)((pa) >> PAGE_SHIFT))
+#define __pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
+#define __paddr_to_pfn(pa) ((unsigned long)((pa) >> PAGE_SHIFT))
+
+/*
+ * We define non-underscored wrappers for above conversion functions. These are
+ * overridden in various source files while underscored versions remain intact.
+ */
+#define mfn_valid(mfn) __mfn_valid(mfn)
+#define virt_to_mfn(va) __virt_to_mfn(va)
+#define mfn_to_virt(mfn) __mfn_to_virt(mfn)
+#define mfn_to_page(mfn) __mfn_to_page(mfn)
+#define page_to_mfn(pg) __page_to_mfn(pg)
+#define maddr_to_page(ma) __maddr_to_page(ma)
+#define page_to_maddr(pg) __page_to_maddr(pg)
+#define virt_to_page(va) __virt_to_page(va)
+#define page_to_virt(pg) __page_to_virt(pg)
+#define pfn_to_paddr(pfn) __pfn_to_paddr(pfn)
+#define paddr_to_pfn(pa) __paddr_to_pfn(pa)
#endif /* !defined(__ASSEMBLY__) */
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|