netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
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, memxor@gmail.com,
	netdev@vger.kernel.org, bpf@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH v3 bpf-next 3/5] bpf: Introduce kptr_rcu.
Date: Tue, 28 Feb 2023 09:39:19 -1000	[thread overview]
Message-ID: <Y/5YZ4LR5ZTLUATc@slm.duckdns.org> (raw)
In-Reply-To: <20230228040121.94253-4-alexei.starovoitov@gmail.com>

On Mon, Feb 27, 2023 at 08:01:19PM -0800, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> The life time of certain kernel structures like 'struct cgroup' is protected by RCU.
> Hence it's safe to dereference them directly from __kptr tagged pointers in bpf maps.
> The resulting pointer is MEM_RCU and can be passed to kfuncs that expect KF_RCU.
> Derefrence of other kptr-s returns PTR_UNTRUSTED.
> 
> For example:
> struct map_value {
>    struct cgroup __kptr *cgrp;
> };
> 
> SEC("tp_btf/cgroup_mkdir")
> int BPF_PROG(test_cgrp_get_ancestors, struct cgroup *cgrp_arg, const char *path)
> {
>   struct cgroup *cg, *cg2;
> 
>   cg = bpf_cgroup_acquire(cgrp_arg); // cg is PTR_TRUSTED and ref_obj_id > 0
>   bpf_kptr_xchg(&v->cgrp, cg);
> 
>   cg2 = v->cgrp; // This is new feature introduced by this patch.
>   // cg2 is PTR_MAYBE_NULL | MEM_RCU.
>   // When cg2 != NULL, it's a valid cgroup, but its percpu_ref could be zero
> 
>   bpf_cgroup_ancestor(cg2, level); // safe to do.
> }
> 
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>

From cgroup POV:

 Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

  parent reply	other threads:[~2023-02-28 19:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28  4:01 [PATCH v3 bpf-next 0/5] bpf: Introduce kptr_rcu Alexei Starovoitov
2023-02-28  4:01 ` [PATCH v3 bpf-next 1/5] bpf: Rename __kptr_ref -> __kptr and __kptr -> __kptr_untrusted Alexei Starovoitov
2023-02-28 15:16   ` David Vernet
2023-02-28  4:01 ` [PATCH v3 bpf-next 2/5] bpf: Mark cgroups and dfl_cgrp fields as trusted Alexei Starovoitov
2023-02-28 16:45   ` David Vernet
2023-02-28 19:32   ` Tejun Heo
2023-02-28  4:01 ` [PATCH v3 bpf-next 3/5] bpf: Introduce kptr_rcu Alexei Starovoitov
2023-02-28 16:45   ` David Vernet
2023-02-28 19:49     ` Alexei Starovoitov
2023-02-28 20:05       ` David Vernet
2023-02-28 19:39   ` Tejun Heo [this message]
2023-02-28  4:01 ` [PATCH v3 bpf-next 4/5] selftests/bpf: Add a test case for kptr_rcu Alexei Starovoitov
2023-02-28 16:52   ` David Vernet
2023-02-28  4:01 ` [PATCH v3 bpf-next 5/5] selftests/bpf: Tweak cgroup kfunc test Alexei Starovoitov
2023-02-28 17:07   ` David Vernet
2023-03-01  0:29     ` Alexei Starovoitov
2023-03-01  2:22       ` David Vernet

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/5YZ4LR5ZTLUATc@slm.duckdns.org \
    --to=tj@kernel.org \
    --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=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).