Skip to content

Commit

Permalink
virtio_ring: support add premapped buf
Browse files Browse the repository at this point in the history
If the vq is the premapped mode, use the sg_dma_address() directly.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Message-Id: <20230810123057.43407-5-xuanzhuo@linux.alibaba.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Xuan Zhuo authored and Michael S. Tsirkin committed Sep 3, 2023
1 parent 8daafe9 commit d7344a2
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ static struct device *vring_dma_dev(const struct vring_virtqueue *vq)
static int vring_map_one_sg(const struct vring_virtqueue *vq, struct scatterlist *sg,
enum dma_data_direction direction, dma_addr_t *addr)
{
if (vq->premapped) {
*addr = sg_dma_address(sg);
return 0;
}

if (!vq->use_dma_api) {
/*
* If DMA is not used, KMSAN doesn't know that the scatterlist
Expand Down Expand Up @@ -639,8 +644,12 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
dma_addr_t addr = vring_map_single(
vq, desc, total_sg * sizeof(struct vring_desc),
DMA_TO_DEVICE);
if (vring_mapping_error(vq, addr))
if (vring_mapping_error(vq, addr)) {
if (vq->premapped)
goto free_indirect;

goto unmap_release;
}

virtqueue_add_desc_split(_vq, vq->split.vring.desc,
head, addr,
Expand Down Expand Up @@ -706,6 +715,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
i = vring_unmap_one_split(vq, i);
}

free_indirect:
if (indirect)
kfree(desc);

Expand Down Expand Up @@ -1307,8 +1317,12 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
addr = vring_map_single(vq, desc,
total_sg * sizeof(struct vring_packed_desc),
DMA_TO_DEVICE);
if (vring_mapping_error(vq, addr))
if (vring_mapping_error(vq, addr)) {
if (vq->premapped)
goto free_desc;

goto unmap_release;
}

vq->packed.vring.desc[head].addr = cpu_to_le64(addr);
vq->packed.vring.desc[head].len = cpu_to_le32(total_sg *
Expand Down Expand Up @@ -1366,6 +1380,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
for (i = 0; i < err_idx; i++)
vring_unmap_desc_packed(vq, &desc[i]);

free_desc:
kfree(desc);

END_USE(vq);
Expand Down

0 comments on commit d7344a2

Please sign in to comment.