Skip to contentSkip to conversation

riscv: Correct the MODULES_VADDR

PATCH In review Song Shuai 3 participants 4 messages Aug 1, 2023 – Aug 2, 2023 RISC-V

lore
Share & tools
lore

Song Shuai

author
#0 lore raw

PATCH 1/1 riscv: Correct the MODULES_VADDR

As Documentation/riscv/vm-layout.rst describes, the 2G-sized "modules, BPF" area should lie right before the "kernel" area. But the current definition of MODULES_VADDR isn't consistent with that, so correct it.

Before this patch, the size of "modules" from print_vm_layout() is not 2G.

[    0.000000]      modules : 0xffffffff2ff2f000 - 0xffffffffae600000 (2022 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffae600000 - 0xffffffffffffffff (1305 MB)

After this patch, the size is 2G.

[    0.000000]      modules : 0xffffffff3a000000 - 0xffffffffba000000 (2048 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffba000000 - 0xffffffffffffffff (1119 MB)
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +1 -1
index 75970ee2bda2..7c57e17fc758 100644
@@ -53,8 +53,8 @@
 #ifdef CONFIG_64BIT
 /* This is used to define the end of the KASAN shadow region */
 #define MODULES_LOWEST_VADDR	(KERNEL_LINK_ADDR - SZ_2G)
-#define MODULES_VADDR		(PFN_ALIGN((unsigned long)&_end) - SZ_2G)
 #define MODULES_END		(PFN_ALIGN((unsigned long)&_start))
+#define MODULES_VADDR		(MODULES_END - SZ_2G)
 #endif
 
 /*
Signature · 7 lines
2.20.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

Hi Song,

Quoted 37 lines · Song Shuai

As Documentation/riscv/vm-layout.rst describes, the 2G-sized "modules, BPF" area should lie right before the "kernel" area. But the current definition of MODULES_VADDR isn't consistent with that, so correct it.

Before this patch, the size of "modules" from print_vm_layout() is not 2G.

[    0.000000]      modules : 0xffffffff2ff2f000 - 0xffffffffae600000 (2022 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffae600000 - 0xffffffffffffffff (1305 MB)

After this patch, the size is 2G.

[    0.000000]      modules : 0xffffffff3a000000 - 0xffffffffba000000 (2048 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffba000000 - 0xffffffffffffffff (1119 MB)
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +1 -2
index 75970ee2bda2..7c57e17fc758 100644
@@ -53,8 +53,8 @@
 #ifdef CONFIG_64BIT
 /* This is used to define the end of the KASAN shadow region */
 #define MODULES_LOWEST_VADDR   (KERNEL_LINK_ADDR - SZ_2G)
-#define MODULES_VADDR          (PFN_ALIGN((unsigned long)&_end) - SZ_2G)
 #define MODULES_END            (PFN_ALIGN((unsigned long)&_start))
+#define MODULES_VADDR          (MODULES_END - SZ_2G)
 #endif
 
 /*
--
Quoted 2 lines

2.20.1

The documentation is approximative, the modules must stay within a 2GB window to *all* the kernel symbols, hence the __end - 2G, not __start.

#2 lore raw
Quoted 39 lines · Alexandre Ghiti

Hi Song,

Quoted 35 lines · Song Shuai

As Documentation/riscv/vm-layout.rst describes, the 2G-sized "modules, BPF" area should lie right before the "kernel" area. But the current definition of MODULES_VADDR isn't consistent with that, so correct it.

Before this patch, the size of "modules" from print_vm_layout() is not 2G.

[    0.000000]      modules : 0xffffffff2ff2f000 - 0xffffffffae600000 (2022 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffae600000 - 0xffffffffffffffff (1305 MB)

After this patch, the size is 2G.

[    0.000000]      modules : 0xffffffff3a000000 - 0xffffffffba000000 (2048 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffba000000 - 0xffffffffffffffff (1119 MB)
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +1 -1
index 75970ee2bda2..7c57e17fc758 100644
@@ -53,8 +53,8 @@
 #ifdef CONFIG_64BIT
 /* This is used to define the end of the KASAN shadow region */
 #define MODULES_LOWEST_VADDR   (KERNEL_LINK_ADDR - SZ_2G)
-#define MODULES_VADDR          (PFN_ALIGN((unsigned long)&_end) - SZ_2G)
 #define MODULES_END            (PFN_ALIGN((unsigned long)&_start))
+#define MODULES_VADDR          (MODULES_END - SZ_2G)
 #endif
 
Quoted 7 lines
Quoted 4 lines
arch/riscv/include/asm/pgtable.h +0 -1
 /*
--

2.20.1

The documentation is approximative, the modules must stay within a 2GB window to *all* the kernel symbols, hence the __end - 2G, not __start.

Thus, the ftrace detour trampoline could cover all kernel symbols.

Signature · 2 lines
Best Regards
 Guo Ren
author
#3 lore raw
Quoted 41 lines · Guo Ren <[email protected]> 于2023年8月1日周二 23:20写道:
Quoted 39 lines · Alexandre Ghiti

Hi Song,

Quoted 35 lines · Song Shuai

As Documentation/riscv/vm-layout.rst describes, the 2G-sized "modules, BPF" area should lie right before the "kernel" area. But the current definition of MODULES_VADDR isn't consistent with that, so correct it.

Before this patch, the size of "modules" from print_vm_layout() is not 2G.

[    0.000000]      modules : 0xffffffff2ff2f000 - 0xffffffffae600000 (2022 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffae600000 - 0xffffffffffffffff (1305 MB)

After this patch, the size is 2G.

[    0.000000]      modules : 0xffffffff3a000000 - 0xffffffffba000000 (2048 MB)
[    0.000000]       lowmem : 0xff60000000000000 - 0xff60000040000000 (1024 MB)
[    0.000000]       kernel : 0xffffffffba000000 - 0xffffffffffffffff (1119 MB)
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/pgtable.h +1 -1
index 75970ee2bda2..7c57e17fc758 100644
@@ -53,8 +53,8 @@
 #ifdef CONFIG_64BIT
 /* This is used to define the end of the KASAN shadow region */
 #define MODULES_LOWEST_VADDR   (KERNEL_LINK_ADDR - SZ_2G)
-#define MODULES_VADDR          (PFN_ALIGN((unsigned long)&_end) - SZ_2G)
 #define MODULES_END            (PFN_ALIGN((unsigned long)&_start))
+#define MODULES_VADDR          (MODULES_END - SZ_2G)
 #endif
 
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
arch/riscv/include/asm/pgtable.h +0 -1
 /*
--

2.20.1

The documentation is approximative, the modules must stay within a 2GB window to *all* the kernel symbols, hence the __end - 2G, not __start.

Thus, the ftrace detour trampoline could cover all kernel symbols.

That's another view to help me understand the definition of MODULES_VADDR,Thanks.

Quoted 3 lines

--
Best Regards
Guo Ren

Signature · 7 lines
Thanks,
Song

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv