hv_netvsc: Fix a warning of suspicious RCU usage [Linux 4.14.143]

This Linux kernel change "hv_netvsc: Fix a warning of suspicious RCU usage" is included in the Linux 4.14.143 release. This change is authored by Dexuan Cui <decui [at] microsoft.com> on Fri Aug 9 01:58:08 2019 +0000. The commit for this change in Linux stable tree is 269e995 (patch) which is from upstream commit 6d0d779. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 6d0d779.

hv_netvsc: Fix a warning of suspicious RCU usage

[ Upstream commit 6d0d779dca73cd5acb649c54f81401f93098b298 ]

This fixes a warning of "suspicious rcu_dereference_check() usage"
when nload runs.

Fixes: 776e726bfb34 ("netvsc: fix RCU warning in get_stats")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>

There are 9 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/hyperv/netvsc_drv.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index eb92720..33c1f65 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1170,12 +1170,15 @@ static void netvsc_get_stats64(struct net_device *net,
                   struct rtnl_link_stats64 *t)
 {
    struct net_device_context *ndev_ctx = netdev_priv(net);
-   struct netvsc_device *nvdev = rcu_dereference_rtnl(ndev_ctx->nvdev);
+   struct netvsc_device *nvdev;
    struct netvsc_vf_pcpu_stats vf_tot;
    int i;

+   rcu_read_lock();
+
+   nvdev = rcu_dereference(ndev_ctx->nvdev);
    if (!nvdev)
-       return;
+       goto out;

    netdev_stats_to_stats64(t, &net->stats);

@@ -1214,6 +1217,8 @@ static void netvsc_get_stats64(struct net_device *net,
        t->rx_packets   += packets;
        t->multicast    += multicast;
    }
+out:
+   rcu_read_unlock();
 }

 static int netvsc_set_mac_addr(struct net_device *ndev, void *p)

Leave a Reply

Your email address will not be published. Required fields are marked *