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

[PATCH for-4.18 v2] iommu/vt-d: fix SAGAW capability parsing


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 18 Oct 2023 18:07:33 +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=0NB+b3J380cq5NzadCk1WF4+vrWWrWFw9x7B0e3IBno=; b=lAPxyw08+6dSbNJHqY/ZOdBz5fKUqS7XAIChZSUblQ5oiqg8ZI1Sgd93NDz+GJOoNOEioWdFC6baNOKSWzlDZ1JSCzF/7CRK+Dq8r9zxnBjOa4pckJdfJxLZWJQ6b6sVB+i+vAu2RvWEezEa9VjFWry2qRTF8sM0UibgWcevjZmI3nYS5YtlCXjTVp9JV91X5OE5Qal0da2H+Olr0kJVAh0XjxF5VJuP1OSXl7vo5tnI6bkW2LU1OcurDUJblbe/H+z06v+XUPpjvfgDkIYAl+epXysEGx23dTJ7ZCFFSDih9tGZS3AKFG9Kvfcrd28Avh0P2/Aip3baoC5YOv4khw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JdYFf1H38Ss7OGzXrSEOIU3QpFruyoUBU8ZSwKMohgtOAinSHkagc+ZsEEEtBr1pgHGYurgr47q3xntyHz6lISG7V0aSLXOvkpnne9wkZBzQ6Y+rMuSN2SEXJrI69AiOXYmV/8aZMywbRGIDOMVRHQINhWrfHOXqoB0ftLqsMirvU3d9Vr7zhFvYnl9G+vhw1JfHCJK6LfMl49eswy36DXeBPEp6Slz3cCRXMN1Ym3l9tVWGXKmmslVddZYSICLxNuzi/CIXspohc4y6mLVpg+lyUXgoHnv6mLl8y9h2LF300YpwCLkfDwEG16OyrrZ7Sxe+ys38BqQaldRfSL233g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Henry Wang <Henry.Wang@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>
  • Delivery-date: Wed, 18 Oct 2023 16:08:27 +0000
  • Ironport-data: A9a23:8MR10qNixtl/0YzvrR1hlsFynXyQoLVcMsEvi/4bfWQNrUol0TMBy GcaXz3VOPncZjHyLYx3O9+2pkMHvpaBn9Q3Sgto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CQ6jefQAOOkVIYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/nrRC9H5qyo42pA5wxmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0ud2W31U1 vdBEzwINTKZnL6b56rkZcA506zPLOGzVG8ekldJ6GiBSNwAHtXESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+vJxujCKpOBy+OGF3N79YNuFSN8Thk+Fj mnH4374ElcRM9n3JT+tqyjx17GUw3ukMG4UPL+J1s5ynVyP/HFNFTImUnTjqPWzm0HrDrqzL GRRoELCt5Ma5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWbkAkQzhbeZoZvck5bTUw0 xmCmNaBLT5lvaCRSHmd3qyJtj70Mi8QRUcBaDEFS00Z4tDliIA1kh/LCN1kFcaIYsbdHDjxx 3WAqnc4jrBK1coTjfzjpBbAni6moYXPQkgt/ALLU2m57wR/Iom4e4iv7lud5vFFRGqEcmS8U LE/s5D2xIgz4Vulz0RhnM1l8GmV2su4
  • Ironport-hdrordr: A9a23:i+e6+azgwm5PqsbTk/nNKrPwPb1zdoMgy1knxilNoH1uH/Bw8v rE9sjzuiWVtN9vYgBDpTntAsa9qBDnmaKdg7NhXotKNTOO0FdAR7sC0WKN+VPd8iTFh4tg6Z s=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

SAGAW is a bitmap field, with bits 1, 2 and 3 signaling support for 3, 4 and 5
level page tables respectively.  According to the Intel VT-d specification, an
IOMMU can report multiple SAGAW bits being set.

Commit 859d11b27912 claims to replace the open-coded find_first_set_bit(), but
it's actually replacing an open coded implementation to find the last set bit.
The change forces the used AGAW to the lowest supported by the IOMMU instead of
the highest one between 1 and 2.

Restore the previous SAGAW parsing by using fls() instead of
find_first_set_bit(), in order to get the highest (supported) AGAW to be used.

However there's a caveat related to the value the AW context entry field must
be set to when using passthrough mode:

"When the Translation-type (TT) field indicates pass-through processing (10b),
this field must be programmed to indicate the largest AGAW value supported by
hardware." [0]

Newer Intel IOMMU implementations support 5 level page tables for the IOMMU,
and signal such support in SAGAW bit 3.

Enabling 5 level paging support (AGAW 3) at this point in the release is too
risky, so instead put a bodge to unconditionally disable passthough mode if
SAGAW has any bits greater than 2 set.  Ignore bit 0, it's reserved in the
specification but unlikely to have any meaning in the future.

Note the message about unhandled SAGAW bits being set is printed
unconditionally, regardless of whether passthrough mode is enabled.  This is
done in order to easily notice IOMMU implementations with not yet supported
SAGAW values.

[0] Intel VT Directed Spec Rev 4.1

Fixes: 859d11b27912 ('VT-d: prune SAGAW recognition')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v1:
 - Reword commit message
 - Put a bodge for SAGAW bit 3.
---
 xen/drivers/passthrough/vtd/iommu.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/xen/drivers/passthrough/vtd/iommu.c 
b/xen/drivers/passthrough/vtd/iommu.c
index ceef7359e553..d2211ecc0b1b 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1327,15 +1327,24 @@ int __init iommu_alloc(struct acpi_drhd_unit *drhd)
 
     /* Calculate number of pagetable levels: 3 or 4. */
     sagaw = cap_sagaw(iommu->cap);
-    if ( sagaw & 6 )
-        agaw = find_first_set_bit(sagaw & 6);
-    if ( !agaw )
+    agaw = fls(sagaw & 6) - 1;
+    if ( agaw == -1 )
     {
         printk(XENLOG_ERR VTDPREFIX "IOMMU: unsupported sagaw %x\n", sagaw);
         print_iommu_regs(drhd);
         rc = -ENODEV;
         goto free;
     }
+    if ( sagaw >> 3 )
+    {
+        printk_once(XENLOG_WARNING VTDPREFIX
+                    "IOMMU: unhandled bits set in sagaw (%#x)%s\n",
+                    sagaw,
+                    iommu_hwdom_passthrough ? " disabling passthrough" : "" );
+        if ( iommu_hwdom_passthrough )
+            iommu_hwdom_passthrough = false;
+    }
+
     iommu->nr_pt_levels = agaw_to_level(agaw);
     if ( min_pt_levels > iommu->nr_pt_levels )
         min_pt_levels = iommu->nr_pt_levels;
-- 
2.42.0




 


Rackspace

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