diff mbox series

[v2] virtio-gpu: fix unmap the already mapped items

Message ID 20200821104708.4632-1-lizhijian@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show
Series [v2] virtio-gpu: fix unmap the already mapped items | expand

Commit Message

Li Zhijian Aug. 21, 2020, 10:47 a.m. UTC
we go here either (!(*iov)[i].iov_base) or (len != l), so we need to consider
to unmap the 'i'th item as well when the 'i'th item is not nil

Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>

---
v2: address Gerd's comments
---
 hw/display/virtio-gpu.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Li Qiang Aug. 26, 2020, 2:54 p.m. UTC | #1
Li Zhijian <lizhijian@cn.fujitsu.com> 于2020年8月21日周五 下午7:34写道:
>
> we go here either (!(*iov)[i].iov_base) or (len != l), so we need to consider
> to unmap the 'i'th item as well when the 'i'th item is not nil
>
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
>
> ---
> v2: address Gerd's comments
> ---
>  hw/display/virtio-gpu.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index 5f0dd7c150..e93f99932a 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -656,6 +656,9 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
>              qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"
>                            " resource %d element %d\n",
>                            __func__, ab->resource_id, i);
> +            if ((*iov)[i].iov_base) {
> +                i++; /* cleanup the 'i'th map */

Should we also reset (*iov)[i].iov_len to 'len' so the
dma_memory_unmap has the right size?

Thanks,
Li Qiang

> +            }
>              virtio_gpu_cleanup_mapping_iov(g, *iov, i);
>              g_free(ents);
>              *iov = NULL;
> --
> 2.17.1
>
>
>
>
Li Zhijian Aug. 27, 2020, 3:41 a.m. UTC | #2
On 8/26/20 10:54 PM, Li Qiang wrote:
> Li Zhijian <lizhijian@cn.fujitsu.com> 于2020年8月21日周五 下午7:34写道:
>> we go here either (!(*iov)[i].iov_base) or (len != l), so we need to consider
>> to unmap the 'i'th item as well when the 'i'th item is not nil
>>
>> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
>>
>> ---
>> v2: address Gerd's comments
>> ---
>>   hw/display/virtio-gpu.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
>> index 5f0dd7c150..e93f99932a 100644
>> --- a/hw/display/virtio-gpu.c
>> +++ b/hw/display/virtio-gpu.c
>> @@ -656,6 +656,9 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
>>               qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"
>>                             " resource %d element %d\n",
>>                             __func__, ab->resource_id, i);
>> +            if ((*iov)[i].iov_base) {
>> +                i++; /* cleanup the 'i'th map */
> Should we also reset (*iov)[i].iov_len to 'len' so the
> dma_memory_unmap has the right size?
Indeed, good caught, thanks



>
> Thanks,
> Li Qiang
>
>> +            }
>>               virtio_gpu_cleanup_mapping_iov(g, *iov, i);
>>               g_free(ents);
>>               *iov = NULL;
>> --
>> 2.17.1
>>
>>
>>
>>
>
diff mbox series

Patch

diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 5f0dd7c150..e93f99932a 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -656,6 +656,9 @@  int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
             qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO memory for"
                           " resource %d element %d\n",
                           __func__, ab->resource_id, i);
+            if ((*iov)[i].iov_base) {
+                i++; /* cleanup the 'i'th map */
+            }
             virtio_gpu_cleanup_mapping_iov(g, *iov, i);
             g_free(ents);
             *iov = NULL;