Skip to contentSkip to conversation

bpf: Call maybe_wait_bpf_programs() only once from generic_map_delete_batch()

PATCH Applied Eric Dumazet 3 participants 3 messages Feb 18, 2022

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

PATCH 1/1 bpf: Call maybe_wait_bpf_programs() only once from generic_map_delete_batch()

From: Eric Dumazet <[email protected]>

As stated in the comment found in maybe_wait_bpf_programs(), the synchronize_rcu() barrier is only needed before returning to userspace, not after each deletion in the batch.

Cc Stanislav Fomichev <[email protected]>
Cc Brian Vazquez <[email protected]>
---
 kernel/bpf/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +2 -1
index a72f63d5a7daee057bcec3fa6119aca32e2945f7..9c7a72b65eee0ec8d54d36e2c0ab9ff4962091af 100644
@@ -1352,7 +1352,6 @@ int generic_map_delete_batch(struct bpf_map *map,
 		err = map->ops->map_delete_elem(map, key);
 		rcu_read_unlock();
 		bpf_enable_instrumentation();
-		maybe_wait_bpf_programs(map);
 		if (err)
 			break;
 		cond_resched();
@@ -1361,6 +1360,8 @@ int generic_map_delete_batch(struct bpf_map *map,
 		err = -EFAULT;
 
 	kvfree(key);
+
+	maybe_wait_bpf_programs(map);
 	return err;
 }
 
Signature · 1 line
2.35.1.473.g83b2b277ed-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

As stated in the comment found in maybe_wait_bpf_programs(), the synchronize_rcu() barrier is only needed before returning to userspace, not after each deletion in the batch.

Cc Stanislav Fomichev <[email protected]>

Makes sense. Probably a copy-paste from the non-batch case...

Quoted 28 lines
Cc Brian Vazquez <[email protected]>
---
  kernel/bpf/syscall.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +2 -2
index a72f63d5a7daee057bcec3fa6119aca32e2945f7..9c7a72b65eee0ec8d54d36e2c0ab9ff4962091af 100644
@@ -1352,7 +1352,6 @@ int generic_map_delete_batch(struct bpf_map *map,
  		err = map->ops->map_delete_elem(map, key);
  		rcu_read_unlock();
  		bpf_enable_instrumentation();
-		maybe_wait_bpf_programs(map);
  		if (err)
  			break;
  		cond_resched();
@@ -1361,6 +1360,8 @@ int generic_map_delete_batch(struct bpf_map *map,
  		err = -EFAULT;
 
  	kvfree(key);
+
+	maybe_wait_bpf_programs(map);
  	return err;
  }
 
--

2.35.1.473.g83b2b277ed-goog

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

Hello:

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

Quoted 11 lines · On Fri, 18 Feb 2022 10:18:01 -0800 you wrote:

From: Eric Dumazet <[email protected]>

As stated in the comment found in maybe_wait_bpf_programs(), the synchronize_rcu() barrier is only needed before returning to userspace, not after each deletion in the batch.

Cc Stanislav Fomichev <[email protected]>
Cc Brian Vazquez <[email protected]>

[...]

Here is the summary with links:
- [bpf-next] bpf: Call maybe_wait_bpf_programs() only once from generic_map_delete_batch()

    https://git.kernel.org/bpf/bpf-next/c/9087c6ff8dfe

You are awesome, thank you!

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