* [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
@ 2026-09-29 7:07 Abhin Parekadan Jose
2026-09-29 7:16 ` sashiko-bot
2026-10-12 5:44 ` Abhin Parekadan Jose
0 siblings, 2 replies; 6+ messages in thread
From: Abhin Parekadan Jose @ 2026-09-29 7:07 UTC (permalink / raw)
To: Dmitry Osipenko, Gerd Hoffmann, David Airlie
Cc: Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Simona Vetter, Dongwon Kim, dri-devel,
virtualization, linux-kernel, syzbot+3590d97d8a586fa955c2,
Abhin Parekadan Jose
virtio_gpu_deinit() calls mutex_destroy() on obj_restore_lock, but
deinit runs from virtio_gpu_remove() at unbind or PCI remove, and GEM
objects can outlive that. An open /dev/fb0 keeps the fbdev buffer
alive, and the fbdev DRM client holds a drm_device reference. When the
fd is finally closed, the buffer is freed and takes the destroyed lock:
fb_release()
drm_fbdev_shmem_fb_destroy()
drm_client_buffer_delete()
virtio_gpu_free_object()
virtio_gpu_remove_from_restore_list()
mutex_lock(&vgdev->obj_restore_lock)
DEBUG_LOCKS_WARN_ON(lock->magic != lock)
WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xf2c/0x12ec
virtio_gpu_deinit() should only do hardware teardown in this case
related virtio, its queues and others. Software state that GEM callbacks
still use belongs in virtio_gpu_release(), which runs on the final
drm_dev_put().
There are two equivalent ways to tie the mutex lifetime to the
drm_device:
1) Move mutex_destroy() from virtio_gpu_deinit() to the end of
virtio_gpu_release(). This is what this patch does. It is the
smallest change and keeps the teardown next to the rest of the
final-put software cleanup.
2) Initialise the lock with drmm_mutex_init() (checking its return
value) and drop mutex_destroy() from virtio_gpu_deinit(), so DRM's
managed release destroys it. This also covers the virtio_gpu_init()
error path, where release returns early because dev_private is
NULL. Skipping mutex_destroy() there is harmless, since it only
matters for mutex debugging.
Either fix removes the WARN. Option 1 is sent as the smaller change,
and option 2 can be done instead if preferred.
Reproduced on arm64 QEMU (-device virtio-gpu-pci) with DEBUG_MUTEXES
and PROVE_LOCKING: open /dev/fb0, write 1 to
/sys/bus/pci/devices/0000:00:01.0/remove, then close the fd. With this
patch the WARN is gone, and rebinding brings back /dev/fb0 and
/dev/dri/card0.
Fixes: 54a970048296 ("drm/virtio: Add support for saving and restoring virtio_gpu_objects")
Reported-by: syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3590d97d8a586fa955c2
Assisted-by: LLM
Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
---
drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
index 1d4d3bf46a20..0ec755c35050 100644
--- a/drivers/gpu/drm/virtio/virtgpu_kms.c
+++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
@@ -354,7 +354,6 @@ void virtio_gpu_deinit(struct drm_device *dev)
virtio_reset_device(vgdev->vdev);
virtio_gpu_reclaim_vbufs(vgdev);
vgdev->vdev->config->del_vqs(vgdev->vdev);
- mutex_destroy(&vgdev->obj_restore_lock);
}
void virtio_gpu_release(struct drm_device *dev)
@@ -370,6 +369,8 @@ void virtio_gpu_release(struct drm_device *dev)
if (vgdev->has_host_visible)
drm_mm_takedown(&vgdev->host_visible_mm);
+
+ mutex_destroy(&vgdev->obj_restore_lock);
}
int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e
--
2.51.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
2026-09-29 7:07 [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put() Abhin Parekadan Jose
@ 2026-09-29 7:16 ` sashiko-bot
2026-10-12 5:44 ` Abhin Parekadan Jose
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-09-29 7:16 UTC (permalink / raw)
To: Abhin Parekadan Jose
Cc: virtualization, dri-devel, Eugenio Perez, Michael S. Tsirkin
> virtio_gpu_deinit() calls mutex_destroy() on obj_restore_lock, but
> deinit runs from virtio_gpu_remove() at unbind or PCI remove, and GEM
> objects can outlive that. An open /dev/fb0 keeps the fbdev buffer
> alive, and the fbdev DRM client holds a drm_device reference. When the
> fd is finally closed, the buffer is freed and takes the destroyed lock:
>
> fb_release()
> drm_fbdev_shmem_fb_destroy()
> drm_client_buffer_delete()
> virtio_gpu_free_object()
> virtio_gpu_remove_from_restore_list()
> mutex_lock(&vgdev->obj_restore_lock)
>
> DEBUG_LOCKS_WARN_ON(lock->magic != lock)
> WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xf2c/0x12ec
> [ ... ]
> Fixes: 54a970048296 ("drm/virtio: Add support for saving and restoring virtio_gpu_objects")
> Reported-by: syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=3590d97d8a586fa955c2
> Assisted-by: LLM
> Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260929070714.169412-1-abhinjoses@gmail.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
2026-09-29 7:07 [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put() Abhin Parekadan Jose
2026-09-29 7:16 ` sashiko-bot
@ 2026-10-12 5:44 ` Abhin Parekadan Jose
2026-10-13 22:16 ` Dmitry Osipenko
1 sibling, 1 reply; 6+ messages in thread
From: Abhin Parekadan Jose @ 2026-10-12 5:44 UTC (permalink / raw)
To: Dmitry Osipenko, Gerd Hoffmann, David Airlie
Cc: Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Simona Vetter, Dongwon Kim, dri-devel,
virtualization, linux-kernel, syzbot+3590d97d8a586fa955c2
Gentle ping on this fix for the syzbot report.
Dmitry, Gerd, do you have a preference between moving mutex_destroy()
to virtio_gpu_release() (this patch) and using drmm_mutex_init()? I can
send a v2 with the other option if you prefer it.
Thanks,
Abhin
On Tue, Sep 29, 2026 at 07:07:14AM +0000, Abhin Parekadan Jose wrote:
> virtio_gpu_deinit() calls mutex_destroy() on obj_restore_lock, but
> deinit runs from virtio_gpu_remove() at unbind or PCI remove, and GEM
> objects can outlive that. An open /dev/fb0 keeps the fbdev buffer
> alive, and the fbdev DRM client holds a drm_device reference. When the
> fd is finally closed, the buffer is freed and takes the destroyed lock:
>
> fb_release()
> drm_fbdev_shmem_fb_destroy()
> drm_client_buffer_delete()
> virtio_gpu_free_object()
> virtio_gpu_remove_from_restore_list()
> mutex_lock(&vgdev->obj_restore_lock)
>
> DEBUG_LOCKS_WARN_ON(lock->magic != lock)
> WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xf2c/0x12ec
>
> virtio_gpu_deinit() should only do hardware teardown in this case
> related virtio, its queues and others. Software state that GEM callbacks
> still use belongs in virtio_gpu_release(), which runs on the final
> drm_dev_put().
>
> There are two equivalent ways to tie the mutex lifetime to the
> drm_device:
>
> 1) Move mutex_destroy() from virtio_gpu_deinit() to the end of
> virtio_gpu_release(). This is what this patch does. It is the
> smallest change and keeps the teardown next to the rest of the
> final-put software cleanup.
>
> 2) Initialise the lock with drmm_mutex_init() (checking its return
> value) and drop mutex_destroy() from virtio_gpu_deinit(), so DRM's
> managed release destroys it. This also covers the virtio_gpu_init()
> error path, where release returns early because dev_private is
> NULL. Skipping mutex_destroy() there is harmless, since it only
> matters for mutex debugging.
>
> Either fix removes the WARN. Option 1 is sent as the smaller change,
> and option 2 can be done instead if preferred.
>
> Reproduced on arm64 QEMU (-device virtio-gpu-pci) with DEBUG_MUTEXES
> and PROVE_LOCKING: open /dev/fb0, write 1 to
> /sys/bus/pci/devices/0000:00:01.0/remove, then close the fd. With this
> patch the WARN is gone, and rebinding brings back /dev/fb0 and
> /dev/dri/card0.
>
> Fixes: 54a970048296 ("drm/virtio: Add support for saving and restoring virtio_gpu_objects")
> Reported-by: syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=3590d97d8a586fa955c2
> Assisted-by: LLM
> Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
> ---
> drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
> index 1d4d3bf46a20..0ec755c35050 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> @@ -354,7 +354,6 @@ void virtio_gpu_deinit(struct drm_device *dev)
> virtio_reset_device(vgdev->vdev);
> virtio_gpu_reclaim_vbufs(vgdev);
> vgdev->vdev->config->del_vqs(vgdev->vdev);
> - mutex_destroy(&vgdev->obj_restore_lock);
> }
>
> void virtio_gpu_release(struct drm_device *dev)
> @@ -370,6 +369,8 @@ void virtio_gpu_release(struct drm_device *dev)
>
> if (vgdev->has_host_visible)
> drm_mm_takedown(&vgdev->host_visible_mm);
> +
> + mutex_destroy(&vgdev->obj_restore_lock);
> }
>
> int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
>
> base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e
> --
> 2.51.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
2026-10-12 5:44 ` Abhin Parekadan Jose
@ 2026-10-13 22:16 ` Dmitry Osipenko
2026-10-14 19:53 ` Abhin Parekadan Jose
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Osipenko @ 2026-10-13 22:16 UTC (permalink / raw)
To: Abhin Parekadan Jose, Gerd Hoffmann, David Airlie
Cc: Gurchetan Singh, Chia-I Wu, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Simona Vetter, Dongwon Kim, dri-devel,
virtualization, linux-kernel, syzbot+3590d97d8a586fa955c2
On 10/12/26 08:44, Abhin Parekadan Jose wrote:
> Gentle ping on this fix for the syzbot report.
>
> Dmitry, Gerd, do you have a preference between moving mutex_destroy()
> to virtio_gpu_release() (this patch) and using drmm_mutex_init()? I can
> send a v2 with the other option if you prefer it.
>
> Thanks,
> Abhin
>
> On Tue, Sep 29, 2026 at 07:07:14AM +0000, Abhin Parekadan Jose wrote:
>> virtio_gpu_deinit() calls mutex_destroy() on obj_restore_lock, but
>> deinit runs from virtio_gpu_remove() at unbind or PCI remove, and GEM
>> objects can outlive that. An open /dev/fb0 keeps the fbdev buffer
>> alive, and the fbdev DRM client holds a drm_device reference. When the
>> fd is finally closed, the buffer is freed and takes the destroyed lock:
>>
>> fb_release()
>> drm_fbdev_shmem_fb_destroy()
>> drm_client_buffer_delete()
>> virtio_gpu_free_object()
>> virtio_gpu_remove_from_restore_list()
>> mutex_lock(&vgdev->obj_restore_lock)
>>
>> DEBUG_LOCKS_WARN_ON(lock->magic != lock)
>> WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xf2c/0x12ec
>>
>> virtio_gpu_deinit() should only do hardware teardown in this case
>> related virtio, its queues and others. Software state that GEM callbacks
>> still use belongs in virtio_gpu_release(), which runs on the final
>> drm_dev_put().
>>
>> There are two equivalent ways to tie the mutex lifetime to the
>> drm_device:
>>
>> 1) Move mutex_destroy() from virtio_gpu_deinit() to the end of
>> virtio_gpu_release(). This is what this patch does. It is the
>> smallest change and keeps the teardown next to the rest of the
>> final-put software cleanup.
>>
>> 2) Initialise the lock with drmm_mutex_init() (checking its return
>> value) and drop mutex_destroy() from virtio_gpu_deinit(), so DRM's
>> managed release destroys it. This also covers the virtio_gpu_init()
>> error path, where release returns early because dev_private is
>> NULL. Skipping mutex_destroy() there is harmless, since it only
>> matters for mutex debugging.
>>
>> Either fix removes the WARN. Option 1 is sent as the smaller change,
>> and option 2 can be done instead if preferred.
>>
>> Reproduced on arm64 QEMU (-device virtio-gpu-pci) with DEBUG_MUTEXES
>> and PROVE_LOCKING: open /dev/fb0, write 1 to
>> /sys/bus/pci/devices/0000:00:01.0/remove, then close the fd. With this
>> patch the WARN is gone, and rebinding brings back /dev/fb0 and
>> /dev/dri/card0.
>>
>> Fixes: 54a970048296 ("drm/virtio: Add support for saving and restoring virtio_gpu_objects")
>> Reported-by: syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?extid=3590d97d8a586fa955c2
>> Assisted-by: LLM
>> Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
>> ---
>> drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
>> index 1d4d3bf46a20..0ec755c35050 100644
>> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
>> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
>> @@ -354,7 +354,6 @@ void virtio_gpu_deinit(struct drm_device *dev)
>> virtio_reset_device(vgdev->vdev);
>> virtio_gpu_reclaim_vbufs(vgdev);
>> vgdev->vdev->config->del_vqs(vgdev->vdev);
>> - mutex_destroy(&vgdev->obj_restore_lock);
>> }
>>
>> void virtio_gpu_release(struct drm_device *dev)
>> @@ -370,6 +369,8 @@ void virtio_gpu_release(struct drm_device *dev)
>>
>> if (vgdev->has_host_visible)
>> drm_mm_takedown(&vgdev->host_visible_mm);
>> +
>> + mutex_destroy(&vgdev->obj_restore_lock);
>> }
>>
>> int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
Calling virtio_gpu_deinit() from virtio_gpu_release() might be a better
option
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
2026-10-13 22:16 ` Dmitry Osipenko
@ 2026-10-14 19:53 ` Abhin Parekadan Jose
2026-10-14 21:03 ` Dmitry Osipenko
0 siblings, 1 reply; 6+ messages in thread
From: Abhin Parekadan Jose @ 2026-10-14 19:53 UTC (permalink / raw)
To: Dmitry Osipenko
Cc: Gerd Hoffmann, David Airlie, Gurchetan Singh, Chia-I Wu,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Dongwon Kim, dri-devel, virtualization,
linux-kernel, syzbot+3590d97d8a586fa955c2
On Wed, Oct 14, 2026 at 01:16:57AM +0300, Dmitry Osipenko wrote:
> On 10/12/26 08:44, Abhin Parekadan Jose wrote:
> > Gentle ping on this fix for the syzbot report.
> >
> > Dmitry, Gerd, do you have a preference between moving mutex_destroy()
> > to virtio_gpu_release() (this patch) and using drmm_mutex_init()? I can
> > send a v2 with the other option if you prefer it.
> >
> > Thanks,
> > Abhin
> >
> > On Tue, Sep 29, 2026 at 07:07:14AM +0000, Abhin Parekadan Jose wrote:
> >> virtio_gpu_deinit() calls mutex_destroy() on obj_restore_lock, but
> >> deinit runs from virtio_gpu_remove() at unbind or PCI remove, and GEM
> >> objects can outlive that. An open /dev/fb0 keeps the fbdev buffer
> >> alive, and the fbdev DRM client holds a drm_device reference. When the
> >> fd is finally closed, the buffer is freed and takes the destroyed lock:
> >>
> >> fb_release()
> >> drm_fbdev_shmem_fb_destroy()
> >> drm_client_buffer_delete()
> >> virtio_gpu_free_object()
> >> virtio_gpu_remove_from_restore_list()
> >> mutex_lock(&vgdev->obj_restore_lock)
> >>
> >> DEBUG_LOCKS_WARN_ON(lock->magic != lock)
> >> WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xf2c/0x12ec
> >>
> >> virtio_gpu_deinit() should only do hardware teardown in this case
> >> related virtio, its queues and others. Software state that GEM callbacks
> >> still use belongs in virtio_gpu_release(), which runs on the final
> >> drm_dev_put().
> >>
> >> There are two equivalent ways to tie the mutex lifetime to the
> >> drm_device:
> >>
> >> 1) Move mutex_destroy() from virtio_gpu_deinit() to the end of
> >> virtio_gpu_release(). This is what this patch does. It is the
> >> smallest change and keeps the teardown next to the rest of the
> >> final-put software cleanup.
> >>
> >> 2) Initialise the lock with drmm_mutex_init() (checking its return
> >> value) and drop mutex_destroy() from virtio_gpu_deinit(), so DRM's
> >> managed release destroys it. This also covers the virtio_gpu_init()
> >> error path, where release returns early because dev_private is
> >> NULL. Skipping mutex_destroy() there is harmless, since it only
> >> matters for mutex debugging.
> >>
> >> Either fix removes the WARN. Option 1 is sent as the smaller change,
> >> and option 2 can be done instead if preferred.
> >>
> >> Reproduced on arm64 QEMU (-device virtio-gpu-pci) with DEBUG_MUTEXES
> >> and PROVE_LOCKING: open /dev/fb0, write 1 to
> >> /sys/bus/pci/devices/0000:00:01.0/remove, then close the fd. With this
> >> patch the WARN is gone, and rebinding brings back /dev/fb0 and
> >> /dev/dri/card0.
> >>
> >> Fixes: 54a970048296 ("drm/virtio: Add support for saving and restoring virtio_gpu_objects")
> >> Reported-by: syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
> >> Closes: https://syzkaller.appspot.com/bug?extid=3590d97d8a586fa955c2
> >> Assisted-by: LLM
> >> Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
> >> ---
> >> drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
> >> 1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
> >> index 1d4d3bf46a20..0ec755c35050 100644
> >> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
> >> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
> >> @@ -354,7 +354,6 @@ void virtio_gpu_deinit(struct drm_device *dev)
> >> virtio_reset_device(vgdev->vdev);
> >> virtio_gpu_reclaim_vbufs(vgdev);
> >> vgdev->vdev->config->del_vqs(vgdev->vdev);
> >> - mutex_destroy(&vgdev->obj_restore_lock);
> >> }
> >>
> >> void virtio_gpu_release(struct drm_device *dev)
> >> @@ -370,6 +369,8 @@ void virtio_gpu_release(struct drm_device *dev)
> >>
> >> if (vgdev->has_host_visible)
> >> drm_mm_takedown(&vgdev->host_visible_mm);
> >> +
> >> + mutex_destroy(&vgdev->obj_restore_lock);
> >> }
> >>
> >> int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
> Calling virtio_gpu_deinit() from virtio_gpu_release() might be a better
> option
Wouldn't that end up freeing the virtqueues twice, or using them after
they are freed? virtio_gpu_deinit() would then run from both the
virtio_gpu_remove() path and the virtio_gpu_release() path.
or do you mean removing it from virtio_gpu_remove() and calling it only
from virtio_gpu_release()?
This is only from a high-level look so far. I'll look into it more
closely and get back to you.
>
> --
> Best regards,
> Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
2026-10-14 19:53 ` Abhin Parekadan Jose
@ 2026-10-14 21:03 ` Dmitry Osipenko
0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2026-10-14 21:03 UTC (permalink / raw)
To: Abhin Parekadan Jose
Cc: Gerd Hoffmann, David Airlie, Gurchetan Singh, Chia-I Wu,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Simona Vetter, Dongwon Kim, dri-devel, virtualization,
linux-kernel, syzbot+3590d97d8a586fa955c2
On 10/14/26 22:53, Abhin Parekadan Jose wrote:
> On Wed, Oct 14, 2026 at 01:16:57AM +0300, Dmitry Osipenko wrote:
>> On 10/12/26 08:44, Abhin Parekadan Jose wrote:
>>> Gentle ping on this fix for the syzbot report.
>>>
>>> Dmitry, Gerd, do you have a preference between moving mutex_destroy()
>>> to virtio_gpu_release() (this patch) and using drmm_mutex_init()? I can
>>> send a v2 with the other option if you prefer it.
>>>
>>> Thanks,
>>> Abhin
>>>
>>> On Tue, Sep 29, 2026 at 07:07:14AM +0000, Abhin Parekadan Jose wrote:
>>>> virtio_gpu_deinit() calls mutex_destroy() on obj_restore_lock, but
>>>> deinit runs from virtio_gpu_remove() at unbind or PCI remove, and GEM
>>>> objects can outlive that. An open /dev/fb0 keeps the fbdev buffer
>>>> alive, and the fbdev DRM client holds a drm_device reference. When the
>>>> fd is finally closed, the buffer is freed and takes the destroyed lock:
>>>>
>>>> fb_release()
>>>> drm_fbdev_shmem_fb_destroy()
>>>> drm_client_buffer_delete()
>>>> virtio_gpu_free_object()
>>>> virtio_gpu_remove_from_restore_list()
>>>> mutex_lock(&vgdev->obj_restore_lock)
>>>>
>>>> DEBUG_LOCKS_WARN_ON(lock->magic != lock)
>>>> WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xf2c/0x12ec
>>>>
>>>> virtio_gpu_deinit() should only do hardware teardown in this case
>>>> related virtio, its queues and others. Software state that GEM callbacks
>>>> still use belongs in virtio_gpu_release(), which runs on the final
>>>> drm_dev_put().
>>>>
>>>> There are two equivalent ways to tie the mutex lifetime to the
>>>> drm_device:
>>>>
>>>> 1) Move mutex_destroy() from virtio_gpu_deinit() to the end of
>>>> virtio_gpu_release(). This is what this patch does. It is the
>>>> smallest change and keeps the teardown next to the rest of the
>>>> final-put software cleanup.
>>>>
>>>> 2) Initialise the lock with drmm_mutex_init() (checking its return
>>>> value) and drop mutex_destroy() from virtio_gpu_deinit(), so DRM's
>>>> managed release destroys it. This also covers the virtio_gpu_init()
>>>> error path, where release returns early because dev_private is
>>>> NULL. Skipping mutex_destroy() there is harmless, since it only
>>>> matters for mutex debugging.
>>>>
>>>> Either fix removes the WARN. Option 1 is sent as the smaller change,
>>>> and option 2 can be done instead if preferred.
>>>>
>>>> Reproduced on arm64 QEMU (-device virtio-gpu-pci) with DEBUG_MUTEXES
>>>> and PROVE_LOCKING: open /dev/fb0, write 1 to
>>>> /sys/bus/pci/devices/0000:00:01.0/remove, then close the fd. With this
>>>> patch the WARN is gone, and rebinding brings back /dev/fb0 and
>>>> /dev/dri/card0.
>>>>
>>>> Fixes: 54a970048296 ("drm/virtio: Add support for saving and restoring virtio_gpu_objects")
>>>> Reported-by: syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
>>>> Closes: https://syzkaller.appspot.com/bug?extid=3590d97d8a586fa955c2
>>>> Assisted-by: LLM
>>>> Signed-off-by: Abhin Parekadan Jose <abhinjoses@gmail.com>
>>>> ---
>>>> drivers/gpu/drm/virtio/virtgpu_kms.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c
>>>> index 1d4d3bf46a20..0ec755c35050 100644
>>>> --- a/drivers/gpu/drm/virtio/virtgpu_kms.c
>>>> +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c
>>>> @@ -354,7 +354,6 @@ void virtio_gpu_deinit(struct drm_device *dev)
>>>> virtio_reset_device(vgdev->vdev);
>>>> virtio_gpu_reclaim_vbufs(vgdev);
>>>> vgdev->vdev->config->del_vqs(vgdev->vdev);
>>>> - mutex_destroy(&vgdev->obj_restore_lock);
>>>> }
>>>>
>>>> void virtio_gpu_release(struct drm_device *dev)
>>>> @@ -370,6 +369,8 @@ void virtio_gpu_release(struct drm_device *dev)
>>>>
>>>> if (vgdev->has_host_visible)
>>>> drm_mm_takedown(&vgdev->host_visible_mm);
>>>> +
>>>> + mutex_destroy(&vgdev->obj_restore_lock);
>>>> }
>>>>
>>>> int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
>> Calling virtio_gpu_deinit() from virtio_gpu_release() might be a better
>> option
>
> Wouldn't that end up freeing the virtqueues twice, or using them after
> they are freed? virtio_gpu_deinit() would then run from both the
> virtio_gpu_remove() path and the virtio_gpu_release() path.
> or do you mean removing it from virtio_gpu_remove() and calling it only
> from virtio_gpu_release()?
> This is only from a high-level look so far. I'll look into it more
> closely and get back to you.
Remove from virtio_gpu_remove() and call only from virtio_gpu_release().
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-14 21:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-29 7:07 [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put() Abhin Parekadan Jose
2026-09-29 7:16 ` sashiko-bot
2026-10-12 5:44 ` Abhin Parekadan Jose
2026-10-13 22:16 ` Dmitry Osipenko
2026-10-14 19:53 ` Abhin Parekadan Jose
2026-10-14 21:03 ` Dmitry Osipenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.