From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: davem@davemloft.net
Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org,
void@manifault.com, davemarchevsky@meta.com, tj@kernel.org,
memxor@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
kernel-team@fb.com
Subject: [PATCH bpf-next 3/4] selftests/bpf: Add a test case for kptr_rcu.
Date: Tue, 14 Feb 2023 22:58:11 -0800 [thread overview]
Message-ID: <20230215065812.7551-4-alexei.starovoitov@gmail.com> (raw)
In-Reply-To: <20230215065812.7551-1-alexei.starovoitov@gmail.com>
From: Alexei Starovoitov <ast@kernel.org>
Tweak existing map_kptr test to check kptr_rcu.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
tools/testing/selftests/bpf/progs/map_kptr.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/progs/map_kptr.c b/tools/testing/selftests/bpf/progs/map_kptr.c
index 4a7da6cb5800..e705972985a7 100644
--- a/tools/testing/selftests/bpf/progs/map_kptr.c
+++ b/tools/testing/selftests/bpf/progs/map_kptr.c
@@ -5,7 +5,7 @@
struct map_value {
struct prog_test_ref_kfunc __kptr_untrusted *unref_ptr;
- struct prog_test_ref_kfunc __kptr *ref_ptr;
+ struct prog_test_ref_kfunc __kptr_rcu *ref_ptr;
};
struct array_map {
@@ -61,6 +61,7 @@ extern struct prog_test_ref_kfunc *bpf_kfunc_call_test_acquire(unsigned long *sp
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;
+void bpf_kfunc_call_test_ref(struct prog_test_ref_kfunc *p) __ksym;
#define WRITE_ONCE(x, val) ((*(volatile typeof(x) *) &(x)) = (val))
@@ -90,12 +91,20 @@ static void test_kptr_ref(struct map_value *v)
WRITE_ONCE(v->unref_ptr, p);
if (!p)
return;
+ /*
+ * p is trusted_ptr_prog_test_ref_kfunc
+ * because bpf prog is non-sleepable and runs in RCU CS.
+ * p can be passed to kfunc that requires KF_TRUSTED_ARGS
+ */
+ bpf_kfunc_call_test_ref(p);
if (p->a + p->b > 100)
return;
/* store NULL */
p = bpf_kptr_xchg(&v->ref_ptr, NULL);
if (!p)
return;
+ /* p is trusted_ptr_prog_test_ref_kfunc */
+ bpf_kfunc_call_test_ref(p);
if (p->a + p->b > 100) {
bpf_kfunc_call_test_release(p);
return;
@@ -288,6 +297,8 @@ int test_map_kptr_ref2(struct __sk_buff *ctx)
if (p_st->cnt.refs.counter != 2)
return 6;
+ /* p_st is trusted, because we're in RCU CS */
+ bpf_kfunc_call_test_ref(p_st);
return 0;
}
--
2.30.2
next prev parent reply other threads:[~2023-02-15 7:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-15 6:58 [PATCH bpf-next 0/4] bpf: Introduce kptr_rcu Alexei Starovoitov
2023-02-15 6:58 ` [PATCH bpf-next 1/4] bpf: Rename __kptr_ref -> __kptr and __kptr -> __kptr_untrusted Alexei Starovoitov
2023-02-15 6:58 ` [PATCH bpf-next 2/4] bpf: Introduce kptr_rcu Alexei Starovoitov
2023-02-15 10:48 ` Kumar Kartikeya Dwivedi
2023-02-15 22:23 ` Alexei Starovoitov
2023-02-15 6:58 ` Alexei Starovoitov [this message]
2023-02-15 6:58 ` [PATCH bpf-next 4/4] selftests/bpf: Tweak cgroup kfunc test Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230215065812.7551-4-alexei.starovoitov@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=davemarchevsky@meta.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox