From nobody Tue Apr 7 18:45:29 2026 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 057E83EFD10 for ; Fri, 27 Feb 2026 11:26:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772191620; cv=none; b=egmjd+46eQsd7X0VycayfDKPU4KOod34ns0MDY1woifCN9tuOGx4fXqyIFavD11ZuZ2kvb2ho+5oKgQb4Oxy1ZbCUaqIsqSH8421ztiX9n0opY8MXMSErt50Q5KvOUXd3xBeSfi3Gwj7PAqvdYO77oEPYbco3ybMuklYlRtzFc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772191620; c=relaxed/simple; bh=gpMPMbasSK61+jjWHW8SpoJQo2GDlM2bsDGS+tXVBAE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=SZz0nwAsdhWoolxMD2SUeFh7j0Yd8yNNM6ftt6o2H0zVznldJSd/QzhgIxDE5akVbTAL9DYz/0stq2jyE4lwHDGEEmI3OjRnO6YSakF0HgFd5aHXSyA4BvINIXQ9CU3DHVc2VBgGPRauR0qQR6jkriKJSOPnGQef6eebehIuguE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=c72Jtzi8; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="c72Jtzi8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1772191613; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=IDOIyRmT6KuqPEPamC/FBdwtm7Gf75eSBm41m3iY6UA=; b=c72Jtzi8Do1BAM/XyUhvUvYQhkrqfKc6LmkbgOFVFecknecUFq05tLKDyrJAOXoNTevDPlbssghCCmi9gse6+Qlt+LJ6A/TyTXVWudId/InVpNpXrWza/vfBtMEgmoIf6BYuuVvHZBWOrXNpvCJOfPs6sx3i81tAH5ZMztlM2+I= Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0WzuBAQN_1772191610 cluster:ay36) by smtp.aliyun-inc.com; Fri, 27 Feb 2026 19:26:51 +0800 From: fangyu.yu@linux.alibaba.com To: tjeznach@rivosinc.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, andrew.jones@oss.qualcomm.com, baolu.lu@linux.intel.com, zong.li@sifive.com Cc: guoren@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Fangyu Yu Subject: [PATCH] iommu/riscv: Stop polling when CQCSR reports an error Date: Fri, 27 Feb 2026 19:26:40 +0800 Message-Id: <20260227112640.20197-1-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fangyu Yu 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 --- 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_qu= eue *queue, unsigned int timeout_us) { unsigned int cons =3D atomic_read(&queue->head); + unsigned int flags =3D RISCV_IOMMU_CQCSR_CQMF | RISCV_IOMMU_CQCSR_CMD_TO | + RISCV_IOMMU_CQCSR_CMD_ILL; =20 /* Already processed by the consumer */ if ((int)(cons - index) > 0) @@ -375,6 +377,7 @@ static int riscv_iommu_queue_wait(struct riscv_iommu_qu= eue *queue, =20 /* 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); } =20 --=20 2.50.1