From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: Jason Wang <jasowang@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
Hamza Khan <hamza.khan@nutanix.com>,
Steve Sistare <steven.sistare@oracle.com>
Subject: [RFC V2 3/8] vhost: reset vhost devices for cpr
Date: Thu, 17 Jul 2025 11:39:23 -0700 [thread overview]
Message-ID: <1752777568-236368-4-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1752777568-236368-1-git-send-email-steven.sistare@oracle.com>
When preserving a vhost fd using CPR, call VHOST_RESET_OWNER prior to CPR
in old QEMU. Otherwise, new QEMU will fail when it calls VHOST_SET_OWNER
during vhost_dev_init.
Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
include/hw/virtio/vhost.h | 1 +
hw/virtio/vhost.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 38800a7..88a4838 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -132,6 +132,7 @@ struct vhost_dev {
QLIST_ENTRY(vhost_dev) logdev_entry;
QLIST_HEAD(, vhost_iommu) iommu_list;
IOMMUNotifier n;
+ NotifierWithReturn cpr_transfer_notifier;
const VhostDevConfigOps *config_ops;
};
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index fc43853..a562e0c 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -24,6 +24,7 @@
#include "standard-headers/linux/vhost_types.h"
#include "hw/virtio/virtio-bus.h"
#include "hw/mem/memory-device.h"
+#include "migration/misc.h"
#include "migration/blocker.h"
#include "migration/qemu-file-types.h"
#include "system/dma.h"
@@ -1506,6 +1507,32 @@ static void vhost_virtqueue_cleanup(struct vhost_virtqueue *vq)
}
}
+static int vhost_cpr_notifier(NotifierWithReturn *notifier,
+ MigrationEvent *e, Error **errp)
+{
+ struct vhost_dev *dev;
+ int r;
+
+ dev = container_of(notifier, struct vhost_dev, cpr_transfer_notifier);
+
+ if (dev->vhost_ops->backend_type != VHOST_BACKEND_TYPE_KERNEL) {
+ return 0;
+ }
+
+ if (e->type == MIG_EVENT_PRECOPY_SETUP) {
+ r = dev->vhost_ops->vhost_reset_device(dev);
+ if (r < 0) {
+ VHOST_OPS_DEBUG(r, "vhost_reset_device failed");
+ }
+ } else if (e->type == MIG_EVENT_PRECOPY_FAILED) {
+ r = dev->vhost_ops->vhost_set_owner(dev);
+ if (r < 0) {
+ VHOST_OPS_DEBUG(r, "vhost_set_owner failed");
+ }
+ }
+ return 0;
+}
+
int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
VhostBackendType backend_type, uint32_t busyloop_timeout,
Error **errp)
@@ -1516,6 +1543,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
hdev->vdev = NULL;
hdev->migration_blocker = NULL;
+ hdev->cpr_transfer_notifier.notify = NULL;
r = vhost_set_backend_type(hdev, backend_type);
assert(r >= 0);
@@ -1616,6 +1644,9 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
hdev->log_enabled = false;
hdev->started = false;
memory_listener_register(&hdev->memory_listener, &address_space_memory);
+ migration_add_notifier_mode(&hdev->cpr_transfer_notifier,
+ vhost_cpr_notifier,
+ MIG_MODE_CPR_TRANSFER);
QLIST_INSERT_HEAD(&vhost_devices, hdev, entry);
/*
@@ -1672,6 +1703,7 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
QLIST_REMOVE(hdev, entry);
}
migrate_del_blocker(&hdev->migration_blocker);
+ migration_remove_notifier(&hdev->cpr_transfer_notifier);
g_free(hdev->mem);
g_free(hdev->mem_sections);
if (hdev->vhost_ops) {
--
1.8.3.1
next prev parent reply other threads:[~2025-07-17 20:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 18:39 [RFC V2 0/8] Live update: tap and vhost Steve Sistare
2025-07-17 18:39 ` [RFC V2 1/8] migration: stop vm earlier for cpr Steve Sistare
2025-07-17 18:39 ` [RFC V2 2/8] migration: cpr setup notifier Steve Sistare
2025-07-17 18:39 ` Steve Sistare [this message]
2025-08-27 11:29 ` [RFC V2 3/8] vhost: reset vhost devices for cpr Vladimir Sementsov-Ogievskiy
2025-08-27 18:38 ` Steven Sistare
2025-07-17 18:39 ` [RFC V2 4/8] cpr: delete all fds Steve Sistare
2025-07-17 18:39 ` [RFC V2 5/8] Revert "vhost-backend: remove vhost_kernel_reset_device()" Steve Sistare
2025-08-22 18:26 ` Steven Sistare
2025-07-17 18:39 ` [RFC V2 6/8] tap: common return label Steve Sistare
2025-07-17 18:39 ` [RFC V2 7/8] tap: cpr support Steve Sistare
2025-07-17 18:39 ` [RFC V2 8/8] tap: postload fix for cpr Steve Sistare
2025-07-18 8:48 ` [RFC V2 0/8] Live update: tap and vhost Lei Yang
2025-07-18 17:31 ` Steven Sistare
2025-07-24 5:46 ` Lei Yang
2025-08-05 13:54 ` Fabiano Rosas
2025-08-05 19:53 ` Steven Sistare
2025-08-06 15:51 ` Peter Xu
2025-08-11 18:24 ` Steven Sistare
2025-08-23 21:53 ` Vladimir Sementsov-Ogievskiy
2025-08-28 15:48 ` Steven Sistare
2025-08-29 19:37 ` Steven Sistare
2025-09-01 11:44 ` Vladimir Sementsov-Ogievskiy
2025-09-02 15:33 ` Steven Sistare
2025-09-02 17:09 ` Vladimir Sementsov-Ogievskiy
2025-09-05 16:16 ` Peter Xu
2025-09-08 9:55 ` Vladimir Sementsov-Ogievskiy
2025-09-09 21:35 ` Vladimir Sementsov-Ogievskiy
2025-09-10 16:58 ` Peter Xu
2025-09-10 17:27 ` Vladimir Sementsov-Ogievskiy
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=1752777568-236368-4-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=farosas@suse.de \
--cc=hamza.khan@nutanix.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.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;
as well as URLs for NNTP newsgroup(s).