* [PATCH] iommu/riscv: Stop polling when CQCSR reports an error
@ 2026-02-27 11:26 fangyu.yu
2026-03-17 12:56 ` Jörg Rödel
0 siblings, 1 reply; 2+ messages in thread
From: fangyu.yu @ 2026-02-27 11:26 UTC (permalink / raw)
To: tjeznach, joro, will, robin.murphy, pjw, palmer, aou, alex,
andrew.jones, baolu.lu, zong.li
Cc: guoren, iommu, linux-kernel, linux-riscv, Fangyu Yu
From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
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")
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
---
drivers/iommu/riscv/iommu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
index fa2ebfd2f912..5d7e49ef7ebb 100644
--- a/drivers/iommu/riscv/iommu.c
+++ b/drivers/iommu/riscv/iommu.c
@@ -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);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iommu/riscv: Stop polling when CQCSR reports an error
2026-02-27 11:26 [PATCH] iommu/riscv: Stop polling when CQCSR reports an error fangyu.yu
@ 2026-03-17 12:56 ` Jörg Rödel
0 siblings, 0 replies; 2+ messages in thread
From: Jörg Rödel @ 2026-03-17 12:56 UTC (permalink / raw)
To: fangyu.yu
Cc: tjeznach, will, robin.murphy, pjw, palmer, aou, alex,
andrew.jones, baolu.lu, zong.li, guoren, iommu, linux-kernel,
linux-riscv
On Fri, Feb 27, 2026 at 07:26:40PM +0800, fangyu.yu@linux.alibaba.com wrote:
> From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
>
> 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")
> Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
> ---
> drivers/iommu/riscv/iommu.c | 3 +++
> 1 file changed, 3 insertions(+)
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-17 12:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 11:26 [PATCH] iommu/riscv: Stop polling when CQCSR reports an error fangyu.yu
2026-03-17 12:56 ` Jörg Rödel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox