Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2367544ybi; Mon, 17 Jun 2019 03:41:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSODDgRVNPVTMkDY0XTqpHAO2NtvI0Pv5zvmxlMaBG8rNUc7Kq/4LzbNAkaHFdkGM2/Z/H X-Received: by 2002:a65:51c7:: with SMTP id i7mr49056236pgq.211.1560768068805; Mon, 17 Jun 2019 03:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560768068; cv=none; d=google.com; s=arc-20160816; b=xr/x0I++o3rpc2hxTjqHjB6azN2eJN9/bx7eJq0RMf1DZe/fWYpe6hU56NOtLBxgVC zTcoCOT24ei9rBQW3pityWEJmN85GWR1/JgCWsICjiIBgDHoSr+omvYIYI+Cys2ltHVx 5ALSYYEpUjwmdqouO9qJtLvrsY9TrZ1f2wprDgaT/iO5LAwlDcHJKrn4t0FjO+4m/X3k PWp3cTmLGpwG90hXAo/908ukWf3mSsWUxjvzfK2fPZySyiiq3IAaPtvcJgmsp9tlY4z1 VUx60MTb6aGqhjUzBZSYACL/H92uHHBfNx9sXMGEcq4VPtrB06X1FM4UZrn/RCHi6chA peeg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=qjyOm5jUlTHrm3VcdpTzvNXJzoC5FF0ZBV+AJFqfwy8=; b=PcTxrGRjrSZyuk7rP51esjJYW8Na1rpouoburcWOn3V0WiI7CWcGsUNMz24q78idQ8 lJdzDhXST8VSJ9vIS6lEEUeC+AaDzq+7oiRPwDKcpNt7TpQrbmg67cIfIuDltUxQP5Fo vsrPwTAYhwdwvWDxX+3V5oiKaEoI8bDpbI8unZtunEeKQVEVCkFR81PcKnSZErN7p25Y ghLxVw01rPLQKi+UxVkIgC2GyD7saGSPXANntydtGuyFVdyEsIabb+vm/zVR49BHRWu2 pK1B4yMNIny0QZqd2GIFkC/MHNmOY2MJxO9dXrO01jWrIvSNWwezLQ6CBvg52JZUV2k7 s/8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=gy5kjwRS; 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=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si10245513plf.261.2019.06.17.03.40.53; Mon, 17 Jun 2019 03:41:08 -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; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=gy5kjwRS; 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=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbfFQKks (ORCPT + 99 others); Mon, 17 Jun 2019 06:40:48 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46109 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbfFQKks (ORCPT ); Mon, 17 Jun 2019 06:40:48 -0400 Received: by mail-lj1-f193.google.com with SMTP id v24so8759967ljg.13 for ; Mon, 17 Jun 2019 03:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=qjyOm5jUlTHrm3VcdpTzvNXJzoC5FF0ZBV+AJFqfwy8=; b=gy5kjwRSDGUmg+loUcjvpvKLKPjh8DRZE092YszFWVPKk36tVOMTs3TvbNA+0dsR91 WIJqH6O9/9sAJonxuI1Bo9pqATokUYLTsE1xdKNrqKtwtSTXwCgpvj3D8O1DiTtBa3OY 7xZj8JVm4zw7NsxAfSMv8gX5XE/N8Pv+2B//BpaRBjwYD/V+pD2KBQL9EJtpdJJJVRYL kJ8RyTd6iaFhRuRtxAHlUP0QKB81uQQochdQfknajVs8eplC+0XzPhRvBq7uNQTewY69 guVmNzppj2Bst0zPUgPbjO0Eu3gjErwfwbcJnGaIMYQB9AmjG1hKKz01MiNje2MoOaMG QOtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=qjyOm5jUlTHrm3VcdpTzvNXJzoC5FF0ZBV+AJFqfwy8=; b=TcuqCWeeAJOVj5XoSB39AXic8yjQBUP1WL5+4QOeBfiT087EoqTy1Zqqoby+4MJ6Lk Lx95QIWRECs/q7s4hrrEB0UkmT9ujWpkBVpcs5J62PZRx5LEc3Mk4bLfCBzeQcswdast FPm8zM472zV4SiHn2NjnnvckdAfuAwlx+KRMleZgJXXtLt2Lh6iKD7piMPt9aPDZmjRS +OrFBDiXZFZ/Fr3MGtmvrbKx3piI11TiUTp/o1uBzl+RPuqIt0wYbo2ZTDTXN+Ouo07/ w4+iKmVxQBGfL+qxCAm4TWPFMI3kv9UmIGiNcpi5/DjhW5Te+vfYqRRe6vEK2j1oe6Cx fL7Q== X-Gm-Message-State: APjAAAXYkgpzmgG5zcFu2V796XwlXvAfvyNKGlZlWbsmaNh7EO2XIXhN t4YjibOGP0UI7+OmjtXr2K7WeDV384Vff8IdwuZalg== X-Received: by 2002:a2e:6c14:: with SMTP id h20mr1705967ljc.38.1560768045802; Mon, 17 Jun 2019 03:40:45 -0700 (PDT) MIME-Version: 1.0 References: <20190617073320.69015-1-lifei.shirley@bytedance.com> <28bef625-ce70-20a1-7d8b-296cd43015c4@redhat.com> <2d05dce3-e19a-2f0f-8b74-8defae38640d@redhat.com> In-Reply-To: From: =?UTF-8?B?5p2O6I+y?= Date: Mon, 17 Jun 2019 18:40:34 +0800 Message-ID: Subject: Re: [External Email] Re: [PATCH] Fix tun: wake up waitqueues after IFF_UP is set To: Jason Wang , davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: zhengfeiran@bytedance.com, duanxiongchun@bytedance.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all, On Mon, Jun 17, 2019 at 5:32 PM =E6=9D=8E=E8=8F=B2 wrote: > > Ok, thanks for detail suggestion! :) > > On Mon, Jun 17, 2019 at 4:16 PM Jason Wang wrote: >> >> >> On 2019/6/17 =E4=B8=8B=E5=8D=884:10, Jason Wang wrote: >> > >> > On 2019/6/17 =E4=B8=8B=E5=8D=883:33, Fei Li wrote: >> >> Currently after setting tap0 link up, the tun code wakes tx/rx waited >> >> queues up in tun_net_open() when .ndo_open() is called, however the >> >> IFF_UP flag has not been set yet. If there's already a wait queue, it >> >> would fail to transmit when checking the IFF_UP flag in tun_sendmsg()= . >> >> Then the saving vhost_poll_start() will add the wq into wqh until it >> >> is waken up again. Although this works when IFF_UP flag has been set >> >> when tun_chr_poll detects; this is not true if IFF_UP flag has not >> >> been set at that time. Sadly the latter case is a fatal error, as >> >> the wq will never be waken up in future unless later manually >> >> setting link up on purpose. >> >> >> >> Fix this by moving the wakeup process into the NETDEV_UP event >> >> notifying process, this makes sure IFF_UP has been set before all >> >> waited queues been waken up. >> >> >> Btw, the title needs some tweak. E.g you need use "net" as prefix since >> it's a fix for net.git and "Fix" could be removed like: >> >> [PATCH net] tun: wake up waitqueues after IFF_UP is set. >> >> Thanks >> >> >> >> >> >> Signed-off-by: Fei Li >> >> --- >> >> drivers/net/tun.c | 17 +++++++++-------- >> >> 1 file changed, 9 insertions(+), 8 deletions(-) >> >> >> >> diff --git a/drivers/net/tun.c b/drivers/net/tun.c >> >> index c452d6d831dd..a3c9cab5a4d0 100644 >> >> --- a/drivers/net/tun.c >> >> +++ b/drivers/net/tun.c >> >> @@ -1015,17 +1015,9 @@ static void tun_net_uninit(struct net_device >> >> *dev) >> >> static int tun_net_open(struct net_device *dev) >> >> { >> >> struct tun_struct *tun =3D netdev_priv(dev); Will remove the above unused struct in next version. Sorry for the negligence! Have a nice day, thanks Fei >> >> - int i; >> >> netif_tx_start_all_queues(dev); >> >> - for (i =3D 0; i < tun->numqueues; i++) { >> >> - struct tun_file *tfile; >> >> - >> >> - tfile =3D rtnl_dereference(tun->tfiles[i]); >> >> - tfile->socket.sk->sk_write_space(tfile->socket.sk); >> >> - } >> >> - >> >> return 0; >> >> } >> >> @@ -3634,6 +3626,7 @@ static int tun_device_event(struct >> >> notifier_block *unused, >> >> { >> >> struct net_device *dev =3D netdev_notifier_info_to_dev(ptr); >> >> struct tun_struct *tun =3D netdev_priv(dev); >> >> + int i; >> >> if (dev->rtnl_link_ops !=3D &tun_link_ops) >> >> return NOTIFY_DONE; >> >> @@ -3643,6 +3636,14 @@ static int tun_device_event(struct >> >> notifier_block *unused, >> >> if (tun_queue_resize(tun)) >> >> return NOTIFY_BAD; >> >> break; >> >> + case NETDEV_UP: >> >> + for (i =3D 0; i < tun->numqueues; i++) { >> >> + struct tun_file *tfile; >> >> + >> >> + tfile =3D rtnl_dereference(tun->tfiles[i]); >> >> + tfile->socket.sk->sk_write_space(tfile->socket.sk); >> >> + } >> >> + break; >> >> default: >> >> break; >> >> } >> > >> > >> > Acked-by: Jason Wang > >