Received: by 10.223.185.116 with SMTP id b49csp5461764wrg; Wed, 7 Mar 2018 12:09:47 -0800 (PST) X-Google-Smtp-Source: AG47ELuw1Ms84rYSl1/xFqPp9LOUutha7chVBDQIST36xTX/RyPGrUcM8zCX9U6uRDL6aslZdrju X-Received: by 10.99.67.1 with SMTP id q1mr2729171pga.365.1520453387369; Wed, 07 Mar 2018 12:09:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520453387; cv=none; d=google.com; s=arc-20160816; b=x35RBUJrad4mzUL+kUOnPZsTiqR1i/Dbwp8sY1VHPvYSr1zLFLJK9PTTNkhwqRTTo1 IyT5FfGLbPCRX3a8XmCtwAu15a2oeJaRaUKCgeukpJhTVO4uY2AftFpwnDuUnKaKolWs 6tdOjxLcxVC8udSw8wH66iuI3Tpl1saR1mhi+B5ErESlOZEUasx/jFF9M30lJ4RzaMKw eQEpQSOCYEldf3/TLIHb/PXF7MoMPZ35EFheI+JvfM5OrU9DJTAXC+PswoRsExTFDlU7 skfkZat/fihfaFv1DUhPTfZv+8Du8BFNiYtUzgvI6vQbHT0Oy0b/0x0Y7QKw0V61V0mz rKgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Scts/hJbY42HoF0zRz6TrXjmzzwhpfANbK5NY/nDezw=; b=ED4vb/lQq8tS94t9iL0StK5uYfIvZPlYWdjVLW9JxqwQjN2anXLpSl+BEPex8AomWt wnwXITEwTGgMvmFPQwD3MnEv8q7M0IjTnBuhJUY0zIdAE76i50g4iklkvOTxQjOC1bCA paaXO0kEI6V64cB+1p5yr5qNZucHZEoml2mR2VighoLTnJCc/DxNG/zibWzis/VtEYfK F2lutbm0qfHvEkYNLONRFP/lI9eOTpmJ9CuS1CS0HdSjrW6Uht7KeEF+NguB14YsmVgf jKhEf63ijZCVV1L4tJB4Ob3AUCETEwElC59jOTiNTYNAneQBymTVhvoEMndNTODqPqIK G1oA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd7-v6si660612plb.474.2018.03.07.12.09.33; Wed, 07 Mar 2018 12:09:47 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965386AbeCGTpp (ORCPT + 99 others); Wed, 7 Mar 2018 14:45:45 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44274 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964807AbeCGTpm (ORCPT ); Wed, 7 Mar 2018 14:45:42 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9D41A31; Wed, 7 Mar 2018 19:45:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Kicinski , "David S. Miller" Subject: [PATCH 4.14 040/110] net: fix race on decreasing number of TX queues Date: Wed, 7 Mar 2018 11:38:23 -0800 Message-Id: <20180307191044.878257226@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jakub Kicinski [ Upstream commit ac5b70198adc25c73fba28de4f78adcee8f6be0b ] netif_set_real_num_tx_queues() can be called when netdev is up. That usually happens when user requests change of number of channels/rings with ethtool -L. The procedure for changing the number of queues involves resetting the qdiscs and setting dev->num_tx_queues to the new value. When the new value is lower than the old one, extra care has to be taken to ensure ordering of accesses to the number of queues vs qdisc reset. Currently the queues are reset before new dev->num_tx_queues is assigned, leaving a window of time where packets can be enqueued onto the queues going down, leading to a likely crash in the drivers, since most drivers don't check if TX skbs are assigned to an active queue. Fixes: e6484930d7c7 ("net: allocate tx queues in register_netdevice") Signed-off-by: Jakub Kicinski Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2343,8 +2343,11 @@ EXPORT_SYMBOL(netdev_set_num_tc); */ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) { + bool disabling; int rc; + disabling = txq < dev->real_num_tx_queues; + if (txq < 1 || txq > dev->num_tx_queues) return -EINVAL; @@ -2360,15 +2363,19 @@ int netif_set_real_num_tx_queues(struct if (dev->num_tc) netif_setup_tc(dev, txq); - if (txq < dev->real_num_tx_queues) { + dev->real_num_tx_queues = txq; + + if (disabling) { + synchronize_net(); qdisc_reset_all_tx_gt(dev, txq); #ifdef CONFIG_XPS netif_reset_xps_queues_gt(dev, txq); #endif } + } else { + dev->real_num_tx_queues = txq; } - dev->real_num_tx_queues = txq; return 0; } EXPORT_SYMBOL(netif_set_real_num_tx_queues);