From: "Björn Töpel" <bjorn.topel@intel.com>
To: Ilya Maximets <i.maximets@samsung.com>,
Jonathan Lemon <jonathan.lemon@gmail.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, xdp-newbies@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Magnus Karlsson <magnus.karlsson@intel.com>
Subject: Re: [PATCH] net: Fix hang while unregistering device bound to xdp socket
Date: Fri, 7 Jun 2019 08:58:00 +0200 [thread overview]
Message-ID: <a8d428ce-2539-b280-d219-6d21a500aa5c@intel.com> (raw)
In-Reply-To: <3014f882-3042-cb6a-2356-ea3a754840a7@samsung.com>
On 2019-06-07 08:36, Ilya Maximets wrote:
> On 06.06.2019 21:03, Jonathan Lemon wrote:
>> On 6 Jun 2019, at 5:40, Ilya Maximets wrote:
>>
>>> Device that bound to XDP socket will not have zero refcount until the
>>> userspace application will not close it. This leads to hang inside
>>> 'netdev_wait_allrefs()' if device unregistering requested:
>>>
>>> # ip link del p1
>>> < hang on recvmsg on netlink socket >
>>>
>>> # ps -x | grep ip
>>> 5126 pts/0 D+ 0:00 ip link del p1
>>>
>>> # journalctl -b
>>>
>>> Jun 05 07:19:16 kernel:
>>> unregister_netdevice: waiting for p1 to become free. Usage count = 1
>>>
>>> Jun 05 07:19:27 kernel:
>>> unregister_netdevice: waiting for p1 to become free. Usage count = 1
>>> ...
>>>
>>> Fix that by counting XDP references for the device and failing
>>> RTM_DELLINK with EBUSY if device is still in use by any XDP socket.
>>>
>>> With this change:
>>>
>>> # ip link del p1
>>> RTNETLINK answers: Device or resource busy
>>>
>>> Fixes: 965a99098443 ("xsk: add support for bind for Rx")
>>> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>>> ---
>>>
>>> Another option could be to force closing all the corresponding AF_XDP
>>> sockets, but I didn't figure out how to do this properly yet.
>>>
>>> include/linux/netdevice.h | 25 +++++++++++++++++++++++++
>>> net/core/dev.c | 10 ++++++++++
>>> net/core/rtnetlink.c | 6 ++++++
>>> net/xdp/xsk.c | 7 ++++++-
>>> 4 files changed, 47 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
>>> index 44b47e9df94a..24451cfc5590 100644
>>> --- a/include/linux/netdevice.h
>>> +++ b/include/linux/netdevice.h
>>> @@ -1705,6 +1705,7 @@ enum netdev_priv_flags {
>>> * @watchdog_timer: List of timers
>>> *
>>> * @pcpu_refcnt: Number of references to this device
>>> + * @pcpu_xdp_refcnt: Number of XDP socket references to this device
>>> * @todo_list: Delayed register/unregister
>>> * @link_watch_list: XXX: need comments on this one
>>> *
>>> @@ -1966,6 +1967,7 @@ struct net_device {
>>> struct timer_list watchdog_timer;
>>>
>>> int __percpu *pcpu_refcnt;
>>> + int __percpu *pcpu_xdp_refcnt;
>>> struct list_head todo_list;
>>
>>
>> I understand the intention here, but don't think that putting a XDP reference
>> into the generic netdev structure is the right way of doing this. Likely the
>> NETDEV_UNREGISTER notifier should be used so the socket and umem unbinds from
>> the device.
>>
>
> Thanks for the pointer! That is exactly what I looked for.
> I'll make a new version that will unbind resources using netdevice notifier.
>
> Best regards, Ilya Maximets.
>
Thanks for working on this.
This would open up for supporting killing sockets via ss(8) (-K,
--kill), as well!
Björn
prev parent reply other threads:[~2019-06-07 6:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20190606124020eucas1p2007396ae8f23a426a17e0e5481636187@eucas1p2.samsung.com>
2019-06-06 12:40 ` [PATCH] net: Fix hang while unregistering device bound to xdp socket Ilya Maximets
2019-06-06 18:03 ` Jonathan Lemon
2019-06-07 6:36 ` Ilya Maximets
2019-06-07 6:58 ` Björn Töpel [this message]
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=a8d428ce-2539-b280-d219-6d21a500aa5c@intel.com \
--to=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=i.maximets@samsung.com \
--cc=jonathan.lemon@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=xdp-newbies@vger.kernel.org \
/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).