[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2e24a7e9-fe8c-4af8-b775-ccc75e6af091@linux.dev>
Date: Mon, 6 Oct 2025 21:05:23 -0700
From: Yonghong Song <yonghong.song@...ux.dev>
To: KaFai Wan <kafai.wan@...ux.dev>, ast@...nel.org, daniel@...earbox.net,
andrii@...nel.org, martin.lau@...ux.dev, eddyz87@...il.com, song@...nel.org,
john.fastabend@...il.com, kpsingh@...nel.org, sdf@...ichev.me,
haoluo@...gle.com, jolsa@...nel.org, shuah@...nel.org, toke@...hat.com,
linux-kernel@...r.kernel.org, bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org
Cc: Le Chen <tom2cat@...u.edu.cn>
Subject: Re: [PATCH bpf v2 1/2] bpf: Avoid RCU context warning when unpinning
htab with internal structs
On 10/6/25 6:22 PM, KaFai Wan wrote:
> When unpinning a BPF hash table (htab or htab_lru) that contains internal
> structures (timer, workqueue, or task_work) in its values, a BUG warning
> is triggered:
> BUG: sleeping function called from invalid context at kernel/bpf/hashtab.c:244
> in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 14, name: ksoftirqd/0
> ...
>
> The issue arises from the interaction between BPF object unpinning and
> RCU callback mechanisms:
> 1. BPF object unpinning uses ->free_inode() which schedules cleanup via
> call_rcu(), deferring the actual freeing to an RCU callback that
> executes within the RCU_SOFTIRQ context.
> 2. During cleanup of hash tables containing internal structures,
> htab_map_free_internal_structs() is invoked, which includes
> cond_resched() or cond_resched_rcu() calls to yield the CPU during
> potentially long operations.
>
> However, cond_resched() or cond_resched_rcu() cannot be safely called from
> atomic RCU softirq context, leading to the BUG warning when attempting
> to reschedule.
>
> Fix this by changing from ->free_inode() to ->destroy_inode() and rename
> bpf_free_inode() to bpf_destroy_inode() for BPF objects (prog, map, link).
> This allows direct inode freeing without RCU callback scheduling,
> avoiding the invalid context warning.
>
> Reported-by: Le Chen <tom2cat@...u.edu.cn>
> Closes: https://lore.kernel.org/all/1444123482.1827743.1750996347470.JavaMail.zimbra@sjtu.edu.cn/
> Fixes: 68134668c17f ("bpf: Add map side support for bpf timers.")
> Suggested-by: Alexei Starovoitov <ast@...nel.org>
> Signed-off-by: KaFai Wan <kafai.wan@...ux.dev>
Acked-by: Yonghong Song <yonghong.song@...ux.dev>
Powered by blists - more mailing lists