Re: [PATCH v5 0/2] riscv: Map the kernel with correct permissions the first time

From: Alex Ghiti
Date: Thu Jun 17 2021 - 08:08:37 EST

Le 17/06/2021 à 14:01, Alexandre Ghiti a écrit :
The kernel permissions are fixed after the kernel page table is created:
avoid that by mapping the kernel 'correctly' the first time.
Patch 1 introduces a new helper to set kernel mapping permissions while
avoiding all the casts when using set_memory_* API.
Patch 2 is the bulk of this work and deals with mapping the kernel with
the right permissions.

Changes in v5:
* Remove non-relevant commits to this patchset that raised issues
* Make load_sz non-static as it is used in kernel address conversions
* Rebased on top for-next

Changes in v4:
* Add patch 1 as noted by Jisheng
* Changes patch 2 title as suggested by Anup
* Add Reviewed-by from Anup
Changes in v3:
* Add a patch that factorizes kernel address conversions
* Add a helper called set_kernel_memory in its own patch, as suggested by
* Prefer IS_ENABLED over #ifdef, as suggested by Christoph
* Split overly long lines, as suggested by Christoph
* Simplify kernel mapping by mapping ALL text as readonly and taking advantage
of already present code that enables write for init text before
Changes in v2:
* Rebased on top of for-next (and "riscv: mm: fix build errors caused by
* Get rid of protect_kernel_linear_mapping_text_rodata as suggested by
* Improve code in general compared to previous RFC

Alexandre Ghiti (2):
riscv: Introduce set_kernel_memory helper
riscv: Map the kernel with correct permissions the first time

arch/riscv/include/asm/page.h | 13 +++-
arch/riscv/include/asm/sections.h | 17 +++++
arch/riscv/include/asm/set_memory.h | 13 ++--
arch/riscv/kernel/setup.c | 11 +--
arch/riscv/mm/init.c | 108 ++++++++++++----------------
arch/riscv/mm/pageattr.c | 10 +++
6 files changed, 91 insertions(+), 81 deletions(-)

@Palmer: I removed the previous patchset (v4) you took in for-next and cherry-picked those 2 while fixing conflicts, so if you do that in that order, you should not have any problem :)