From: Peter Xu <peterx@redhat.com>
To: "Maciej S. Szmigiero" <mail@maciej.szmigiero.name>
Cc: "Fabiano Rosas" <farosas@suse.de>,
"Alex Williamson" <alex@shazbot.org>,
"Cédric Le Goater" <clg@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Avihai Horon" <avihaih@nvidia.com>,
qemu-devel@nongnu.org
Subject: Re: [PATCH 2/2] vfio/migration: Parallelize device state transitions
Date: Wed, 15 Jul 2026 11:30:33 -0400 [thread overview]
Message-ID: <alenmdWqD-x3bYll@x1.local> (raw)
In-Reply-To: <19b76c19-4c7b-4a48-8c77-7db8746ff570@maciej.szmigiero.name>
On Tue, Jul 14, 2026 at 10:23:05PM +0200, Maciej S. Szmigiero wrote:
> The VFIO devices in {PRE_COPY,RUNNING}_P2P states can {still,already} accept
> DMA so in the master branch by the time prepare_cb() handlers exit and
> cb() ones start running the VFIO devices are {still,already} capable of
> accepting incoming DMA.
>
> On the other hand, if you meant the state transition into STOP_COPY on the
> migration source currently initiated from cb() handler then there can be an
> ordering issue in principle.
>
> It looks like the current master branch mostly avoids this by registering
> vhost-net vm_state_change handler from VirtIODevice and not from its parent
> PCI device, so with the usual PCI topology vhost-net cb() handler will run
> before the VFIO PCI device one (and so still hit DMA-capable VFIO device)
> due to the vhost-net VirtIODevice being one level deeper in the qdev tree.
> It could theoretically be problem with more complex PCI topology though.
That's an interesting observation, but neither do I think it's intentional,
nor do I think it guarantees the depth ordering. Consider when a VFIO
device is put under a few layers of PCIe switches, or PCI bridges. In that
case the VFIO device notifier can have larger depth value v.s. the virtio
device when the virtio device is attached to the root complex.
>
> > It is also an issue then even before P2P_DMA state introduced, because
> > before that all cb()s can be run at random orders.
>
> Technically, the order is based on the device qdev tree depth and within
> the same qdev tree depth level it looks like the handler calling order will
> be dependent on the order the registering devices were instantiated.
>
> This means that even before these P2P states were introduced
> VM configurations that instantiated VFIO/virtio devices in the certain
> "right" order or topology weren't affected.
>
> So maybe adding these P2P states mostly fixed this issue too?
I still think they're two different issues, and I still think with/without
P2P the issue is the same, now I tend to agree this issue exists,
especially if virtio-blk have similar behavior like virtio-net.
For one example of virtio-blk DMA to VFIO MMIO regions:
https://lore.kernel.org/r/20260616052552.389021-1-gshan@redhat.com
Said that, I don't know it's 100% triggerable in this case with notifiers,
but sounds relevant. For virtio-net and others, I have less idea.
In all cases, I still think there are two issues to fix, and I think we
don't need to fix this problem in one shot. I still don't think they're
directly relevant, at least on the goals.
So with what I suggested previously relying on prepare_cb() I believe we
can still do the concurrency issue you're looking for, making sure when
reaching VFIO's cb() it's still at least accepting DMAs (P2P is fine).
For the other issue you reported, even if existed, I am not yet sure VFIO
is the only special case that got affected. I think it's possible some
other emulated devices suffer the same even if it has no direct hardware
attached. Say, there can be device backends got stopped in cb() when VM
stopped, further DMA to it may cause assertions, then it's the same issue
that needs solving, where essentially we may require all such devices to
provide similar P2P states like VFIO to make sure they initiate DMAs and
flush them in a prepare_cb(), then if all devices' prepare_cb() will make
sure no DMA to be initiated anymore, cb()s will have no ordering constraint
on DMAs.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2026-07-15 15:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 14:41 [PATCH 0/2] VFIO device migration parallel state transitions Maciej S. Szmigiero
2026-05-20 14:41 ` [PATCH 1/2] system/runstate: Allow adjustment of priority for VM state change handlers Maciej S. Szmigiero
2026-06-01 13:26 ` Fabiano Rosas
2026-05-20 14:41 ` [PATCH 2/2] vfio/migration: Parallelize device state transitions Maciej S. Szmigiero
2026-06-01 13:39 ` Fabiano Rosas
2026-06-01 19:33 ` Peter Xu
2026-06-02 10:01 ` Maciej S. Szmigiero
2026-06-02 20:17 ` Peter Xu
2026-06-03 21:34 ` Maciej S. Szmigiero
2026-07-02 18:36 ` Maciej S. Szmigiero
2026-07-06 16:23 ` Peter Xu
2026-07-13 20:23 ` Maciej S. Szmigiero
2026-07-14 17:06 ` Peter Xu
2026-07-14 20:23 ` Maciej S. Szmigiero
2026-07-15 15:30 ` Peter Xu [this message]
2026-07-16 12:18 ` Maciej S. Szmigiero
2026-07-16 13:30 ` Peter Xu
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=alenmdWqD-x3bYll@x1.local \
--to=peterx@redhat.com \
--cc=alex@shazbot.org \
--cc=avihaih@nvidia.com \
--cc=clg@redhat.com \
--cc=farosas@suse.de \
--cc=mail@maciej.szmigiero.name \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 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.