Skip to content

Commit 2a54e34

Browse files
rosatomjjgunthorpe
authored andcommitted
vfio/ap: Validate iova during dma_unmap and trigger irq disable
Currently, each mapped iova is stashed in its associated vfio_ap_queue; when we get an unmap request, validate that it matches with one or more of these stashed values before attempting unpins. Each stashed iova represents IRQ that was enabled for a queue. Therefore, if a match is found, trigger IRQ disable for this queue to ensure that underlying firmware will no longer try to use the associated pfn after the page is unpinned. IRQ disable will also handle the associated unpin. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Tony Krowiak <[email protected]> Signed-off-by: Matthew Rosato <[email protected]> Signed-off-by: Yi Liu <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4dc334c commit 2a54e34

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,13 +1535,29 @@ static int vfio_ap_mdev_set_kvm(struct ap_matrix_mdev *matrix_mdev,
15351535
return 0;
15361536
}
15371537

1538+
static void unmap_iova(struct ap_matrix_mdev *matrix_mdev, u64 iova, u64 length)
1539+
{
1540+
struct ap_queue_table *qtable = &matrix_mdev->qtable;
1541+
struct vfio_ap_queue *q;
1542+
int loop_cursor;
1543+
1544+
hash_for_each(qtable->queues, loop_cursor, q, mdev_qnode) {
1545+
if (q->saved_iova >= iova && q->saved_iova < iova + length)
1546+
vfio_ap_irq_disable(q);
1547+
}
1548+
}
1549+
15381550
static void vfio_ap_mdev_dma_unmap(struct vfio_device *vdev, u64 iova,
15391551
u64 length)
15401552
{
15411553
struct ap_matrix_mdev *matrix_mdev =
15421554
container_of(vdev, struct ap_matrix_mdev, vdev);
15431555

1544-
vfio_unpin_pages(&matrix_mdev->vdev, iova, 1);
1556+
mutex_lock(&matrix_dev->mdevs_lock);
1557+
1558+
unmap_iova(matrix_mdev, iova, length);
1559+
1560+
mutex_unlock(&matrix_dev->mdevs_lock);
15451561
}
15461562

15471563
/**

0 commit comments

Comments
 (0)