Commit b2f17564 authored by Alexander Duyck's avatar Alexander Duyck Committed by David S. Miller

net-sysfs: Add rtnl locking for getting Tx queue traffic class

In order to access the suboordinate dev for a device we should be holding
the rtnl_lock when outside of the transmit path. The existing code was not
doing that for the sysfs dump function and as a result we were open to a
possible race.

To resolve that take the rtnl lock prior to accessing the sb_dev field of
the Tx queue and release it after we have retrieved the tc for the queue.
Signed-off-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 796c9015
...@@ -1136,18 +1136,25 @@ static ssize_t traffic_class_show(struct netdev_queue *queue, ...@@ -1136,18 +1136,25 @@ static ssize_t traffic_class_show(struct netdev_queue *queue,
char *buf) char *buf)
{ {
struct net_device *dev = queue->dev; struct net_device *dev = queue->dev;
int num_tc, tc;
int index; int index;
int tc;
if (!netif_is_multiqueue(dev)) if (!netif_is_multiqueue(dev))
return -ENOENT; return -ENOENT;
if (!rtnl_trylock())
return restart_syscall();
index = get_netdev_queue_index(queue); index = get_netdev_queue_index(queue);
/* If queue belongs to subordinate dev use its TC mapping */ /* If queue belongs to subordinate dev use its TC mapping */
dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev; dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev;
num_tc = dev->num_tc;
tc = netdev_txq_to_tc(dev, index); tc = netdev_txq_to_tc(dev, index);
rtnl_unlock();
if (tc < 0) if (tc < 0)
return -EINVAL; return -EINVAL;
...@@ -1158,8 +1165,8 @@ static ssize_t traffic_class_show(struct netdev_queue *queue, ...@@ -1158,8 +1165,8 @@ static ssize_t traffic_class_show(struct netdev_queue *queue,
* belongs to the root device it will be reported with just the * belongs to the root device it will be reported with just the
* traffic class, so just "0" for TC 0 for example. * traffic class, so just "0" for TC 0 for example.
*/ */
return dev->num_tc < 0 ? sprintf(buf, "%d%d\n", tc, dev->num_tc) : return num_tc < 0 ? sprintf(buf, "%d%d\n", tc, num_tc) :
sprintf(buf, "%d\n", tc); sprintf(buf, "%d\n", tc);
} }
#ifdef CONFIG_XPS #ifdef CONFIG_XPS
......
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