Re: [PATCH bpf v5 2/2] xdp: fix hang while unregistering device bound to xdp socket

From: Ilya Maximets
Date: Fri Jun 28 2019 - 04:01:32 EST


On 28.06.2019 1:04, Jonathan Lemon wrote:
> On 27 Jun 2019, at 3:15, 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 implementing NETDEV_UNREGISTER event notification handler
>> to properly clean up all the resources and unref device.
>>
>> This should also allow socket killing via ss(8) utility.
>>
>> Fixes: 965a99098443 ("xsk: add support for bind for Rx")
>> Signed-off-by: Ilya Maximets <i.maximets@xxxxxxxxxxx>
>> ---
>> Âinclude/net/xdp_sock.h |Â 5 +++
>> Ânet/xdp/xdp_umem.cÂÂÂÂ | 10 ++---
>> Ânet/xdp/xdp_umem.hÂÂÂÂ |Â 1 +
>> Ânet/xdp/xsk.cÂÂÂÂÂÂÂÂÂ | 87 ++++++++++++++++++++++++++++++++++++------
>> Â4 files changed, 87 insertions(+), 16 deletions(-)
>>
>> diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
>> index d074b6d60f8a..82d153a637c7 100644
>> --- a/include/net/xdp_sock.h
>> +++ b/include/net/xdp_sock.h
>> @@ -61,6 +61,11 @@ struct xdp_sock {
>> ÂÂÂÂ struct xsk_queue *tx ____cacheline_aligned_in_smp;
>> ÂÂÂÂ struct list_head list;
>> ÂÂÂÂ bool zc;
>> +ÂÂÂ enum {
>> +ÂÂÂÂÂÂÂ XSK_UNINITIALIZED = 0,
>> +ÂÂÂÂÂÂÂ XSK_BINDED,
>> +ÂÂÂÂÂÂÂ XSK_UNBINDED,
>> +ÂÂÂ } state;
>
> I'd prefer that these were named better, perhaps:
> ÂÂ XSK_READY,
> ÂÂ XSK_BOUND,
> ÂÂ XSK_UNBOUND,

Sure. Thanks for suggestion!

>
> Other than that:
> Acked-by: Jonathan Lemon <jonathan.lemon@xxxxxxxxx>
>

I'll send a new version with the new state names keeping your ACK.

Best regards, Ilya Maximets.