Skip to content

Commit

Permalink
parisc/led: hold the netdev lists lock when retrieving device statistics
Browse files Browse the repository at this point in the history
In the effort of making .ndo_get_stats64 be able to sleep, we need to
ensure the callers of dev_get_stats do not use atomic context.

The LED driver for HP-PARISC workstations uses a workqueue to
periodically check for updates in network interface statistics, and
flicker when those have changed (i.e. there has been activity on the
line). Ignoring the fact that this driver is completely duplicating
drivers/leds/trigger/ledtrig-netdev.c, there is an even bigger problem.
Now, the dev_get_stats call can sleep, and iterating through the list of
network interfaces still needs to ensure the integrity of list of
network interfaces. So that leaves us only one locking option given the
current design of the network stack, and that is the netns mutex.

Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: linux-parisc@vger.kernel.org
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
  • Loading branch information
vladimiroltean authored and intel-lab-lkp committed Dec 7, 2020
1 parent 350ebdb commit 4c4eb38
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions drivers/parisc/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <linux/ctype.h>
#include <linux/blkdev.h>
#include <linux/workqueue.h>
#include <linux/rcupdate.h>
#include <asm/io.h>
#include <asm/processor.h>
#include <asm/hardware.h>
Expand Down Expand Up @@ -356,24 +355,28 @@ static __inline__ int led_get_net_activity(void)

rx_total = tx_total = 0;

/* we are running as a workqueue task, so we can use an RCU lookup */
rcu_read_lock();
for_each_netdev_rcu(&init_net, dev) {
/* we are running as a workqueue task, so we can sleep */
mutex_lock(&init_net->netdev_lists_lock);

for_each_netdev(&init_net, dev) {
struct in_device *in_dev = in_dev_get(dev);
const struct rtnl_link_stats64 *stats;
struct rtnl_link_stats64 temp;
struct in_device *in_dev = __in_dev_get_rcu(dev);

if (!in_dev || !in_dev->ifa_list)
if (!in_dev || !in_dev->ifa_list ||
ipv4_is_loopback(in_dev->ifa_list->ifa_local)) {
in_dev_put(in_dev);
continue;
}

if (ipv4_is_loopback(in_dev->ifa_list->ifa_local))
continue;
in_dev_put(in_dev);

stats = dev_get_stats(dev, &temp);
rx_total += stats->rx_packets;
tx_total += stats->tx_packets;
}
rcu_read_unlock();

mutex_unlock(&init_net->netdev_lists_lock);

retval = 0;

Expand Down

0 comments on commit 4c4eb38

Please sign in to comment.