From patchwork Tue May 21 13:11:46 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: 13669445 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 47BD4C25B74 for ; Tue, 21 May 2024 13:15:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9PHo-00081T-3N; Tue, 21 May 2024 09:12:12 -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 1s9PHX-0007j4-Il for qemu-devel@nongnu.org; Tue, 21 May 2024 09:11:56 -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 1s9PHV-0001ZU-9j for qemu-devel@nongnu.org; Tue, 21 May 2024 09:11:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1716297113; x=1747833113; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=8GU03lMLg26o1svETtJlIBqEUa69Gidx+p5JjCEJw4o=; b=pNYY1y+svE8M0v3ADhYd3OoSBY9IaXGN1ZNgVkpr11v/Nk2Z8ACgo1+6 uxjjOWmWh5YI2DevxVbcq28UfAu9g8wUUabakvhiktg/qWaHzdqFOtXqW 2jmaI1P26x0xt17MxSL5KML3Mwo3WnAH95si7H0ENs9BaH9ZQeA9m22HK E7RYXLhIlDBhyham9BEwkcOLd2TOpmV6KxaxS7SrQNH6DJueBbh1d1clS Cb2Ent2Zl2FZTbwWCQfWG8Oqv26OyfW3Sg2TEVxHmpNk1w9dtBRJQw7JN +FVH1E8+xskNPx4NMjdKxpVjyzeoydHzFkfAgNdEMGVbR3lT8jNZYMSZK g==; X-IronPort-AV: E=Sophos;i="6.08,177,1712613600"; d="scan'208";a="13008001" X-MGA-submission: MDG9qdn3Uyn/Y7UYQZwolynDeoy6s57ew4fIMErye0JCeA64twQk2W96vDNTdcaBh5X5e/C521o3x6/8j1UlEoeZ4tNz4qyqbebNeBsADuFBkgkQ3+xVsaApJjpNnfOYV1+dJYlrSl1FCY85yd3aNokIwxQk2JSMVnpyzFUZKgYjyg== Received: from mail-dbaeur03lp2168.outbound.protection.outlook.com (HELO EUR03-DBA-obe.outbound.protection.outlook.com) ([104.47.51.168]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 15:11:47 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XONUUh3ILGm9RX0Fq6QAv2u4BKP5VIbl/zqY82nijyZJyjVq9kMLgANPuaEgqn+a5aC3n3IYuKaCxx9ylTpaqxZNBFistEF8chFhCEY91S8npzGha72c0q4JqYXu/NKKKqa4rzgC+NA9Ov+ME+caQyQYy8viOfHI53iYHeYkfcEPbXGl8vqapjc/vhjfxqG5cMdHoyXjKJgRmppiyUnDccSsWASYahSRLdFQUt2skyi7JEm9pgHmyEN9izSIPr/21FQSy/ohUDOfZispv03Cvj/jtsTHqTcSnLIiuRDhJ1j2KuFKediZcoM3pFFjhWRhE+xS5sCbimTbvbWghN1jkQ== 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=8GU03lMLg26o1svETtJlIBqEUa69Gidx+p5JjCEJw4o=; b=f6js85/VWNiG164qr4NV0QxstjR5ftbav/Yxztd7l+BqSwGCLcaGfRUe+WuU0hdBik9gfH/NJQ9NDB2es5GY47grUnDKT/uS3+U2h3FinoQIXBSNttnr17mafZre6V7vc6H4P4aLQ4sWwSxThwJ2M5V+8EdRK8fvqYqCGUsUiCRTQ0liMATZBh+K3ktd2zGL0BKzSBqWurKYncztwmgCfUnP7F0bEBFIE9ZqZ+ojjePHRUWP8owBbC4y7UeRLNchRGHWMjS2YXM5O85Xw5VQzRBSHZUyBjTuVswPOAK8TKLKg0MgvAwEbRiUaffwDs5yE0mxmcH/3JPsxEFCcv2S2Q== 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 DB8PR07MB6249.eurprd07.prod.outlook.com (2603:10a6:10:140::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Tue, 21 May 2024 13:11:46 +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.7587.035; Tue, 21 May 2024 13:11:46 +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 ats_vtd 12/22] pci: add a pci-level initialization function for iommu notifiers Thread-Topic: [PATCH ats_vtd 12/22] pci: add a pci-level initialization function for iommu notifiers Thread-Index: AQHaq4BuIH0I4A4DJUyHT8GkQmNaSw== Date: Tue, 21 May 2024 13:11:46 +0000 Message-ID: <20240521130946.117849-13-clement.mathieu--drif@eviden.com> References: <20240521130946.117849-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240521130946.117849-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_|DB8PR07MB6249:EE_ x-ms-office365-filtering-correlation-id: 74c113ac-ce04-4578-13e8-08dc79979122 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|366007|1800799015|376005|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?a4le2eXC+PDt5J0C49I+2Is91Ga5yIS?= =?utf-8?q?s9foRKqcvKIv1HFUhDWu2AK9enN1MpzUZVzwiSUP7cakFiwUb0iCZ53e9SZvb/TjH?= =?utf-8?q?u7lhDDytbQ1vipyQ7D1075RhpAtL4CTaTDXucWog7fV7yuuvZD0rd2XcSWO8NnrB5?= =?utf-8?q?UmS/5YFttw7j/yIFdtx997PZgpkQpcm2XJ4EKDVVcriHk0Gd5+0pJ2DrKbXbwVBdU?= =?utf-8?q?YZSjnCGDBscFw9Y7I2OBIGlMPUiYVwjO1FY/qZkGHwVfSufwmcsd6vvc/Ai4fHY8U?= =?utf-8?q?w5s+ajjmkIZw30AcAunVPYSy09+eQJIMmBiTm354dd5Hln5lvnUmZU9y2E1ei4sOf?= =?utf-8?q?BBID5c8aLmMwp4DALczMCysEBupK2Wz9tK2m4bLPdmeaXnwdL+13h3ZacQqwTcCaU?= =?utf-8?q?a/0juP7DE8kqPpJh9JTkmhzKFh6CSLH49y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D=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)(366007)(1800799015)(376005)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?9gQ2lzLCUoNzMQrHeEbWOfB6oho/?= =?utf-8?q?ddq9zaqb9huiiQiom+2RZ0aJKOe3h18ANTSpSVSKTj+o7bVhiSZSDy9wa0dcLhTx7?= =?utf-8?q?uD+Bwuq+anCR7eMLN+orDjGTUbu0ERt215crWOHlW9RBJWWuWSyazGLypV4AvHrGt?= =?utf-8?q?tm+qzECWCR23xKMmj/F2vyLa2aV3pTNfxfvE3FEUTrIuSt4RM5oXEp+hOoPqRq7xk?= =?utf-8?q?5i69CoUEcezJ49QoBTaETCT5Rm05h+QFxxKLSbJFUM/MsJ6dLBg9+ddLc14ARUr6c?= =?utf-8?q?z7x4eFA3l/hqrLjoGs3o/09uRJXr7BlAFIvAla/OXBDzr/fF/1CohLVndTEnfQlal?= =?utf-8?q?eUokW4cglV9n+fH81g8eEAtA0fytzdiNHQ1KORnfzpkua/WQ166OfTYEEA1Fd6yFW?= =?utf-8?q?sH0lrd2NgvFHFZ6z5ajLRySYUs4E7WLaYF17Uhagi6UWwzjSta9N8SlEspUkqvGUF?= =?utf-8?q?kM8PcU/11QWa5Nu1P4mdowMnEOj5nj/nOeMNiWWAt18Zwc3ypbOsJ1E4723fSUtAi?= =?utf-8?q?2OUe/8IfPPE/RmHmDc/6kvQIHm3lfZM0rPmdC1WmX8nLVq+ZiDVNqTY1M2ZYwwMB8?= =?utf-8?q?7m9HX6sEbhss0SaYXV5zpFPjNnG0WhU6NcMpNACJmdOhcJxeiQ0DsrbxKKM3CD9u6?= =?utf-8?q?gjI+zKRYMGXVrqKlp6eknHEOaz9KrQD6p6WxTLYa3f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JG5NAd5z0lGv5aalqXE=3D?= Content-ID: <81569FAB2078DC4D84B676C8B7C99CFA@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: 74c113ac-ce04-4578-13e8-08dc79979122 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 May 2024 13:11:46.1263 (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: 5wVz3ykZjwVZRfeQli12TkNPKeKzWlyc2pN8GWYnaARcYjCJy8xJQcXqNtvmPKH2aEm9MDWB22+2duFHXNJz/FiVdkGVRlHf587rbNj//AikAkTwuHuzmWYkW09phvDq X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR07MB6249 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 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 *