aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-06-12 07:56:40 -0400
committerIngo Molnar <mingo@elte.hu>2008-06-19 07:31:42 -0400
commit59ea746337c69f6a5f1bc4d5e8544b3cbf12f801 (patch)
tree118c9c69eb8a2f6a22c62967ec36288153c87303
parent952f4a0a9b27e6dbd5d32e330b3f609ebfa0b061 (diff)
MM: virtual address debug
Add some (configurable) expensive sanity checking to catch wrong address translations on x86. - create linux/mmdebug.h file to be able include this file in asm headers to not get unsolvable loops in header files - __phys_addr on x86_32 became a function in ioremap.c since PAGE_OFFSET, is_vmalloc_addr and VMALLOC_* non-constasts are undefined if declared in page_32.h - add __phys_addr_const for initializing doublefault_tss.__cr3 Tested on 386, 386pae, x86_64 and x86_64 numa=fake=2. Contains Andi's enable numa virtual address debug patch. Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/doublefault_32.c2
-rw-r--r--arch/x86/mm/ioremap.c31
-rw-r--r--include/asm-x86/mmzone_64.h2
-rw-r--r--include/asm-x86/page_32.h3
-rw-r--r--include/linux/mm.h7
-rw-r--r--include/linux/mmdebug.h18
-rw-r--r--lib/Kconfig.debug9
-rw-r--r--mm/vmalloc.c5
8 files changed, 61 insertions, 16 deletions
diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
index a47798b59f07..395acb12b0d1 100644
--- a/arch/x86/kernel/doublefault_32.c
+++ b/arch/x86/kernel/doublefault_32.c
@@ -66,6 +66,6 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
66 .ds = __USER_DS, 66 .ds = __USER_DS,
67 .fs = __KERNEL_PERCPU, 67 .fs = __KERNEL_PERCPU,
68 68
69 .__cr3 = __pa(swapper_pg_dir) 69 .__cr3 = __phys_addr_const((unsigned long)swapper_pg_dir)
70 } 70 }
71}; 71};
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 2b2bb3f9b683..a78ffef62a2b 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -23,18 +23,26 @@
23 23
24#ifdef CONFIG_X86_64 24#ifdef CONFIG_X86_64
25 25
26unsigned long __phys_addr(unsigned long x) 26static inline int phys_addr_valid(unsigned long addr)
27{ 27{
28 if (x >= __START_KERNEL_map) 28 return addr < (1UL << boot_cpu_data.x86_phys_bits);
29 return x - __START_KERNEL_map + phys_base;
30 return x - PAGE_OFFSET;
31} 29}
32EXPORT_SYMBOL(__phys_addr);
33 30
34static inline int phys_addr_valid(unsigned long addr) 31unsigned long __phys_addr(unsigned long x)
35{ 32{
36 return addr < (1UL << boot_cpu_data.x86_phys_bits); 33 if (x >= __START_KERNEL_map) {
34 x -= __START_KERNEL_map;
35 VIRTUAL_BUG_ON(x >= KERNEL_IMAGE_SIZE);
36 x += phys_base;
37 } else {
38 VIRTUAL_BUG_ON(x < PAGE_OFFSET);
39 x -= PAGE_OFFSET;
40 VIRTUAL_BUG_ON(system_state == SYSTEM_BOOTING ? x > MAXMEM :
41 !phys_addr_valid(x));
42 }
43 return x;
37} 44}
45EXPORT_SYMBOL(__phys_addr);
38 46
39#else 47#else
40 48
@@ -43,6 +51,15 @@ static inline int phys_addr_valid(unsigned long addr)
43 return 1; 51 return 1;
44} 52}
45 53
54unsigned long __phys_addr(unsigned long x)
55{
56 /* VMALLOC_* aren't constants; not available at the boot time */
57 VIRTUAL_BUG_ON(x < PAGE_OFFSET || (system_state != SYSTEM_BOOTING &&
58 is_vmalloc_addr((void *)x)));
59 return x - PAGE_OFFSET;
60}
61EXPORT_SYMBOL(__phys_addr);
62
46#endif 63#endif
47 64
48int page_is_ram(unsigned long pagenr) 65int page_is_ram(unsigned long pagenr)
diff --git a/include/asm-x86/mmzone_64.h b/include/asm-x86/mmzone_64.h
index 594bd0dc1d08..facde3e5314f 100644
--- a/include/asm-x86/mmzone_64.h
+++ b/include/asm-x86/mmzone_64.h
@@ -7,7 +7,7 @@
7 7
8#ifdef CONFIG_NUMA 8#ifdef CONFIG_NUMA
9 9
10#define VIRTUAL_BUG_ON(x) 10#include <linux/mmdebug.h>
11 11
12#include <asm/smp.h> 12#include <asm/smp.h>
13 13
diff --git a/include/asm-x86/page_32.h b/include/asm-x86/page_32.h
index 424e82f8ae27..9159bfb9dcf9 100644
--- a/include/asm-x86/page_32.h
+++ b/include/asm-x86/page_32.h
@@ -64,7 +64,8 @@ typedef struct page *pgtable_t;
64#endif 64#endif
65 65
66#ifndef __ASSEMBLY__ 66#ifndef __ASSEMBLY__
67#define __phys_addr(x) ((x) - PAGE_OFFSET) 67#define __phys_addr_const(x) ((x) - PAGE_OFFSET)
68extern unsigned long __phys_addr(unsigned long);
68#define __phys_reloc_hide(x) RELOC_HIDE((x), 0) 69#define __phys_reloc_hide(x) RELOC_HIDE((x), 0)
69 70
70#ifdef CONFIG_FLATMEM 71#ifdef CONFIG_FLATMEM
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 586a943cab01..3414a8813e97 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -7,6 +7,7 @@
7 7
8#include <linux/gfp.h> 8#include <linux/gfp.h>
9#include <linux/list.h> 9#include <linux/list.h>
10#include <linux/mmdebug.h>
10#include <linux/mmzone.h> 11#include <linux/mmzone.h>
11#include <linux/rbtree.h> 12#include <linux/rbtree.h>
12#include <linux/prio_tree.h> 13#include <linux/prio_tree.h>
@@ -210,12 +211,6 @@ struct inode;
210 */ 211 */
211#include <linux/page-flags.h> 212#include <linux/page-flags.h>
212 213
213#ifdef CONFIG_DEBUG_VM
214#define VM_BUG_ON(cond) BUG_ON(cond)
215#else
216#define VM_BUG_ON(condition) do { } while(0)
217#endif
218
219/* 214/*
220 * Methods to modify the page usage count. 215 * Methods to modify the page usage count.
221 * 216 *
diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h
new file mode 100644
index 000000000000..860ed1a71bbe
--- /dev/null
+++ b/include/linux/mmdebug.h
@@ -0,0 +1,18 @@
1#ifndef LINUX_MM_DEBUG_H
2#define LINUX_MM_DEBUG_H 1
3
4#include <linux/autoconf.h>
5
6#ifdef CONFIG_DEBUG_VM
7#define VM_BUG_ON(cond) BUG_ON(cond)
8#else
9#define VM_BUG_ON(cond) do { } while(0)
10#endif
11
12#ifdef CONFIG_DEBUG_VIRTUAL
13#define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
14#else
15#define VIRTUAL_BUG_ON(cond) do { } while(0)
16#endif
17
18#endif
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index d2099f41aa1e..9d9dc0ddf13a 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -469,6 +469,15 @@ config DEBUG_VM
469 469
470 If unsure, say N. 470 If unsure, say N.
471 471
472config DEBUG_VIRTUAL
473 bool "Debug VM translations"
474 depends on DEBUG_KERNEL && X86
475 help
476 Enable some costly sanity checks in virtual to page code. This can
477 catch mistakes with virt_to_page() and friends.
478
479 If unsure, say N.
480
472config DEBUG_WRITECOUNT 481config DEBUG_WRITECOUNT
473 bool "Debug filesystem writers count" 482 bool "Debug filesystem writers count"
474 depends on DEBUG_KERNEL 483 depends on DEBUG_KERNEL
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 6e45b0f3d125..dc41e9c8ca6f 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -180,6 +180,11 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
180 pmd_t *pmd; 180 pmd_t *pmd;
181 pte_t *ptep, pte; 181 pte_t *ptep, pte;
182 182
183 /* XXX we might need to change this if we add VIRTUAL_BUG_ON for
184 * architectures that do not vmalloc module space */
185 VIRTUAL_BUG_ON(!is_vmalloc_addr(vmalloc_addr) &&
186 !is_module_address(addr));
187
183 if (!pgd_none(*pgd)) { 188 if (!pgd_none(*pgd)) {
184 pud = pud_offset(pgd, addr); 189 pud = pud_offset(pgd, addr);
185 if (!pud_none(*pud)) { 190 if (!pud_none(*pud)) {