From patchwork Mon Jun 3 05:59:48 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: 13683285 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 BA000C27C4F for ; Mon, 3 Jun 2024 06:04:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE0jm-0006oV-Oo; Mon, 03 Jun 2024 02:00:07 -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 1sE0je-0006gB-5p for qemu-devel@nongnu.org; Mon, 03 Jun 2024 01:59:58 -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 1sE0jc-00072M-6L for qemu-devel@nongnu.org; Mon, 03 Jun 2024 01:59:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1717394396; x=1748930396; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=3iGn8iTNBgQPofEUaGJboBsdoJafrIzD0MJJvX9ZvNk=; b=jvGMQsa072dGf2LQOUtoyh9n0IRX0MY/CqBJksFor2+SDVxoeyuns5bY dZILWau2ZxL0qBVUiJdJlgbFgvUgfNKu2WrrG6yHfuq9v2XbbaELD5YoN eDTi9urBa6jd9xoFAE8tB5Mv1qa6ay+vg+favYSLHxKcdDAWCpY9wETvq uSYOhz7cTrtifP6Ye8j+/0DXRV9W8uvc1u8jr+QzDpd+iWWqh1a7YxBOu gFCdoYu+6hv3xLhmv5NYhN4sjG2r8ig5ZU/tuQIAjp6gMQy+XhYYEaiSY MvTyINKAR2wVdwiKEbAeO9Ri/AvhYJE+Hj69E9I6lttmZW+3u9/JVCPX5 Q==; X-IronPort-AV: E=Sophos;i="6.08,210,1712613600"; d="scan'208";a="13763247" X-MGA-submission: MDGKF2e07mPGcTeH995K0EDXBeG5TS+uvNrQv4gEJbQZctbhJgnT6zdAdoslSNR21fpvMsa5fAaOM/jRz3dmTw3TopwqHbNzFCfFrl212+B+jA/krVtGXINjbOqzhkXZZIxboPnrJCTP1YEWyMxeig/ySoJ4YzcIFdv/0K0cFJydBA== 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:52 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VQvut47cWXXHlJUP1FR6d7m6TI+UqefBobnlz53wfVQREZAWfse+KU+eunVW1oALOUKD/7J4W2aZj337hgZJ4EQQlET2A9UUte9h/QC9T4gm6Y0LDLm1xOWzsTptd6BWPrD1Y0SWSB+BIx+C1pzuLmekK7wZUbaoTl/Zu6EZLJf8Md1eUa2F6rQ/pBWl50vUO5+GxUWiJRuhtwrq+UTpPnldNhKEHvlZgoyr0ZPyBPML1HLTtGQsc5yzT96VwZSCY1ExsC1nHu7NRO1jDmmsV0/1YaBO2j3hI6TU0wCBtitiD0spXP16mHJ3pPiJlBX0oUQKzIln/2KaE/fPH/C0Sg== 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=3iGn8iTNBgQPofEUaGJboBsdoJafrIzD0MJJvX9ZvNk=; b=WBYV69HMqPL93JhI5fvq8PyBXeJF7EqSlBPqC2vnPPXTbtvVbTx2iTVrnkPbIDc8QNg9ZUUdMCnNaTSnPXOmLR5Rdg8+lXHreEHlObAArGSOa+FFIXqXnLwym7kaQIoYkDPxpjmXFShjePG2KFgOXp1tJDOMtLOZgMM23AD6+Y33uNRcE9nYo2KsGRvyDlj0YxPXprybcWtUOmMOxUsHy+FvqQZMWfIGvmyutGR+HHfqpLUsaXUWjOH7/NMflH17k7kaK/OAimYvWLrb8QQo+i/wSle91ucM4jEp2LX9YezzlBFxXSvp/MiGe/LntGy8vl9AQO7XA+0krczGE77BOg== 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=3iGn8iTNBgQPofEUaGJboBsdoJafrIzD0MJJvX9ZvNk=; b=B8YyyqlgZo1UJFQYkd5k1jQT2RNBhEWPzLPysUSvOEX9hYjOHURI7hgdW4HnK0lkfX9GA8E8xRJxUKB6SWhKqpstlreSNiCv7z3/lMxj/LyVjW7PhN3pI5C1L3iLlQTEyJXTv3aCfeBZkshIiAFaIaT2jol6rUXL5+QAXaXqYK2gNReJCW2UlNLXyQkMuK/Lx4e0UnpE9eIcdH9hNG/XXTSkmaSLzuSOyOBEBEgGW9w3HcMiSeUpbdrVbNkBttEvn4eUUZ+YfS6DyNDlMzMLfucAtXabLTudvGegVEnpI9Ou2jR8KOVThXExPlBKd86iTOGpuwBjuuPELhhrCNsTeg== 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:48 +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:48 +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 12/22] pci: add a pci-level initialization function for iommu notifiers Thread-Topic: [PATCH ats_vtd v5 12/22] pci: add a pci-level initialization function for iommu notifiers Thread-Index: AQHatXs9hOklV2j/n0yx4sycS/sVhQ== Date: Mon, 3 Jun 2024 05:59:48 +0000 Message-ID: <20240603055917.18735-13-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: bcfc999d-997e-4c64-daa7-08dc8392605b 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: =?ut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fRQH+8jFv5/PF9XrgghKRrqc5O0K0gZpYNDUa4viljx?= =?utf-8?q?qS6rkDw2yxzDDJ+STwqxpKsRPxwq2f8D1labo/L2pqzihMint/vlYaJlbDTCdnkfD?= =?utf-8?q?RTfX4TWal+kAxC/vZ4nEX4FNdcvfQyzVUw6pdlO5FCwcEjYwibIDeKUnqdUApyku7?= =?utf-8?q?qgjedNtJACPVKOPyEMPnNxlwXlMLU+a7lbXleB2qMT6GaGm+24XkESUGwhTyLa4nn?= =?utf-8?q?5hUqgeB0HiwIHfQSoA2HkKga68cSW9Klbc87eFgbLLnj5+MWMqFBpGlZI3YHzmXvk?= =?utf-8?q?upaMt2AGTqmejlCYZzeOHdtRN9JrblUkLETcISv3Imp9ooWIEyjT3fu3kx5USrGh6?= =?utf-8?q?IzSbjE27sltF8owds/oz9Ox8PrTc1cH4ljrJq/OmUUo0rwsXqEEc+V939eg4g6p66?= =?utf-8?q?NJ3dVFbs6yFHdKiYN5sa2d7gJ5KNVjTJmIg=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?LPBZd+dPDDg2b+3KyC5xUERRjDal?= =?utf-8?q?BMiFTDJGLahUXdGU0KMfMi3euZWI9LzX7w/2v0Lhs6zsykxEzn6CqrgXIsCN0CtNQ?= =?utf-8?q?2u7UWNoJOH6JipIu/vMpfjQSP3PwH6KhTI9GWiNXN5IcFOTys2+6xjGxWrkJbkskZ?= =?utf-8?q?Y+/9N6dGMTBZhtTdtXSfArGYUID2boVU9BfCwE728/15PXT7ovVML7WjiQLQC7W/7?= =?utf-8?q?LNER27TCnBWorKzfBcy5rtGmNxCyZijsnnPAgdDz6soz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ANDIk7jVMzXNV30962zNYly3gz?= =?utf-8?q?RSaD9lQlvLLSnbTy90WQZ0ciLJ+LpoI6C24QtKb57ARwUAVdXhXiQqPevkMMMle33?= =?utf-8?q?hJ4Q5TZwhypZM674NQtStoRHu4nThFukOKLeZ30PIs3e6gjhiLA8RJTx3qHtym+TA?= =?utf-8?q?KPdUC3/JCqUBGbOFUj6oScUiqSHwDaMsFSy4bzyOYA+Y0mEjMNH7VWbBdfs7OAKBG?= =?utf-8?q?4rbueu4Iqi1mifRoW+2kvNeD7KSSDMbcgxndVbcvq/g6+mCohquLZA69+wpD6NnnM?= =?utf-8?q?wN90q2kJecnYYIi7+LdD0st73myax6aR9+1M2LLMlpLxJ1q1cGDqhSFaVu3kJDEdp?= =?utf-8?q?w/pOVE64j8qz7RxRBA2v+rRczhHiJfI4C1nRRkyihchxf3SyueLTYUuNQKCMf6Y1K?= =?utf-8?q?85bi+b+wQq8tgqZB4YyazjJjVovzaDVtAMHZg068lOaFqiRGQP5vdHo=3D?= Content-ID: <9EA5EFDC58048A46BFECDF1F9ABB0802@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: bcfc999d-997e-4c64-daa7-08dc8392605b X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jun 2024 05:59:48.4400 (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: +ujNv+q6SuZMFmReHHzb8cBuuEzNgfQV+UQ/9t9oh6gbzzKZXoWM/FnNCniefq6UK8NskL2ZEZ636tdMaK6r9kGE9uWHwEbkcQZ6RLiCYPIBwbow+fETXdsrMUHAVoTL 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 We add a convenient way to initialize an device-iotlb notifier. This is meant to be used by ATS-capable devices. pci_device_iommu_memory_region_pasid is introduces in this commit and will be used in several other SVM-related functions exposed in the PCI API. Signed-off-by: Clément Mathieu--Drif --- hw/pci/pci.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 15 +++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 3fe47d4002..0e14ef4ab2 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2747,6 +2747,46 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) return &address_space_memory; } +static IOMMUMemoryRegion *pci_device_iommu_memory_region_pasid(PCIDevice *dev, + uint32_t pasid) +{ + PCIBus *bus; + PCIBus *iommu_bus; + int devfn; + + /* + * This function is for internal use in the module, + * we can call it with PCI_NO_PASID + */ + if (!dev->is_master || + ((pasid != PCI_NO_PASID) && !pcie_pasid_enabled(dev))) { + return NULL; + } + + pci_device_get_iommu_bus_devfn(dev, &bus, &iommu_bus, &devfn); + if (iommu_bus && iommu_bus->iommu_ops->get_memory_region_pasid) { + return iommu_bus->iommu_ops->get_memory_region_pasid(bus, + iommu_bus->iommu_opaque, devfn, pasid); + } + return NULL; +} + +bool pci_iommu_init_iotlb_notifier(PCIDevice *dev, uint32_t pasid, + IOMMUNotifier *n, IOMMUNotify fn, + void* opaque) +{ + IOMMUMemoryRegion *iommu_mr = pci_device_iommu_memory_region_pasid(dev, + pasid); + if (!iommu_mr) { + return false; + } + iommu_notifier_init(n, fn, IOMMU_NOTIFIER_DEVIOTLB_EVENTS, 0, HWADDR_MAX, + memory_region_iommu_attrs_to_index(iommu_mr, + MEMTXATTRS_UNSPECIFIED)); + n->opaque = opaque; + return true; +} + AddressSpace *pci_device_iommu_address_space_pasid(PCIDevice *dev, uint32_t pasid) { diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 6c60f7a7c5..2147981423 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -458,6 +458,21 @@ bool pci_device_set_iommu_device(PCIDevice *dev, HostIOMMUDevice *hiod, Error **errp); void pci_device_unset_iommu_device(PCIDevice *dev); +/** + * pci_iommu_init_iotlb_notifier: initialize an IOMMU notifier + * + * This function is used by devices before registering an IOTLB notifier + * + * @dev: the device + * @pasid: the pasid of the address space to watch + * @n: the notifier to initialize + * @fn: the callback to be installed + * @opaque: user pointer that can be used to store a state + */ +bool pci_iommu_init_iotlb_notifier(PCIDevice *dev, uint32_t pasid, + IOMMUNotifier *n, IOMMUNotify fn, + void* opaque); + /** * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus *