Skip to contentSkip to conversation

iommu/riscv: Stop polling when CQCSR reports an error

PATCH Applied [email protected] 3 participants 3 messages Feb 27 – Apr 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/riscv: Stop polling when CQCSR reports an error

From: Fangyu Yu <[email protected]>

The cmdq wait loop busy-polls the consumer index until it advances or the software timeout expires. If the IOMMU has already signaled a command queue failure in CQCSR, continuing to poll for progress is pointless.

Make riscv_iommu_queue_wait() also terminate the poll when any of these CQCSR error bits are observed.

This helps the caller return earlier in failure cases and avoids spinning until the full timeout interval when the hardware has already reported an error. On single-core systems in particular, the current busy-wait can delay servicing the command-timeout interrupt until the software timeout expires (90s by default).

Fixes 856c0cfe5c5f ("iommu/riscv: Command and fault queue support")
---
 drivers/iommu/riscv/iommu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/riscv/iommu.c +3 -0
index fa2ebfd2f912..5d7e49ef7ebb 100644
@@ -368,6 +368,8 @@ static int riscv_iommu_queue_wait(struct riscv_iommu_queue *queue,
 				  unsigned int timeout_us)
 {
 	unsigned int cons = atomic_read(&queue->head);
+	unsigned int flags = RISCV_IOMMU_CQCSR_CQMF | RISCV_IOMMU_CQCSR_CMD_TO |
+			     RISCV_IOMMU_CQCSR_CMD_ILL;
 
 	/* Already processed by the consumer */
 	if ((int)(cons - index) > 0)
@@ -375,6 +377,7 @@ static int riscv_iommu_queue_wait(struct riscv_iommu_queue *queue,
 
 	/* Monitor consumer index */
 	return readx_poll_timeout(riscv_iommu_queue_cons, queue, cons,
+				 (riscv_iommu_readl(queue->iommu, queue->qcr) & flags) ||
 				 (int)(cons - index) > 0, 0, timeout_us);
 }
 
Signature · 1 line
2.50.1
maintainer Applied
#1 lore raw
Quoted 16 lines · On Fri, Feb 27, 2026 at 07:26:40PM +0800, [email protected] wrote:

From: Fangyu Yu <[email protected]>

The cmdq wait loop busy-polls the consumer index until it advances or the software timeout expires. If the IOMMU has already signaled a command queue failure in CQCSR, continuing to poll for progress is pointless.

Make riscv_iommu_queue_wait() also terminate the poll when any of these CQCSR error bits are observed.

This helps the caller return earlier in failure cases and avoids spinning until the full timeout interval when the hardware has already reported an error. On single-core systems in particular, the current busy-wait can delay servicing the command-timeout interrupt until the software timeout expires (90s by default).

Quoted 5 lines
Fixes 856c0cfe5c5f ("iommu/riscv: Command and fault queue support")
---
 drivers/iommu/riscv/iommu.c | 3 +++
 1 file changed, 3 insertions(+)

Applied, thanks.

#2 lore raw
In reply to [email protected]
This patch was applied to riscv/linux.git (fixes) by Joerg Roedel <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Joerg Roedel <[email protected]>:

Quoted 8 lines · On Fri, 27 Feb 2026 19:26:40 +0800 you wrote:

From: Fangyu Yu <[email protected]>

The cmdq wait loop busy-polls the consumer index until it advances or the software timeout expires. If the IOMMU has already signaled a command queue failure in CQCSR, continuing to poll for progress is pointless.

[...]

Here is the summary with links:
- iommu/riscv: Stop polling when CQCSR reports an error

    https://git.kernel.org/riscv/c/b2e5684558ed

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html