From ce91e1727eea7aafe86b31821effc80edb9c60cc Mon Sep 17 00:00:00 2001 From: Zelin Deng Date: Fri, 9 Apr 2021 11:20:47 +0800 Subject: [PATCH 2682/2944] alinux: virtio_ring: Distinguish max mapping size between swiotlb and direct dma to #39258954 In former commit dma_max_mapping_size() is introduced to determine max dma mapping size. For swiotlb, in that function SIZE_MAX will be returned directly as swiotlb has its own dma ops while its dma ops has no max_mapping_size hooked -- neither "if" nor "else if" will be executed. Hence swiotlb must be distinguished to get its own max mapping size for virtio. Signed-off-by: Zelin Deng Reviewed-by: Artie Ding Reviewed-by: Baolin Wang --- drivers/virtio/virtio_ring.c | 8 ++++++-- kernel/dma/swiotlb.c | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index a32afbf..dfa2157 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1047,8 +1047,12 @@ 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); + if (vring_use_dma_api(vdev)) { + if (is_swiotlb_active()) + max_segment_size = swiotlb_max_mapping_size(&vdev->dev); + else + max_segment_size = dma_max_mapping_size(&vdev->dev); + } return max_segment_size; } diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 5d091b1..0ab112a 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1022,6 +1022,7 @@ bool is_swiotlb_active(void) */ return io_tlb_end != 0; } +EXPORT_SYMBOL(is_swiotlb_active); void *swiotlb_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) -- 1.8.3.1