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:10 -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 03/30] ACPI: IORT: Make a iort_iommu_for_each_id()

Similar to of_iommu_for_each_id() this parses the IORT ACPI description
and invokes a function over each entry in the table.

Have iort_iommu_configure_id() use the new function to call
iort_iommu_xlate().

Signed-off-by: Jason Gunthorpe <jgg@...dia.com>
---
 drivers/acpi/arm64/iort.c | 118 ++++++++++++++++++++++++--------------
 include/linux/acpi_iort.h |  12 ++++
 2 files changed, 86 insertions(+), 44 deletions(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index bdaf9256870d92..5c9b4c23f96a87 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -1218,9 +1218,10 @@ static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node)
 	return pci_rc->ats_attribute & ACPI_IORT_ATS_SUPPORTED;
 }
 
-static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
-			    u32 streamid)
+static int iort_iommu_xlate(struct acpi_iort_node *node, u32 streamid,
+			    void *info)
 {
+	struct device *dev = info;
 	const struct iommu_ops *ops;
 	struct fwnode_handle *iort_fwnode;
 
@@ -1250,9 +1251,11 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node,
 struct iort_pci_alias_info {
 	struct device *dev;
 	struct acpi_iort_node *node;
+	iort_for_each_fn fn;
+	void *info;
 };
 
-static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data)
+static int __for_each_pci_alias(struct pci_dev *pdev, u16 alias, void *data)
 {
 	struct iort_pci_alias_info *info = data;
 	struct acpi_iort_node *parent;
@@ -1260,7 +1263,7 @@ static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data)
 
 	parent = iort_node_map_id(info->node, alias, &streamid,
 				  IORT_IOMMU_TYPE);
-	return iort_iommu_xlate(info->dev, parent, streamid);
+	return info->fn(parent, streamid, info->info);
 }
 
 static void iort_named_component_init(struct device *dev,
@@ -1280,7 +1283,8 @@ static void iort_named_component_init(struct device *dev,
 		dev_warn(dev, "Could not add device properties\n");
 }
 
-static int iort_nc_iommu_map(struct device *dev, struct acpi_iort_node *node)
+static int __for_each_platform(struct acpi_iort_node *node, iort_for_each_fn fn,
+			       void *info)
 {
 	struct acpi_iort_node *parent;
 	int err = -ENODEV, i = 0;
@@ -1293,27 +1297,71 @@ static int iort_nc_iommu_map(struct device *dev, struct acpi_iort_node *node)
 						   i++);
 
 		if (parent)
-			err = iort_iommu_xlate(dev, parent, streamid);
+			err = fn(parent, streamid, info);
 	} while (parent && !err);
 
 	return err;
 }
 
-static int iort_nc_iommu_map_id(struct device *dev,
-				struct acpi_iort_node *node,
-				const u32 *in_id)
+int iort_iommu_for_each_id(struct device *dev, const u32 *id_in,
+			   struct iort_params *params, iort_for_each_fn fn,
+			   void *info)
 {
-	struct acpi_iort_node *parent;
-	u32 streamid;
+	struct acpi_iort_named_component *nc;
+	struct acpi_iort_node *node;
+	int err = -ENODEV;
 
-	parent = iort_node_map_id(node, *in_id, &streamid, IORT_IOMMU_TYPE);
-	if (parent)
-		return iort_iommu_xlate(dev, parent, streamid);
+	memset(params, 0, sizeof(*params));
+	if (dev_is_pci(dev)) {
+		struct pci_bus *bus = to_pci_dev(dev)->bus;
+		struct iort_pci_alias_info pci_info = { .dev = dev,
+							.fn = fn,
+							.info = info };
 
-	return -ENODEV;
+		node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX,
+				      iort_match_node_callback, &bus->dev);
+		if (!node)
+			return -ENODEV;
+
+		pci_info.node = node;
+		err = pci_for_each_dma_alias(to_pci_dev(dev),
+					     __for_each_pci_alias, &pci_info);
+
+		if (iort_pci_rc_supports_ats(node))
+			params->pci_rc_ats = true;
+		return 0;
+	}
+
+	node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT,
+			      iort_match_node_callback, dev);
+	if (!node)
+		return -ENODEV;
+
+	if (id_in) {
+		struct acpi_iort_node *parent;
+		u32 streamid;
+
+		parent = iort_node_map_id(node, *id_in, &streamid,
+					  IORT_IOMMU_TYPE);
+		if (!parent)
+			return -ENODEV;
+		err = fn(parent, streamid, info);
+	} else {
+		err = __for_each_platform(node, fn, info);
+	}
+	if (err)
+		return err;
+
+	nc = (struct acpi_iort_named_component *)node->node_data;
+	params->pasid_num_bits = FIELD_GET(ACPI_IORT_NC_PASID_BITS,
+						nc->node_flags);
+	if (nc->node_flags & ACPI_IORT_NC_STALL_SUPPORTED)
+		params->dma_can_stall = true;
+
+	iort_named_component_init(dev, node);
+	return 0;
 }
 
-
 /**
  * iort_iommu_configure_id - Set-up IOMMU configuration for a device.
  *
@@ -1324,40 +1372,22 @@ static int iort_nc_iommu_map_id(struct device *dev,
  */
 int iort_iommu_configure_id(struct device *dev, const u32 *id_in)
 {
-	struct acpi_iort_node *node;
-	int err = -ENODEV;
+	struct iort_params params;
+	int err;
 
-	if (dev_is_pci(dev)) {
+	err = iort_iommu_for_each_id(dev, id_in, &params, &iort_iommu_xlate,
+				     dev);
+	if (err)
+		return err;
+
+	if (params.pci_rc_ats) {
 		struct iommu_fwspec *fwspec;
-		struct pci_bus *bus = to_pci_dev(dev)->bus;
-		struct iort_pci_alias_info info = { .dev = dev };
-
-		node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX,
-				      iort_match_node_callback, &bus->dev);
-		if (!node)
-			return -ENODEV;
-
-		info.node = node;
-		err = pci_for_each_dma_alias(to_pci_dev(dev),
-					     iort_pci_iommu_init, &info);
 
 		fwspec = dev_iommu_fwspec_get(dev);
-		if (fwspec && iort_pci_rc_supports_ats(node))
+		if (fwspec)
 			fwspec->flags |= IOMMU_FWSPEC_PCI_RC_ATS;
-	} else {
-		node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT,
-				      iort_match_node_callback, dev);
-		if (!node)
-			return -ENODEV;
-
-		err = id_in ? iort_nc_iommu_map_id(dev, node, id_in) :
-			      iort_nc_iommu_map(dev, node);
-
-		if (!err)
-			iort_named_component_init(dev, node);
 	}
-
-	return err;
+	return 0;
 }
 
 #else
diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h
index 1cb65592c95dd3..5423abff9b6b09 100644
--- a/include/linux/acpi_iort.h
+++ b/include/linux/acpi_iort.h
@@ -29,6 +29,18 @@ void iort_deregister_domain_token(int trans_id);
 struct fwnode_handle *iort_find_domain_token(int trans_id);
 int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id);
 
+struct iort_params {
+	unsigned int pasid_num_bits;
+	bool dma_can_stall : 1;
+	bool pci_rc_ats : 1;
+};
+
+typedef int (*iort_for_each_fn)(struct acpi_iort_node *iommu, u32 streamid,
+				void *info);
+int iort_iommu_for_each_id(struct device *dev, const u32 *id_in,
+			   struct iort_params *params, iort_for_each_fn fn,
+			   void *info);
+
 #ifdef CONFIG_ACPI_IORT
 u32 iort_msi_map_id(struct device *dev, u32 id);
 struct irq_domain *iort_get_device_domain(struct device *dev, u32 id,
-- 
2.42.0


Powered by blists - more mailing lists