Sockmap copying
Subsystems (8)
cover Sockmap copying
Enable calling map_update_elem on sockmaps from bpf_iter context. This in turn allows us to copy a sockmap by iterating its elements.
The change itself is tiny, all thanks to the ground work from Martin, whose series [1] this patch is based on. I updated the tests to do some copying, and also included two cleanups.
I'm sending this out now rather than when Martin's series has landed because I hope this can get in before the merge window (potentially) closes this weekend.
1: https://lore.kernel.org/bpf/[email protected]/
Lorenz Bauer (4):
bpf: sockmap: enable map_update_elem from bpf_iter
selftests: bpf: Add helper to compare socket cookies
bpf: selftests: remove shared header from sockmap iter test
selftest: bpf: Test copying a sockmap and sockhash
kernel/bpf/verifier.c | 2 +- net/core/sock_map.c | 3 + .../selftests/bpf/prog_tests/sockmap_basic.c | 100 +++++++++++------- .../selftests/bpf/progs/bpf_iter_sockmap.c | 32 ++++-- .../selftests/bpf/progs/bpf_iter_sockmap.h | 3 - 5 files changed, 90 insertions(+), 50 deletions(-) delete mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_sockmap.h
Signature · 1 line
2.25.1
PATCH 2/4 selftests: bpf: Add helper to compare socket cookies
We compare socket cookies to ensure that insertion into a sockmap worked. Pull this out into a helper function for use in other tests.
--- .../selftests/bpf/prog_tests/sockmap_basic.c | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-)
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +36 -14
@@ -50,6 +50,37 @@ static int connected_socket_v4(void)return -1 ; } +static void compare_cookies (struct bpf_map *src,struct bpf_map *dst) +{ +__u32 i, max_entries =bpf_map__max_entries (src); +int err, duration, src_fd, dst_fd; + + src_fd =bpf_map__fd (src); + dst_fd =bpf_map__fd (dst); + +for (i =0 ; i < max_entries; i++) { +__u64 src_cookie, dst_cookie; + + err =bpf_map_lookup_elem (src_fd, &i, &src_cookie); +if (err && errno ==ENOENT ) { + err =bpf_map_lookup_elem (dst_fd, &i, &dst_cookie); +CHECK (!err,"map_lookup_elem(dst)" ,"element %u not deleted\n" , i); +CHECK (err && errno !=ENOENT ,"map_lookup_elem(dst)" ,"%s\n" , +strerror (errno)); +continue ; + } +if (CHECK (err,"lookup_elem(src)" ,"%s\n" ,strerror (errno))) +continue ; + + err =bpf_map_lookup_elem (dst_fd, &i, &dst_cookie); +if (CHECK (err,"lookup_elem(dst)" ,"%s\n" ,strerror (errno))) +continue ; + +CHECK (dst_cookie != src_cookie,"cookie mismatch" , +"%llu != %llu (pos %u)\n" , dst_cookie, src_cookie, i); + } +} +/* Create a map, populate it with one socket, and free the map. */ static void test_sockmap_create_update_free (enum bpf_map_type map_type) {
@@ -109,9 +140,9 @@ static void test_skmsg_helpers(enum bpf_map_type map_type)static void test_sockmap_update (enum bpf_map_type map_type) {struct bpf_prog_test_run_attr tattr; -int err, prog, src, dst, duration =0 ; +int err, prog, src, duration =0 ;struct test_sockmap_update *skel; -__u64 src_cookie, dst_cookie; +struct bpf_map *dst_map;const __u32 zero =0 ;char dummy[14 ] = {0 };__s64 sk;
@@ -127,18 +158,14 @@ static void test_sockmap_update(enum bpf_map_type map_type) prog =bpf_program__fd (skel->progs.copy_sock_map); src =bpf_map__fd (skel->maps.src);if (map_type ==BPF_MAP_TYPE_SOCKMAP ) - dst =bpf_map__fd (skel->maps.dst_sock_map); + dst_map = skel->maps.dst_sock_map;else - dst =bpf_map__fd (skel->maps.dst_sock_hash); + dst_map = skel->maps.dst_sock_hash; err =bpf_map_update_elem (src, &zero, &sk,BPF_NOEXIST );if (CHECK (err,"update_elem(src)" ,"errno=%u\n" , errno)) goto out; - err =bpf_map_lookup_elem (src, &zero, &src_cookie); -if (CHECK (err,"lookup_elem(src, cookie)" ,"errno=%u\n" , errno)) - goto out; - tattr = (struct bpf_prog_test_run_attr ){ .prog_fd = prog, .repeat =1 ,
@@ -151,12 +178,7 @@ static void test_sockmap_update(enum bpf_map_type map_type) "errno=%u retval=%u\n", errno, tattr.retval)) goto out; - err =bpf_map_lookup_elem (dst, &zero, &dst_cookie); -if (CHECK (err,"lookup_elem(dst, cookie)" ,"errno=%u\n" , errno)) - goto out; - -CHECK (dst_cookie != src_cookie,"cookie mismatch" ,"%llu != %llu\n" , - dst_cookie, src_cookie); +compare_cookies (skel->maps.src, dst_map); out:test_sockmap_update__destroy (skel);
Signature · 1 line
2.25.1
PATCH 1/4 bpf: sockmap: enable map_update_elem from bpf_iter
In reply to Lorenz BauerAllow passing a pointer to a BTF struct sock_common* when updating a sockmap or sockhash. Since BTF pointers can fault and therefore be NULL at runtime we need to add an additional !sk check to sock_map_update_elem. Doing this allows calling map_update_elem on sockmap from bpf_iter context, which uses BTF pointers.
--- kernel/bpf/verifier.c | 2 +- net/core/sock_map.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -3943,7 +3943,7 @@ static int resolve_map_arg_type(struct bpf_verifier_env *env,case BPF_MAP_TYPE_SOCKMAP :case BPF_MAP_TYPE_SOCKHASH :if (*arg_type ==ARG_PTR_TO_MAP_VALUE ) { - *arg_type =ARG_PTR_TO_SOCKET ; + *arg_type =ARG_PTR_TO_BTF_ID_SOCK_COMMON ; }else {verbose (env,"invalid arg_type for sockmap/sockhash\n" );return -EINVAL ;
net/core/sock_map.c +3 -0
@@ -610,6 +610,9 @@ static int sock_map_update_elem(struct bpf_map *map, void *key,struct sock *sk = (struct sock *)value;int ret; +if (unlikely (!sk)) +return -EINVAL ; +if (!sock_map_sk_is_suitable (sk))return -EOPNOTSUPP ;
Signature · 1 line
2.25.1
PATCH 3/4 bpf: selftests: remove shared header from sockmap iter test
In reply to Lorenz BauerThe shared header to define SOCKMAP_MAX_ENTRIES is a bit overkill. Dynamically allocate the sock_fd array based on bpf_map__max_entries instead.
--- .../selftests/bpf/prog_tests/sockmap_basic.c | 36 +++++++++---------- .../selftests/bpf/progs/bpf_iter_sockmap.c | 5 ++- .../selftests/bpf/progs/bpf_iter_sockmap.h | 3 -- 3 files changed, 20 insertions(+), 24 deletions(-) delete mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_sockmap.h
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +18 -18
@@ -8,8 +8,6 @@#include "test_sockmap_invalid_update.skel.h" #include "bpf_iter_sockmap.skel.h" -#include "progs/bpf_iter_sockmap.h" -#define TCP_REPAIR 19/* TCP sock is under repair right now */ #define TCP_REPAIR_ON 1
@@ -201,9 +199,9 @@ static void test_sockmap_iter(enum bpf_map_type map_type)DECLARE_LIBBPF_OPTS (bpf_iter_attach_opts, opts);int err, len, src_fd, iter_fd, duration =0 ;union bpf_iter_link_info linfo = {0 }; -__s64 sock_fd[SOCKMAP_MAX_ENTRIES ]; -__u32 i, num_sockets, max_elems; +__u32 i, num_sockets, num_elems;struct bpf_iter_sockmap *skel; +__s64 *sock_fd =NULL ;struct bpf_link *link;struct bpf_map *src;char buf[64 ];
@@ -212,22 +210,23 @@ static void test_sockmap_iter(enum bpf_map_type map_type)if (CHECK (!skel,"bpf_iter_sockmap__open_and_load" ,"skeleton open_and_load failed\n" ))return ; -for (i =0 ; i <ARRAY_SIZE (sock_fd); i++) - sock_fd[i] =-1 ; - -/* Make sure we have at least one "empty" entry to test iteration of -* an empty slot. -*/ - num_sockets =ARRAY_SIZE (sock_fd) -1 ; -if (map_type ==BPF_MAP_TYPE_SOCKMAP ) { src = skel->maps.sockmap; - max_elems =bpf_map__max_entries (src); + num_elems =bpf_map__max_entries (src); + num_sockets = num_elems -1 ; }else { src = skel->maps.sockhash; - max_elems = num_sockets; + num_elems =bpf_map__max_entries (src) -1 ; + num_sockets = num_elems; } + sock_fd =calloc (num_sockets,sizeof (*sock_fd)); +if (CHECK (!sock_fd,"calloc(sock_fd)" ,"failed to allocate\n" )) + goto out; + +for (i =0 ; i < num_sockets; i++) + sock_fd[i] =-1 ; + src_fd =bpf_map__fd (src);for (i =0 ; i < num_sockets; i++) {
@@ -258,8 +257,8 @@ static void test_sockmap_iter(enum bpf_map_type map_type) goto close_iter;/* test results */ -if (CHECK (skel->bss->elems != max_elems,"elems" ,"got %u expected %u\n" , - skel->bss->elems, max_elems)) +if (CHECK (skel->bss->elems != num_elems,"elems" ,"got %u expected %u\n" , + skel->bss->elems, num_elems)) goto close_iter; if (CHECK(skel->bss->socks != num_sockets, "socks", "got %u expected %u\n",
@@ -271,10 +270,11 @@ static void test_sockmap_iter(enum bpf_map_type map_type) free_link:bpf_link__destroy (link); out: -for (i =0 ; i < num_sockets; i++) { +for (i =0 ; sock_fd && i < num_sockets; i++)if (sock_fd[i] >=0 )close (sock_fd[i]); - } +if (sock_fd) +free (sock_fd);bpf_iter_sockmap__destroy (skel); }
tools/testing/selftests/bpf/progs/bpf_iter_sockmap.c +2 -3
@@ -2,7 +2,6 @@/* Copyright (c) 2020 Cloudflare */ #include "bpf_iter.h" #include "bpf_tracing_net.h" -#include "bpf_iter_sockmap.h" #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> #include <errno.h>
@@ -11,14 +10,14 @@ char _license[] SEC("license") = "GPL";struct { __uint(type, BPF_MAP_TYPE_SOCKMAP); - __uint(max_entries, SOCKMAP_MAX_ENTRIES); + __uint(max_entries, 64); __type(key, __u32); __type(value, __u64); } sockmap SEC(".maps");struct { __uint(type, BPF_MAP_TYPE_SOCKHASH); - __uint(max_entries, SOCKMAP_MAX_ENTRIES); + __uint(max_entries, 64); __type(key, __u32); __type(value, __u64); } sockhash SEC(".maps");
tools/testing/selftests/bpf/progs/bpf_iter_sockmap.h deleted +0 -3
@@ -1,3 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#define SOCKMAP_MAX_ENTRIES (64)
Signature · 1 line
2.25.1
PATCH 4/4 selftest: bpf: Test copying a sockmap and sockhash
In reply to Lorenz BauerSince we can now call map_update_elem(sockmap) from bpf_iter context it's possible to copy a sockmap or sockhash in the kernel. Add a selftest which exercises this.
--- .../selftests/bpf/prog_tests/sockmap_basic.c | 14 +++++----- .../selftests/bpf/progs/bpf_iter_sockmap.c | 27 +++++++++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-)
tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +8 -6
@@ -194,7 +194,7 @@ static void test_sockmap_invalid_update(void)test_sockmap_invalid_update__destroy (skel); } -static void test_sockmap_iter (enum bpf_map_type map_type) +static void test_sockmap_copy (enum bpf_map_type map_type) {DECLARE_LIBBPF_OPTS (bpf_iter_attach_opts, opts);int err, len, src_fd, iter_fd, duration =0 ;
@@ -242,7 +242,7 @@ static void test_sockmap_iter(enum bpf_map_type map_type) linfo.map.map_fd = src_fd; opts.link_info = &linfo; opts.link_info_len =sizeof (linfo); - link =bpf_program__attach_iter (skel->progs.count_elems, &opts); + link =bpf_program__attach_iter (skel->progs.copy, &opts);if (CHECK (IS_ERR (link),"attach_iter" ,"attach_iter failed\n" )) goto out;
@@ -265,6 +265,8 @@ static void test_sockmap_iter(enum bpf_map_type map_type) skel->bss->socks, num_sockets)) goto close_iter; +compare_cookies (src, skel->maps.dst); + close_iter:close (iter_fd); free_link:
@@ -294,8 +296,8 @@ void test_sockmap_basic(void)test_sockmap_update (BPF_MAP_TYPE_SOCKHASH );if (test__start_subtest ("sockmap update in unsafe context" ))test_sockmap_invalid_update (); -if (test__start_subtest ("sockmap iter" )) -test_sockmap_iter (BPF_MAP_TYPE_SOCKMAP ); -if (test__start_subtest ("sockhash iter" )) -test_sockmap_iter (BPF_MAP_TYPE_SOCKHASH ); +if (test__start_subtest ("sockmap copy" )) +test_sockmap_copy (BPF_MAP_TYPE_SOCKMAP ); +if (test__start_subtest ("sockhash copy" )) +test_sockmap_copy (BPF_MAP_TYPE_SOCKHASH ); }
tools/testing/selftests/bpf/progs/bpf_iter_sockmap.c +22 -5
@@ -22,21 +22,38 @@ struct {__type (value, __u64); } sockhash SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_SOCKHASH); + __uint(max_entries, 64); + __type(key, __u32); + __type(value, __u64); +} dst SEC(".maps"); +__u32 elems =0 ;__u32 socks =0 ; SEC("iter/sockmap") -int count_elems (struct bpf_iter__sockmap *ctx) +int copy (struct bpf_iter__sockmap *ctx) {struct sock *sk = ctx->sk;__u32 tmp, *key = ctx->key;int ret; -if (key) - elems++; +if (!key) +return 0 ; -if (sk) + elems++; + +/* We need a temporary buffer on the stack, since the verifier doesn't +* let us use the pointer from the context as an argument to the helper. +*/ + tmp = *key; + +if (sk) { socks++; +return bpf_map_update_elem (&dst, &tmp, sk,0 ) !=0 ; + } -return 0 ; + ret =bpf_map_delete_elem (&dst, &tmp); +return ret && ret != -ENOENT ; }
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH bpf-next 1/4] bpf: sockmap: enable map_update_elem from bpf_iter
In reply to Lorenz BauerI love your patch! Yet something to improve:
Hi Lorenz,
I love your patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Lorenz-Bauer/Sockmap-copying/20200925-175852 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: xtensa-allyesconfig (attached as .config) compiler: xtensa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/8021d25b95546c5e69261c6083c6eed8909caffd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Lorenz-Bauer/Sockmap-copying/20200925-175852 git checkout 8021d25b95546c5e69261c6083c6eed8909caffd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=xtensa
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
kernel/bpf/verifier.c: In function 'resolve_map_arg_type':
>> kernel/bpf/verifier.c:3941:16: error: 'ARG_PTR_TO_BTF_ID_SOCK_COMMON' undeclared (first use in this function); did you mean 'ARG_PTR_TO_SOCK_COMMON'?
3941 | *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ARG_PTR_TO_SOCK_COMMON
kernel/bpf/verifier.c:3941:16: note: each undeclared identifier is reported only once for each function it appears in
In file included from include/linux/bpf_verifier.h:8,
from kernel/bpf/verifier.c:12:
kernel/bpf/verifier.c: In function 'jit_subprogs':
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'unsigned int (*)(const void *, const struct bpf_insn *)' to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10435:16: note: in expansion of macro 'BPF_CAST_CALL'
10435 | insn->imm = BPF_CAST_CALL(func[subprog]->bpf_func) -
| ^~~~~~~~~~~~~
kernel/bpf/verifier.c: In function 'fixup_bpf_calls':
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'void * (* const)(struct bpf_map *, void *)' to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10826:17: note: in expansion of macro 'BPF_CAST_CALL'
10826 | insn->imm = BPF_CAST_CALL(ops->map_lookup_elem) -
| ^~~~~~~~~~~~~
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'int (* const)(struct bpf_map *, void *, void *, u64)' {aka 'int (* const)(struct bpf_map *, void *, void *, long long unsigned int)'} to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10830:17: note: in expansion of macro 'BPF_CAST_CALL'
10830 | insn->imm = BPF_CAST_CALL(ops->map_update_elem) -
| ^~~~~~~~~~~~~
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'int (* const)(struct bpf_map *, void *)' to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10834:17: note: in expansion of macro 'BPF_CAST_CALL'
10834 | insn->imm = BPF_CAST_CALL(ops->map_delete_elem) -
| ^~~~~~~~~~~~~
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'int (* const)(struct bpf_map *, void *, u64)' {aka 'int (* const)(struct bpf_map *, void *, long long unsigned int)'} to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10838:17: note: in expansion of macro 'BPF_CAST_CALL'
10838 | insn->imm = BPF_CAST_CALL(ops->map_push_elem) -
| ^~~~~~~~~~~~~
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'int (* const)(struct bpf_map *, void *)' to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10842:17: note: in expansion of macro 'BPF_CAST_CALL'
10842 | insn->imm = BPF_CAST_CALL(ops->map_pop_elem) -
| ^~~~~~~~~~~~~
include/linux/filter.h:345:4: warning: cast between incompatible function types from 'int (* const)(struct bpf_map *, void *)' to 'u64 (*)(u64, u64, u64, u64, u64)' {aka 'long long unsigned int (*)(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'} [-Wcast-function-type]
345 | ((u64 (*)(u64, u64, u64, u64, u64))(x))
| ^
kernel/bpf/verifier.c:10846:17: note: in expansion of macro 'BPF_CAST_CALL'
10846 | insn->imm = BPF_CAST_CALL(ops->map_peek_elem) -
| ^~~~~~~~~~~~~vim +3941 kernel/bpf/verifier.c
3926
3927 static int resolve_map_arg_type(struct bpf_verifier_env *env,
3928 const struct bpf_call_arg_meta *meta,
3929 enum bpf_arg_type *arg_type)
3930 {
3931 if (!meta->map_ptr) {
3932 /* kernel subsystem misconfigured verifier */
3933 verbose(env, "invalid map_ptr to access map->type\n");
3934 return -EACCES;
3935 }
3936
3937 switch (meta->map_ptr->map_type) {
3938 case BPF_MAP_TYPE_SOCKMAP:
3939 case BPF_MAP_TYPE_SOCKHASH:
3940 if (*arg_type == ARG_PTR_TO_MAP_VALUE) {
> 3941 *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON;
3942 } else {
3943 verbose(env, "invalid arg_type for sockmap/sockhash\n");
3944 return -EINVAL;
3945 }
3946 break;
3947
3948 default:
3949 break;
3950 }
3951 return 0;
3952 }
3953
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH bpf-next 1/4] bpf: sockmap: enable map_update_elem from bpf_iter
In reply to Lorenz BauerI love your patch! Yet something to improve:
Hi Lorenz,
I love your patch! Yet something to improve:
[auto build test ERROR on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Lorenz-Bauer/Sockmap-copying/20200925-175852 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: arm-randconfig-r023-20200925 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c32e69b2ce7abfb151a87ba363ac9e25abf7d417)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/8021d25b95546c5e69261c6083c6eed8909caffd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Lorenz-Bauer/Sockmap-copying/20200925-175852 git checkout 8021d25b95546c5e69261c6083c6eed8909caffd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> kernel/bpf/verifier.c:3941:16: error: use of undeclared identifier 'ARG_PTR_TO_BTF_ID_SOCK_COMMON'; did you mean 'ARG_PTR_TO_SOCK_COMMON'?
*arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ARG_PTR_TO_SOCK_COMMON include/linux/bpf.h:286:2: note: 'ARG_PTR_TO_SOCK_COMMON' declared here
ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */ ^
1 error generated.
vim +3941 kernel/bpf/verifier.c
3926
3927 static int resolve_map_arg_type(struct bpf_verifier_env *env,
3928 const struct bpf_call_arg_meta *meta,
3929 enum bpf_arg_type *arg_type)
3930 {
3931 if (!meta->map_ptr) {
3932 /* kernel subsystem misconfigured verifier */
3933 verbose(env, "invalid map_ptr to access map->type\n");
3934 return -EACCES;
3935 }
3936
3937 switch (meta->map_ptr->map_type) {
3938 case BPF_MAP_TYPE_SOCKMAP:
3939 case BPF_MAP_TYPE_SOCKHASH:
3940 if (*arg_type == ARG_PTR_TO_MAP_VALUE) {
> 3941 *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON;
3942 } else {
3943 verbose(env, "invalid arg_type for sockmap/sockhash\n");
3944 return -EINVAL;
3945 }
3946 break;
3947
3948 default:
3949 break;
3950 }
3951 return 0;
3952 }
3953
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH bpf-next 1/4] bpf: sockmap: enable map_update_elem from bpf_iter
In reply to Lorenz BauerOn Fri, Sep 25, 2020 at 10:56:27AM +0100, Lorenz Bauer wrote:
[ ... ]
net/core/sock_map.c static int sock_map_update_elem(struct bpf_map *map, void *key, · line 613
Quoted 9 lines
net/core/sock_map.c +1
-0@@ -610,6 +610,9 @@ static int sock_map_update_elem(struct bpf_map *map, void *key,struct sock *sk = (struct sock *)value;int ret; +if (unlikely (!sk))
sk_fullsock(sk) test is also needed.
net/core/sock_map.c static int sock_map_update_elem(struct bpf_map *map, void *key, · line 616
Quoted 4 lines
net/core/sock_map.c +2
-0+return -EINVAL ; +if (!sock_map_sk_is_suitable (sk))
sk->sk_type is used in sock_map_sk_is_suitable().sk_type is not in sock_common.
Re: [PATCH bpf-next 1/4] bpf: sockmap: enable map_update_elem from bpf_iter
Quoted 10 lines · Martin KaFai Lau
Quoted 2 lines
+ if (unlikely(!sk))
sk_fullsock(sk)test is also needed.net/core/sock_map.c static int sock_map_update_elem(struct bpf_map *map, void *key, · line 616
Quoted 4 lines
net/core/sock_map.c +2
-0+return -EINVAL ; +if (!sock_map_sk_is_suitable (sk))
sk->sk_typeis used insock_map_sk_is_suitable().sk_typeis not insock_common.
Oh my, thanks!
Signature · 4 lines
Lorenz Bauer | Systems Engineer 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK www.cloudflare.com