Skip to contentSkip to conversation

virtio-scsi: finalize IOMMU support

PATCH In review Jason Wang 4 participants 5 messages Jul 4, 2017 – Jul 5, 2017

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 virtio-scsi: finalize IOMMU support

After converting to use DMA api for virtio devices, we should use dma_as instead of address_space_memory. Otherwise it won't work if IOMMU is enabled.

Fixes commit 8607f5c3072c ("virtio: convert to use DMA api")
---
 hw/scsi/virtio-scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +2 -1
index f46f06d..d076fe7 100644
@@ -43,12 +43,13 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
 
 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     const size_t zero_skip =
         offsetof(VirtIOSCSIReq, resp_iov) + sizeof(req->resp_iov);
 
     req->vq = vq;
     req->dev = s;
-    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
+    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, vdev->dma_as);
     qemu_iovec_init(&req->resp_iov, 1);
     memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip);
 }
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jason Wang
Quoted 20 lines · Jason Wang

After converting to use DMA api for virtio devices, we should use dma_as instead of address_space_memory. Otherwise it won't work if IOMMU is enabled.

Fixes commit 8607f5c3072c ("virtio: convert to use DMA api")
---
 hw/scsi/virtio-scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +1 -0
index f46f06d..d076fe7 100644
@@ -43,12 +43,13 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
 
 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);

hw/scsi/virtio-scsi.c static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun) · line 55

Quoted 10 lines
hw/scsi/virtio-scsi.c +1 -1
     const size_t zero_skip =
         offsetof(VirtIOSCSIReq, resp_iov) + sizeof(req->resp_iov);
 
     req->vq = vq;
     req->dev = s;
-    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
+    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, vdev->dma_as);
     qemu_iovec_init(&req->resp_iov, 1);
     memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip);
 }
Quoted 4 lines
Signature · 1 line
2.7.4
#3 lore raw
In reply to Jason Wang
Quoted 17 lines · Jason Wang

After converting to use DMA api for virtio devices, we should use dma_as instead of address_space_memory. Otherwise it won't work if IOMMU is enabled.

Fixes commit 8607f5c3072c ("virtio: convert to use DMA api")
---
 hw/scsi/virtio-scsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/virtio-scsi.c +0 -0
index f46f06d..d076fe7 100644
@@ -43,12 +43,13 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
 

hw/scsi/virtio-scsi.c static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun) · line 52

Quoted 10 lines
hw/scsi/virtio-scsi.c +2 -1
 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
     const size_t zero_skip =
         offsetof(VirtIOSCSIReq, resp_iov) + sizeof(req->resp_iov);
 
     req->vq = vq;
     req->dev = s;
-    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
+    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, vdev->dma_as);

Not related to this patch, but is our vIOMMU iotlb implementation safe for data plane (both virtio-blk and virtio-scsi)? There we don't have BQL to synchronize between IOVA lookup and update, which means threads can race when accessing the iotlb GHashTable.

Did I overlook a synchronization mechanism? Or is it missing? Paolo, MST?

Fam

Quoted 7 lines
hw/scsi/virtio-scsi.c +0 -0
     qemu_iovec_init(&req->resp_iov, 1);
     memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip);
 }
Signature · 1 line
2.7.4
#4 lore raw
Quoted 10 lines · Fam Zheng

hw/scsi/virtio-scsi.c static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun) · line 52

Quoted 4 lines
     req->vq = vq;
     req->dev = s;
hw/scsi/virtio-scsi.c +1 -1
-    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
+    qemu_sglist_init(&req->qsgl, DEVICE(s), 8, vdev->dma_as);

Not related to this patch, but is our vIOMMU iotlb implementation safe for data plane (both virtio-blk and virtio-scsi)? There we don't have BQL to synchronize between IOVA lookup and update, which means threads can race when accessing the iotlb GHashTable.

Did I overlook a synchronization mechanism? Or is it missing? Paolo, MST?

I think it's missing. One way to fix it could be to finish the MemoryRegionCache work and have an IOMMU->virtio notifier, similar to how vhost works.

Paolo