[PATCH v2 02/11] iommu/arm-smmu-v3: Factor out __queue_empty() and __queue_consumed()

Nicolin Chen nicolinc at nvidia.com
Thu May 28 00:59:30 PDT 2026


queue_empty() and queue_consumed() each compare a ring-position pair where
one operand is fixed to a cached llq field (q->prod, q->cons).

A subsequent change will need the same ring-position comparisons against a
CONS value read live from MMIO into a local, which does not live in q->llq.

Factor the ring-position checks in queue_empty() and queue_consumed() into
__queue_empty() and __queue_consumed() primitives that accept both operands
explicitly. queue_empty() and queue_consumed() become pass-through wrappers
that pass the cached fields.

No functional change intended; it's a prerequisite to apply bug fix calling
iopf_queue_flush_dev().

Fixes: cfea71aea921 ("iommu/arm-smmu-v3: Put iopf enablement in the domain attach path")
Cc: stable at vger.kernel.org # v6.16
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Nicolin Chen <nicolinc at nvidia.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 620c67811df48..cf41b3cf5985f 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -146,18 +146,28 @@ static bool queue_full(struct arm_smmu_ll_queue *q)
 	       Q_WRP(q, q->prod) != Q_WRP(q, q->cons);
 }
 
+static bool __queue_empty(struct arm_smmu_ll_queue *q, u32 cons, u32 prod)
+{
+	return Q_IDX(q, prod) == Q_IDX(q, cons) &&
+	       Q_WRP(q, prod) == Q_WRP(q, cons);
+}
+
 static bool queue_empty(struct arm_smmu_ll_queue *q)
 {
-	return Q_IDX(q, q->prod) == Q_IDX(q, q->cons) &&
-	       Q_WRP(q, q->prod) == Q_WRP(q, q->cons);
+	return __queue_empty(q, q->cons, q->prod);
+}
+
+static bool __queue_consumed(struct arm_smmu_ll_queue *q, u32 cons, u32 prod)
+{
+	return ((Q_WRP(q, cons) == Q_WRP(q, prod)) &&
+		(Q_IDX(q, cons) > Q_IDX(q, prod))) ||
+	       ((Q_WRP(q, cons) != Q_WRP(q, prod)) &&
+		(Q_IDX(q, cons) <= Q_IDX(q, prod)));
 }
 
 static bool queue_consumed(struct arm_smmu_ll_queue *q, u32 prod)
 {
-	return ((Q_WRP(q, q->cons) == Q_WRP(q, prod)) &&
-		(Q_IDX(q, q->cons) > Q_IDX(q, prod))) ||
-	       ((Q_WRP(q, q->cons) != Q_WRP(q, prod)) &&
-		(Q_IDX(q, q->cons) <= Q_IDX(q, prod)));
+	return __queue_consumed(q, q->cons, prod);
 }
 
 static void queue_sync_cons_out(struct arm_smmu_queue *q)
-- 
2.43.0




More information about the linux-arm-kernel mailing list