public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v4] bpf: Fix RCU stall in bpf_fd_array_map_clear()
@ 2026-04-07 10:38 Sechang Lim
  2026-04-10 19:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Sechang Lim @ 2026-04-07 10:38 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, sun.jian.kdev,
	leon.hwang, linux-kernel, Sechang Lim

Add a missing cond_resched() in bpf_fd_array_map_clear() loop.

For PROG_ARRAY maps with many entries this loop calls
prog_array_map_poke_run() per entry which can be expensive, and
without yielding this can cause RCU stalls under load:

  rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
  rcu: 	(detected by 0, t=6502 jiffies, g=729293, q=305 ncpus=1)
  rcu: All QSes seen, last rcu_preempt kthread activity 6502 (4295096514-4295090012), jiffies_till_next_fqs=1, root ->qsmask 0x0
  rcu: rcu_preempt kthread starved for 6502 jiffies! g729293 f0x2 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=0
  rcu: 	Unless rcu_preempt kthread gets sufficient CPU time, OOM is now expected behavior.
  rcu: RCU grace-period kthread stack dump:
  task:rcu_preempt     state:R  running task     stack:0     pid:15    tgid:15    ppid:2      task_flags:0x208040 flags:0x00004000
  Call Trace:
   <TASK>
   context_switch kernel/sched/core.c:5382 [inline]
   __schedule+0x697/0x1430 kernel/sched/core.c:6767
   __schedule_loop kernel/sched/core.c:6845 [inline]
   schedule+0x10a/0x3e0 kernel/sched/core.c:6860
   schedule_timeout+0x145/0x2c0 kernel/time/sleep_timeout.c:99
   rcu_gp_fqs_loop+0x255/0x1350 kernel/rcu/tree.c:2046
   rcu_gp_kthread+0x347/0x680 kernel/rcu/tree.c:2248
   kthread+0x465/0x880 kernel/kthread.c:464
   ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:153
   ret_from_fork_asm+0x19/0x30 arch/x86/entry/entry_64.S:245
   </TASK>
  rcu: Stack dump where RCU GP kthread last ran:
  CPU: 0 UID: 0 PID: 30932 Comm: kworker/0:2 Not tainted 6.14.0-13195-g967e8def1100 #2 PREEMPT(undef)
  Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
  Workqueue: events prog_array_map_clear_deferred
  RIP: 0010:write_comp_data+0x38/0x90 kernel/kcov.c:246
  Call Trace:
   <TASK>
   prog_array_map_poke_run+0x77/0x380 kernel/bpf/arraymap.c:1096
   __fd_array_map_delete_elem+0x197/0x310 kernel/bpf/arraymap.c:925
   bpf_fd_array_map_clear kernel/bpf/arraymap.c:1000 [inline]
   prog_array_map_clear_deferred+0x119/0x1b0 kernel/bpf/arraymap.c:1141
   process_one_work+0x898/0x19d0 kernel/workqueue.c:3238
   process_scheduled_works kernel/workqueue.c:3319 [inline]
   worker_thread+0x770/0x10b0 kernel/workqueue.c:3400
   kthread+0x465/0x880 kernel/kthread.c:464
   ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:153
   ret_from_fork_asm+0x19/0x30 arch/x86/entry/entry_64.S:245
   </TASK>

Reviewed-by: Sun Jian <sun.jian.kdev@gmail.com>
Fixes: da765a2f5993 ("bpf: Add poke dependency tracking for prog array maps")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
v3 -> v4: Add changelog, no functional change
v3: https://lore.kernel.org/bpf/20260331023056.484354-1-rhkrqnwk98@gmail.com

v2 -> v3: Add Reviewed-by tag, fix CC typo
v2: https://lore.kernel.org/bpf/20260329020748.3649741-1-rhkrqnwk98@gmail.com

v1 -> v2: Add Fixes tag
v1: https://lore.kernel.org/bpf/20260328174428.3554328-1-rhkrqnwk98@gmail.com

 kernel/bpf/arraymap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 33de68c95ad8..5e25e0353509 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -1015,8 +1015,10 @@ static void bpf_fd_array_map_clear(struct bpf_map *map, bool need_defer)
 	struct bpf_array *array = container_of(map, struct bpf_array, map);
 	int i;
 
-	for (i = 0; i < array->map.max_entries; i++)
+	for (i = 0; i < array->map.max_entries; i++) {
 		__fd_array_map_delete_elem(map, &i, need_defer);
+		cond_resched();
+	}
 }
 
 static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf v4] bpf: Fix RCU stall in bpf_fd_array_map_clear()
  2026-04-07 10:38 [PATCH bpf v4] bpf: Fix RCU stall in bpf_fd_array_map_clear() Sechang Lim
@ 2026-04-10 19:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-10 19:20 UTC (permalink / raw)
  To: Sechang Lim
  Cc: bpf, ast, daniel, andrii, martin.lau, eddyz87, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
	sun.jian.kdev, leon.hwang, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue,  7 Apr 2026 10:38:23 +0000 you wrote:
> Add a missing cond_resched() in bpf_fd_array_map_clear() loop.
> 
> For PROG_ARRAY maps with many entries this loop calls
> prog_array_map_poke_run() per entry which can be expensive, and
> without yielding this can cause RCU stalls under load:
> 
>   rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
>   rcu: 	(detected by 0, t=6502 jiffies, g=729293, q=305 ncpus=1)
>   rcu: All QSes seen, last rcu_preempt kthread activity 6502 (4295096514-4295090012), jiffies_till_next_fqs=1, root ->qsmask 0x0
>   rcu: rcu_preempt kthread starved for 6502 jiffies! g729293 f0x2 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=0
>   rcu: 	Unless rcu_preempt kthread gets sufficient CPU time, OOM is now expected behavior.
>   rcu: RCU grace-period kthread stack dump:
>   task:rcu_preempt     state:R  running task     stack:0     pid:15    tgid:15    ppid:2      task_flags:0x208040 flags:0x00004000
>   Call Trace:
>    <TASK>
>    context_switch kernel/sched/core.c:5382 [inline]
>    __schedule+0x697/0x1430 kernel/sched/core.c:6767
>    __schedule_loop kernel/sched/core.c:6845 [inline]
>    schedule+0x10a/0x3e0 kernel/sched/core.c:6860
>    schedule_timeout+0x145/0x2c0 kernel/time/sleep_timeout.c:99
>    rcu_gp_fqs_loop+0x255/0x1350 kernel/rcu/tree.c:2046
>    rcu_gp_kthread+0x347/0x680 kernel/rcu/tree.c:2248
>    kthread+0x465/0x880 kernel/kthread.c:464
>    ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:153
>    ret_from_fork_asm+0x19/0x30 arch/x86/entry/entry_64.S:245
>    </TASK>
>   rcu: Stack dump where RCU GP kthread last ran:
>   CPU: 0 UID: 0 PID: 30932 Comm: kworker/0:2 Not tainted 6.14.0-13195-g967e8def1100 #2 PREEMPT(undef)
>   Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
>   Workqueue: events prog_array_map_clear_deferred
>   RIP: 0010:write_comp_data+0x38/0x90 kernel/kcov.c:246
>   Call Trace:
>    <TASK>
>    prog_array_map_poke_run+0x77/0x380 kernel/bpf/arraymap.c:1096
>    __fd_array_map_delete_elem+0x197/0x310 kernel/bpf/arraymap.c:925
>    bpf_fd_array_map_clear kernel/bpf/arraymap.c:1000 [inline]
>    prog_array_map_clear_deferred+0x119/0x1b0 kernel/bpf/arraymap.c:1141
>    process_one_work+0x898/0x19d0 kernel/workqueue.c:3238
>    process_scheduled_works kernel/workqueue.c:3319 [inline]
>    worker_thread+0x770/0x10b0 kernel/workqueue.c:3400
>    kthread+0x465/0x880 kernel/kthread.c:464
>    ret_from_fork+0x4d/0x80 arch/x86/kernel/process.c:153
>    ret_from_fork_asm+0x19/0x30 arch/x86/entry/entry_64.S:245
>    </TASK>
> 
> [...]

Here is the summary with links:
  - [bpf,v4] bpf: Fix RCU stall in bpf_fd_array_map_clear()
    https://git.kernel.org/bpf/bpf-next/c/4406942e65ca

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-10 19:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 10:38 [PATCH bpf v4] bpf: Fix RCU stall in bpf_fd_array_map_clear() Sechang Lim
2026-04-10 19:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox