[PATCH] iommufd/selftest: Fix wrong slot cleared on mock HW queue destroy

Peiyang He posted 1 patch 2 weeks, 3 days ago
drivers/iommu/iommufd/selftest.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] iommufd/selftest: Fix wrong slot cleared on mock HW queue destroy
Posted by Peiyang He 2 weeks, 3 days ago
mock_hw_queue_init_phys() publishes a new queue in
mock_viommu->hw_queue[index] but never stores the index in
mock_hw_queue->index, while mock_hw_queue_destroy() uses that field to
clear the slot. Since the object is zero-allocated, destroying any queue
always clears hw_queue[0] instead of the queue's own slot.

Record the index before publishing the queue so that destroy clears the
correct slot.

Fixes: 20896914da8a ("iommufd/selftest: Add coverage for IOMMUFD_CMD_HW_QUEUE_ALLOC")
Signed-off-by: Peiyang He <peiyang_he@smail.nju.edu.cn>
Cc: stable@vger.kernel.org
---
This bug cannot be detected by any sanitizers or kernel warnings.
We observed this kind of weird situation and thus found this bug:
after allocating queues 0 and 1 and destroying queue 1,
later IOMMU_HW_QUEUE_ALLOC for index 1 still fails with -EEXIST.

 drivers/iommu/iommufd/selftest.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 25387969a..54d86bce7 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -759,6 +759,7 @@ static int mock_hw_queue_init_phys(struct iommufd_hw_queue *hw_queue, u32 index,
 
 	mock_hw_queue->prev = prev;
 	mock_hw_queue->mock_viommu = mock_viommu;
+	mock_hw_queue->index = index;
 	mock_viommu->hw_queue[index] = mock_hw_queue;
 
 	hw_queue->destroy = &mock_hw_queue_destroy;
Re: [PATCH] iommufd/selftest: Fix wrong slot cleared on mock HW queue destroy
Posted by Jason Gunthorpe 1 week, 6 days ago
On Fri, 06 Nov 2026 20:28:32 +0800, Peiyang He wrote:
> iommufd/selftest: Fix wrong slot cleared on mock HW queue destroy

Applied, thanks!

[1/1] iommufd/selftest: Fix wrong slot cleared on mock HW queue destroy
      https://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd.git/commit/?id=231e471ac4d0579bba3a800fc46519f8a04894d9

Best regards,
-- 
Jason