Skip to contentSkip to conversation

pci/linux: copy new id for inserted device

PATCH Superseded Jim Harris 2 participants 10 messages Aug 21, 2020 – Oct 13, 2020

lore
Share & tools
lore

Jim Harris

author
#0 lore raw

PATCH 1/1 pci/linux: copy new id for inserted device

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

---
 drivers/bus/pci/linux/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +3 -1
index a2198abf4..4701661e5 100644
@@ -352,6 +352,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 				if (!rte_dev_is_probed(&dev2->device)) {
 					dev2->kdrv = dev->kdrv;
 					dev2->max_vfs = dev->max_vfs;
+					memcpy(&dev2->id, &dev->id, sizeof(dev2->id));
 					pci_name_set(dev2);
 					memmove(dev2->mem_resource,
 						dev->mem_resource,
@@ -365,7 +366,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 					 * need to do anything here unless...
 					 **/
 					if (dev2->kdrv != dev->kdrv ||
-						dev2->max_vfs != dev->max_vfs)
+						dev2->max_vfs != dev->max_vfs ||
+						memcmp(&dev2->id, &dev->id, sizeof(dev2->id))
 						/*
 						 * This should not happens.
 						 * But it is still possible if
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v2 1/1 pci/linux: copy new id for inserted device

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

---
 drivers/bus/pci/linux/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +3 -1
index a2198abf4..d8fd973b2 100644
@@ -352,6 +352,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 				if (!rte_dev_is_probed(&dev2->device)) {
 					dev2->kdrv = dev->kdrv;
 					dev2->max_vfs = dev->max_vfs;
+					memcpy(&dev2->id, &dev->id, sizeof(dev2->id));
 					pci_name_set(dev2);
 					memmove(dev2->mem_resource,
 						dev->mem_resource,
@@ -365,7 +366,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 					 * need to do anything here unless...
 					 **/
 					if (dev2->kdrv != dev->kdrv ||
-						dev2->max_vfs != dev->max_vfs)
+						dev2->max_vfs != dev->max_vfs ||
+						memcmp(&dev2->id, &dev->id, sizeof(dev2->id)))
 						/*
 						 * This should not happens.
 						 * But it is still possible if
Signature · 1 line
2.20.1
#2 lore raw

Hi Jim,

Sorry I see nobody reviewed your patch.

Quoted 1 line · Jim Harris

+ memcpy(&dev2->id, &dev->id, sizeof(dev2->id));

[...]

Quoted 1 line

+ memcmp(&dev2->id, &dev->id, sizeof(dev2->id)))

Why using memcpy and memcmp instead of simple assignment and comparison?

#3 lore raw

On 10/7/20, 8:06 AM, "Thomas Monjalon" <[email protected]> wrote:

Hi Jim,

Sorry I see nobody reviewed your patch.

Jim Harris <[email protected]> wrote:
> + memcpy(&dev2->id, &dev->id, sizeof(dev2->id)); [...]
> + memcmp(&dev2->id, &dev->id, sizeof(dev2->id)))

Why using memcpy and memcmp instead of simple assignment and comparison?

Direct assignment and comparison would work too. I did see some similar cases though using memcpy for rte_pci_addr (which is similar to rte_pci_id) in linux/pci_uio.c and linux/pci_vfio.c. It wasn't clear to me if direct assignment/comparison for structures was the norm for DPDK.

I'm happy to send a v2 with a direct assignment/comparison though if that is preferred.

-Jim

#4 lore raw

12/10/2020 22:58, Harris, James R:

Quoted 12 lines

On 10/7/20, 8:06 AM, "Thomas Monjalon" <[email protected]> wrote:

Hi Jim,

Sorry I see nobody reviewed your patch.

Jim Harris <[email protected]> wrote:
> + memcpy(&dev2->id, &dev->id, sizeof(dev2->id)); [...]
> + memcmp(&dev2->id, &dev->id, sizeof(dev2->id)))

Quoted 5 lines

Why using memcpy and memcmp instead of simple assignment and comparison?

Direct assignment and comparison would work too. I did see some similar cases though using memcpy for rte_pci_addr (which is similar to rte_pci_id) in linux/pci_uio.c and linux/pci_vfio.c. It wasn't clear to me if direct assignment/comparison for structures was the norm for DPDK.

I'm happy to send a v2 with a direct assignment/comparison though if that is preferred.

Yes please, direct assignment is preferred.
Thanks

author
#5 lore raw

PATCH v3 1/1 pci/linux: copy new id for inserted device

In reply to Jim Harris

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

---
 drivers/bus/pci/linux/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +3 -1
index a2198abf4..2e37735c2 100644
@@ -352,6 +352,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 				if (!rte_dev_is_probed(&dev2->device)) {
 					dev2->kdrv = dev->kdrv;
 					dev2->max_vfs = dev->max_vfs;
+					dev2->id = dev->id;
 					pci_name_set(dev2);
 					memmove(dev2->mem_resource,
 						dev->mem_resource,
@@ -365,7 +366,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 					 * need to do anything here unless...
 					 **/
 					if (dev2->kdrv != dev->kdrv ||
-						dev2->max_vfs != dev->max_vfs)
+						dev2->max_vfs != dev->max_vfs ||
+						dev2->id != dev->id)
 						/*
 						 * This should not happens.
 						 * But it is still possible if
Signature · 1 line
2.20.1
#6 lore raw

13/10/2020 00:01, Jim Harris:

Quoted 11 lines

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

---

drivers/bus/pci/linux/pci.c pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) · line 355

Quoted 4 lines
drivers/bus/pci/linux/pci.c +1 -0
@@ -352,6 +352,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 				if (!rte_dev_is_probed(&dev2->device)) {
 					dev2->kdrv = dev->kdrv;
 					dev2->max_vfs = dev->max_vfs;
+					dev2->id = dev->id;

This simple assignment looks nicer than memcpy.
Thanks for this change.

[...]

drivers/bus/pci/linux/pci.c pci_scan_one(const char *dirname, const struct rte_pci_addr *addr) · line 370

Quoted 4 lines
drivers/bus/pci/linux/pci.c +2 -1
 					if (dev2->kdrv != dev->kdrv ||
-						dev2->max_vfs != dev->max_vfs)
+						dev2->max_vfs != dev->max_vfs ||
+						dev2->id != dev->id)

Unfortunately comparison of structs is not supported. It seems your original memcmp is right.

author
#7 lore raw

PATCH v4 1/1 pci/linux: copy new id for inserted device

In reply to Jim Harris

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

---
 drivers/bus/pci/linux/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +3 -1
index a2198abf4..86e920d1c 100644
@@ -352,6 +352,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 				if (!rte_dev_is_probed(&dev2->device)) {
 					dev2->kdrv = dev->kdrv;
 					dev2->max_vfs = dev->max_vfs;
+					dev2->id = dev->id;
 					pci_name_set(dev2);
 					memmove(dev2->mem_resource,
 						dev->mem_resource,
@@ -365,7 +366,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 					 * need to do anything here unless...
 					 **/
 					if (dev2->kdrv != dev->kdrv ||
-						dev2->max_vfs != dev->max_vfs)
+						dev2->max_vfs != dev->max_vfs ||
+						memcmp(&dev2->id, &dev->id))
 						/*
 						 * This should not happens.
 						 * But it is still possible if
Signature · 1 line
2.20.1
author
#8 lore raw

PATCH v5 1/1 pci/linux: copy new id for inserted device

In reply to Jim Harris

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

---
 drivers/bus/pci/linux/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci.c +3 -1
index a2198abf4..e51f9d756 100644
@@ -352,6 +352,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 				if (!rte_dev_is_probed(&dev2->device)) {
 					dev2->kdrv = dev->kdrv;
 					dev2->max_vfs = dev->max_vfs;
+					dev2->id = dev->id;
 					pci_name_set(dev2);
 					memmove(dev2->mem_resource,
 						dev->mem_resource,
@@ -365,7 +366,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 					 * need to do anything here unless...
 					 **/
 					if (dev2->kdrv != dev->kdrv ||
-						dev2->max_vfs != dev->max_vfs)
+						dev2->max_vfs != dev->max_vfs ||
+						memcmp(&dev2->id, &dev->id, sizeof(dev2->id)))
 						/*
 						 * This should not happens.
 						 * But it is still possible if
Signature · 1 line
2.20.1
#9 lore raw

13/10/2020 19:03, Jim Harris:

Quoted 7 lines

When a device is inserted into an existing BDF slot that has not been probed, we must overwrite the old PCI ID with the ID of the new function. Otherwise we may not probe the function with the correct driver, if at all.

Applied, thanks