Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1158817imm; Wed, 1 Aug 2018 11:09:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdUeg3ghu7SZdedymfjf+M69B46otYaFsuL72dlC8Y118utnKJIi6sSnkIilNESHaLKM2GC X-Received: by 2002:a65:504c:: with SMTP id k12-v6mr25499337pgo.435.1533146949386; Wed, 01 Aug 2018 11:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533146949; cv=none; d=google.com; s=arc-20160816; b=Dq3k0FKfYgAACsToltcEuIzpK6Bgr6o1zUX8fwnBC7Yk5VVwq0v4Fvb2X3+LARVWt5 MHL+f9DZqbbmIXRhPAm8E7nSSxjehh32LGDawJ5/Vj68XljouSoZ9A5gjfqtTpcbIFkE 6F1JLf4UHx6ALYrV36U4Rev2fYX267yM0QCFF6j6vurXaqrhdC8KGtiVG4cU6AiJ6PmN +o/pdTJW0+5T1VMv/WFkJ8jKNQwtfSoSMQQKfVW7MZZRiw/PC2X+nzdESAi0rfC8KxWd 7W105n/0YlDpuOE9ZxbU+ia8s1TOrfq84TS71bUhadk2O5qdTP1MnCkWSEUGPAxX/wII f+tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XI8tg8FVsXKRQ08iNjk/9bTHUS0YHGk3ybtCk/vod1M=; b=b31pPbjiQCp1/PX9kAouH0KcVYiKUuCF1batCNhMpEb8DTjlEV9+7+ZfG2fjRfMsSl RTaf3LpggVM1Wj+yg3OF4wA/IXlpKND+4kpJfjV9omwfOXwKWwQDij1DMN9S2EvoQBs2 QCZEOSo/o1IieJkpw+ShyMtw8XMmF+1jTUf73R8PNrxZb3riPPJCfVIIulpOKVuL1Bsz gSMKMqSSkJ087FBmAusgHptlXDWcWIbJyGTJmZL2cL4ctDwOTYL15/A1OtEhDKCMyttf pK44RCWhA6S8U+/U1rsdHld7QlFLFXIeitsaepgxtjcGW9Z4XFtHUdKdOAFYvqJ4ygVS GKSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j19-v6si16841132pgg.313.2018.08.01.11.08.54; Wed, 01 Aug 2018 11:09:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731342AbeHATzD (ORCPT + 99 others); Wed, 1 Aug 2018 15:55:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50226 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405749AbeHATIg (ORCPT ); Wed, 1 Aug 2018 15:08:36 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 66C68137B; Wed, 1 Aug 2018 17:14:01 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Hemminger , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 022/246] hv_netvsc: fix network namespace issues with VF support Date: Wed, 1 Aug 2018 18:48:52 +0200 Message-Id: <20180801165012.756257714@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephen Hemminger [ Upstream commit 7bf7bb37f16a80465ee3bd7c6c966f96f5a075a6 ] When finding the parent netvsc device, the search needs to be across all netvsc device instances (independent of network namespace). Find parent device of VF using upper_dev_get routine which searches only adjacent list. Fixes: e8ff40d4bff1 ("hv_netvsc: improve VF device matching") Signed-off-by: Stephen Hemminger netns aware byref Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/hyperv/hyperv_net.h | 2 + drivers/net/hyperv/netvsc_drv.c | 45 ++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 24 deletions(-) --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -724,6 +724,8 @@ struct net_device_context { struct hv_device *device_ctx; /* netvsc_device */ struct netvsc_device __rcu *nvdev; + /* list of netvsc net_devices */ + struct list_head list; /* reconfigure work */ struct delayed_work dwork; /* last reconfig time */ --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -66,6 +66,8 @@ static int debug = -1; module_param(debug, int, S_IRUGO); MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); +static LIST_HEAD(netvsc_dev_list); + static void netvsc_change_rx_flags(struct net_device *net, int change) { struct net_device_context *ndev_ctx = netdev_priv(net); @@ -1749,13 +1751,10 @@ out_unlock: static struct net_device *get_netvsc_bymac(const u8 *mac) { - struct net_device *dev; - - ASSERT_RTNL(); + struct net_device_context *ndev_ctx; - for_each_netdev(&init_net, dev) { - if (dev->netdev_ops != &device_ops) - continue; /* not a netvsc device */ + list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { + struct net_device *dev = hv_get_drvdata(ndev_ctx->device_ctx); if (ether_addr_equal(mac, dev->perm_addr)) return dev; @@ -1766,25 +1765,18 @@ static struct net_device *get_netvsc_bym static struct net_device *get_netvsc_byref(struct net_device *vf_netdev) { + struct net_device_context *net_device_ctx; struct net_device *dev; - ASSERT_RTNL(); - - for_each_netdev(&init_net, dev) { - struct net_device_context *net_device_ctx; - - if (dev->netdev_ops != &device_ops) - continue; /* not a netvsc device */ - - net_device_ctx = netdev_priv(dev); - if (!rtnl_dereference(net_device_ctx->nvdev)) - continue; /* device is removed */ + dev = netdev_master_upper_dev_get(vf_netdev); + if (!dev || dev->netdev_ops != &device_ops) + return NULL; /* not a netvsc device */ + + net_device_ctx = netdev_priv(dev); + if (!rtnl_dereference(net_device_ctx->nvdev)) + return NULL; /* device is removed */ - if (rtnl_dereference(net_device_ctx->vf_netdev) == vf_netdev) - return dev; /* a match */ - } - - return NULL; + return dev; } /* Called when VF is injecting data into network stack. @@ -2065,15 +2057,19 @@ static int netvsc_probe(struct hv_device else net->max_mtu = ETH_DATA_LEN; - ret = register_netdev(net); + rtnl_lock(); + ret = register_netdevice(net); if (ret != 0) { pr_err("Unable to register netdev.\n"); goto register_failed; } - return ret; + list_add(&net_device_ctx->list, &netvsc_dev_list); + rtnl_unlock(); + return 0; register_failed: + rtnl_unlock(); rndis_filter_device_remove(dev, nvdev); rndis_failed: free_percpu(net_device_ctx->vf_stats); @@ -2119,6 +2115,7 @@ static int netvsc_remove(struct hv_devic rndis_filter_device_remove(dev, nvdev); unregister_netdevice(net); + list_del(&ndev_ctx->list); rtnl_unlock(); rcu_read_unlock();