Re: [PATCH v4 2/9] mm/kmsan: skip vunmap_range_noflush when KMSAN is disabled
From: Hao Ge
Date: Thu Nov 12 2026 - 02:33:22 EST
Hi Suren
On 2026/11/12 06:10, Suren Baghdasaryan wrote:
> On Tue, Nov 10, 2026 at 11:24 AM Hao Ge <hao.ge@xxxxxxxxx> wrote:
>>
>> kmsan_vmap_pages_range_noflush() returns 0 when kmsan_enabled is
>> false. The unmap side does not, so it still walks the shadow and
>> origin page tables even though KMSAN never installed any metadata
>> there.
>
> Note that KMSAN_WARN_ON() can reset kmsan_enabled flag, so the fact
> that it's false does not mean that metadata was never installed. I
> think a proper bailout should depend on CONFIG_KMSAN, not on
> kmsan_enabled.
Sorry, I did not realize this logic.
I will go through the code again and will probably drop
this patch in the next version.
Thanks
Best Regards
Hao
>
>>
>> Add the matching early return.
>>
>> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
>> Reviewed-by: Dev Jain <dev.jain@xxxxxxx>
>> Signed-off-by: Hao Ge <hao.ge@xxxxxxxxx>
>> ---
>> mm/kmsan/hooks.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c
>> index a706666db097..107f66841274 100644
>> --- a/mm/kmsan/hooks.c
>> +++ b/mm/kmsan/hooks.c
>> @@ -138,6 +138,9 @@ static unsigned long vmalloc_origin(unsigned long addr)
>>
>> void kmsan_vunmap_range_noflush(unsigned long start, unsigned long end)
>> {
>> + if (!kmsan_enabled)
>> + return;
>> +
>> __vunmap_range_noflush(vmalloc_shadow(start), vmalloc_shadow(end));
>> __vunmap_range_noflush(vmalloc_origin(start), vmalloc_origin(end));
>> flush_cache_vmap(vmalloc_shadow(start), vmalloc_shadow(end));
>> --
>> 2.25.1
>>