From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BECD9C5B57D for ; Tue, 2 Jul 2019 08:15:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 985D420645 for ; Tue, 2 Jul 2019 08:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562055321; bh=H3AGDmzp0Zp1pSbvJRNNH0Kcv9iuWLBCIvSBDtcO4X0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dqICEDnj2PdAhMVmRHy0rP+f/Wpy6F3qF+ClPdwXTSMxDCzZEIN5lrcxhRYivDppP W3b5QGGluG/Op1ffd5YERERK2IyE9QnqZS5NsdMcPfBWnFKj5SsO7jTOPB1LYlNmsE 9rHNxogmrTH74aE/RfKSn2DlACRxw+03XMTMD4O0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728196AbfGBIPU (ORCPT ); Tue, 2 Jul 2019 04:15:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:50952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727869AbfGBIFH (ORCPT ); Tue, 2 Jul 2019 04:05:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F20AB2184B; Tue, 2 Jul 2019 08:05:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562054706; bh=H3AGDmzp0Zp1pSbvJRNNH0Kcv9iuWLBCIvSBDtcO4X0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s2pUQHdh1ZN1IqY0M6/TEKr/J1tdlpg5tplyg6LXSBMYDC37lzwGUNAq4+na1dweT rKIuHx5NXqK+LcUjKDxTdqYL1oCCj+XFyBc6+/9zbkFE4lu0cd2lUktxNaL95Kw7RY K8vmDa8HyF73aWlwDkSgfpzUl90zW8GCDgrl+Ops= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fei Li , Jason Wang , "David S. Miller" Subject: [PATCH 5.1 42/55] tun: wake up waitqueues after IFF_UP is set Date: Tue, 2 Jul 2019 10:01:50 +0200 Message-Id: <20190702080126.295927263@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080124.103022729@linuxfoundation.org> References: <20190702080124.103022729@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fei Li [ Upstream commit 72b319dc08b4924a29f5e2560ef6d966fa54c429 ] 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. Signed-off-by: Fei Li Acked-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/tun.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1024,18 +1024,8 @@ static void tun_net_uninit(struct net_de /* Net device open. */ static int tun_net_open(struct net_device *dev) { - struct tun_struct *tun = netdev_priv(dev); - int i; - netif_tx_start_all_queues(dev); - for (i = 0; i < tun->numqueues; i++) { - struct tun_file *tfile; - - tfile = rtnl_dereference(tun->tfiles[i]); - tfile->socket.sk->sk_write_space(tfile->socket.sk); - } - return 0; } @@ -3636,6 +3626,7 @@ static int tun_device_event(struct notif { struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct tun_struct *tun = netdev_priv(dev); + int i; if (dev->rtnl_link_ops != &tun_link_ops) return NOTIFY_DONE; @@ -3645,6 +3636,14 @@ static int tun_device_event(struct notif if (tun_queue_resize(tun)) return NOTIFY_BAD; break; + case NETDEV_UP: + for (i = 0; i < tun->numqueues; i++) { + struct tun_file *tfile; + + tfile = rtnl_dereference(tun->tfiles[i]); + tfile->socket.sk->sk_write_space(tfile->socket.sk); + } + break; default: break; }