* [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
@ 2017-06-30 1:17 Chao Gao
2017-06-30 9:19 ` Tian, Kevin
0 siblings, 1 reply; 12+ messages in thread
From: Chao Gao @ 2017-06-30 1:17 UTC (permalink / raw)
To: xen-devel
Cc: Kevin Tian, Venu Busireddy, Jan Beulich, Roger Pau Monné,
Crawford Eric R, Chao Gao
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.
Reported-by: Crawford, Eric R <Eric.R.Crawford@intel.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
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(-)
diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c
index 82040dd..27ff471 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -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
{
--
1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-06-30 1:17 [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit Chao Gao
@ 2017-06-30 9:19 ` Tian, Kevin
2017-06-30 10:40 ` Jan Beulich
2017-07-03 4:36 ` Chao Gao
0 siblings, 2 replies; 12+ messages in thread
From: Tian, Kevin @ 2017-06-30 9:19 UTC (permalink / raw)
To: Gao, Chao, xen-devel@lists.xen.org
Cc: Venu Busireddy, Crawford, Eric R, Jan Beulich,
Roger Pau Monné
> 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.
>
> 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
>
> Reported-by: Crawford, Eric R <Eric.R.Crawford@intel.com>
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> ---
> v3:
> - access pf's struct pci_pdev between pcidevs_lock() and pcidevs_unlock()
should be v4.
> ---
> xen/drivers/passthrough/vtd/dmar.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/xen/drivers/passthrough/vtd/dmar.c
> b/xen/drivers/passthrough/vtd/dmar.c
> index 82040dd..27ff471 100644
> --- a/xen/drivers/passthrough/vtd/dmar.c
> +++ b/xen/drivers/passthrough/vtd/dmar.c
> @@ -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;
is it legal to have physfn as NULL when is_virtfn is true?
> + pcidevs_unlock();
> }
> else
> {
> --
> 1.8.3.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-06-30 9:19 ` Tian, Kevin
@ 2017-06-30 10:40 ` Jan Beulich
2017-07-03 4:36 ` Chao Gao
1 sibling, 0 replies; 12+ messages in thread
From: Jan Beulich @ 2017-06-30 10:40 UTC (permalink / raw)
To: kevin.tian
Cc: venu.busireddy, chao.gao, xen-devel, eric.r.crawford, roger.pau
>>> "Tian, Kevin" <kevin.tian@intel.com> 06/30/17 11:20 AM >>>
>> From: Gao, Chao
>> Sent: Friday, June 30, 2017 9:17 AM
>> --- a/xen/drivers/passthrough/vtd/dmar.c
>> +++ b/xen/drivers/passthrough/vtd/dmar.c
>> @@ -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;
>
>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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-06-30 9:19 ` Tian, Kevin
2017-06-30 10:40 ` Jan Beulich
@ 2017-07-03 4:36 ` Chao Gao
2017-07-05 2:46 ` Tian, Kevin
1 sibling, 1 reply; 12+ messages in thread
From: Chao Gao @ 2017-07-03 4:36 UTC (permalink / raw)
To: Tian, Kevin
Cc: Crawford, Eric R, Venu Busireddy, Roger Pau Monné,
Jan Beulich, xen-devel@lists.xen.org
On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:
>> 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.
>>
>> 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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-03 4:36 ` Chao Gao
@ 2017-07-05 2:46 ` Tian, Kevin
2017-07-05 4:28 ` Chao Gao
0 siblings, 1 reply; 12+ messages in thread
From: Tian, Kevin @ 2017-07-05 2:46 UTC (permalink / raw)
To: Gao, Chao
Cc: Crawford, Eric R, Venu Busireddy, Roger Pau Monné,
Jan Beulich, xen-devel@lists.xen.org
> From: Gao, Chao
> Sent: Monday, July 3, 2017 12:37 PM
>
> On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:
> >> 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.
> >>
> >> 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
where did above check come from in original code?
- devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn;
> 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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 2:46 ` Tian, Kevin
@ 2017-07-05 4:28 ` Chao Gao
2017-07-05 5:18 ` Tian, Kevin
0 siblings, 1 reply; 12+ messages in thread
From: Chao Gao @ 2017-07-05 4:28 UTC (permalink / raw)
To: Tian, Kevin
Cc: Crawford, Eric R, Venu Busireddy, Roger Pau Monné,
Jan Beulich, xen-devel@lists.xen.org
On Wed, Jul 05, 2017 at 10:46:39AM +0800, Tian, Kevin wrote:
>> From: Gao, Chao
>> Sent: Monday, July 3, 2017 12:37 PM
>>
>> On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:
>> >> 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.
>> >>
>> >> 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
>
>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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 4:28 ` Chao Gao
@ 2017-07-05 5:18 ` Tian, Kevin
2017-07-05 7:56 ` Chao Gao
0 siblings, 1 reply; 12+ messages in thread
From: Tian, Kevin @ 2017-07-05 5:18 UTC (permalink / raw)
To: Gao, Chao
Cc: Crawford, Eric R, Venu Busireddy, Roger Pau Monné,
Jan Beulich, xen-devel@lists.xen.org
> From: Gao, Chao
> Sent: Wednesday, July 5, 2017 12:28 PM
>
> On Wed, Jul 05, 2017 at 10:46:39AM +0800, Tian, Kevin wrote:
> >> From: Gao, Chao
> >> Sent: Monday, July 3, 2017 12:37 PM
> >>
> >> On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:
> >> >> 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.
> >> >>
> >> >> 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
> >
> >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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 5:18 ` Tian, Kevin
@ 2017-07-05 7:56 ` Chao Gao
2017-07-05 8:06 ` Tian, Kevin
2017-07-05 8:19 ` Jan Beulich
0 siblings, 2 replies; 12+ messages in thread
From: Chao Gao @ 2017-07-05 7:56 UTC (permalink / raw)
To: Tian, Kevin
Cc: Crawford, Eric R, Venu Busireddy, Roger Pau Monné,
Jan Beulich, xen-devel@lists.xen.org
On Wed, Jul 05, 2017 at 01:18:38PM +0800, Tian, Kevin wrote:
>> From: Gao, Chao
>> Sent: Wednesday, July 5, 2017 12:28 PM
>>
>> On Wed, Jul 05, 2017 at 10:46:39AM +0800, Tian, Kevin wrote:
>> >> From: Gao, Chao
>> >> Sent: Monday, July 3, 2017 12:37 PM
>> >>
>> >> On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:
>> >> >> 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.
>> >> >>
>> >> >> 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
>> >
>> >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.
>
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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 7:56 ` Chao Gao
@ 2017-07-05 8:06 ` Tian, Kevin
2017-07-05 8:19 ` Jan Beulich
1 sibling, 0 replies; 12+ messages in thread
From: Tian, Kevin @ 2017-07-05 8:06 UTC (permalink / raw)
To: Gao, Chao
Cc: Crawford, Eric R, Venu Busireddy, Roger Pau Monné,
Jan Beulich, xen-devel@lists.xen.org
> From: Gao, Chao
> Sent: Wednesday, July 5, 2017 3:57 PM
>
> On Wed, Jul 05, 2017 at 01:18:38PM +0800, Tian, Kevin wrote:
> >> From: Gao, Chao
> >> Sent: Wednesday, July 5, 2017 12:28 PM
> >>
> >> On Wed, Jul 05, 2017 at 10:46:39AM +0800, Tian, Kevin wrote:
> >> >> From: Gao, Chao
> >> >> Sent: Monday, July 3, 2017 12:37 PM
> >> >>
> >> >> On Fri, Jun 30, 2017 at 05:19:52PM +0800, Tian, Kevin wrote:
> >> >> >> 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.
> >> >> >>
> >> >> >> 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
> >> >
> >> >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.
> >
>
> 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.
>
good to me.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 7:56 ` Chao Gao
2017-07-05 8:06 ` Tian, Kevin
@ 2017-07-05 8:19 ` Jan Beulich
2017-07-05 8:29 ` Roger Pau Monné
1 sibling, 1 reply; 12+ messages in thread
From: Jan Beulich @ 2017-07-05 8:19 UTC (permalink / raw)
To: Chao Gao
Cc: Kevin Tian, xen-devel@lists.xen.org, Eric R Crawford,
Venu Busireddy, Roger Pau Monné
>>> On 05.07.17 at 09:56, <chao.gao@intel.com> 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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 8:19 ` Jan Beulich
@ 2017-07-05 8:29 ` Roger Pau Monné
2017-07-05 8:45 ` Chao Gao
0 siblings, 1 reply; 12+ messages in thread
From: Roger Pau Monné @ 2017-07-05 8:29 UTC (permalink / raw)
To: Jan Beulich
Cc: Kevin Tian, xen-devel@lists.xen.org, Eric R Crawford,
Venu Busireddy, Chao Gao
On Wed, Jul 05, 2017 at 02:19:17AM -0600, Jan Beulich wrote:
> >>> On 05.07.17 at 09:56, <chao.gao@intel.com> 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?
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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit
2017-07-05 8:29 ` Roger Pau Monné
@ 2017-07-05 8:45 ` Chao Gao
0 siblings, 0 replies; 12+ messages in thread
From: Chao Gao @ 2017-07-05 8:45 UTC (permalink / raw)
To: Roger Pau Monné, Jan Beulich
Cc: Kevin Tian, Venu Busireddy, Eric R Crawford,
xen-devel@lists.xen.org
On Wed, Jul 05, 2017 at 09:29:29AM +0100, Roger Pau Monné wrote:
>On Wed, Jul 05, 2017 at 02:19:17AM -0600, Jan Beulich wrote:
>> >>> On 05.07.17 at 09:56, <chao.gao@intel.com> 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?
>
>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?
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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2017-07-05 8:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-30 1:17 [PATCH v4] VT-d: fix VF of RC integrated PF matched to wrong VT-d unit Chao Gao
2017-06-30 9:19 ` Tian, Kevin
2017-06-30 10:40 ` Jan Beulich
2017-07-03 4:36 ` Chao Gao
2017-07-05 2:46 ` Tian, Kevin
2017-07-05 4:28 ` Chao Gao
2017-07-05 5:18 ` Tian, Kevin
2017-07-05 7:56 ` Chao Gao
2017-07-05 8:06 ` Tian, Kevin
2017-07-05 8:19 ` Jan Beulich
2017-07-05 8:29 ` Roger Pau Monné
2017-07-05 8:45 ` Chao Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).