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

[PATCH for-4.18] iommu/vt-d: use max supported AGAW


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 17 Oct 2023 15:09:43 +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=Q3Pqfakh+wivShd6JtJSI6AU5g2VmHIJhHRDI3lyRBY=; b=GtHyCQVOYHFwcTt4t/5CB6vU7rjaq0QNmjWe9CV9tc3vmKa2aT+PGbaxggkPxrfb+Fpcu3GTcIHhlqpf3Y2L3Owvh2mR9xb5KpQRTyLCSZZN3MLhbagXrZLYq83DnPuE44ZbeIUhoASnVD28gcUK7UEkMoKNwSKhawKLDpRwUWR/eiERli7sRwNNGWUw2qh16A+rJG9tdnLPaTbVVG2pZksYVt9EDjiR5mk7j28Kg/AO+rLso4Sx7g8kvDhbCPiO7lBpxiK95cxyJQlzd27TJAU3XZlXOMooIhPPzNyIFzeX8LE6jcyuq7/C7WbRMiLd5gWVGxhsaa0oiDcvVe7SPQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m5e4k5SEA50VOQXaiLPZ1zDoE47qMrbyN1IaO/Qi/Mu7jaf7yvsv/my76mH62+BMAQjIoMKhnsZtWRlUGGZdIfNOV+K86Qg/cNTb7CQluzyjUjUY4tfR15Id6KJOWLwusIGn3rAZcTt+Lp/kKClCYl48XaFNDF28AZ0tqAUA3uT+SrTyJDfC0i3+7jhiwq4EKAgVPJUO7P3reS4tdgZSf6Ngubq8wBKBMW/eHDYn/o7FGttjoQaUd0Yg2PFQz+94Uo1N42URX1adhoPcYQRElzaFnoHnJbvtc9NwZ+H8GYpJganMnplHR4hX8PPv3beJ1fhCeUoH0BLfP//0ZVCifg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Henry Wang <Henry.Wang@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>
  • Delivery-date: Tue, 17 Oct 2023 13:10:46 +0000
  • Ironport-data: A9a23:v6fJP6piFQeSkjUykT6KZwWSi15eBmIwZBIvgKrLsJaIsI4StFCzt garIBmOPKuOMTP2c49yaI6y9U8EuseHytFlTwFs+CAyHigb9ZuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbOCYmYpA1Y8FE/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKq04GhwUmAWP6gR5waGziZNVvrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXACgOT0yIiO2d+ZK+GsNQofoRPvPgLYxK7xmMzRmBZRonabbqZv2QoPV+hXI3jM0IGuvCb c0EbzYpdA7HfxBEJlYQDtQ5gfusgX78NTZfrTp5p4JuuzSVkFM3jeGrbIO9lt+iHK25mm6Co W3L5SLhCwwyP92D0zuVtHmrg4cjmAuiAtJPReHjqKQCbFu75jIPOBIHSGuH/9LnyWSeQflaO 2ZP0397xUQ13AnxJjXnZDWorXjBshMCVt54F+wh9BrL2qfS+xyeBGUPUnhGctNOnO87QyY7k GCAmdzBDCZq9raSTBq19bqKrDX0JSkcK0cDYzMJSU0O5NyLnW0ophfGT9ImGqjsiNTwQWv02 2rS8HF4gKgPh8kW0an95UrAnz+nupnOSEgy+xnTWWWmqAh+YeZJerCV1LQS1t4YRK7xc7VLl CFsdxS2hAzWMaywqQ==
  • Ironport-hdrordr: A9a23:QzYtMqmQ+atLEm4EKPzQ7Bu0giHpDfLa3DAbv31ZSRFFG/Fw9/ rCoB3U73/JYVcqKRcdcLW7UpVoLkmyyXcY2+cs1PKZLWvbUQiTXeZfBOnZsl7d8kTFn4Yw6U 4jSdkaNDSZNzNHZK3BkW2F+rgboeVu8MqT9JjjJ3UGd3AVV0m3hT0JezpyESdNNXl77YJSLu vk2iLezQDQBEj+aK6AdwE4dtmGnfLnvrT8byULAhY2gTP+8Q9BuNbBYmOlNg51aUI0/Ysf
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

SAGAW is a bitmap field, with bits 1 and 2 signaling support for AGAW 1 and
AGAW 2 respectively.  According to the Intel VT-d specification, an IOMMU might
support multiple AGAW values.

The AGAW value for each device is set in the device context entry, however
there's a caveat related to the value the field supports depending on the
translation type:

"When the Translation-type (T) field indicates pass-through (010b) or
guest-mode (100b or 101b), this field must be programmed to indicate the
largest AGAW value supported by hardware."

Of the translation types listed above Xen only uses pass-through (010b), and
hence we need to make sure the context entry AGAW field is set appropriately,
or else the IOMMU will report invalid context entry errors.

To do so calculate the IOMMU supported page table levels based on the last bit
set in the SAGAW field, instead of the first one.  This also allows making use
of the widest address width supported by the IOMMU, in case multiple AGAWs are
supported.

Note that 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.

Fixes: 859d11b27912 ('VT-d: prune SAGAW recognition')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/drivers/passthrough/vtd/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/vtd/iommu.c 
b/xen/drivers/passthrough/vtd/iommu.c
index ceef7359e553..be60d7573dae 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1328,7 +1328,7 @@ 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);
+        agaw = fls(sagaw & 6) - 1;
     if ( !agaw )
     {
         printk(XENLOG_ERR VTDPREFIX "IOMMU: unsupported sagaw %x\n", sagaw);
-- 
2.42.0




 


Rackspace

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