From patchwork Wed May 15 07:14:17 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: 13664734 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 BE3B7C25B75 for ; Wed, 15 May 2024 07:15:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s78qv-0004hA-CM; Wed, 15 May 2024 03:15:05 -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 1s78qb-0004c9-QA for qemu-devel@nongnu.org; Wed, 15 May 2024 03:14:47 -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 1s78qM-0000oJ-SN for qemu-devel@nongnu.org; Wed, 15 May 2024 03:14:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eviden.com; i=@eviden.com; q=dns/txt; s=mail; t=1715757270; x=1747293270; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=8grq/D3/2ZZYyfmF7krWIJodD2cmB/YeOpbkvdktkRQ=; b=hd2izDj7c1Xj+fyw8ZNgP0BC/IGpXBgBg8Q8qgWNhcx4wDm/5/noEFkU mbaePuuJrURnEYPJQXi1oU1pOOJ2LV8wK2E8gzoMzK+VHlbjL3E7Kidna Y4zbmDGFu2coiEtu0krMmGMlW+7q+RrJQlm8ZCg8yZulzyymgjkjYaK2D 1EvR1VfX50nH2KBrpjtFheS5JRkcq0UC5ZKi1UnTgW2YRNnXefibn4vzZ CKuZoMPP2tM3W9ka7wiKMGcaD49Q05Xy+UvJNxqka0EI4kNqk4wkOWjC8 SUMQ396WLZfhKIsoKCGRLO7XQmXC+u7cm4KDakaWJkYog+mIm3y+j3tLG Q==; X-IronPort-AV: E=Sophos;i="6.08,161,1712613600"; d="scan'208";a="12581804" X-MGA-submission: MDG1y+UdqLLOfxbozO9ycBp4QTb2hQajx5VORdR9B3hSgSEHLXLcnPplE32UbQGKix3Fosjf4YkMGXzac/GGz4fc8VnnhOVv8Z0BPK2WcgJ4CQFYhJl1IfdF2IpXaLqPsJQb20rjgUkBcdK18CmpEvIJM2HcnCUjIzwoxtklv/P3Ng== Received: from mail-vi1eur04lp2050.outbound.protection.outlook.com (HELO outbound.mail.protection.outlook.com) ([104.47.14.50]) by smarthost3.eviden.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 09:14:19 +0200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aEdTi/xeZFyAG1eupNrSiXSC6Zw+YYjszvUeoQ1GY1hEJx+kPbCxoApmB7sOgajPxhMoCqrOPgwDPyCzfZsDVZWmXko0UgzgsSrS7AO1rzit697ig9ANbBYfMaOvC7VpotNoRTtY6I3dU/zLVxBmzrTHHQhoo1BkbSsoW5U2EFZDvlR7fUgvDRECYbSZRI9W1bjT9r/VHErZbyYItdyqTG7i6EtjaZN/YpWzCVTsIMIeeDANdDPKIcPyuP/pRSHyBTT3SFdGYvLHGtEfHmWHp3OpeQQcp4JLHCmT7L3qbbaU1Ul2siIhOaxjxqQ/Eh3NzF7Kw03Wst/HEaCzBBCWZQ== 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=8grq/D3/2ZZYyfmF7krWIJodD2cmB/YeOpbkvdktkRQ=; b=O2DgQkYvkwpp9S5EcY19CbQPzucsCpxCoNAu50difO1cJWso15lwM0nwTvxUTi8KBN6gRYN9BDa3NSm+w8bugkOqpM4S4D1cUE4OadzVN7Ah21Gv5JhC0N0lbihO2g/xlSpJcZHLUJx2SzsGxud8S+RhAQ0lUOi+Ik4JQEND8se/h36ylnTKticuiW2GNOd42H7tHleqi3HCi8Tg//BEmMGeNW9V5LsNsuEpnF13bEiUrQtAhkKEOG5liSy51aPdKiiakzh6v5pZLLarJ3Kq2QE1nfxQkR+4/v5o5hHB7f3NJJYTG79PaKjpMOruP5Vx6Jy1ladyPGhpYvsoWQPAug== 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 VI1PR07MB6718.eurprd07.prod.outlook.com (2603:10a6:800:18f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Wed, 15 May 2024 07:14:18 +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.7544.056; Wed, 15 May 2024 07:14:18 +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 v2 16/25] pci: add a pci-level initialization function for iommu notifiers Thread-Topic: [PATCH ats_vtd v2 16/25] pci: add a pci-level initialization function for iommu notifiers Thread-Index: AQHappeANlzl0qOEI0mcoeWbkElSrw== Date: Wed, 15 May 2024 07:14:17 +0000 Message-ID: <20240515071057.33990-17-clement.mathieu--drif@eviden.com> References: <20240515071057.33990-1-clement.mathieu--drif@eviden.com> In-Reply-To: <20240515071057.33990-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_|VI1PR07MB6718:EE_ x-ms-office365-filtering-correlation-id: 05d07f11-dcb5-4d88-6cdc-08dc74aea2ac x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230031|366007|376005|1800799015|38070700009; x-microsoft-antispam-message-info: =?utf-8?q?YmAnh+Nvg0Z237d2942eH4I+5B6ZQur?= =?utf-8?q?6TdF0sQGzOfiMJzmldx0N5+PEFZMEV4R7gfxz6Gsmr80gHB5mQcwXlsYFcwy+HPxU?= =?utf-8?q?gVnLPMvqmMQV3ewYq8Q1/aKFD8eiBBLEa6bmFa4jxK/zXMbtzY+w/DanvR3qCmmhi?= =?utf-8?q?JBGVskF4yH8bqE/Ez/xt/Q199c+8ZVJUzO7FS4gvOxDhQtOZwfnUzlgysD2uFMBIl?= =?utf-8?q?jLCHywFibUslu8s5nxFEYWj68bJYgMyterT3MyRaTBWS/QaeLT7Mg/A7IS2wAdfUV?= =?utf-8?q?6Q9wQc3Ynms1G9iAeP3yU1pEwqQSpyyb7iNVvF+1/h4eB6Y+fQqU+PBJMgkd/SXVW?= =?utf-8?q?pX1qxuAkG79yPhWDesIDcap7eP58n2z3cEGLb0rEIM+EfS62lOrO60THr/VHAtZuq?= =?utf-8?q?s77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2lsRLo0uIIb8vMsV+ySdg=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)(366007)(376005)(1800799015)(38070700009); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?X0NlPik3yrXHkMNId5CzhiTzyJFs?= =?utf-8?q?glt0ug6fSKbvavJPttK+HDc2KOYXMoYAMgXHQjDi5kYX20qSBIfePCC9OE3wDuMZc?= =?utf-8?q?STykxLjm9kJBUzdhu5e5a5NzfANdbdWV8sNTXCCzJGXrMH7DpG80xLl14zGMiFJvD?= =?utf-8?q?ZBDF+qUfHqDmK/0ARqGVRe60crrz6UMVAbBS51LvcwuIxfTQwiXzmcntYZu+K3PDV?= =?utf-8?q?7sKTrk0RxAKZjg/CMbtsMiok4HS6+QtKmR0JS+tewvhEJxyTtKEwL7c9NAcYfFiGl?= =?utf-8?q?Ndn9d+P1MzAqI9Grsn20kX5NHzU/1de7aGyVdEdcP1YXxzg+CS2iC18z8EsNE0cHa?= =?utf-8?q?6iYPwT/XrffF4FI0L1BYcoG2DUJFQlYhrp/4tEdVOu33Q5rxHNgivbNQ/VRf0dNQN?= =?utf-8?q?ybQodV7SYCVyWxs/YtTKNXWXUEmIzrdNqxVPVji5ShMykEq1cN+eVUHn9J1kzGMeP?= =?utf-8?q?IvA8/bw43TU+DvwPt27ia52777E61xSHW3wjb7wguqhgO85+lutbLSuhHTqAwPsfb?= =?utf-8?q?Xa0HhwESF6neg5x7zW4fMENUso3VSXQod5iJVTJqd2cl7CS09anIV89hcyFNTa7tv?= =?utf-8?q?eF8nZsFJ8VSkSPblCDzGaO4B6QpgbhMwbjoIl0a70NkC3IM10w8IiTe7VFni1zXEG?= =?utf-8?q?LET9LSBzAP2DTYLiYIhlvtgXTM9xCxk8y5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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: 05d07f11-dcb5-4d88-6cdc-08dc74aea2ac X-MS-Exchange-CrossTenant-originalarrivaltime: 15 May 2024 07:14:17.9150 (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: 3cheS968gWWZ1lkkxbNkZ+O1H5QnDNMyd5TiJCVfoJw6L73VPnhwRHE2vu7a2gt/kY5QK/VI1zwvAWxW3BgEKWeK2sPIBB36y9xhyvk5QuXcq5EAqFPSFE5Hjxm77c6Z X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6718 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 | 38 ++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 13 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2b42b4e4cc..f90eb04fda 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2747,6 +2747,44 @@ 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) +{ + 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)); + 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 0c532c563c..1587c18cd9 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -458,6 +458,19 @@ int 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 + */ +bool pci_iommu_init_iotlb_notifier(PCIDevice *dev, uint32_t pasid, + IOMMUNotifier *n, IOMMUNotify fn); + /** * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus *