]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
riscv: remove limit on the size of read-only section for XIP kernel
authorNam Cao <namcao@linutronix.de>
Fri, 7 Jun 2024 20:22:13 +0000 (22:22 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 12 Sep 2024 14:23:02 +0000 (07:23 -0700)
XIP_OFFSET is the hard-coded offset of writable data section within the
kernel.

By hard-coding this value, the read-only section of the kernel (which is
placed before the writable data section) is restricted in size. This causes
build failures if the kernel gets too big [1].

Remove this limit.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202404211031.J6l2AfJk-lkp@intel.com [1]
Signed-off-by: Nam Cao <namcao@linutronix.de>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/3bf3a77be10ebb0d8086c028500baa16e7a8e648.1717789719.git.namcao@linutronix.de
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/pgtable.h
arch/riscv/include/asm/set_memory.h
arch/riscv/kernel/vmlinux-xip.lds.S

index 6e16ee77619f15bc25bbf84a5d6d830615db2d12..ede2f921967c088fbf95d84071aa7ae63755d1ec 100644 (file)
 
 #endif
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET             SZ_32M
-#define XIP_OFFSET_MASK                (SZ_32M - 1)
-#else
-#define XIP_OFFSET             0
-#endif
-
 #ifndef __ASSEMBLY__
 
 #include <asm/page.h>
index ec11001c3fe04223e3417161ca5468d29590d092..ab92fc84e1fc9e67bbaa286343af618a6c79ee4e 100644 (file)
@@ -46,7 +46,7 @@ bool kernel_page_present(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_STRICT_KERNEL_RWX
+#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_XIP_KERNEL)
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)
 #else
index 8c3daa1b05313af6b35311be22b7c8de3515633d..a7611789bad5bf8b5c9d5fb18ff3c8fe2695495f 100644 (file)
@@ -14,6 +14,7 @@
 #include <asm/page.h>
 #include <asm/cache.h>
 #include <asm/thread_info.h>
+#include <asm/set_memory.h>
 
 OUTPUT_ARCH(riscv)
 ENTRY(_start)
@@ -65,10 +66,10 @@ SECTIONS
  * From this point, stuff is considered writable and will be copied to RAM
  */
        __data_loc = ALIGN(PAGE_SIZE);          /* location in file */
-       . = KERNEL_LINK_ADDR + XIP_OFFSET;      /* location in memory */
+       . = ALIGN(SECTION_ALIGN);               /* location in memory */
 
 #undef LOAD_OFFSET
-#define LOAD_OFFSET (KERNEL_LINK_ADDR + XIP_OFFSET - (__data_loc & XIP_OFFSET_MASK))
+#define LOAD_OFFSET (KERNEL_LINK_ADDR + _sdata - __data_loc)
 
        _sdata = .;                     /* Start of data section */
        _data = .;