mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Abhin Parekadan Jose <abhinjoses@gmail.com>
To: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	David Airlie <airlied@redhat.com>,
	Gurchetan Singh <gurchetansingh@chromium.org>,
	Chia-I Wu <olvaffe@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Simona Vetter <simona@ffwll.ch>,
	Dongwon Kim <dongwon.kim@intel.com>,
	dri-devel@lists.freedesktop.org, virtualization@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com
Subject: Re: [PATCH] drm/virtio: Destroy obj_restore_lock on the final drm_dev_put()
Date: Sun, 18 Oct 2026 18:17:37 +0200	[thread overview]
Message-ID: <atTxIeLq1VspA70F@home-desktop> (raw)
In-Reply-To: <8e193dd9-4ceb-4bd0-a28f-f4af084b73e8@collabora.com>

On Thu, Oct 15, 2026 at 12:03:32AM +0300, Dmitry Osipenko wrote:
> 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:
> >> 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().

I tried this out and here are my findings.

That would undo b1df3a2b24a9 ("drm/virtio: add drm_driver.release
callback."), which split virtio_gpu_deinit() on purpose: "move the drm
shutdown and release to virtio_gpu_release() ... use
drm_dev_{enter,exit,unplug} to avoid touching hardware after device
removal". That matches what the documentation asks for. drm_dev_unplug()
exists so the device can be unplugged "while there are still open users
of @dev", and Documentation/gpu/drm-uapi.rst (Device Hot-Unplug) says
the DRM instance is torn down only after userspace has closed all
descriptors and mmaps. Meanwhile the virtio side has to be gone when
->remove() returns: the example in
Documentation/driver-api/virtio/writing_virtio_drivers.rst resets the
device and deletes the vqs in remove(), and virtio_dev_remove() warns
("Driver should have reset device") if the driver did not.

So the virtio teardown (reset, flushing the vq workers, del_vqs) has to
stay in remove(), and everything that open files and GEM objects can
still reach has to wait for release(). I tried moving the deinit call
into release() to be sure: the virtio core warns that the device was
not reset and that the vq MSI vectors are still allocated at PCI
removal, and the deferred reset then runs on a virtio_device that
virtio_pci_remove() already freed (KASAN use-after-free in
virtio_reset_device()). It only makes things more complicated.

obj_restore_lock is on the wrong side of that split. It is only used
from GEM paths (the ->free callbacks via
virtio_gpu_remove_from_restore_list(), object creation, and the PM
freeze/restore ops), and the free callbacks can run after unplug, like
the vbuf cache and host_visible_mm that release() already handles. So
the mutex belongs in virtio_gpu_release(), which is what this patch
does.

It only looks like the mutex_destroy(...) landed in the wrong function
virtio_gpu_deinit() instead of virtio_gpu_release() in 54a970048296.

Is there something I am missing in the framework, or have I understood
it wrong?

Regards,
Abhin

      reply	other threads:[~2026-10-18 16:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  7:07 Abhin Parekadan Jose
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
2026-10-18 16:17         ` Abhin Parekadan Jose [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=atTxIeLq1VspA70F@home-desktop \
    --to=abhinjoses@gmail.com \
    --cc=airlied@redhat.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dongwon.kim@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=olvaffe@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=syzbot+3590d97d8a586fa955c2@syzkaller.appspotmail.com \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®