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

[PATCH v3] iommu/vtd: fix address translation for leaf entries


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Thu, 25 May 2023 10:08:59 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=UlsVx+vz8iEzY3emfUcaCeeXNrSn049ryPKxtlFAKgc=; b=KTBl9X0gkK0kCVwA0xPwS7ct/fPtYb4OYH5aDDLi9oIKjB/kP0poaHr70DdpqDgN94OV6AAw5JO72cAFq3+g97ArdN+wG5qWNKXGpe4jb1l0Ez1DJJunkne+Hc58e8W+7E4lfCqv5pkCYYM0jCGFV4Lav1D+tM4TNcrwyEMLImuSR/Vj+afImHC5k4lXw40MC6pebFJNKxSkd3MvCqELBhHMatm78BLHTWihkBW89XFPMA4AQHEScMgOsEVPNOC44ep7fClB7ITMjAB40IO+SVL4pjlgHYbdVD1hrPplJSwiA27pUzxfCR0o0C4f6qwbXRUnem865tHcr/Exx4dLoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJzcoiShheu/WNMPNk5+UC11C2roSw8TKxPtoVc3D3oHCVwGq2G8ny8S+Ms1WYbovdARYI5yqFAjNv/+SvYeEtyYFzSBUKoBbFEVoRxS8NhEL5siwHlbtFOH7ntUeKj+sB7BOwURHvSOu+IdKLhIpxk078gs+sGQG6rItaC/+1fA4wjCVCzh+RNLuLZeFqbUmxD7AsqWEZ+aQUfDaPFVKlcefBP9cYYqbPtD366yi1eiPcJB8ORUj+gMoeVblSz0R7fbBRJSE35vho+yZBHzu5rsinGGzXD7l4JYQgIpgR0lCo9XfwJnkL+3Jz4kKopKdYHcd7+3bX7acfMcolAYzg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>
  • Delivery-date: Thu, 25 May 2023 08:09:30 +0000
  • Ironport-data: A9a23:/0kp7qvwkbAprvWY5U6zBVNYCufnVElfMUV32f8akzHdYApBsoF/q tZmKW2HOP+JajT1KI8lPozi8kJT75bUn9NrTAs/rS41Fiwb+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg3HVQ+IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4rKq4Fv0gnRkPaoQ5AKEyyFJZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwI2oSSzKaqeGPwqO4acxp2u0TI9L0I9ZK0p1g5Wmx4fcOZ7nmGv2Pz/kHmTA6i4ZJAOrUY NcfZXx3dhPcbhZTO1ARTpUjgOOvgXq5eDpdwL6XjfNvvy6Pk0ouiP60aIC9lt+iHK25mm6Co W3L5SLhCwwyP92D0zuVtHmrg4cjmAuiANNKReLkqqACbFu7/2ADAk0EbxiAh8KomE7hR/Rzc lIYw397xUQ13AnxJjXnZDWorXjBshMCVt54F+wh9BrL2qfS+xyeBGUPUnhGctNOnMw7Wz0sk EOIltXBBDpzvbnTQnWYnop4thu3MCkRaGUEOikNSFJd58G5+dlpyBXSUtxkDai5yMXvHi39y CyLqy54gKgPickM1OOw+lWvby+Qm6UlhzUdvm3/Nl9JJCsgDGJ5T+REMWTm0Ms=
  • Ironport-hdrordr: A9a23:YfAyXqA+x7DeX/TlHemp55DYdb4zR+YMi2TDtnoBLyC9Hfbo8/ xG8M566faMslcssRIb6Le90cu7K080nKQdieIs1NGZLWrbUQCTXeRfBOXZsl/d8hrFm9K1BJ 0PT0AuYOeeMbAl5fyX3DWF
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Fix two issues related to leaf address lookups in VT-d:

* When translating an address that falls inside of a superpage in the
  IOMMU page tables the fetching of the PTE value wasn't masking of the
  contiguous related data, which caused the returned data to be
  corrupt as it would contain bits that the caller would interpret as
  part of the address.

* When the requested leaf address wasn't mapped by a superpage the
  returned value wouldn't have any of the low 12 bits set, thus missing
  the permission bits expected by the caller.

Take the opportunity to also adjust the function comment to note that
when returning the full PTE the bits above PADDR_BITS are removed.

Fixes: c71e55501a61 ('VT-d: have callers specify the target level for page 
table walks')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v2:
 - Use PADDR_MASK.
 - Also fix the non-superpage case.

Changes since v1:
 - Return all the PTE bits except for the contiguous count ones.
---
 xen/drivers/passthrough/vtd/iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/xen/drivers/passthrough/vtd/iommu.c 
b/xen/drivers/passthrough/vtd/iommu.c
index 130a159cde07..0e3062c820f9 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -310,7 +310,7 @@ static u64 bus_to_context_maddr(struct vtd_iommu *iommu, u8 
bus)
  *   failure,
  * - for target > 0 the physical address of the page table holding the leaf
  *   PTE for the requested address,
- * - for target == 0 the full PTE.
+ * - for target == 0 the full PTE contents below PADDR_BITS limit.
  */
 static uint64_t addr_to_dma_page_maddr(struct domain *domain, daddr_t addr,
                                        unsigned int target,
@@ -368,7 +368,7 @@ static uint64_t addr_to_dma_page_maddr(struct domain 
*domain, daddr_t addr,
                  * with the address adjusted to account for the residual of
                  * the walk.
                  */
-                pte_maddr = pte->val +
+                pte_maddr = (pte->val & PADDR_MASK) +
                     (addr & ((1UL << level_to_offset_bits(level)) - 1) &
                      PAGE_MASK);
                 if ( !target )
@@ -413,7 +413,11 @@ static uint64_t addr_to_dma_page_maddr(struct domain 
*domain, daddr_t addr,
         }
 
         if ( --level == target )
+        {
+            if ( !target )
+                pte_maddr = pte->val & PADDR_MASK;
             break;
+        }
 
         unmap_vtd_domain_page(parent);
         parent = map_vtd_domain_page(pte_maddr);
-- 
2.40.0




 


Rackspace

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