From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52797 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751845AbeDJRIp (ORCPT ); Tue, 10 Apr 2018 13:08:45 -0400 From: Saeed Mahameed To: netdev@vger.kernel.org Cc: Saeed Mahameed Subject: [RFC net-next 2/2] net: net-sysfs: Reduce netstat_show read_lock critical section Date: Tue, 10 Apr 2018 10:08:12 -0700 Message-Id: <20180410170812.18905-2-saeedm@mellanox.com> In-Reply-To: <20180410170812.18905-1-saeedm@mellanox.com> References: <20180410170812.18905-1-saeedm@mellanox.com> Sender: netdev-owner@vger.kernel.org List-ID: Instead of holding the device chain read_lock also while calling dev_get_stats just hold it only to check dev_isalive, if the dev is alive, hold that dev via dev_hold then release the read_lock. When done handling the device, dev_put it. Signed-off-by: Saeed Mahameed --- net/core/net-sysfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index c476f0794132..ee6f9fed43df 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -563,13 +563,20 @@ static ssize_t netstat_show(const struct device *d, offset % sizeof(u64) != 0); read_lock(&dev_base_lock); - if (dev_isalive(dev)) { + if (dev_isalive(dev)) + dev_hold(dev); + else + dev = NULL; + read_unlock(&dev_base_lock); + + if (dev) { struct rtnl_link_stats64 temp; const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); + dev_put(dev); ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); } - read_unlock(&dev_base_lock); + return ret; } -- 2.14.3