On Tue, Nov 10, 2026 at 11:24 AM Hao Ge <[email protected]> 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.

>
> Add the matching early return.
>
> Reported-by: Sashiko <[email protected]>
> Reviewed-by: Dev Jain <[email protected]>
> Signed-off-by: Hao Ge <[email protected]>
> ---
>  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
>

Reply via email to