Jan Beulich
2008-May-15 12:54 UTC
[Xen-devel] [PATCH] linux/x86: utilize lookup_address() for virt_to_ptep()
As usual, written and tested on 2.6.25.2 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich <jbeulich@novell.com> Index: head-2008-05-08/arch/x86_64/mm/pageattr-xen.c ==================================================================--- head-2008-05-08.orig/arch/x86_64/mm/pageattr-xen.c 2008-05-15 13:44:37.000000000 +0200 +++ head-2008-05-08/arch/x86_64/mm/pageattr-xen.c 2008-05-15 14:44:59.000000000 +0200 @@ -276,7 +276,7 @@ } #endif /* CONFIG_XEN */ -static inline pte_t *lookup_address(unsigned long address) +pte_t *lookup_address(unsigned long address) { pgd_t *pgd = pgd_offset_k(address); pud_t *pud; Index: head-2008-05-08/include/asm-i386/mach-xen/asm/pgtable.h ==================================================================--- head-2008-05-08.orig/include/asm-i386/mach-xen/asm/pgtable.h 2008-05-15 13:44:37.000000000 +0200 +++ head-2008-05-08/include/asm-i386/mach-xen/asm/pgtable.h 2008-05-15 13:38:59.000000000 +0200 @@ -477,19 +477,16 @@ void make_page_writable(void *va, unsign void make_pages_readonly(void *va, unsigned int nr, unsigned int feature); void make_pages_writable(void *va, unsigned int nr, unsigned int feature); -#define virt_to_ptep(__va) \ -({ \ - pgd_t *__pgd = pgd_offset_k((unsigned long)(__va)); \ - pud_t *__pud = pud_offset(__pgd, (unsigned long)(__va)); \ - pmd_t *__pmd = pmd_offset(__pud, (unsigned long)(__va)); \ - pte_offset_kernel(__pmd, (unsigned long)(__va)); \ -}) - -#define arbitrary_virt_to_machine(__va) \ -({ \ - maddr_t m = (maddr_t)pte_mfn(*virt_to_ptep(__va)) << PAGE_SHIFT;\ - m | ((unsigned long)(__va) & (PAGE_SIZE-1)); \ -}) +#define virt_to_ptep(va) \ +({ \ + pte_t *__ptep = lookup_address((unsigned long)(va)); \ + BUG_ON(!__ptep || !pte_present(*__ptep)); \ + __ptep; \ +}) + +#define arbitrary_virt_to_machine(va) \ + (((maddr_t)pte_mfn(*virt_to_ptep(va)) << PAGE_SHIFT) \ + | ((unsigned long)(va) & (PAGE_SIZE - 1))) #endif /* !__ASSEMBLY__ */ Index: head-2008-05-08/include/asm-x86_64/mach-xen/asm/pgtable.h ==================================================================--- head-2008-05-08.orig/include/asm-x86_64/mach-xen/asm/pgtable.h 2008-05-15 13:44:37.000000000 +0200 +++ head-2008-05-08/include/asm-x86_64/mach-xen/asm/pgtable.h 2008-05-15 13:38:29.000000000 +0200 @@ -18,19 +18,18 @@ extern void xen_init_pt(void); -#define virt_to_ptep(__va) \ -({ \ - pgd_t *__pgd = pgd_offset_k((unsigned long)(__va)); \ - pud_t *__pud = pud_offset(__pgd, (unsigned long)(__va)); \ - pmd_t *__pmd = pmd_offset(__pud, (unsigned long)(__va)); \ - pte_offset_kernel(__pmd, (unsigned long)(__va)); \ -}) - -#define arbitrary_virt_to_machine(__va) \ -({ \ - maddr_t m = (maddr_t)pte_mfn(*virt_to_ptep(__va)) << PAGE_SHIFT;\ - m | ((unsigned long)(__va) & (PAGE_SIZE-1)); \ -}) +extern pte_t *lookup_address(unsigned long address); + +#define virt_to_ptep(va) \ +({ \ + pte_t *__ptep = lookup_address((unsigned long)(va)); \ + BUG_ON(!__ptep || !pte_present(*__ptep)); \ + __ptep; \ +}) + +#define arbitrary_virt_to_machine(va) \ + (((maddr_t)pte_mfn(*virt_to_ptep(va)) << PAGE_SHIFT) \ + | ((unsigned long)(va) & (PAGE_SIZE - 1))) #endif extern pud_t level3_kernel_pgt[512]; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel