From: Vladimir Oltean <vladimir.olt...@nxp.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.

I need to preface this by saying that I have no idea why netstat_show
takes the dev_base_lock rwlock. Two things can be observed:
(a) it does not appear to be due to dev_isalive requiring it for some
    reason, because broadcast_show() also calls dev_isalive() and has
    had no problem existing since the beginning of git.
(b) the dev_get_stats function definitely does not need dev_base_lock
    protection either. In fact, holding the dev_base_lock is the entire
    problem here, because we want to make dev_get_stats sleepable, and
    holding a rwlock gives us atomic context.

So since no protection seems to be necessary, just run unlocked while
retrieving the /sys/class/net/eth0/statistics/* values.

Cc: Christian Brauner <christian.brau...@ubuntu.com>
Cc: Eric Dumazet <eduma...@google.com>
Signed-off-by: Vladimir Oltean <vladimir.olt...@nxp.com>
---
Changes in v4:
None.

Changes in v3:
None.

Changes in v2:
None.

 net/core/net-sysfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index daf502c13d6d..8604183678fc 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -585,14 +585,13 @@ static ssize_t netstat_show(const struct device *d,
        WARN_ON(offset > sizeof(struct rtnl_link_stats64) ||
                offset % sizeof(u64) != 0);
 
-       read_lock(&dev_base_lock);
        if (dev_isalive(dev)) {
                struct rtnl_link_stats64 temp;
                const struct rtnl_link_stats64 *stats = dev_get_stats(dev, 
&temp);
 
                ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset));
        }
-       read_unlock(&dev_base_lock);
+
        return ret;
 }
 
-- 
2.25.1

Reply via email to