public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/virtio: Add PM notifier to restore objects after hibernation
Date: Tue, 05 May 2026 11:00:35 +1000	[thread overview]
Message-ID: <review-patch3-20260429204729.993669-4-dongwon.kim@intel.com> (raw)
In-Reply-To: <20260429204729.993669-4-dongwon.kim@intel.com>

Patch Review

This patch ties everything together with the PM notifier and adds the unref-before-hibernate / restore-after-resume logic.

**Issue 1 (bug): Use-after-free risk in `virtio_gpu_cmd_unref_resource` with `no_cb=true`**

```c
vbuf->resp_cb_data = bo;
ret = virtio_gpu_queue_ctrl_buffer(vgdev, vbuf);
if (ret < 0)
    virtio_gpu_cleanup_object(bo);
```

When `no_cb=true` (called from `virtio_gpu_object_unref_all`), if `virtio_gpu_queue_ctrl_buffer()` fails, `virtio_gpu_cleanup_object(bo)` is called. This frees the BO while it's still on the restore list and still referenced by userspace GEM handles. The `no_cb` path needs different error handling — it should not call `virtio_gpu_cleanup_object()` since the intent is to keep the guest-side object alive. A simple approach:

```c
if (ret < 0 && !no_cb)
    virtio_gpu_cleanup_object(bo);
```

**Issue 2 (style): `no_cb` parameter type and naming**

```c
void virtio_gpu_cmd_unref_resource(struct virtio_gpu_device *vgdev,
                   struct virtio_gpu_object *bo,
                   int no_cb);
```

`int no_cb` should be `bool`. Also, negative-sense parameter names are confusing — `true` means "don't do the callback". Consider `bool skip_cleanup` for clarity.

**Issue 3 (style): Missing braces in `virtio_gpu_object_unref_all`**

```c
list_for_each_entry_safe(bo, tmp, &vgdev->obj_restore_list,
             restore_node)
    if (bo->created) {
        virtio_gpu_cmd_unref_resource(vgdev, bo, true);
        virtio_gpu_notify(vgdev);
    }
```

The `list_for_each_entry_safe` macro body should have braces around it per kernel coding style when the body is a compound statement. Also, `_safe` is not needed here since entries are not removed from the list during iteration — plain `list_for_each_entry` would suffice.

**Issue 4 (minor): Unnecessary include**

```c
#include <linux/pm_runtime.h>
```

in `virtgpu_kms.c` — the code only uses `register_pm_notifier()` / `unregister_pm_notifier()` from `<linux/suspend.h>`. `pm_runtime.h` appears unused.

**Issue 5 (minor): Per-object `virtio_gpu_notify` in unref_all loop**

```c
list_for_each_entry_safe(bo, tmp, ...) 
    if (bo->created) {
        virtio_gpu_cmd_unref_resource(vgdev, bo, true);
        virtio_gpu_notify(vgdev);
    }
```

Calling `virtio_gpu_notify()` after every single unref is inefficient. A single notify after the loop would batch the kick to the host.

**Issue 6 (minor): Stale `hibernation` flag after aborted hibernation**

The PM notifier sets `vgdev->hibernation = true` on `PM_HIBERNATION_PREPARE` but never clears it on `PM_POST_HIBERNATION` (which fires if hibernation is aborted). The flag is only cleared in `virtgpu_restore()`. If hibernation is attempted but aborts before freeze() runs, the flag remains set. While this is likely benign in practice (freeze/restore are only called during actual S4), handling `PM_POST_HIBERNATION` to clear the flag would be more robust:

```c
if (mode == PM_POST_HIBERNATION)
    vgdev->hibernation = false;
```

**Issue 7 (minor): Partial state on restore failure**

In `virtgpu_restore()`, if `virtio_gpu_object_restore_all()` fails:
```c
if (vgdev->hibernation) {
    vgdev->hibernation = false;
    error = virtio_gpu_object_restore_all(vgdev);
    if (error) {
        DRM_ERROR("Failed to recover virtio-gpu objects\n");
        return error;
    }
}
```

The function returns an error but the device is already marked ready (`virtio_device_ready(vdev)`) and virtqueues are established. The error path doesn't tear down the partially initialized state, though there may not be a clean way to recover at that point.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-05  1:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-04-29 20:47 ` [PATCH v8 2/3] drm/virtio: Add support for saving and restoring virtio_gpu_objects dongwon.kim
2026-05-05  1:00   ` Claude review: " Claude Code Review Bot
2026-04-29 20:47 ` [PATCH v8 3/3] drm/virtio: Add PM notifier to restore objects after hibernation dongwon.kim
2026-05-05  1:00   ` Claude Code Review Bot [this message]
2026-05-05  1:00 ` Claude review: Virtio-GPU S4 (hibernation) support Claude Code Review Bot

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=review-patch3-20260429204729.993669-4-dongwon.kim@intel.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /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