xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7] VT-d: use correct BDF for VF to search VT-d unit
@ 2017-08-21 21:52 Chao Gao
  2017-08-22  7:29 ` Roger Pau Monné
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Chao Gao @ 2017-08-21 21:52 UTC (permalink / raw)
  To: xen-devel
  Cc: Kevin Tian, Stefano Stabellini, Wei Liu, George Dunlap,
	Ian Jackson, Tim Deegan, Jan Beulich, Andrew Cooper, Chao Gao,
	Crawford Eric R, Roger Pau Monné

When SR-IOV is enabled, 'Virtual Functions' of a 'Physical Function' are under
the scope of the same VT-d unit as the 'Physical Function'. A 'Physical
Function' can be a 'Traditional Function' or an ARI 'Extended Function'.
And furthermore, 'Extended Functions' on an endpoint are under the scope of
the same VT-d unit as the 'Traditional Functions' on the endpoint. To search
VT-d unit, the BDF of PF or the BDF of a traditional function may be used. And
it depends on whether the PF is an extended function or not.

Current code uses PCI_SLOT() to recognize an ARI 'Extended Funcion'. But it
is problematic for a corner case (a RC endpoint with SRIOV capability
and has its own VT-d unit), leading to matching to a wrong VT-d unit.

This patch reuses 'is_extfn' field in VF's struct pci_dev_info to indicate
whether the PF of this VF is an extended function. The field helps to use
correct BDF to search VT-d unit.

Reported-by: Crawford, Eric R <Eric.R.Crawford@intel.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
---
v7:
 - Drop Eric's tested-by
 - Change commit message to be clearer
 - Re-use VF's is_extfn field
 - access PF's is_extfn field in locked area
---
 xen/drivers/passthrough/pci.c      | 6 ++++++
 xen/drivers/passthrough/vtd/dmar.c | 2 +-
 xen/include/xen/pci.h              | 4 ++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 27bdb71..2a91320 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -599,6 +599,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
     unsigned int slot = PCI_SLOT(devfn), func = PCI_FUNC(devfn);
     const char *pdev_type;
     int ret;
+    bool pf_is_extfn = false;
 
     if (!info)
         pdev_type = "device";
@@ -608,6 +609,8 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
     {
         pcidevs_lock();
         pdev = pci_get_pdev(seg, info->physfn.bus, info->physfn.devfn);
+        if ( pdev )
+            pf_is_extfn = pdev->info.is_extfn;
         pcidevs_unlock();
         if ( !pdev )
             pci_add_device(seg, info->physfn.bus, info->physfn.devfn,
@@ -707,6 +710,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
                    seg, bus, slot, func, ctrl);
     }
 
+    /* VF's 'is_extfn' is used to indicate whether PF is an extended function */
+    if ( pdev->info.is_virtfn )
+        pdev->info.is_extfn = pf_is_extfn;
     check_pdev(pdev);
 
     ret = 0;
diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c
index 82040dd..83ce5d4 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -219,7 +219,7 @@ struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
     else if ( pdev->info.is_virtfn )
     {
         bus = pdev->info.physfn.bus;
-        devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn;
+        devfn = pdev->info.is_extfn ? 0 : pdev->info.physfn.devfn;
     }
     else
     {
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index 59b6e8a..3b0da66 100644
--- a/xen/include/xen/pci.h
+++ b/xen/include/xen/pci.h
@@ -39,6 +39,10 @@
 #define PCI_SBDF3(s,b,df) ((((s) & 0xffff) << 16) | PCI_BDF2(b, df))
 
 struct pci_dev_info {
+    /*
+     * When 'is_virtfn' is set, 'is_extfn' is re-used to indicate whether
+     * the PF of this VF is an extended function.
+     */
     bool_t is_extfn;
     bool_t is_virtfn;
     struct {
-- 
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] 21+ messages in thread

end of thread, other threads:[~2017-08-24  9:36 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-21 21:52 [PATCH v7] VT-d: use correct BDF for VF to search VT-d unit Chao Gao
2017-08-22  7:29 ` Roger Pau Monné
2017-08-22  8:48   ` Chao Gao
2017-08-22 12:43 ` Jan Beulich
2017-08-23  1:05   ` Chao Gao
2017-08-23  7:16     ` Roger Pau Monné
2017-08-23  7:20       ` Jan Beulich
2017-08-23  7:31         ` Roger Pau Monné
2017-08-23  6:46           ` Chao Gao
2017-08-23  8:01             ` Roger Pau Monné
2017-08-23  7:42               ` Chao Gao
2017-08-23  8:52                 ` Jan Beulich
2017-08-24  7:29                   ` Tian, Kevin
2017-08-23  8:00           ` Jan Beulich
2017-08-23  8:04     ` Jan Beulich
2017-08-23  7:39       ` Chao Gao
2017-08-23  8:51         ` Jan Beulich
2017-08-24  7:22 ` Tian, Kevin
     [not found] ` <AADFC41AFE54684AB9EE6CBC0274A5D190D80DD6@SHSMSX101.ccr.corp.intel.com>
2017-08-24  8:01   ` Tian, Kevin
2017-08-24  8:22     ` Jan Beulich
2017-08-24  9:36       ` 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).