mm: check phys_to_xxxx macro on 32bit OS [1/1]
authortao zeng <tao.zeng@amlogic.com>
Tue, 20 Nov 2018 04:14:57 +0000 (12:14 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Mon, 10 Dec 2018 02:52:46 +0000 (18:52 -0800)
PD#SWPL-1909

Problem:
If physical address of a memory location is not in linear mapping
range, then any caller with phys_to_xxxx to get a pointer will
cause bug.

Solution:
Check input address range for phys_to_xxxx to get a BUG output.
This change is used for debug

Verify:
P212

Change-Id: I13bcaa3983e2d730b8d2bc03cd28c62585f49969
Signed-off-by: tao zeng <tao.zeng@amlogic.com>
arch/arm/include/asm/memory.h
arch/arm/mm/mmu.c

index 76cbd9c674dff7815e7f25a293a8b03e80e3b442..5ecadde3b02c93d1f8ee4fda153d5173a16b1f76 100644 (file)
@@ -238,14 +238,27 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
 #define PHYS_OFFSET    PLAT_PHYS_OFFSET
 #define PHYS_PFN_OFFSET        ((unsigned long)(PHYS_OFFSET >> PAGE_SHIFT))
 
+#ifdef CONFIG_AMLOGIC_MODIFY
+extern unsigned long phys_check(phys_addr_t x);
+extern unsigned long virt_check(unsigned long x);
+extern int scheduler_running;
+#endif
 static inline phys_addr_t __virt_to_phys(unsigned long x)
 {
+#ifdef CONFIG_AMLOGIC_MODIFY
+       return virt_check(x);
+#else
        return (phys_addr_t)x - PAGE_OFFSET + PHYS_OFFSET;
+#endif
 }
 
 static inline unsigned long __phys_to_virt(phys_addr_t x)
 {
+#ifdef CONFIG_AMLOGIC_MODIFY
+       return phys_check(x);
+#else
        return x - PHYS_OFFSET + PAGE_OFFSET;
+#endif
 }
 
 #endif
index f7c741358f37ea5dd3ecef6b8852b8454bc91c99..7099113b1aa836b4d07bd0188f7cda0442cfd00b 100644 (file)
@@ -1640,3 +1640,39 @@ void __init paging_init(const struct machine_desc *mdesc)
        empty_zero_page = virt_to_page(zero_page);
        __flush_dcache_page(NULL, empty_zero_page);
 }
+
+#ifdef CONFIG_AMLOGIC_MODIFY
+unsigned long notrace phys_check(phys_addr_t x)
+{
+       unsigned long addr;
+       struct page *page;
+
+       addr = x - PHYS_OFFSET + PAGE_OFFSET;
+       if (scheduler_running) {
+               page = phys_to_page(x);
+
+               /*
+                * if physical address is not in linear mapping range,
+                * then this will cause BUG
+                */
+               if (is_vmalloc_or_module_addr((const void *)addr) ||
+                   PageHighMem(page)) {
+                       pr_err("BAD USING of phys_to_virt, addr:%x, page:%lx\n",
+                               x, page_to_pfn(page));
+                       dump_stack();
+               }
+       }
+       return addr;
+}
+EXPORT_SYMBOL(phys_check);
+
+unsigned long notrace virt_check(unsigned long x)
+{
+       if (scheduler_running && (x >= VMALLOC_START || x <= PAGE_OFFSET)) {
+               pr_err("bad input of virt:%lx\n", x);
+               dump_stack();
+       }
+       return (phys_addr_t)x - PAGE_OFFSET + PHYS_OFFSET;
+}
+EXPORT_SYMBOL(virt_check);
+#endif