Skip to contentSkip to conversation

clean up types in pageattr code

PATCH New Dave Hansen 1 participant 1 message Aug 25, 2004 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 clean up types in pageattr code

Here's another one that started off chasing an "unsigned long" passed to __pa() in lookup_adddress(). It's kinda like pulling a loose thread on a sweater.

A couple of functions in arch/i386/mm/pageattr.c pass around virtual addresses as "unsigned long"s and pass them to __pa(). However, only lookup_address() even gets close to doing any arithmetic on them.

I have the feeling these types were all cascaded because do_page_fault() keeps the faulting address in an unsigned long and calls lookup_address(). But, do_page_fault() really is the oddball here because it does so much arithmetic on that address. So, push the cast in to there.

split_large_page() also gets some renamed variables. Can I just point out that I'd support any regulation to forcefully remove the keyboards from anyone who declares 2 variables in the same function called address and addr?

changes to split_large_page():
- rename the variables to more descriptive things than addr
- save some shifts by storing things in pfns to begin with.
- use __get_free_pages() instead of calling alloc_pages() directly
- return virt_to_page() instead of keeping the struct page around (this effectively does a page_to_virt() in __get_free_pages(), and a virt_to_page() later on, but this looks a lot nicer, and it't not any kind of hot path to begin with)

One nice end result is that set_kernel_exec() can take a void* like it wants to naturally and avoid some casts.

This patch depends on the unsigned long casts for the p*_index() functions patch that I just sent.

---

 memhotplug-dave/arch/i386/kernel/smpboot.c |    4 +-
 memhotplug-dave/arch/i386/mm/fault.c       |    2 -
 memhotplug-dave/arch/i386/mm/init.c        |    2 -
 memhotplug-dave/arch/i386/mm/pageattr.c    |   41 +++++++++++++++--------------
 memhotplug-dave/include/asm-i386/pgtable.h |    6 ++--
 5 files changed, 29 insertions(+), 26 deletions(-)
arch/i386/mm/fault.c renamed from arch/i386/mm/fault.c~AA1-lookup_address-cousins-types +1 -1
diff -puN arch/i386/mm/fault.c~AA1-lookup_address-cousins-types arch/i386/mm/fault.c
@@ -442,7 +442,7 @@ no_context:
 
 #ifdef CONFIG_X86_PAE
 	if (error_code & 16) {
-		pte_t *pte = lookup_address(address);
+		pte_t *pte = lookup_address((void *)address);
 
 		if (pte && pte_present(*pte) && !pte_exec_kernel(*pte))
 			printk(KERN_CRIT "kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n", current->uid);

diff -puN arch/i386/mm/pgtable.c~AA1-lookup_address-cousins-types arch/i386/mm/pgtable.c

arch/i386/mm/init.c renamed from arch/i386/mm/init.c~AA1-lookup_address-cousins-types +1 -1
diff -puN arch/i386/mm/init.c~AA1-lookup_address-cousins-types arch/i386/mm/init.c
@@ -478,7 +478,7 @@ static void __init set_nx(void)
  * Enables/disables executability of a given kernel page and
  * returns the previous setting.
  */
-int __init set_kernel_exec(unsigned long vaddr, int enable)
+int __init set_kernel_exec(void *vaddr, int enable)
 {
 	pte_t *pte;
 	int ret = 1;
arch/i386/mm/pageattr.c renamed from arch/i386/mm/pageattr.c~AA1-lookup_address-cousins-types +22 -19

84 lines not on this page · raw message

diff -puN arch/x86_64/kernel/early_printk.c~AA1-lookup_address-cousins-types arch/x86_64/kernel/early_printk.c diff -L include/linux/nonlinear.h -puN /dev/null /dev/null

include/asm-i386/pgtable.h renamed from include/asm-i386/pgtable.h~AA1-lookup_address-cousins-types +3 -3
diff -puN include/asm-i386/pgtable.h~AA1-lookup_address-cousins-types include/asm-i386/pgtable.h
@@ -350,7 +350,7 @@ static inline pte_t pte_modify(pte_t pte
  * NOTE: the return type is pte_t but if the pmd is PSE then we return it
  * as a pte too.
  */
-extern pte_t *lookup_address(unsigned long address);
+extern pte_t *lookup_address(void *address);
 
 /*
  * Make a given kernel text page executable/non-executable.
@@ -359,9 +359,9 @@ extern pte_t *lookup_address(unsigned lo
  * NOTE: this is an __init function for security reasons.
  */
 #ifdef CONFIG_X86_PAE
- extern int set_kernel_exec(unsigned long vaddr, int enable);
+ extern int set_kernel_exec(void *vaddr, int enable);
 #else
- static inline int set_kernel_exec(unsigned long vaddr, int enable) { return 0;}
+ static inline int set_kernel_exec(void *vaddr, int enable) { return 0;}
 #endif
 
 #if defined(CONFIG_HIGHPTE)

diff -puN include/asm-i386/page.h~AA1-lookup_address-cousins-types include/asm-i386/page.h diff -puN mm/slab.c~AA1-lookup_address-cousins-types mm/slab.c
diff -L mm/nonlinear.c -puN /dev/null /dev/null
diff -L mm/memory_hotplug.c -puN /dev/null /dev/null
diff -puN arch/i386/kernel/sysenter.c~AA1-lookup_address-cousins-types arch/i386/kernel/sysenter.c

arch/i386/kernel/smpboot.c renamed from arch/i386/kernel/smpboot.c~AA1-lookup_address-cousins-types +2 -2
diff -puN arch/i386/kernel/smpboot.c~AA1-lookup_address-cousins-types arch/i386/kernel/smpboot.c
@@ -122,7 +122,7 @@ void __init smp_alloc_memory(void)
 	/*
 	 * Make the SMP trampoline executable:
 	 */
-	trampoline_exec = set_kernel_exec((unsigned long)trampoline_base, 1);
+	trampoline_exec = set_kernel_exec(trampoline_base, 1);
 }
 
 /*
@@ -1249,7 +1249,7 @@ void __init smp_cpus_done(unsigned int m
 	/*
 	 * Disable executability of the SMP trampoline:
 	 */
-	set_kernel_exec((unsigned long)trampoline_base, trampoline_exec);
+	set_kernel_exec(trampoline_base, trampoline_exec);
 }
 
 void __init smp_intr_init(void)

_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>