From patchwork Tue Jul 2 05:52:44 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: 13718998 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 CE402C3064D for ; Tue, 2 Jul 2024 05:56:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOWRo-00084K-7r; Tue, 02 Jul 2024 01:53:00 -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 1sOWRe-00080a-Mq for qemu-devel@nongnu.org; Tue, 02 Jul 2024 01:52:50 -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 1sOWRc-0006b9-Cb for qemu-devel@nongnu.org; Tue, 02 Jul 2024 01:52:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1719899568; x=1751435568; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=uURpO697BJoj6AGiwIj7FDv0GD3NcoC+arT0L1cxEHg=; b=nnzZqchFsscFnvrRhrj80P5maoJwsvoEXuiZordrv/ZsnuuBuXz2jxML pgWIIvE+x4RnJxfTgq0uisdwzQiFvkDbfZB4rzovmyqrlw1NS+mc6WNQC BZyEgj3r7/aviVDQp+wN6i+fhg+HbnG7/i9Fos9pJgvmieZ89QlxKxqGq t2DL/YsIsLZptgeBBIBBWu8NIzYR5XgED/p4J1kpPngzx6QU5M8wOuypS An1ILutANL+BA4g4y30yN1r47shvhOGbjeZXi8fTmaRDnHmrPhr8NMX7U xDlBg+4cdbql5TYZ350ylJfPMZqXWqD/WoRilpoNpbyb/Fw+mY0W+nTNw w==; X-IronPort-AV: E=Sophos;i="6.09,178,1716242400"; d="scan'208";a="15721602" X-MGA-submission: MDF5T5rs6JXIApWHkNP8w+Y9fcB4KmelyVPoLk1bLPG5Ez6TzI4ZVmkhNJK8fQyWOq7ejF/3x88FvQ4M+grQpPMYlwzQt89MavadkrhtIvGvMek3poozHTRtwTtmqzxKS/balpGUmITTAsYt9Te9bpaecgLqo8wm/VgT/2Z5GRvMmw== Received: from mail-db8eur05lp2104.outbound.protection.outlook.com (HELO EUR05-DB8-obe.outbound.protection.outlook.com) ([104.47.17.104]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2024 07:52:47 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jcRSPq+IQq4y0OvyPgIJHH+7PXWJSNOEEAliyPTYg2Djb389Hvy4nsBfmweDTGcGR9/XvgrX9qotx8pNp5RtQc1/VxnXpGFZvJ/+YP2dqbXj6UUjnlxXhogvYsgjZmUgOTns8pUcK2zEB8U65QVwEfzZbf3B8g76yITs0R4LsDhOd0yUKebMp0o39vdHVtV6LW4qCBlE9DX6lbCPLqU/md6LWRjPYmoME1aOoAtg0Wzzy+2IIbGQVe16Zy5s8E7nUu4C4RU4WGECYK6Kut6GS4yCk5MTOcEzLWSFXttjH8gP7bOIrmfcr/1GA5BvTiBeNd8ZIBP1R39n9Eg5v66Jqw== 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=uURpO697BJoj6AGiwIj7FDv0GD3NcoC+arT0L1cxEHg=; b=CxX1u6VMsZMuKhDe0P5S4iUHx8UoNsO5Kwu18Q+cPrNfW9rY1jolkrFgVa4ObIXX43DuErItVnJjGg7RcCv6uCZWDhO29O1CysgUzNec6QgKCI0ghji6vFs1QtB/XPJRjuDhJj9h8Oz0e5omgOsuSlBxw5/GvRC6psBLoJdCUcWRSlrL3d+PBBLuk5sDszH8AjsmbYBlTmk3adlczj5vl779Ryilor/rZQgBIzd8bNMl5KQtQAVzds5OEW0Uvv52dsNrh2Uux/vovUB47Ztssx4oKB+iysgUhx7tqO5RVt8rHnyqgU3Gx/lkFFFgqJwMDGhqOcRmg2CRyglHTNnGOA== 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=uURpO697BJoj6AGiwIj7FDv0GD3NcoC+arT0L1cxEHg=; b=gjo85wzfp07PAHmFkBYJu3Fo+UchodubMQmgn+DNy+DD3rLQFhr065ShltrM0xal+z7m00PizfkL5iWTCTkjEGnlrrJb4Jnad40NUrcVJEw54AUlhQWPmu0wwLh1ntf93SPsAAWmoHnLGLRiutzGfCLeEvU7xyAofedvqdTjcT2o2zsRL9VQMd8z/edjyQqrrlF/L2Ki1KVV7ps2Zo4B7G1HUkNXMNI7nZcYKZu33sX0YmOC04PG1B2yncVV+sQvAPXX3uRn/v2LI1cYbp79giAt5Bh76eLx/IYioTZ6a1ASTyL0urASnjIrBpDo4XKG1Gc5ZegBPrnhoDQBV5wPQw== Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by AM7PR07MB6215.eurprd07.prod.outlook.com (2603:10a6:20b:13d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.21; Tue, 2 Jul 2024 05:52:44 +0000 Received: from AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d]) by AM8PR07MB7602.eurprd07.prod.outlook.com ([fe80::fbd7:ca71:b636:6f9d%4]) with mapi id 15.20.7741.017; Tue, 2 Jul 2024 05:52:44 +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" , CLEMENT MATHIEU--DRIF Subject: [PATCH ats_vtd v5 19/22] memory: add an API for ATS support Thread-Topic: [PATCH ats_vtd v5 19/22] memory: add an API for ATS support Thread-Index: AQHazEQPuEYX/3NIkkWJkupwBDAHeg== Date: Tue, 2 Jul 2024 05:52:44 +0000 Message-ID: <20240702055221.1337035-20-clement.mathieu--drif@eviden.com> References: <20240702055221.1337035-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240702055221.1337035-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_|AM7PR07MB6215:EE_ x-ms-office365-filtering-correlation-id: e16c1f1f-f0ea-4c17-d229-08dc9a5b31b8 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|366016|1800799024|376014|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?Lqp5BDoHfJ0ugIvGk9Ek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rrXMc1fyX?= =?utf-8?q?Pl8hdPO1ixbzSeGkQpYveSu8tKhAbBghtzI1XwMyFkDP6LgfcPnjtHGyMLEzb/vjm?= =?utf-8?q?03f3ASNqQA3vqH/hncSM7c0IIibJegGvbsOECBS2moH+jFv6hDomdcuC7VCvroqmx?= =?utf-8?q?DHesOYH51aAQ0K6exSjcfHpnjNKAquupXBKns8wERW/HuEoFhEMM17y0TI6AJSEvQ?= =?utf-8?q?NMbVb+VM5qaGP6Nej8ndjHUtL+LV1b5ZVnCBbXhRsW/XOJw97JqFuN1yEE0PAL0q3?= =?utf-8?q?gcYtxGrGDyBJXY4iygca+x5InIbyihSrKJmEJt9A/HAxfv7Yjq+VEzbfrk+GZBUUF?= =?utf-8?q?bRnTB+5P5ONksQxAarvpCIj0DcsbBJqeEQrIg6DzwhPoT5CJr61b5/N72dt8NY6fs?= =?utf-8?q?02iQPf0lQmn7pmfqdT4ibjxiWvAIEpxdyUAdSPlmJfXdk/mph7fBg9P+MXEqc00jS?= =?utf-8?q?Eko7NCg30jmX/3lCFaHSQIGDwENbqlRdTA=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:(13230040)(366016)(1800799024)(376014)(38070700018); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?Y8g4To+K3n+SLuAIFJWMl02An8Ic?= =?utf-8?q?saZfuOT/fmSutLh0B6r8VXDvPLjfYxHXKbj7pGPFMjyT3hnW+asQ5mfjl+L/jPT5g?= =?utf-8?q?BQ6YJ9GQ9TofHfPi5I+bOZSzoixeq2M5cICo2oxKskFozxkEZwk1AerA9l+ZRawdR?= =?utf-8?q?yGOagLTj8CJwxY4WOXXEGCkaG+lPJlHe7c4B9Rz1fXBkQNbBavT8rI139y8bx6scP?= =?utf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8?q?5k8OFAKFvXmfWx8qUfDWU9OWsKRRbwP7UMbI0zlE6vwLT83e0aY6ufUddiJe/nsX0?= =?utf-8?q?O1a3H/ElyCB7WEttD2GY9o/SjvRywE09NDkF4yJlsGZTF8EuGF9nDIjQ6ZDtel5OM?= =?utf-8?q?+O/ndPxrm5xtKqlDDSFgpu3IVEsVs885wKSRBcQU3kNpmmTbb/Asg/AtID6u0V1Z6?= =?utf-8?q?h7FdcE08XyJq7gAP/zP0wGn+xdqgpsdA5S6xJIEf0Xf7GeUzlR/NRYpUXh4XMv/55?= =?utf-8?q?YCMPDmUktYi8pbEzukAUxfpwil7vdON10p5f3nLCaYmufPqtgXHklBHsW3JMUtIgL?= =?utf-8?q?rECTxta/zgYWTgLEyZ38SdwA2SKsx7ubOdRGYKUlJLqPhU1jfsqL8kR0q3C7TCrgI?= =?utf-8?q?G4pWvPyG7kKy1zG+N9xcxDCpvZDR3fwskuxPy/No4yadApghXzszWRb9HI/qPBE3E?= =?utf-8?q?j0uaCzkU8REjFBqYufq187TYLiFypOCzoGP0QHtjb+m63R1mzqcN35c=3D?= Content-ID: <3CAD16FE784C0D49A88AF199A8B04E69@eurprd07.prod.outlook.com> 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: e16c1f1f-f0ea-4c17-d229-08dc9a5b31b8 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Jul 2024 05:52:44.6561 (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: 8NvTJddmTW8qDPpYJeji3f8bh/OMUw/35tEZ8RZV3SSEfshYbi8fJuGrUJDdElnGA7iYTtgE3W3wQNXLz9i5hMPe9vDH0vK+WlztoZO6IkGfOyNx/MG64eS1hEnpLIP/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR07MB6215 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 From: Clément Mathieu--Drif IOMMU have to implement iommu_ats_request_translation to support ATS. Devices can use IOMMU_TLB_ENTRY_TRANSLATION_ERROR to check the tlb entries returned by a translation request. Signed-off-by: Clément Mathieu--Drif --- include/exec/memory.h | 26 ++++++++++++++++++++++++++ system/memory.c | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 003ee06610..48555c87c6 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -148,6 +148,10 @@ struct IOMMUTLBEntry { uint32_t pasid; }; +/* Check if an IOMMU TLB entry indicates a translation error */ +#define IOMMU_TLB_ENTRY_TRANSLATION_ERROR(entry) ((((entry)->perm) & IOMMU_RW) \ + == IOMMU_NONE) + /* * Bitmap for different IOMMUNotifier capabilities. Each notifier can * register with one or multiple IOMMU Notifier capability bit(s). @@ -571,6 +575,20 @@ struct IOMMUMemoryRegionClass { int (*iommu_set_iova_ranges)(IOMMUMemoryRegion *iommu, GList *iova_ranges, Error **errp); + + /** + * @iommu_ats_request_translation: + * This method must be implemented if the IOMMU has ATS enabled + * + * @see pci_ats_request_translation_pasid + */ + ssize_t (*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); }; typedef struct RamDiscardListener RamDiscardListener; @@ -1926,6 +1944,14 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n); void memory_region_unregister_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n); +ssize_t memory_region_iommu_ats_request_translation(IOMMUMemoryRegion *iommu_mr, + bool priv_req, bool exec_req, + hwaddr addr, size_t length, + bool no_write, + IOMMUTLBEntry *result, + size_t result_length, + uint32_t *err_count); + /** * memory_region_iommu_get_attr: return an IOMMU attr if get_attr() is * defined on the IOMMU. diff --git a/system/memory.c b/system/memory.c index 74cd73ebc7..8268df7bf5 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2005,6 +2005,26 @@ void memory_region_unregister_iommu_notifier(MemoryRegion *mr, memory_region_update_iommu_notify_flags(iommu_mr, NULL); } +ssize_t memory_region_iommu_ats_request_translation(IOMMUMemoryRegion *iommu_mr, + bool priv_req, + bool exec_req, + hwaddr addr, size_t length, + bool no_write, + IOMMUTLBEntry *result, + size_t result_length, + uint32_t *err_count) +{ + IOMMUMemoryRegionClass *imrc = memory_region_get_iommu_class_nocheck(iommu_mr); + + if (!imrc->iommu_ats_request_translation) { + return -ENODEV; + } + + return imrc->iommu_ats_request_translation(iommu_mr, priv_req, exec_req, + addr, length, no_write, result, + result_length, err_count); +} + void memory_region_notify_iommu_one(IOMMUNotifier *notifier, IOMMUTLBEvent *event) {