From nobody Wed Feb 11 05:41:50 2026 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2045.outbound.protection.outlook.com [40.107.244.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BA5820F061 for ; Thu, 6 Mar 2025 21:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741294888; cv=fail; b=uXVAr66Mc5b/eQVyYjRmsYEiOuDk82vrEil5uKqxvpU5DNaKoN2+N4xZ9Z2ue/4e8CuapKkL0fXEmfOV3StCXz2vY9mEEgQVBpNVl5Znix/bCS6aC8rqSbiDZ6bsOoez3B6jy/nmnE0UmAvk2QcDrrw22B00ecU4c7L9jfzy+eY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741294888; c=relaxed/simple; bh=58eBuaO/n0raa9xMEUXEyKdJVETJ+Ki/CuNRIzmEYu8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qgbGbG5P+xDc/d2E8C7fpAaUL3J7hZxrYnDmqjbFvpsZCRnWmFCaBwJZpJQu0z++3EsNe7i0KF5K2vcu8Nrs6l84UoW5f7AbCSyTHgQu75v7KlQQePw9i/htfcJcrfoZgNhQAJJ6eMVlQkkqhbLatpHRan85Fs6Qftorj4JrTdk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=O+qK4n+a; arc=fail smtp.client-ip=40.107.244.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="O+qK4n+a" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LPVvD+A1aojizbi+u2RoO8fIqw8uzvCux9DvuQ8pAZk/7F2OOzO49+eSwKxaD8IePKlgw2MICmDmqa4Cq/bClauFE8VoRA9LfuBJcKn8dsL4suKqFcUJ9/c/XPoUQiULVdW0H+7YYF+Uh5YRwBpbHxvDmNVwHLSEZqylNSf1kiG2Jb9cEW/AcoB2VV1fCxIrfWsaadhpHcfsiDvwBAWsxXRyNPee7ZR99/gicz1Kkg3GTYONpciRTGNgMSy/gQx1UOYwfm7I+a/kFhzCOkC1enF1AGCwGePI/j88Xn3sKT+nlTNNk2PE+wzcYmmR/LyHamP6MtWjLwLN+pN1cO1jog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Gc0+fsi4jlU8LiygH4CsAV+Ji7txlImXInPGqy92II8=; b=bvxNjrHyrwSF0rfKB0WxTym5nsoyfSnV7Vef2U/5Vp7Rk4CSxDwdS0tzlHG/cbH9AcHXwsigHj9S3zK2wUlmRLDOKmUwNzjShiQy9lTbsmHmE98Pb6AK5alKTz4/EJXl972silSvxe88d8aSPJCJrYOLX2DAoPY4Dc30fpERK+q2SjsHyxEic4zth+c/ImuLhnj79r2eYZLTVbdCwQ8gKR87k8dEIx7+14M0G9FWiFKxTTkxe/Jsow59leERJrLDWwDxJ95fS/VZlgHBEewOv1yTsUkrCICZATDBPDUtatgho4IoCc35mZAZqFSrlBiMz10ZHY0DYvVH5p90Sneyrw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gc0+fsi4jlU8LiygH4CsAV+Ji7txlImXInPGqy92II8=; b=O+qK4n+aV58DTIKcqXIgdnVOlrVLLhAleXHQX5yK63GGz70nQaHPdWqJTiAg7Y7qJuThfLvkEnhoCMVjQ10A5Am9E6VQDgdmgnL+2k53KjqvXlUa6ACTZQVZRZV74AlUrAlpPJyoyEER/bdEdDQL4o7MVWYwmdi9OaqWqH6HCSDYrTxKUlkkxjTC7ONLNt6VbK2COsqiDLJiLtnU7G8jlbABvaM9uM7JBv8oF+lL+g1n9LZTBVvUfox87YhjV6ECLUxTer+hXJvUtLUXHb9fQSD67lLUfEStq8Oq+/0xt9E/hjdGEL9hOqwmyFM4IDUwzwqyjHG+VYe85KxOpue5EQ== Received: from MW4P221CA0011.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::16) by SA1PR12MB6824.namprd12.prod.outlook.com (2603:10b6:806:25f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.19; Thu, 6 Mar 2025 21:01:21 +0000 Received: from CO1PEPF000075F4.namprd03.prod.outlook.com (2603:10b6:303:8b:cafe::38) by MW4P221CA0011.outlook.office365.com (2603:10b6:303:8b::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.17 via Frontend Transport; Thu, 6 Mar 2025 21:01:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CO1PEPF000075F4.mail.protection.outlook.com (10.167.249.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 21:01:21 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 6 Mar 2025 13:01:04 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Thu, 6 Mar 2025 13:01:04 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Thu, 6 Mar 2025 13:01:03 -0800 From: Nicolin Chen To: , , , , CC: , Subject: [PATCH v4 3/3] iommu: Drop sw_msi from iommu_domain Date: Thu, 6 Mar 2025 13:00:49 -0800 Message-ID: <6d4b493d20926c8d14e29bc776639cdcf2095146.1741294235.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075F4:EE_|SA1PR12MB6824:EE_ X-MS-Office365-Filtering-Correlation-Id: 23d10e12-f34d-4334-158f-08dd5cf20c6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?RS/l1OCcXLIHlYRVje3OF92+jWIPZ75+cur0E01pY0mo8pFsb7sbxCNhLr0S?= =?us-ascii?Q?gt1g8vJuO+qr/8lKAiQUwkuoNDjI8iyT6NfCSCCmDfCkvURb3PKkh4Lzj0gD?= =?us-ascii?Q?7if53nS34Md6iu+RyVgUJFHDeTQETIfyiZJ0c3uvoGlw1X5eDQPgkBdbTB0e?= =?us-ascii?Q?m/OXtRPPFjEsfbrP8H9IrNKi5AHenVTIxt7Q6tRPT6tAG5+d2txk1CVyCLEf?= =?us-ascii?Q?CjRm1EPFebD/GOJBUeqnhCoGASgP+lgRFUSKrOEqTuVFNxWiHmwH6fp+qXu+?= =?us-ascii?Q?ig8pwhAqRg25phcYyYU/TMaiXmgpO+Po66+FaTdBI/xZLalxSMrcA6qga5DX?= =?us-ascii?Q?2Bsk14CFfGXZFuoxQsbLN72sqIX+RJLaP10cWFuRJPnm/6irVaamJ5cZQdr4?= =?us-ascii?Q?FLfGi6yWx+JZ89QpOjtH2S2M/UgyXHpuKaOhIeUKoOYNQSJ4wdUG6Z31XMJ1?= =?us-ascii?Q?0T9QIwTfKlYKsuz/fQm/NIGZ5SWdwoJ8LcMqhiPT8Q6qRAyK8qRGLk4FpEYg?= =?us-ascii?Q?d/X8x1mrFDsITQJhsYg+RU1SW8USFBkS4u/Hj3cJGERZafjiMUI1Tk8x35RX?= =?us-ascii?Q?/k2uGfRl+2zsxnjDH1kCixVMsOFPbXw2adlJ/zstlFxtKEwBKbZbQP6c1z3u?= =?us-ascii?Q?ZVu9aG105afzNI5ngdxvlmUHL67DEJ//S2/ftaDXZbEMumWDjbGpw0jedify?= =?us-ascii?Q?V3CMOmFVfao4sZ2hbqEAJZTHtM66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;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 21:01:21.6079 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23d10e12-f34d-4334-158f-08dd5cf20c6e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6824 Content-Type: text/plain; charset="utf-8" There are only two sw_msi implementations in the entire system, thus it's not very necessary to have an sw_msi pointer. Instead, check domain->cookie_type to call the two sw_msi implementations directly from the core code. Suggested-by: Robin Murphy Reviewed-by: Robin Murphy Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Tested-by: Nathan Chancellor --- drivers/iommu/dma-iommu.h | 9 +++++++++ include/linux/iommu.h | 15 --------------- drivers/iommu/dma-iommu.c | 14 ++------------ drivers/iommu/iommu.c | 17 +++++++++++++++-- drivers/iommu/iommufd/hw_pagetable.c | 3 --- 5 files changed, 26 insertions(+), 32 deletions(-) diff --git a/drivers/iommu/dma-iommu.h b/drivers/iommu/dma-iommu.h index 9cca11806e5d..eca201c1f963 100644 --- a/drivers/iommu/dma-iommu.h +++ b/drivers/iommu/dma-iommu.h @@ -19,6 +19,9 @@ int iommu_dma_init_fq(struct iommu_domain *domain); =20 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list= ); =20 +int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, + phys_addr_t msi_addr); + extern bool iommu_dma_forcedac; =20 #else /* CONFIG_IOMMU_DMA */ @@ -49,5 +52,11 @@ static inline void iommu_dma_get_resv_regions(struct dev= ice *dev, struct list_he { } =20 +static inline int iommu_dma_sw_msi(struct iommu_domain *domain, + struct msi_desc *desc, phys_addr_t msi_addr) +{ + return -ENODEV; +} + #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 06cc14e9993d..e01c855ae8a7 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -229,11 +229,6 @@ struct iommu_domain { struct iommu_domain_geometry geometry; int (*iopf_handler)(struct iopf_group *group); =20 -#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU) - int (*sw_msi)(struct iommu_domain *domain, struct msi_desc *desc, - phys_addr_t msi_addr); -#endif - union { /* cookie */ struct iommu_dma_cookie *iova_cookie; struct iommu_dma_msi_cookie *msi_cookie; @@ -254,16 +249,6 @@ struct iommu_domain { }; }; =20 -static inline void iommu_domain_set_sw_msi( - struct iommu_domain *domain, - int (*sw_msi)(struct iommu_domain *domain, struct msi_desc *desc, - phys_addr_t msi_addr)) -{ -#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU) - domain->sw_msi =3D sw_msi; -#endif -} - static inline bool iommu_is_dma_domain(struct iommu_domain *domain) { return domain->type & __IOMMU_DOMAIN_DMA_API; diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 31a7b4b81656..2bd9f80a83fe 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -94,9 +94,6 @@ static int __init iommu_dma_forcedac_setup(char *str) } early_param("iommu.forcedac", iommu_dma_forcedac_setup); =20 -static int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *= desc, - phys_addr_t msi_addr); - /* Number of entries per flush queue */ #define IOVA_DEFAULT_FQ_SIZE 256 #define IOVA_SINGLE_FQ_SIZE 32768 @@ -377,7 +374,6 @@ int iommu_get_dma_cookie(struct iommu_domain *domain) =20 mutex_init(&cookie->mutex); INIT_LIST_HEAD(&cookie->msi_page_list); - iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi); domain->cookie_type =3D IOMMU_COOKIE_DMA_IOVA; domain->iova_cookie =3D cookie; return 0; @@ -411,7 +407,6 @@ int iommu_get_msi_cookie(struct iommu_domain *domain, d= ma_addr_t base) =20 cookie->msi_iova =3D base; INIT_LIST_HEAD(&cookie->msi_page_list); - iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi); domain->cookie_type =3D IOMMU_COOKIE_DMA_MSI; domain->msi_cookie =3D cookie; return 0; @@ -427,11 +422,6 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) struct iommu_dma_cookie *cookie =3D domain->iova_cookie; struct iommu_dma_msi_page *msi, *tmp; =20 -#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU) - if (domain->sw_msi !=3D iommu_dma_sw_msi) - return; -#endif - if (cookie->iovad.granule) { iommu_dma_free_fq(cookie); put_iova_domain(&cookie->iovad); @@ -1826,8 +1816,8 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_p= age(struct device *dev, return NULL; } =20 -static int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *= desc, - phys_addr_t msi_addr) +int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, + phys_addr_t msi_addr) { struct device *dev =3D msi_desc_to_dev(desc); const struct iommu_dma_msi_page *msi_page; diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index c92e47f333cb..0f4cc15ded1c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -3650,8 +3651,20 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phy= s_addr_t msi_addr) return 0; =20 mutex_lock(&group->mutex); - if (group->domain && group->domain->sw_msi) - ret =3D group->domain->sw_msi(group->domain, desc, msi_addr); + if (group->domain) { + switch (group->domain->cookie_type) { + case IOMMU_COOKIE_DMA_MSI: + case IOMMU_COOKIE_DMA_IOVA: + ret =3D iommu_dma_sw_msi(group->domain, desc, msi_addr); + break; + case IOMMU_COOKIE_IOMMUFD: + ret =3D iommufd_sw_msi(group->domain, desc, msi_addr); + break; + default: + ret =3D -EOPNOTSUPP; + break; + } + } mutex_unlock(&group->mutex); return ret; } diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/h= w_pagetable.c index cefe71a4e9e8..f97c4e49d486 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -161,7 +161,6 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, str= uct iommufd_ioas *ioas, } hwpt->domain->iommufd_hwpt =3D hwpt; hwpt->domain->cookie_type =3D IOMMU_COOKIE_IOMMUFD; - iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi); =20 /* * Set the coherency mode before we do iopt_table_add_domain() as some @@ -259,7 +258,6 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, hwpt->domain->owner =3D ops; hwpt->domain->iommufd_hwpt =3D hwpt; hwpt->domain->cookie_type =3D IOMMU_COOKIE_IOMMUFD; - iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi); =20 if (WARN_ON_ONCE(hwpt->domain->type !=3D IOMMU_DOMAIN_NESTED)) { rc =3D -EINVAL; @@ -318,7 +316,6 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu = *viommu, u32 flags, hwpt->domain->iommufd_hwpt =3D hwpt; hwpt->domain->owner =3D viommu->iommu_dev->ops; hwpt->domain->cookie_type =3D IOMMU_COOKIE_IOMMUFD; - iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi); =20 if (WARN_ON_ONCE(hwpt->domain->type !=3D IOMMU_DOMAIN_NESTED)) { rc =3D -EINVAL; --=20 2.43.0