bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Lau <kafai@fb.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: "daniel@iogearbox.net" <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@fb.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Subject: Re: [PATCH bpf v2] xdp: Handle device unregister for devmap_hash map type
Date: Fri, 18 Oct 2019 16:50:57 +0000	[thread overview]
Message-ID: <20191018165049.rm6du3yq2e4vg45h@kafai-mbp> (raw)
In-Reply-To: <87pniue4cw.fsf@toke.dk>

On Fri, Oct 18, 2019 at 12:26:55PM +0200, Toke Høiland-Jørgensen wrote:
> Martin Lau <kafai@fb.com> writes:
> 
> > On Thu, Oct 17, 2019 at 12:52:32PM +0200, Toke Høiland-Jørgensen wrote:
> >> It seems I forgot to add handling of devmap_hash type maps to the device
> >> unregister hook for devmaps. This omission causes devices to not be
> >> properly released, which causes hangs.
> >> 
> >> Fix this by adding the missing handler.
> >> 
> >> Fixes: 6f9d451ab1a3 ("xdp: Add devmap_hash map type for looking up devices by hashed index")
> >> Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> >> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> >> ---
> >> v2:
> >>   - Grab the update lock while walking the map and removing entries.
> >> 
> >>  kernel/bpf/devmap.c | 37 +++++++++++++++++++++++++++++++++++++
> >>  1 file changed, 37 insertions(+)
> >> 
> >> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> >> index d27f3b60ff6d..a0a1153da5ae 100644
> >> --- a/kernel/bpf/devmap.c
> >> +++ b/kernel/bpf/devmap.c
> >> @@ -719,6 +719,38 @@ const struct bpf_map_ops dev_map_hash_ops = {
> >>  	.map_check_btf = map_check_no_btf,
> >>  };
> >>  
> >> +static void dev_map_hash_remove_netdev(struct bpf_dtab *dtab,
> >> +				       struct net_device *netdev)
> >> +{
> >> +	unsigned long flags;
> >> +	int i;
> > dtab->n_buckets is u32.
> 
> Oh, right, will fix.
> 
> >> +
> >> +	spin_lock_irqsave(&dtab->index_lock, flags);
> >> +	for (i = 0; i < dtab->n_buckets; i++) {
> >> +		struct bpf_dtab_netdev *dev, *odev;
> >> +		struct hlist_head *head;
> >> +
> >> +		head = dev_map_index_hash(dtab, i);
> >> +		dev = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)),
> > The spinlock has already been held.  Is rcu_deref still needed?
> 
> I guess it's not strictly needed, but since it's an rcu-protected list,
> and hlist_first_rcu() returns an __rcu-annotated type, I think we will
> get a 'sparse' warning if it's omitted, no?
> 
> And since it's just a READ_ONCE, it doesn't actually hurt since this is
> not the fast path, so I'd lean towards just keeping it? WDYT?
>
Can hlist_for_each_safe() be used instead then?
A bonus is the following long line will go away.
I think the change will be simpler also.


> +                                    struct bpf_dtab_netdev,
> +                                    index_hlist);
> +
> +             while (dev) {
> +                     odev = (netdev == dev->dev) ? dev : NULL;
> +                     dev = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(&dev->index_hlist)),
> +                                            struct bpf_dtab_netdev,
> +                                            index_hlist);
> +
> +                     if (odev) {
> +                             hlist_del_rcu(&odev->index_hlist);
> +                             call_rcu(&odev->rcu,
> +                                      __dev_map_entry_free);
> +                     }
> +             }
> +     }
> +     spin_unlock_irqrestore(&dtab->index_lock, flags);
> +}
> +

  reply	other threads:[~2019-10-18 16:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 10:52 [PATCH bpf v2] xdp: Handle device unregister for devmap_hash map type Toke Høiland-Jørgensen
2019-10-17 19:02 ` Martin Lau
2019-10-18 10:26   ` Toke Høiland-Jørgensen
2019-10-18 16:50     ` Martin Lau [this message]
2019-10-18 19:28       ` Toke Høiland-Jørgensen

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=20191018165049.rm6du3yq2e4vg45h@kafai-mbp \
    --to=kafai@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --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).