[PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

Subsystems: hyper-v/azure core and drivers, networking drivers, the rest

STALE2888d

5 messages, 4 authors, 2018-10-12 · open the first message on its own page

[PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <hidden>
Date: 2018-10-11 20:15:48

From: Haiyang Zhang <haiyangz@microsoft.com>

The VF device's serial number is saved as a string in PCI slot's
kobj name, not the slot->number. This patch corrects the netvsc
driver, so the VF device can be successfully paired with synthetic
NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 9bcaf204a7d4..8121ce34a39f 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct *w)
 	rtnl_unlock();
 }
 
-/* Find netvsc by VMBus serial number.
- * The PCI hyperv controller records the serial number as the slot.
+/* Find netvsc by VF serial number.
+ * The PCI hyperv controller records the serial number as the slot kobj name.
  */
 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 pci_dev *pdev;
+	u32 serial;
 
 	if (!parent || !dev_is_pci(parent))
 		return NULL; /* not a PCI device */
@@ -2048,16 +2049,22 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 		return NULL;
 	}
 
+	if (kstrtou32(pdev->slot->kobj.name, 10, &serial)) {
+		netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
+			      pdev->slot->kobj.name);
+		return NULL;
+	}
+
 	list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) {
 		if (!ndev_ctx->vf_alloc)
 			continue;
 
-		if (ndev_ctx->vf_serial == pdev->slot->number)
+		if (ndev_ctx->vf_serial == serial)
 			return hv_get_drvdata(ndev_ctx->device_ctx);
 	}
 
 	netdev_notice(vf_netdev,
-		      "no netdev found for slot %u\n", pdev->slot->number);
+		      "no netdev found for vf serial:%u\n", serial);
 	return NULL;
 }
 
-- 
2.18.0

RE: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <haiyangz@microsoft.com>
Date: 2018-10-11 22:31:04

-----Original Message-----
From: Haiyang Zhang <redacted>
Sent: Thursday, October 11, 2018 4:15 PM
To: davem@davemloft.net; netdev@vger.kernel.org
Cc: Haiyang Zhang <haiyangz@microsoft.com>; KY Srinivasan
[off-list ref]; Stephen Hemminger [off-list ref];
olaf@aepfle.de; vkuznets [off-list ref];
devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
Subject: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <haiyangz@microsoft.com>

The VF device's serial number is saved as a string in PCI slot's kobj name, not
the slot->number. This patch corrects the netvsc driver, so the VF device can be
successfully paired with synthetic NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Thanks Stephen for the reminder -- I added the "reported-by" here:

Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>

RE: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: 2018-10-12 06:27:51

Haiyang Zhang [off-list ref] writes:
quoted
-----Original Message-----
From: Haiyang Zhang <redacted>
Sent: Thursday, October 11, 2018 4:15 PM
To: davem@davemloft.net; netdev@vger.kernel.org
Cc: Haiyang Zhang <haiyangz@microsoft.com>; KY Srinivasan
[off-list ref]; Stephen Hemminger [off-list ref];
olaf@aepfle.de; vkuznets [off-list ref];
devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
Subject: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <haiyangz@microsoft.com>

The VF device's serial number is saved as a string in PCI slot's kobj name, not
the slot->number. This patch corrects the netvsc driver, so the VF device can be
successfully paired with synthetic NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Thanks Stephen for the reminder -- I added the "reported-by" here:

Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Thanks) 

The difference in the hack I sent to Stephen was that instead of using
kstrtou32() and checking the return value I opted for snprintf() and
doing strncmp().

-- 
Vitaly

Re: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Greg KH <gregkh@linuxfoundation.org>
Date: 2018-10-12 06:36:25

On Thu, Oct 11, 2018 at 08:14:34PM +0000, Haiyang Zhang wrote:
quoted hunk
From: Haiyang Zhang <haiyangz@microsoft.com>

The VF device's serial number is saved as a string in PCI slot's
kobj name, not the slot->number. This patch corrects the netvsc
driver, so the VF device can be successfully paired with synthetic
NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 9bcaf204a7d4..8121ce34a39f 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct *w)
 	rtnl_unlock();
 }
 
-/* Find netvsc by VMBus serial number.
- * The PCI hyperv controller records the serial number as the slot.
+/* Find netvsc by VF serial number.
+ * The PCI hyperv controller records the serial number as the slot kobj name.
  */
 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 pci_dev *pdev;
+	u32 serial;
 
 	if (!parent || !dev_is_pci(parent))
 		return NULL; /* not a PCI device */
@@ -2048,16 +2049,22 @@ static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 		return NULL;
 	}
 
+	if (kstrtou32(pdev->slot->kobj.name, 10, &serial)) {
kobject_name()?

And that feels _very_ fragile to me.  This is now an api that you are
guaranteeing will never change?

Good luck with that!

greg k-h

RE: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <haiyangz@microsoft.com>
Date: 2018-10-12 17:38:46

quoted hunk
-----Original Message-----
From: Greg KH <gregkh@linuxfoundation.org>
Sent: Friday, October 12, 2018 2:36 AM
To: Haiyang Zhang <haiyangz@microsoft.com>
Cc: davem@davemloft.net; netdev@vger.kernel.org; olaf@aepfle.de; Stephen
Hemminger [off-list ref]; linux-kernel@vger.kernel.org;
devel@linuxdriverproject.org; vkuznets [off-list ref]
Subject: Re: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

On Thu, Oct 11, 2018 at 08:14:34PM +0000, Haiyang Zhang wrote:
quoted
From: Haiyang Zhang <haiyangz@microsoft.com>

The VF device's serial number is saved as a string in PCI slot's kobj
name, not the slot->number. This patch corrects the netvsc driver, so
the VF device can be successfully paired with synthetic NIC.

Fixes: 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/net/hyperv/netvsc_drv.c
b/drivers/net/hyperv/netvsc_drv.c index 9bcaf204a7d4..8121ce34a39f
100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct
*w)
quoted
 	rtnl_unlock();
 }

-/* Find netvsc by VMBus serial number.
- * The PCI hyperv controller records the serial number as the slot.
+/* Find netvsc by VF serial number.
+ * The PCI hyperv controller records the serial number as the slot kobj name.
  */
 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 pci_dev *pdev;
+	u32 serial;

 	if (!parent || !dev_is_pci(parent))
 		return NULL; /* not a PCI device */ @@ -2048,16 +2049,22
@@ static
quoted
struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)
 		return NULL;
 	}

+	if (kstrtou32(pdev->slot->kobj.name, 10, &serial)) {
kobject_name()?

And that feels _very_ fragile to me.  This is now an api that you are
guaranteeing will never change?
Thanks for the suggestion -- I will update it to use kobject_name() to 
access the name.

For stability, the VF NIC's serial numbers are always unique according
to the Hyper-V documents. Other devices may have same numbers,
but they are not handled by netvsc driver.

Thanks,
- Haiyang
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help