[PATCH 0/3] iommu/riscv: Fix command queue publishing races
fangyu.yu at linux.alibaba.com
fangyu.yu at linux.alibaba.com
Mon Aug 17 07:27:25 PDT 2026
From: Fangyu Yu <fangyu.yu at linux.alibaba.com>
This series fixes races in the RISC-V IOMMU command queue submission
path.
The current command queue code reserves a producer index before the
command is written and before the hardware tail is updated. Multiple CPUs
can therefore reserve different producer indexes concurrently and then
wait for the software tail to reach their index before publishing their
own command.
That model is fragile when a command submission fails after reserving an
index. The failed producer index is never published, so later submitters
can wait behind a hole in the software producer stream. This can also
lead to misleading IOFENCE.C completion timeouts, because the sync path
may wait for a producer index whose command was never actually enqueued.
Fix this by serializing command queue publishing with a raw spinlock.
Instead of reserving producer indexes ahead of time, the submission path
uses the current software tail as the next command index, writes the
command, publishes the hardware tail, and then advances the software tail
while holding the lock. When the command queue is full, the code drops
the lock and waits for hardware consumption before retrying, so other CPUs
are not blocked behind a long hardware poll.
The final patch changes the queue submission helper to return an error
when enqueue fails. The IOFENCE.C sync path then avoids waiting for a
command that was never published to hardware.
This series does not attempt to add full RAS/error recovery for command
queue failures. It keeps the existing local error reporting behavior and
only fixes the software queue state and wait semantics.
Fangyu Yu (3):
iommu/riscv: Add command queue lock
iommu/riscv: Serialize command queue publishing
iommu/riscv: Avoid waiting on failed command enqueue
drivers/iommu/riscv/iommu.c | 121 ++++++++++++++++++++++--------------
drivers/iommu/riscv/iommu.h | 2 +
2 files changed, 76 insertions(+), 47 deletions(-)
--
2.50.1
More information about the linux-riscv
mailing list