From: Stanislav Fomichev <sdf@google.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: davem@davemloft.net, 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: Re: [PATCH v2 bpf-next 4/4] selftests/bpf: Tweak cgroup kfunc test.
Date: Thu, 23 Feb 2023 13:48:44 -0800 [thread overview]
Message-ID: <Y/ffPMRzRANCZS+1@google.com> (raw)
In-Reply-To: <20230223030717.58668-5-alexei.starovoitov@gmail.com>
On 02/22, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> Adjust cgroup kfunc test to dereference RCU protected cgroup pointer
> as PTR_TRUSTED and pass into KF_TRUSTED_ARGS kfunc.
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
> tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h | 2 +-
> tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c | 2 +-
> tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c | 7 ++++++-
> 3 files changed, 8 insertions(+), 3 deletions(-)
> diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h
> b/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h
> index 50d8660ffa26..eb5bf3125816 100644
> --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h
> +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_common.h
> @@ -10,7 +10,7 @@
> #include <bpf/bpf_tracing.h>
> struct __cgrps_kfunc_map_value {
> - struct cgroup __kptr * cgrp;
> + struct cgroup __kptr_rcu * cgrp;
> };
> struct hash_map {
> diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c
> b/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c
> index 4ad7fe24966d..d5a53b5e708f 100644
> --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c
> +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c
> @@ -205,7 +205,7 @@ int BPF_PROG(cgrp_kfunc_get_unreleased, struct cgroup
> *cgrp, const char *path)
> }
> SEC("tp_btf/cgroup_mkdir")
> -__failure __msg("arg#0 is untrusted_ptr_or_null_ expected ptr_ or
> socket")
> +__failure __msg("bpf_cgroup_release expects refcounted")
> int BPF_PROG(cgrp_kfunc_release_untrusted, struct cgroup *cgrp, const
> char *path)
> {
> struct __cgrps_kfunc_map_value *v;
> diff --git a/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c
> b/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c
> index 0c23ea32df9f..37ed73186fba 100644
> --- a/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c
> +++ b/tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c
> @@ -61,7 +61,7 @@ int BPF_PROG(test_cgrp_acquire_leave_in_map, struct
> cgroup *cgrp, const char *pa
> SEC("tp_btf/cgroup_mkdir")
> int BPF_PROG(test_cgrp_xchg_release, struct cgroup *cgrp, const char
> *path)
> {
> - struct cgroup *kptr;
> + struct cgroup *kptr, *cg;
> struct __cgrps_kfunc_map_value *v;
> long status;
> @@ -80,6 +80,11 @@ int BPF_PROG(test_cgrp_xchg_release, struct cgroup
> *cgrp, const char *path)
> return 0;
> }
[..]
> + kptr = v->cgrp;
> + cg = bpf_cgroup_ancestor(kptr, 1);
> + if (cg)
> + bpf_cgroup_release(cg);
I went through the series, it all makes sense, I'm assuming Kumar
will have another look eventually? (since he did for v1).
One question here, should we have something like the following?
if (cg) {
bpf_cgroup_release(cg);
} else {
err = 4;
return 0;
}
Or are we just making sure here that the verifier is not complaining
about bpf_cgroup_ancestor(v->cgrp) and don't really care whether
bpf_cgroup_ancestor returns something useful or not?
> +
> kptr = bpf_kptr_xchg(&v->cgrp, NULL);
> if (!kptr) {
> err = 3;
> --
> 2.30.2
next prev parent reply other threads:[~2023-02-23 21:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 3:07 [PATCH v2 bpf-next 0/4] bpf: Introduce kptr_rcu Alexei Starovoitov
2023-02-23 3:07 ` [PATCH v2 bpf-next 1/4] bpf: Rename __kptr_ref -> __kptr and __kptr -> __kptr_untrusted Alexei Starovoitov
2023-02-23 3:07 ` [PATCH v2 bpf-next 2/4] bpf: Introduce kptr_rcu Alexei Starovoitov
2023-02-27 17:52 ` Alexei Starovoitov
2023-02-23 3:07 ` [PATCH v2 bpf-next 3/4] selftests/bpf: Add a test case for kptr_rcu Alexei Starovoitov
2023-02-23 3:07 ` [PATCH v2 bpf-next 4/4] selftests/bpf: Tweak cgroup kfunc test Alexei Starovoitov
2023-02-23 21:48 ` Stanislav Fomichev [this message]
2023-02-24 23:10 ` 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=Y/ffPMRzRANCZS+1@google.com \
--to=sdf@google.com \
--cc=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;
as well as URLs for NNTP newsgroup(s).