diff options
author | Samuel Holland <samuel.holland@sifive.com> | 2024-10-26 10:13:58 -0700 |
---|---|---|
committer | Palmer Dabbelt <palmer@rivosinc.com> | 2025-03-26 15:56:46 -0700 |
commit | e1cf2d009b00fd890dbbcb8b79613ff538732559 (patch) | |
tree | 8e1a2a9d38d27ab5fe96ea4cc42d106bfb1b8e5f | |
parent | ea2bde36a46d5724c1b44d80cc9fafbd73c2ecf9 (diff) | |
download | linux-e1cf2d009b00fd890dbbcb8b79613ff538732559.tar.gz linux-e1cf2d009b00fd890dbbcb8b79613ff538732559.tar.bz2 linux-e1cf2d009b00fd890dbbcb8b79613ff538732559.zip |
riscv: Remove CONFIG_PAGE_OFFSET
The current definition of CONFIG_PAGE_OFFSET is problematic for a couple
of reasons:
1) The value is misleading for normal 64-bit kernels, where it is
overridden at runtime if Sv48 or Sv39 is chosen. This is especially
the case for XIP kernels, which always use Sv39.
2) The option is not user-visible, but for NOMMU kernels it must be a
valid RAM address, and for !RELOCATABLE it must additionally be the
exact address where the kernel is loaded.
Fix both of these by removing the option.
1) For MMU kernels, drop the indirection through Kconfig. Additionally,
for XIP, drop the indirection through kernel_map.
2) For NOMMU kernels, use the user-visible physical RAM base if
provided. Otherwise, force the kernel to be relocatable.
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Jesse Taube <mr.bossman075@gmail.com>
Link: https://lore.kernel.org/r/20241026171441.3047904-7-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
-rw-r--r-- | arch/riscv/Kconfig | 8 | ||||
-rw-r--r-- | arch/riscv/include/asm/page.h | 15 | ||||
-rw-r--r-- | arch/riscv/include/asm/pgtable.h | 2 | ||||
-rw-r--r-- | arch/riscv/mm/init.c | 8 |
4 files changed, 12 insertions, 21 deletions
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7d3d457045ee..551b9a9b243f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -201,6 +201,7 @@ config RISCV select PCI_DOMAINS_GENERIC if PCI select PCI_ECAM if (ACPI && PCI) select PCI_MSI if PCI + select RELOCATABLE if !MMU && !PHYS_RAM_BASE_FIXED select RISCV_ALTERNATIVE if !XIP_KERNEL select RISCV_APLIC select RISCV_IMSIC @@ -288,13 +289,6 @@ config MMU Select if you want MMU-based virtualised addressing space support by paged memory management. If unsure, say 'Y'. -config PAGE_OFFSET - hex - default 0x80000000 if !MMU && RISCV_M_MODE - default 0x80200000 if !MMU - default 0xc0000000 if 32BIT - default 0xff60000000000000 if 64BIT - config KASAN_SHADOW_OFFSET hex depends on KASAN_GENERIC diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 6409fd78ae6f..572a141ddecd 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -26,15 +26,16 @@ */ #ifdef CONFIG_MMU #ifdef CONFIG_64BIT -#define PAGE_OFFSET kernel_map.page_offset -/* - * By default, CONFIG_PAGE_OFFSET value corresponds to SV57 address space so - * define the PAGE_OFFSET value for SV48 and SV39. - */ +#define PAGE_OFFSET_L5 _AC(0xff60000000000000, UL) #define PAGE_OFFSET_L4 _AC(0xffffaf8000000000, UL) #define PAGE_OFFSET_L3 _AC(0xffffffd600000000, UL) +#ifdef CONFIG_XIP_KERNEL +#define PAGE_OFFSET PAGE_OFFSET_L3 #else -#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) +#define PAGE_OFFSET kernel_map.page_offset +#endif /* CONFIG_XIP_KERNEL */ +#else +#define PAGE_OFFSET _AC(0xc0000000, UL) #endif /* CONFIG_64BIT */ #else #define PAGE_OFFSET ((unsigned long)phys_ram_base) @@ -98,7 +99,6 @@ typedef struct page *pgtable_t; #define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base)) struct kernel_mapping { - unsigned long page_offset; unsigned long virt_addr; unsigned long virt_offset; uintptr_t phys_addr; @@ -112,6 +112,7 @@ struct kernel_mapping { uintptr_t xiprom; uintptr_t xiprom_sz; #else + unsigned long page_offset; unsigned long va_kernel_pa_offset; #endif }; diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index babd951222db..ddebdfb4519a 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -15,7 +15,7 @@ #ifdef CONFIG_RELOCATABLE #define KERNEL_LINK_ADDR UL(0) #else -#define KERNEL_LINK_ADDR _AC(CONFIG_PAGE_OFFSET, UL) +#define KERNEL_LINK_ADDR _AC(CONFIG_PHYS_RAM_BASE, UL) #endif #define KERN_VIRT_SIZE (UL(-1)) #else diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index d1494d48a70d..37af6513a50f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -859,6 +859,8 @@ static __init void set_satp_mode(uintptr_t dtb_pa) uintptr_t set_satp_mode_pmd = ((unsigned long)set_satp_mode) & PMD_MASK; u64 satp_mode_cmdline = __pi_set_satp_mode_from_cmdline(dtb_pa); + kernel_map.page_offset = PAGE_OFFSET_L5; + if (satp_mode_cmdline == SATP_MODE_57) { disable_pgtable_l5(); } else if (satp_mode_cmdline == SATP_MODE_48) { @@ -1106,11 +1108,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset; #ifdef CONFIG_XIP_KERNEL -#ifdef CONFIG_64BIT - kernel_map.page_offset = PAGE_OFFSET_L3; -#else - kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL); -#endif kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR; kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom); @@ -1125,7 +1122,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.va_kernel_xip_data_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr + (uintptr_t)&_sdata - (uintptr_t)&_start; #else - kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL); kernel_map.phys_addr = (uintptr_t)(&_start); kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr; kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr; |