[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAG_fn=XM_HRovM+VanVsNoi2ug1HQ1yx8oBhYAj0sVDJsh0nfQ@mail.gmail.com>
Date: Wed, 22 Oct 2025 11:43:24 +0200
From: Alexander Potapenko <glider@...gle.com>
To: Aleksei Nikiforov <aleksei.nikiforov@...ux.ibm.com>
Cc: Marco Elver <elver@...gle.com>, Dmitry Vyukov <dvyukov@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>, kasan-dev@...glegroups.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Ilya Leoshkevich <iii@...ux.ibm.com>
Subject: Re: [PATCH] mm/kmsan: Fix kmsan kmalloc hook when no stack depots are
allocated yet
On Tue, Sep 30, 2025 at 1:56 PM Aleksei Nikiforov
<aleksei.nikiforov@...ux.ibm.com> wrote:
>
> If no stack depot is allocated yet,
> due to masking out __GFP_RECLAIM flags
> kmsan called from kmalloc cannot allocate stack depot.
> kmsan fails to record origin and report issues.
>
> Reusing flags from kmalloc without modifying them should be safe for kmsan.
> For example, such chain of calls is possible:
> test_uninit_kmalloc -> kmalloc -> __kmalloc_cache_noprof ->
> slab_alloc_node -> slab_post_alloc_hook ->
> kmsan_slab_alloc -> kmsan_internal_poison_memory.
>
> Only when it is called in a context without flags present
> should __GFP_RECLAIM flags be masked.
>
> With this change all kmsan tests start working reliably.
I think this makes sense. The whole __GFP_RECLAIM filtering was mostly
for poisoning local variables, so we don't need it for allocation
hooks.
It is still possible to pass __GFP_RECLAIM to kmsan_poison_memory(), but:
- it is actually not used in the entire codebase;
- the documentation clearly states that kmsan_poison_memory() will be
allocating memory, so one should be mindful of passing wrong GFP
flags.
> Signed-off-by: Aleksei Nikiforov <aleksei.nikiforov@...ux.ibm.com>
Reviewed-by: Alexander Potapenko <glider@...gle.com>
Powered by blists - more mailing lists