* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests
@ 2022-01-22 9:03 kernel test robot
2022-01-22 8:58 ` [PATCH] selftests/bpf: fix flexible_array.cocci warnings kernel test robot
0 siblings, 1 reply; 10+ messages in thread
From: kernel test robot @ 2022-01-22 9:03 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 1325 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220114163953.1455836-10-memxor@gmail.com>
References: <20220114163953.1455836-10-memxor@gmail.com>
TO: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Hi Kumar,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Kumar-Kartikeya-Dwivedi/Introduce-unstable-CT-lookup-helpers/20220115-004219
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 8 days ago
:::::: commit date: 8 days ago
config: x86_64-randconfig-c022-20220117 (https://download.01.org/0day-ci/archive/20220122/202201221618.3iotxtfv-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> net/bpf/test_run.c:296:6-10: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH] selftests/bpf: fix flexible_array.cocci warnings 2022-01-22 9:03 [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests kernel test robot @ 2022-01-22 8:58 ` kernel test robot 0 siblings, 0 replies; 10+ messages in thread From: kernel test robot @ 2022-01-22 8:58 UTC (permalink / raw) To: kbuild [-- Attachment #1: Type: text/plain, Size: 1453 bytes --] CC: kbuild-all(a)lists.01.org In-Reply-To: <20220114163953.1455836-10-memxor@gmail.com> References: <20220114163953.1455836-10-memxor@gmail.com> TO: Kumar Kartikeya Dwivedi <memxor@gmail.com> From: kernel test robot <lkp@intel.com> net/bpf/test_run.c:296:6-10: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays) Zero-length and one-element arrays are deprecated, see Documentation/process/deprecated.rst Flexible-array members should be used instead. Generated by: scripts/coccinelle/misc/flexible_array.cocci CC: Kumar Kartikeya Dwivedi <memxor@gmail.com> Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: kernel test robot <lkp@intel.com> --- url: https://github.com/0day-ci/linux/commits/Kumar-Kartikeya-Dwivedi/Introduce-unstable-CT-lookup-helpers/20220115-004219 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master :::::: branch date: 8 days ago :::::: commit date: 8 days ago Please take the patch only if it's a positive warning. Thanks! test_run.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -293,7 +293,7 @@ struct prog_test_fail2 { struct prog_test_fail3 { int len; char arr1[2]; - char arr2[0]; + char arr2[]; }; noinline void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests
@ 2022-02-09 2:27 kernel test robot
0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2022-02-09 2:27 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220114163953.1455836-10-memxor@gmail.com>
References: <20220114163953.1455836-10-memxor@gmail.com>
TO: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Hi Kumar,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Kumar-Kartikeya-Dwivedi/Introduce-unstable-CT-lookup-helpers/20220115-004219
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 4 weeks ago
:::::: commit date: 4 weeks ago
config: x86_64-randconfig-c022-20220117 (https://download.01.org/0day-ci/archive/20220209/202202091058.J42UnQfr-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> net/bpf/test_run.c:296:6-10: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests
@ 2022-02-07 20:43 kernel test robot
0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2022-02-07 20:43 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220114163953.1455836-10-memxor@gmail.com>
References: <20220114163953.1455836-10-memxor@gmail.com>
TO: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Hi Kumar,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Kumar-Kartikeya-Dwivedi/Introduce-unstable-CT-lookup-helpers/20220115-004219
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 3 weeks ago
:::::: commit date: 3 weeks ago
config: x86_64-randconfig-c022-20220117 (https://download.01.org/0day-ci/archive/20220208/202202080402.OAVS4oRI-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> net/bpf/test_run.c:296:6-10: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests
@ 2022-01-26 2:28 kernel test robot
0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2022-01-26 2:28 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 1327 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220114163953.1455836-10-memxor@gmail.com>
References: <20220114163953.1455836-10-memxor@gmail.com>
TO: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Hi Kumar,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Kumar-Kartikeya-Dwivedi/Introduce-unstable-CT-lookup-helpers/20220115-004219
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 11 days ago
:::::: commit date: 11 days ago
config: x86_64-randconfig-c022-20220117 (https://download.01.org/0day-ci/archive/20220126/202201260919.EU2zNroM-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> net/bpf/test_run.c:296:6-10: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests
@ 2022-01-18 14:57 kernel test robot
0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2022-01-18 14:57 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 1325 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220114163953.1455836-10-memxor@gmail.com>
References: <20220114163953.1455836-10-memxor@gmail.com>
TO: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Hi Kumar,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
url: https://github.com/0day-ci/linux/commits/Kumar-Kartikeya-Dwivedi/Introduce-unstable-CT-lookup-helpers/20220115-004219
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: x86_64-randconfig-c022-20220117 (https://download.01.org/0day-ci/archive/20220118/202201182215.eXTopxlT-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
cocci warnings: (new ones prefixed by >>)
>> net/bpf/test_run.c:296:6-10: WARNING use flexible-array member instead (https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays)
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH bpf-next v8 00/10] Introduce unstable CT lookup helpers @ 2022-01-14 16:39 Kumar Kartikeya Dwivedi 2022-01-14 16:39 ` [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests Kumar Kartikeya Dwivedi 0 siblings, 1 reply; 10+ messages in thread From: Kumar Kartikeya Dwivedi @ 2022-01-14 16:39 UTC (permalink / raw) To: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, netdev, netfilter-devel Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, Maxim Mikityanskiy, Pablo Neira Ayuso, Florian Westphal, Jesper Dangaard Brouer, Toke Høiland-Jørgensen This series adds unstable conntrack lookup helpers using BPF kfunc support. The patch adding the lookup helper is based off of Maxim's recent patch to aid in rebasing their series on top of this, all adjusted to work with module kfuncs [0]. [0]: https://lore.kernel.org/bpf/20211019144655.3483197-8-maximmi@nvidia.com To enable returning a reference to struct nf_conn, the verifier is extended to support reference tracking for PTR_TO_BTF_ID, and kfunc is extended with support for working as acquire/release functions, similar to existing BPF helpers. kfunc returning pointer (limited to PTR_TO_BTF_ID in the kernel) can also return a PTR_TO_BTF_ID_OR_NULL now, typically needed when acquiring a resource can fail. kfunc can also receive PTR_TO_CTX and PTR_TO_MEM (with some limitations) as arguments now. There is also support for passing a mem, len pair as argument to kfunc now. In such cases, passing pointer to unsized type (void) is also permitted. Please see individual commits for details. Changelog: ---------- v7 -> v8: v7: https://lore.kernel.org/bpf/20220111180428.931466-1-memxor@gmail.com * Move enum btf_kfunc_hook to btf.c (Alexei) * Drop verbose log for unlikely failure case in __find_kfunc_desc_btf (Alexei) * Remove unnecessary barrier in register_btf_kfunc_id_set (Alexei) * Switch macro in bpf_nf test to __always_inline function (Alexei) v6 -> v7: v6: https://lore.kernel.org/bpf/20220102162115.1506833-1-memxor@gmail.com * Drop try_module_get_live patch, use flag in btf_module struct (Alexei) * Add comments and expand commit message detailing why we have to concatenate and sort vmlinux kfunc BTF ID sets (Alexei) * Use bpf_testmod for testing btf_try_get_module race (Alexei) * Use bpf_prog_type for both btf_kfunc_id_set_contains and register_btf_kfunc_id_set calls (Alexei) * In case of module set registration, directly assign set (Alexei) * Add CONFIG_USERFAULTFD=y to selftest config * Fix other nits v5 -> v6: v5: https://lore.kernel.org/bpf/20211230023705.3860970-1-memxor@gmail.com * Fix for a bug in btf_try_get_module leading to use-after-free * Drop *kallsyms_on_each_symbol loop, reinstate register_btf_kfunc_id_set (Alexei) * btf_free_kfunc_set_tab now takes struct btf, and handles resetting tab to NULL * Check return value btf_name_by_offset for param_name * Instead of using tmp_set, use btf->kfunc_set_tab directly, and simplify cleanup v4 -> v5: v4: https://lore.kernel.org/bpf/20211217015031.1278167-1-memxor@gmail.com * Move nf_conntrack helpers code to its own separate file (Toke, Pablo) * Remove verifier callbacks, put btf_id_sets in struct btf (Alexei) * Convert the in-kernel users away from the old API * Change len__ prefix convention to __sz suffix (Alexei) * Drop parent_ref_obj_id patch (Alexei) v3 -> v4: v3: https://lore.kernel.org/bpf/20211210130230.4128676-1-memxor@gmail.com * Guard unstable CT helpers with CONFIG_DEBUG_INFO_BTF_MODULES * Move addition of prog_test test kfuncs to selftest commit * Move negative kfunc tests to test_verifier suite * Limit struct nesting depth to 4, which should be enough for now v2 -> v3: v2: https://lore.kernel.org/bpf/20211209170929.3485242-1-memxor@gmail.com * Fix build error for !CONFIG_BPF_SYSCALL (Patchwork) RFC v1 -> v2: v1: https://lore.kernel.org/bpf/20211030144609.263572-1-memxor@gmail.com * Limit PTR_TO_MEM support to pointer to scalar, or struct with scalars (Alexei) * Use btf_id_set for checking acquire, release, ret type null (Alexei) * Introduce opts struct for CT helpers, move int err parameter to it * Add l4proto as parameter to CT helper's opts, remove separate tcp/udp helpers * Add support for mem, len argument pair to kfunc * Allow void * as pointer type for mem, len argument pair * Extend selftests to cover new additions to kfuncs * Copy ref_obj_id to PTR_TO_BTF_ID dst_reg on btf_struct_access, test it * Fix other misc nits, bugs, and expand commit messages Kumar Kartikeya Dwivedi (10): bpf: Fix UAF due to race between btf_try_get_module and load_module bpf: Populate kfunc BTF ID sets in struct btf bpf: Remove check_kfunc_call callback and old kfunc BTF ID API bpf: Introduce mem, size argument pair support for kfunc bpf: Add reference tracking support to kfunc net/netfilter: Add unstable CT lookup helpers for XDP and TC-BPF selftests/bpf: Add test for unstable CT lookup API selftests/bpf: Add test_verifier support to fixup kfunc call insns selftests/bpf: Extend kfunc selftests selftests/bpf: Add test for race in btf_try_get_module include/linux/bpf.h | 8 - include/linux/bpf_verifier.h | 7 + include/linux/btf.h | 75 ++-- include/linux/btf_ids.h | 13 +- include/net/netfilter/nf_conntrack_bpf.h | 23 ++ kernel/bpf/btf.c | 368 ++++++++++++++++-- kernel/bpf/verifier.c | 196 ++++++---- net/bpf/test_run.c | 150 ++++++- net/core/filter.c | 1 - net/core/net_namespace.c | 1 + net/ipv4/bpf_tcp_ca.c | 22 +- net/ipv4/tcp_bbr.c | 18 +- net/ipv4/tcp_cubic.c | 17 +- net/ipv4/tcp_dctcp.c | 18 +- net/netfilter/Makefile | 5 + net/netfilter/nf_conntrack_bpf.c | 257 ++++++++++++ net/netfilter/nf_conntrack_core.c | 8 + .../selftests/bpf/bpf_testmod/bpf_testmod.c | 21 +- tools/testing/selftests/bpf/config | 5 + .../selftests/bpf/prog_tests/bpf_mod_race.c | 230 +++++++++++ .../testing/selftests/bpf/prog_tests/bpf_nf.c | 48 +++ .../selftests/bpf/prog_tests/kfunc_call.c | 6 + .../selftests/bpf/progs/bpf_mod_race.c | 100 +++++ .../selftests/bpf/progs/kfunc_call_race.c | 14 + .../selftests/bpf/progs/kfunc_call_test.c | 52 ++- tools/testing/selftests/bpf/progs/ksym_race.c | 13 + .../testing/selftests/bpf/progs/test_bpf_nf.c | 109 ++++++ tools/testing/selftests/bpf/test_verifier.c | 28 ++ tools/testing/selftests/bpf/verifier/calls.c | 75 ++++ 29 files changed, 1674 insertions(+), 214 deletions(-) create mode 100644 include/net/netfilter/nf_conntrack_bpf.h create mode 100644 net/netfilter/nf_conntrack_bpf.c create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_mod_race.c create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_nf.c create mode 100644 tools/testing/selftests/bpf/progs/bpf_mod_race.c create mode 100644 tools/testing/selftests/bpf/progs/kfunc_call_race.c create mode 100644 tools/testing/selftests/bpf/progs/ksym_race.c create mode 100644 tools/testing/selftests/bpf/progs/test_bpf_nf.c -- 2.34.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests 2022-01-14 16:39 [PATCH bpf-next v8 00/10] Introduce unstable CT lookup helpers Kumar Kartikeya Dwivedi @ 2022-01-14 16:39 ` Kumar Kartikeya Dwivedi 2022-05-26 1:22 ` Benjamin Poirier 0 siblings, 1 reply; 10+ messages in thread From: Kumar Kartikeya Dwivedi @ 2022-01-14 16:39 UTC (permalink / raw) To: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, netdev, netfilter-devel Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, Maxim Mikityanskiy, Pablo Neira Ayuso, Florian Westphal, Jesper Dangaard Brouer, Toke Høiland-Jørgensen Use the prog_test kfuncs to test the referenced PTR_TO_BTF_ID kfunc support, and PTR_TO_CTX, PTR_TO_MEM argument passing support. Also testing the various failure cases for invalid kfunc prototypes. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> --- net/bpf/test_run.c | 129 +++++++++++++++++- .../selftests/bpf/prog_tests/kfunc_call.c | 6 + .../selftests/bpf/progs/kfunc_call_test.c | 52 ++++++- tools/testing/selftests/bpf/verifier/calls.c | 75 ++++++++++ 4 files changed, 258 insertions(+), 4 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 7796a8c747a0..93ba56507240 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -233,6 +233,105 @@ struct sock * noinline bpf_kfunc_call_test3(struct sock *sk) return sk; } +struct prog_test_ref_kfunc { + int a; + int b; + struct prog_test_ref_kfunc *next; +}; + +static struct prog_test_ref_kfunc prog_test_struct = { + .a = 42, + .b = 108, + .next = &prog_test_struct, +}; + +noinline struct prog_test_ref_kfunc * +bpf_kfunc_call_test_acquire(unsigned long *scalar_ptr) +{ + /* randomly return NULL */ + if (get_jiffies_64() % 2) + return NULL; + return &prog_test_struct; +} + +noinline void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) +{ +} + +struct prog_test_pass1 { + int x0; + struct { + int x1; + struct { + int x2; + struct { + int x3; + }; + }; + }; +}; + +struct prog_test_pass2 { + int len; + short arr1[4]; + struct { + char arr2[4]; + unsigned long arr3[8]; + } x; +}; + +struct prog_test_fail1 { + void *p; + int x; +}; + +struct prog_test_fail2 { + int x8; + struct prog_test_pass1 x; +}; + +struct prog_test_fail3 { + int len; + char arr1[2]; + char arr2[0]; +}; + +noinline void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) +{ +} + +noinline void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) +{ +} + +noinline void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) +{ +} + +noinline void bpf_kfunc_call_test_fail1(struct prog_test_fail1 *p) +{ +} + +noinline void bpf_kfunc_call_test_fail2(struct prog_test_fail2 *p) +{ +} + +noinline void bpf_kfunc_call_test_fail3(struct prog_test_fail3 *p) +{ +} + +noinline void bpf_kfunc_call_test_mem_len_pass1(void *mem, int mem__sz) +{ +} + +noinline void bpf_kfunc_call_test_mem_len_fail1(void *mem, int len) +{ +} + +noinline void bpf_kfunc_call_test_mem_len_fail2(u64 *mem, int len) +{ +} + __diag_pop(); ALLOW_ERROR_INJECTION(bpf_modify_return_test, ERRNO); @@ -241,8 +340,31 @@ BTF_SET_START(test_sk_check_kfunc_ids) BTF_ID(func, bpf_kfunc_call_test1) BTF_ID(func, bpf_kfunc_call_test2) BTF_ID(func, bpf_kfunc_call_test3) +BTF_ID(func, bpf_kfunc_call_test_acquire) +BTF_ID(func, bpf_kfunc_call_test_release) +BTF_ID(func, bpf_kfunc_call_test_pass_ctx) +BTF_ID(func, bpf_kfunc_call_test_pass1) +BTF_ID(func, bpf_kfunc_call_test_pass2) +BTF_ID(func, bpf_kfunc_call_test_fail1) +BTF_ID(func, bpf_kfunc_call_test_fail2) +BTF_ID(func, bpf_kfunc_call_test_fail3) +BTF_ID(func, bpf_kfunc_call_test_mem_len_pass1) +BTF_ID(func, bpf_kfunc_call_test_mem_len_fail1) +BTF_ID(func, bpf_kfunc_call_test_mem_len_fail2) BTF_SET_END(test_sk_check_kfunc_ids) +BTF_SET_START(test_sk_acquire_kfunc_ids) +BTF_ID(func, bpf_kfunc_call_test_acquire) +BTF_SET_END(test_sk_acquire_kfunc_ids) + +BTF_SET_START(test_sk_release_kfunc_ids) +BTF_ID(func, bpf_kfunc_call_test_release) +BTF_SET_END(test_sk_release_kfunc_ids) + +BTF_SET_START(test_sk_ret_null_kfunc_ids) +BTF_ID(func, bpf_kfunc_call_test_acquire) +BTF_SET_END(test_sk_ret_null_kfunc_ids) + static void *bpf_test_init(const union bpf_attr *kattr, u32 size, u32 headroom, u32 tailroom) { @@ -1063,8 +1185,11 @@ int bpf_prog_test_run_syscall(struct bpf_prog *prog, } static const struct btf_kfunc_id_set bpf_prog_test_kfunc_set = { - .owner = THIS_MODULE, - .check_set = &test_sk_check_kfunc_ids, + .owner = THIS_MODULE, + .check_set = &test_sk_check_kfunc_ids, + .acquire_set = &test_sk_acquire_kfunc_ids, + .release_set = &test_sk_release_kfunc_ids, + .ret_null_set = &test_sk_ret_null_kfunc_ids, }; static int __init bpf_prog_test_run_init(void) diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c index 7d7445ccc141..b39a4f09aefd 100644 --- a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c +++ b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c @@ -27,6 +27,12 @@ static void test_main(void) ASSERT_OK(err, "bpf_prog_test_run(test2)"); ASSERT_EQ(retval, 3, "test2-retval"); + prog_fd = skel->progs.kfunc_call_test_ref_btf_id.prog_fd; + err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4), + NULL, NULL, (__u32 *)&retval, NULL); + ASSERT_OK(err, "bpf_prog_test_run(test_ref_btf_id)"); + ASSERT_EQ(retval, 0, "test_ref_btf_id-retval"); + kfunc_call_test_lskel__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/kfunc_call_test.c b/tools/testing/selftests/bpf/progs/kfunc_call_test.c index 8a8cf59017aa..5aecbb9fdc68 100644 --- a/tools/testing/selftests/bpf/progs/kfunc_call_test.c +++ b/tools/testing/selftests/bpf/progs/kfunc_call_test.c @@ -1,13 +1,20 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2021 Facebook */ -#include <linux/bpf.h> +#include <vmlinux.h> #include <bpf/bpf_helpers.h> -#include "bpf_tcp_helpers.h" extern int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __ksym; extern __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b, __u32 c, __u64 d) __ksym; +extern struct prog_test_ref_kfunc *bpf_kfunc_call_test_acquire(unsigned long *sp) __ksym; +extern void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym; +extern void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) __ksym; +extern void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym; +extern void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) __ksym; +extern void bpf_kfunc_call_test_mem_len_pass1(void *mem, int len) __ksym; +extern void bpf_kfunc_call_test_mem_len_fail2(__u64 *mem, int len) __ksym; + SEC("tc") int kfunc_call_test2(struct __sk_buff *skb) { @@ -44,4 +51,45 @@ int kfunc_call_test1(struct __sk_buff *skb) return ret; } +SEC("tc") +int kfunc_call_test_ref_btf_id(struct __sk_buff *skb) +{ + struct prog_test_ref_kfunc *pt; + unsigned long s = 0; + int ret = 0; + + pt = bpf_kfunc_call_test_acquire(&s); + if (pt) { + if (pt->a != 42 || pt->b != 108) + ret = -1; + bpf_kfunc_call_test_release(pt); + } + return ret; +} + +SEC("tc") +int kfunc_call_test_pass(struct __sk_buff *skb) +{ + struct prog_test_pass1 p1 = {}; + struct prog_test_pass2 p2 = {}; + short a = 0; + __u64 b = 0; + long c = 0; + char d = 0; + int e = 0; + + bpf_kfunc_call_test_pass_ctx(skb); + bpf_kfunc_call_test_pass1(&p1); + bpf_kfunc_call_test_pass2(&p2); + + bpf_kfunc_call_test_mem_len_pass1(&a, sizeof(a)); + bpf_kfunc_call_test_mem_len_pass1(&b, sizeof(b)); + bpf_kfunc_call_test_mem_len_pass1(&c, sizeof(c)); + bpf_kfunc_call_test_mem_len_pass1(&d, sizeof(d)); + bpf_kfunc_call_test_mem_len_pass1(&e, sizeof(e)); + bpf_kfunc_call_test_mem_len_fail2(&b, -1); + + return 0; +} + char _license[] SEC("license") = "GPL"; diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c index d7b74eb28333..829be2b9e08e 100644 --- a/tools/testing/selftests/bpf/verifier/calls.c +++ b/tools/testing/selftests/bpf/verifier/calls.c @@ -21,6 +21,81 @@ .prog_type = BPF_PROG_TYPE_TRACEPOINT, .result = ACCEPT, }, +{ + "calls: invalid kfunc call: ptr_to_mem to struct with non-scalar", + .insns = { + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = REJECT, + .errstr = "arg#0 pointer type STRUCT prog_test_fail1 must point to scalar", + .fixup_kfunc_btf_id = { + { "bpf_kfunc_call_test_fail1", 2 }, + }, +}, +{ + "calls: invalid kfunc call: ptr_to_mem to struct with nesting depth > 4", + .insns = { + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = REJECT, + .errstr = "max struct nesting depth exceeded\narg#0 pointer type STRUCT prog_test_fail2", + .fixup_kfunc_btf_id = { + { "bpf_kfunc_call_test_fail2", 2 }, + }, +}, +{ + "calls: invalid kfunc call: ptr_to_mem to struct with FAM", + .insns = { + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = REJECT, + .errstr = "arg#0 pointer type STRUCT prog_test_fail3 must point to scalar", + .fixup_kfunc_btf_id = { + { "bpf_kfunc_call_test_fail3", 2 }, + }, +}, +{ + "calls: invalid kfunc call: reg->type != PTR_TO_CTX", + .insns = { + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = REJECT, + .errstr = "arg#0 expected pointer to ctx, but got PTR", + .fixup_kfunc_btf_id = { + { "bpf_kfunc_call_test_pass_ctx", 2 }, + }, +}, +{ + "calls: invalid kfunc call: void * not allowed in func proto without mem size arg", + .insns = { + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = REJECT, + .errstr = "arg#0 pointer type UNKNOWN must point to scalar", + .fixup_kfunc_btf_id = { + { "bpf_kfunc_call_test_mem_len_fail1", 2 }, + }, +}, { "calls: basic sanity", .insns = { -- 2.34.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests 2022-01-14 16:39 ` [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests Kumar Kartikeya Dwivedi @ 2022-05-26 1:22 ` Benjamin Poirier 2022-05-26 5:15 ` Kumar Kartikeya Dwivedi 0 siblings, 1 reply; 10+ messages in thread From: Benjamin Poirier @ 2022-05-26 1:22 UTC (permalink / raw) To: Kumar Kartikeya Dwivedi Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, netdev, netfilter-devel, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, Maxim Mikityanskiy, Pablo Neira Ayuso, Florian Westphal, Jesper Dangaard Brouer, Toke Høiland-Jørgensen On 2022-01-14 22:09 +0530, Kumar Kartikeya Dwivedi wrote: > Use the prog_test kfuncs to test the referenced PTR_TO_BTF_ID kfunc > support, and PTR_TO_CTX, PTR_TO_MEM argument passing support. Also > testing the various failure cases for invalid kfunc prototypes. > > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> > --- > net/bpf/test_run.c | 129 +++++++++++++++++- > .../selftests/bpf/prog_tests/kfunc_call.c | 6 + > .../selftests/bpf/progs/kfunc_call_test.c | 52 ++++++- > tools/testing/selftests/bpf/verifier/calls.c | 75 ++++++++++ > 4 files changed, 258 insertions(+), 4 deletions(-) > It looks like this patch broke building the bpf tests: tools/testing/selftests/bpf$ make CLNG-BPF [test_maps] kfunc_call_test.o progs/kfunc_call_test.c:13:46: error: declaration of 'struct prog_test_pass1' will not be visible outside of this function [-Werror,-Wvisibility] extern void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym; ^ The only definition of struct prog_test_pass1 that I see is in net/bpf/test_run.c. How is this supposed to work? commit 87091063df5d ("selftests/bpf: Add test for unstable CT lookup API") from the same series added a similar problem in progs/test_bpf_nf.c: progs/test_bpf_nf.c:31:21: error: variable has incomplete type 'struct bpf_ct_opts' struct bpf_ct_opts opts_def = { .l4proto = IPPROTO_TCP, .netns_id = -1 }; ^ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests 2022-05-26 1:22 ` Benjamin Poirier @ 2022-05-26 5:15 ` Kumar Kartikeya Dwivedi 2022-05-26 6:19 ` Benjamin Poirier 0 siblings, 1 reply; 10+ messages in thread From: Kumar Kartikeya Dwivedi @ 2022-05-26 5:15 UTC (permalink / raw) To: Benjamin Poirier Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, netdev, netfilter-devel, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, Maxim Mikityanskiy, Pablo Neira Ayuso, Florian Westphal, Jesper Dangaard Brouer, Toke Høiland-Jørgensen On Thu, May 26, 2022 at 06:52:59AM IST, Benjamin Poirier wrote: > On 2022-01-14 22:09 +0530, Kumar Kartikeya Dwivedi wrote: > > Use the prog_test kfuncs to test the referenced PTR_TO_BTF_ID kfunc > > support, and PTR_TO_CTX, PTR_TO_MEM argument passing support. Also > > testing the various failure cases for invalid kfunc prototypes. > > > > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> > > --- > > net/bpf/test_run.c | 129 +++++++++++++++++- > > .../selftests/bpf/prog_tests/kfunc_call.c | 6 + > > .../selftests/bpf/progs/kfunc_call_test.c | 52 ++++++- > > tools/testing/selftests/bpf/verifier/calls.c | 75 ++++++++++ > > 4 files changed, 258 insertions(+), 4 deletions(-) > > > > It looks like this patch broke building the bpf tests: > > tools/testing/selftests/bpf$ make > CLNG-BPF [test_maps] kfunc_call_test.o > progs/kfunc_call_test.c:13:46: error: declaration of 'struct prog_test_pass1' will not be visible outside of this function [-Werror,-Wvisibility] > extern void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym; > ^ > > The only definition of struct prog_test_pass1 that I see is in > net/bpf/test_run.c. How is this supposed to work? > > > commit 87091063df5d ("selftests/bpf: Add test for unstable CT lookup > API") from the same series added a similar problem in > progs/test_bpf_nf.c: > > progs/test_bpf_nf.c:31:21: error: variable has incomplete type 'struct bpf_ct_opts' > struct bpf_ct_opts opts_def = { .l4proto = IPPROTO_TCP, .netns_id = -1 }; > Both of them should have their definition in vmlinux.h. Can you check? Also for BPF selftests we require conntrack to be built into the kernel, instead of as a module. -- Kartikeya ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests 2022-05-26 5:15 ` Kumar Kartikeya Dwivedi @ 2022-05-26 6:19 ` Benjamin Poirier 0 siblings, 0 replies; 10+ messages in thread From: Benjamin Poirier @ 2022-05-26 6:19 UTC (permalink / raw) To: Kumar Kartikeya Dwivedi Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, netdev, netfilter-devel, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, Maxim Mikityanskiy, Pablo Neira Ayuso, Florian Westphal, Jesper Dangaard Brouer, Toke Høiland-Jørgensen On 2022-05-26 10:45 +0530, Kumar Kartikeya Dwivedi wrote: > On Thu, May 26, 2022 at 06:52:59AM IST, Benjamin Poirier wrote: > > On 2022-01-14 22:09 +0530, Kumar Kartikeya Dwivedi wrote: > > > Use the prog_test kfuncs to test the referenced PTR_TO_BTF_ID kfunc > > > support, and PTR_TO_CTX, PTR_TO_MEM argument passing support. Also > > > testing the various failure cases for invalid kfunc prototypes. > > > > > > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> > > > --- > > > net/bpf/test_run.c | 129 +++++++++++++++++- > > > .../selftests/bpf/prog_tests/kfunc_call.c | 6 + > > > .../selftests/bpf/progs/kfunc_call_test.c | 52 ++++++- > > > tools/testing/selftests/bpf/verifier/calls.c | 75 ++++++++++ > > > 4 files changed, 258 insertions(+), 4 deletions(-) > > > > > > > It looks like this patch broke building the bpf tests: > > > > tools/testing/selftests/bpf$ make > > CLNG-BPF [test_maps] kfunc_call_test.o > > progs/kfunc_call_test.c:13:46: error: declaration of 'struct prog_test_pass1' will not be visible outside of this function [-Werror,-Wvisibility] > > extern void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym; > > ^ > > > > The only definition of struct prog_test_pass1 that I see is in > > net/bpf/test_run.c. How is this supposed to work? > > > > > > commit 87091063df5d ("selftests/bpf: Add test for unstable CT lookup > > API") from the same series added a similar problem in > > progs/test_bpf_nf.c: > > > > progs/test_bpf_nf.c:31:21: error: variable has incomplete type 'struct bpf_ct_opts' > > struct bpf_ct_opts opts_def = { .l4proto = IPPROTO_TCP, .netns_id = -1 }; > > > > Both of them should have their definition in vmlinux.h. Can you check? My bad, I didn't realize it was generated from the running kernel. The build works after trying again while running v5.18. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-05-26 6:19 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-01-22 9:03 [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests kernel test robot 2022-01-22 8:58 ` [PATCH] selftests/bpf: fix flexible_array.cocci warnings kernel test robot -- strict thread matches above, loose matches on Subject: below -- 2022-02-09 2:27 [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests kernel test robot 2022-02-07 20:43 kernel test robot 2022-01-26 2:28 kernel test robot 2022-01-18 14:57 kernel test robot 2022-01-14 16:39 [PATCH bpf-next v8 00/10] Introduce unstable CT lookup helpers Kumar Kartikeya Dwivedi 2022-01-14 16:39 ` [PATCH bpf-next v8 09/10] selftests/bpf: Extend kfunc selftests Kumar Kartikeya Dwivedi 2022-05-26 1:22 ` Benjamin Poirier 2022-05-26 5:15 ` Kumar Kartikeya Dwivedi 2022-05-26 6:19 ` Benjamin Poirier
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.