[xen stable-4.7] VT-d: use correct BDF for VF to search VT-d unit

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen stable-4.7] VT-d: use correct BDF for VF to search VT-d unit

patchbot
commit 145c18d81058ba4dcfbc5fbd854b8143c1681925
Author:     Chao Gao <[hidden email]>
AuthorDate: Fri Oct 6 15:14:47 2017 +0200
Commit:     Jan Beulich <[hidden email]>
CommitDate: Fri Oct 6 15:14:47 2017 +0200

    VT-d: use correct BDF for VF to search VT-d unit
   
    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 for a VF, if its PF
    isn't an extended function, the BDF of PF should be used. Otherwise
    the BDF of a traditional function in the same device with the PF
    should be used.
   
    Current code uses PCI_SLOT() to recognize an ARI 'Extended Funcion'.
    But it is conceptually wrong w/o checking whether PF is an extended
    function and would lead to match VFs of a RC integrated PF to a wrong
    VT-d unit.
   
    This patch overrides VF 'is_extfn' field and uses this field 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 <[hidden email]>
    Signed-off-by: Chao Gao <[hidden email]>
    Reviewed-by: Kevin Tian <[hidden email]>
    Acked-by: Jan Beulich <[hidden email]>
    Tested-by: Crawford, Eric R <[hidden email]>
    master commit: c286af54c7177c14180121b422d8df7281e547cb
    master date: 2017-09-01 11:02:23 +0200
---
 xen/drivers/passthrough/pci.c      | 19 +++++++++++++++----
 xen/drivers/passthrough/vtd/dmar.c | 12 ++++++------
 xen/include/xen/pci.h              |  4 ++++
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c
index 98936f55c..f2bd64e 100644
--- a/xen/drivers/passthrough/pci.c
+++ b/xen/drivers/passthrough/pci.c
@@ -594,21 +594,24 @@ 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_t pf_is_extfn = 0;
 
-    if (!info)
+    if ( !info )
         pdev_type = "device";
-    else if (info->is_extfn)
-        pdev_type = "extended function";
-    else if (info->is_virtfn)
+    else if ( info->is_virtfn )
     {
         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,
                            NULL, node);
         pdev_type = "virtual function";
     }
+    else if ( info->is_extfn )
+        pdev_type = "extended function";
     else
     {
         info = NULL;
@@ -632,7 +635,15 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn,
     pdev->node = node;
 
     if ( info )
+    {
         pdev->info = *info;
+        /*
+         * VF's 'is_extfn' field is used to indicate whether its PF is an
+         * extended function.
+         */
+        if ( pdev->info.is_virtfn )
+            pdev->info.is_extfn = pf_is_extfn;
+    }
     else if ( !pdev->vf_rlen[0] )
     {
         unsigned int pos = pci_find_ext_capability(seg, bus, devfn,
diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c
index 08c1d2d..1ff7bd3 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -211,15 +211,15 @@ struct acpi_drhd_unit *acpi_find_matched_drhd_unit(const struct pci_dev *pdev)
     if ( pdev == NULL )
         return NULL;
 
-    if ( pdev->info.is_extfn )
+    if ( pdev->info.is_virtfn )
     {
-        bus = pdev->bus;
-        devfn = 0;
+        bus = pdev->info.physfn.bus;
+        devfn = !pdev->info.is_extfn ? pdev->info.physfn.devfn : 0;
     }
-    else if ( pdev->info.is_virtfn )
+    else if ( pdev->info.is_extfn )
     {
-        bus = pdev->info.physfn.bus;
-        devfn = PCI_SLOT(pdev->info.physfn.devfn) ? 0 : pdev->info.physfn.devfn;
+        bus = pdev->bus;
+        devfn = 0;
     }
     else
     {
diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h
index 6ed29dd..7ddf7f2 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 {
+    /*
+     * VF's 'is_extfn' field is used to indicate whether its PF is an extended
+     * function.
+     */
     bool_t is_extfn;
     bool_t is_virtfn;
     struct {
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.7

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog