Skip to contentSkip to conversation

virtio_ring: Fix querying of maximum DMA mapping size for virtio device

PATCH In review Will Deacon 3 participants 3 messages Dec 1, 2021 – Dec 3, 2021 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_ring: Fix querying of maximum DMA mapping size for virtio device

virtio_max_dma_size() returns the maximum DMA mapping size of the virtio device by querying dma_max_mapping_size() for the device when the DMA API is in use for the vring. Unfortunately, the device passed is initialised by register_virtio_device() and does not inherit the DMA configuration from its parent, resulting in SWIOTLB errors when bouncing is enabled and the default 256K mapping limit (IO_TLB_SEGSIZE) is not respected:

| virtio-pci 0000:00:01.0: swiotlb buffer is full (sz: 294912 bytes), total 1024 (slots), used 725 (slots)

Follow the pattern used elsewhere in the virtio_ring code when calling into the DMA layer and pass the parent device to dma_max_mapping_size() instead.

Cc Marc Zyngier <[email protected]>
Cc Quentin Perret <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Jason Wang <[email protected]>
---
 drivers/virtio/virtio_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +1 -1
index 6d2614e34470..028b05d44546 100644
@@ -268,7 +268,7 @@ 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);
+		max_segment_size = dma_max_mapping_size(vdev->dev.parent);
 
 	return max_segment_size;
 }
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Will Deacon

virtio_max_dma_size() returns the maximum DMA mapping size of the virtio device by querying dma_max_mapping_size() for the device when the DMA API is in use for the vring. Unfortunately, the device passed is initialised by register_virtio_device() and does not inherit the DMA configuration from its parent, resulting in SWIOTLB errors when bouncing is enabled and the default 256K mapping limit (IO_TLB_SEGSIZE) is not respected:

| virtio-pci 0000:00:01.0: swiotlb buffer is full (sz: 294912 bytes), total 1024 (slots), used 725 (slots)

Follow the pattern used elsewhere in the virtio_ring code when calling into the DMA layer and pass the parent device to dma_max_mapping_size() instead.

Quoted 5 lines
Cc Marc Zyngier <[email protected]>
Cc Quentin Perret <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Jason Wang <[email protected]>
Quoted 20 lines
---
 drivers/virtio/virtio_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +1 -2
index 6d2614e34470..028b05d44546 100644
@@ -268,7 +268,7 @@ 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);
+               max_segment_size = dma_max_mapping_size(vdev->dev.parent);
 
        return max_segment_size;
 }
--

2.34.0.rc2.393.gf8c9666880-goog

Tested-by on v1 1/1
#2 lore raw
In reply to Will Deacon
Quoted 14 lines · Will Deacon

virtio_max_dma_size() returns the maximum DMA mapping size of the virtio device by querying dma_max_mapping_size() for the device when the DMA API is in use for the vring. Unfortunately, the device passed is initialised by register_virtio_device() and does not inherit the DMA configuration from its parent, resulting in SWIOTLB errors when bouncing is enabled and the default 256K mapping limit (IO_TLB_SEGSIZE) is not respected:

| virtio-pci 0000:00:01.0: swiotlb buffer is full (sz: 294912 bytes), total 1024 (slots), used 725 (slots)

Follow the pattern used elsewhere in the virtio_ring code when calling into the DMA layer and pass the parent device to dma_max_mapping_size() instead.

Quoted 5 lines
Cc Marc Zyngier <[email protected]>
Cc Quentin Perret <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Jason Wang <[email protected]>

We hit a similar problem and ended up in the same patch, a bit late [0].

FWIW:

[0] https://lkml.kernel.org/r/[email protected]

Quoted 18 lines
---
  drivers/virtio/virtio_ring.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +1 -1
index 6d2614e34470..028b05d44546 100644
@@ -268,7 +268,7 @@ 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);
+		max_segment_size = dma_max_mapping_size(vdev->dev.parent);
 
  	return max_segment_size;
  }