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  linux-cve-announce  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:36 -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 29/30] iommu: Check for EPROBE_DEFER using the new FW parsers

The last thing the iommu_fwspec logic is doing is to generate an
EPROBE_DEFER if we don't have the iommu driver loaded. The OF side does
this by checking for the iommus OF property and the ACPI side does this by
checking both VIOT and IORT tables.

Duplicate this behavior. If probing gets -ENODEV and we are under a
dma_configure then ensure that all the applicable FW parsers are given a
chance to run.

Keep track of any parsers that may have run during the probe ops call and
don't do them again.

Signed-off-by: Jason Gunthorpe <jgg@...dia.com>
---
 drivers/iommu/iommu.c        | 51 +++++++++++++++++++++++++++++++++---
 drivers/iommu/iort_iommu.c   |  1 +
 drivers/iommu/of_iommu.c     |  2 ++
 drivers/iommu/viot_iommu.c   |  1 +
 include/linux/iommu-driver.h |  3 +++
 5 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 54e3f14429b3b4..c76edc9061f123 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -518,6 +518,48 @@ static void iommu_deinit_device(struct device *dev)
 	dev_iommu_free(dev);
 }
 
+/*
+ * When being called from dma_configure it is necessary to check if an ENODEV
+ * result indicates that we haven't loaded the driver yet. Since we may not have
+ * any drivers registered yet we have no way to predict what kind of FW
+ * description could need to be parsed. Check the widely used ones we have
+ * common parsers for.
+ *
+ * Drivers that use FW descriptions other than these common ones (AMD, Intel,
+ * etc) must probe the iommus during early boot otherwise they will have
+ * problems with probe ordering.
+ *
+ * The *_get_single_iommu() implementations will generate EPROBE_DEFER if they
+ * detect a FW description with no registered iommu driver which will cause
+ * the driver binding from dma_configure to abort and try later.
+ */
+static int iommu_fw_check_deferred(struct iommu_probe_info *pinf)
+{
+	struct iommu_device *iommu;
+
+	if (!pinf->is_dma_configure)
+		return -ENODEV;
+
+	if (!pinf->cached_checked_of && pinf->of_master_np) {
+		iommu = __iommu_of_get_single_iommu(pinf, NULL, -1);
+		if (iommu != ERR_PTR(-ENODEV))
+			return PTR_ERR(iommu);
+	}
+
+	if (!pinf->cached_checked_iort && pinf->is_acpi) {
+		iommu = __iommu_iort_get_single_iommu(pinf, NULL, NULL);
+		if (iommu != ERR_PTR(-ENODEV))
+			return PTR_ERR(iommu);
+	}
+
+	if (!pinf->cached_checked_viot && pinf->is_acpi) {
+		iommu = __iommu_viot_get_single_iommu(pinf, NULL);
+		if (iommu != ERR_PTR(-ENODEV))
+			return PTR_ERR(iommu);
+	}
+	return -ENODEV;
+}
+
 DEFINE_MUTEX(iommu_probe_device_lock);
 
 static int iommu_find_init_device(struct iommu_probe_info *pinf)
@@ -540,7 +582,7 @@ static int iommu_find_init_device(struct iommu_probe_info *pinf)
 				return ret;
 		}
 	}
-	return -ENODEV;
+	return iommu_fw_check_deferred(pinf);
 }
 
 static int __iommu_probe_device(struct iommu_probe_info *pinf)
@@ -580,10 +622,13 @@ static int __iommu_probe_device(struct iommu_probe_info *pinf)
 	if (dev->iommu_group)
 		return 0;
 
-	if (ops)
+	if (ops) {
 		ret = iommu_init_device(pinf, ops);
-	else
+		if (ret == -ENODEV)
+			return iommu_fw_check_deferred(pinf);
+	} else {
 		ret = iommu_find_init_device(pinf);
+	}
 	if (ret)
 		return ret;
 
diff --git a/drivers/iommu/iort_iommu.c b/drivers/iommu/iort_iommu.c
index 9a997b0fd5d5f1..2174ae477486a6 100644
--- a/drivers/iommu/iort_iommu.c
+++ b/drivers/iommu/iort_iommu.c
@@ -88,6 +88,7 @@ __iommu_iort_get_single_iommu(struct iommu_probe_info *pinf,
 		params = &unused_params;
 
 	iommu_fw_clear_cache(pinf);
+	pinf->cached_checked_iort = true;
 	err = iort_iommu_for_each_id(pinf->dev, pinf->acpi_map_id, params,
 				     parse_single_iommu, &info);
 	if (err)
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index 6f6e442f899ded..463d17ab5057d6 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -367,6 +367,7 @@ struct iommu_device *__iommu_of_get_single_iommu(struct iommu_probe_info *pinf,
 		return ERR_PTR(-ENODEV);
 
 	iommu_fw_clear_cache(pinf);
+	pinf->cached_checked_of = true;
 	err = of_iommu_for_each_id(pinf->dev, pinf->of_master_np,
 				   pinf->of_map_id, parse_single_iommu, &info);
 	if (err)
@@ -412,6 +413,7 @@ int iommu_of_xlate(struct iommu_probe_info *pinf, const struct iommu_ops *ops,
 				   .priv = priv };
 
 	pinf->num_ids = 0;
+	pinf->cached_checked_of = true;
 	return of_iommu_for_each_id(pinf->dev, pinf->of_master_np,
 				    pinf->of_map_id, parse_of_xlate, &info);
 }
diff --git a/drivers/iommu/viot_iommu.c b/drivers/iommu/viot_iommu.c
index e35bd4099e6c6a..32abda73eb3b6c 100644
--- a/drivers/iommu/viot_iommu.c
+++ b/drivers/iommu/viot_iommu.c
@@ -61,6 +61,7 @@ __iommu_viot_get_single_iommu(struct iommu_probe_info *pinf,
 		return ERR_PTR(-ENODEV);
 
 	iommu_fw_clear_cache(pinf);
+	pinf->cached_checked_viot = true;
 	err = viot_iommu_for_each_id(pinf->dev, parse_single_iommu, &info);
 	if (err)
 		return ERR_PTR(err);
diff --git a/include/linux/iommu-driver.h b/include/linux/iommu-driver.h
index 8f7089d3bb7135..aa4cbf0cb91907 100644
--- a/include/linux/iommu-driver.h
+++ b/include/linux/iommu-driver.h
@@ -50,6 +50,9 @@ struct iommu_probe_info {
 	bool is_dma_configure : 1;
 	bool is_acpi : 1;
 	bool cached_single_iommu : 1;
+	bool cached_checked_of : 1;
+	bool cached_checked_iort : 1;
+	bool cached_checked_viot : 1;
 };
 
 static inline void iommu_fw_clear_cache(struct iommu_probe_info *pinf)
-- 
2.42.0


Powered by blists - more mailing lists