Re: [PATCH v9 0/3] riscv: Use PUD/P4D/PGD pages for the linear mapping

From: Anup Patel
Date: Mon Mar 27 2023 - 08:13:15 EST


On Fri, Mar 24, 2023 at 9:24 PM Alexandre Ghiti <alexghiti@xxxxxxxxxxxx> wrote:
>
> This patchset intends to improve tlb utilization by using hugepages for
> the linear mapping.
>
> As reported by Anup in v6, when STRICT_KERNEL_RWX is enabled, we must
> take care of isolating the kernel text and rodata so that they are not
> mapped with a PUD mapping which would then assign wrong permissions to
> the whole region: it is achieved the same way as arm64 by using the
> memblock nomap API which isolates those regions and re-merge them afterwards
> thus avoiding any issue with the system resources tree creation.
>
> base-commit-tag: v6.3-rc1
>
> v9:
> - Remove new API and arm64 patches as it created more issues than it
> solved, thanks Anup for reporting those bugs!
> - Add a patch that moves the linear mapping creation outside of setup_vm_final
> - Use nomap API like arm64
> - Removed RB from Andrew and Anup as the patch changed its logic
> - Fix kernel rodata size computation
>
> v8:
> - Fix rv32, as reported by Anup
> - Do not modify memblock_isolate_range and fixes comment, as suggested by Mike
> - Use the new memblock API for crash kernel too in arm64, as suggested by Andrew
> - Fix arm64 double mapping (which to me did not work in v7), but ends up not
> being pretty at all, will wait for comments from arm64 reviewers, but
> this patch can easily be dropped if they do not want it.
>
> v7:
> - Fix Anup bug report by introducing memblock_isolate_memory which
> allows us to split the memblock mappings and then avoid to map the
> the PUD which contains the kernel as read only
> - Add a patch to arm64 to use this newly introduced API
>
> v6:
> - quiet LLVM warning by casting phys_ram_base into an unsigned long
>
> v5:
> - Fix nommu builds by getting rid of riscv_pfn_base in patch 1, thanks
> Conor
> - Add RB from Andrew
>
> v4:
> - Rebase on top of v6.2-rc3, as noted by Conor
> - Add Acked-by Rob
>
> v3:
> - Change the comment about initrd_start VA conversion so that it fits
> ARM64 and RISCV64 (and others in the future if needed), as suggested
> by Rob
>
> v2:
> - Add a comment on why RISCV64 does not need to set initrd_start/end that
> early in the boot process, as asked by Rob
>
> Alexandre Ghiti (3):
> riscv: Get rid of riscv_pfn_base variable
> riscv: Move the linear mapping creation in its own function
> riscv: Use PUD/P4D/PGD pages for the linear mapping

I have tested this series again on QEMU RV64 and RV32. I also tried
KVM RV64 and RV32, this works fine as well.

>
> arch/riscv/include/asm/page.h | 19 ++++++-
> arch/riscv/mm/init.c | 102 ++++++++++++++++++++++++++--------
> arch/riscv/mm/physaddr.c | 16 ++++++
> drivers/of/fdt.c | 11 ++--
> 4 files changed, 118 insertions(+), 30 deletions(-)
>
> --
> 2.37.2
>

Regards,
Anup