ia64/xen-unstable

changeset 19182:3c44c7dcf482

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@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Feb 06 11:15:28 2009 +0000 (2009-02-06)
parents a5bd5722360c
children 57e98fc0d956
files xen/arch/x86/mm/hap/hap.c xen/arch/x86/mm/p2m.c xen/arch/x86/mm/paging.c xen/arch/x86/mm/shadow/private.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h
line diff
     1.1 --- a/xen/arch/x86/mm/hap/hap.c	Fri Feb 06 10:43:58 2009 +0000
     1.2 +++ b/xen/arch/x86/mm/hap/hap.c	Fri Feb 06 11:15:28 2009 +0000
     1.3 @@ -45,11 +45,11 @@
     1.4  
     1.5  /* Override macros from asm/page.h to make them work with mfn_t */
     1.6  #undef mfn_to_page
     1.7 -#define mfn_to_page(_m) (frame_table + mfn_x(_m))
     1.8 +#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
     1.9  #undef mfn_valid
    1.10 -#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
    1.11 +#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
    1.12  #undef page_to_mfn
    1.13 -#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
    1.14 +#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
    1.15  
    1.16  /************************************************/
    1.17  /*            HAP LOG DIRTY SUPPORT             */
     2.1 --- a/xen/arch/x86/mm/p2m.c	Fri Feb 06 10:43:58 2009 +0000
     2.2 +++ b/xen/arch/x86/mm/p2m.c	Fri Feb 06 11:15:28 2009 +0000
     2.3 @@ -89,11 +89,11 @@
     2.4  
     2.5  /* Override macros from asm/page.h to make them work with mfn_t */
     2.6  #undef mfn_to_page
     2.7 -#define mfn_to_page(_m) (frame_table + mfn_x(_m))
     2.8 +#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
     2.9  #undef mfn_valid
    2.10 -#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
    2.11 +#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
    2.12  #undef page_to_mfn
    2.13 -#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
    2.14 +#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
    2.15  
    2.16  
    2.17  /* PTE flags for the various types of p2m entry */
     3.1 --- a/xen/arch/x86/mm/paging.c	Fri Feb 06 10:43:58 2009 +0000
     3.2 +++ b/xen/arch/x86/mm/paging.c	Fri Feb 06 11:15:28 2009 +0000
     3.3 @@ -47,11 +47,11 @@
     3.4  /************************************************/
     3.5  /* Override macros from asm/page.h to make them work with mfn_t */
     3.6  #undef mfn_to_page
     3.7 -#define mfn_to_page(_m) (frame_table + mfn_x(_m))
     3.8 +#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
     3.9  #undef mfn_valid
    3.10 -#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
    3.11 +#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
    3.12  #undef page_to_mfn
    3.13 -#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
    3.14 +#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
    3.15  
    3.16  /* The log-dirty lock.  This protects the log-dirty bitmap from
    3.17   * concurrent accesses (and teardowns, etc).
     4.1 --- a/xen/arch/x86/mm/shadow/private.h	Fri Feb 06 10:43:58 2009 +0000
     4.2 +++ b/xen/arch/x86/mm/shadow/private.h	Fri Feb 06 11:15:28 2009 +0000
     4.3 @@ -474,20 +474,13 @@ mfn_t oos_snapshot_lookup(struct vcpu *v
     4.4   * MFN/page-info handling 
     4.5   */
     4.6  
     4.7 -// Override mfn_to_page from asm/page.h, which was #include'd above,
     4.8 -// in order to make it work with our mfn type.
     4.9 +/* Override macros from asm/page.h to make them work with mfn_t */
    4.10  #undef mfn_to_page
    4.11 -#define mfn_to_page(_m) (frame_table + mfn_x(_m))
    4.12 -
    4.13 -// Override page_to_mfn from asm/page.h, which was #include'd above,
    4.14 -// in order to make it work with our mfn type.
    4.15 +#define mfn_to_page(_m) __mfn_to_page(mfn_x(_m))
    4.16 +#undef mfn_valid
    4.17 +#define mfn_valid(_mfn) __mfn_valid(mfn_x(_mfn))
    4.18  #undef page_to_mfn
    4.19 -#define page_to_mfn(_pg) (_mfn((_pg) - frame_table))
    4.20 -
    4.21 -// Override mfn_valid from asm/page.h, which was #include'd above,
    4.22 -// in order to make it work with our mfn type.
    4.23 -#undef mfn_valid
    4.24 -#define mfn_valid(_mfn) (mfn_x(_mfn) < max_page)
    4.25 +#define page_to_mfn(_pg) _mfn(__page_to_mfn(_pg))
    4.26  
    4.27  /* Override pagetable_t <-> struct page_info conversions to work with mfn_t */
    4.28  #undef pagetable_get_page
     5.1 --- a/xen/include/asm-x86/mm.h	Fri Feb 06 10:43:58 2009 +0000
     5.2 +++ b/xen/include/asm-x86/mm.h	Fri Feb 06 11:15:28 2009 +0000
     5.3 @@ -210,7 +210,8 @@ struct page_info
     5.4  })
     5.5  #else
     5.6  #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
     5.7 -#define is_xen_heap_mfn(mfn) is_xen_heap_page(&frame_table[mfn])
     5.8 +#define is_xen_heap_mfn(mfn) \
     5.9 +    (__mfn_valid(mfn) && is_xen_heap_page(__mfn_to_page(mfn)))
    5.10  #endif
    5.11  
    5.12  #if defined(__i386__)
     6.1 --- a/xen/include/asm-x86/page.h	Fri Feb 06 10:43:58 2009 +0000
     6.2 +++ b/xen/include/asm-x86/page.h	Fri Feb 06 11:15:28 2009 +0000
     6.3 @@ -220,31 +220,47 @@ void copy_page_sse2(void *, const void *
     6.4                               copy_page_sse2(_t, _f) :                   \
     6.5                               (void)memcpy(_t, _f, PAGE_SIZE))
     6.6  
     6.7 -#define mfn_valid(mfn)      ((mfn) < max_page)
     6.8 +#define __mfn_valid(mfn)    ((mfn) < max_page)
     6.9  
    6.10  /* Convert between Xen-heap virtual addresses and machine addresses. */
    6.11  #define __pa(x)             (virt_to_maddr(x))
    6.12  #define __va(x)             (maddr_to_virt(x))
    6.13  
    6.14  /* Convert between Xen-heap virtual addresses and machine frame numbers. */
    6.15 -#define virt_to_mfn(va)     (virt_to_maddr(va) >> PAGE_SHIFT)
    6.16 -#define mfn_to_virt(mfn)    (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
    6.17 +#define __virt_to_mfn(va)   (virt_to_maddr(va) >> PAGE_SHIFT)
    6.18 +#define __mfn_to_virt(mfn)  (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
    6.19  
    6.20  /* Convert between machine frame numbers and page-info structures. */
    6.21 -#define mfn_to_page(mfn)    (frame_table + (mfn))
    6.22 -#define page_to_mfn(pg)     ((unsigned long)((pg) - frame_table))
    6.23 +#define __mfn_to_page(mfn)  (frame_table + (mfn))
    6.24 +#define __page_to_mfn(pg)   ((unsigned long)((pg) - frame_table))
    6.25  
    6.26  /* Convert between machine addresses and page-info structures. */
    6.27 -#define maddr_to_page(ma)   (frame_table + ((ma) >> PAGE_SHIFT))
    6.28 -#define page_to_maddr(pg)   ((paddr_t)((pg) - frame_table) << PAGE_SHIFT)
    6.29 +#define __maddr_to_page(ma) (frame_table + ((ma) >> PAGE_SHIFT))
    6.30 +#define __page_to_maddr(pg) ((paddr_t)((pg) - frame_table) << PAGE_SHIFT)
    6.31  
    6.32  /* Convert between Xen-heap virtual addresses and page-info structures. */
    6.33 -#define virt_to_page(va)    (frame_table + (__pa(va) >> PAGE_SHIFT))
    6.34 -#define page_to_virt(pg)    (maddr_to_virt(page_to_maddr(pg)))
    6.35 +#define __virt_to_page(va)  (frame_table + (__pa(va) >> PAGE_SHIFT))
    6.36 +#define __page_to_virt(pg)  (maddr_to_virt(page_to_maddr(pg)))
    6.37  
    6.38  /* Convert between frame number and address formats.  */
    6.39 -#define pfn_to_paddr(pfn)   ((paddr_t)(pfn) << PAGE_SHIFT)
    6.40 -#define paddr_to_pfn(pa)    ((unsigned long)((pa) >> PAGE_SHIFT))
    6.41 +#define __pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
    6.42 +#define __paddr_to_pfn(pa)  ((unsigned long)((pa) >> PAGE_SHIFT))
    6.43 +
    6.44 +/*
    6.45 + * We define non-underscored wrappers for above conversion functions. These are
    6.46 + * overridden in various source files while underscored versions remain intact.
    6.47 + */
    6.48 +#define mfn_valid(mfn)      __mfn_valid(mfn)
    6.49 +#define virt_to_mfn(va)     __virt_to_mfn(va)
    6.50 +#define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
    6.51 +#define mfn_to_page(mfn)    __mfn_to_page(mfn)
    6.52 +#define page_to_mfn(pg)     __page_to_mfn(pg)
    6.53 +#define maddr_to_page(ma)   __maddr_to_page(ma)
    6.54 +#define page_to_maddr(pg)   __page_to_maddr(pg)
    6.55 +#define virt_to_page(va)    __virt_to_page(va)
    6.56 +#define page_to_virt(pg)    __page_to_virt(pg)
    6.57 +#define pfn_to_paddr(pfn)   __pfn_to_paddr(pfn)
    6.58 +#define paddr_to_pfn(pa)    __paddr_to_pfn(pa)
    6.59  
    6.60  #endif /* !defined(__ASSEMBLY__) */
    6.61