do {
llq->val = READ_ONCE(cmdq->q.llq.val);
- if (!queue_full(llq))
+ if (!queue_has_space(llq, n))
break;
+ /*
+ * We must return here even if there's no space, because the producer
+ * having moved forward could mean that the last thread observing the
+ * SMMU progress has allocated space in the cmdq and moved on, leaving
+ * us in this waiting loop with no other thread updating
+ * llq->state->val.
+ */
+ if (llq->prod != prod)
+ return -EAGAIN;
+
ret = queue_poll(&qp);