From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AG47ELs26kcp0QAn7U4xyl3sKheECsQlkYOi/mx7/9ofDsLd6+2NYqA3x7joyWBkSDM5ZLTEpf9n ARC-Seal: i=1; a=rsa-sha256; t=1520641317; cv=none; d=google.com; s=arc-20160816; b=x0p9Rm+g64K06IWIpABXab4JYhi4r0Bo/GD1Cb1Ng+u3m90ymlpV+ssDom9MNiOPuH LftZ9qfpt2T0JnmyMkzMvJZqNi5xY+/BYL7GZTc/buPnxgHeOPltgA1/5H6O3CkTsTl+ 5YYimlbpQMF9ZZ6PV7aerNK0m41EVWwF8SSNDdsNPhMu9sIy3oJwcSwv8UOyJASDSq25 MwfkU1jhwzg1pfmt4mxbobwptNTJzPcHFXwiT0qD9D/Ubf6uNgRq9si8ub5L9EAK8TGd 0PZrQFb4EjI73HDOSlgFhAHmrhW61R2dpUhaq5dTWQ2OVLDPLL5XCzkwKbK+PtWyaCuf 7lQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ow0Eb5UcJakGeERhLBnP+q99RDAAxfN3fzm4ZU05jdg=; b=RaFk4AkXyLHtER1LXTr6m/Lk4lcD5POc3TzAS5f6FNqHPZPPvncCnP4B3AdbKDnwfY M+rvybK34wj7kWoYb6Vbf5nwwUv0i7ah8zYR8cB9h1n2nBsbbxuPPEDR9FeQx/6sy713 UAzTyl7WYg3tDsZBMssiLrVT5wsfiNzZerBbdM3O0tGst2I6enaSMmZRJ8D9e0sUlpcV COWowEif9qwHn7cDNJLsXYgBroqqz7X4aM4jadN4ExfX7MpxgChCuf1O1k51ZiKC38iN jmN27ZtfuG0B/+PFMkJSB/SGUuPR3mDa53Hyl+xnaWtaoN9Gmf9hyNKw1w1CDRuOJy+V sAwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 185.236.200.248 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 185.236.200.248 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org 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.9 37/65] net: fix race on decreasing number of TX queues Date: Fri, 9 Mar 2018 16:18:37 -0800 Message-Id: <20180310001827.922330526@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1594507800170011350?= X-GMAIL-MSGID: =?utf-8?q?1594507990374827746?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.9-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 @@ -2199,8 +2199,11 @@ EXPORT_SYMBOL(netif_set_xps_queue); */ 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; @@ -2216,15 +2219,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);