Skip to contentSkip to conversation

hv_netvsc: fix vf serial matching with pci slot info

PATCH Superseded Haiyang Zhang 4 participants 5 messages Oct 11, 2018 – Oct 12, 2018

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <[email protected]>

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")
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/hyperv/netvsc_drv.c +11 -4
index 9bcaf204a7d4..8121ce34a39f 100644
@@ -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;
 }
 
Signature · 1 line
2.18.0
maintainer
#1 lore raw
Quoted 12 lines

-----Original Message-----
From: Haiyang Zhang <[email protected]>
Sent: Thursday, October 11, 2018 4:15 PM
To: [email protected]; [email protected]
Cc: Haiyang Zhang <[email protected]>; KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]
Subject: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

Quoted 8 lines

From: Haiyang Zhang <[email protected]>

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")

Thanks Stephen for the reminder -- I added the "reported-by" here:

#2 lore raw
Quoted 16 lines · Haiyang Zhang
Quoted 16 lines

-----Original Message-----
From: Haiyang Zhang <[email protected]>
Sent: Thursday, October 11, 2018 4:15 PM
To: [email protected]; [email protected]
Cc: Haiyang Zhang <[email protected]>; KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; vkuznets <[email protected]>; [email protected]; [email protected]
Subject: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

From: Haiyang Zhang <[email protected]>

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.

Quoted 6 lines
Quoted 2 lines
Fixes 00d7ddba1143 ("hv_netvsc: pair VF based on serial number")

Thanks Stephen for the reminder -- I added the "reported-by" here:

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().

Signature · 1 line
Vitaly
#3 lore raw
In reply to Haiyang Zhang
Quoted 36 lines · Haiyang Zhang

From: Haiyang Zhang <[email protected]>

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")
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/hyperv/netvsc_drv.c +3 -2
index 9bcaf204a7d4..8121ce34a39f 100644
@@ -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 */

drivers/net/hyperv/netvsc_drv.c static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) · line 2052

Quoted 4 lines
drivers/net/hyperv/netvsc_drv.c +1 -0
@@ -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

maintainer
#4 lore raw
Quoted 53 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Friday, October 12, 2018 2:36 AM
To: Haiyang Zhang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; [email protected]; [email protected]; vkuznets <[email protected]>
Subject: Re: [PATCH net-next] hv_netvsc: fix vf serial matching with pci slot info

drivers/net/hyperv/netvsc_drv.c static void netvsc_vf_setup(struct work_struct

Quoted 18 lines · Haiyang Zhang

From: Haiyang Zhang <[email protected]>

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")
---
 drivers/net/hyperv/netvsc_drv.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/hyperv/netvsc_drv.c index 9bcaf204a7d4..8121ce34a39f 100644

drivers/net/hyperv/netvsc_drv.c +0 -0
@@ -2030,14 +2030,15 @@ static void netvsc_vf_setup(struct work_struct

*w)

Quoted 7 lines
drivers/net/hyperv/netvsc_drv.c +2 -2
 	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.

drivers/net/hyperv/netvsc_drv.c static void netvsc_vf_setup(struct work_struct *w)

Quoted 10 lines
drivers/net/hyperv/netvsc_drv.c +1 -0
  */
 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 4 lines

struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev)

drivers/net/hyperv/netvsc_drv.c +0 -0
 		return NULL;
 	}
Quoted 6 lines

drivers/net/hyperv/netvsc_drv.c static struct net_device *get_netvsc_byslot(const struct net_device *vf_netdev) · line 2052

Quoted 1 line
drivers/net/hyperv/netvsc_drv.c +1 -0
+	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