Virtuozzo QEMU development (svt-core@virtuozzo.com)
 help / color / mirror / Atom feed
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: svt-core@virtuozzo.com
Cc: den@openvz.org
Subject: Re: [PATCH hci-dev v6 1/2] vfio/migration: stop a device left running after a guest shutdown #VSTOR-153976
Date: Mon,  9 Nov 2026 23:07:20 +0200	[thread overview]
Message-ID: <20261109210721.222909-1-andrey.drobyshev@virtuozzo.com> (raw)
In-Reply-To: <010701a1c217fe1a-e6584213-39bd-4c2d-b5c0-3d03ca1537d2-000000@eu-central-1.amazonses.com>

On 11/9/26 22:55, no-reply@sashiko.virtuozzo.com wrote:
> [Severity: Medium]
> Can a device still be closed or saved running after a reset of the stopped
> VM? The stop decision uses only the cached migration->device_state.
>
> At this commit, a VM stop with RUN_STATE_SHUTDOWN runs
> vfio_vmstate_change(), which moves the device to STOP and caches STOP.
>
> A later reset goes through qemu_system_reset() -> qemu_devices_reset() ->
> vfio_pci_reset() -> ioctl(VFIO_DEVICE_RESET). This path does not go through
> vm_state_notify() and does not update migration->device_state.

This is how QEMU behaves today, without this series: the cache says STOP
while the kernel has reset the device. The patch does not change that
sequence. A device that has just been reset is idle, it has no guest
driver and no DMA, so closing or saving it is the same as closing or
saving a freshly started device. The patch is about a device the guest
shutdown left running, not about the cache after a reset.

Updating the cache on reset is not safe either: the NVIDIA vGPU driver
keeps its migration state across a reset, so a paused VM that is reset
and continued would end up with the device in STOP while the guest runs.

> [Severity: Low]
> Is the commit message accurate for this patch on its own? It says:
>
>     A reset of the stopped VM leaves the device in RUNNING_P2P. Nothing
>     else does, so a device in that state is stopped in any run state.
> [...]
> A reset therefore does not find the device in RUNNING_P2P here. The
> RUNNING_P2P arm of the new helper is unreachable until the follow-up patch
> adds an early return in vfio_vmstate_change() for the guest-shutdown case.

That is intended. This patch has to come first, so that no commit in the
series can close a device running. On its own it is a no-op, and the
message says so: "The next patch does it at every guest shutdown."

> Also, "Only that leaves a device in RUNNING_P2P" does not seem strictly
> true, since a failed vfio_vmstate_change() on VM start can leave
> RUNNING_P2P with the VM running.

It cannot. vfio_vmstate_change() uses vfio_migration_set_state_or_reset(),
which resets the device when the transition fails and caches RUNNING.
RUNNING_P2P is never left behind by a failure.

> [Severity: Low]
> Is it safe to move a device in RUNNING directly to STOP here? This bypasses
> the RUNNING -> RUNNING_P2P step that vfio_vmstate_change_prepare() runs for
> all devices before any device is stopped.
> [...]
> For example, with -no-shutdown, a migration of a SHUTDOWN VM fails.
> vfio_migration_state_notifier() then sets every device to RUNNING with no
> P2P round. A following quit or a new save moves one RUNNING device straight
> to STOP while its peers are still RUNNING, so a running peer could issue
> P2P DMA to a stopped device.

The failure handler itself moves the devices to RUNNING one by one, with
no P2P round, for any stopped VM, today. The VM has been stopped the
whole time, so the guest cannot have started any new DMA. Stopping the
devices one by one afterwards adds nothing to what that path already
does. The comment states exactly this.

  reply	other threads:[~2026-11-09 21:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 20:45 [PATCH hci-dev v6 0/2] vfio/migration: don't stop the device on " Andrey Drobyshev
2026-11-09 20:45 ` [PATCH hci-dev v6 1/2] vfio/migration: stop a device left running after a " Andrey Drobyshev
2026-11-09 20:55   ` no-reply
2026-11-09 21:07     ` Andrey Drobyshev [this message]
2026-11-09 20:45 ` [PATCH hci-dev v6 2/2] vfio/migration: don't stop the device on " Andrey Drobyshev
2026-11-09 20:57   ` no-reply
2026-11-09 21:07     ` Andrey Drobyshev

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=20261109210721.222909-1-andrey.drobyshev@virtuozzo.com \
    --to=andrey.drobyshev@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=svt-core@virtuozzo.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