From patchwork Mon Jan 20 17:41:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CLEMENT MATHIEU--DRIF X-Patchwork-Id: 13945427 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 D7089C02181 for ; Mon, 20 Jan 2025 17:42:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tZvmo-0004zP-55; Mon, 20 Jan 2025 12:42:06 -0500 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 1tZvmk-0004uV-SC for qemu-devel@nongnu.org; Mon, 20 Jan 2025 12:42:02 -0500 Received: from smarthost4.eviden.com ([80.78.11.85]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tZvmi-0000cP-Ol for qemu-devel@nongnu.org; Mon, 20 Jan 2025 12:42:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1737394921; x=1768930921; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=utsA/EQVP03hwimpwCFqp0/zAZAKoMG7SGkkjc+HEe0=; b=BwJx7Uy+2LxpoAsHvu6514TeeWBTwPcsFy3EFcLqLNirc6WfOA7SNaTF Q+RNAIXdnujCpW3XPkGO9hRkvQImQTovb8nTvImq4A9lj60L7TI+qkbzZ 5PHoxp7LCt/0EnYjkM/xNE0CUa+y1NTgF1JiiXjMafrfDvr+Dq3KyFgPE XGATf437OyPkUWcVAP9Ivitxp520qhiwlm7Cagp1y94mGKiYJlfyGqydd vdhtlhMjfWcOjMOtemjYwXRtTovnrc86g9YKp6RSySur2ch+o/5vEFhLP BCz1sR/yyDIplqKM1T8mCRxLSpLv8uy84HriVzUUr9kZAjSYdoR3q2Mdm w==; X-CSE-ConnectionGUID: w6X+yHKRT4WtPDlE8ZVuzw== X-CSE-MsgGUID: eehT+nbbSZSWWkUJZiNW1w== X-IronPort-AV: E=Sophos;i="6.13,219,1732575600"; d="scan'208";a="30291725" X-MGA-submission: MDGmhSgbKL5sAAE0UseJojG6mRYDFo8OFpDe0bsAXrJG7YDsjLvyP1QeLDsNn43tUzmyP30qqz/WV+m8uQY5fA5Hu32zrDy74ha2fOQXhd2sBGYvDRseNEn1Qqwqdv8Q+mId7/Npi6xpt6MeV9HBu5UFMjYD+gtfQp/iNWB/UMvyCA== Received: from mail-am6eur05lp2105.outbound.protection.outlook.com (HELO EUR05-AM6-obe.outbound.protection.outlook.com) ([104.47.18.105]) by smarthost4.eviden.com with ESMTP/TLS/TLS_AES_256_GCM_SHA384; 20 Jan 2025 18:41:59 +0100 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kHz9Dg4ft0lGIRaNU/0znUPkrhndbovlRG4FGhvHeOJ59Zl0oCbvzUKTdzM4LLYQsW2t8a80j3fN5Bi6WvZeO2b2c5ou6P5KumjBEAcv/GL4plKgiXEzgTRHDnW5qM3spjJEhXIrzizaMpYV/Y4tpYyB1MN7wN222IG1IwT7qmY6tl64etO/EyIKX4I0jSrZOLOMmNXoYOyI0qP+HrW4JHWkqz4x6ec8IMEszw+PdR+kuhgMkfkd5XgVfLEwcnn88u32jr0AYGaf1ZDTsAGYOhNuq6QjarafNuajqlwl6eguycDTyL0xw9/0A0+jgZt1TxkCV6yXVbEypewaN4tAPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ihlsVNHBhWzOiyKsk02pHbXIfjbbzjC7MTfT0JrY5gA=; b=QGSuZO7ZBCnEzsUFhAl3DT04B3tyftyDzxJywFo105TOoMV0bZDMF5RxuJfHlr5tLZStjOy7On5/zFUKHhXbVXLDnqiSZHDKpgVfI74gBo2m11HUf/OhuMUfbRvaFZBfim5I7s/p7FBlAaZihy1nF28LGNTo7rNqf/fSxuFzarjbO/umYw8bKgUE5pGWrserCIo/EiavMSj4i60UPG2mrj/wyU1xzEHcPD6zMMpdBtraRzWx/+sLXYMouOy6OMC4BIKr7xt8iiVmRkGwCcTeDwYhGDx4ULEbNhWCAjRLrDZ7Txc3LdkNqm9wExXckuFUbWtGkKLfEUEo/Ehlzg6tSQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Eviden.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ihlsVNHBhWzOiyKsk02pHbXIfjbbzjC7MTfT0JrY5gA=; b=sJK+yA0GUJg//9XRTDRDxXVR9FvEN8ifTynXwM8djgyg/2mdV9n/YQY8bTV1aQjV7SZiBQoF2JrovY3f4zbbbAAai3okOEZGjXX3AHe0gOOZBe6RalZttTa9hKl9OLmJ0//n6e9RFPoWOncQHMCA8IZp3Sh7zxLHb1dOLSRAjjoidprQpTlUT1dRw+05KvcAA0X3rS4N+g5hE856i1o2+qFYkHhNx2UqEVnC5hewkljXskgwTJomJqyJnVRV1pDzzS3Snrd+Tx3P8fgfGQzOGa4GhzzgRDk2U1qgszLAavrtEpacEdzCBoO/nTPkShpd5ty9PNunnwjQSb46k/zDYw== Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by DBBPR07MB7548.eurprd07.prod.outlook.com (2603:10a6:10:1eb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.21; Mon, 20 Jan 2025 17:41:58 +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.8356.020; Mon, 20 Jan 2025 17:41:58 +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" , "mst@redhat.com" , "tjeznach@rivosinc.com" , "minwoo.im@samsung.com" , CLEMENT MATHIEU--DRIF Subject: [PATCH v2 19/19] intel_iommu: Add support for ATS Thread-Topic: [PATCH v2 19/19] intel_iommu: Add support for ATS Thread-Index: AQHba2Ka+y6joUjfBUuVcadc89bZlQ== Date: Mon, 20 Jan 2025 17:41:58 +0000 Message-ID: <20250120174033.308518-20-clement.mathieu--drif@eviden.com> References: <20250120174033.308518-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20250120174033.308518-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_|DBBPR07MB7548:EE_ x-ms-office365-filtering-correlation-id: 6e0e3279-7344-45ee-8ec7-08dd3979bd05 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|1800799024|366016|7416014|376014|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?q?I4g3E3Rn03D5DstDWfHv/wpB8v?= =?iso-8859-1?q?w4jlp4z4TC5gYyRRBRCuW+6TLMKN+E7pGl+2LUQ4VJaxY+EOSHvLJfkbJGra?= =?iso-8859-1?q?6jWi5zxxWZdrkI4EOGG9BLYEe0spnJiOofVq8fOY+A23wD/qxID64gg/A1HE?= =?iso-8859-1?q?LSIplF09X4LPfXgkQUyGK55FcNbiSOs1wRwqt+37ovTnQxWnWWodGTHLI0s+?= =?iso-8859-1?q?jWBY01wEisXPqiMrOaO3ezeZ4T/AnFfTHaYCDY8UG67U8iYJ7N+82ePt9Ke2?= =?iso-8859-1?q?ixStxmnTrj10g70E2kNSk3Bwwf6zM9W6zWDozyvHDU2YF2yKlZvapObSS7bE?= =?iso-8859-1?q?ECrPp/d7RgKEIVe+ePHytrrUvnkSiapPeZ6CdndfZxgtlj7gU+wLipLvwu8C?= =?iso-8859-1?q?7b15lEI45LjbVVNa+SgVChpMbNmZtTFDka5zu+T2257BvcVnq/ePMi1qvQNr?= =?iso-8859-1?q?fJojLVXBsR+ZdpNd84qRSKMINAI9Z9maI10iLPN49eqFHPaSJmS4H10UljDq?= =?iso-8859-1?q?Q/Rmm4uMYGRK57T49VjKyWxQR1k9/xaMwrcRS2vWLOAJiIhD9EOAQelx2gzO?= =?iso-8859-1?q?kH/VZ0M3XRRIfgZv5fXf5wlShn9w8oOMogbD6gvApfXO/82XaqY8f/r4LsFt?= =?iso-8859-1?q?1d/oPVefjPd2m+lwc28pK0UBRhGh/voDzqspL4XVqjCeNBwTZMIuC0qpFDXK?= =?iso-8859-1?q?piP50YgmpSfmbOFheCTwbdso2dpl2klPkZImGslKbI8b8YkfTcwMd74hneMD?= =?iso-8859-1?q?zdmWJNukJRH0INBx1dI9ll9rHupMdJ+UsqtynNPR/+OjUwxQExAvUW2pU/lu?= =?iso-8859-1?q?J7lSdop5Mc3KCc5ctZv2OE37gJW8wkU9GNXqcSQcF9xi7SsLhHLERbxuaA90?= =?iso-8859-1?q?Fap1tRNaLsSMRCp4mPDv4J//7J0/wqghw1/j8M3H+XKQa7b3Bg6JZujGMVNq?= =?iso-8859-1?q?8svfY2ofKjqkNR3s2jierFlisfUA0eRGwYxS+EeoxDC71l39nDoR61R696Z3?= =?iso-8859-1?q?Q36OWSFts0IbHG9LFZHeWvvsAQbAhoKzCOe73dGuQCpbUQqoRr4wGhIduFN9?= =?iso-8859-1?q?rmuSEFKvh2xjSRDhWxaW6Ts+4Z3uPP8fs+dDmc+lzZw31BhV9B0sWaU3MQrn?= =?iso-8859-1?q?MWpcoHmbNkSw2SL0F/DyO5vZB5xEXDe0ipi3MREbJDntkVWTcZHnVN8dL1dY?= =?iso-8859-1?q?9PCcsGTDr6gt8g+TxX9qdmVIJDBqOTgDsA5A2U6+YgNelemw2p9rTThhJA/z?= =?iso-8859-1?q?l1sEZ5zai+OjO4VCQGr4dbQQ9BGVO0WaXmJX6tGBd6cjvvd+nfXsCOz7j+JA?= =?iso-8859-1?q?wmCDZltH77MtsqieG/krF4tRcrxrVJAJ2/MrNmuLKEHf6jbxp4WOgcL070xb?= =?iso-8859-1?q?Ae1mtnlFaFqdDB4UUX9RlD8RbDzqFb5Kf9L0Ri0zchA/K/3Hn7+Zy0gDkcG8?= =?iso-8859-1?q?WDVd1tSMPhkQPW8ukItRlZrcQkojjkjFS+ehi0TtmXg6FTsHb+Oox1YFu+9p?= =?iso-8859-1?q?uyj2eC?= 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:(13230040)(1800799024)(366016)(7416014)(376014)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?FrNv2lzVOxqSq/IoIH5OZwp?= =?iso-8859-1?q?KcyNsHKAdFzMLSW0hDlsUyrxGCLntzF6Oz0esN3YbwX8+JVbCabLf0DcE64z?= =?iso-8859-1?q?VEaivKTdQY/1e6d+0lBpI5CodZkIvxtDh+dDDHEaYERsoswaKH+YIV7LzYmm?= =?iso-8859-1?q?3aIfDH7VyxFb+JJQysP4xsPXz6MompBNth2uPq5i8gDFoaLBtHgCphGAwyqQ?= =?iso-8859-1?q?C0dE+vesTj7IhbK1xpy/U1a08vxRZlAT+5ESYkSvSoXWQzI0J+m/eiutKVJO?= =?iso-8859-1?q?hfkDe3Ca/FHBXarc1xfZv8io8ATLZ+3RKPziIK+kf2PjtMOyKgmq0jcIQLHO?= =?iso-8859-1?q?/gPE1xDuD3GDTAzNLixjMWI5cXaH+1q7YkYLdfs84d5D6N2boRLS8HgQHKUi?= =?iso-8859-1?q?fQcPJbN1G2EqRx0U8LnPCuzH8lC4r+G6K4agZ39MwXc0wz5QsZXf7TaHAWiz?= =?iso-8859-1?q?IE6i+3NJuO9TEgyPW+pb23ahy6gxjB/8+bFLmSBCbJRqQ9KngoZsDKN/DbPd?= =?iso-8859-1?q?K73nSY9GzDSbVVgvgt3okxw/z5+28gVXB2SL3YIz9RjE3v8cia7BSYg6d1fi?= =?iso-8859-1?q?pmPlDMhzBmzHV8yVkaySorNQbjzaBi7HXw5pnUFU/8cwb6o7eh5IvpjndtFU?= =?iso-8859-1?q?cDGhZzTlooTDo2eZadp0wTibKhBOzLxklWuP+QkZGR078gUd2ou7MkKu/s7z?= =?iso-8859-1?q?HJhsmn1qOwWj4bovTAS+azK0E3DbCIJHzWFABxU1vwRqo5jL5ytmfLIZbnIv?= =?iso-8859-1?q?OSNQCMLjrMAEMqA86rqBy2dfdkI+fnaUQLJYUprd1eTqfiQntNSdFiwKZPbg?= =?iso-8859-1?q?weZp5jhVeXy/iPfvc8LnMktFP8rRV8/vvcFeR6gNwmRATw8fs8KhSPNDUJBV?= =?iso-8859-1?q?DEdO1+jtV9vVJkUk3ZihDBTS97eZFIp3nPuIK/cwGi9EtuQgQLI3WXAUMJLd?= =?iso-8859-1?q?iQnRqe3Mro7sDiGewy6dShotQvXK1bdD9dQv6fLX7kzAm4CzGa0KOcSctUkg?= =?iso-8859-1?q?4H6SRzp80oNpkGVIRCl73DUDq424uqspZhrDvJXg5l0gsC19Qv4hBEfk8zQz?= =?iso-8859-1?q?Ub7kloUggvUnocsVuwLgpFIpdOqhG8qpL6ln0257J6bmLYaYpQxylFmihiQN?= =?iso-8859-1?q?Ctk8ZjYsrtU7zSwgyL/uK4AEBlvBwXRrp15PBzqk3tCcjzpAC5D2FkdEJLyA?= =?iso-8859-1?q?7bL1UW9BVGvstBwqID4Ejbexc9t3X1bdnnscuZe4xAkMOhmaGd2+KyNjetpQ?= =?iso-8859-1?q?3CS27OhIkefwCfQeakF/sT/WYrAk73C20g/2d6M0m+e2T1rKSTWV65GXeM/R?= =?iso-8859-1?q?qwvq3HazgoX9ZZIOVYI1pPr+PYz5pNEudJsZrhLZINF6nrl76+8NKWiLFYDb?= =?iso-8859-1?q?B6Un/aoYS34UYEWCFyCI0SMeQ9UBIvvz/Pg065zVn4CRjJPoegQl4sIqbea5?= =?iso-8859-1?q?GbuY5pmvC3QdfAs2wIIY1M+GAMMMvD5F89yPIZVpwF4mmgUXp2KF/2G22PvO?= =?iso-8859-1?q?eo4IAc6i+ixrN+7nqfzvrdpM2NbC8zTRjSAFpVVzG4ePqmQtrtlLuJD9RaJ0?= =?iso-8859-1?q?JS6JzKfb+TNvgxRSTeQuZTzja7xvgq2ngrNSVMeiLLI0c0t/CGrQmUoI7pkE?= =?iso-8859-1?q?Aky27M8qu/JuqsSu+eH/BBg44GLNkhraypgDwyzNGAHH8AL3CxGiQLlrrDzY?= =?iso-8859-1?q?=3D?= 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: 6e0e3279-7344-45ee-8ec7-08dd3979bd05 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2025 17:41:58.1438 (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: ilDy/tlk4MxbtIvNE0+RzvWdN+W0o105Grb178XDYOA1cxOWYJhBv7otDZCfoGR5n0wfsskC4DRy6eQyYiVLRjfmg+dncQQ9Ig52ac9XvmvqadmkVscFKFR1CtnJZJys X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR07MB7548 Received-SPF: pass client-ip=80.78.11.85; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost4.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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 From: Clement Mathieu--Drif Signed-off-by: Clement Mathieu--Drif --- hw/i386/intel_iommu.c | 71 ++++++++++++++++++++++++++++++++-- hw/i386/intel_iommu_internal.h | 1 + 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3c31dc1047..698e1286da 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4159,12 +4159,10 @@ static void vtd_report_ir_illegal_access(VTDAddressSpace *vtd_as, bool is_fpd_set = false; VTDContextEntry ce; - assert(vtd_as->pasid != PCI_NO_PASID); - /* Try out best to fetch FPD, we can't do anything more */ if (vtd_dev_to_context_entry(s, bus_n, vtd_as->devfn, &ce) == 0) { is_fpd_set = ce.lo & VTD_CONTEXT_ENTRY_FPD; - if (!is_fpd_set && s->root_scalable) { + if (!is_fpd_set && s->root_scalable && vtd_as->pasid != PCI_NO_PASID) { vtd_ce_get_pasid_fpd(s, &ce, &is_fpd_set, vtd_as->pasid); } } @@ -4738,6 +4736,71 @@ static IOMMUMemoryRegion *vtd_get_memory_region_pasid(PCIBus *bus, return &vtd_as->iommu; } +static IOMMUTLBEntry vtd_iommu_ats_do_translate(IOMMUMemoryRegion *iommu, + hwaddr addr, + IOMMUAccessFlags flags, + int iommu_idx) +{ + IOMMUTLBEntry entry; + VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu); + + if (vtd_is_interrupt_addr(addr)) { + vtd_report_ir_illegal_access(vtd_as, addr, flags & IOMMU_WO); + entry.iova = 0; + entry.translated_addr = 0; + entry.addr_mask = ~VTD_PAGE_MASK_4K; + entry.perm = IOMMU_NONE; + entry.pasid = PCI_NO_PASID; + } else { + entry = vtd_iommu_translate(iommu, addr, flags, iommu_idx); + } + return entry; +} + +static ssize_t vtd_iommu_ats_request_translation(IOMMUMemoryRegion *iommu, + bool priv_req, bool exec_req, + hwaddr addr, size_t length, + bool no_write, + IOMMUTLBEntry *result, + size_t result_length, + uint32_t *err_count) +{ + IOMMUAccessFlags flags = IOMMU_ACCESS_FLAG_FULL(true, !no_write, exec_req, + priv_req, false, false); + ssize_t res_index = 0; + hwaddr target_address = addr + length; + IOMMUTLBEntry entry; + + *err_count = 0; + + while ((addr < target_address) && (res_index < result_length)) { + entry = vtd_iommu_ats_do_translate(iommu, addr, flags, 0); + if (!IOMMU_TLB_ENTRY_TRANSLATION_ERROR(&entry)) { /* Translation done */ + /* + * 4.1.2 : Global Mapping (G) : Remapping hardware provides a value + * of 0 in this field + */ + entry.perm &= ~IOMMU_GLOBAL; + } else { + *err_count += 1; + } + result[res_index] = entry; + res_index += 1; + addr = (addr & (~entry.addr_mask)) + (entry.addr_mask + 1); + } + + /* Buffer too small */ + if (addr < target_address) { + return -ENOMEM; + } + return res_index; +} + +static uint64_t vtd_get_min_page_size(IOMMUMemoryRegion *iommu) +{ + return VTD_PAGE_SIZE; +} + static PCIIOMMUOps vtd_iommu_ops = { .get_address_space = vtd_host_dma_iommu, .get_memory_region_pasid = vtd_get_memory_region_pasid, @@ -4915,6 +4978,8 @@ static void vtd_iommu_memory_region_class_init(ObjectClass *klass, imrc->translate = vtd_iommu_translate; imrc->notify_flag_changed = vtd_iommu_notify_flag_changed; imrc->replay = vtd_iommu_replay; + imrc->iommu_ats_request_translation = vtd_iommu_ats_request_translation; + imrc->get_min_page_size = vtd_get_min_page_size; } static const TypeInfo vtd_iommu_memory_region_info = { diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 238f1f443f..7e2071cd4d 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -192,6 +192,7 @@ #define VTD_ECAP_SC (1ULL << 7) #define VTD_ECAP_MHMV (15ULL << 20) #define VTD_ECAP_SRS (1ULL << 31) +#define VTD_ECAP_NWFS (1ULL << 33) #define VTD_ECAP_PSS (19ULL << 35) #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_SMTS (1ULL << 43)