Received: by 10.223.185.111 with SMTP id b44csp916255wrg; Fri, 9 Mar 2018 16:47:34 -0800 (PST) X-Google-Smtp-Source: AG47ELt+3GZ8rNusHVBPInBO+jQYOgSKPiISafugjKpr6cFmLU+2CQNMbOJQdXFMIDBUOzQwKMKn X-Received: by 2002:a17:902:8c91:: with SMTP id t17-v6mr362273plo.233.1520642854535; Fri, 09 Mar 2018 16:47:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642854; cv=none; d=google.com; s=arc-20160816; b=RvYgb+9VzriDr4EXvI1MN+DLdb5WohQlVxjCeASdKCeXT4Qm4ZgW8Wffpfc8jsxXx/ tctVcZfbUALhFnWf9rAzBE9VM74sbIwOLinOWCPqIW+uKFPL2ozp0rDCfWPb7zsSrwLA r4bPAlDFA02MD2v6fy7ZgcUVSSBbBrttAuZL8BrMHpG42Hx4nSQJLQvBulLKX2LUuyfs XynUau/EsU3fwKXj8os+KYWQIJ3dmhNvg++dt0kqvapWNZ6TVEu5YS/7IAG6KGB+jNXR dncEA+KtYME/v/E76TkjJgLlj93oIUdP5pueTf9NDAef+lJVxcPFRzizw2H5oU4/oMAX yNyg== 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=Oo9ctgVeMRZBr9hgxeI51d20fo4SR4FvDcwZG4Mu9eY=; b=E28L7sjnsc6YfWlec55wdg42VuMqFMQfE2mYZlmkklo4ZHKdoEPC9D6OigXFJbYnMT YZCS+PIAyUhB7I7zteP8hoXwB8jUvUaJ1ROtgR1F+Gkrnio2lgoM0ugtR90rTN3cfyjM e8bE2Q44WP5rpUzz7wmiHMSGjH9MPwBQxX6yTcGWWWg+NNPWMuwRIsB6fSQHsqwle0j/ WbnaK7tK0MjqybbNmK4+H24QSxJpfaJjXwT2NIy90rJ1bZe8cSSWWXRH9hFcdsWtmwT8 L+qY4Lp8IVajgSJOiHBUeSPpn2ra8ReEohobsDpwAvl/WEeXo+WGQAixhFiEsCQhBsWg GwZQ== 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 i127si1000997pfc.148.2018.03.09.16.47.20; Fri, 09 Mar 2018 16:47:34 -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 S933325AbeCJAUL (ORCPT + 99 others); Fri, 9 Mar 2018 19:20:11 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39004 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933296AbeCJAUI (ORCPT ); Fri, 9 Mar 2018 19:20:08 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3CDD2FCD; Sat, 10 Mar 2018 00:20:08 +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.4 22/36] net: fix race on decreasing number of TX queues Date: Fri, 9 Mar 2018 16:18:38 -0800 Message-Id: <20180310001808.579152274@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001807.213987241@linuxfoundation.org> References: <20180310001807.213987241@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.4-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 @@ -2183,8 +2183,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; @@ -2200,15 +2203,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);