From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B05ED388378 for ; Mon, 1 Jun 2026 08:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780302414; cv=none; b=gQtLza/7DMdsOcT22LUoz8/qu2CrXZJg5cGQgVnecxUplISNu62odrs9Inj4WeAZmGRvE9N8xu+lpnpzRi2qGTq8dYV3/qCD8JALV2fYpq/Ylb6qM5mF6YDf8eyJSN1+7oONam6Pxu2rVLo0aH3pN5nIbP7YbVhcktHmt3iT5M4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780302414; c=relaxed/simple; bh=Nm6ji3B39VNemjFaFH4NUtpw3r+jyDTQyS8JtBJqiMw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KrJFLvxXUyZpANLkgwMY2WAP8ssOiDuorAgKdu5Z26o+zHzc1urcCw1cWHLLo2tHAOBFM5VdCf2GkUhPK2Ev5QiPfDCUm2gWZis82C2JcTw+VUzVMKPxDD8AeHIaSKOzMi1A01jXVVD7jHO/26vKG/9hQKizVGOgXq2pW3fMjz8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from [10.213.19.193] (unknown [36.110.52.2]) by APP-01 (Coremail) with SMTP id qwCowAB3F9A5Qh1qWQpVAA--.175S2; Mon, 01 Jun 2026 16:26:34 +0800 (CST) Message-ID: <48855978-6834-4427-ae55-e05650b1ea89@iscas.ac.cn> Date: Mon, 1 Jun 2026 16:26:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: mm: Call mark_new_valid_map() after hotplugging vmemmap To: Mike Rapoport Cc: Paul Walmsley , Palmer Dabbelt , Alexandre Ghiti , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20260525-mark-after-vmemmap-populate-v1-1-e698d859ba16@iscas.ac.cn> Content-Language: en-US From: Vivian Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CM-TRANSID:qwCowAB3F9A5Qh1qWQpVAA--.175S2 X-Coremail-Antispam: 1UD129KBjvJXoWxZr4DKF4kJF4DWw1DGFyUJrb_yoW5Gr4DpF W29a1fKF4UJr1xuws7u3WIqr4Fk3ZYvr18G3WrK34rZry5uFy29wnYkF4Ygry7Gr97Ga40 yFn0kas8G34DAa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvmb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4 A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IE w4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r4UJVWxJr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7 MxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2I x0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7IU5-jjPUUUUU== X-CM-SenderInfo: pzdqw2pxlnt03j6l2u1dvotugofq/ 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 >> --- >> 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 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 > [...]