Commit 65fe24fd authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Greg Kroah-Hartman

net: fix race on decreasing number of TX queues


[ Upstream commit ac5b7019 ]

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: e6484930 ("net: allocate tx queues in register_netdevice")
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2f9e04ca
...@@ -2183,8 +2183,11 @@ EXPORT_SYMBOL(netif_set_xps_queue); ...@@ -2183,8 +2183,11 @@ EXPORT_SYMBOL(netif_set_xps_queue);
*/ */
int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
{ {
bool disabling;
int rc; int rc;
disabling = txq < dev->real_num_tx_queues;
if (txq < 1 || txq > dev->num_tx_queues) if (txq < 1 || txq > dev->num_tx_queues)
return -EINVAL; return -EINVAL;
...@@ -2200,15 +2203,19 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) ...@@ -2200,15 +2203,19 @@ int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq)
if (dev->num_tc) if (dev->num_tc)
netif_setup_tc(dev, txq); 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); qdisc_reset_all_tx_gt(dev, txq);
#ifdef CONFIG_XPS #ifdef CONFIG_XPS
netif_reset_xps_queues_gt(dev, txq); netif_reset_xps_queues_gt(dev, txq);
#endif #endif
} }
} else {
dev->real_num_tx_queues = txq;
} }
dev->real_num_tx_queues = txq;
return 0; return 0;
} }
EXPORT_SYMBOL(netif_set_real_num_tx_queues); EXPORT_SYMBOL(netif_set_real_num_tx_queues);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment