Skip to contentSkip to conversation

hv_netvsc: fix vf serial matching with pci slot info

PATCH Superseded Haiyang Zhang 3 participants 3 messages Oct 12, 2018

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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..ded623862003 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(kobject_name(&pdev->slot->kobj), 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
#1 lore raw

On Fri, 12 Oct 2018 20:55:15 +0000
Haiyang Zhang <[email protected]> wrote:

Thanks for fixing this.

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

Quoted 5 lines
drivers/net/hyperv/netvsc_drv.c +5 -0
+	if (kstrtou32(kobject_name(&pdev->slot->kobj), 10, &serial)) {
+		netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
+			      pdev->slot->kobj.name);
+		return NULL;
+	}

Shouldn't this use kobject_name() in the message as well.

Looking at the pci.h code there is already an API to get name from slot (it uses kobject_name()). So please use that one.

maintainer
#2 lore raw
Quoted 26 lines

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

On Fri, 12 Oct 2018 20:55:15 +0000
Haiyang Zhang <[email protected]> wrote:

Thanks for fixing this.

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

Quoted 5 lines
drivers/net/hyperv/netvsc_drv.c +5 -0
+	if (kstrtou32(kobject_name(&pdev->slot->kobj), 10, &serial)) {
+		netdev_notice(vf_netdev, "Invalid vf serial:%s\n",
+			      pdev->slot->kobj.name);
+		return NULL;
+	}

Shouldn't this use kobject_name() in the message as well.

Quoted 2 lines

Looking at the pci.h code there is already an API to get name from slot (it uses kobject_name()). So please use that one.

Sure, I will look for that api. Thanks.