Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp694794ybh; Tue, 10 Mar 2020 06:36:52 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsg/plvDpSyLbk2g0QWBjluyP1kr85KpIwGou232GqpCF7PuZ4W3Q3NvNc1lio7xtkaG8wD X-Received: by 2002:a9d:64d4:: with SMTP id n20mr15834887otl.193.1583847412011; Tue, 10 Mar 2020 06:36:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583847412; cv=none; d=google.com; s=arc-20160816; b=Z15bTjO1NwSZSc9opD1vw8zdZlfBDwR7tZqcrFvrIsp8rvUYf5XHThGN5d/nEnw1Yg Er6wECa83HaX7uNKbrF5yFORRWsz6ec3IdHsCE53nsh2Dus81K2JeJpuCSpyEbpsDoEe frTLRhmiZdjUlH3Hqri6f8eU4HP5jRrS1ipV1mATGUT27b+s6OpRECYfmmLoGoMK9r9a e6WlqC4tR1iaI9wpdBWVG+ZlfqTgcyq/jgQU8jlU2jCtilWTOKj+4SjdErSohjzubKT6 3yzzHRhOVqnIPyhSZkCx0YHJO5czZp1l8l3CEGdQvdtYndzFeCxuerPy+3/Ew4ZjSBIM lW5w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KV+2uWM4jhAJGYtB5WzS/vmPhnaH2emUNhcOz0boTSY=; b=rDyViy00sxICioG5Pz5i8RJx4wtdE/aMlOvg/7C73Bor6ftB7awNqTZo3GE0hXq4cV 33ApiolcaxGQJr/9893NpFmAR4sNAdtWNbwhek0lDNhsAriq+RYGXZ/j6OCWvEeDxiE0 zfg0+L0t4XlaqojFuzllmQDqp6OVRJfjQqo0zQsZSLk0ojqWQ3m/JACHRVRxnT9Oimmz JC/2u4ihDGsvJx05IikJXVS4arLR5V916EZjGaS8UiUmb/abpwrlI6rR8NAIh1hu5ZID KnEejZmJv4vDQzGfCUkP7Zay7+ob2E07xNL0+pcZmGaHDMZuOnBTx9GvJ1WRPwgEeRYo h1eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JgbbTD2a; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si7892246ote.183.2020.03.10.06.36.38; Tue, 10 Mar 2020 06:36:52 -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=@kernel.org header.s=default header.b=JgbbTD2a; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbgCJNe5 (ORCPT + 99 others); Tue, 10 Mar 2020 09:34:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:48366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727680AbgCJMpi (ORCPT ); Tue, 10 Mar 2020 08:45:38 -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 9175C2469C; Tue, 10 Mar 2020 12:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844338; bh=LDOxMJhlqNsrmrC05OIe9jerg9X6oq49/7cKqgJ+Cqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JgbbTD2adDFY9Y+slJtyUvR172cUMMzwuaprOB/lDQuK2yI1Q5ITPOeWTQOGYjuXK uQINQkK4ZYi/uZ2gZldw7NgmQt//2g9lcSO71+llIkgQ7BTGdxwsWD1ssIn7CuOzCr jxwtUiCQrRuB+ppMkOG3564g/I9D2DbXXXloJjOI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hannes Frederic Sowa , Eric Dumazet , Jason Wang , "David S. Miller" , Tommi Rantala Subject: [PATCH 4.9 45/88] tuntap: correctly set SOCKWQ_ASYNC_NOSPACE Date: Tue, 10 Mar 2020 13:38:53 +0100 Message-Id: <20200310123617.162923966@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123606.543939933@linuxfoundation.org> References: <20200310123606.543939933@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: Jason Wang commit 2f3ab6221e4c87960347d65c7cab9bd917d1f637 upstream. When link is down, writes to the device might fail with -EIO. Userspace needs an indication when the status is resolved. As a fix, tun_net_open() attempts to wake up writers - but that is only effective if SOCKWQ_ASYNC_NOSPACE has been set in the past. This is not the case of vhost_net which only poll for EPOLLOUT after it meets errors during sendmsg(). This patch fixes this by making sure SOCKWQ_ASYNC_NOSPACE is set when socket is not writable or device is down to guarantee EPOLLOUT will be raised in either tun_chr_poll() or tun_sock_write_space() after device is up. Cc: Hannes Frederic Sowa Cc: Eric Dumazet Fixes: 1bd4978a88ac2 ("tun: honor IFF_UP in tun_get_user()") Signed-off-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman Signed-off-by: Tommi Rantala --- drivers/net/tun.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1106,6 +1106,13 @@ static void tun_net_init(struct net_devi } } +static bool tun_sock_writeable(struct tun_struct *tun, struct tun_file *tfile) +{ + struct sock *sk = tfile->socket.sk; + + return (tun->dev->flags & IFF_UP) && sock_writeable(sk); +} + /* Character device part */ /* Poll */ @@ -1128,10 +1135,14 @@ static unsigned int tun_chr_poll(struct if (!skb_array_empty(&tfile->tx_array)) mask |= POLLIN | POLLRDNORM; - if (tun->dev->flags & IFF_UP && - (sock_writeable(sk) || - (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) && - sock_writeable(sk)))) + /* Make sure SOCKWQ_ASYNC_NOSPACE is set if not writable to + * guarantee EPOLLOUT to be raised by either here or + * tun_sock_write_space(). Then process could get notification + * after it writes to a down device and meets -EIO. + */ + if (tun_sock_writeable(tun, tfile) || + (!test_and_set_bit(SOCKWQ_ASYNC_NOSPACE, &sk->sk_socket->flags) && + tun_sock_writeable(tun, tfile))) mask |= POLLOUT | POLLWRNORM; if (tun->dev->reg_state != NETREG_REGISTERED)