From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1086C05027 for ; Thu, 26 Jan 2023 18:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjAZS0e (ORCPT ); Thu, 26 Jan 2023 13:26:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjAZS0b (ORCPT ); Thu, 26 Jan 2023 13:26:31 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 19AAE599A8 for ; Thu, 26 Jan 2023 10:26:31 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B3B86C14; Thu, 26 Jan 2023 10:27:12 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C25DF3F71E; Thu, 26 Jan 2023 10:26:29 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 1/8] iommu: Decouple iommu_present() from bus ops Date: Thu, 26 Jan 2023 18:26:16 +0000 Message-Id: X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Much as I'd like to remove iommu_present(), the final remaining users are proving stubbornly difficult to clean up, so kick that can down the road and just rework it to preserve the current behaviour without depending on bus ops. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- v2: No change drivers/iommu/iommu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 42591766266d..b27f5d3453bb 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1871,9 +1871,24 @@ int bus_iommu_probe(struct bus_type *bus) return ret; } =20 +static int __iommu_present(struct device *dev, void *unused) +{ + return device_iommu_mapped(dev); +} + +/** + * iommu_present() - make platform-specific assumptions about an IOMMU + * @bus: bus to check + * + * Do not use this function. You want device_iommu_mapped() instead. + * + * Return: true if some IOMMU is present for some device on the given bus.= In + * general it may not be the only IOMMU, and it may not be for the device = you + * are ultimately interested in. + */ bool iommu_present(struct bus_type *bus) { - return bus->iommu_ops !=3D NULL; + return bus_for_each_dev(bus, NULL, NULL, __iommu_present) > 0; } EXPORT_SYMBOL_GPL(iommu_present); =20 --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C113C61DA7 for ; Thu, 26 Jan 2023 18:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232009AbjAZS0g (ORCPT ); Thu, 26 Jan 2023 13:26:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbjAZS0d (ORCPT ); Thu, 26 Jan 2023 13:26:33 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 452C62E811 for ; Thu, 26 Jan 2023 10:26:32 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E49AA1424; Thu, 26 Jan 2023 10:27:13 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F33893F71E; Thu, 26 Jan 2023 10:26:30 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 2/8] iommu: Validate that devices match domains Date: Thu, 26 Jan 2023 18:26:17 +0000 Message-Id: <0f78ba36a7b31a0d534416e56ea0f1af0efc2659.1674753627.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Before we can allow drivers to coexist, we need to make sure that one driver's domain ops can't misinterpret another driver's dev_iommu_priv data. To that end, add a token to the domain so we can remember how it was allocated - for now this may as well be the device ops, since they still correlate 1:1 with drivers. We can trust ourselves for internal default domain attachment, so add the check where it covers both the external attach interfaces. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- v2: Tweaked commit message drivers/iommu/iommu.c | 13 +++++++++---- include/linux/iommu.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b27f5d3453bb..d48e5499e0fa 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1941,20 +1941,22 @@ EXPORT_SYMBOL_GPL(iommu_set_fault_handler); static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, unsigned type) { + const struct iommu_ops *ops =3D bus ? bus->iommu_ops : NULL; struct iommu_domain *domain; =20 - if (bus =3D=3D NULL || bus->iommu_ops =3D=3D NULL) + if (!ops) return NULL; =20 - domain =3D bus->iommu_ops->domain_alloc(type); + domain =3D ops->domain_alloc(type); if (!domain) return NULL; =20 domain->type =3D type; + domain->owner =3D ops; /* Assume all sizes by default; the driver may override this later */ - domain->pgsize_bitmap =3D bus->iommu_ops->pgsize_bitmap; + domain->pgsize_bitmap =3D ops->pgsize_bitmap; if (!domain->ops) - domain->ops =3D bus->iommu_ops->default_domain_ops; + domain->ops =3D ops->default_domain_ops; =20 if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) { iommu_domain_free(domain); @@ -2120,6 +2122,9 @@ static int iommu_group_do_attach_device(struct device= *dev, void *data) { struct iommu_domain *domain =3D data; =20 + if (dev_iommu_ops(dev) !=3D domain->owner) + return -EINVAL; + return __iommu_attach_device(domain, dev); } =20 diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 3589d1b8f922..86fa52025e75 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -95,6 +95,7 @@ struct iommu_domain_geometry { struct iommu_domain { unsigned type; const struct iommu_domain_ops *ops; + const struct iommu_ops *owner; /* Whose domain_alloc we came from */ unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */ struct iommu_domain_geometry geometry; struct iommu_dma_cookie *iova_cookie; --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D571C05027 for ; Thu, 26 Jan 2023 18:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232021AbjAZS0k (ORCPT ); Thu, 26 Jan 2023 13:26:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbjAZS0e (ORCPT ); Thu, 26 Jan 2023 13:26:34 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AA0A0677A7 for ; Thu, 26 Jan 2023 10:26:33 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 216944B3; Thu, 26 Jan 2023 10:27:15 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2FF463F71E; Thu, 26 Jan 2023 10:26:32 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 3/8] iommu: Add lockdep annotations for group list iterators Date: Thu, 26 Jan 2023 18:26:18 +0000 Message-Id: <57cba0cf89556d586e554a9c64cbd28205d67c5c.1674753627.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Before we add any more common helpers for iterating or otherwise accessing the group device list, let's start the good habit of annotating their locking expectations for robustness. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Lu Baolu --- v2: New. Note that I've left the group_pasid helpers, since they're pretty much right next to where the relevant locking happens, and highly unlikely to be reused from anywhere else anyway. drivers/iommu/iommu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d48e5499e0fa..77f076030995 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1100,6 +1101,7 @@ static int iommu_group_device_count(struct iommu_grou= p *group) struct group_device *entry; int ret =3D 0; =20 + lockdep_assert_held(&group->mutex); list_for_each_entry(entry, &group->devices, list) ret++; =20 @@ -1112,6 +1114,7 @@ static int __iommu_group_for_each_dev(struct iommu_gr= oup *group, void *data, struct group_device *device; int ret =3D 0; =20 + lockdep_assert_held(&group->mutex); list_for_each_entry(device, &group->devices, list) { ret =3D fn(device->dev, data); if (ret) --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 059BDC05027 for ; Thu, 26 Jan 2023 18:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232030AbjAZS0m (ORCPT ); Thu, 26 Jan 2023 13:26:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231969AbjAZS0g (ORCPT ); Thu, 26 Jan 2023 13:26:36 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B767559B46 for ; Thu, 26 Jan 2023 10:26:34 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53EA3C14; Thu, 26 Jan 2023 10:27:16 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 613063F71E; Thu, 26 Jan 2023 10:26:33 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 4/8] iommu: Factor out some helpers Date: Thu, 26 Jan 2023 18:26:19 +0000 Message-Id: <959a1e8d598c0a82f94123e017cafb273784f848.1674753627.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The pattern for picking the first device out of the group list is repeated a few times now, so it's clearly worth factoring out to hide the group_device detail from places that don't need to know. Similarly, the safety check for dev_iommu_ops() at public interfaces starts looking a bit repetitive, and might not be completely obvious at first glance, so let's factor that out for clarity as well, in preparation for more uses of both. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Lu Baolu --- v2: - Add dev_iommu_ops_valid() helper - Add lockdep assertion [Jason] drivers/iommu/iommu.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 77f076030995..440bb3b7bded 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -284,6 +284,12 @@ static void dev_iommu_free(struct device *dev) kfree(param); } =20 +/* Only needed in public APIs which allow unchecked devices for convenienc= e */ +static bool dev_iommu_ops_valid(struct device *dev) +{ + return dev->iommu && dev->iommu->iommu_dev; +} + static u32 dev_iommu_get_max_pasids(struct device *dev) { u32 max_pasids =3D 0, bits =3D 0; @@ -1096,6 +1102,12 @@ void iommu_group_remove_device(struct device *dev) } EXPORT_SYMBOL_GPL(iommu_group_remove_device); =20 +static struct device *iommu_group_first_dev(struct iommu_group *group) +{ + lockdep_assert_held(&group->mutex); + return list_first_entry(&group->devices, struct group_device, list)->dev; +} + static int iommu_group_device_count(struct iommu_group *group) { struct group_device *entry; @@ -1907,7 +1919,7 @@ bool device_iommu_capable(struct device *dev, enum io= mmu_cap cap) { const struct iommu_ops *ops; =20 - if (!dev->iommu || !dev->iommu->iommu_dev) + if (!dev_iommu_ops_valid(dev)) return false; =20 ops =3D dev_iommu_ops(dev); @@ -2770,8 +2782,8 @@ EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids); */ int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f= eat) { - if (dev->iommu && dev->iommu->iommu_dev) { - const struct iommu_ops *ops =3D dev->iommu->iommu_dev->ops; + if (dev_iommu_ops_valid(dev)) { + const struct iommu_ops *ops =3D dev_iommu_ops(dev); =20 if (ops->dev_enable_feat) return ops->dev_enable_feat(dev, feat); @@ -2786,8 +2798,8 @@ EXPORT_SYMBOL_GPL(iommu_dev_enable_feature); */ int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features = feat) { - if (dev->iommu && dev->iommu->iommu_dev) { - const struct iommu_ops *ops =3D dev->iommu->iommu_dev->ops; + if (dev_iommu_ops_valid(dev)) { + const struct iommu_ops *ops =3D dev_iommu_ops(dev); =20 if (ops->dev_disable_feat) return ops->dev_disable_feat(dev, feat); @@ -2816,7 +2828,6 @@ static int iommu_change_dev_def_domain(struct iommu_g= roup *group, struct device *prev_dev, int type) { struct iommu_domain *prev_dom; - struct group_device *grp_dev; int ret, dev_def_dom; struct device *dev; =20 @@ -2848,8 +2859,7 @@ static int iommu_change_dev_def_domain(struct iommu_g= roup *group, } =20 /* Since group has only one device */ - grp_dev =3D list_first_entry(&group->devices, struct group_device, list); - dev =3D grp_dev->dev; + dev =3D iommu_group_first_dev(group); =20 if (prev_dev !=3D dev) { dev_err_ratelimited(prev_dev, "Cannot change default domain: Device has = been changed\n"); @@ -2946,7 +2956,6 @@ static int iommu_change_dev_def_domain(struct iommu_g= roup *group, static ssize_t iommu_group_store_type(struct iommu_group *group, const char *buf, size_t count) { - struct group_device *grp_dev; struct device *dev; int ret, req_type; =20 @@ -2981,8 +2990,7 @@ static ssize_t iommu_group_store_type(struct iommu_gr= oup *group, } =20 /* Since group has only one device */ - grp_dev =3D list_first_entry(&group->devices, struct group_device, list); - dev =3D grp_dev->dev; + dev =3D iommu_group_first_dev(group); get_device(dev); =20 /* @@ -3107,21 +3115,18 @@ void iommu_device_unuse_default_domain(struct devic= e *dev) =20 static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) { - struct group_device *dev =3D - list_first_entry(&group->devices, struct group_device, list); + struct device *dev =3D iommu_group_first_dev(group); =20 if (group->blocking_domain) return 0; =20 - group->blocking_domain =3D - __iommu_domain_alloc(dev->dev->bus, IOMMU_DOMAIN_BLOCKED); + group->blocking_domain =3D __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_BL= OCKED); if (!group->blocking_domain) { /* * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED * create an empty domain instead. */ - group->blocking_domain =3D __iommu_domain_alloc( - dev->dev->bus, IOMMU_DOMAIN_UNMANAGED); + group->blocking_domain =3D __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_U= NMANAGED); if (!group->blocking_domain) return -EINVAL; } --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CC8DC61DA3 for ; Thu, 26 Jan 2023 18:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232062AbjAZS0q (ORCPT ); Thu, 26 Jan 2023 13:26:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231995AbjAZS0i (ORCPT ); Thu, 26 Jan 2023 13:26:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5ED236A731 for ; Thu, 26 Jan 2023 10:26:35 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 84C931424; Thu, 26 Jan 2023 10:27:17 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 93A133F71E; Thu, 26 Jan 2023 10:26:34 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 5/8] iommu: Switch __iommu_domain_alloc() to device ops Date: Thu, 26 Jan 2023 18:26:20 +0000 Message-Id: <23b51c84247cb36e96c242d3aef8ef555b6d05cd.1674753627.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In all the places we allocate default domains, we have (or can easily get hold of) a device from which to resolve the right IOMMU ops; only the public iommu_domain_alloc() interface actually depends on bus ops. Reworking the public API is a big enough mission in its own right, but in the meantime we can still decouple it from bus ops internally to move forward. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Lu Baolu --- v2: - Explain the mitigation better in the warning message - Fix theoretical bug if alloc_dev is never assigned because the bus has no devices - Use new dev_iommu_ops_valid() since in theory VFIO noiommu makes device_iommu_mapped() -> dev_iommu_ops() an unsafe assumption [Baolu] drivers/iommu/iommu.c | 59 ++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 440bb3b7bded..bdc5fdf39d2b 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -89,7 +89,7 @@ static int iommu_bus_notifier(struct notifier_block *nb, unsigned long action, void *data); static int iommu_alloc_default_domain(struct iommu_group *group, struct device *dev); -static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, +static struct iommu_domain *__iommu_domain_alloc(struct device *dev, unsigned type); static int __iommu_attach_device(struct iommu_domain *domain, struct device *dev); @@ -1641,15 +1641,15 @@ static int iommu_get_def_domain_type(struct device = *dev) return 0; } =20 -static int iommu_group_alloc_default_domain(struct bus_type *bus, - struct iommu_group *group, +static int iommu_group_alloc_default_domain(struct iommu_group *group, + struct device *dev, unsigned int type) { struct iommu_domain *dom; =20 - dom =3D __iommu_domain_alloc(bus, type); + dom =3D __iommu_domain_alloc(dev, type); if (!dom && type !=3D IOMMU_DOMAIN_DMA) { - dom =3D __iommu_domain_alloc(bus, IOMMU_DOMAIN_DMA); + dom =3D __iommu_domain_alloc(dev, IOMMU_DOMAIN_DMA); if (dom) pr_warn("Failed to allocate default IOMMU domain of type %u for group %= s - Falling back to IOMMU_DOMAIN_DMA", type, group->name); @@ -1674,7 +1674,7 @@ static int iommu_alloc_default_domain(struct iommu_gr= oup *group, =20 type =3D iommu_get_def_domain_type(dev) ? : iommu_def_domain_type; =20 - return iommu_group_alloc_default_domain(dev->bus, group, type); + return iommu_group_alloc_default_domain(group, dev, type); } =20 /** @@ -1787,8 +1787,7 @@ static int probe_get_default_domain_type(struct devic= e *dev, void *data) return 0; } =20 -static void probe_alloc_default_domain(struct bus_type *bus, - struct iommu_group *group) +static void probe_alloc_default_domain(struct iommu_group *group) { struct __group_domain_type gtype; =20 @@ -1798,10 +1797,12 @@ static void probe_alloc_default_domain(struct bus_t= ype *bus, __iommu_group_for_each_dev(group, >ype, probe_get_default_domain_type); =20 - if (!gtype.type) + if (!gtype.type) { gtype.type =3D iommu_def_domain_type; + gtype.dev =3D iommu_group_first_dev(group); + } =20 - iommu_group_alloc_default_domain(bus, group, gtype.type); + iommu_group_alloc_default_domain(group, gtype.dev, gtype.type); =20 } =20 @@ -1864,7 +1865,7 @@ int bus_iommu_probe(struct bus_type *bus) list_del_init(&group->entry); =20 /* Try to allocate default domain */ - probe_alloc_default_domain(bus, group); + probe_alloc_default_domain(group); =20 if (!group->default_domain) { mutex_unlock(&group->mutex); @@ -1953,15 +1954,12 @@ void iommu_set_fault_handler(struct iommu_domain *d= omain, } EXPORT_SYMBOL_GPL(iommu_set_fault_handler); =20 -static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus, +static struct iommu_domain *__iommu_domain_alloc(struct device *dev, unsigned type) { - const struct iommu_ops *ops =3D bus ? bus->iommu_ops : NULL; + const struct iommu_ops *ops =3D dev_iommu_ops(dev); struct iommu_domain *domain; =20 - if (!ops) - return NULL; - domain =3D ops->domain_alloc(type); if (!domain) return NULL; @@ -1980,9 +1978,30 @@ static struct iommu_domain *__iommu_domain_alloc(str= uct bus_type *bus, return domain; } =20 +static int __iommu_domain_alloc_dev(struct device *dev, void *data) +{ + struct device **alloc_dev =3D data; + + if (!dev_iommu_ops_valid(dev)) + return 0; + + WARN_ONCE(*alloc_dev && dev_iommu_ops(dev) !=3D dev_iommu_ops(*alloc_dev), + "Multiple IOMMU drivers present, which the public IOMMU API can't fully = support yet. You may still need to disable one or more to get the expected = result here, sorry!\n"); + + *alloc_dev =3D dev; + return 0; +} + struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) { - return __iommu_domain_alloc(bus, IOMMU_DOMAIN_UNMANAGED); + struct device *dev =3D NULL; + + /* We always check the whole bus, so the return value isn't useful */ + bus_for_each_dev(bus, NULL, &dev, __iommu_domain_alloc_dev); + if (!dev) + return NULL; + + return __iommu_domain_alloc(dev, IOMMU_DOMAIN_UNMANAGED); } EXPORT_SYMBOL_GPL(iommu_domain_alloc); =20 @@ -2906,7 +2925,7 @@ static int iommu_change_dev_def_domain(struct iommu_g= roup *group, } =20 /* Sets group->default_domain to the newly allocated domain */ - ret =3D iommu_group_alloc_default_domain(dev->bus, group, type); + ret =3D iommu_group_alloc_default_domain(group, dev, type); if (ret) goto out; =20 @@ -3120,13 +3139,13 @@ static int __iommu_group_alloc_blocking_domain(stru= ct iommu_group *group) if (group->blocking_domain) return 0; =20 - group->blocking_domain =3D __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_BL= OCKED); + group->blocking_domain =3D __iommu_domain_alloc(dev, IOMMU_DOMAIN_BLOCKED= ); if (!group->blocking_domain) { /* * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED * create an empty domain instead. */ - group->blocking_domain =3D __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_U= NMANAGED); + group->blocking_domain =3D __iommu_domain_alloc(dev, IOMMU_DOMAIN_UNMANA= GED); if (!group->blocking_domain) return -EINVAL; } --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34397C05027 for ; Thu, 26 Jan 2023 18:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbjAZS0w (ORCPT ); Thu, 26 Jan 2023 13:26:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbjAZS0m (ORCPT ); Thu, 26 Jan 2023 13:26:42 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E73168103 for ; Thu, 26 Jan 2023 10:26:37 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BEC2F14BF; Thu, 26 Jan 2023 10:27:18 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C45D63F71E; Thu, 26 Jan 2023 10:26:35 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 6/8] iommu/arm-smmu: Don't register fwnode for legacy binding Date: Thu, 26 Jan 2023 18:26:21 +0000 Message-Id: <93678b819d70079797734d9a8b0ebdc5beca43d2.1674753627.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When using the legacy binding we bypass the of_xlate mechanism, so avoid registering the instance fwnodes which act as keys for that. This will help __iommu_probe_device() to retrieve the registered ops the same way as for x86 etc. when no fwspec has previously been set up by of_xlate. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- v2: No change drivers/iommu/arm/arm-smmu/arm-smmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-= smmu/arm-smmu.c index 719fbca1fe52..607f06af01b6 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -2156,7 +2156,8 @@ static int arm_smmu_device_probe(struct platform_devi= ce *pdev) return err; } =20 - err =3D iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); + err =3D iommu_device_register(&smmu->iommu, &arm_smmu_ops, + using_legacy_binding ? NULL : dev); if (err) { dev_err(dev, "Failed to register iommu\n"); iommu_device_sysfs_remove(&smmu->iommu); --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C47CFC05027 for ; Thu, 26 Jan 2023 18:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232076AbjAZS05 (ORCPT ); Thu, 26 Jan 2023 13:26:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbjAZS0t (ORCPT ); Thu, 26 Jan 2023 13:26:49 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 359BF6BBDA for ; Thu, 26 Jan 2023 10:26:40 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92D9A1515; Thu, 26 Jan 2023 10:27:21 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CB963F71E; Thu, 26 Jan 2023 10:26:38 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com, "Rafael J . Wysocki" , Greg Kroah-Hartman Subject: [PATCH v2 7/8] iommu: Retire bus ops Date: Thu, 26 Jan 2023 18:26:22 +0000 Message-Id: <198e82a6b1a28605409c395da4ec1a67b0e1587b.1674753627.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With the rest of the API internals converted, it's time to finally tackle probe_device and how we bootstrap the per-device ops association to begin with. This ends up being disappointingly straightforward, since fwspec users are already doing it in order to find their of_xlate callback, and it works out that we can easily do the equivalent for other drivers too. Then shuffle the remaining awareness of iommu_ops into the couple of core headers that still need it, and breathe a sigh of relief. Ding dong the bus ops are gone! CC: Rafael J. Wysocki CC: Christoph Hellwig Acked-by: Greg Kroah-Hartman Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- v2: Clarify the iommu_ops_from_fwnode(NULL) assumption [Baolu] drivers/iommu/iommu.c | 28 +++++++++++++++++----------- include/acpi/acpi_bus.h | 2 ++ include/linux/device.h | 1 - include/linux/device/bus.h | 5 ----- include/linux/dma-map-ops.h | 1 + 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index bdc5fdf39d2b..7fb7c84e3dc6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -219,13 +219,6 @@ int iommu_device_register(struct iommu_device *iommu, /* We need to be able to take module references appropriately */ if (WARN_ON(is_module_address((unsigned long)ops) && !ops->owner)) return -EINVAL; - /* - * Temporarily enforce global restriction to a single driver. This was - * already the de-facto behaviour, since any possible combination of - * existing drivers would compete for at least the PCI or platform bus. - */ - if (iommu_buses[0]->iommu_ops && iommu_buses[0]->iommu_ops !=3D ops) - return -EBUSY; =20 iommu->ops =3D ops; if (hwdev) @@ -235,10 +228,8 @@ int iommu_device_register(struct iommu_device *iommu, list_add_tail(&iommu->list, &iommu_device_list); spin_unlock(&iommu_device_lock); =20 - for (int i =3D 0; i < ARRAY_SIZE(iommu_buses) && !err; i++) { - iommu_buses[i]->iommu_ops =3D ops; + for (int i =3D 0; i < ARRAY_SIZE(iommu_buses) && !err; i++) err =3D bus_iommu_probe(iommu_buses[i]); - } if (err) iommu_device_unregister(iommu); return err; @@ -310,12 +301,27 @@ static u32 dev_iommu_get_max_pasids(struct device *de= v) =20 static int __iommu_probe_device(struct device *dev, struct list_head *grou= p_list) { - const struct iommu_ops *ops =3D dev->bus->iommu_ops; + const struct iommu_ops *ops; struct iommu_device *iommu_dev; + struct iommu_fwspec *fwspec; struct iommu_group *group; static DEFINE_MUTEX(iommu_probe_device_lock); int ret; =20 + /* + * For FDT-based systems and ACPI IORT/VIOT, drivers register IOMMU + * instances with non-NULL fwnodes, and client devices should have been + * identified with a fwspec by this point. Otherwise, we can currently + * assume that only one of Intel, AMD, s390, PAMU or legacy SMMUv2 can + * be present, and that any of their registered instances has suitable + * ops for probing, and thus cheekily co-opt the same mechanism. + */ + fwspec =3D dev_iommu_fwspec_get(dev); + if (fwspec && fwspec->ops) + ops =3D fwspec->ops; + else + ops =3D iommu_ops_from_fwnode(NULL); + if (!ops) return -ENODEV; /* diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index cd3b75e08ec3..067dde9291c9 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -614,6 +614,8 @@ struct acpi_pci_root { =20 /* helper */ =20 +struct iommu_ops; + bool acpi_dma_supported(const struct acpi_device *adev); enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); int acpi_iommu_fwspec_init(struct device *dev, u32 id, diff --git a/include/linux/device.h b/include/linux/device.h index 44e3acae7b36..f7a7ecafedd3 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -41,7 +41,6 @@ struct class; struct subsys_private; struct device_node; struct fwnode_handle; -struct iommu_ops; struct iommu_group; struct dev_pin_info; struct dev_iommu; diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index d8b29ccd07e5..4ece3470112f 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -63,9 +63,6 @@ struct fwnode_handle; * this bus. * @pm: Power management operations of this bus, callback the specific * device driver's pm-ops. - * @iommu_ops: IOMMU specific operations for this bus, used to attach IOM= MU - * driver implementations to a bus and allow the driver to do - * bus-specific setup * @p: The private data of the driver core, only the driver core can * touch this. * @lock_key: Lock class key for use by the lock validator @@ -109,8 +106,6 @@ struct bus_type { =20 const struct dev_pm_ops *pm; =20 - const struct iommu_ops *iommu_ops; - struct subsys_private *p; struct lock_class_key lock_key; =20 diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index d678afeb8a13..e8ebf0bf611b 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -10,6 +10,7 @@ #include =20 struct cma; +struct iommu_ops; =20 /* * Values for struct dma_map_ops.flags: --=20 2.36.1.dirty From nobody Sun Sep 14 03:48:13 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB0C9C05027 for ; Thu, 26 Jan 2023 18:27:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbjAZS1D (ORCPT ); Thu, 26 Jan 2023 13:27:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbjAZS0v (ORCPT ); Thu, 26 Jan 2023 13:26:51 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4DA1A6D347 for ; Thu, 26 Jan 2023 10:26:41 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C36E1152B; Thu, 26 Jan 2023 10:27:22 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D28483F71E; Thu, 26 Jan 2023 10:26:39 -0800 (PST) From: Robin Murphy To: joro@8bytes.org, will@kernel.org Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, hch@lst.de, jgg@nvidia.com, baolu.lu@linux.intel.com Subject: [PATCH v2 8/8] iommu: Clean up open-coded ownership checks Date: Thu, 26 Jan 2023 18:26:23 +0000 Message-Id: X-Mailer: git-send-email 2.36.1.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some drivers already implement their own defence against the possibility of being given someone else's device. Since this is now taken care of by the core code (and via a slightly different path from the original fwspec-based idea), let's clean them up. Signed-off-by: Robin Murphy Acked-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe --- v2: No change, but I'll note here that it's really about the fwspec->ops checks; the !fwspec clauses are just going along for the ride where that's clearly impossible as well. I plan to sweep for other redundant checks in future when looking at the relevant flows. drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 9 +-------- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 14 ++------------ drivers/iommu/mtk_iommu.c | 7 +------ drivers/iommu/mtk_iommu_v1.c | 3 --- drivers/iommu/sprd-iommu.c | 8 +------- drivers/iommu/virtio-iommu.c | 3 --- 7 files changed, 5 insertions(+), 42 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index ab160198edd6..cb05d9771192 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2642,9 +2642,6 @@ static struct iommu_device *arm_smmu_probe_device(str= uct device *dev) struct arm_smmu_master *master; struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); =20 - if (!fwspec || fwspec->ops !=3D &arm_smmu_ops) - return ERR_PTR(-ENODEV); - if (WARN_ON_ONCE(dev_iommu_priv_get(dev))) return ERR_PTR(-EBUSY); =20 diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-= smmu/arm-smmu.c index 607f06af01b6..235550db0d59 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1118,11 +1118,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *= domain, struct device *dev) struct arm_smmu_device *smmu; int ret; =20 - if (!fwspec || fwspec->ops !=3D &arm_smmu_ops) { - dev_err(dev, "cannot attach to SMMU, is it on the same bus?\n"); - return -ENXIO; - } - /* * FIXME: The arch/arm DMA API code tries to attach devices to its own * domains between of_xlate() and probe_device() - we have no way to cope @@ -1352,10 +1347,8 @@ static struct iommu_device *arm_smmu_probe_device(st= ruct device *dev) fwspec =3D dev_iommu_fwspec_get(dev); if (ret) goto out_free; - } else if (fwspec && fwspec->ops =3D=3D &arm_smmu_ops) { - smmu =3D arm_smmu_get_by_fwnode(fwspec->iommu_fwnode); } else { - return ERR_PTR(-ENODEV); + smmu =3D arm_smmu_get_by_fwnode(fwspec->iommu_fwnode); } =20 ret =3D -EINVAL; diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/ar= m-smmu/qcom_iommu.c index d7be3adee426..3fe02720ab29 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -79,16 +79,6 @@ static struct qcom_iommu_domain *to_qcom_iommu_domain(st= ruct iommu_domain *dom) =20 static const struct iommu_ops qcom_iommu_ops; =20 -static struct qcom_iommu_dev * to_iommu(struct device *dev) -{ - struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); - - if (!fwspec || fwspec->ops !=3D &qcom_iommu_ops) - return NULL; - - return dev_iommu_priv_get(dev); -} - static struct qcom_iommu_ctx * to_ctx(struct qcom_iommu_domain *d, unsigne= d asid) { struct qcom_iommu_dev *qcom_iommu =3D d->iommu; @@ -361,7 +351,7 @@ static void qcom_iommu_domain_free(struct iommu_domain = *domain) =20 static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct devic= e *dev) { - struct qcom_iommu_dev *qcom_iommu =3D to_iommu(dev); + struct qcom_iommu_dev *qcom_iommu =3D dev_iommu_priv_get(dev); struct qcom_iommu_domain *qcom_domain =3D to_qcom_iommu_domain(domain); int ret; =20 @@ -486,7 +476,7 @@ static bool qcom_iommu_capable(struct device *dev, enum= iommu_cap cap) =20 static struct iommu_device *qcom_iommu_probe_device(struct device *dev) { - struct qcom_iommu_dev *qcom_iommu =3D to_iommu(dev); + struct qcom_iommu_dev *qcom_iommu =3D dev_iommu_priv_get(dev); struct device_link *link; =20 if (!qcom_iommu) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index d5a4955910ff..ce19a2a21e2a 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -776,16 +776,11 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iomm= u_domain *domain, static struct iommu_device *mtk_iommu_probe_device(struct device *dev) { struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); - struct mtk_iommu_data *data; + struct mtk_iommu_data *data =3D dev_iommu_priv_get(dev); struct device_link *link; struct device *larbdev; unsigned int larbid, larbidx, i; =20 - if (!fwspec || fwspec->ops !=3D &mtk_iommu_ops) - return ERR_PTR(-ENODEV); /* Not a iommu client device */ - - data =3D dev_iommu_priv_get(dev); - if (!MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) return &data->iommu; =20 diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index 78d0a84c704f..328833823181 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -478,9 +478,6 @@ static struct iommu_device *mtk_iommu_v1_probe_device(s= truct device *dev) idx++; } =20 - if (!fwspec || fwspec->ops !=3D &mtk_iommu_v1_ops) - return ERR_PTR(-ENODEV); /* Not a iommu client device */ - data =3D dev_iommu_priv_get(dev); =20 /* Link the consumer device with the smi-larb device(supplier) */ diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index ae94d74b73f4..85378f7cfd1f 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -358,13 +358,7 @@ static phys_addr_t sprd_iommu_iova_to_phys(struct iomm= u_domain *domain, =20 static struct iommu_device *sprd_iommu_probe_device(struct device *dev) { - struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); - struct sprd_iommu_device *sdev; - - if (!fwspec || fwspec->ops !=3D &sprd_iommu_ops) - return ERR_PTR(-ENODEV); - - sdev =3D dev_iommu_priv_get(dev); + struct sprd_iommu_device *sdev =3D dev_iommu_priv_get(dev); =20 return &sdev->iommu; } diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 5b8fe9bfa9a5..59f1abd6ee53 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -945,9 +945,6 @@ static struct iommu_device *viommu_probe_device(struct = device *dev) struct viommu_dev *viommu =3D NULL; struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); =20 - if (!fwspec || fwspec->ops !=3D &viommu_ops) - return ERR_PTR(-ENODEV); - viommu =3D viommu_get_by_fwnode(fwspec->iommu_fwnode); if (!viommu) return ERR_PTR(-ENODEV); --=20 2.36.1.dirty