[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210105185902.3922928-8-olteanv@gmail.com>
Date: Tue, 5 Jan 2021 20:58:57 +0200
From: Vladimir Oltean <olteanv@...il.com>
To: "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: netdev@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Paul Gortmaker <paul.gortmaker@...driver.com>,
Pablo Neira Ayuso <pablo@...filter.org>,
Jiri Benc <jbenc@...hat.com>,
Cong Wang <xiyou.wangcong@...il.com>,
Jamal Hadi Salim <jhs@...atatu.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Eric Dumazet <edumazet@...gle.com>,
George McCollister <george.mccollister@...il.com>,
Oleksij Rempel <o.rempel@...gutronix.de>,
Jay Vosburgh <j.vosburgh@...il.com>,
Veaceslav Falico <vfalico@...il.com>,
Andy Gospodarek <andy@...yhouse.net>,
Arnd Bergmann <arnd@...db.de>,
Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andriin@...com>,
Daniel Borkmann <daniel@...earbox.net>,
Taehee Yoo <ap420073@...il.com>,
Jiri Pirko <jiri@...lanox.com>,
Björn Töpel <bjorn.topel@...el.com>,
Paolo Abeni <pabeni@...hat.com>,
Christian Brauner <christian.brauner@...ntu.com>,
Florian Westphal <fw@...len.de>, linux-s390@...r.kernel.org,
intel-wired-lan@...ts.osuosl.org, linux-parisc@...r.kernel.org,
linux-scsi@...r.kernel.org, linux-usb@...r.kernel.org,
dev@...nvswitch.org
Subject: [RFC PATCH v2 net-next 07/12] parisc/led: hold the netdev lists lock when retrieving device statistics
From: Vladimir Oltean <vladimir.oltean@....com>
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@...senPartnership.com>
Cc: Helge Deller <deller@....de>
Cc: linux-parisc@...r.kernel.org
Signed-off-by: Vladimir Oltean <vladimir.oltean@....com>
---
drivers/parisc/led.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 3cada632a4be..c8c6b2301dc9 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -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>
@@ -355,25 +354,29 @@ static __inline__ int led_get_net_activity(void)
int retval;
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 */
+ netif_lists_lock(&init_net);
+
+ 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();
+
+ netif_lists_unlock(&init_net);
retval = 0;
--
2.25.1
Powered by blists - more mailing lists