public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH v9 0/3] Virtio-GPU S4 support
@ 2026-05-26 19:28 dongwon.kim
  2026-05-26 19:28 ` [PATCH v9 1/3] drm/virtio: Freeze and restore hooks to support suspend and resume dongwon.kim
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: dongwon.kim @ 2026-05-26 19:28 UTC (permalink / raw)
  To: dri-devel, airlied, kraxel, dmitry.osipenko

From: Dongwon Kim <dongwon.kim@intel.com>

This patch series implements the .freeze and .restore hooks for the virtio-gpu
driver, alongside a PM notifier to properly handle object tracking and 
restoration for S4 (hibernation) scenarios.

The first patch adds the `virtgpu_freeze` and `virtgpu_restore` functions. 
These functions orchestrate flushing pending work, safely deleting virtio 
queues before suspension once they are empty, and recreating them during 
the restoration process.

The second patch implements a tracking and recreation mechanism for active 
`virtio_gpu_object` instances. This is necessary because the host hypervisor 
(e.g., QEMU) terminates or resets the backend during a full hibernation cycle, 
wiping out all previously established graphics resources and causing post-resume 
errors in the guest.

The third patch integrates a PM notifier block into the driver. It captures 
the PM_HIBERNATION_PREPARE phase to check compatibility (blocking S4 if Virgl 
3D is active) and sets a state flag. This flag instructs `virtgpu_restore` to 
fully re-submit and restore active GPU objects immediately after the fresh 
virtqueues are reconfigured.

These changes ensure that the virtio-gpu driver can cleanly survive guest 
hibernation without experiencing host-side resource loss.

v2: 10ms sleep is added in virtgpu_freeze to avoid the situation
    the driver is locked up during resumption.

v3: Plain 10ms delay (v2) is replaced with wait calls which wait until
    the virtio queue is empty.
    (Dmitry Osipenko)

v4: New version of patchset only covers S4 case because loss of resources in S3
    case can be avoided by skipping virtio-gpu-reset in QEMU (hw/display/virtio-gpu.c).
    To skip virtio-gpu-reset (soft-reset), virtio-gpu-pci device should be attached to
    PCIE bus AND a PCIE option, 'x-pcie-pm-no-soft-reset' should added and set to 'true'.
    (e.g. -device virtio-gpu-pci,bus=port,x-pcie-pm-no-soft-reset=true)

v5: Remove virtio_gpu_object from the restore list before freeing the object
    to prevent an use-after-free situation.
    (Nirmoy Das)

    Protect restore list operations with a spinlock
    (Nirmoy Das)

    Move restore list node into virtio_gpu_bo struct to reduce memory usage
    (Dmitry Osipenko)

    Remove unused header - drm_atomic_helper.h
    (Dmitry Osipenko)

v6: Include object backed by imported dmabuf
    (Dmitry Osipenko)

    Not storing virgl objects in the restore_list as virgl 3D objects are not
    recoverable.
    (Dmitry Osipenko)

    Change the name 'list',a node in restore_list to 'restore_node'
    (Nirmoy Das)

    Use mutex instead of spinlock when updating restore_list
    (Nirmoy Das)

    Initialize restore_node when virtio_gpu_object is created - this is to
    check if the node is in the list with 'list_empty' before removing it.

    Restoring objects in the PM notifier is too late, as virtio-gpu
    message communication begins in virtgpu_restore once virtqueues
    are re-established. To address this, a 'hibernation' flag is set
    during the PM_HIBERNATION_PREPARE phase in the notifier. This flag
    is then used in virtgpu_restore to detect if the system is resuming
    from S4, allowing objects to be recovered immediately after virtqueues
    are reconfigured.

v7: Add a helper, virtio_gpu_add_object_to_restore_list
    (Dmitry Osipenko)

    Unreference all objects before hibernation so they can be removed
    on the host side, since they will be fully restored anyway. This
    prevents the situation where host-side hibernation fails (leaving
    all associated resources still alive) while the virtio-gpu driver
    still attempts to restore those objects.
    (Dmitry Osipenko)

v8: Add drm_print.h to virtgpu_prime.c

v9: Move duplicate wait_event_timeout blocks into a single
    virtio_gpu_wait_queue helper function.
    (Dmitry Osipenko)

    Handle timeouts gracefully by returning -ETIMEDOUT to abort
    the freeze operation if the host hangs.
    (Dmitry Osipenko)

Dongwon Kim (3):
  drm/virtio: Freeze and restore hooks to support suspend and resume
  drm/virtio: Add support for saving and restoring virtio_gpu_objects
  drm/virtio: Add PM notifier to restore objects after hibernation

 drivers/gpu/drm/virtio/virtgpu_drv.c    | 80 ++++++++++++++++++++++-
 drivers/gpu/drm/virtio/virtgpu_drv.h    | 25 ++++++-
 drivers/gpu/drm/virtio/virtgpu_kms.c    | 54 +++++++++++++--
 drivers/gpu/drm/virtio/virtgpu_object.c | 87 ++++++++++++++++++++++++-
 drivers/gpu/drm/virtio/virtgpu_prime.c  | 45 ++++++++++++-
 drivers/gpu/drm/virtio/virtgpu_vq.c     | 30 ++++++++-
 drivers/gpu/drm/virtio/virtgpu_vram.c   |  5 +-
 7 files changed, 312 insertions(+), 14 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH v8 0/3] Virtio-GPU S4 (hibernation) support
@ 2026-04-29 20:47 dongwon.kim
  2026-04-29 20:47 ` [PATCH v8 1/3] drm/virtio: Freeze and restore hooks to support suspend and resume dongwon.kim
  0 siblings, 1 reply; 9+ messages in thread
From: dongwon.kim @ 2026-04-29 20:47 UTC (permalink / raw)
  To: dri-devel, airlied, kraxel, dmitry.osipenko

From: Dongwon Kim <dongwon.kim@intel.com>

This patch series implements the .freeze and .restore hooks for the virtio-gpu 
driver, alongside a PM notifier to manage object restoration during S4 
(hibernation) cycles.

The series is structured as follows:

1. The first patch introduces `virtgpu_freeze` and `virtgpu_restore`. These
   functions handle the teardown of virtio queues before suspension and their
   subsequent recreation during the resume process.

2. The second patch implements a tracking and restoration mechanism for
   `virtio_gpu_object` instances. This is essential because the host (e.g., QEMU)
   destroys all associated graphics resources during the virtio-gpu reset
   triggered by the hibernation/resume cycle.

3. The third patch adds a PM notifier to handle the resubmission of these
   tracked virtio-gpu objects to the host once the guest restores its
   virtqueues.

Together, these changes ensure that the virtio-gpu driver can survive 
hibernation without resource loss or invalid resource errors.

v2: - Added 10ms sleep in virtgpu_freeze to prevent lockups during resumption.

v3: - Replaced the fixed 10ms delay with wait calls that trigger once the 
      virtio queue is empty.
      (Dmitry Osipenko)

v4: - Limited the scope to S4 (hibernation). S3 resource loss can be avoided 
      via QEMU configurations (e.g., x-pcie-pm-no-soft-reset=true).

v5: - Implemented removal of objects from the restore list before freeing to 
      prevent a use-after-free situation.
      (Nirmoy Das)

    - Protected restore list operations with a spinlock.
      (Nirmoy Das)

    - Moved the restore list node into the virtio_gpu_bo struct to optimize 
      memory usage.
      (Dmitry Osipenko)

    - Removed unused header: drm_atomic_helper.h.
      (Dmitry Osipenko)

v6: - Added support for objects backed by imported dma-bufs.
      (Dmitry Osipenko)

    - Excluded virgl 3D objects from the restore list as they are currently 
      non-recoverable.
      (Dmitry Osipenko)

    - Renamed the list node to 'restore_node'.
      (Nirmoy Das)

    - Switched from spinlock to mutex for restore list updates.
      (Nirmoy Das)

    - Initialized restore_node at creation to allow safe 'list_empty' checks.

    - Introduced a 'hibernation' flag in the PM notifier to trigger restoration 
      at the correct stage in `virtgpu_restore`.

v7: - Added helper: virtio_gpu_add_object_to_restore_list.
      (Dmitry Osipenko)

    - Implemented unreferencing of all host-side objects before hibernation 
      to ensure a clean state upon resume.
      (Dmitry Osipenko)

v8: - Introduced virtio_gpu_remove_from_restore_list helper and ensured it is 
      called across all object destruction paths (General, Prime, and VRAM) 
      to prevent use-after-free.
      (Dmitry Osipenko)

    - Relocated restore list removal logic from the final cleanup stage to 
      the initial free stage for improved synchronization.
      (Dmitry Osipenko)

    - Added missing drm_print.h header.

Dongwon Kim (3):
  drm/virtio: Freeze and restore hooks to support suspend and resume
  drm/virtio: Add support for saving and restoring virtio_gpu_objects
  drm/virtio: Add PM notifier to restore objects after hibernation

 drivers/gpu/drm/virtio/virtgpu_drv.c    | 74 ++++++++++++++++++++-
 drivers/gpu/drm/virtio/virtgpu_drv.h    | 24 ++++++-
 drivers/gpu/drm/virtio/virtgpu_kms.c    | 54 +++++++++++++--
 drivers/gpu/drm/virtio/virtgpu_object.c | 88 ++++++++++++++++++++++++-
 drivers/gpu/drm/virtio/virtgpu_prime.c  | 45 ++++++++++++-
 drivers/gpu/drm/virtio/virtgpu_vq.c     | 13 +++-
 drivers/gpu/drm/virtio/virtgpu_vram.c   |  5 +-
 7 files changed, 289 insertions(+), 14 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-05-27  4:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26 19:28 [PATCH v9 0/3] Virtio-GPU S4 support dongwon.kim
2026-05-26 19:28 ` [PATCH v9 1/3] drm/virtio: Freeze and restore hooks to support suspend and resume dongwon.kim
2026-05-27  4:17   ` Claude review: " Claude Code Review Bot
2026-05-26 19:28 ` [PATCH v9 2/3] drm/virtio: Add support for saving and restoring virtio_gpu_objects dongwon.kim
2026-05-27  4:17   ` Claude review: " Claude Code Review Bot
2026-05-26 19:28 ` [PATCH v9 3/3] drm/virtio: Add PM notifier to restore objects after hibernation dongwon.kim
2026-05-27  4:17   ` Claude review: " Claude Code Review Bot
2026-05-27  4:17 ` Claude review: Virtio-GPU S4 support Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-04-29 20:47 [PATCH v8 0/3] Virtio-GPU S4 (hibernation) support dongwon.kim
2026-04-29 20:47 ` [PATCH v8 1/3] drm/virtio: Freeze and restore hooks to support suspend and resume dongwon.kim
2026-05-05  1:00   ` Claude review: " Claude Code Review Bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox