Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] iommu/rockchip: page fault and reset handling fixes
@ 2026-12-03  2:38 Arun Iyengar via B4 Relay
  2026-12-03  2:38 ` [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports Arun Iyengar via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-03  2:38 UTC (permalink / raw)
  To: Joerg Roedel (AMD), Will Deacon, Robin Murphy, Heiko Stuebner,
	Jeffy Chen, Tomasz Figa
  Cc: Simon Xue, iommu, linux-arm-kernel, linux-rockchip, linux-kernel,
	Arun Iyengar

Fixes for the Rockchip IOMMU, found on an Orange Pi 5 (RK3588S) with
codec jobs that fault (Hantro VEPU121 JPEG encoder, rkvdec VDPU381):
the fault reports are rate-limited, FORCE_RESET had its poll period and
timeout swapped, and the stall/paging helpers skipped a bank whose
state differed from the other bank's.

The faulting encoder job itself is recovered by the Hantro series
"media: verisilicon: Recover the Rockchip VPUs from faults and
timeouts":
https://lore.kernel.org/r/20261113-hantro-robust-v3-0-82383c722ad2@gmail.com

Tested on the same board with bad JPEG encode jobs.

Developed with Claude (Anthropic), which wrote the code and the commit
messages. I reviewed every change.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Changes in v2:
- Drop v1 patch 1 (log_iova() on a reset IOMMU): superseded by
  b62f4603b0d5 ("iommu/rockchip: do not walk the page tables of a
  disabled MMU").
- Drop v1 patch 5 (hold the master in a fault storm): it masked the
  fault interrupt, and Sashiko found races in it; the cause is fixed in
  the Hantro series above.
- Rebase on iommu next.
- Add a Fixes tag to the bank patch (Sashiko).
- Shorter commit messages and comments.
- Link to v1: https://patch.msgid.link/20261110-iommu-rockchip-faults-v1-0-b1dda574dbb8@gmail.com

---
Arun Iyengar (3):
      iommu/rockchip: Rate-limit the page fault reports
      iommu/rockchip: Fix the poll period and timeout of FORCE_RESET
      iommu/rockchip: Don't skip a bank whose state differs from the others

 drivers/iommu/rockchip-iommu.c | 82 ++++++++++++++++++++++++++++++------------
 1 file changed, 59 insertions(+), 23 deletions(-)
---
base-commit: 052bac98639386c83fc5d6d74a645fd993855fbc
change-id: 20261110-iommu-rockchip-faults-0c1e41c33ed7

Best regards,
--  
Arun Iyengar <aiyengar1990@gmail.com>




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports
  2026-12-03  2:38 [PATCH v2 0/3] iommu/rockchip: page fault and reset handling fixes Arun Iyengar via B4 Relay
@ 2026-12-03  2:38 ` Arun Iyengar via B4 Relay
  2026-12-04  7:51   ` Joerg Roedel (AMD)
  2026-12-03  2:38 ` [PATCH v2 2/3] iommu/rockchip: Fix the poll period and timeout of FORCE_RESET Arun Iyengar via B4 Relay
  2026-12-03  2:38 ` [PATCH v2 3/3] iommu/rockchip: Don't skip a bank whose state differs from the others Arun Iyengar via B4 Relay
  2 siblings, 1 reply; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-03  2:38 UTC (permalink / raw)
  To: Joerg Roedel (AMD), Will Deacon, Robin Murphy, Heiko Stuebner,
	Jeffy Chen, Tomasz Figa
  Cc: Simon Xue, iommu, linux-arm-kernel, linux-rockchip, linux-kernel,
	Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

rk_iommu_irq() prints three lines per page fault from the hard
interrupt handler, now with iommu->lock held. A VEPU121 core on RK3588
that kept faulting took 149 faults in its 2 s timeout, and a 115200
baud console kept the CPU in the handler for about all of it.

Print at most DEFAULT_RATELIMIT_BURST reports per
DEFAULT_RATELIMIT_INTERVAL and IOMMU, BUS_ERROR included.
report_iommu_fault() is still called for every fault.

Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/iommu/rockchip-iommu.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 45d78fca6758..1509b4527be9 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -23,6 +23,7 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/ratelimit.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/string_choices.h>
@@ -117,6 +118,7 @@ struct rk_iommu {
 	struct iommu_domain *domain; /* domain to which iommu is attached */
 	spinlock_t lock;
 	const struct rk_iommu_ops *rk_ops;
+	struct ratelimit_state fault_rs; /* for the fault reports */
 };
 
 struct rk_iommudata {
@@ -606,6 +608,7 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id)
 	u32 int_status;
 	dma_addr_t iova;
 	irqreturn_t ret = IRQ_NONE;
+	bool print;
 	int i, err;
 
 	err = pm_runtime_get_if_in_use(iommu->dev);
@@ -632,11 +635,14 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id)
 			flags = (status & RK_MMU_STATUS_PAGE_FAULT_IS_WRITE) ?
 					IOMMU_FAULT_WRITE : IOMMU_FAULT_READ;
 
-			dev_err(iommu->dev, "Page fault at %pad of type %s\n",
-				&iova,
-				str_write_read(flags == IOMMU_FAULT_WRITE));
-
-			log_iova(iommu, domain, i, iova);
+			/* A faulting master faults again at once; don't print every time */
+			print = __ratelimit(&iommu->fault_rs);
+			if (print) {
+				dev_err(iommu->dev, "Page fault at %pad of type %s\n",
+					&iova,
+					str_write_read(flags == IOMMU_FAULT_WRITE));
+				log_iova(iommu, domain, i, iova);
+			}
 
 			/*
 			 * Report page fault to any installed handlers.
@@ -646,14 +652,15 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id)
 			if (domain != &rk_identity_domain)
 				report_iommu_fault(domain, iommu->dev, iova,
 						   flags);
-			else
+			else if (print)
 				dev_err(iommu->dev, "Page fault while iommu not attached to domain?\n");
 
 			rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_ZAP_CACHE);
 			rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_PAGE_FAULT_DONE);
 		}
 
-		if (int_status & RK_MMU_IRQ_BUS_ERROR)
+		if ((int_status & RK_MMU_IRQ_BUS_ERROR) &&
+		    __ratelimit(&iommu->fault_rs))
 			dev_err(iommu->dev, "BUS_ERROR occurred at %pad\n", &iova);
 
 		if (int_status & ~RK_MMU_IRQ_MASK)
@@ -1278,6 +1285,8 @@ static int rk_iommu_probe(struct platform_device *pdev)
 
 	iommu->reset_disabled = device_property_read_bool(dev,
 					"rockchip,disable-mmu-reset");
+	ratelimit_state_init(&iommu->fault_rs, DEFAULT_RATELIMIT_INTERVAL,
+			     DEFAULT_RATELIMIT_BURST);
 
 	/*
 	 * Take every clock the devicetree provides.  Most IOMMU instances

-- 
2.55.0




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] iommu/rockchip: Fix the poll period and timeout of FORCE_RESET
  2026-12-03  2:38 [PATCH v2 0/3] iommu/rockchip: page fault and reset handling fixes Arun Iyengar via B4 Relay
  2026-12-03  2:38 ` [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports Arun Iyengar via B4 Relay
@ 2026-12-03  2:38 ` Arun Iyengar via B4 Relay
  2026-12-03  2:38 ` [PATCH v2 3/3] iommu/rockchip: Don't skip a bank whose state differs from the others Arun Iyengar via B4 Relay
  2 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-03  2:38 UTC (permalink / raw)
  To: Joerg Roedel (AMD), Will Deacon, Robin Murphy, Heiko Stuebner,
	Jeffy Chen, Tomasz Figa
  Cc: Simon Xue, iommu, linux-arm-kernel, linux-rockchip, linux-kernel,
	Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

rk_iommu_force_reset() passes the 100 ms timeout as the poll period and
the 1 ms poll timeout as the timeout. A reset that is not done at the
first read sleeps 25-100 ms, reads once more and gives up.

Poll every RK_MMU_POLL_PERIOD_US for up to RK_MMU_FORCE_RESET_TIMEOUT_US.

Fixes: 0416bf6479ac ("iommu/rockchip: Use iopoll helpers to wait for hardware")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/iommu/rockchip-iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 1509b4527be9..103e1f957260 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -536,8 +536,8 @@ static int rk_iommu_force_reset(struct rk_iommu *iommu)
 	rk_iommu_command(iommu, RK_MMU_CMD_FORCE_RESET);
 
 	ret = readx_poll_timeout(rk_iommu_is_reset_done, iommu, val,
-				 val, RK_MMU_FORCE_RESET_TIMEOUT_US,
-				 RK_MMU_POLL_TIMEOUT_US);
+				 val, RK_MMU_POLL_PERIOD_US,
+				 RK_MMU_FORCE_RESET_TIMEOUT_US);
 	if (ret) {
 		dev_err(iommu->dev, "FORCE_RESET command timed out\n");
 		return ret;

-- 
2.55.0




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] iommu/rockchip: Don't skip a bank whose state differs from the others
  2026-12-03  2:38 [PATCH v2 0/3] iommu/rockchip: page fault and reset handling fixes Arun Iyengar via B4 Relay
  2026-12-03  2:38 ` [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports Arun Iyengar via B4 Relay
  2026-12-03  2:38 ` [PATCH v2 2/3] iommu/rockchip: Fix the poll period and timeout of FORCE_RESET Arun Iyengar via B4 Relay
@ 2026-12-03  2:38 ` Arun Iyengar via B4 Relay
  2 siblings, 0 replies; 5+ messages in thread
From: Arun Iyengar via B4 Relay @ 2026-12-03  2:38 UTC (permalink / raw)
  To: Joerg Roedel (AMD), Will Deacon, Robin Murphy, Heiko Stuebner,
	Jeffy Chen, Tomasz Figa
  Cc: Simon Xue, iommu, linux-arm-kernel, linux-rockchip, linux-kernel,
	Arun Iyengar

From: Arun Iyengar <aiyengar1990@gmail.com>

The state helpers AND the status of all banks, and the callers skip a
command when the banks disagree: no DISABLE_PAGING unless every bank
pages, no ENABLE_STALL when one bank is in bypass, no DISABLE_STALL
unless every bank is stalled.

The two banks of an RK3588 decoder IOMMU were read back as paging
(STATUS 0x11) and bypass (STATUS 0x18) after a FORCE_RESET that timed
out; rk_iommu_disable() then sent neither DISABLE_PAGING nor
ENABLE_STALL.

Decide per bank. Nothing changes when the banks agree.

Fixes: cd6438c5f844 ("iommu/rockchip: Reconstruct to support multi slaves")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 drivers/iommu/rockchip-iommu.c | 55 +++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 103e1f957260..99dd84d1f763 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -374,16 +374,46 @@ static void rk_iommu_zap_lines(struct rk_iommu *iommu, dma_addr_t iova_start,
 	}
 }
 
+/* Every bank that translates is stalled (a bank in bypass cannot stall). */
 static bool rk_iommu_is_stall_active(struct rk_iommu *iommu)
 {
-	bool active = true;
+	u32 status;
+	int i;
+
+	for (i = 0; i < iommu->num_mmu; i++) {
+		status = rk_iommu_read(iommu->bases[i], RK_MMU_STATUS);
+		if ((status & RK_MMU_STATUS_PAGING_ENABLED) &&
+		    !(status & RK_MMU_STATUS_STALL_ACTIVE))
+			return false;
+	}
+
+	return true;
+}
+
+/* No bank is stalled. */
+static bool rk_iommu_is_stall_inactive(struct rk_iommu *iommu)
+{
+	int i;
+
+	for (i = 0; i < iommu->num_mmu; i++)
+		if (rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) &
+		    RK_MMU_STATUS_STALL_ACTIVE)
+			return false;
+
+	return true;
+}
+
+/* No bank translates. */
+static bool rk_iommu_is_paging_disabled(struct rk_iommu *iommu)
+{
 	int i;
 
 	for (i = 0; i < iommu->num_mmu; i++)
-		active &= !!(rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) &
-					   RK_MMU_STATUS_STALL_ACTIVE);
+		if (rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) &
+		    RK_MMU_STATUS_PAGING_ENABLED)
+			return false;
 
-	return active;
+	return true;
 }
 
 static bool rk_iommu_is_paging_enabled(struct rk_iommu *iommu)
@@ -414,13 +444,10 @@ static int rk_iommu_enable_stall(struct rk_iommu *iommu)
 	int ret, i;
 	bool val;
 
+	/* Stall can only be enabled on the banks that translate */
 	if (rk_iommu_is_stall_active(iommu))
 		return 0;
 
-	/* Stall can only be enabled if paging is enabled */
-	if (!rk_iommu_is_paging_enabled(iommu))
-		return 0;
-
 	/*
 	 * Boot firmware can leave a bank in PAGE_FAULT_ACTIVE with no handler
 	 * (PAGE_FAULT_ACTIVE & !STALL_ACTIVE & IDLE).  Such a bank ignores
@@ -452,13 +479,13 @@ static int rk_iommu_disable_stall(struct rk_iommu *iommu)
 	int ret, i;
 	bool val;
 
-	if (!rk_iommu_is_stall_active(iommu))
+	if (rk_iommu_is_stall_inactive(iommu))
 		return 0;
 
 	rk_iommu_command(iommu, RK_MMU_CMD_DISABLE_STALL);
 
-	ret = readx_poll_timeout(rk_iommu_is_stall_active, iommu, val,
-				 !val, RK_MMU_POLL_PERIOD_US,
+	ret = readx_poll_timeout(rk_iommu_is_stall_inactive, iommu, val,
+				 val, RK_MMU_POLL_PERIOD_US,
 				 RK_MMU_POLL_TIMEOUT_US);
 	if (ret)
 		for (i = 0; i < iommu->num_mmu; i++)
@@ -494,13 +521,13 @@ static int rk_iommu_disable_paging(struct rk_iommu *iommu)
 	int ret, i;
 	bool val;
 
-	if (!rk_iommu_is_paging_enabled(iommu))
+	if (rk_iommu_is_paging_disabled(iommu))
 		return 0;
 
 	rk_iommu_command(iommu, RK_MMU_CMD_DISABLE_PAGING);
 
-	ret = readx_poll_timeout(rk_iommu_is_paging_enabled, iommu, val,
-				 !val, RK_MMU_POLL_PERIOD_US,
+	ret = readx_poll_timeout(rk_iommu_is_paging_disabled, iommu, val,
+				 val, RK_MMU_POLL_PERIOD_US,
 				 RK_MMU_POLL_TIMEOUT_US);
 	if (ret)
 		for (i = 0; i < iommu->num_mmu; i++)

-- 
2.55.0




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports
  2026-12-03  2:38 ` [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports Arun Iyengar via B4 Relay
@ 2026-12-04  7:51   ` Joerg Roedel (AMD)
  0 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel (AMD) @ 2026-12-04  7:51 UTC (permalink / raw)
  To: aiyengar1990
  Cc: Will Deacon, Robin Murphy, Heiko Stuebner, Jeffy Chen,
	Tomasz Figa, Simon Xue, iommu, linux-arm-kernel, linux-rockchip,
	linux-kernel

On Thu, Dec 03, 2026 at 02:38:01AM +0000, Arun Iyengar via B4 Relay wrote:
> -		if (int_status & RK_MMU_IRQ_BUS_ERROR)
> +		if ((int_status & RK_MMU_IRQ_BUS_ERROR) &&
> +		    __ratelimit(&iommu->fault_rs))
>  			dev_err(iommu->dev, "BUS_ERROR occurred at %pad\n", &iova);

Why are BUS_ERRORs rate-limited as well? A series of page-faults can then hide
the bus error from being logged. Is that intentional?

-Joerg


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04  7:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  2:38 [PATCH v2 0/3] iommu/rockchip: page fault and reset handling fixes Arun Iyengar via B4 Relay
2026-12-03  2:38 ` [PATCH v2 1/3] iommu/rockchip: Rate-limit the page fault reports Arun Iyengar via B4 Relay
2026-12-04  7:51   ` Joerg Roedel (AMD)
2026-12-03  2:38 ` [PATCH v2 2/3] iommu/rockchip: Fix the poll period and timeout of FORCE_RESET Arun Iyengar via B4 Relay
2026-12-03  2:38 ` [PATCH v2 3/3] iommu/rockchip: Don't skip a bank whose state differs from the others Arun Iyengar via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox