[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/3] VT-d: consider hidden devices when unmapping


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 17 Sep 2021 13:00:00 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=UppQocqB70WkQjVr0azZfPR+2KVYqhGJJEBclpY3yOc=; b=hH/snVUFNV+ZU+56I7eTrijwfQ7Sp0wOsdkrBWl8OUeFyDsU9gX80Sp2Lcvc/UpKiql2m6E0Iiy5+XW0W390CNC8tbSr2uedAMPmeSKrZZi7VymbG/gV3SJk542WAt0ggtwwbDum/lBw/STqGJwUmQdzpZnqAasdbQmGZ/+GjgYpO/bJyAy44yU65dUlJgmZN/+BVrYzGoIYAbxx8aWQerrHbh/UQwO/zSlJV3d24AQCaqneNcZWPZYav78c+XUFGUgssEovnywk5iGd0Gu5/4gBgi2ZMY9uEnMrZz0Ya3b6dmykyJx9WGanzTuglY6XtJH2qBiL7aF5RXsVqehANQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=esBbik5m8aj4/bF7Qq79cwRcycdRp8/IY9JuTaL+h2HZk3EcfOnDm/L3lM+htqnPrx+fBLBEjGj6eY/xNiIz1+Gby59NZWnW4XCfjS/2Fx79FSjnksru0xGcqUrHTby6IgiMiYN3NOu3ou/dPkuBoDePTqQFdKPI8SqazBj82M55UgJ3oUcjqTZJnfK5Gn6RnMO4eK3yCkQ1Cm3UEZtRaanR5lZcDUoch2bMdzyA9Qr6VMBwAN10Cgezs70+pe4UgzsXsuAoOTPL3S+DYay7dU1YIjdhJq1ud2dEliqUaDFYsh6m9cX74/z7TAojaPgLxiCR4cckkQIMGPOS8+HvVw==
  • Authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=suse.com;
  • Cc: Paul Durrant <paul@xxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>
  • Delivery-date: Fri, 17 Sep 2021 11:00:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Whether to clear an IOMMU's bit in the domain's bitmap should depend on
all devices the domain can control. For the hardware domain this
includes hidden devices, which are associated with DomXEN.

While touching related logic
- convert the "current device" exclusion check to a simple pointer
  comparison,
- convert "found" to "bool",
- adjust style and correct a typo in an existing comment.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: Introduce helper function.

--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1650,6 +1650,27 @@ int domain_context_unmap_one(
     return rc;
 }
 
+static bool any_pdev_behind_iommu(const struct domain *d,
+                                  const struct pci_dev *exclude,
+                                  const struct vtd_iommu *iommu)
+{
+    const struct pci_dev *pdev;
+
+    for_each_pdev ( d, pdev )
+    {
+        const struct acpi_drhd_unit *drhd;
+
+        if ( pdev == exclude )
+            continue;
+
+        drhd = acpi_find_matched_drhd_unit(pdev);
+        if ( drhd && drhd->iommu == iommu )
+            return true;
+    }
+
+    return false;
+}
+
 static int domain_context_unmap(struct domain *domain, u8 devfn,
                                 struct pci_dev *pdev)
 {
@@ -1657,7 +1678,7 @@ static int domain_context_unmap(struct d
     struct vtd_iommu *iommu = drhd ? drhd->iommu : NULL;
     int ret;
     u8 seg = pdev->seg, bus = pdev->bus, tmp_bus, tmp_devfn, secbus;
-    int found = 0;
+    bool found;
 
     switch ( pdev->type )
     {
@@ -1737,23 +1758,18 @@ static int domain_context_unmap(struct d
         return ret;
 
     /*
-     * if no other devices under the same iommu owned by this domain,
-     * clear iommu in iommu_bitmap and clear domain_id in domid_bitmp
+     * If no other devices under the same iommu owned by this domain,
+     * clear iommu in iommu_bitmap and clear domain_id in domid_bitmap.
      */
-    for_each_pdev ( domain, pdev )
-    {
-        if ( pdev->seg == seg && pdev->bus == bus && pdev->devfn == devfn )
-            continue;
-
-        drhd = acpi_find_matched_drhd_unit(pdev);
-        if ( drhd && drhd->iommu == iommu )
-        {
-            found = 1;
-            break;
-        }
-    }
+    found = any_pdev_behind_iommu(domain, pdev, iommu);
+    /*
+     * Hidden devices are associated with DomXEN but usable by the hardware
+     * domain. Hence they need considering here as well.
+     */
+    if ( !found && is_hardware_domain(domain) )
+        found = any_pdev_behind_iommu(dom_xen, pdev, iommu);
 
-    if ( found == 0 )
+    if ( !found )
     {
         clear_bit(iommu->index, &dom_iommu(domain)->arch.vtd.iommu_bitmap);
         cleanup_domid_map(domain, iommu);




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.