[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240719172119.3199738-4-amery.hung@bytedance.com>
Date: Fri, 19 Jul 2024 17:21:19 +0000
From: Amery Hung <ameryhung@...il.com>
To: ameryhung@...il.com
Cc: alexei.starovoitov@...il.com,
andrii@...nel.org,
bpf@...r.kernel.org,
daniel@...earbox.net,
jhs@...atatu.com,
jiri@...nulli.us,
martin.lau@...nel.org,
netdev@...r.kernel.org,
sdf@...gle.com,
sinquersw@...il.com,
toke@...hat.com,
xiyou.wangcong@...il.com,
yangpeihao@...u.edu.cn,
yepeilin.cs@...il.com,
donald.hunter@...il.com
Subject: [OFFLIST RFC 4/4] selftests/bpf: Test bpf_kptr_xchg stashing into local kptr
From: Dave Marchevsky <davemarchevsky@...com>
Signed-off-by: Dave Marchevsky <davemarchevsky@...com>
---
.../selftests/bpf/progs/local_kptr_stash.c | 21 +++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/local_kptr_stash.c b/tools/testing/selftests/bpf/progs/local_kptr_stash.c
index 75043ffc5dad..8532abcae5c0 100644
--- a/tools/testing/selftests/bpf/progs/local_kptr_stash.c
+++ b/tools/testing/selftests/bpf/progs/local_kptr_stash.c
@@ -11,6 +11,7 @@
struct node_data {
long key;
long data;
+ struct prog_test_ref_kfunc __kptr *stashed_in_node;
struct bpf_rb_node node;
};
@@ -85,17 +86,33 @@ static bool less(struct bpf_rb_node *a, const struct bpf_rb_node *b)
static int create_and_stash(int idx, int val)
{
+ struct prog_test_ref_kfunc *inner;
struct map_value *mapval;
struct node_data *res;
+ unsigned long dummy;
mapval = bpf_map_lookup_elem(&some_nodes, &idx);
if (!mapval)
return 1;
+ dummy = 0;
+ inner = bpf_kfunc_call_test_acquire(&dummy);
+ if (!inner)
+ return 2;
+
res = bpf_obj_new(typeof(*res));
- if (!res)
- return 1;
+ if (!res) {
+ bpf_kfunc_call_test_release(inner);
+ return 3;
+ }
res->key = val;
+ inner = bpf_kptr_xchg(&res->stashed_in_node, inner);
+ if (inner) {
+ /* Should never happen, we just obj_new'd res */
+ bpf_kfunc_call_test_release(inner);
+ bpf_obj_drop(res);
+ return 4;
+ }
res = bpf_kptr_xchg(&mapval->node, res);
if (res)
--
2.20.1
Powered by blists - more mailing lists