Skip to contentSkip to conversation

VT-d: fix VF of RC integrated PF matched to wrong VT-d unit

PATCH Superseded Chao Gao 4 participants 12 messages Jun 30, 2017 – Jul 5, 2017

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Chao Gao

author
#0 lore raw

PATCH v4 1/1 VT-d: fix VF of RC integrated PF matched to wrong VT-d unit

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be classified to two kinds: one is RC integrated PF and the other is non-RC integrated PF. The former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d unit. And according to PCIe spec, Extened Function means within an ARI device, a Function whose Function Number is greater than 7. Thus, the former can't be an extended function, while the latter is as long as its devfn > 7, this check is exactly what the original code did; The original code wasn't aware the former.

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

---
v3:
- access pf's struct pci_pdev between pcidevs_lock() and pcidevs_unlock()

---
 xen/drivers/passthrough/vtd/dmar.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/dmar.c +10 -1
index 82040dd..27ff471 100644
@@ -218,8 +218,17 @@ struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
     }
     else if ( pdev->info.is_virtfn )
     {
+        struct pci_dev *physfn;
+
         bus = pdev->info.physfn.bus;
-        devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn;
+        /*
+         * Use 0 as 'devfn' to search VT-d unit when the physical function
+         * is an Extended Function.
+         */
+        pcidevs_lock();
+        physfn = pci_get_pdev(pdev->seg, bus, pdev->info.physfn.devfn);
+        devfn = (physfn && physfn->info.is_extfn) ? 0 : pdev->info.physfn.devfn;
+        pcidevs_unlock();
     }
     else
     {
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 19 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be classified to two kinds: one is RC integrated PF and the other is non-RC integrated PF. The former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d unit. And according to PCIe spec, Extened Function means within an ARI device, a Function whose Function Number is greater than 7. Thus, the former can't be an
extended function, while the latter is as long as its devfn > 7, this check is exactly what the original code did; The original code wasn't aware the former.

Quoted 2 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

Quoted 6 lines

---
v3:
- access pf's struct pci_pdev between pcidevs_lock() and pcidevs_unlock()

should be v4.

Quoted 17 lines
---
 xen/drivers/passthrough/vtd/dmar.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
xen/drivers/passthrough/vtd/dmar.c +2 -0
index 82040dd..27ff471 100644
@@ -218,8 +218,17 @@ struct acpi_drhd_unit
 *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
     }
     else if ( pdev->info.is_virtfn )
     {
+        struct pci_dev *physfn;
+
         bus = pdev->info.physfn.bus;

xen/drivers/passthrough/vtd/dmar.c struct acpi_drhd_unit · line 233

Quoted 10 lines
xen/drivers/passthrough/vtd/dmar.c +7 -1
-        devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev-
 >info.physfn.devfn;
+        /*
+         * Use 0 as 'devfn' to search VT-d unit when the physical function
+         * is an Extended Function.
+         */
+        pcidevs_lock();
+        physfn = pci_get_pdev(pdev->seg, bus, pdev->info.physfn.devfn);
+        devfn = (physfn && physfn->info.is_extfn) ? 0 : pdev-
 >info.physfn.devfn;

is it legal to have physfn as NULL when is_virtfn is true?

Quoted 6 lines
xen/drivers/passthrough/vtd/dmar.c +1 -0
+        pcidevs_unlock();
     }
     else
     {

--
1.8.3.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 22 lines
Quoted 22 lines
Quoted 1 line

"Tian, Kevin" <[email protected]> 06/30/17 11:20 AM >>>

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

xen/drivers/passthrough/vtd/dmar.c +9 -1
@@ -218,8 +218,17 @@ struct acpi_drhd_unit
 *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
     }
     else if ( pdev->info.is_virtfn )
     {
+        struct pci_dev *physfn;
+
         bus = pdev->info.physfn.bus;
-        devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev-
 >info.physfn.devfn;
+        /*
+         * Use 0 as 'devfn' to search VT-d unit when the physical function
+         * is an Extended Function.
+         */
+        pcidevs_lock();
+        physfn = pci_get_pdev(pdev->seg, bus, pdev->info.physfn.devfn);
+        devfn = (physfn && physfn->info.is_extfn) ? 0 : pdev-
Quoted 3 lines

xen/drivers/passthrough/vtd/dmar.c struct acpi_drhd_unit · line 233

Quoted 1 line
xen/drivers/passthrough/vtd/dmar.c +0 -0
 >info.physfn.devfn;

is it legal to have physfn as NULL when is_virtfn is true?

I had asked for the check to be there just to be on the safe side.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#3 lore raw
In reply to Tian, Kevin
Quoted 19 lines · Kevin
Quoted 19 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be classified to two kinds: one is RC integrated PF and the other is non-RC integrated PF. The former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d unit. And according to PCIe spec, Extened Function means within an ARI device, a Function whose Function Number is greater than 7. Thus, the former can't be an
extended function, while the latter is as long as its devfn > 7, this check is exactly what the original code did; The original code wasn't aware the former.

Quoted 8 lines
Quoted 2 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

How about this:

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

If a PF is an extended function, a traditional function's BDF should be used to search VT-d unit. Previous code only checks whether Function Number is greater than 7, without checking the prerequisite that the function should be within an ARI device. This incurs wrongly using traditional function's BDF when the PF is RC integrated and thus cannot be within an ARI device.

Considering 'is_extfn' field of struct pci_dev has been passed down from Domain0 to indicate whether the function is an extended function, this patch just looks up that field of PF's struct pci_dev and adjust BDF used to search VT-d unit accordingly.

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 38 lines

From: Gao, Chao
Sent: Monday, July 3, 2017 12:37 PM

Quoted 10 lines · Kevin
Quoted 10 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be classified

to

Quoted 1 line
Quoted 1 line

two kinds: one is RC integrated PF and the other is non-RC integrated PF.

The

Quoted 2 lines
Quoted 2 lines

former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d

unit.

Quoted 1 line
Quoted 1 line

And according to PCIe spec, Extened Function means within an ARI device,

a

Quoted 1 line
Quoted 1 line

Function whose Function Number is greater than 7. Thus, the former can't

be

Quoted 3 lines
Quoted 3 lines

an
extended function, while the latter is as long as its devfn > 7, this check is exactly what the original code did; The original code wasn't aware the

former.

Quoted 9 lines
Quoted 3 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

Quoted 8 lines

How about this:

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

If a PF is an extended function, a traditional function's BDF should be used to search VT-d unit. Previous code only checks whether Function Number is greater than 7, without checking the prerequisite that the

where did above check come from in original code?

- devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn;

Quoted 9 lines

function should be within an ARI device. This incurs wrongly using traditional function's BDF when the PF is RC integrated and thus cannot be within an ARI device.

Considering 'is_extfn' field of struct pci_dev has been passed down from Domain0 to indicate whether the function is an extended function, this patch just looks up that field of PF's struct pci_dev and adjust BDF used to search VT-d unit accordingly.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#5 lore raw
Quoted 43 lines · Kevin
Quoted 43 lines

From: Gao, Chao
Sent: Monday, July 3, 2017 12:37 PM

Quoted 10 lines · Kevin
Quoted 10 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be classified

to

Quoted 1 line
Quoted 1 line

two kinds: one is RC integrated PF and the other is non-RC integrated PF.

The

Quoted 2 lines
Quoted 2 lines

former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d

unit.

Quoted 1 line
Quoted 1 line

And according to PCIe spec, Extened Function means within an ARI device,

a

Quoted 1 line
Quoted 1 line

Function whose Function Number is greater than 7. Thus, the former can't

be

Quoted 3 lines
Quoted 3 lines

an
extended function, while the latter is as long as its devfn > 7, this check is exactly what the original code did; The original code wasn't aware the

former.

Quoted 9 lines
Quoted 3 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

How about this:

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

Quoted 8 lines
Quoted 3 lines

If a PF is an extended function, a traditional function's BDF should be used to search VT-d unit. Previous code only checks whether Function Number is greater than 7, without checking the prerequisite that the

where did above check come from in original code?

- devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn;

Yes. It is the check I described. This line assigns 0 to 'devfn' if PF's function number > 7. Otherwise, use PF's real devfn.

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
Quoted 56 lines

From: Gao, Chao
Sent: Wednesday, July 5, 2017 12:28 PM

Quoted 7 lines · Kevin
Quoted 7 lines

From: Gao, Chao
Sent: Monday, July 3, 2017 12:37 PM

Quoted 3 lines · Kevin
Quoted 3 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be

classified

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line
Quoted 1 line

two kinds: one is RC integrated PF and the other is non-RC integrated

PF.

Quoted 5 lines
Quoted 5 lines

The

Quoted 2 lines
Quoted 2 lines

former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d

unit.

Quoted 1 line
Quoted 1 line

And according to PCIe spec, Extened Function means within an ARI

device,

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

Function whose Function Number is greater than 7. Thus, the former

can't

Quoted 3 lines
Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

an
extended function, while the latter is as long as its devfn > 7, this check

is

Quoted 21 lines
Quoted 20 lines
Quoted 1 line
Quoted 1 line

exactly what the original code did; The original code wasn't aware the

former.

Quoted 9 lines
Quoted 3 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

How about this:

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

If a PF is an extended function, a traditional function's BDF should be used to search VT-d unit. Previous code only checks whether Function Number is greater than 7, without checking the prerequisite that the

Quoted 9 lines
Quoted 5 lines

where did above check come from in original code?

- devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev-
info.physfn.devfn;

Yes. It is the check I described. This line assigns 0 to 'devfn' if PF's function number > 7. Otherwise, use PF's real devfn.

sorry I overlooked PCI_SLOT. However your description is still about the wrong behavior if PF is an extended function. You didn't explain it's also wrong even when PF is not an extended function.

Thanks
Kevin

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#7 lore raw
Quoted 62 lines · Kevin
Quoted 62 lines

From: Gao, Chao
Sent: Wednesday, July 5, 2017 12:28 PM

Quoted 7 lines · Kevin
Quoted 7 lines

From: Gao, Chao
Sent: Monday, July 3, 2017 12:37 PM

Quoted 3 lines · Kevin
Quoted 3 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all other SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be

classified

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line
Quoted 1 line

two kinds: one is RC integrated PF and the other is non-RC integrated

PF.

Quoted 5 lines
Quoted 5 lines

The

Quoted 2 lines
Quoted 2 lines

former can't support ARI and the latter shall support ARI. For Extended Functions, one traditional function's BDF should be used to search VT-d

unit.

Quoted 1 line
Quoted 1 line

And according to PCIe spec, Extened Function means within an ARI

device,

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

Function whose Function Number is greater than 7. Thus, the former

can't

Quoted 3 lines
Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

an
extended function, while the latter is as long as its devfn > 7, this check

is

Quoted 26 lines
Quoted 12 lines
Quoted 1 line
Quoted 1 line

exactly what the original code did; The original code wasn't aware the

former.

Quoted 9 lines
Quoted 3 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

Quoted 8 lines

How about this:

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

If a PF is an extended function, a traditional function's BDF should be used to search VT-d unit. Previous code only checks whether Function Number is greater than 7, without checking the prerequisite that the

where did above check come from in original code?

- devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev-
info.physfn.devfn;

Quoted 8 lines
Quoted 3 lines

Yes. It is the check I described. This line assigns 0 to 'devfn' if PF's function number > 7. Otherwise, use PF's real devfn.

sorry I overlooked PCI_SLOT. However your description is still about the wrong behavior if PF is an extended function. You didn't explain it's also wrong even when PF is not an extended function.

How about changing the second paragraph to:

If a PF is an extended function, the BDF of a traditional function within the same device should be used to search VT-d unit. Otherwise, the real BDF of PF should be used. According PCI-e spec, an extended function is a function within an ARI device and Function Number > 7. But the original code only checks the latter requirement, without checking the former requirement. It incurs that a function whose Function Number > 7 but which isn't within an ARI device (such as RC integrated function with Function Number > 7) is wrongly classified to an extended function and then we wrongly use 0 as 'devfn' to search VT-d unit for this case.

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw
Quoted 84 lines

From: Gao, Chao
Sent: Wednesday, July 5, 2017 3:57 PM

Quoted 8 lines · Kevin
Quoted 8 lines

From: Gao, Chao
Sent: Wednesday, July 5, 2017 12:28 PM

Quoted 4 lines · Kevin
Quoted 4 lines

From: Gao, Chao
Sent: Monday, July 3, 2017 12:37 PM

On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

From: Gao, Chao
Sent: Friday, June 30, 2017 9:17 AM

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

From SRIOV spec REV 1.0 section 3.7.3, it says:
"ARI is not applicable to Root Complex integrated Endpoints; all

other

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

SR-IOV Capable Devices (Devices that include at least one PF) shall implement the ARI Capability in each Function.". So PFs can be

classified

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line
Quoted 1 line

two kinds: one is RC integrated PF and the other is non-RC

integrated

Quoted 3 lines
Quoted 3 lines

PF.

Quoted 2 lines
Quoted 2 lines

The

Quoted 1 line
Quoted 1 line

former can't support ARI and the latter shall support ARI. For

Extended

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Functions, one traditional function's BDF should be used to search

VT-d

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

unit.

Quoted 1 line
Quoted 1 line

And according to PCIe spec, Extened Function means within an ARI

device,

Quoted 2 lines
Quoted 2 lines

a

Quoted 1 line
Quoted 1 line

Function whose Function Number is greater than 7. Thus, the

former

Quoted 4 lines
Quoted 4 lines

can't

Quoted 3 lines
Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

an
extended function, while the latter is as long as its devfn > 7, this

check

Quoted 2 lines
Quoted 2 lines

is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

exactly what the original code did; The original code wasn't aware

the

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 11 lines

former.

Quoted 9 lines
Quoted 3 lines

This patch directly looks up the 'is_extfn' field of PF's struct pci_dev to decide whether the PF is a extended function.

Above description looks like the bug is caused by ARI problem. But if you look at the original code (and the problem you described), it's not related to ARI. ARI comes just when adding a clean fix, so please revise the description to make that part clear

Quoted 8 lines

How about this:

The problem is for a VF of RC integrated PF (e.g. PF's BDF is 00:02.0), we would wrongly use 00:00.0 to search VT-d unit.

If a PF is an extended function, a traditional function's BDF should be used to search VT-d unit. Previous code only checks whether Function Number is greater than 7, without checking the prerequisite that the

where did above check come from in original code?

- devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev-
info.physfn.devfn;

Quoted 8 lines
Quoted 3 lines

Yes. It is the check I described. This line assigns 0 to 'devfn' if PF's function number > 7. Otherwise, use PF's real devfn.

sorry I overlooked PCI_SLOT. However your description is still about the wrong behavior if PF is an extended function. You didn't explain it's also wrong even when PF is not an extended function.

How about changing the second paragraph to:

Quoted 11 lines

If a PF is an extended function, the BDF of a traditional function within the same device should be used to search VT-d unit. Otherwise, the real BDF of PF should be used. According PCI-e spec, an extended function is a function within an ARI device and Function Number > 7. But the original code only checks the latter requirement, without checking the former requirement. It incurs that a function whose Function Number > 7 but which isn't within an ARI device (such as RC integrated function with Function Number > 7) is wrongly classified to an extended function and then we wrongly use 0 as 'devfn' to search VT-d unit for this case.

good to me.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw
In reply to Chao Gao
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 05.07.17 at 09:56, <[email protected]> wrote:

How about changing the second paragraph to:

If a PF is an extended function, the BDF of a traditional function within the same device should be used to search VT-d unit. Otherwise, the real BDF of PF should be used. According PCI-e spec, an extended function is a function within an ARI device and Function Number > 7. But the original code only checks the latter requirement, without checking the former requirement. It incurs that a function whose Function Number > 7 but which isn't within an ARI device (such as RC integrated function with Function Number > 7) is wrongly classified to an extended function and then we wrongly use 0 as 'devfn' to search VT-d unit for this case.

There's one part here which I continue to not understand: The function number being just 3 bits, how can it possibly be larger than 7?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 05.07.17 at 09:56, <[email protected]> wrote:

How about changing the second paragraph to:

If a PF is an extended function, the BDF of a traditional function within the same device should be used to search VT-d unit. Otherwise, the real BDF of PF should be used. According PCI-e spec, an extended function is a function within an ARI device and Function Number > 7. But the original code only checks the latter requirement, without checking the former requirement. It incurs that a function whose Function Number > 7 but which isn't within an ARI device (such as RC integrated function with Function Number > 7) is wrongly classified to an extended function and then we wrongly use 0 as 'devfn' to search VT-d unit for this case.

Quoted 3 lines

There's one part here which I continue to not understand: The function number being just 3 bits, how can it possibly be larger than 7?

It's a special case on the PCIe spec, quoting it:

"Note: for Requests targeting Extended Functions in an ARI Device, A[19:12] represents the (8-bit) Function Number, which replaces the (5-bit) Device Number and (3-bit) Function Number fields above."

It's in the PCIe 3.1a spec, page 657. The function number is expanded from 7 to 255.

What I fail to see is how this device is registered with Xen, is the devfn field used to store the function number only?

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#11 lore raw
Quoted 25 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 05.07.17 at 09:56, <[email protected]> wrote:

How about changing the second paragraph to:

If a PF is an extended function, the BDF of a traditional function within the same device should be used to search VT-d unit. Otherwise, the real BDF of PF should be used. According PCI-e spec, an extended function is a function within an ARI device and Function Number > 7. But the original code only checks the latter requirement, without checking the former requirement. It incurs that a function whose Function Number > 7 but which isn't within an ARI device (such as RC integrated function with Function Number > 7) is wrongly classified to an extended function and then we wrongly use 0 as 'devfn' to search VT-d unit for this case.

Quoted 3 lines

There's one part here which I continue to not understand: The function number being just 3 bits, how can it possibly be larger than 7?

It's a special case on the PCIe spec, quoting it:

"Note: for Requests targeting Extended Functions in an ARI Device, A[19:12] represents the (8-bit) Function Number, which replaces the (5-bit) Device Number and (3-bit) Function Number fields above."

Quoted 5 lines

It's in the PCIe 3.1a spec, page 657. The function number is expanded from 7 to 255.

What I fail to see is how this device is registered with Xen, is the devfn field used to store the function number only?

The devfn is passed down by dom0. Judging from how is_extfn is set in xen_add_device() in linux kernel, I think linux kernel reuses the Device Fields as the higher 5 bits of an extended function's Function Number.

Thanks
Chao

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel