Skip to contentSkip to conversation

sock_map: add a cond_resched() in sock_hash_free()

PATCH Applied Eric Dumazet 4 participants 4 messages Sep 6, 2024 – Sep 11, 2024

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sock_map: add a cond_resched() in sock_hash_free()

Several syzbot soft lockup reports all have in common sock_hash_free()

If a map with a large number of buckets is destroyed, we need to yield the cpu when needed.

Fixes 75e68e5bf2c7 ("bpf, sockhash: Synchronize delete from bucket list on map free")
Cc John Fastabend <[email protected]>
Cc Jakub Sitnicki <[email protected]>
---
 net/core/sock_map.c | 1 +
 1 file changed, 1 insertion(+)
net/core/sock_map.c +1 -0
index d3dbb92153f2fe7f1ddc8e35b495533fbf60a8cb..724b6856fcc3e9fd51673d31927cfd52d5d7d0aa 100644
@@ -1183,6 +1183,7 @@ static void sock_hash_free(struct bpf_map *map)
 			sock_put(elem->sk);
 			sock_hash_free_elem(htab, elem);
 		}
+		cond_resched();
 	}
 
 	/* wait for psock readers accessing its map link */
Signature · 1 line
2.46.0.469.g59c65b2a67-goog
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Eric Dumazet

Several syzbot soft lockup reports all have in common sock_hash_free()

If a map with a large number of buckets is destroyed, we need to yield the cpu when needed.

Fixes 75e68e5bf2c7 ("bpf, sockhash: Synchronize delete from bucket list on map free")
Cc John Fastabend <[email protected]>
Cc Jakub Sitnicki <[email protected]>
---
  net/core/sock_map.c | 1 +
  1 file changed, 1 insertion(+)
net/core/sock_map.c +0 -0
index d3dbb92153f2fe7f1ddc8e35b495533fbf60a8cb..724b6856fcc3e9fd51673d31927cfd52d5d7d0aa 100644

net/core/sock_map.c static void sock_hash_free(struct bpf_map *map) · line 1186

Quoted 4 lines
net/core/sock_map.c +1 -0
@@ -1183,6 +1183,7 @@ static void sock_hash_free(struct bpf_map *map)
  			sock_put(elem->sk);
  			sock_hash_free_elem(htab, elem);
  		}
+		cond_resched();

Jakub, may be you can directly take it to net tree ?

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 29 lines · Eric Dumazet

Several syzbot soft lockup reports all have in common sock_hash_free()

If a map with a large number of buckets is destroyed, we need to yield the cpu when needed.

Fixes 75e68e5bf2c7 ("bpf, sockhash: Synchronize delete from bucket list on map free")
Cc John Fastabend <[email protected]>
Cc Jakub Sitnicki <[email protected]>
---
 net/core/sock_map.c | 1 +
 1 file changed, 1 insertion(+)
net/core/sock_map.c +1 -0
index d3dbb92153f2fe7f1ddc8e35b495533fbf60a8cb..724b6856fcc3e9fd51673d31927cfd52d5d7d0aa 100644
@@ -1183,6 +1183,7 @@ static void sock_hash_free(struct bpf_map *map)
 			sock_put(elem->sk);
 			sock_hash_free_elem(htab, elem);
 		}
+		cond_resched();
 	}
 
 	/* wait for psock readers accessing its map link */
Signature · 1 line
2.46.0.469.g59c65b2a67-goog

Thanks, looks good to me.

#3 lore raw
In reply to Eric Dumazet
This patch was applied to bpf/bpf-next.git (net) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (net)
by Daniel Borkmann <[email protected]>:

Quoted 5 lines · On Fri, 6 Sep 2024 15:44:49 +0000 you wrote:

Several syzbot soft lockup reports all have in common sock_hash_free()

If a map with a large number of buckets is destroyed, we need to yield the cpu when needed.

Quoted 7 lines
Fixes 75e68e5bf2c7 ("bpf, sockhash: Synchronize delete from bucket list on map free")
Cc John Fastabend <[email protected]>
Cc Jakub Sitnicki <[email protected]>

[...]

Here is the summary with links:
- [bpf] sock_map: add a cond_resched() in sock_hash_free()

    https://git.kernel.org/bpf/bpf-next/c/b1339be951ad

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html