On Wed, Mar 23, 2022 at 02:30:57AM IST, Andrii Nakryiko wrote: > On Sun, Mar 20, 2022 at 8:56 AM Kumar Kartikeya Dwivedi > <memxor@xxxxxxxxx> wrote: > > > > This uses the __kptr and __kptr_ref macros as well, and tries to test > > the stuff that is supposed to work, since we have negative tests in > > test_verifier suite. Also include some code to test map-in-map support, > > such that the inner_map_meta matches the kptr_off_tab of map added as > > element. > > > > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> > > --- > > .../selftests/bpf/prog_tests/map_kptr.c | 20 ++ > > tools/testing/selftests/bpf/progs/map_kptr.c | 194 ++++++++++++++++++ > > 2 files changed, 214 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/prog_tests/map_kptr.c > > create mode 100644 tools/testing/selftests/bpf/progs/map_kptr.c > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr.c b/tools/testing/selftests/bpf/prog_tests/map_kptr.c > > new file mode 100644 > > index 000000000000..688732295ce9 > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/prog_tests/map_kptr.c > > @@ -0,0 +1,20 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include <test_progs.h> > > + > > +#include "map_kptr.skel.h" > > + > > +void test_map_kptr(void) > > +{ > > + struct map_kptr *skel; > > + char buf[24]; > > + int key = 0; > > + > > + skel = map_kptr__open_and_load(); > > + if (!ASSERT_OK_PTR(skel, "map_kptr__open_and_load")) > > + return; > > + ASSERT_OK(bpf_map_update_elem(bpf_map__fd(skel->maps.hash_map), &key, buf, 0), > > + "bpf_map_update_elem hash_map"); > > + ASSERT_OK(bpf_map_update_elem(bpf_map__fd(skel->maps.hash_malloc_map), &key, buf, 0), > > + "bpf_map_update_elem hash_malloc_map"); > > > nit: it's quite messy and verbose, please do the operation outside of > ASSERT_OK() and just validate error: > > err = bpf_map_update_elem(...); > ASSERT_OK(err, "hash_map_update"); > > And keep those ASSERT_XXX() string descriptors relatively short (see > how they are used internally in ASSERT_XXX() macros). > Ok. > > + map_kptr__destroy(skel); > > +} > > [...] > > > + > > +extern struct prog_test_ref_kfunc *bpf_kfunc_call_test_acquire(unsigned long *sp) __ksym; > > +extern struct prog_test_ref_kfunc * > > +bpf_kfunc_call_test_kptr_get(struct prog_test_ref_kfunc **p, int a, int b) __ksym; > > +extern void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym; > > + > > +static __always_inline > > nit: no need for __always_inline everywhere, just `static void` will > do the right thing. > Ok, will drop. > > +void test_kptr_unref(struct map_value *v) > > +{ > > + struct prog_test_ref_kfunc *p; > > + > > + p = v->unref_ptr; > > + /* store untrusted_ptr_or_null_ */ > > + v->unref_ptr = p; > > + if (!p) > > + return; > > + if (p->a + p->b > 100) > > + return; > > + /* store untrusted_ptr_ */ > > + v->unref_ptr = p; > > + /* store NULL */ > > + v->unref_ptr = NULL; > > +} > > + > > [...] -- Kartikeya