From patchwork Wed May 15 07:14:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: CLEMENT MATHIEU--DRIF X-Patchwork-Id: 13664741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8467CC25B75 for ; Wed, 15 May 2024 07:16:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s78qe-0004c8-46; Wed, 15 May 2024 03:14:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s78qM-0004Yr-Ik for qemu-devel@nongnu.org; Wed, 15 May 2024 03:14:31 -0400 Received: from smarthost3.eviden.com ([80.78.11.84]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s78qJ-0000oW-Lv for qemu-devel@nongnu.org; Wed, 15 May 2024 03:14:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1715757267; x=1747293267; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=mWrNNAaJaIPTkry3BhmfpwvoRGFU2OPTQ+DvsncCn3U=; b=C2EUs9hPTmMNBNxS1b0pSM6JPSjpL8XkfexAsuNzyG4hAFUyCBTn7rw9 rhElGGvLGDiUElLgHZvkmjUD2fFpQ3HU8/6zRyY06S0YTvqvayTzHyiEX xm1D4BwnNMOxGX9iQEOLOEZ8qtUYSLNgJGg2BRzwKXS42PULy15j/BsMc oVCTaVaPKeAV1HY+0eVuRrjcq6vxdd8dxVV+193MZouLYK46PVNVjJBpX U8TOvdFPAjMvvK1Bm7AOLVHB0ylxcyws5R73fG6hBqYcnHbhD4uA9BBZU TznYdPdonKilaQI/37ngkHauBoje7TDplsFqfxjXt2W5zF7Ng1VsfozBq g==; X-IronPort-AV: E=Sophos;i="6.08,161,1712613600"; d="scan'208";a="12581802" X-MGA-submission: MDFvjhHg6qsZitBI+5IywTdK9eursV928Nv+//b1YdeGCQmczQCVeYlh5Njkgt1p5MohSiecv5wcV+xKci0NKGLUfsJJF5SzBIKnz2FP3P1p8hxenLcBZL0/EprF+FvJPpngwp9l361YLI5+h42U05reqfP8Zz/yS5shCnFlAjyw2Q== Received: from mail-vi1eur04lp2050.outbound.protection.outlook.com (HELO outbound.mail.protection.outlook.com) ([104.47.14.50]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 09:14:19 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j6PTvIrfW9ZydZPrNE/ofGAMwrieRyp2uxOx0kTjVvz815AoSOJMRmj4L1I9a9hIZ8qHdlsgC2WXEoHX59kBEz4LkkUxbwg17463xb0wdz0/Fb7Fhkdie2yo64AOMJzUC3DeSR8FgOCIDSU6n9omArbPmiUMu+uP9mHk/UD9OOCGH84ATzB4F2UzV4ArhmkhGK4bWU4o5QEB1piiQKpk6gLayNlIvr+DdiW8DFcBtHOs7a5UygaFmKZ9Ue8b6dvC5ins5Lq6w1rNSmqhQjFBqNPpC8jfWPa/8Loy1tnKr0PIh7XwV3C4homGwti9xP7zW2o2G3TLusePIJcZIx40mA== 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=mWrNNAaJaIPTkry3BhmfpwvoRGFU2OPTQ+DvsncCn3U=; b=mpd5tyAEltd3W5I0ldwwF42A4E5e9ex/R0aSQDR7NaGzcmnw1ndmQoOudj4f4i/35F4yWJl7y0FHVLhdwQQV0QwD+ItjedaKPfPea7423Iq79YeyxtJHxs94re4Kvkx/ZYl3qCxaFgjGHUv4s59gut4yw4fSVTj5ilu0Qq60Y/nzr0vJkCiB8f0qUO3IOFwVNe4IHEPGneu6F+5H4NLk0yxHH1wGdL3A5OaOFFEczX+kyP79c2dz2oKsSkrwqTc9e+Ea7erk9fWcb8kiuMOY43phPyr1Ac7XOyK9KLny9nXAfSOuFDmixxule6myOJ6QJ4M2XETV71H/+XmG1YXeNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=eviden.com; dmarc=pass action=none header.from=eviden.com; dkim=pass header.d=eviden.com; arc=none Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by VI1PR07MB6718.eurprd07.prod.outlook.com (2603:10a6:800:18f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Wed, 15 May 2024 07:14:17 +0000 Received: from AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d]) by AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d%5]) with mapi id 15.20.7544.056; Wed, 15 May 2024 07:14:17 +0000 From: CLEMENT MATHIEU--DRIF To: "qemu-devel@nongnu.org" CC: "jasowang@redhat.com" , "zhenzhong.duan@intel.com" , "kevin.tian@intel.com" , "yi.l.liu@intel.com" , "joao.m.martins@oracle.com" , "peterx@redhat.com" , CLEMENT MATHIEU--DRIF Subject: [PATCH ats_vtd v2 13/25] intel_iommu: add support for PASID-based device IOTLB invalidation Thread-Topic: [PATCH ats_vtd v2 13/25] intel_iommu: add support for PASID-based device IOTLB invalidation Thread-Index: AQHappd/Mn4U7rZK2kaAPkj64rXn9w== Date: Wed, 15 May 2024 07:14:17 +0000 Message-ID: <20240515071057.33990-14-clement.mathieu--drif@eviden.com> References: <20240515071057.33990-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240515071057.33990-1-clement.mathieu--drif@eviden.com> Accept-Language: en-GB, fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=eviden.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AM8PR07MB7602:EE_|VI1PR07MB6718:EE_ x-ms-office365-filtering-correlation-id: 0a08e020-04fe-498a-e046-08dc74aea21a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|366007|376005|1800799015|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?/4fkxxfgbMiyjkrQyv3A6vkxYPpQWc8?= =?utf-8?q?VtoHiWKfuJ8SUlp3VS/yjU1uhOHtFxgGohQ4s2qJE/JW+/i6muqUw+lScMADzuCJ9?= =?utf-8?q?Cs+FtSCJNm3cmUwJbhzME+noT7GByOwX+WnM9EFFrFYp/FYyMskoDavzYEUV4GRnS?= =?utf-8?q?GuiVdu+7Yu8nl/tnMj9I95a0TjfVNQS/RVHy/rfvhQYPQo7UtbvX35VSVlnmQop3w?= =?utf-8?q?la7ljkid3RTE8jWd75wE3HHK5n8Wl4ZbKEGJonfMzXVLno7xikes34DKlNj64+te4?= =?utf-8?q?Umse+EGdxSRnP58qFBbQDI+Iqwp489Fg8zloEr76KkhAWftH5AfRbdPt/1Qdeoakd?= =?utf-8?q?9o/pjrdFY/3vcAHa887zRhNbia+rFQwqJ5RbKpDi960ih21kIAYz4nTTr8KcgfBeb?= =?utf-8?q?AR0vDrzFjUJtQBOyVL3nUqVMs/9U8+7Jx/KyTRazjJQIcFj1Hy09ySy+rMuGF5cR2?= =?utf-8?q?uicTACfmt/34ikOGQ1w8Xazm6a+KvDrqDZIn4aPIRKxy814BfgENLi4pD9N4gxRLq?= =?utf-8?q?6+5N7HinVm0jIVXUq4n9//V2uxeUt5zvUWNZsGslUqOJAL5RPsn5+AbvBR7i25OyY?= =?utf-8?q?9aZVrUBnolYqgTkM0NAitViXd7l2yXOwDZEli7hvJO6KZ9yux8kel6VMnAHmpVegA?= =?utf-8?q?2Gdfm2r8o+lklmQMwHVBva7QqW4pEtlm1Wz6/1GJAWzwAonx4U9aCbjub3pVYCZma?= =?utf-8?q?IQErqymq9si886jYPd6mEVo0gHDsHwP0OWlWDmqtC4LthaA2w9K+UVPRa7jD57/on?= =?utf-8?q?B3jnXXJc0Pv8FDIEVWIKmTwhVmk7wtQ3awDSlXTCLxyP8rwdKUZySFNjazOT4mBL5?= =?utf-8?q?GFdO/TMynBQYcbFrWM/DJ11+n1A0MKxlS7dXqTB3qAwjpY2yaHiUydmgAIPtDLcUz?= =?utf-8?q?FhKyUTlQhtFMrq2M+lL9bM79I+t/34MKz2xZ5T2yeipLgl+qvKAqISPDHQdZiDl6b?= =?utf-8?q?c36RqbFQkusKUzqs8v8l7VRG9WiNJ6YIvRKCM//c16itGoODMu/aDlzyOY84mpdmx?= =?utf-8?q?5lOPDYe8zFlqecwKpOXSu+FkCXQF11p3sPvs/nMdZOmJBw9HNmGz98X5H00AYBGVu?= =?utf-8?q?DE90hvZliwJPUDealNDQlEMZqiUkriwfjvVUv+r+9EW6+frIJxczm2kp9yfeyYvcc?= =?utf-8?q?KqySGarfOTM98Em2YjzB1cxdpCuXi8Pf1h+vElq3jvrhLopqlw3ubFZqIFhfYF6wr?= =?utf-8?q?TPB3BFtADmbvjbtWvpDAlXNYNq50b1jm0BE/e0akG5xCF7btDc0VtwWYADVRAsXJl?= =?utf-8?q?cUlAieTftDOST66uNcTpPgs1Wg0cC0SVo1w=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM8PR07MB7602.eurprd07.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?uQLnaxPG+lroo5MXoO6DjAQuK3IY?= =?utf-8?q?2ZII3oLyY5G8V8owUesdUETQJDkRNfW4NVbpek9wT4gbJ/gn9PM07X7+abZIVXOd8?= =?utf-8?q?C5ibs4dBnjzCdNFMJGo7ty6NaBAmu05Xpc/BtnQNtSCkjzkd8eTrbNYJR9BHNhjWB?= =?utf-8?q?dYrGAO/ZZKSE++SgV2OoQf0fFtc1W3YuKNk3KSVuf+vy7j8TqwmCylnOjVYhFDJGW?= =?utf-8?q?9GsBttPOLEzhWhaut+9EPsJ8wqv3Rk4nK8EATYxr6v6hMooFJG9TrQt0Dsh6SY1sp?= =?utf-8?q?bLHgSOf2GRybABWIly4X1VCpHrK19Xob6Q0eI1jKcOqCaf891Gr6abyqtdF6gds3i?= =?utf-8?q?Vne9kcgWMb3cJY4GZlxF1OsSf7IScp5232hqi12NduVVRwMQt7QYQCIcs8ATkhIKR?= =?utf-8?q?42pjwrFmGgHeEPP7e5i0MJAWR5TIQfduayD+d+zZSKTC8erprmmXKpsLxXLZcR+zu?= =?utf-8?q?4Aw/vXiiAJkgGSSl92T1MZT9qDKOIPnvLhWUYH+9Z2D7GSZZbdYjaeZ7E0EouFI+5?= =?utf-8?q?pBYK7Ohw80hSfe0Apr0V1DmxbN7gxIRSdFeCBHzkDrprnRqrDD1C/cxymzGascPlP?= =?utf-8?q?8feWNBTFkDDEvrUu3tIFAcbaZ42d2MREmpACoOlQno6KhlpxjKU4yaLDn2jLbnBwv?= =?utf-8?q?x3vBb8WOOV6WYhIkkEBi5GpGSbRr1ehFJAz1ceHmyv7AcZmrEbqSUsmHGt5NbS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iSVaYNo=3D?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: eviden.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM8PR07MB7602.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a08e020-04fe-498a-e046-08dc74aea21a X-MS-Exchange-CrossTenant-originalarrivaltime: 15 May 2024 07:14:17.2084 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 7d1c7785-2d8a-437d-b842-1ed5d8fbe00a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BVu02JEEbSkBG141tPbXlYQgoygAgbwdc+7gXTkX2BIxZqYe20gBv8Ch2lUUrMpyFIvwOawRJG8pl7lMDPNxdkJaR89b/u04ijAYCmI5LUR/d9aWUif+hGuyHRYsKLIG X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6718 Received-SPF: pass client-ip=80.78.11.84; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost3.eviden.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Clément Mathieu--Drif --- hw/i386/intel_iommu.c | 42 ++++++++++++++++++++++++++++++---- hw/i386/intel_iommu_internal.h | 10 ++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 166103510e..fd4710ba28 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4341,11 +4341,43 @@ static void do_invalidate_device_tlb(VTDAddressSpace *vtd_dev_as, static bool vtd_process_device_piotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { - /* - * no need to handle it for passthru device, for emulated - * devices with device tlb, it may be required, but for now, - * return is enough - */ + uint16_t sid; + VTDAddressSpace *vtd_dev_as; + bool size; + bool global; + hwaddr addr; + uint32_t pasid; + + if ((inv_desc->hi & VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_HI) || + (inv_desc->lo & VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_LO)) { + error_report_once("%s: invalid pasid-based dev iotlb inv desc:" + "hi=%"PRIx64 "(reserved nonzero)", + __func__, inv_desc->hi); + return false; + } + + global = VTD_INV_DESC_PASID_DEVICE_IOTLB_GLOBAL(inv_desc->hi); + size = VTD_INV_DESC_PASID_DEVICE_IOTLB_SIZE(inv_desc->hi); + addr = VTD_INV_DESC_PASID_DEVICE_IOTLB_ADDR(inv_desc->hi); + sid = VTD_INV_DESC_PASID_DEVICE_IOTLB_SID(inv_desc->lo); + if (global) { + QLIST_FOREACH(vtd_dev_as, &s->vtd_as_with_notifiers, next) { + if ((vtd_dev_as->pasid != PCI_NO_PASID) && + (PCI_BUILD_BDF(pci_bus_num(vtd_dev_as->bus), + vtd_dev_as->devfn) == sid)) { + do_invalidate_device_tlb(vtd_dev_as, size, addr); + } + } + } else { + pasid = VTD_INV_DESC_PASID_DEVICE_IOTLB_PASID(inv_desc->lo); + vtd_dev_as = vtd_get_as_by_sid_and_pasid(s, sid, pasid); + if (!vtd_dev_as) { + return true; + } + + do_invalidate_device_tlb(vtd_dev_as, size, addr); + } + return true; } diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index d63ff049a7..3d59e10488 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -424,6 +424,16 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_DEVICE_IOTLB_RSVD_HI 0xffeULL #define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8 +/* Mask for PASID Device IOTLB Invalidate Descriptor */ +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_ADDR(val) ((val) & \ + 0xfffffffffffff000ULL) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_SIZE(val) ((val >> 11) & 0x1) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_GLOBAL(val) ((val) & 0x1) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_SID(val) (((val) >> 16) & 0xffffULL) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_PASID(val) ((val >> 32) & 0xfffffULL) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_HI 0x7feULL +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_LO 0xfff000000000f000ULL + /* Rsvd field masks for spte */ #define VTD_SPTE_SNP 0x800ULL