Re: [PATCH] bpf: Call cond_resched() to avoid soft lockup in trie_free()
From: Song Liu
Date: Mon Jun 16 2025 - 11:52:10 EST
On Mon, Jun 16, 2025 at 2:55 AM Matt Fleming <matt@xxxxxxxxxxxxxxxx> wrote:
>
> From: Matt Fleming <mfleming@xxxxxxxxxxxxxx>
>
> Calls to kfree() in trie_free() can be expensive for KASAN-enabled
> kernels. This can cause soft lockup warnings when traversing large maps,
I think this could also happen to KASAN-disabled kernels, so the commit log
is a bit misleading.
>
> watchdog: BUG: soft lockup - CPU#41 stuck for 76s! [kworker/u518:14:1158211]
>
> Avoid an unbounded loop and periodically check whether we should reschedule.
>
> Signed-off-by: Matt Fleming <mfleming@xxxxxxxxxxxxxx>
Other than that:
Acked-by: Song Liu <song@xxxxxxxxxx>
> ---
> kernel/bpf/lpm_trie.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
> index be66d7e520e0..a35619cd99f6 100644
> --- a/kernel/bpf/lpm_trie.c
> +++ b/kernel/bpf/lpm_trie.c
> @@ -646,6 +646,8 @@ static void trie_free(struct bpf_map *map)
> RCU_INIT_POINTER(*slot, NULL);
> break;
> }
> +
> + cond_resched();
> }
>
> out:
> --
> 2.34.1
>