lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 29 Nov 2023 21:10:13 -0400
From: Jason Gunthorpe <jgg@...dia.com>
To: acpica-devel@...ts.linux.dev,
	Andy Gross <agross@...nel.org>,
	Alim Akhtar <alim.akhtar@...sung.com>,
	Alyssa Rosenzweig <alyssa@...enzweig.io>,
	Bjorn Andersson <andersson@...nel.org>,
	AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
	asahi@...ts.linux.dev,
	Baolin Wang <baolin.wang@...ux.alibaba.com>,
	devicetree@...r.kernel.org,
	Frank Rowand <frowand.list@...il.com>,
	Hanjun Guo <guohanjun@...wei.com>,
	"Gustavo A. R. Silva" <gustavoars@...nel.org>,
	Heiko Stuebner <heiko@...ech.de>,
	iommu@...ts.linux.dev,
	Jean-Philippe Brucker <jean-philippe@...aro.org>,
	Jernej Skrabec <jernej.skrabec@...il.com>,
	Jonathan Hunter <jonathanh@...dia.com>,
	Joerg Roedel <joro@...tes.org>,
	Kees Cook <keescook@...omium.org>,
	Konrad Dybcio <konrad.dybcio@...aro.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>,
	Len Brown <lenb@...nel.org>,
	linux-acpi@...r.kernel.org,
	linux-arm-kernel@...ts.infradead.org,
	linux-arm-msm@...r.kernel.org,
	linux-hardening@...r.kernel.org,
	linux-mediatek@...ts.infradead.org,
	linux-rockchip@...ts.infradead.org,
	linux-samsung-soc@...r.kernel.org,
	linux-sunxi@...ts.linux.dev,
	linux-tegra@...r.kernel.org,
	Lorenzo Pieralisi <lpieralisi@...nel.org>,
	Marek Szyprowski <m.szyprowski@...sung.com>,
	Hector Martin <marcan@...can.st>,
	Matthias Brugger <matthias.bgg@...il.com>,
	Orson Zhai <orsonzhai@...il.com>,
	"Rafael J. Wysocki" <rafael@...nel.org>,
	Rob Clark <robdclark@...il.com>,
	Robert Moore <robert.moore@...el.com>,
	Rob Herring <robh+dt@...nel.org>,
	Robin Murphy <robin.murphy@....com>,
	Samuel Holland <samuel@...lland.org>,
	Sudeep Holla <sudeep.holla@....com>,
	Sven Peter <sven@...npeter.dev>,
	Thierry Reding <thierry.reding@...il.com>,
	Krishna Reddy <vdumpa@...dia.com>,
	virtualization@...ts.linux.dev,
	Chen-Yu Tsai <wens@...e.org>,
	Will Deacon <will@...nel.org>,
	Yong Wu <yong.wu@...iatek.com>,
	Chunyan Zhang <zhang.lyra@...il.com>
Cc: André Draszik <andre.draszik@...aro.org>,
	patches@...ts.linux.dev
Subject: [PATCH 06/30] iommu: Make iommu_ops_from_fwnode() return the iommu_device

Return the entire struct iommu_device instead of just the ops. Name
the changed function iommu_device_from_fwnode().

The iommu_device pointer is kept valid because this is always called
under the iommu_probe_device_lock.

If iommu_device is valid then ops is valid too, the module refcounting
is pointless. Remove it.

Signed-off-by: Jason Gunthorpe <jgg@...dia.com>
---
 drivers/acpi/arm64/iort.c    | 12 +++++++-----
 drivers/acpi/viot.c          |  9 +++++----
 drivers/iommu/iommu.c        | 20 +++++++++++++-------
 drivers/iommu/of_iommu.c     | 16 ++++++----------
 include/linux/iommu-driver.h |  3 +++
 include/linux/iommu.h        |  7 -------
 6 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index 93e30f2f5004f0..798c0b344f4be8 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -797,6 +797,8 @@ void acpi_configure_pmsi_domain(struct device *dev)
 }
 
 #ifdef CONFIG_IOMMU_API
+#include <linux/iommu-driver.h>
+
 static void iort_rmr_free(struct device *dev,
 			  struct iommu_resv_region *region)
 {
@@ -1242,7 +1244,7 @@ static int iort_iommu_xlate(struct acpi_iort_node *node, u32 streamid,
 			    void *info)
 {
 	struct device *dev = info;
-	const struct iommu_ops *ops;
+	struct iommu_device *iommu;
 	struct fwnode_handle *iort_fwnode;
 
 	if (!node)
@@ -1253,19 +1255,19 @@ static int iort_iommu_xlate(struct acpi_iort_node *node, u32 streamid,
 		return -ENODEV;
 
 	/*
-	 * If the ops look-up fails, this means that either
+	 * If the iommu look-up fails, this means that either
 	 * the SMMU drivers have not been probed yet or that
 	 * the SMMU drivers are not built in the kernel;
 	 * Depending on whether the SMMU drivers are built-in
 	 * in the kernel or not, defer the IOMMU configuration
 	 * or just abort it.
 	 */
-	ops = iommu_ops_from_fwnode(iort_fwnode);
-	if (!ops)
+	iommu = iommu_device_from_fwnode(iort_fwnode);
+	if (!iommu)
 		return iort_iommu_driver_enabled(node->type) ?
 		       -EPROBE_DEFER : -ENODEV;
 
-	return acpi_iommu_fwspec_init(dev, streamid, iort_fwnode, ops);
+	return acpi_iommu_fwspec_init(dev, streamid, iort_fwnode, iommu->ops);
 }
 
 struct iort_pci_alias_info {
diff --git a/drivers/acpi/viot.c b/drivers/acpi/viot.c
index 7ab35ef05c84e0..9780b1d477503e 100644
--- a/drivers/acpi/viot.c
+++ b/drivers/acpi/viot.c
@@ -21,6 +21,7 @@
 #include <linux/acpi_viot.h>
 #include <linux/fwnode.h>
 #include <linux/iommu.h>
+#include <linux/iommu-driver.h>
 #include <linux/list.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
@@ -299,7 +300,7 @@ void __init acpi_viot_init(void)
 
 static int viot_dev_iommu_init(struct viot_iommu *viommu, u32 epid, void *info)
 {
-	const struct iommu_ops *ops;
+	struct iommu_device *iommu;
 	struct device *dev = info;
 
 	if (!viommu)
@@ -309,12 +310,12 @@ static int viot_dev_iommu_init(struct viot_iommu *viommu, u32 epid, void *info)
 	if (device_match_fwnode(dev, viommu->fwnode))
 		return -EINVAL;
 
-	ops = iommu_ops_from_fwnode(viommu->fwnode);
-	if (!ops)
+	iommu = iommu_device_from_fwnode(viommu->fwnode);
+	if (!iommu)
 		return IS_ENABLED(CONFIG_VIRTIO_IOMMU) ?
 			-EPROBE_DEFER : -ENODEV;
 
-	return acpi_iommu_fwspec_init(dev, epid, viommu->fwnode, ops);
+	return acpi_iommu_fwspec_init(dev, epid, viommu->fwnode, iommu->ops);
 }
 
 struct viot_pci_iommu_alias_info {
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 76b245973cfafc..45e6543748fd46 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -520,13 +520,19 @@ static int __iommu_probe_device(struct iommu_probe_info *pinf)
 	 * ops for probing, and thus cheekily co-opt the same mechanism.
 	 */
 	fwspec = dev_iommu_fwspec_get(dev);
-	if (fwspec && fwspec->ops)
+	if (fwspec && fwspec->ops) {
 		ops = fwspec->ops;
-	else
-		ops = iommu_ops_from_fwnode(NULL);
+		if (!ops)
+			return -ENODEV;
+	} else {
+		struct iommu_device *iommu;
+
+		iommu = iommu_device_from_fwnode(NULL);
+		if (!iommu)
+			return -ENODEV;
+		ops = iommu->ops;
+	}
 
-	if (!ops)
-		return -ENODEV;
 	/*
 	 * Serialise to avoid races between IOMMU drivers registering in
 	 * parallel and/or the "replay" calls from ACPI/OF code via client
@@ -2997,7 +3003,7 @@ bool iommu_default_passthrough(void)
 }
 EXPORT_SYMBOL_GPL(iommu_default_passthrough);
 
-const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
+struct iommu_device *iommu_device_from_fwnode(struct fwnode_handle *fwnode)
 {
 	struct iommu_device *iommu;
 
@@ -3005,7 +3011,7 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
 
 	list_for_each_entry(iommu, &iommu_device_list, list)
 		if (iommu->fwnode == fwnode)
-			return iommu->ops;
+			return iommu;
 	return NULL;
 }
 
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index fb743ddd239e0b..cf68cdebc9f318 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -21,16 +21,16 @@
 static int of_iommu_xlate(struct of_phandle_args *iommu_spec, void *info)
 {
 	struct device *dev = info;
-	const struct iommu_ops *ops;
+	struct iommu_device *iommu;
 	struct fwnode_handle *fwnode = &iommu_spec->np->fwnode;
 	int ret;
 
-	ops = iommu_ops_from_fwnode(fwnode);
-	if ((ops && !ops->of_xlate) ||
+	iommu = iommu_device_from_fwnode(fwnode);
+	if ((iommu && !iommu->ops->of_xlate) ||
 	    !of_device_is_available(iommu_spec->np))
 		return -ENODEV;
 
-	ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops);
+	ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, iommu->ops);
 	if (ret)
 		return ret;
 	/*
@@ -38,14 +38,10 @@ static int of_iommu_xlate(struct of_phandle_args *iommu_spec, void *info)
 	 * IOMMU device we're waiting for, which will be useful if we ever get
 	 * a proper probe-ordering dependency mechanism in future.
 	 */
-	if (!ops)
+	if (!iommu)
 		return driver_deferred_probe_check_state(dev);
 
-	if (!try_module_get(ops->owner))
-		return -ENODEV;
-
-	ret = ops->of_xlate(dev, iommu_spec);
-	module_put(ops->owner);
+	ret = iommu->ops->of_xlate(dev, iommu_spec);
 	return ret;
 }
 
diff --git a/include/linux/iommu-driver.h b/include/linux/iommu-driver.h
index b85c9f15cf478b..636b5b5f18f76f 100644
--- a/include/linux/iommu-driver.h
+++ b/include/linux/iommu-driver.h
@@ -14,6 +14,8 @@
 
 #include <linux/types.h>
 
+struct fwnode_handle;
+
 struct iommu_probe_info {
 	struct device *dev;
 	struct list_head *deferred_group_list;
@@ -21,5 +23,6 @@ struct iommu_probe_info {
 };
 
 int iommu_probe_device_pinf(struct iommu_probe_info *pinf);
+struct iommu_device *iommu_device_from_fwnode(struct fwnode_handle *fwnode);
 
 #endif
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index cf578b8e0b59a4..f0aaf55db3c09b 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -819,7 +819,6 @@ int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
 		      const struct iommu_ops *ops);
 void iommu_fwspec_free(struct device *dev);
 int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
-const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode);
 
 static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev)
 {
@@ -1168,12 +1167,6 @@ static inline int iommu_fwspec_add_ids(struct device *dev, u32 *ids,
 	return -ENODEV;
 }
 
-static inline
-const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
-{
-	return NULL;
-}
-
 static inline int
 iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat)
 {
-- 
2.42.0


Powered by blists - more mailing lists