Skip to contentSkip to conversation

virtio-gpu: fix unmap in error path

PATCH In review Gerd Hoffmann 3 participants 3 messages Jun 28, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-gpu: fix unmap in error path

We land here in case not everything we've asked for could be mapped. So unmap only the bytes which have actually been mapped.

Also we didn't access anything, so acces_len can be 0.

---
 hw/display/virtio-gpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +2 -2
index 2b0f66b1d68d..475a018c027c 100644
@@ -1048,9 +1048,9 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
                 if (res->iov[i].iov_base) {
                     dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as,
                                      res->iov[i].iov_base,
-                                     res->iov[i].iov_len,
+                                     len,
                                      DMA_DIRECTION_TO_DEVICE,
-                                     res->iov[i].iov_len);
+                                     0);
                 }
                 /* ...and the mappings for previous loop iterations */
                 res->iov_cnt = i;
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Gerd Hoffmann

We land here in case not everything we've asked for could be mapped. So unmap only the bytes which have actually been mapped.

Also we didn't access anything, so acces_len can be 0.

s/acces_len/access_len/

With that:

Thank you!
Laszlo

Quoted 24 lines
---
 hw/display/virtio-gpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +2 -2
index 2b0f66b1d68d..475a018c027c 100644
@@ -1048,9 +1048,9 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
                 if (res->iov[i].iov_base) {
                     dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as,
                                      res->iov[i].iov_base,
-                                     res->iov[i].iov_len,
+                                     len,
                                      DMA_DIRECTION_TO_DEVICE,
-                                     res->iov[i].iov_len);
+                                     0);
                 }
                 /* ...and the mappings for previous loop iterations */
                 res->iov_cnt = i;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann <[email protected]> 于2019年6月28日周五 下午3:24写道:

We land here in case not everything we've asked for could be mapped. So unmap only the bytes which have actually been mapped.

Also we didn't access anything, so acces_len can be 0.

It is reasonable, so

btw: Does it break something before this patch?
AFAICS, the 'len' is not used for the unmap, only the 'access_len' is used.

Thanks,
Li Qiang

Quoted 26 lines
---
 hw/display/virtio-gpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +2 -2
index 2b0f66b1d68d..475a018c027c 100644
@@ -1048,9 +1048,9 @@ static int virtio_gpu_load(QEMUFile *f, void
 *opaque, size_t size,
                 if (res->iov[i].iov_base) {
                     dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as,
                                      res->iov[i].iov_base,
-                                     res->iov[i].iov_len,
+                                     len,
                                      DMA_DIRECTION_TO_DEVICE,
-                                     res->iov[i].iov_len);
+                                     0);
                 }
                 /* ...and the mappings for previous loop iterations */
                 res->iov_cnt = i;

--
2.18.1