Re: [PATCH] riscv: mm: Flush vmemmap TLB after sparse_init()

From: David Hildenbrand (Arm)

Date: Thu Aug 27 2026 - 07:09:46 EST


On 8/27/26 09:36, Yaxing Guo wrote:
> Commit 4267739cabb8 ("arch, mm: consolidate initialization of SPARSE
> memory model") moved sparse_init() from RISC-V arch setup code into
> free_area_init(), but left the RISC-V VMEMMAP TLB flush in
> misc_mem_init(). RISC-V now flushes the VMEMMAP range before
> sparse_init() populates the vmemmap page tables.
>
> RISC-V supports caching non-present entries in the TLB. If a hart cached
> a non-present translation for the VMEMMAP range, installing the vmemmap
> page-table entries is not guaranteed to be observed until an sfence.vma
> invalidates the stale entry. The first access to the corresponding
> struct page during memmap initialization can then hit the old non-present
> entry.
>
> Call an arch hook at the end of sparse_init(), after the boot-time
> vmemmap population has completed.

If it's a vmemmap thing, it should go into the vmemmap machinery, not slapped
into sparse.c.

Why can't the proposed vmemmap_populate_finalize() [1] cleanly take care of that?

[1]
https://lore.kernel.org/linux-riscv/20260630-mark-after-vmemmap-populate-v4-1-febbc15da028@xxxxxxxxxxx/

(independent of that, I really don't enjoy the suggested callback name)

--
Cheers,

David