linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dexuan Cui <decui@microsoft.com>
To: davem@davemloft.net, kuba@kernel.org, kys@microsoft.com,
	haiyangz@microsoft.com, stephen@networkplumber.org,
	sthemmin@microsoft.com, wei.liu@kernel.org, liuwe@microsoft.com,
	netdev@vger.kernel.org, leon@kernel.org, andrew@lunn.ch,
	bernd@petrovitsch.priv.at, rdunlap@infradead.org,
	shacharr@microsoft.com
Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org,
	Dexuan Cui <decui@microsoft.com>
Subject: [PATCH v8 net-next 1/2] hv_netvsc: Make netvsc/VF binding check both MAC and serial number
Date: Fri, 16 Apr 2021 13:11:58 -0700	[thread overview]
Message-ID: <20210416201159.25807-2-decui@microsoft.com> (raw)
In-Reply-To: <20210416201159.25807-1-decui@microsoft.com>

Currently the netvsc/VF binding logic only checks the PCI serial number.

The upcoming Microsoft Azure Network Adapter (MANA) supports multiple
net_device interfaces (each such interface is called a "vPort", and has
its unique MAC address) which are backed by the same VF PCI device, so
the binding logic should check both the MAC address and the PCI serial
number.

The change should not break any other existing VF drivers, because
Hyper-V NIC SR-IOV implementation requires the netvsc network
interface and the VF network interface have the same MAC address.

Co-developed-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Co-developed-by: Shachar Raindel <shacharr@microsoft.com>
Signed-off-by: Shachar Raindel <shacharr@microsoft.com>
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 7349a70af083..f682a5572d84 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2297,6 +2297,7 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 {
 	struct device *parent = vf_netdev->dev.parent;
 	struct net_device_context *ndev_ctx;
+	struct net_device *ndev;
 	struct pci_dev *pdev;
 	u32 serial;
 
@@ -2319,8 +2320,17 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 		if (!ndev_ctx->vf_alloc)
 			continue;
 
-		if (ndev_ctx->vf_serial == serial)
-			return hv_get_drvdata(ndev_ctx->device_ctx);
+		if (ndev_ctx->vf_serial != serial)
+			continue;
+
+		ndev = hv_get_drvdata(ndev_ctx->device_ctx);
+		if (ndev->addr_len != vf_netdev->addr_len ||
+		    memcmp(ndev->perm_addr, vf_netdev->perm_addr,
+			   ndev->addr_len) != 0)
+			continue;
+
+		return ndev;
+
 	}
 
 	netdev_notice(vf_netdev,
-- 
2.25.1


  reply	other threads:[~2021-04-16 20:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 20:11 [PATCH v8 net-next 0/2] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) Dexuan Cui
2021-04-16 20:11 ` Dexuan Cui [this message]
2021-04-19 15:53   ` [PATCH v8 net-next 1/2] hv_netvsc: Make netvsc/VF binding check both MAC and serial number Stephen Hemminger
2021-04-22  0:18     ` Dexuan Cui
2021-04-16 20:11 ` [PATCH v8 net-next 2/2] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) Dexuan Cui
2021-04-19 15:54   ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416201159.25807-2-decui@microsoft.com \
    --to=decui@microsoft.com \
    --cc=andrew@lunn.ch \
    --cc=bernd@petrovitsch.priv.at \
    --cc=davem@davemloft.net \
    --cc=haiyangz@microsoft.com \
    --cc=kuba@kernel.org \
    --cc=kys@microsoft.com \
    --cc=leon@kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuwe@microsoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=shacharr@microsoft.com \
    --cc=stephen@networkplumber.org \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).