Skip to contentSkip to conversation

pci: properly parse 32-bit domain numbers

PATCH Applied Darek Stojaczyk 5 participants 6 messages May 12, 2020 – May 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: properly parse 32-bit domain numbers

The parsing code was bailing on domains greater than UINT16_MAX, but domain numbers like that are still valid and present on some systems. One example is Intel VMD (Volume Management Device), which acts somewhat as a software-managed PCI switch and its upstream linux driver assigns all downstream devices a PCI domain of 0x10000.

Parsing a BDF like 10000:01:00.0 was failing before. To fix it, increase the upper limit of domain number to UINT32_MAX. This matches the size of struct rte_pci_addr->domain (uint32).

---
 lib/librte_pci/rte_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_pci/rte_pci.c +2 -2
index d1ab6b414d..ad2cdfebb2 100644
@@ -72,9 +72,9 @@ pci_dbdf_parse(const char *input, struct rte_pci_addr *dev_addr)
 
 	errno = 0;
 	val = strtoul(in, &end, 16);
-	if (errno != 0 || end[0] != ':' || val > UINT16_MAX)
+	if (errno != 0 || end[0] != ':' || val > UINT32_MAX)
 		return -EINVAL;
-	dev_addr->domain = (uint16_t)val;
+	dev_addr->domain = (uint32_t)val;
 	in = end + 1;
 	in = get_u8_pciaddr_field(in, &dev_addr->bus, ':');
 	if (in == NULL)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 6 lines · Darek Stojaczyk

The parsing code was bailing on domains greater than UINT16_MAX, but domain numbers like that are still valid and present on some systems. One example is Intel VMD (Volume Management Device), which acts somewhat as a software-managed PCI switch and its upstream linux driver assigns all downstream devices a PCI domain of 0x10000.

Quoted 6 lines

Parsing a BDF like 10000:01:00.0 was failing before. To fix it, increase the upper limit of domain number to UINT32_MAX. This matches the size of struct rte_pci_addr->domain (uint32).

---

Cc stable?
Signature · 2 lines
Thanks,
Anatoly
#2 lore raw
In reply to Darek Stojaczyk
Quoted 31 lines · Darek Stojaczyk

The parsing code was bailing on domains greater than UINT16_MAX, but domain numbers like that are still valid and present on some systems. One example is Intel VMD (Volume Management Device), which acts somewhat as a software-managed PCI switch and its upstream linux driver assigns all downstream devices a PCI domain of 0x10000.

Parsing a BDF like 10000:01:00.0 was failing before. To fix it, increase the upper limit of domain number to UINT32_MAX. This matches the size of struct rte_pci_addr->domain (uint32).

Signed-off-by Darek Stojaczyk <[email protected] <mailto:[email protected]>>
---
 lib/librte_pci/rte_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_pci/rte_pci.c +2 -2
index d1ab6b414d..ad2cdfebb2 100644
@@ -72,9 +72,9 @@ pci_dbdf_parse(const char *input, struct 
 rte_pci_addr *dev_addr)
 
 	errno = 0;
 	val = strtoul(in, &end, 16);
-	if (errno != 0 || end[0] != ':' || val > UINT16_MAX)
+	if (errno != 0 || end[0] != ':' || val > UINT32_MAX)
 		return -EINVAL;
-	dev_addr->domain = (uint16_t)val;
+	dev_addr->domain = (uint32_t)val;
 	in = end + 1;
 	in = get_u8_pciaddr_field(in, &dev_addr->bus, ':');
Quoted 3 lines

if (in == NULL)
--
2.17.1

Agree this came up before on Hyper-V as well. It meant fixing libpci.

Not sure the cast of val is necessary, other than an attempt to silence some static checker about implicit type conversion causing loss of precision.

Quoted 1 line
Acked-by
#3 lore raw
Quoted 11 lines · Stephen Hemminger
Quoted 7 lines · Darek Stojaczyk

The parsing code was bailing on domains greater than UINT16_MAX, but domain numbers like that are still valid and present on some systems.
One example is Intel VMD (Volume Management Device), which acts somewhat as a software-managed PCI switch and its upstream linux driver assigns all downstream devices a PCI domain of 0x10000.

Quoted 6 lines
Quoted 6 lines

Parsing a BDF like 10000:01:00.0 was failing before. To fix it, increase the upper limit of domain number to UINT32_MAX. This matches the size of struct rte_pci_addr->domain (uint32).

<mailto:[email protected]>>

The original code predates the change from macro in commit c742e8d3110b.

Fixes af75078fece3 ("first public release")

Thanks for the fix,

Quoted 27 lines
Quoted 20 lines
---
 lib/librte_pci/rte_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_pci/rte_pci.c +2 -2
index d1ab6b414d..ad2cdfebb2 100644
@@ -72,9 +72,9 @@ pci_dbdf_parse(const char *input, struct rte_pci_addr
 *dev_addr)
 
 	errno = 0;
 	val = strtoul(in, &end, 16);
-	if (errno != 0 || end[0] != ':' || val > UINT16_MAX)
+	if (errno != 0 || end[0] != ':' || val > UINT32_MAX)
 		return -EINVAL;
-	dev_addr->domain = (uint16_t)val;
+	dev_addr->domain = (uint32_t)val;
 	in = end + 1;
 	in = get_u8_pciaddr_field(in, &dev_addr->bus, ':');
Quoted 3 lines

if (in == NULL)
--
2.17.1

Agree this came up before on Hyper-V as well. It meant fixing libpci.

Quoted 7 lines

Not sure the cast of val is necessary, other than an attempt to silence some static checker
about implicit type conversion causing loss of precision.

Quoted 1 line

The cast is useless indeed. Remnants from the original macro. For now best to leave it as-is, make another patch to remove those casts.

There are other potential bugs in parsing, -FFFFFFFFFFFF0001 is considered valid (-FFFFFFFF00000001 with this patch) as well as an empty domain. I will send a fix for those.

Signature · 1 line
Gaëtan
#4 lore raw
Quoted 9 lines

-----Original Message-----
From: Gaëtan Rivet <[email protected]>
Sent: Wednesday, May 13, 2020 11:04 AM
To: Stephen Hemminger <[email protected]>
Cc: Stojaczyk, Dariusz <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] pci: properly parse 32-bit domain numbers

[SNIP]

Quoted 8 lines

The original code predates the change from macro in commit c742e8d3110b.

Fixes af75078fece3 ("first public release")

Thanks for the fix,

Yes, I wasn't sure if this is a fix or more of a feature. Well, it *could* be backported, I guess. D.

Quoted 46 lines
Quoted 27 lines
Quoted 20 lines
---
 lib/librte_pci/rte_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_pci/rte_pci.c +2 -2
index d1ab6b414d..ad2cdfebb2 100644
@@ -72,9 +72,9 @@ pci_dbdf_parse(const char *input, struct rte_pci_addr
 *dev_addr)
 
 	errno = 0;
 	val = strtoul(in, &end, 16);
-	if (errno != 0 || end[0] != ':' || val > UINT16_MAX)
+	if (errno != 0 || end[0] != ':' || val > UINT32_MAX)
 		return -EINVAL;
-	dev_addr->domain = (uint16_t)val;
+	dev_addr->domain = (uint32_t)val;
 	in = end + 1;
 	in = get_u8_pciaddr_field(in, &dev_addr->bus, ':');
Quoted 3 lines

if (in == NULL)
--
2.17.1

Agree this came up before on Hyper-V as well. It meant fixing libpci.

Quoted 7 lines

Not sure the cast of val is necessary, other than an attempt to silence some static checker
about implicit type conversion causing loss of precision.

Quoted 1 line

The cast is useless indeed. Remnants from the original macro. For now best to leave it as-is, make another patch to remove those casts.

There are other potential bugs in parsing, -FFFFFFFFFFFF0001 is considered valid (-FFFFFFFF00000001 with this patch) as well as an empty domain.
I will send a fix for those.

--
Gaëtan

Acked-by Gaetan Rivet on v1 1/1 Applied
#5 lore raw
In reply to Darek Stojaczyk
Quoted 10 lines · Darek Stojaczyk

The parsing code was bailing on domains greater than UINT16_MAX, but domain numbers like that are still valid and present on some systems. One example is Intel VMD (Volume Management Device), which acts somewhat as a software-managed PCI switch and its upstream linux driver assigns all downstream devices a PCI domain of 0x10000.

Parsing a BDF like 10000:01:00.0 was failing before. To fix it, increase the upper limit of domain number to UINT32_MAX. This matches the size of struct rte_pci_addr->domain (uint32).

Fixes af75078fece3 ("first public release")
Quoted 1 line

Applied, thanks.

Signature · 1 line
David Marchand