diff mbox series

[-fixes,1/4] riscv: Fix is_linear_mapping with recent move of KASAN region

Message ID 20220218133513.1762929-2-alexandre.ghiti@canonical.com (mailing list archive)
State New, archived
Headers show
Series Fixes KASAN and other along the way | expand

Commit Message

Alexandre Ghiti Feb. 18, 2022, 1:35 p.m. UTC
KASAN region was recently moved between the linear mapping and the
kernel mapping, is_linear_mapping used to check the validity of an
address by using the start of the kernel mapping, which is now wrong.

Fix this by using the maximum size of the physical memory.

Fixes: f7ae02333d13 ("riscv: Move KASAN mapping next to the kernel mapping")
Signed-off-by: Alexandre Ghiti <alexandre.ghiti@canonical.com>
---
 arch/riscv/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

kernel test robot Feb. 20, 2022, 5:55 p.m. UTC | #1
Hi Alexandre,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.17-rc4 next-20220217]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Alexandre-Ghiti/Fixes-KASAN-and-other-along-the-way/20220220-181628
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 4f12b742eb2b3a850ac8be7dc4ed52976fc6cb0b
config: riscv-nommu_virt_defconfig (https://download.01.org/0day-ci/archive/20220221/202202210123.ilPycxXe-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/0day-ci/linux/commit/de8a909a9eabf9066802a3396b7009cbf4fa4369
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Alexandre-Ghiti/Fixes-KASAN-and-other-along-the-way/20220220-181628
        git checkout de8a909a9eabf9066802a3396b7009cbf4fa4369
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv prepare

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/riscv/kernel/asm-offsets.c:10:
>> include/linux/mm.h:837:22: error: use of undeclared identifier 'KERN_VIRT_SIZE'; did you mean 'KERN_VERSION'?
           struct page *page = virt_to_page(x);
                               ^
   arch/riscv/include/asm/page.h:165:42: note: expanded from macro 'virt_to_page'
   #define virt_to_page(vaddr)     (pfn_to_page(virt_to_pfn(vaddr)))
                                                ^
   arch/riscv/include/asm/page.h:162:41: note: expanded from macro 'virt_to_pfn'
   #define virt_to_pfn(vaddr)      (phys_to_pfn(__pa(vaddr)))
                                                ^
   arch/riscv/include/asm/page.h:156:18: note: expanded from macro '__pa'
   #define __pa(x)         __virt_to_phys((unsigned long)(x))
                           ^
   arch/riscv/include/asm/page.h:151:27: note: expanded from macro '__virt_to_phys'
   #define __virt_to_phys(x)       __va_to_pa_nodebug(x)
                                   ^
   arch/riscv/include/asm/page.h:143:2: note: expanded from macro '__va_to_pa_nodebug'
           is_linear_mapping(_x) ?                                                 \
           ^
   arch/riscv/include/asm/page.h:122:75: note: expanded from macro 'is_linear_mapping'
           ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE))
                                                                                    ^
   include/uapi/linux/sysctl.h:88:2: note: 'KERN_VERSION' declared here
           KERN_VERSION=4,         /* string: compile time info */
           ^
   In file included from arch/riscv/kernel/asm-offsets.c:10:
   include/linux/mm.h:844:22: error: use of undeclared identifier 'KERN_VIRT_SIZE'; did you mean 'KERN_VERSION'?
           struct page *page = virt_to_page(x);
                               ^
   arch/riscv/include/asm/page.h:165:42: note: expanded from macro 'virt_to_page'
   #define virt_to_page(vaddr)     (pfn_to_page(virt_to_pfn(vaddr)))
                                                ^
   arch/riscv/include/asm/page.h:162:41: note: expanded from macro 'virt_to_pfn'
   #define virt_to_pfn(vaddr)      (phys_to_pfn(__pa(vaddr)))
                                                ^
   arch/riscv/include/asm/page.h:156:18: note: expanded from macro '__pa'
   #define __pa(x)         __virt_to_phys((unsigned long)(x))
                           ^
   arch/riscv/include/asm/page.h:151:27: note: expanded from macro '__virt_to_phys'
   #define __virt_to_phys(x)       __va_to_pa_nodebug(x)
                                   ^
   arch/riscv/include/asm/page.h:143:2: note: expanded from macro '__va_to_pa_nodebug'
           is_linear_mapping(_x) ?                                                 \
           ^
   arch/riscv/include/asm/page.h:122:75: note: expanded from macro 'is_linear_mapping'
           ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE))
                                                                                    ^
   include/uapi/linux/sysctl.h:88:2: note: 'KERN_VERSION' declared here
           KERN_VERSION=4,         /* string: compile time info */
           ^
   2 errors generated.
   make[2]: *** [scripts/Makefile.build:121: arch/riscv/kernel/asm-offsets.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1191: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:219: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +837 include/linux/mm.h

70b50f94f1644e Andrea Arcangeli   2011-11-02  834  
b49af68ff9fc5d Christoph Lameter  2007-05-06  835  static inline struct page *virt_to_head_page(const void *x)
b49af68ff9fc5d Christoph Lameter  2007-05-06  836  {
b49af68ff9fc5d Christoph Lameter  2007-05-06 @837  	struct page *page = virt_to_page(x);
ccaafd7fd039ae Joonsoo Kim        2015-02-10  838  
1d798ca3f16437 Kirill A. Shutemov 2015-11-06  839  	return compound_head(page);
b49af68ff9fc5d Christoph Lameter  2007-05-06  840  }
b49af68ff9fc5d Christoph Lameter  2007-05-06  841  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h
index 160e3a1e8f8b..004372f8da54 100644
--- a/arch/riscv/include/asm/page.h
+++ b/arch/riscv/include/asm/page.h
@@ -119,7 +119,7 @@  extern phys_addr_t phys_ram_base;
 	((x) >= kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_map.size))
 
 #define is_linear_mapping(x)	\
-	((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < kernel_map.virt_addr))
+	((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE))
 
 #define linear_mapping_pa_to_va(x)	((void *)((unsigned long)(x) + kernel_map.va_pa_offset))
 #define kernel_mapping_pa_to_va(y)	({						\