From patchwork Mon Jun 3 05:59:47 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: 13683281 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 1B9B2C25B75 for ; Mon, 3 Jun 2024 06:03:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0jd-0006gA-SK; Mon, 03 Jun 2024 01:59:57 -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 1sE0jb-0006f7-Qu for qemu-devel@nongnu.org; Mon, 03 Jun 2024 01:59:55 -0400 Received: from smarthost2.eviden.com ([80.78.11.83]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sE0jZ-00072M-RV for qemu-devel@nongnu.org; Mon, 03 Jun 2024 01:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1717394394; x=1748930394; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=acc0XnlBTdWdElPteZmm/CA3s/ptFk3pV/0xf9UxvH8=; b=uKMPl2HqthknXeq+41F/P47bM9xcsfjrUTJOe8H5GdZZyzSaV1gR6obH H6AgP1k145Ac9v18HSFTh0UtrRHPFFKWvWlwb8QId6e72KJu4Lo2qTIER Wo7bUCWOjlEvVrpfCAztm4erId+9Ixy0GmxcRiDU3QIC1WU/drTwtD5Mz g3wgkjF6dOOMjsFafgwJvCLjVSMKLPXqu3yrJx3rceTovOkgj3UERtUTT lpBGfAogx6rh/wN0u3ZfenAK1eYz9uVhtaoPdMdRJu2xsr/OThjzdfOyd j/QZc715R/TrZKc8AJ5F2iQNtgz1SDC/kVwuHeNvPK9LN1P3mQVZFQ9Lp g==; X-IronPort-AV: E=Sophos;i="6.08,210,1712613600"; d="scan'208";a="13763240" X-MGA-submission: MDEyFvRha8IsJXlP/gqwAblC3FzKbidQSdwk4FuY/W+YTr+9/S5wsLs3Pod4G78HrdyvwOaDLAHPrHq6bqM6W8yM0WmzQxZflNEaL8my9Z21PcOtEO2nI++nCHQ8HK8Kx39qyevVBVMUptqBjJuTJ7gDT6xeQAfkR1g7G1WUkFO+JA== Received: from mail-he1eur01lp2051.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) ([104.47.0.51]) by smarthost2.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2024 07:59:51 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OkQcw5RavQjBkbVsa9pUSQoKwU4NJkUFs9jlh9857EgE0Z/3l4zC0EMYFkmFvCKwvWilSP3eoYpIGxSn+lJxg1cfhNAe+SW8YMiSE6NZ2lMF3kC4FlxUig4yKtzlKO8UkfNS0Wjl29WMQpK99JnLCBsUfN9g2yYo+eb5rF+VTMnSHq+scQGvoejtMQvmhqxEfENzn6+8++v4eCOTosI726L+M0mhdyh0LiGmarf8TDP6yokH0c7b02ofBNBkcbsldCZn6egdy9nqOwDmj2IJNfXeREvINUDE9Pqov8Vf9mNCJ1/LyC+lb3qqrAjcKWrof+Dxl98wn0vxWb5es6ow9w== 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=acc0XnlBTdWdElPteZmm/CA3s/ptFk3pV/0xf9UxvH8=; b=hraPycEsjMYjNMcn5APBafZv8x7gjyEsXUJ76NBqVK9e/Bju3HnBwfkUQkax5bnLPMIN9GZsc00m37yGomJaSZYo5mcVylZ49u18yCKyiGeZgdOrm/xQyV3c8yptYqgkr27hgrnaAWdH8Ae2CPLhnU5BmCjJqN+q9GVK5s/+w+CH6ZnGrnuac4Mx2SlbCJL2w2R3PQH0JXc36oLKtbKOPeear40x/sWfbKqEpqidPUG7fwjNYbFsSaFInU2KiEUnFkABP8aXICLiNXzmaUW6+a6z1nVB5XsWZattQ+MR9WQ0fqtGKGvMat8qIXBmNSqfEjPESwHi7RrjIZD6wXQI7g== 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=acc0XnlBTdWdElPteZmm/CA3s/ptFk3pV/0xf9UxvH8=; b=pH0ijjeEtBmx0o8UJavljH+9OaRocCk1rX21rAN+ERWliuNkXLsILrKt4uYfio2vC6+eYWyd1zmFZfwqyumrjYG9RRfcoHUTs5Md1o7iEjLR1GhThU41xtss8uHVkTloj1ysMFgQmxNa9CPgp9EBuT3hgYtG690P/Iq7o0LLSYxbzvw2dhMF777brLcaddiMilkwDYae/EHvLli+U2w8f+yEIK4H0haWYeiW6OQLhHbsrftLIUEIrsthxhokQkIrhiWJUBbNC+gufDrB2SvfTcBXPJYPeAl3z/MiLzuTc9N8Jai8m/phhmbXnizsIAUU/3ePOtDy5k2po35f7J5+BQ== Received: from AM8PR07MB7602.eurprd07.prod.outlook.com (2603:10a6:20b:24b::7) by VI1PR07MB6238.eurprd07.prod.outlook.com (2603:10a6:800:136::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Mon, 3 Jun 2024 05:59:47 +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:47 +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 10/22] pci: add IOMMU operations to get address spaces and memory regions with PASID Thread-Topic: [PATCH ats_vtd v5 10/22] pci: add IOMMU operations to get address spaces and memory regions with PASID Thread-Index: AQHatXs9KwLmXjyVvEupV37REpL8HA== Date: Mon, 3 Jun 2024 05:59:47 +0000 Message-ID: <20240603055917.18735-11-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_|VI1PR07MB6238:EE_ x-ms-office365-filtering-correlation-id: d5d58363-0ddd-4808-2a04-08dc83925f9d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|376005|366007|1800799015|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?BP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TdscBSOM/383Kjw6+R/1GLZow0T2arQG?= =?utf-8?q?vVvlKs5uUECrSjJduB1PAKdtjRReL40Qrgqwc4uMkEhzAB8BUo8voJgOtbsiKcbJ3?= =?utf-8?q?ZMryL/wKHH4qL+jGy4xx1zKi6lEIFuxsp6nO8Bx/SSFtjDD6K4Z1Vrun1H1/5Bc3u?= =?utf-8?q?rsFEmNPZ2NJGsaI45UhwWYyxKjst2jeoqjBn/nqR+xTy33nXk5FsOYMT0F7PtTNwF?= =?utf-8?q?rZlFvm5pZ+4BjuxctasWwJTWIgQ63GkTaGXlNc3dkuRIHKKdoGmea/vuyOjA4a6F3?= =?utf-8?q?PNSIUmsDcu0+ZQcsd2+ZpGjE4hzXp4NTGdILArNnEVMg8z4E/Sau+45Tva/PNPopo?= =?utf-8?q?ZvnlVyuwdCQ0bgeVyZUbkFTmwKFrvX83Kkz2iCmxBtO039FnTCIC6B98Tp9/5bj5z?= =?utf-8?q?8B+GAspAQ9UyBnkdTvKaYbx/4IA6xWJ67DA=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)(366007)(1800799015)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?XB5MWw/ELla0bPYmG6Pwmj80VbIj?= =?utf-8?q?l7vii5eHgAjpI9nZmgbTKOtnQ5os0vonAIDYbUpMHEqNQ5gB6KGmy0G5h6dn8MKpX?= =?utf-8?q?CTtaa4Gu8/0nvKICeFW7Xu/adPqv+/FwE3HjtY/jaHdbsLvOgj7bjyq3FSWGChx7F?= =?utf-8?q?JZHjRZ+jhxBd840XgUn86RaMbqtMS2NJhgUlponsaxvLQZz/TgloGE3TeGaMHEXrN?= =?utf-8?q?7P/KYW90G029NcWD6VczY3n0uX/6hWfs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DzcvR5ceuXF9yE2s5Tryf8V?= =?utf-8?q?LIGcofoAUuenueCS9Lr6luyDmyfxGU3nWqgmb7uuV2PEvXjy1m4+9qojMYtsniWwO?= =?utf-8?q?cPl68obrPoSBwSdjpMj0inPSuZyJi1RVe9nzfXpnfv6w/YLZs/xq053jUa7qwob3V?= =?utf-8?q?fv99MiLFw9ux6QaUn0SSpq8hfkY4oL7knYnbsOD9JKb0NpNupwrlRrulkv8vPWNzo?= =?utf-8?q?3s67Dxw142gitx/HRdcJTvZctSyTcIhmZiROgPFg7N/YhmvHU27PpwbjqHc6+QHkn?= =?utf-8?q?CSg4B3JmdpwaQKUSGyuIrhjfBhaLezOkIXii+omOVBGXDiceYqkeYuoH8ufyAmOTl?= =?utf-8?q?6FFdtUasOCVUketPOVi23c3CultrUCgk9dkAZ0LpAFcdAwJKKfdZB6IyCqb5b6zTy?= =?utf-8?q?bYt5Gs/QyF7gTndQ9VjmYytMG07dCgLgGjyu9lt6Zq6/4nn9ddDFH88=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: d5d58363-0ddd-4808-2a04-08dc83925f9d X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jun 2024 05:59:47.2109 (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: WEQYzi64BlfSRPu6wgbsZVHKXZ/3l6qV8P5qxjCIiTfILRGCeU2Dqr8U574cFQu/+EfVk2j9MEn3a5AmeTDOJMh/r86tar59iOHeBaRtsyf4FTfEgIWhYC0DbjeC1bCm X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6238 Received-SPF: pass client-ip=80.78.11.83; envelope-from=clement.mathieu--drif@eviden.com; helo=smarthost2.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 Signed-off-by: Clément Mathieu--Drif --- hw/pci/pci.c | 19 +++++++++++++++++++ include/hw/pci/pci.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 51feede3cf..3fe47d4002 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2747,6 +2747,25 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) return &address_space_memory; } +AddressSpace *pci_device_iommu_address_space_pasid(PCIDevice *dev, + uint32_t pasid) +{ + PCIBus *bus; + PCIBus *iommu_bus; + int devfn; + + if (!dev->is_master || !pcie_pasid_enabled(dev) || pasid == PCI_NO_PASID) { + return NULL; + } + + pci_device_get_iommu_bus_devfn(dev, &bus, &iommu_bus, &devfn); + if (iommu_bus && iommu_bus->iommu_ops->get_address_space_pasid) { + return iommu_bus->iommu_ops->get_address_space_pasid(bus, + iommu_bus->iommu_opaque, devfn, pasid); + } + return NULL; +} + bool pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, Error **errp) { diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index c84cc9b99a..6c60f7a7c5 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -385,6 +385,38 @@ typedef struct PCIIOMMUOps { * @devfn: device and function number */ AddressSpace * (*get_address_space)(PCIBus *bus, void *opaque, int devfn); + /** + * @get_address_space_pasid: same as get_address_space but returns an + * address space with the requested PASID + * + * This callback is required for PASID-based operations + * + * @bus: the #PCIBus being accessed. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number + * + * @pasid: the pasid associated with the requested memory region + */ + AddressSpace * (*get_address_space_pasid)(PCIBus *bus, void *opaque, + int devfn, uint32_t pasid); + /** + * @get_memory_region_pasid: get the iommu memory region for a given + * device and pasid + * + * @bus: the #PCIBus being accessed. + * + * @opaque: the data passed to pci_setup_iommu(). + * + * @devfn: device and function number + * + * @pasid: the pasid associated with the requested memory region + */ + IOMMUMemoryRegion * (*get_memory_region_pasid)(PCIBus *bus, + void *opaque, + int devfn, + uint32_t pasid); /** * @set_iommu_device: attach a HostIOMMUDevice to a vIOMMU * @@ -420,6 +452,8 @@ typedef struct PCIIOMMUOps { } PCIIOMMUOps; AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); +AddressSpace *pci_device_iommu_address_space_pasid(PCIDevice *dev, + uint32_t pasid); bool pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, Error **errp); void pci_device_unset_iommu_device(PCIDevice *dev);