Skip to content

Commit d5c0ed1

Browse files
fengidrimstsirkin
authored andcommitted
virtio: packed: fix unmap leak for indirect desc table
When use_dma_api and premapped are true, then the do_unmap is false. Because the do_unmap is false, vring_unmap_extra_packed is not called by detach_buf_packed. if (unlikely(vq->do_unmap)) { curr = id; for (i = 0; i < state->num; i++) { vring_unmap_extra_packed(vq, &vq->packed.desc_extra[curr]); curr = vq->packed.desc_extra[curr].next; } } So the indirect desc table is not unmapped. This causes the unmap leak. So here, we check vq->use_dma_api instead. Synchronously, dma info is updated based on use_dma_api judgment This bug does not occur, because no driver use the premapped with indirect. Fixes: b319940 ("virtio_ring: skip unmap for premapped") Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Message-Id: <20240223071833.26095-1-xuanzhuo@linux.alibaba.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 1ac61dd commit d5c0ed1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/virtio/virtio_ring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
13401340
sizeof(struct vring_packed_desc));
13411341
vq->packed.vring.desc[head].id = cpu_to_le16(id);
13421342

1343-
if (vq->do_unmap) {
1343+
if (vq->use_dma_api) {
13441344
vq->packed.desc_extra[id].addr = addr;
13451345
vq->packed.desc_extra[id].len = total_sg *
13461346
sizeof(struct vring_packed_desc);
@@ -1481,7 +1481,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
14811481
desc[i].len = cpu_to_le32(sg->length);
14821482
desc[i].id = cpu_to_le16(id);
14831483

1484-
if (unlikely(vq->do_unmap)) {
1484+
if (unlikely(vq->use_dma_api)) {
14851485
vq->packed.desc_extra[curr].addr = addr;
14861486
vq->packed.desc_extra[curr].len = sg->length;
14871487
vq->packed.desc_extra[curr].flags =
@@ -1615,7 +1615,7 @@ static void detach_buf_packed(struct vring_virtqueue *vq,
16151615
vq->free_head = id;
16161616
vq->vq.num_free += state->num;
16171617

1618-
if (unlikely(vq->do_unmap)) {
1618+
if (unlikely(vq->use_dma_api)) {
16191619
curr = id;
16201620
for (i = 0; i < state->num; i++) {
16211621
vring_unmap_extra_packed(vq,

0 commit comments

Comments
 (0)