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

[PATCH v2 2/2] VT-d: avoid infinite recursion on domain_context_mapping_one() error path


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 7 Apr 2022 08:11:45 +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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E6G0lhWDzKngo22Cqa5yFBt1cU5VEIbGGSfIbs2WoXA=; b=TxIaEUflRhoixXGlv21DitWLc2WgrCcWSPRRQin23/TerJGzTXknrBavIx76RI2olPDaCWebJU+IxA0JBG+0XECamcW+2iDAoU9JtuD0SCQYr7VMDnf6LmZmawi3C99MRxubEgvhv6YzKw5vDrBBOSaHBZtnR7fJRqXC94sLsUnBD438GE75ArC+UHComH1iYt8lVhZJbxHtpwUkIC062vn11Ydc+S77Jo33Ro3Pg7RC2W5KeehK6x4K1d79v5Dh+gtj9Ck2QErBwHvDNYzaM/kBU3lha8td3C1gNQIEooJO7B8k6jOk8VpkBlaSlva+bsyllK4BTmdcaiTg7CW93Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dq3lw7XZacNFhs1Cz0SGnmrmzWQ1dLsL9kg599Nag5GAylMP/gf7osFv9/3nxTxCdjTbComiXVF5oFx/mz54do3wnjn9XdZqsAMqyrHOVZyZKy0wumB2t06W6d7+Jjax3v0GLoGTsmkewYv5gwx6Yc2RYek+2yl7dahBx1ws5GyObTkri5hhtmwywrw/M8mIyzIjY5YK9PNyaEN7dvfQ3qgvA1OaQUAxVx1GXDvVQLuyTQAFlQq6cXfFpO/+taskf/voIIxv91AcE4LY1KQvC4EGFN12hItffyDmBISj32aBigBpuhe0KQA3LTlUSL1XFtOjsAUl0m5aiBWAiH154A==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Thu, 07 Apr 2022 06:12:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Despite the comment there infinite recursion was still possible, by
flip-flopping between two domains. This is because prev_dom is derived
from the DID found in the context entry, which was already updated by
the time error recovery is invoked. Simply introduce yet another mode
flag to prevent rolling back an in-progress roll-back of a prior
mapping attempt.

Also drop the existing recursion prevention for having been dead anyway:
Earlier in the function we already bail when prev_dom == domain.

Fixes: 8f41e481b485 ("VT-d: re-assign devices directly")
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: Extend scope of the approach taken. Leverage for some cleanup.

--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1599,7 +1599,7 @@ int domain_context_mapping_one(
     if ( !seg && !rc )
         rc = me_wifi_quirk(domain, bus, devfn, domid, pgd_maddr, mode);
 
-    if ( rc )
+    if ( rc && !(mode & MAP_ERROR_RECOVERY) )
     {
         if ( !prev_dom ||
              /*
@@ -1609,13 +1609,12 @@ int domain_context_mapping_one(
               */
              (prev_dom == dom_io && !pdev) )
             ret = domain_context_unmap_one(domain, iommu, bus, devfn);
-        else if ( prev_dom != domain ) /* Avoid infinite recursion. */
+        else
             ret = domain_context_mapping_one(prev_dom, iommu, bus, devfn, pdev,
                                              DEVICE_DOMID(prev_dom, pdev),
                                              DEVICE_PGTABLE(prev_dom, pdev),
-                                             mode & MAP_WITH_RMRR) < 0;
-        else
-            ret = 1;
+                                             (mode & MAP_WITH_RMRR) |
+                                             MAP_ERROR_RECOVERY) < 0;
 
         if ( !ret && pdev && pdev->devfn == devfn )
             check_cleanup_domid_map(domain, pdev, iommu);
--- a/xen/drivers/passthrough/vtd/vtd.h
+++ b/xen/drivers/passthrough/vtd/vtd.h
@@ -29,7 +29,8 @@
 #define MAP_WITH_RMRR         (1u << 0)
 #define MAP_OWNER_DYING       (1u << 1)
 #define MAP_SINGLE_DEVICE     (1u << 2)
-#define UNMAP_ME_PHANTOM_FUNC (1u << 3)
+#define MAP_ERROR_RECOVERY    (1u << 3)
+#define UNMAP_ME_PHANTOM_FUNC (1u << 4)
 
 /* Allow for both IOAPIC and IOSAPIC. */
 #define IO_xAPIC_route_entry IO_APIC_route_entry




 


Rackspace

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