From: Shakeel Butt <shakeel.butt@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@kernel.org, vbabka@suse.cz, yepeilin@google.com,
harry.yoo@oracle.com, linux-mm@kvack.org
Subject: Re: [PATCH bpf] bpf: Replace bpf_map_kmalloc_node() with kmalloc_nolock() to allocate bpf_async_cb structures.
Date: Tue, 14 Oct 2025 15:57:11 -0700 [thread overview]
Message-ID: <ts7ewzhspasn2n3gfpscqpvhhzeod7cv6nml4g457ytzgojbek@gd5vts6hpdjf> (raw)
In-Reply-To: <20251014212541.67930-1-alexei.starovoitov@gmail.com>
On Tue, Oct 14, 2025 at 02:25:41PM -0700, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> The following kmemleak splat:
> [ 8.105530] kmemleak: Trying to color unknown object at 0xff11000100e918c0 as Black
> [ 8.106521] Call Trace:
> [ 8.106521] <TASK>
> [ 8.106521] dump_stack_lvl+0x4b/0x70
> [ 8.106521] kvfree_call_rcu+0xcb/0x3b0
> [ 8.106521] ? hrtimer_cancel+0x21/0x40
> [ 8.106521] bpf_obj_free_fields+0x193/0x200
> [ 8.106521] htab_map_update_elem+0x29c/0x410
> [ 8.106521] bpf_prog_cfc8cd0f42c04044_overwrite_cb+0x47/0x4b
> [ 8.106521] bpf_prog_8c30cd7c4db2e963_overwrite_timer+0x65/0x86
> [ 8.106521] bpf_prog_test_run_syscall+0xe1/0x2a0
>
> happens due to the combination of features and fixes, but mainly due to
> commit 6d78b4473cdb ("bpf: Tell memcg to use allow_spinning=false path in bpf_timer_init()")
> It's using __GFP_HIGH, which instructs slub/kmemleak internals to skip
> kmemleak_alloc_recursive() on allocation, so subsequent kfree_rcu()->
> kvfree_call_rcu()->kmemleak_ignore() complains with the above splat.
>
> To fix this imbalance, replace bpf_map_kmalloc_node() with
> kmalloc_nolock() and kfree_rcu() with call_rcu() + kfree_nolock() to
> make sure that the objects allocated with kmalloc_nolock() are freed
> with kfree_nolock() rather than the implicit kfree() that kfree_rcu()
> uses internally.
>
> Note, the kmalloc_nolock() happens under bpf_spin_lock_irqsave(), so
> it will always fail in PREEMPT_RT. This is not an issue at the moment,
> since bpf_timers are disabled in PREEMPT_RT. In the future
> bpf_spin_lock will be replaced with state machine similar to
> bpf_task_work.
>
> Fixes: 6d78b4473cdb ("bpf: Tell memcg to use allow_spinning=false path in bpf_timer_init()")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
prev parent reply other threads:[~2025-10-14 22:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 21:25 Alexei Starovoitov
2025-10-14 22:57 ` Shakeel Butt [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=ts7ewzhspasn2n3gfpscqpvhhzeod7cv6nml4g457ytzgojbek@gd5vts6hpdjf \
--to=shakeel.butt@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=harry.yoo@oracle.com \
--cc=linux-mm@kvack.org \
--cc=martin.lau@kernel.org \
--cc=vbabka@suse.cz \
--cc=yepeilin@google.com \
/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