diff options
author | Alexei Starovoitov <ast@kernel.org> | 2022-05-11 16:57:27 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2022-05-11 16:57:27 -0700 |
commit | 571b8739dd6df6d41bdcc83ed50b481a27af912c (patch) | |
tree | bb6dfa8f502812fcf7a081aa26b0ae0b2603b287 /net | |
parent | fd0ad6f1d10c01796904608aacd6e70d6f624305 (diff) | |
parent | 0ef6740e97777bbe04aeacd32239ccb1732098d7 (diff) | |
download | linux-571b8739dd6df6d41bdcc83ed50b481a27af912c.tar.bz2 |
Merge branch 'Follow ups for kptr series'
Kumar Kartikeya Dwivedi says:
====================
Fix a build time warning, and address comments from Alexei on the merged
version [0].
[0]: https://lore.kernel.org/bpf/20220424214901.2743946-1-memxor@gmail.com
Changelog:
----------
v1 -> v2
v1: https://lore.kernel.org/bpf/20220510211727.575686-1-memxor@gmail.com
* Add Fixes tag to patch 1
* Fix test_progs-noalu32 failure in CI due to different alloc_insn (Alexei)
* Remove per-CPU struct, use global struct (Alexei)
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/bpf/test_run.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 7a1579c91432..4d08cca771c7 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -564,31 +564,36 @@ struct prog_test_ref_kfunc { int b; struct prog_test_member memb; struct prog_test_ref_kfunc *next; + refcount_t cnt; }; static struct prog_test_ref_kfunc prog_test_struct = { .a = 42, .b = 108, .next = &prog_test_struct, + .cnt = REFCOUNT_INIT(1), }; 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; + refcount_inc(&prog_test_struct.cnt); return &prog_test_struct; } noinline struct prog_test_member * bpf_kfunc_call_memb_acquire(void) { - return &prog_test_struct.memb; + WARN_ON_ONCE(1); + return NULL; } noinline void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) { + if (!p) + return; + + refcount_dec(&p->cnt); } noinline void bpf_kfunc_call_memb_release(struct prog_test_member *p) @@ -597,12 +602,18 @@ noinline void bpf_kfunc_call_memb_release(struct prog_test_member *p) noinline void bpf_kfunc_call_memb1_release(struct prog_test_member1 *p) { + WARN_ON_ONCE(1); } noinline struct prog_test_ref_kfunc * -bpf_kfunc_call_test_kptr_get(struct prog_test_ref_kfunc **p, int a, int b) +bpf_kfunc_call_test_kptr_get(struct prog_test_ref_kfunc **pp, int a, int b) { - return &prog_test_struct; + struct prog_test_ref_kfunc *p = READ_ONCE(*pp); + + if (!p) + return NULL; + refcount_inc(&p->cnt); + return p; } struct prog_test_pass1 { |