All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Robin Murphy <robin.murphy@arm.com>,
	Serge Semin <Sergey.Semin@baikalelectronics.ru>,
	Rob Herring <robh@kernel.org>, Sasha Levin <sashal@kernel.org>,
	robh+dt@kernel.org, frowand.list@gmail.com,
	devicetree@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 12/16] of: Fix "dma-ranges" handling for bus controllers
Date: Mon, 17 Oct 2022 20:10:25 -0400	[thread overview]
Message-ID: <20221018001029.2731620-12-sashal@kernel.org> (raw)
In-Reply-To: <20221018001029.2731620-1-sashal@kernel.org>

From: Robin Murphy <robin.murphy@arm.com>

[ Upstream commit f1ad5338a4d57fe1fe6475003acb8c70bf9d1bdf ]

Commit 951d48855d86 ("of: Make of_dma_get_range() work on bus nodes")
relaxed the handling of "dma-ranges" for any leaf node on the assumption
that it would still represent a usage error for the property to be
present on a non-bus leaf node. However there turns out to be a fiddly
case where a bus also represents a DMA-capable device in its own right,
such as a PCIe root complex with an integrated DMA engine on its
platform side. In such cases, "dma-ranges" translation is entirely valid
for devices discovered behind the bus, but should not be erroneously
applied to the bus controller device itself which operates in its
parent's address space. Fix this by restoring the previous behaviour for
the specific case where a device is configured via its own OF node,
since it is logical to assume that a device should never represent its
own parent bus.

Reported-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/112e8f3d3e7c054ecf5e12b5ac0aa5596ec00681.1664455433.git.robin.murphy@arm.com
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/of/address.c    | 4 +++-
 drivers/of/device.c     | 9 ++++++++-
 drivers/of/of_private.h | 5 +++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 73ddf2540f3f..fdacf6c3c91f 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -626,7 +626,8 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
 }
 EXPORT_SYMBOL(of_translate_address);
 
-static struct device_node *__of_get_dma_parent(const struct device_node *np)
+#ifdef CONFIG_HAS_DMA
+struct device_node *__of_get_dma_parent(const struct device_node *np)
 {
 	struct of_phandle_args args;
 	int ret, index;
@@ -643,6 +644,7 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np)
 
 	return of_node_get(args.np);
 }
+#endif
 
 static struct device_node *of_get_next_dma_parent(struct device_node *np)
 {
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 1122daa8e273..f760199abda6 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -93,12 +93,19 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 {
 	const struct iommu_ops *iommu;
 	const struct bus_dma_region *map = NULL;
+	struct device_node *bus_np;
 	u64 dma_start = 0;
 	u64 mask, end, size = 0;
 	bool coherent;
 	int ret;
 
-	ret = of_dma_get_range(np, &map);
+	if (np == dev->of_node)
+		bus_np = __of_get_dma_parent(np);
+	else
+		bus_np = of_node_get(np);
+
+	ret = of_dma_get_range(bus_np, &map);
+	of_node_put(bus_np);
 	if (ret < 0) {
 		/*
 		 * For legacy reasons, we have to assume some devices need
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index d9e6a324de0a..ffc2099935f5 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -161,12 +161,17 @@ struct bus_dma_region;
 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
 int of_dma_get_range(struct device_node *np,
 		const struct bus_dma_region **map);
+struct device_node *__of_get_dma_parent(const struct device_node *np);
 #else
 static inline int of_dma_get_range(struct device_node *np,
 		const struct bus_dma_region **map)
 {
 	return -ENODEV;
 }
+static inline struct device_node *__of_get_dma_parent(const struct device_node *np)
+{
+	return of_get_parent(np);
+}
 #endif
 
 #endif /* _LINUX_OF_PRIVATE_H */
-- 
2.35.1


  parent reply	other threads:[~2022-10-18  0:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18  0:10 [PATCH AUTOSEL 5.10 01/16] crypto: qcom-rng - Fix qcom_rng_of_match unused warning Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 02/16] crypto: ccp - Add a quirk to firmware update Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 03/16] gfs2: Switch from strlcpy to strscpy Sasha Levin
2022-10-18  0:10   ` [Cluster-devel] " Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 04/16] powerpc/hw_breakpoint: Avoid relying on caller synchronization Sasha Levin
2022-10-18  0:10   ` Sasha Levin
2022-10-18  9:35   ` Pavel Machek
2022-10-18  9:35     ` Pavel Machek
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 05/16] cgroup: Remove data-race around cgrp_dfl_visible Sasha Levin
2022-10-18  0:10   ` Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 06/16] of/fdt: Don't calculate initrd size from DT if start > end Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 07/16] objtool,x86: Teach decode about LOOP* instructions Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 08/16] gfs2: Check sb_bsize_shift after reading superblock Sasha Levin
2022-10-18  0:10   ` [Cluster-devel] " Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 09/16] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined Sasha Levin
2022-10-18  0:10   ` Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 10/16] m68knommu: fix non-specific 68328 choice interrupt build failure Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 11/16] m68knommu: fix non-mmu classic 68000 legacy timer tick selection Sasha Levin
2022-10-18  0:10 ` Sasha Levin [this message]
2022-10-20 13:19   ` [PATCH AUTOSEL 5.10 12/16] of: Fix "dma-ranges" handling for bus controllers Rob Herring
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 13/16] kmsan: disable physical page merging in biovec Sasha Levin
2022-10-18  9:34   ` Pavel Machek
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 14/16] 9p: trans_fd/p9_conn_cancel: drop client lock earlier Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 15/16] 9p/trans_fd: always use O_NONBLOCK read/write Sasha Levin
2022-10-18  0:10 ` [PATCH AUTOSEL 5.10 16/16] virtio_pci: don't try to use intxif pin is zero Sasha Levin
2022-10-18  0:10   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018001029.2731620-12-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.