diff mbox series

riscv: Correct the MODULES_VADDR

Message ID 20230801111014.1432679-1-suagrfillet@gmail.com (mailing list archive)
State Changes Requested
Headers show
Series riscv: Correct the MODULES_VADDR | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next at HEAD 471aba2e4760
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 4 and now 4
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 2786 this patch: 2786
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig success Errors and warnings before: 15671 this patch: 15671
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Song Shuai Aug. 1, 2023, 11:10 a.m. UTC
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)

Signed-off-by: Song Shuai <suagrfillet@gmail.com>
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexandre Ghiti Aug. 1, 2023, 12:05 p.m. UTC | #1
Hi Song,

On Tue, Aug 1, 2023 at 1:10 PM Song Shuai <suagrfillet@gmail.com> wrote:
>
> 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)
>
> Signed-off-by: Song Shuai <suagrfillet@gmail.com>
> ---
>  arch/riscv/include/asm/pgtable.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index 75970ee2bda2..7c57e17fc758 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -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
>
>  /*
> --
> 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.
Guo Ren Aug. 1, 2023, 11:20 p.m. UTC | #2
On Tue, Aug 1, 2023 at 8:05 AM Alexandre Ghiti <alexghiti@rivosinc.com> wrote:
>
> Hi Song,
>
> On Tue, Aug 1, 2023 at 1:10 PM Song Shuai <suagrfillet@gmail.com> wrote:
> >
> > 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)
> >
> > Signed-off-by: Song Shuai <suagrfillet@gmail.com>
> > ---
> >  arch/riscv/include/asm/pgtable.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> > index 75970ee2bda2..7c57e17fc758 100644
> > --- a/arch/riscv/include/asm/pgtable.h
> > +++ b/arch/riscv/include/asm/pgtable.h
> > @@ -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
> >
> >  /*
> > --
> > 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.
Song Shuai Aug. 2, 2023, 1:05 a.m. UTC | #3
Guo Ren <guoren@kernel.org> 于2023年8月1日周二 23:20写道:
>
> On Tue, Aug 1, 2023 at 8:05 AM Alexandre Ghiti <alexghiti@rivosinc.com> wrote:
> >
> > Hi Song,
> >
> > On Tue, Aug 1, 2023 at 1:10 PM Song Shuai <suagrfillet@gmail.com> wrote:
> > >
> > > 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)
> > >
> > > Signed-off-by: Song Shuai <suagrfillet@gmail.com>
> > > ---
> > >  arch/riscv/include/asm/pgtable.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> > > index 75970ee2bda2..7c57e17fc758 100644
> > > --- a/arch/riscv/include/asm/pgtable.h
> > > +++ b/arch/riscv/include/asm/pgtable.h
> > > @@ -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
> > >
> > >  /*
> > > --
> > > 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.
> --
> Best Regards
>  Guo Ren
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 75970ee2bda2..7c57e17fc758 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -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
 
 /*