From: Vivian Wang <wangruikang@iscas.ac.cn>
To: Mike Rapoport <rppt@kernel.org>
Cc: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Alexandre Ghiti <alex@ghiti.fr>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH] riscv: mm: Call mark_new_valid_map() after hotplugging vmemmap
Date: Mon, 1 Jun 2026 16:26:33 +0800 [thread overview]
Message-ID: <48855978-6834-4427-ae55-e05650b1ea89@iscas.ac.cn> (raw)
In-Reply-To: <ah0xLeD1_6oRKDkx@kernel.org>
Hi Mike,
Thanks for your review.
On 6/1/26 15:13, Mike Rapoport wrote:
> Hi,
>
> On Mon, May 25, 2026 at 12:23:29PM +0800, Vivian Wang wrote:
>> section_activate() creates new mappings in the vmemmap range without
>> flushing TLB, which may cause faults on some RISC-V implementations that
>> cache non-present PTEs and crashes.
>>
>> This seems to be most easily reproduced with DEBUG_VM=y and
>> PAGE_POISONING=y, which causes these newly mapped struct pages to be
>> poisoned i.e. written to immediately after mapping.
>>
>> Add a hook vmemmap_populate_finalize() in __populate_section_memmap(),
>> and implement it as calling mark_new_valid_map() on RISC-V, which
>> arranges for the exception handler to deal with these faults if they
>> happen.
>>
>> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
>> ---
>> I'm not sure if this is the right place to add this hook. I didn't add
>> it to vmemmap_populate because it doesn't seem to be called in all
>> cases. Please advise.
> Indeed it looks like we'd need a new hook to let architectures run
> post-populate actions.
>
> The explanation that says why a new hook is needed should be a part of the
> changelog.
>
I will reorganize this in v2.
>> Depends on my earlier kfence fixes for mark_new_valid_map() [1].
>>
>> Found while testing AMD_HSA/ZONE_DEVICE on SpacemiT K3. Using
>> ZONE_DEVICE requires another fix [2].
>>
>> [1]: https://lore.kernel.org/linux-riscv/20260303-handle-kfence-protect-spurious-fault-v2-0-f80d8354d79d@iscas.ac.cn
>> [2]: https://lore.kernel.org/linux-riscv/20260309-riscv-sparsemem-vmemmap-limits-v1-2-f40efe18e3cd@iscas.ac.cn
>> ---
>> arch/riscv/mm/init.c | 6 ++++++
>> include/linux/mm.h | 1 +
>> mm/sparse-vmemmap.c | 6 ++++++
>> 3 files changed, 13 insertions(+)
[...]
>> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
>> index 6eadb9d116e4..2b860d2b1703 100644
>> --- a/mm/sparse-vmemmap.c
>> +++ b/mm/sparse-vmemmap.c
>> @@ -544,6 +544,10 @@ static int __meminit vmemmap_populate_compound_pages(unsigned long start_pfn,
>>
>> #endif
>>
>> +void __weak __meminit vmemmap_populate_finalize(void)
>> +{
>> +}
>> +
> The existing hooks in sparse-vmemmap use #ifdef <hook> rather than __weak
> functions. Take a look at vmemmap_can_optimize() and
> vmemmap_populate_compound_pages().
>
> Let's keep it consistent.
I wasn't sure since it seems that both styles exist in this file.
I will change it to #ifdef in v2, as that seems to be preferable.
Vivian "dramforever" Wang
> [...]
prev parent reply other threads:[~2026-06-01 8:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 4:23 Vivian Wang
2026-06-01 7:13 ` Mike Rapoport
2026-06-01 8:26 ` Vivian Wang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48855978-6834-4427-ae55-e05650b1ea89@iscas.ac.cn \
--to=wangruikang@iscas.ac.cn \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®