Skip to content

virtgpu: fix memory leak on device removal

Manos Pitsidianakis dri-devel lkml virtualization 1 version In review

Get series with b4
b4 am [email protected] change-id 20250505-virtgpu-queue-cleanup-v1-3392995cab5f

Versions newest first

  1. v1 Latest3 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3virtgpu: add virtio_gpu_queue_cleanup()drivers/gpu/drm/virtio/virtgpu_drv.h drivers/gpu/drm/virtio/virtgpu_kms.c drivers/gpu/drm/virtio/virtgpu_vq.c+57 -01 reply
2/3virtgpu: add virtio_gpu_fence_cleanup()drivers/gpu/drm/virtio/virtgpu_drv.h drivers/gpu/drm/virtio/virtgpu_fence.c drivers/gpu/drm/virtio/virtgpu_kms.c+14 -01 reply
3/3virtgpu: deallocate capsets on device deinitdrivers/gpu/drm/virtio/virtgpu_kms.c+4 -03 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] virtgpu: fix memory leak on device removal

When a VIRTIO GPU device is removed, it cleans up any command buffers that the VIRTIO frontend has responded to. It however ignores commands that have yet to be replied to, which still reside in the avail rings of the virt queues. This leaks two type of objects:

- VIRTIO command buffers
- Fences

Furthermore, if the virtio config has num_capsets > 0, the capsets field of the device is also leaked.

These memory leaks are reported by:

- /sys/kernel/debug/kmemleak
- slab debug options "BUG virtio-gpu-vbufs: Objects remaining in virtio-gpu-vbufs on __kmem_cache_shutdown()"
- drm:drm_mm_takedown "Memory manager not clean during takedown."

This patch series adds cleanup logic in virtio_gpu_deinit(), after calling virtio_reset_device(), to free any such allocations.

---
Manos Pitsidianakis (3):
virtgpu: add virtio_gpu_queue_cleanup()
virtgpu: add virtio_gpu_fence_cleanup()
virtgpu: deallocate capsets on device deinit

 drivers/gpu/drm/virtio/virtgpu_drv.h   |  2 ++
 drivers/gpu/drm/virtio/virtgpu_fence.c | 12 ++++++++
 drivers/gpu/drm/virtio/virtgpu_kms.c   |  6 ++++
 drivers/gpu/drm/virtio/virtgpu_vq.c    | 55 ++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+)

---
base-commit: ad10b82c2bcac7f87ac6eaecfca33378b43425ee
change-id: 20250505-virtgpu-queue-cleanup-v1-3392995cab5f

--
γαῖα πυρί μιχθήτω