Skip to contentSkip to conversation

bpf: no longer acquire map_idr_lock in bpf_map_inc_not_zero()

PATCH Applied Eric Dumazet 3 participants 3 messages Mar 1, 2025 – Mar 3, 2025

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

PATCH 1/1 bpf: no longer acquire map_idr_lock in bpf_map_inc_not_zero()

bpf_sk_storage_clone() is the only caller of bpf_map_inc_not_zero() and is holding rcu_read_lock().

map_idr_lock does not add any protection, just remove the cost for passive TCP flows.

Cc Kui-Feng Lee <[email protected]>
Cc Martin KaFai Lau <[email protected]>
---
 kernel/bpf/syscall.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/bpf/syscall.c +2 -5
index e1e42e918ba7f682223e9a78028bb0cc360c01ce..d68c8d61f7ceddb732a5646c00b8f0c71fdc2d71 100644
@@ -1593,11 +1593,8 @@ struct bpf_map *__bpf_map_inc_not_zero(struct bpf_map *map, bool uref)
 
 struct bpf_map *bpf_map_inc_not_zero(struct bpf_map *map)
 {
-	spin_lock_bh(&map_idr_lock);
-	map = __bpf_map_inc_not_zero(map, false);
-	spin_unlock_bh(&map_idr_lock);
-
-	return map;
+	lockdep_assert(rcu_read_lock_held());
+	return __bpf_map_inc_not_zero(map, false);
 }
 EXPORT_SYMBOL_GPL(bpf_map_inc_not_zero);
 
Signature · 1 line
2.48.1.711.g2feabab25a-goog
#2 lore raw
In reply to Eric Dumazet
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 11 lines · On Sat, 1 Mar 2025 19:13:15 +0000 you wrote:

bpf_sk_storage_clone() is the only caller of bpf_map_inc_not_zero() and is holding rcu_read_lock().

map_idr_lock does not add any protection, just remove the cost for passive TCP flows.

Cc Kui-Feng Lee <[email protected]>
Cc Martin KaFai Lau <[email protected]>

[...]

Here is the summary with links:
- [bpf-next] bpf: no longer acquire map_idr_lock in bpf_map_inc_not_zero()

    https://git.kernel.org/bpf/bpf-next/c/17a82ed98f62

You are awesome, thank you!

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