2021-01-29 19:07:41

by Atish Patra

[permalink] [raw]
Subject: [PATCH 1/3] RISC-V: Fix .init section permission update

.init section permission should only updated to non-execute if
STRICT_KERNEL_RWX is enabled. Otherwise, this will lead to a kernel hang.

Fixes: 19a00869028f ("RISC-V: Protect all kernel sections including init early")

Suggested-by: Geert Uytterhoeven <[email protected]>
Reported-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
---
arch/riscv/kernel/setup.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 3fa3f26dde85..c7c0655dd45b 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -293,6 +293,8 @@ void free_initmem(void)
unsigned long init_begin = (unsigned long)__init_begin;
unsigned long init_end = (unsigned long)__init_end;

- set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+ if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+ set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+
free_initmem_default(POISON_FREE_INITMEM);
}
--
2.25.1


2021-01-29 19:09:58

by Atish Patra

[permalink] [raw]
Subject: [PATCH 3/3] RISC-V: Define MAXPHYSMEM_1GB only for RV32

MAXPHYSMEM_1GB option was added for RV32 because RV32 only supports 1GB
of maximum physical memory. This lead to few compilation errors reported
by kernel test robot which created the following configuration combination
which are not useful but can be configured.

1. MAXPHYSMEM_1GB & RV64
2, MAXPHYSMEM_2GB & RV32

Fixes: e557793799c5 ("RISC-V: Fix maximum allowed phsyical memory for RV32")

Fix this by restricting MAXPHYSMEM_1GB for RV32 and MAXPHYSMEM_2GB only for
RV64.

Reported-by: Randy Dunlap <[email protected]>
Acked-by: Randy Dunlap <[email protected]>
Tested-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Atish Patra <[email protected]>
---
arch/riscv/Kconfig | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index e9e2c1f0a690..e0a34eb5ed3b 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -252,8 +252,10 @@ choice
default MAXPHYSMEM_128GB if 64BIT && CMODEL_MEDANY

config MAXPHYSMEM_1GB
+ depends on 32BIT
bool "1GiB"
config MAXPHYSMEM_2GB
+ depends on 64BIT && CMODEL_MEDLOW
bool "2GiB"
config MAXPHYSMEM_128GB
depends on 64BIT && CMODEL_MEDANY
--
2.25.1

2021-02-03 02:37:02

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH 3/3] RISC-V: Define MAXPHYSMEM_1GB only for RV32

On Fri, 29 Jan 2021 11:00:38 PST (-0800), Atish Patra wrote:
> MAXPHYSMEM_1GB option was added for RV32 because RV32 only supports 1GB
> of maximum physical memory. This lead to few compilation errors reported
> by kernel test robot which created the following configuration combination
> which are not useful but can be configured.
>
> 1. MAXPHYSMEM_1GB & RV64
> 2, MAXPHYSMEM_2GB & RV32
>
> Fixes: e557793799c5 ("RISC-V: Fix maximum allowed phsyical memory for RV32")
>
> Fix this by restricting MAXPHYSMEM_1GB for RV32 and MAXPHYSMEM_2GB only for
> RV64.
>
> Reported-by: Randy Dunlap <[email protected]>
> Acked-by: Randy Dunlap <[email protected]>
> Tested-by: Geert Uytterhoeven <[email protected]>
> Signed-off-by: Atish Patra <[email protected]>
> ---
> arch/riscv/Kconfig | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index e9e2c1f0a690..e0a34eb5ed3b 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -252,8 +252,10 @@ choice
> default MAXPHYSMEM_128GB if 64BIT && CMODEL_MEDANY
>
> config MAXPHYSMEM_1GB
> + depends on 32BIT
> bool "1GiB"
> config MAXPHYSMEM_2GB
> + depends on 64BIT && CMODEL_MEDLOW
> bool "2GiB"
> config MAXPHYSMEM_128GB
> depends on 64BIT && CMODEL_MEDANY

Ah, I guess here's the patch :). This is on fixes.

Thanks!

2021-02-03 02:38:40

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH 1/3] RISC-V: Fix .init section permission update

On Fri, 29 Jan 2021 11:00:36 PST (-0800), Atish Patra wrote:
> .init section permission should only updated to non-execute if
> STRICT_KERNEL_RWX is enabled. Otherwise, this will lead to a kernel hang.
>
> Fixes: 19a00869028f ("RISC-V: Protect all kernel sections including init early")
>
> Suggested-by: Geert Uytterhoeven <[email protected]>
> Reported-by: Geert Uytterhoeven <[email protected]>
> Signed-off-by: Atish Patra <[email protected]>
> ---
> arch/riscv/kernel/setup.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
> index 3fa3f26dde85..c7c0655dd45b 100644
> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c
> @@ -293,6 +293,8 @@ void free_initmem(void)
> unsigned long init_begin = (unsigned long)__init_begin;
> unsigned long init_end = (unsigned long)__init_end;
>
> - set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
> + if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
> + set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
> +
> free_initmem_default(POISON_FREE_INITMEM);
> }

Thanks, this is on fixes.