From patchwork Mon Jun 3 05:59:53 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: 13683267 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 3C325C41513 for ; Mon, 3 Jun 2024 06:01:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0jt-0006s6-FU; Mon, 03 Jun 2024 02:00:13 -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 1sE0jl-0006nT-PV for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:00:05 -0400 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 1sE0jh-00071T-NQ for qemu-devel@nongnu.org; Mon, 03 Jun 2024 02:00:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1717394402; x=1748930402; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=uUNdQjejwD19GDvGqzTWmxMIvWgcJeiOCFc/IfPyiss=; b=OmdIp0zVqbNxZ6IcYNenGGrhRbe/FdgV3oTNLHCqpk+xjy+XwmBSD6Lx Q6pRrQVScBtB2FRbLE1EmY0UWopn0zOKMLsJOVd/1f8FwLXAuHNII9vTM CL9rPSP2j49ksVDym+iVsjLQsIEglptqx1hZJ6Uvap4ER/hzUWfVoA7FZ vGadUlDJ7qbGtCWPEUWbZbYuU5Za2ungGBdaEvLLgKXZUyufwVWodhPvB MMZYL5Z6FL9lXSKevXqCCBCRQcqFhbvVmuZl0hFdEkyfEW6wNZm+9Ay0e ZVsZEfzLPlduD13X7XHiKXJ/1XxWLyr1brNS6H5qOtEJ5t5jVHz4t6wz0 A==; X-IronPort-AV: E=Sophos;i="6.08,210,1712613600"; d="scan'208";a="13815889" X-MGA-submission: MDGKsKxKnEJsFH9MhGljupOGHWmH15QFEyM+F0Yv51LXdZ/9zUIZNZUxNEAvKk0cIOnynLg0aZd7fIS/8J16a2Zjiz9kHVdjZzP4AibrNjUv5BtAVBMxstwqzJPY0mTFuTrpmWnNRho1ncc9GnhM4IN+OdzAndV6OXxoSX1u7QVcNw== Received: from mail-vi1eur02lp2041.outbound.protection.outlook.com (HELO EUR02-VI1-obe.outbound.protection.outlook.com) ([104.47.11.41]) by smarthost4.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2024 07:59:55 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WenOiXZXwxTSFuI+R8QUz2YuFH+2CwuwgnuY4Mrmy1lAR7q+MA3pl2I6H/j6bnNtlcgYji28o1pAUUapBg5LrIMCOF8FG5NFwf38BMSWU6OCm7OzpHu/AL5ZROUPw37I89HR6Cmi+nmy3XYdoHRSr6qhid7GOrk8QZmK5fpoxJzU06p4B+VnZ6y9Id53uA7qz1zpLHWkhLcoB/XkJ2wnsac8rs2RFIqPfNEmGk7haG+RhYH2i1MBawaU9PUuD6J1feikXhrCOCRRPmVr4p7vxUw0y1i4skp64xF8soRD0Uq6s4GPDPt8A1aOO0IgpKfqA+Jo4V32L7XI4ZNzwXYxUA== 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=uUNdQjejwD19GDvGqzTWmxMIvWgcJeiOCFc/IfPyiss=; b=dphmP0iGw+zpgoVjxHQnUZOvcivUi2F1GoPP9iWRSNrDZMkUYbwbKUroogJBdrXHRL7eUdmZjm+jEk9GeZbssnuMAnR9fNv9QuO+hupJqXF7850Q52f6AKhbK1F9b5HLp+Xp8wYLWABcvck0Y0gdUJR7PIc26RUiE+7Tw/eOVzzBRp4w0kUnblOactxcVt2QS0xdzPmIbkBApiK/BMTX7MnQ5LcBgkbxoKLnDwDJVDsX6iTJaKb+iYw/cOnJIe2fwEJnXUnVeumN+LDceFSSNrkKg7iGTctt5DqYs6Tj0DYYXnh56Y/8RjbWrh5OPvQ01GE/in789jRJHX1H0Ly9xQ== 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=uUNdQjejwD19GDvGqzTWmxMIvWgcJeiOCFc/IfPyiss=; b=cgVQ8/VNtfIjJ1ol0kZuq2QZ9Zot24BqEr1eLCuY2ekee60rTBtUlPyHTJhbPFDpqLNJdUdR4mL5MWxyW+pt2IAOeTFWVNFh2NFEROm4HSQQ4qlMHp+UVmOqdi5bFxCO1GIa7RR+nH8g8iev+2vUx2aKvUW9thBQwuyCEL3zSQ51aEud4SYkFkWDMPjXGyiWKrDQ7j24S9T5RQmOTqv6nXZyOPMZbYgWtq4ltu+4+wdJHNoptmvfC98r4T9q/4317pnwYT1P7Unh7Oa0/mjSYgP4qrgChvgXgbiYm7WGlYvE1n+8f8oHYQBizYFU7hsXayVUdWFwtSqIFV1PaDpXKA== Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by AM8PR07MB8192.eurprd07.prod.outlook.com (2603:10a6:20b:323::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25; Mon, 3 Jun 2024 05:59:53 +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.7633.021; Mon, 3 Jun 2024 05:59:53 +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: AQHatXtACltASpuAL0qCo+7Ga8q92Q== Date: Mon, 3 Jun 2024 05:59:53 +0000 Message-ID: <20240603055917.18735-20-clement.mathieu--drif@eviden.com> References: <20240603055917.18735-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240603055917.18735-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_|AM8PR07MB8192:EE_ x-ms-office365-filtering-correlation-id: 29129a78-1818-429f-bd51-08dc83926324 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|376005|1800799015|366007|38070700009; x-microsoft-antispam-message-info: =?ut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CScvNHy6Skkh1BvQyI/TsjKxSHiJucbFFvvwG+y5k?= =?utf-8?q?e+fW6voJsasxDO7/O1efE1IiXIY/90tnEUFjzQrY+S96f/lbAWghRK0HNei4BmGrh?= =?utf-8?q?/VcEKt/Hq56kBe3aaG5ZHlAbJcPRK/zvgkV4I0jArqOQqo2KeA4l1H7/25F/qQqHE?= =?utf-8?q?hF6bBmxbMFAv3kNwfd0XIuPcRdHZcDWtlyH0sq+9+TV+s6ePhcIyEpt3Tr9IZzDLX?= =?utf-8?q?ZwewG4UKrfP2yi+N6HUiNVMTnMaagDLo5spivxJ5AOnKnhTMqt5joiLOVcJlslaFm?= =?utf-8?q?eugWxzFvzqc2s8zOvqQKOA8D3gfl3Mq/jOwP6RCN2ZowjNrIm0Ac8iCGvr3KtnoyX?= =?utf-8?q?4xuiOFdianb+AmZWHlti7seChMNRm3f2onbHl1A8U8OQX7Z9A1KKJrUl3fBkqeiKp?= =?utf-8?q?RTufneq94BnMLbuG3Jkpv2gaEjKt5IblKFQ=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)(376005)(1800799015)(366007)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?VtInfSHKHYQ7iQZBlQPxyQ9qn6AZ?= =?utf-8?q?Iy1tMOD4bSGEsggYW15WwCH3b4IMtd9jEZo1R24/Qyv1+2V3Zz3q61qRkph43GQ6l?= =?utf-8?q?MPoSzyDbzTuJhgLb/fEe4h08ipHRPD2eJvpRBhZJH0R9o41KhqWvdan897qmBSXx0?= =?utf-8?q?b8OgFfF1o6rjTNwyQhns9QPR2NzcCnB82CXUlcwXdKJIklW817mUTmpZkGYl43Lto?= =?utf-8?q?8LANAbC9nvjQ2az4R5ldG/KB3b2SrQpH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Ap9wRTq9jdtoaOegXr?= =?utf-8?q?R878BEXKJ9Lr2Vf7Frz7tKmdHqNRMYRBIS6jzBxMqukMQZZqoCEs/waAScbtSwud+?= =?utf-8?q?GAeJjzzXXvW1ZRaJWQAviAoGLPvQgzDTzMQBKjY7RyLmvnCE2GQBclSNDaw2Cuc1u?= =?utf-8?q?fpJZQCC3QKOS/ayimgZcXRG0QNlDGZF2NsNVrQB20eeba716R/G2ho1kmTb+9zppU?= =?utf-8?q?QImf92Ywci6HOuzosXV2vkb4csdN+N0wJZIZMBptJnSK1/2uuZe5QDB6pNSmiZkmE?= =?utf-8?q?ixN+/cBX3EX/ti1rVHPyS4rWWN4YQQZWETTevt8h1JZQqw28tRuhRXPrKPTvbFZ9O?= =?utf-8?q?ha/vutDNSQHYFTFoLmykG7E3PCL27Q+v5Mo1THgLL93XOWJOeixE6evzLRII/De7X?= =?utf-8?q?BTLqPbTbqDbIO01Vj8P6dTZHZc0AZt4FPYE5VmDG7pUojKiw9Q5xyQY=3D?= Content-ID: <63288BA5FA2A9F4DA5AD9E1A135B4E08@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: 29129a78-1818-429f-bd51-08dc83926324 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jun 2024 05:59:53.1208 (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: O4fKFbPblmN1FNJ6P1n16ZzKebr1t6vP8P4ScWmWModbTa0VpTHyAqZn5sdMJLw4Yj9UMcS+sU8I5gycDl1bMcYi4PohCXwfxrueedvwIIpybmi+4r5hm1jQ9h7C69zk X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR07MB8192 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 56ef48780f..0ced7c33b1 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; @@ -1888,6 +1906,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 49f1cb2c38..d9d66ae2e1 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) {