[PATCH bpf] bpf: Fix soft lockup in fd_array_map_free()

From: Li Jinyue

Date: Thu Nov 12 2026 - 07:51:18 EST


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@xxxxxxxxxxxxxxxxx>
---
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