]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
MM: virtual address debug
authorJiri Slaby <jirislaby@gmail.com>
Thu, 12 Jun 2008 11:56:40 +0000 (13:56 +0200)
committerIngo Molnar <mingo@elte.hu>
Thu, 19 Jun 2008 11:31:42 +0000 (13:31 +0200)
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>
arch/x86/kernel/doublefault_32.c
arch/x86/mm/ioremap.c
include/asm-x86/mmzone_64.h
include/asm-x86/page_32.h
include/linux/mm.h
include/linux/mmdebug.h [new file with mode: 0644]
lib/Kconfig.debug
mm/vmalloc.c

index a47798b59f07e82205cc6f24d2e4ccc5f0cb6db7..395acb12b0d1bfe1a5e1764d00ef4271b00a7e2f 100644 (file)
@@ -66,6 +66,6 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
                .ds             = __USER_DS,
                .fs             = __KERNEL_PERCPU,
 
-               .__cr3          = __pa(swapper_pg_dir)
+               .__cr3          = __phys_addr_const((unsigned long)swapper_pg_dir)
        }
 };
index 2b2bb3f9b683156b7ef25aac9ccfeca69e90d364..a78ffef62a2bf2f67e5a512e0a847289d75f726f 100644 (file)
 
 #ifdef CONFIG_X86_64
 
-unsigned long __phys_addr(unsigned long x)
+static inline int phys_addr_valid(unsigned long addr)
 {
-       if (x >= __START_KERNEL_map)
-               return x - __START_KERNEL_map + phys_base;
-       return x - PAGE_OFFSET;
+       return addr < (1UL << boot_cpu_data.x86_phys_bits);
 }
-EXPORT_SYMBOL(__phys_addr);
 
-static inline int phys_addr_valid(unsigned long addr)
+unsigned long __phys_addr(unsigned long x)
 {
-       return addr < (1UL << boot_cpu_data.x86_phys_bits);
+       if (x >= __START_KERNEL_map) {
+               x -= __START_KERNEL_map;
+               VIRTUAL_BUG_ON(x >= KERNEL_IMAGE_SIZE);
+               x += phys_base;
+       } else {
+               VIRTUAL_BUG_ON(x < PAGE_OFFSET);
+               x -= PAGE_OFFSET;
+               VIRTUAL_BUG_ON(system_state == SYSTEM_BOOTING ? x > MAXMEM :
+                                       !phys_addr_valid(x));
+       }
+       return x;
 }
+EXPORT_SYMBOL(__phys_addr);
 
 #else
 
@@ -43,6 +51,15 @@ static inline int phys_addr_valid(unsigned long addr)
        return 1;
 }
 
+unsigned long __phys_addr(unsigned long x)
+{
+       /* VMALLOC_* aren't constants; not available at the boot time */
+       VIRTUAL_BUG_ON(x < PAGE_OFFSET || (system_state != SYSTEM_BOOTING &&
+                                       is_vmalloc_addr((void *)x)));
+       return x - PAGE_OFFSET;
+}
+EXPORT_SYMBOL(__phys_addr);
+
 #endif
 
 int page_is_ram(unsigned long pagenr)
index 594bd0dc1d081db7865f80e5a33c4c8ab4f7a718..facde3e5314f23bf4e101e93344bf83898f46f29 100644 (file)
@@ -7,7 +7,7 @@
 
 #ifdef CONFIG_NUMA
 
-#define VIRTUAL_BUG_ON(x)
+#include <linux/mmdebug.h>
 
 #include <asm/smp.h>
 
index 424e82f8ae272888d0a3faa73e23b56454b2fd66..9159bfb9dcf9194000470995354d48ef4b2acec2 100644 (file)
@@ -64,7 +64,8 @@ typedef struct page *pgtable_t;
 #endif
 
 #ifndef __ASSEMBLY__
-#define __phys_addr(x)         ((x) - PAGE_OFFSET)
+#define __phys_addr_const(x)   ((x) - PAGE_OFFSET)
+extern unsigned long __phys_addr(unsigned long);
 #define __phys_reloc_hide(x)   RELOC_HIDE((x), 0)
 
 #ifdef CONFIG_FLATMEM
index 586a943cab018647da208582bc1f19e0dc485f1d..3414a8813e97b0d72b57945d7efb5bd04d7a25e8 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <linux/gfp.h>
 #include <linux/list.h>
+#include <linux/mmdebug.h>
 #include <linux/mmzone.h>
 #include <linux/rbtree.h>
 #include <linux/prio_tree.h>
@@ -210,12 +211,6 @@ struct inode;
  */
 #include <linux/page-flags.h>
 
-#ifdef CONFIG_DEBUG_VM
-#define VM_BUG_ON(cond) BUG_ON(cond)
-#else
-#define VM_BUG_ON(condition) do { } while(0)
-#endif
-
 /*
  * Methods to modify the page usage count.
  *
diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h
new file mode 100644 (file)
index 0000000..860ed1a
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef LINUX_MM_DEBUG_H
+#define LINUX_MM_DEBUG_H 1
+
+#include <linux/autoconf.h>
+
+#ifdef CONFIG_DEBUG_VM
+#define VM_BUG_ON(cond) BUG_ON(cond)
+#else
+#define VM_BUG_ON(cond) do { } while(0)
+#endif
+
+#ifdef CONFIG_DEBUG_VIRTUAL
+#define VIRTUAL_BUG_ON(cond) BUG_ON(cond)
+#else
+#define VIRTUAL_BUG_ON(cond) do { } while(0)
+#endif
+
+#endif
index d2099f41aa1ebe46bc614c7187290f7a32dd941c..9d9dc0ddf13ae0bbfa9bee3373b9b4d6399132d5 100644 (file)
@@ -469,6 +469,15 @@ config DEBUG_VM
 
          If unsure, say N.
 
+config DEBUG_VIRTUAL
+       bool "Debug VM translations"
+       depends on DEBUG_KERNEL && X86
+       help
+         Enable some costly sanity checks in virtual to page code. This can
+         catch mistakes with virt_to_page() and friends.
+
+         If unsure, say N.
+
 config DEBUG_WRITECOUNT
        bool "Debug filesystem writers count"
        depends on DEBUG_KERNEL
index 6e45b0f3d1256e0bdc3a3caffa74597cf96a5138..dc41e9c8ca6fe6f8ba3d187f70a1f26d57919931 100644 (file)
@@ -180,6 +180,11 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
        pmd_t *pmd;
        pte_t *ptep, pte;
 
+       /* XXX we might need to change this if we add VIRTUAL_BUG_ON for
+        * architectures that do not vmalloc module space */
+       VIRTUAL_BUG_ON(!is_vmalloc_addr(vmalloc_addr) &&
+                       !is_module_address(addr));
+
        if (!pgd_none(*pgd)) {
                pud = pud_offset(pgd, addr);
                if (!pud_none(*pud)) {