diff mbox series

[-next,5/5] bpf: Remove map_get_next_key callbacks with -EOPNOTSUPP

Message ID 20250217014122.65645-6-zhangxiaomeng13@huawei.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series remove unnecessary -EOPNOTSUPP callbacks | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 13 of 13 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 139 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / GCC BPF
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for aarch64-gcc / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-12 success Logs for aarch64-gcc / veristat-meta
bpf/vmtest-bpf-next-VM_Test-19 success Logs for s390x-gcc / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-20 success Logs for s390x-gcc / veristat-meta
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / GCC BPF
bpf/vmtest-bpf-next-VM_Test-18 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-17 / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-17 / veristat-meta
bpf/vmtest-bpf-next-VM_Test-43 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-44 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-50 success Logs for x86_64-llvm-18 / veristat-kernel
bpf/vmtest-bpf-next-VM_Test-51 success Logs for x86_64-llvm-18 / veristat-meta
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-gcc / veristat-kernel / x86_64-gcc veristat_kernel
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / GCC BPF / GCC BPF
bpf/vmtest-bpf-next-VM_Test-45 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-49 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / GCC BPF / GCC BPF
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-gcc / veristat-meta / x86_64-gcc veristat_meta
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / GCC BPF / GCC BPF
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-46 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-47 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-48 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18

Commit Message

Xiaomeng Zhang Feb. 17, 2025, 1:41 a.m. UTC
Remove redundant map_get_next_key callbacks with return -EOPNOTSUPP. We can
directly return -EOPNOTSUPP when calling the unimplemented callbacks.

Signed-off-by: Xiaomeng Zhang <zhangxiaomeng13@huawei.com>
---
 kernel/bpf/arena.c             |  6 ------
 kernel/bpf/bloom_filter.c      |  6 ------
 kernel/bpf/bpf_cgrp_storage.c  |  6 ------
 kernel/bpf/bpf_inode_storage.c |  7 -------
 kernel/bpf/bpf_task_storage.c  |  6 ------
 kernel/bpf/ringbuf.c           |  8 --------
 kernel/bpf/syscall.c           | 10 ++++++++--
 7 files changed, 8 insertions(+), 41 deletions(-)

Comments

Hou Tao Feb. 17, 2025, 2:42 a.m. UTC | #1
Hi,

On 2/17/2025 9:41 AM, Xiaomeng Zhang wrote:
> Remove redundant map_get_next_key callbacks with return -EOPNOTSUPP. We can
> directly return -EOPNOTSUPP when calling the unimplemented callbacks.
>
> Signed-off-by: Xiaomeng Zhang <zhangxiaomeng13@huawei.com>
> ---
>  kernel/bpf/arena.c             |  6 ------
>  kernel/bpf/bloom_filter.c      |  6 ------
>  kernel/bpf/bpf_cgrp_storage.c  |  6 ------
>  kernel/bpf/bpf_inode_storage.c |  7 -------
>  kernel/bpf/bpf_task_storage.c  |  6 ------
>  kernel/bpf/ringbuf.c           |  8 --------
>  kernel/bpf/syscall.c           | 10 ++++++++--
>  7 files changed, 8 insertions(+), 41 deletions(-)
>
> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index 50f07bbd33fa..7f37ef1b72ce 100644
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c
> @@ -62,11 +62,6 @@ u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena)
>  	return arena ? arena->user_vm_start : 0;
>  }
>  

SNIP
> diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
> index e2d22f10a11f..932a6c06e3e0 100644
> --- a/kernel/bpf/ringbuf.c
> +++ b/kernel/bpf/ringbuf.c
> @@ -247,12 +247,6 @@ static long ringbuf_map_update_elem(struct bpf_map *map, void *key, void *value,
>  	return -ENOTSUPP;
>  }
>  
> -static int ringbuf_map_get_next_key(struct bpf_map *map, void *key,
> -				    void *next_key)
> -{
> -	return -ENOTSUPP;
> -}
> -
>  static int ringbuf_map_mmap_kern(struct bpf_map *map, struct vm_area_struct *vma)
>  {
>  	struct bpf_ringbuf_map *rb_map;
> @@ -351,7 +345,6 @@ const struct bpf_map_ops ringbuf_map_ops = {
>  	.map_poll = ringbuf_map_poll_kern,
>  	.map_lookup_elem = ringbuf_map_lookup_elem,
>  	.map_update_elem = ringbuf_map_update_elem,
> -	.map_get_next_key = ringbuf_map_get_next_key,
>  	.map_mem_usage = ringbuf_map_mem_usage,
>  	.map_btf_id = &ringbuf_map_btf_ids[0],
>  };
> @@ -365,7 +358,6 @@ const struct bpf_map_ops user_ringbuf_map_ops = {
>  	.map_poll = ringbuf_map_poll_user,
>  	.map_lookup_elem = ringbuf_map_lookup_elem,
>  	.map_update_elem = ringbuf_map_update_elem,
> -	.map_get_next_key = ringbuf_map_get_next_key,
>  	.map_mem_usage = ringbuf_map_mem_usage,
>  	.map_btf_id = &user_ringbuf_map_btf_ids[0],
>  };
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 36eed7016da4..087abbacbd05 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -1850,7 +1850,10 @@ static int map_get_next_key(union bpf_attr *attr)
>  	}
>  
>  	rcu_read_lock();
> -	err = map->ops->map_get_next_key(map, key, next_key);
> +	if (map->ops->map_get_next_key)
> +		err = map->ops->map_get_next_key(map, key, next_key);
> +	else
> +		err = -EOPNOTSUPP;

The old return value is ENOTSUPP. For consistency, I think it is better
to still return ENOTSUPP.
>  	rcu_read_unlock();
>  out:
>  	if (err)
> @@ -2037,7 +2040,10 @@ int generic_map_lookup_batch(struct bpf_map *map,
>  
>  	for (cp = 0; cp < max_count;) {
>  		rcu_read_lock();
> -		err = map->ops->map_get_next_key(map, prev_key, key);
> +		if (map->ops->map_get_next_key)
> +			err = map->ops->map_get_next_key(map, prev_key, key);
> +		else
> +			err = -EOPNOTSUPP;
>  		rcu_read_unlock();

How about only check ->map_get_next_key() once instead of checking it
every time ? And there are another two invocations of
->map_get_next_key(), please update these invocations as well.
>  		if (err)
>  			break;
diff mbox series

Patch

diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
index 50f07bbd33fa..7f37ef1b72ce 100644
--- a/kernel/bpf/arena.c
+++ b/kernel/bpf/arena.c
@@ -62,11 +62,6 @@  u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena)
 	return arena ? arena->user_vm_start : 0;
 }
 
-static int arena_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
-{
-	return -EOPNOTSUPP;
-}
-
 static long compute_pgoff(struct bpf_arena *arena, long uaddr)
 {
 	return (u32)(uaddr - (u32)arena->user_vm_start) >> PAGE_SHIFT;
@@ -382,7 +377,6 @@  const struct bpf_map_ops arena_map_ops = {
 	.map_direct_value_addr = arena_map_direct_value_addr,
 	.map_mmap = arena_map_mmap,
 	.map_get_unmapped_area = arena_get_unmapped_area,
-	.map_get_next_key = arena_map_get_next_key,
 	.map_lookup_elem = arena_map_lookup_elem,
 	.map_update_elem = arena_map_update_elem,
 	.map_check_btf = arena_map_check_btf,
diff --git a/kernel/bpf/bloom_filter.c b/kernel/bpf/bloom_filter.c
index f3bba8ac2532..3aed40c92c26 100644
--- a/kernel/bpf/bloom_filter.c
+++ b/kernel/bpf/bloom_filter.c
@@ -65,11 +65,6 @@  static long bloom_map_push_elem(struct bpf_map *map, void *value, u64 flags)
 	return 0;
 }
 
-static int bloom_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
-{
-	return -EOPNOTSUPP;
-}
-
 /* Called from syscall */
 static int bloom_map_alloc_check(union bpf_attr *attr)
 {
@@ -196,7 +191,6 @@  const struct bpf_map_ops bloom_filter_map_ops = {
 	.map_alloc_check = bloom_map_alloc_check,
 	.map_alloc = bloom_map_alloc,
 	.map_free = bloom_map_free,
-	.map_get_next_key = bloom_map_get_next_key,
 	.map_push_elem = bloom_map_push_elem,
 	.map_peek_elem = bloom_map_peek_elem,
 	.map_lookup_elem = bloom_map_lookup_elem,
diff --git a/kernel/bpf/bpf_cgrp_storage.c b/kernel/bpf/bpf_cgrp_storage.c
index 54ff2a85d4c0..305f23c36afc 100644
--- a/kernel/bpf/bpf_cgrp_storage.c
+++ b/kernel/bpf/bpf_cgrp_storage.c
@@ -141,11 +141,6 @@  static long bpf_cgrp_storage_delete_elem(struct bpf_map *map, void *key)
 	return err;
 }
 
-static int notsupp_get_next_key(struct bpf_map *map, void *key, void *next_key)
-{
-	return -ENOTSUPP;
-}
-
 static struct bpf_map *cgroup_storage_map_alloc(union bpf_attr *attr)
 {
 	return bpf_local_storage_map_alloc(attr, &cgroup_cache, true);
@@ -208,7 +203,6 @@  const struct bpf_map_ops cgrp_storage_map_ops = {
 	.map_alloc_check = bpf_local_storage_map_alloc_check,
 	.map_alloc = cgroup_storage_map_alloc,
 	.map_free = cgroup_storage_map_free,
-	.map_get_next_key = notsupp_get_next_key,
 	.map_lookup_elem = bpf_cgrp_storage_lookup_elem,
 	.map_update_elem = bpf_cgrp_storage_update_elem,
 	.map_delete_elem = bpf_cgrp_storage_delete_elem,
diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c
index 15a3eb9b02d9..6db158c2a42b 100644
--- a/kernel/bpf/bpf_inode_storage.c
+++ b/kernel/bpf/bpf_inode_storage.c
@@ -175,12 +175,6 @@  BPF_CALL_2(bpf_inode_storage_delete,
 	return inode_storage_delete(inode, map);
 }
 
-static int notsupp_get_next_key(struct bpf_map *map, void *key,
-				void *next_key)
-{
-	return -ENOTSUPP;
-}
-
 static struct bpf_map *inode_storage_map_alloc(union bpf_attr *attr)
 {
 	return bpf_local_storage_map_alloc(attr, &inode_cache, false);
@@ -196,7 +190,6 @@  const struct bpf_map_ops inode_storage_map_ops = {
 	.map_alloc_check = bpf_local_storage_map_alloc_check,
 	.map_alloc = inode_storage_map_alloc,
 	.map_free = inode_storage_map_free,
-	.map_get_next_key = notsupp_get_next_key,
 	.map_lookup_elem = bpf_fd_inode_storage_lookup_elem,
 	.map_update_elem = bpf_fd_inode_storage_update_elem,
 	.map_delete_elem = bpf_fd_inode_storage_delete_elem,
diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c
index 1109475953c0..3bdb49aab55f 100644
--- a/kernel/bpf/bpf_task_storage.c
+++ b/kernel/bpf/bpf_task_storage.c
@@ -303,11 +303,6 @@  BPF_CALL_2(bpf_task_storage_delete, struct bpf_map *, map, struct task_struct *,
 	return ret;
 }
 
-static int notsupp_get_next_key(struct bpf_map *map, void *key, void *next_key)
-{
-	return -ENOTSUPP;
-}
-
 static struct bpf_map *task_storage_map_alloc(union bpf_attr *attr)
 {
 	return bpf_local_storage_map_alloc(attr, &task_cache, true);
@@ -324,7 +319,6 @@  const struct bpf_map_ops task_storage_map_ops = {
 	.map_alloc_check = bpf_local_storage_map_alloc_check,
 	.map_alloc = task_storage_map_alloc,
 	.map_free = task_storage_map_free,
-	.map_get_next_key = notsupp_get_next_key,
 	.map_lookup_elem = bpf_pid_task_storage_lookup_elem,
 	.map_update_elem = bpf_pid_task_storage_update_elem,
 	.map_delete_elem = bpf_pid_task_storage_delete_elem,
diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
index e2d22f10a11f..932a6c06e3e0 100644
--- a/kernel/bpf/ringbuf.c
+++ b/kernel/bpf/ringbuf.c
@@ -247,12 +247,6 @@  static long ringbuf_map_update_elem(struct bpf_map *map, void *key, void *value,
 	return -ENOTSUPP;
 }
 
-static int ringbuf_map_get_next_key(struct bpf_map *map, void *key,
-				    void *next_key)
-{
-	return -ENOTSUPP;
-}
-
 static int ringbuf_map_mmap_kern(struct bpf_map *map, struct vm_area_struct *vma)
 {
 	struct bpf_ringbuf_map *rb_map;
@@ -351,7 +345,6 @@  const struct bpf_map_ops ringbuf_map_ops = {
 	.map_poll = ringbuf_map_poll_kern,
 	.map_lookup_elem = ringbuf_map_lookup_elem,
 	.map_update_elem = ringbuf_map_update_elem,
-	.map_get_next_key = ringbuf_map_get_next_key,
 	.map_mem_usage = ringbuf_map_mem_usage,
 	.map_btf_id = &ringbuf_map_btf_ids[0],
 };
@@ -365,7 +358,6 @@  const struct bpf_map_ops user_ringbuf_map_ops = {
 	.map_poll = ringbuf_map_poll_user,
 	.map_lookup_elem = ringbuf_map_lookup_elem,
 	.map_update_elem = ringbuf_map_update_elem,
-	.map_get_next_key = ringbuf_map_get_next_key,
 	.map_mem_usage = ringbuf_map_mem_usage,
 	.map_btf_id = &user_ringbuf_map_btf_ids[0],
 };
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 36eed7016da4..087abbacbd05 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1850,7 +1850,10 @@  static int map_get_next_key(union bpf_attr *attr)
 	}
 
 	rcu_read_lock();
-	err = map->ops->map_get_next_key(map, key, next_key);
+	if (map->ops->map_get_next_key)
+		err = map->ops->map_get_next_key(map, key, next_key);
+	else
+		err = -EOPNOTSUPP;
 	rcu_read_unlock();
 out:
 	if (err)
@@ -2037,7 +2040,10 @@  int generic_map_lookup_batch(struct bpf_map *map,
 
 	for (cp = 0; cp < max_count;) {
 		rcu_read_lock();
-		err = map->ops->map_get_next_key(map, prev_key, key);
+		if (map->ops->map_get_next_key)
+			err = map->ops->map_get_next_key(map, prev_key, key);
+		else
+			err = -EOPNOTSUPP;
 		rcu_read_unlock();
 		if (err)
 			break;