virtio_ring: check use_dma_api before unmap desc for indirect
authorXuan Zhuo <xuanzhuo@linux.alibaba.com>
Thu, 10 Aug 2023 12:30:46 +0000 (20:30 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Sun, 3 Sep 2023 22:10:22 +0000 (18:10 -0400)
Inside detach_buf_split(), if use_dma_api is false,
vring_unmap_one_split_indirect will be called many times, but actually
nothing is done. So this patch check use_dma_api firstly.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230810123057.43407-2-xuanzhuo@linux.alibaba.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/virtio/virtio_ring.c

index c5310ea..f8754f1 100644 (file)
@@ -774,8 +774,10 @@ static void detach_buf_split(struct vring_virtqueue *vq, unsigned int head,
                                VRING_DESC_F_INDIRECT));
                BUG_ON(len == 0 || len % sizeof(struct vring_desc));
 
-               for (j = 0; j < len / sizeof(struct vring_desc); j++)
-                       vring_unmap_one_split_indirect(vq, &indir_desc[j]);
+               if (vq->use_dma_api) {
+                       for (j = 0; j < len / sizeof(struct vring_desc); j++)
+                               vring_unmap_one_split_indirect(vq, &indir_desc[j]);
+               }
 
                kfree(indir_desc);
                vq->split.desc_state[head].indir_desc = NULL;