]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
virtio: Introduce virtio_max_dma_size()
authorJoerg Roedel <jroedel@suse.de>
Thu, 7 Feb 2019 11:59:16 +0000 (12:59 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 6 Mar 2019 16:19:15 +0000 (11:19 -0500)
This function returns the maximum segment size for a single
dma transaction of a virtio device. The possible limit comes
from the SWIOTLB implementation in the Linux kernel, that
has an upper limit of (currently) 256kb of contiguous
memory it can map. Other DMA-API implementations might also
have limits.

Use the new dma_max_mapping_size() function to determine the
maximum mapping size when DMA-API is in use for virtio.

Cc: stable@vger.kernel.org
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/virtio/virtio_ring.c
include/linux/virtio.h

index a0b07c3312550463b689acf9aa8d524ac5ad7d89..18846afb39da189e3f0dd0168727e0cf2865549e 100644 (file)
@@ -271,6 +271,17 @@ static bool vring_use_dma_api(struct virtio_device *vdev)
        return false;
 }
 
+size_t virtio_max_dma_size(struct virtio_device *vdev)
+{
+       size_t max_segment_size = SIZE_MAX;
+
+       if (vring_use_dma_api(vdev))
+               max_segment_size = dma_max_mapping_size(&vdev->dev);
+
+       return max_segment_size;
+}
+EXPORT_SYMBOL_GPL(virtio_max_dma_size);
+
 static void *vring_alloc_queue(struct virtio_device *vdev, size_t size,
                              dma_addr_t *dma_handle, gfp_t flag)
 {
index fa1b5da2804e6041df3b8f47e5ce0c7ddf828a54..673fe3ef360788642edf1f4c448f3618a556373f 100644 (file)
@@ -157,6 +157,8 @@ int virtio_device_freeze(struct virtio_device *dev);
 int virtio_device_restore(struct virtio_device *dev);
 #endif
 
+size_t virtio_max_dma_size(struct virtio_device *vdev);
+
 #define virtio_device_for_each_vq(vdev, vq) \
        list_for_each_entry(vq, &vdev->vqs, list)