bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: David Ahern <dsahern@gmail.com>
Cc: "Andrii Nakryiko" <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	"Alexei Starovoitov" <ast@fb.com>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Kernel Team" <kernel-team@fb.com>,
	"Jakub Kicinski" <kicinski@fb.com>,
	"Andrey Ignatov" <rdna@fb.com>,
	"Takshak Chahande" <ctakshak@fb.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: [PATCH bpf-next 4/7] bpf: implement BPF XDP link-specific introspection APIs
Date: Mon, 13 Jul 2020 15:41:03 -0700	[thread overview]
Message-ID: <CAEf4BzZw_1B8bafnxXThOvaAts5WFbE-mYgzM3f8ZMpwnedvHQ@mail.gmail.com> (raw)
In-Reply-To: <7a68d9cc-f8dc-a11f-f1d4-7307519be866@gmail.com>

On Mon, Jul 13, 2020 at 7:32 AM David Ahern <dsahern@gmail.com> wrote:
>
> On 7/10/20 4:49 PM, Andrii Nakryiko wrote:
> > diff --git a/net/core/dev.c b/net/core/dev.c
> > index 025687120442..a9c634be8dd7 100644
> > --- a/net/core/dev.c
> > +++ b/net/core/dev.c
> > @@ -8973,6 +8973,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)
> >       kfree(xdp_link);
> >  }
> >
> > +static void bpf_xdp_link_show_fdinfo(const struct bpf_link *link,
> > +                                  struct seq_file *seq)
> > +{
> > +     struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
> > +     u32 ifindex = 0;
> > +
> > +     rtnl_lock();
> > +     if (xdp_link->dev)
> > +             ifindex = xdp_link->dev->ifindex;
> > +     rtnl_unlock();
>
> Patch 2 you set dev but don't hold a refcnt on it which is why you need
> the locking here. How do you know that the dev pointer is even valid here?
>
> If xdp_link is going to have dev reference you need to take the refcnt
> and you need to handle NETDEV notifications to cleanup the bpf_link when
> the device goes away.

Here I'm following the approach taken for cgroup and netns, where we
don't want to hold cgroup with extra refcnt (as well as netns for
bpf_netns_link). The dev is guaranteed to be valid because
dev_xdp_uninstall() will be called (under rtnl_lock) before net_device
is removed/destroyed. dev_xdp_uninstall() is the only one that can set
xdp_link->dev to NULL. So if we got rtnl_lock() and see non-NULL dev
here, it means that at worst we are waiting on a rtnl lock in
dev_xdp_uninstall() in a separate thread, and until this thread
releases that lock, it's ok to query dev.

Even if we do extra refcnt, due to dev_xdp_uninstall() which sets
xdp_link->dev to NULL, any code (fill_info, show_fdinfo, update, etc)
that does something with xdp_link->dev will have to take a lock
anyways.

  reply	other threads:[~2020-07-13 22:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200710224924.4087399-1-andriin@fb.com>
     [not found] ` <20200710224924.4087399-3-andriin@fb.com>
2020-07-13 14:19   ` [PATCH bpf-next 2/7] bpf, xdp: add bpf_link-based XDP attachment API David Ahern
2020-07-13 22:33     ` Andrii Nakryiko
2020-07-14 13:57   ` Toke Høiland-Jørgensen
2020-07-14 18:59     ` Andrii Nakryiko
2020-07-14 20:12       ` Toke Høiland-Jørgensen
2020-07-14 20:37         ` Andrii Nakryiko
2020-07-14 21:41           ` Toke Høiland-Jørgensen
2020-07-14 22:26             ` Andrii Nakryiko
2020-07-15 15:48               ` Toke Høiland-Jørgensen
2020-07-15 20:54                 ` Andrii Nakryiko
2020-07-16 10:52                   ` Toke Høiland-Jørgensen
2020-07-22  6:45                     ` Andrii Nakryiko
     [not found] ` <20200710224924.4087399-5-andriin@fb.com>
2020-07-13 14:32   ` [PATCH bpf-next 4/7] bpf: implement BPF XDP link-specific introspection APIs David Ahern
2020-07-13 22:41     ` Andrii Nakryiko [this message]
2020-07-13  5:12 [PATCH bpf-next 0/7] BPF XDP link Andrii Nakryiko
2020-07-13  5:12 ` [PATCH bpf-next 4/7] bpf: implement BPF XDP link-specific introspection APIs Andrii Nakryiko

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=CAEf4BzZw_1B8bafnxXThOvaAts5WFbE-mYgzM3f8ZMpwnedvHQ@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=ctakshak@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=dsahern@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=kicinski@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=rdna@fb.com \
    --cc=toke@redhat.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).