From patchwork Thu May 30 12:25:03 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: 13680348 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 64E51C25B74 for ; Thu, 30 May 2024 12:26:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCeqO-00073o-9B; Thu, 30 May 2024 08:25:20 -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 1sCeqL-00072p-RF for qemu-devel@nongnu.org; Thu, 30 May 2024 08:25:17 -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 1sCeqH-00060c-3F for qemu-devel@nongnu.org; Thu, 30 May 2024 08:25:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1717071913; x=1748607913; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=/KNC9YlY5dCStxnGJESvt06kpnylow9D0BXt0DFqGPc=; b=mCM2Vo+EUPllv77ox8NlC06wXaoor4vRDaUk+Nfjd5LB+z87JmeiKN9+ V0kE2GCncucyVkIxFArzapp/IXDQGG6/ZcOgvBxIGhZfcndoY265uANCk JVal2dBhIvivfCYEtxiEIBA+r8L83YnUpxg5KdY5MReokz8qhAP4tb5G7 g+hjvukmJTR6uWksHeul/jagT/7yL4copq7MrQL4ro/JD0vlk521D2Y0U DIJgjPPVkCsC94Uz5jZsCQMDOIWHdiRUcA14knUn7SRimq6zQp1Cl9abP l0VVxAKGEsRYa2oCzRCegS2KgtdB/EM+pPr8ehEOY3/tt9VwUuSzxIFxO g==; X-IronPort-AV: E=Sophos;i="6.08,201,1712613600"; d="scan'208";a="13581115" X-MGA-submission: MDGjkgWSbnOmxXEr9n3nj4xnTvOvTz++DNMLrrI2i7mIkF19EKy9SLv2BwvdW78SzO1Q/OmMHDlY8tnoy9HcXJtZTXXyoIoZJfSnNyKgWyaP24k4gtU8YXIvqY06EaOZKFiTWLQ+XLxohd0xrgclD/pBb389T5wCGSkdqdynGg7kNA== Received: from mail-he1eur01lp2051.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) ([104.47.0.51]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 14:25:04 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bZ5p3tfQWys1jZkUX7RRszpJE4NXAcG4I/Yo9V4exvzk45RDIcCkOSwOQ09sAYbnuBxJ3+P/kapwMt3IK8LreGMd73pP0Wc9ZJLnyAVdSQsXUinO2gJQZePyuPtXkikY5DmenoTVFNg9Kut3qxVzielCyvMJWp15s7TnG1MKH8VoPNR57wHxAHTjCCn0Bt/6cVPp0YIBmTSegEzbXu89ZSP5iAw6ab3vA9JISXjRW/xBkJvyFSdF2eXP49wdU5X8xjsx4J3P5sXgXjFTEZvi2XVmDN8b2KHl7+zBpxNpl8PBtjAbiMKrPkEgMVOlv8nM3xlujnA0FxoKuZ8/gykatQ== 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=/KNC9YlY5dCStxnGJESvt06kpnylow9D0BXt0DFqGPc=; b=fxKdN0N1/EisrjBTWI8XLjXttiGH0fdlUW4quCNNiL4/okzn4hHe0wZQQVj5vujuRFaPRtrmk6pfV/dNqbbzOy4jo30XKsL7tF6A1Y6+m+XqLMEFBGvqjIx+MJRTIXR2KVRjN6gG+vOGtJ+l3RpNNk7a45dvu0/+DyxVL2PX3Ox7Q2krsw2kwzdHxO6vOdJZW2t7AY4gPO17WzaACjSlPx/4XJrYMzoG3z+oxdGzIeVdaWAd6fNHdJ2/bfIMFCggkHGj5z1d4Kcg+mm1O1+5+MIi9/EXrvWBEhN1LTlPwC0v9ZyqE4aFtDyzc83w9n6IUiawgnpC+ex2S7xkp1M+pQ== 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 AS8PR07MB8069.eurprd07.prod.outlook.com (2603:10a6:20b:358::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Thu, 30 May 2024 12:25:03 +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.018; Thu, 30 May 2024 12:25:03 +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 v1 5/8] pci: add a PCI-level API for PRI Thread-Topic: [PATCH v1 5/8] pci: add a PCI-level API for PRI Thread-Index: AQHasoxlDbCdNhpNy0WmSlq+hx398A== Date: Thu, 30 May 2024 12:25:03 +0000 Message-ID: <20240530122439.42888-6-clement.mathieu--drif@eviden.com> References: <20240530122439.42888-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240530122439.42888-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_|AS8PR07MB8069:EE_ x-ms-office365-filtering-correlation-id: 020b8aaa-8221-451e-cc68-08dc80a38828 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: =?utf-8?q?3RXjLkjDIxd0yBSV0FsUe0s/ga6hR+j?= =?utf-8?q?R0q5oJEUuZkxK3iDLKAuHYi260mwOSPkP9OW1BdXXN9MtUDEUU7SvuEf00kIujUGD?= =?utf-8?q?qak3x0BfFj6HJoxF+veaL+FA9iolJgwwkD9SUEP0CfmHPQDMKfwKcQurXrIEl4uIn?= =?utf-8?q?tl8pssG2luHJ6KBn0XkSa32NEtpb3n/iUCjWihs5e+VQOVEzktS9yeOeo//V8UmGf?= =?utf-8?q?DllDEXG87OUAcuyRruglrTc0rW4qoCZsEcpopTKyhg7aoqiFyeniNeKGDdso5mwwt?= =?utf-8?q?TaFz31ua9NIMgO8wOr9MKrdyh/gA5VyUVute+sS1Ifk3S6DfH/0AMpabpw3dGRHab?= =?utf-8?q?Lo3dYa8V5Dmq/W2fyvoZWgXtub6b+SJkbwZ3OEMiUSPUvV4iKtH9PgjaJyJHExdQ+?= =?utf-8?q?Xg8QygERXoyUDPs/Q43AcIE4slx9PpA0GuijB3Rql7OVDDz5xk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: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?RQMmiXJRAPJGw6Bxb7M95Qppy5VJ?= =?utf-8?q?/Rqpo+2X3vUlmKO0IRbMeZL8vv7YV3Yybypt070Y7qyzBhBBnsSvclfM0XjE15Tcp?= =?utf-8?q?TmLubfowHhupf5Po94KnqZsfxvpwqGDDmz63BEtvoo+OQV23R3GC1UXiM48gjjU9x?= =?utf-8?q?h8EMFTfawp7QtQqPt+A91DjFmRn1qj5TObLTdby4FHQvRjejp+UtHpPeuVtK9Iz5L?= =?utf-8?q?ym5zNQV4TsciAvtJmJlZ/YbbZdjFbMUWWA9bhGz4bteqjOE7HrshmRjBLOPvlAdFy?= =?utf-8?q?NV7BtRwJ+ApZ2wTJfs9NT1MdCSSTAhTPPnibicslWpTpe4D/I/7cGk1GU5Epd0jqN?= =?utf-8?q?V9PoaRvgHUZDsFxxn6V32hce0zBj7BvvqhiQ72ZrGaBR7m/wd/UF+Mw04UUzewCoU?= =?utf-8?q?JatKYFW72AulGPMjjwW+P7a779ABmGIto0WCZp+th64yA08vaH87y1yjn0CfVvs6X?= =?utf-8?q?9DJbQKmTcQda2v2MCTuYATj2EV2FJ7iQbu5H0Znmdt5pajaQ6ftbLxRHMIICzrTJA?= =?utf-8?q?4vXysCbi73AOMTfVMazfjDD5zRv/OT4vNSp/s3nrcZKb8Up0hytKH5QcoHyG+wCCy?= =?utf-8?q?bQ33xCl05EdfPsDQWS06ZppDXKJyXpnDWCTdEo+wWl2kpe5A59WMzq1KQMLqYUBzv?= =?utf-8?q?1ykJiTOCAMkT51+9CE0/I0A/+uEUm3mji0w+PHNlXEKTXFDoxhzdp/YWvHJyCPWaT?= =?utf-8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B5836E2F704D91A22E38E442386F@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: 020b8aaa-8221-451e-cc68-08dc80a38828 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 May 2024 12:25:03.1956 (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: VOeU5bDG+bE7EsRvy3pmnDMZZ3/dPVBLT1u+uxXBzVzlegbseBDmfORYnXRcS7EsjSH/UiNizpKl1rDRBF97EPbdFjj2zW4qgU3ZHk/WDmVQnGOCE8rqOnWt8Jcxzi+P X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR07MB8069 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, 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 A device can send a PRI request to the IOMMU using pci_pri_request_page_pasid. The PRI response is sent back using the notifier managed with pci_pri_register_notifier and pci_pri_unregister_notifier. Signed-off-by: Clément Mathieu--Drif --- hw/pci/pci.c | 37 ++++++++++++++++++++++++++++++++ include/exec/memory.h | 35 +++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 45 +++++++++++++++++++++++++++++++++++++++ system/memory.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 10b0708130..dd854fc18f 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2833,6 +2833,43 @@ void pci_device_unset_iommu_device(PCIDevice *dev) } } +int pci_pri_request_page_pasid(PCIDevice *dev, uint32_t pasid, bool priv_req, + bool exec_req, hwaddr addr, bool lpig, + uint16_t prgi, bool is_read, bool is_write) +{ + IOMMUMemoryRegion *iommu_mr = pci_device_iommu_memory_region_pasid(dev, + pasid); + if (!iommu_mr || !pcie_pri_enabled(dev)) { + return -EPERM; + } + return memory_region_iommu_pri_request_page(iommu_mr, priv_req, exec_req, + addr, lpig, prgi, is_read, + is_write); +} + +int pci_pri_register_notifier(PCIDevice *dev, uint32_t pasid, + IOMMUPRINotifier *notifier) +{ + IOMMUMemoryRegion *iommu_mr = pci_device_iommu_memory_region_pasid(dev, + pasid); + if (!iommu_mr || !pcie_pri_enabled(dev)) { + return -EPERM; + } + return memory_region_register_iommu_pri_notifier(MEMORY_REGION(iommu_mr), + notifier); +} + +int pci_pri_unregister_notifier(PCIDevice *dev, uint32_t pasid) +{ + IOMMUMemoryRegion *iommu_mr = pci_device_iommu_memory_region_pasid(dev, + pasid); + if (!iommu_mr || !pcie_pri_enabled(dev)) { + return -EPERM; + } + memory_region_unregister_iommu_pri_notifier(MEMORY_REGION(iommu_mr)); + return 0; +} + ssize_t pci_ats_request_translation_pasid(PCIDevice *dev, uint32_t pasid, bool priv_req, bool exec_req, hwaddr addr, size_t length, bool no_write, diff --git a/include/exec/memory.h b/include/exec/memory.h index f4780d3920..71bdd7e64d 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1870,6 +1870,16 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, int iommu_idx, IOMMUTLBEvent event); +/** + * Notify the device attached to a memory region by calling the PRI + * callback (if exists) + * + * @iommu_mr: the region in which the PRI request has been performed + * @response: the response to be forwarded to the device + */ +void memory_region_notify_pri_iommu(IOMMUMemoryRegion *iommu_mr, + IOMMUPRIResponse *response); + /** * memory_region_notify_iommu_one: notify a change in an IOMMU translation * entry to a single notifier @@ -1944,6 +1954,31 @@ ssize_t memory_region_iommu_ats_request_translation(IOMMUMemoryRegion *iommu_mr, size_t result_length, uint32_t *err_count); +/** + * Register a PRI callback in an IOMMU memory region + * + * Return 0 if the notifier has been installed, + * error code otherwise. + * An error occurs when the region already has a + * callback configured. + * + * @mr: the target iommu memory region + * @n: the notifier to be installed + */ +int memory_region_register_iommu_pri_notifier(MemoryRegion *mr, + IOMMUPRINotifier *n); + +/** + * Unregister a PRI callback from an IOMMU memory region + * + * @mr: the target iommu memory region + */ +void memory_region_unregister_iommu_pri_notifier(MemoryRegion *mr); + +int memory_region_iommu_pri_request_page(IOMMUMemoryRegion *iommu_mr, + bool priv_req, bool exec_req, + hwaddr addr, bool lpig, uint16_t prgi, + bool is_read, bool is_write); /** * memory_region_iommu_get_attr: return an IOMMU attr if get_attr() is * defined on the IOMMU. diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 8adba6af97..76a6031d8d 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -473,6 +473,51 @@ bool pci_iommu_init_iotlb_notifier(PCIDevice *dev, uint32_t pasid, IOMMUNotifier *n, IOMMUNotify fn, void* opaque); +/** + * Perform a PRI request + * + * This function is intended to be used by PCIe devices using SVM + * + * Return 0 if the PRI request has been sent to the guest OS, + * an error code otherwise + * + * @dev: the PRI capable PCI device + * @pasid: the pasid of the address space in which the translation will be made + * @priv_req: privileged mode bit (PASID TLP) + * @exec_req: execute request bit (PASID TLP) + * @addr: untranslated address of the requested page + * @lpig: last page in group + * @prgi: page request group index + * @is_read: request read access + * @is_write: request write access + */ +int pci_pri_request_page_pasid(PCIDevice *dev, uint32_t pasid, bool priv_req, + bool exec_req, hwaddr addr, bool lpig, + uint16_t prgi, bool is_read, bool is_write); + +/** + * Register a PRI callback for a given address space + * + * Return 0 on success, an error code otherwise + * + * @dev: the PRI-capable PCI device + * @pasid: the pasid of the address space to install the callback in + * @notifier: the notifier to register + */ +int pci_pri_register_notifier(PCIDevice *dev, uint32_t pasid, + IOMMUPRINotifier *notifier); + +/** + * Unregister a PRI callback from a given address space identified + * by a pasid. + * + * Return 0 if the callback has been unregistered, an error code otherwise + * + * @dev: the PRI-capable PCI device + * @pasid: the pasid of the address space to remove the callback from + */ +int pci_pri_unregister_notifier(PCIDevice *dev, uint32_t pasid); + /** * pci_ats_request_translation_pasid: perform an ATS request * diff --git a/system/memory.c b/system/memory.c index d9d66ae2e1..105c02b686 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1765,6 +1765,7 @@ void memory_region_init_iommu(void *_iommu_mr, mr->terminates = true; /* then re-forwards */ QLIST_INIT(&iommu_mr->iommu_notify); iommu_mr->iommu_notify_flags = IOMMU_NOTIFIER_NONE; + iommu_mr->pri_notifier = NULL; } static void memory_region_finalize(Object *obj) @@ -2025,6 +2026,45 @@ ssize_t memory_region_iommu_ats_request_translation(IOMMUMemoryRegion *iommu_mr, result_length, err_count); } +int memory_region_register_iommu_pri_notifier(MemoryRegion *mr, + IOMMUPRINotifier *n) +{ + IOMMUMemoryRegion *iommu_mr; + if (mr->alias) { + return memory_region_register_iommu_pri_notifier(mr->alias, n); + } + iommu_mr = IOMMU_MEMORY_REGION(mr); + if (iommu_mr->pri_notifier) { + return -EBUSY; + } + iommu_mr->pri_notifier = n; + return 0; +} + +void memory_region_unregister_iommu_pri_notifier(MemoryRegion *mr) +{ + IOMMUMemoryRegion *iommu_mr; + if (mr->alias) { + memory_region_unregister_iommu_pri_notifier(mr->alias); + return; + } + iommu_mr = IOMMU_MEMORY_REGION(mr); + iommu_mr->pri_notifier = NULL; +} + +int memory_region_iommu_pri_request_page(IOMMUMemoryRegion *iommu_mr, + bool priv_req, bool exec_req, + hwaddr addr, bool lpig, uint16_t prgi, + bool is_read, bool is_write) +{ + IOMMUMemoryRegionClass *imrc = memory_region_get_iommu_class_nocheck(iommu_mr); + if (!imrc->iommu_pri_request_page) { + return -ENODEV; + } + return imrc->iommu_pri_request_page(iommu_mr, addr, lpig, prgi, is_read, + is_write, exec_req, priv_req); +} + void memory_region_notify_iommu_one(IOMMUNotifier *notifier, IOMMUTLBEvent *event) { @@ -2085,6 +2125,15 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr, } } +void memory_region_notify_pri_iommu(IOMMUMemoryRegion *iommu_mr, + IOMMUPRIResponse *response) +{ + assert(memory_region_is_iommu(MEMORY_REGION(iommu_mr))); + if (iommu_mr->pri_notifier) { + iommu_mr->pri_notifier->notify(iommu_mr->pri_notifier, response); + } +} + int memory_region_iommu_get_attr(IOMMUMemoryRegion *iommu_mr, enum IOMMUMemoryRegionAttr attr, void *data)