BPF List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Fix soft lockup in fd_array_map_free()
@ 2026-11-12 12:20 Li Jinyue
  2026-11-12 12:30 ` sashiko-bot
  2026-11-12 19:59 ` Alexei Starovoitov
  0 siblings, 2 replies; 3+ messages in thread
From: Li Jinyue @ 2026-11-12 12:20 UTC (permalink / raw)
  To: bpf, Alexei Starovoitov, Daniel Borkmann
  Cc: Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, linux-kernel

fd_array_map_free() walks all map entries to assert that the map is
empty before its memory is freed. max_entries is not bounded, and the
free runs from the bpf_map_free_deferred work item, so with a large
max_entries the scan occupies the CPU for a long time without a
scheduling point:

  watchdog: BUG: soft lockup - CPU#1 stuck for 26s! [kworker/u8:5:8894]
  Workqueue: events_unbound bpf_map_free_deferred
   epc : fd_array_map_free+0x7c/0xea

Add cond_resched() to the loop, matching what commit 4406942e65ca
("bpf: Fix RCU stall in bpf_fd_array_map_clear()") did for
bpf_fd_array_map_clear().

Fixes: 04fd61ab36ec ("bpf: allow bpf programs to tail-call other bpf programs")
Signed-off-by: Li Jinyue <jinyue.li@linux.alibaba.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 0ce26b538075..3c908373333e 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -924,8 +924,10 @@ static void fd_array_map_free(struct bpf_map *map)
 	int i;
 
 	/* make sure it's empty */
-	for (i = 0; i < array->map.max_entries; i++)
+	for (i = 0; i < array->map.max_entries; i++) {
 		BUG_ON(array->ptrs[i] != NULL);
+		cond_resched();
+	}
 
 	bpf_map_area_free(array);
 }

-- 
2.25.1


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

end of thread, other threads:[~2026-11-12 19:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 12:20 [PATCH bpf] bpf: Fix soft lockup in fd_array_map_free() Li Jinyue
2026-11-12 12:30 ` sashiko-bot
2026-11-12 19:59 ` Alexei Starovoitov

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