Skip to content

Commit e1cf2d0

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
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>
1 parent ea2bde3 commit e1cf2d0

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ config RISCV
201201
select PCI_DOMAINS_GENERIC if PCI
202202
select PCI_ECAM if (ACPI && PCI)
203203
select PCI_MSI if PCI
204+
select RELOCATABLE if !MMU && !PHYS_RAM_BASE_FIXED
204205
select RISCV_ALTERNATIVE if !XIP_KERNEL
205206
select RISCV_APLIC
206207
select RISCV_IMSIC
@@ -288,13 +289,6 @@ config MMU
288289
Select if you want MMU-based virtualised addressing space
289290
support by paged memory management. If unsure, say 'Y'.
290291

291-
config PAGE_OFFSET
292-
hex
293-
default 0x80000000 if !MMU && RISCV_M_MODE
294-
default 0x80200000 if !MMU
295-
default 0xc0000000 if 32BIT
296-
default 0xff60000000000000 if 64BIT
297-
298292
config KASAN_SHADOW_OFFSET
299293
hex
300294
depends on KASAN_GENERIC

arch/riscv/include/asm/page.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
*/
2727
#ifdef CONFIG_MMU
2828
#ifdef CONFIG_64BIT
29-
#define PAGE_OFFSET kernel_map.page_offset
30-
/*
31-
* By default, CONFIG_PAGE_OFFSET value corresponds to SV57 address space so
32-
* define the PAGE_OFFSET value for SV48 and SV39.
33-
*/
29+
#define PAGE_OFFSET_L5 _AC(0xff60000000000000, UL)
3430
#define PAGE_OFFSET_L4 _AC(0xffffaf8000000000, UL)
3531
#define PAGE_OFFSET_L3 _AC(0xffffffd600000000, UL)
32+
#ifdef CONFIG_XIP_KERNEL
33+
#define PAGE_OFFSET PAGE_OFFSET_L3
3634
#else
37-
#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
35+
#define PAGE_OFFSET kernel_map.page_offset
36+
#endif /* CONFIG_XIP_KERNEL */
37+
#else
38+
#define PAGE_OFFSET _AC(0xc0000000, UL)
3839
#endif /* CONFIG_64BIT */
3940
#else
4041
#define PAGE_OFFSET ((unsigned long)phys_ram_base)
@@ -98,7 +99,6 @@ typedef struct page *pgtable_t;
9899
#define ARCH_PFN_OFFSET (PFN_DOWN((unsigned long)phys_ram_base))
99100

100101
struct kernel_mapping {
101-
unsigned long page_offset;
102102
unsigned long virt_addr;
103103
unsigned long virt_offset;
104104
uintptr_t phys_addr;
@@ -112,6 +112,7 @@ struct kernel_mapping {
112112
uintptr_t xiprom;
113113
uintptr_t xiprom_sz;
114114
#else
115+
unsigned long page_offset;
115116
unsigned long va_kernel_pa_offset;
116117
#endif
117118
};

arch/riscv/include/asm/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifdef CONFIG_RELOCATABLE
1616
#define KERNEL_LINK_ADDR UL(0)
1717
#else
18-
#define KERNEL_LINK_ADDR _AC(CONFIG_PAGE_OFFSET, UL)
18+
#define KERNEL_LINK_ADDR _AC(CONFIG_PHYS_RAM_BASE, UL)
1919
#endif
2020
#define KERN_VIRT_SIZE (UL(-1))
2121
#else

arch/riscv/mm/init.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ static __init void set_satp_mode(uintptr_t dtb_pa)
859859
uintptr_t set_satp_mode_pmd = ((unsigned long)set_satp_mode) & PMD_MASK;
860860
u64 satp_mode_cmdline = __pi_set_satp_mode_from_cmdline(dtb_pa);
861861

862+
kernel_map.page_offset = PAGE_OFFSET_L5;
863+
862864
if (satp_mode_cmdline == SATP_MODE_57) {
863865
disable_pgtable_l5();
864866
} else if (satp_mode_cmdline == SATP_MODE_48) {
@@ -1106,11 +1108,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
11061108
kernel_map.virt_addr = KERNEL_LINK_ADDR + kernel_map.virt_offset;
11071109

11081110
#ifdef CONFIG_XIP_KERNEL
1109-
#ifdef CONFIG_64BIT
1110-
kernel_map.page_offset = PAGE_OFFSET_L3;
1111-
#else
1112-
kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
1113-
#endif
11141111
kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR;
11151112
kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom);
11161113

@@ -1125,7 +1122,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
11251122
kernel_map.va_kernel_xip_data_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr
11261123
+ (uintptr_t)&_sdata - (uintptr_t)&_start;
11271124
#else
1128-
kernel_map.page_offset = _AC(CONFIG_PAGE_OFFSET, UL);
11291125
kernel_map.phys_addr = (uintptr_t)(&_start);
11301126
kernel_map.size = (uintptr_t)(&_end) - kernel_map.phys_addr;
11311127
kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;

0 commit comments

Comments
 (0)