Skip to contentSkip to conversation

iommu/rockchip: Disable paging on banks that still page before a force reset

PATCH In review Jiaxing Hu 2 participants 2 messages Nov 23 – Nov 24

Subsystems (2)
lore
Share & tools
lore

Jiaxing Hu

author
#0 lore raw

PATCH 1/1 iommu/rockchip: Disable paging on banks that still page before a force reset

After an RK3576 NPU job timeout resets the core, the banks of its IOMMU can be left in different states: bank 0 is still paging while bank 1 has been reset.

In this state the existing stall and paging helpers do nothing, so the force reset that follows fails as well. The IOMMU can then no longer be enabled, and the NPU stops working.

When the banks disagree, stop paging on the banks that still page first, then run the existing sequence.

Tested on a ROCK 4D with repeated forced job timeouts. Without this patch, one in every 2 to 10 timeouts was not recovered from; with it, 20 out of 20 recovered.

Fixes cd6438c5f844 ("iommu/rockchip: Reconstruct to support multi slaves")

---
Not tested on the RK3588.

LLM-assisted.

 drivers/iommu/rockchip-iommu.c | 61 ++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/iommu/rockchip-iommu.c +61 -0
index 1fa3110b142a..5eabefb0ad14 100644
@@ -507,6 +507,64 @@ static int rk_iommu_disable_paging(struct rk_iommu *iommu)
 	return ret;
 }
 
+/*
+ * The helpers above only act when every bank agrees. After a reset of the
+ * master, one bank can still be paging; stop it bank by bank.
+ */
+static void rk_iommu_quiesce_paging_banks(struct rk_iommu *iommu)
+{
+	int i, ret;
+	u32 status;
+
+	for (i = 0; i < iommu->num_mmu; i++) {
+		void __iomem *base = iommu->bases[i];
+
+		if (!(rk_iommu_read(base, RK_MMU_STATUS) & RK_MMU_STATUS_PAGING_ENABLED))
+			continue;
+
+		dev_warn_ratelimited(iommu->dev, "bank %d still paging, status %#08x; disabling it\n",
+				     i, rk_iommu_read(base, RK_MMU_STATUS));
+
+		if (rk_iommu_read(base, RK_MMU_STATUS) & RK_MMU_STATUS_PAGE_FAULT_ACTIVE)
+			writel(RK_MMU_CMD_PAGE_FAULT_DONE, base + RK_MMU_COMMAND);
+
+		rk_iommu_base_command(base, RK_MMU_CMD_ENABLE_STALL);
+		ret = readl_poll_timeout(base + RK_MMU_STATUS, status,
+					 status & RK_MMU_STATUS_STALL_ACTIVE,
+					 RK_MMU_POLL_PERIOD_US, RK_MMU_POLL_TIMEOUT_US);
+		if (ret)
+			dev_err(iommu->dev, "bank %d: stall timed out, status %#08x\n",
+				i, status);
+
+		rk_iommu_base_command(base, RK_MMU_CMD_DISABLE_PAGING);
+		ret = readl_poll_timeout(base + RK_MMU_STATUS, status,
+					 !(status & RK_MMU_STATUS_PAGING_ENABLED),
+					 RK_MMU_POLL_PERIOD_US, RK_MMU_POLL_TIMEOUT_US);
+		if (ret)
+			dev_err(iommu->dev, "bank %d: disable paging timed out, status %#08x\n",
+				i, status);
+
+		rk_iommu_base_command(base, RK_MMU_CMD_DISABLE_STALL);
+		ret = readl_poll_timeout(base + RK_MMU_STATUS, status,
+					 !(status & RK_MMU_STATUS_STALL_ACTIVE),
+					 RK_MMU_POLL_PERIOD_US, RK_MMU_POLL_TIMEOUT_US);
+		if (ret)
+			dev_err(iommu->dev, "bank %d: disable stall timed out, status %#08x\n",
+				i, status);
+	}
+}
+
+static bool rk_iommu_banks_disagree_on_paging(struct rk_iommu *iommu)
+{
+	int i, n = 0;
+
+	for (i = 0; i < iommu->num_mmu; i++)
+		n += !!(rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) &
+			RK_MMU_STATUS_PAGING_ENABLED);
+
+	return n && n != iommu->num_mmu;
+}
+
 static int rk_iommu_force_reset(struct rk_iommu *iommu)
 {
 	int ret, i;
@@ -947,6 +1005,9 @@ static int rk_iommu_enable(struct rk_iommu *iommu)
 	if (ret)
 		return ret;
 
+	if (rk_iommu_banks_disagree_on_paging(iommu))
+		rk_iommu_quiesce_paging_banks(iommu);
+
 	ret = rk_iommu_enable_stall(iommu);
 	if (ret)
 		goto out_disable_clocks;

base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726

Signature · 1 line
2.43.0
#1 lore raw

Thanks, that description matches the end state I see, so it is worth telling you where it does and does not fit my board.

Mine is an RK3566 with a single bank. The MMU node is 0x40 bytes of registers and
the driver ends up with num_mmu = 1, so two banks cannot disagree. I took the nearest analogue of your fix that exists for a single bank, the one in the Android tree: acknowledge a latched page fault with CMD_PAGE_FAULT_DONE before sending CMD_ENABLE_STALL, because a bank sitting in PAGE_FAULT_ACTIVE with no stall ignores the stall command and the poll times out.

Measured on 6.18.24, twenty separate processes, five runs each, IOMMU mode:

- before: 3 ok, 4 wrong output, 18 timeouts (the failures are sticky, only a reboot clears them);
- with the stale-fault ack: 2 ok, 0 wrong, 18 timeouts.

No change, and more useful: dmesg has no "Enable stall request timed out" and no "Disable paging request timed out" line at all. So on my board the re-enable path
is never the one that fails.

What I see instead, at the first failure: the job is submitted, the kick registers
hold what the driver wrote, and the core never runs it. INT_RAW_STATUS reads 0x10000 while the required mask is 0x300, task counter 0. The MMU is healthy at that moment, paging enabled, no fault pending. Later failures sometimes leave a fault in the register, but the first one has none.

Two questions if you have the logs at hand:

- on your RK3576, does the hang start the same way, with a job that never executes, or does the MMU re-enable failure come first?
- do you ever see bit 0x10000 in the NPU's INT_RAW_STATUS on a hung job? I cannot
find what that bit is in the RK3566 register map, and the driver does not mask it in, so it never raises an interrupt.

For the record, the other three things I ruled out by measurement on the same board, in case one of them is what your patch really fixes: TLB staleness (full ZAP_CACHE and a domain detach/attach before every kick), cache coherency for the task and regcmd buffers, and the iova width (limiting the dma mask to 30 bits). None of them moved the failure rate.

вт, 24 нояб. 2026 г. в 02:52, Jiaxing Hu <[email protected]>:

Quoted 110 lines

After an RK3576 NPU job timeout resets the core, the banks of its IOMMU can be left in different states: bank 0 is still paging while bank 1 has been reset.

In this state the existing stall and paging helpers do nothing, so the force reset that follows fails as well. The IOMMU can then no longer be enabled, and the NPU stops working.

When the banks disagree, stop paging on the banks that still page first, then run the existing sequence.

Tested on a ROCK 4D with repeated forced job timeouts. Without this patch, one in every 2 to 10 timeouts was not recovered from; with it, 20 out of 20 recovered.

Fixes cd6438c5f844 ("iommu/rockchip: Reconstruct to support multi slaves")

---
Not tested on the RK3588.

LLM-assisted.

 drivers/iommu/rockchip-iommu.c | 61 ++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/iommu/rockchip-iommu.c +61 -0
index 1fa3110b142a..5eabefb0ad14 100644
@@ -507,6 +507,64 @@ static int rk_iommu_disable_paging(struct rk_iommu *iommu)
        return ret;
 }
 
+/*
+ * The helpers above only act when every bank agrees. After a reset of the
+ * master, one bank can still be paging; stop it bank by bank.
+ */
+static void rk_iommu_quiesce_paging_banks(struct rk_iommu *iommu)
+{
+       int i, ret;
+       u32 status;
+
+       for (i = 0; i < iommu->num_mmu; i++) {
+               void __iomem *base = iommu->bases[i];
+
+               if (!(rk_iommu_read(base, RK_MMU_STATUS) & RK_MMU_STATUS_PAGING_ENABLED))
+                       continue;
+
+               dev_warn_ratelimited(iommu->dev, "bank %d still paging, status %#08x; disabling it\n",
+                                    i, rk_iommu_read(base, RK_MMU_STATUS));
+
+               if (rk_iommu_read(base, RK_MMU_STATUS) & RK_MMU_STATUS_PAGE_FAULT_ACTIVE)
+                       writel(RK_MMU_CMD_PAGE_FAULT_DONE, base + RK_MMU_COMMAND);
+
+               rk_iommu_base_command(base, RK_MMU_CMD_ENABLE_STALL);
+               ret = readl_poll_timeout(base + RK_MMU_STATUS, status,
+                                        status & RK_MMU_STATUS_STALL_ACTIVE,
+                                        RK_MMU_POLL_PERIOD_US, RK_MMU_POLL_TIMEOUT_US);
+               if (ret)
+                       dev_err(iommu->dev, "bank %d: stall timed out, status %#08x\n",
+                               i, status);
+
+               rk_iommu_base_command(base, RK_MMU_CMD_DISABLE_PAGING);
+               ret = readl_poll_timeout(base + RK_MMU_STATUS, status,
+                                        !(status & RK_MMU_STATUS_PAGING_ENABLED),
+                                        RK_MMU_POLL_PERIOD_US, RK_MMU_POLL_TIMEOUT_US);
+               if (ret)
+                       dev_err(iommu->dev, "bank %d: disable paging timed out, status %#08x\n",
+                               i, status);
+
+               rk_iommu_base_command(base, RK_MMU_CMD_DISABLE_STALL);
+               ret = readl_poll_timeout(base + RK_MMU_STATUS, status,
+                                        !(status & RK_MMU_STATUS_STALL_ACTIVE),
+                                        RK_MMU_POLL_PERIOD_US, RK_MMU_POLL_TIMEOUT_US);
+               if (ret)
+                       dev_err(iommu->dev, "bank %d: disable stall timed out, status %#08x\n",
+                               i, status);
+       }
+}
+
+static bool rk_iommu_banks_disagree_on_paging(struct rk_iommu *iommu)
+{
+       int i, n = 0;
+
+       for (i = 0; i < iommu->num_mmu; i++)
+               n += !!(rk_iommu_read(iommu->bases[i], RK_MMU_STATUS) &
+                       RK_MMU_STATUS_PAGING_ENABLED);
+
+       return n && n != iommu->num_mmu;
+}
+
 static int rk_iommu_force_reset(struct rk_iommu *iommu)
 {
        int ret, i;
@@ -947,6 +1005,9 @@ static int rk_iommu_enable(struct rk_iommu *iommu)
        if (ret)
                return ret;
 
+       if (rk_iommu_banks_disagree_on_paging(iommu))
+               rk_iommu_quiesce_paging_banks(iommu);
+
        ret = rk_iommu_enable_stall(iommu);
        if (ret)
                goto out_disable_clocks;

base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726 --
2.43.0

Signature · 3 lines
With respect,
Anton Sovetov (co-Founder and CEO of 3d-club LLC")
https://3d-club.ru                        tel:+7 (999) 246-78-36