[PATCH] [3/8] CPA: Test the correct mapping alias on x86-64

From: Andi Kleen
Date: Mon Feb 11 2008 - 04:36:00 EST



static_protections previously would test against the x86-64 kernel mapping
twice. First against the unchanged symbol directly from the linker (which
always points into the kernel mapping) and then again it would manually
relocate the address into the kernel mapping and test again.

This patch reverses the second test instead to test against the direct mapping
(low) aliases virtual addresses which was probably intended in the first place.

Simply use __pa and __va for that.

This also allows to drop an ifdef because it will work both on 32bit and 64bit.

Signed-off-by: Andi Kleen <ak@xxxxxxx>

---
arch/x86/mm/pageattr.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)

Index: linux/arch/x86/mm/pageattr.c
===================================================================
--- linux.orig/arch/x86/mm/pageattr.c
+++ linux/arch/x86/mm/pageattr.c
@@ -128,17 +128,9 @@ static void cpa_flush_range(unsigned lon
#define HIGH_MAP_START __START_KERNEL_map
#define HIGH_MAP_END (__START_KERNEL_map + KERNEL_TEXT_SIZE)

-
-/*
- * Converts a virtual address to a X86-64 highmap address
- */
-static unsigned long virt_to_highmap(void *address)
+static unsigned long virt_to_direct(void *address)
{
-#ifdef CONFIG_X86_64
- return __pa((unsigned long)address) + HIGH_MAP_START - phys_base;
-#else
- return (unsigned long)address;
-#endif
+ return (unsigned long)__va(__pa(address));
}

/*
@@ -165,9 +157,9 @@ static inline pgprot_t static_protection
if (within(address, (unsigned long)_text, (unsigned long)_etext))
pgprot_val(forbidden) |= _PAGE_NX;
/*
- * Do the same for the x86-64 high kernel mapping
+ * Do the same for the direct map alias of the x86-64 text mapping
*/
- if (within(address, virt_to_highmap(_text), virt_to_highmap(_etext)))
+ if (within(address, virt_to_direct(_text), virt_to_direct(_etext)))
pgprot_val(forbidden) |= _PAGE_NX;

/* The .rodata section needs to be read-only */
@@ -175,10 +167,10 @@ static inline pgprot_t static_protection
(unsigned long)__end_rodata))
pgprot_val(forbidden) |= _PAGE_RW;
/*
- * Do the same for the x86-64 high kernel mapping
+ * Do the same for the direct map alias of the x86-64 text mapping
*/
- if (within(address, virt_to_highmap(__start_rodata),
- virt_to_highmap(__end_rodata)))
+ if (within(address, virt_to_direct(__start_rodata),
+ virt_to_direct(__end_rodata)))
pgprot_val(forbidden) |= _PAGE_RW;

prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/