Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8978215ybi; Fri, 7 Jun 2019 01:09:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOBVApoLBZ/WLDuJ+h9Zaz6PDgnyA55K1vXuebZeLjFpD4TQW9foR8zWIqp2H/o+nzzGZE X-Received: by 2002:a17:90a:b115:: with SMTP id z21mr4100275pjq.64.1559894941663; Fri, 07 Jun 2019 01:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559894941; cv=none; d=google.com; s=arc-20160816; b=j3Y2eiQTH4bpfRaFls4hprC7rCpCR6mkSlvx5xxlcjz/fakfPwRTTwwkFG4eapnNWs r94vA9GrXdMrBeobCbGPPKaMM1GRPif5AolczARr6JTLLEQp7iB1A5hWn5SQ1ZczcaDA H+EgHH+IZFrYGNrUwMdwld8Sm+a+W58rHKgQqgugu76bt86tbmpKHhe7tf4nW2v+wJ7r xlOIln0Q46JHMqlO0y8cMaWKi3W62acc2SDT2yrm2dAYRepukov6MZSQgOOYHHtyb2Wy qmbqYK30JfGi/LBOE+p/9FzQvhpWweRmz0fEHYcE2CV3QGabcrTh3XW2VtvUcGX5DumH PveQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=jfsNFKXVo0tNdt9Z8k+64FHNjRLmLfmwkVEoJ1Z1POw=; b=SzIS42NH6WUBLPFjjLJPo0kuQuAsYyk0FEjCfeQNysf1Xga4ARNXLdsO786ri4bg+c IExuz2ali+cVwQz6+qSSeQ/n1C5S/HgJGNR7bM39D+xrKnoRR57fXyqYdoDw0tPMWxqp LJzmoDj8YHlZRz9JKrtyXVWRnygv1WX2PdNkKurJUQlDk2zBP+Be+nOqsc0hgPNW4hgj 0+3c6SaksYo+Sy42PbzDWU6ZqwRAACsGu99Kkfc+Gm2fRXr8ReaA/pv94HBhXqJPu1pW XDHRGStOWEoRl1AkpyYgwKnoVA67dxZJcJ5TqvEoOvwwQIPGFCoh1efkUEGAyeoVoQen 8nog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z24si1127996pfa.190.2019.06.07.01.08.44; Fri, 07 Jun 2019 01:09:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbfFGG6F (ORCPT + 99 others); Fri, 7 Jun 2019 02:58:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:53763 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726891AbfFGG6F (ORCPT ); Fri, 7 Jun 2019 02:58:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2019 23:58:04 -0700 X-ExtLoop1: 1 Received: from btopel-mobl.isw.intel.com (HELO btopel-mobl.ger.intel.com) ([10.103.211.150]) by fmsmga001.fm.intel.com with ESMTP; 06 Jun 2019 23:58:01 -0700 Subject: Re: [PATCH] net: Fix hang while unregistering device bound to xdp socket To: Ilya Maximets , Jonathan Lemon Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, xdp-newbies@vger.kernel.org, "David S. Miller" , Magnus Karlsson References: <20190606124014.23231-1-i.maximets@samsung.com> <4414B6B6-3FE2-4CF2-A67A-159FCF6B9ECF@gmail.com> <3014f882-3042-cb6a-2356-ea3a754840a7@samsung.com> From: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= Message-ID: Date: Fri, 7 Jun 2019 08:58:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <3014f882-3042-cb6a-2356-ea3a754840a7@samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>> --- >>> >>> 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