qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Cedric Le Goater <clg@redhat.com>, Yi Liu <yi.l.liu@intel.com>,
	Eric Auger <eric.auger@redhat.com>,
	Zhenzhong Duan <zhenzhong.duan@intel.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
	Steve Sistare <steven.sistare@oracle.com>
Subject: [PATCH V6 13/21] migration: vfio cpr state hook
Date: Wed,  2 Jul 2025 14:58:50 -0700	[thread overview]
Message-ID: <1751493538-202042-14-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1751493538-202042-1-git-send-email-steven.sistare@oracle.com>

Define a list of vfio devices in CPR state, in a subsection so that
older QEMU can be live updated to this version.  However, new QEMU
will not be live updateable to old QEMU.  This is acceptable because
CPR is not yet commonly used, and updates to older versions are unusual.

The contents of each device object will be defined by the vfio subsystem
in a subsequent patch.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 include/hw/vfio/vfio-cpr.h |  1 +
 include/migration/cpr.h    | 12 ++++++++++++
 hw/vfio/cpr-iommufd.c      |  2 ++
 hw/vfio/iommufd-stubs.c    | 18 ++++++++++++++++++
 migration/cpr.c            | 15 ++++++---------
 hw/vfio/meson.build        |  1 +
 6 files changed, 40 insertions(+), 9 deletions(-)
 create mode 100644 hw/vfio/iommufd-stubs.c

diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h
index e0e3ee2..c94d5e0 100644
--- a/include/hw/vfio/vfio-cpr.h
+++ b/include/hw/vfio/vfio-cpr.h
@@ -74,6 +74,7 @@ void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
                                int nr);
 
 extern const VMStateDescription vfio_cpr_pci_vmstate;
+extern const VMStateDescription vmstate_cpr_vfio_devices;
 
 void vfio_cpr_add_kvm_notifier(void);
 
diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index eb27a93..3fc19a7 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -9,11 +9,23 @@
 #define MIGRATION_CPR_H
 
 #include "qapi/qapi-types-migration.h"
+#include "qemu/queue.h"
 
 #define MIG_MODE_NONE           -1
 
 #define QEMU_CPR_FILE_MAGIC     0x51435052
 #define QEMU_CPR_FILE_VERSION   0x00000001
+#define CPR_STATE "CprState"
+
+typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
+typedef QLIST_HEAD(CprVFIODeviceList, CprVFIODevice) CprVFIODeviceList;
+
+typedef struct CprState {
+    CprFdList fds;
+    CprVFIODeviceList vfio_devices;
+} CprState;
+
+extern CprState cpr_state;
 
 void cpr_save_fd(const char *name, int id, int fd);
 void cpr_delete_fd(const char *name, int id);
diff --git a/hw/vfio/cpr-iommufd.c b/hw/vfio/cpr-iommufd.c
index 2f58b43..f95773b 100644
--- a/hw/vfio/cpr-iommufd.c
+++ b/hw/vfio/cpr-iommufd.c
@@ -14,6 +14,8 @@
 #include "system/iommufd.h"
 #include "vfio-iommufd.h"
 
+const VMStateDescription vmstate_cpr_vfio_devices;  /* TBD in a later patch */
+
 static bool vfio_cpr_supported(IOMMUFDBackend *be, Error **errp)
 {
     if (!iommufd_change_process_capable(be)) {
diff --git a/hw/vfio/iommufd-stubs.c b/hw/vfio/iommufd-stubs.c
new file mode 100644
index 0000000..0be5276
--- /dev/null
+++ b/hw/vfio/iommufd-stubs.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2025 Oracle and/or its affiliates.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "migration/cpr.h"
+#include "migration/vmstate.h"
+
+const VMStateDescription vmstate_cpr_vfio_devices = {
+    .name = CPR_STATE "/vfio devices",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]){
+        VMSTATE_END_OF_LIST()
+    }
+};
diff --git a/migration/cpr.c b/migration/cpr.c
index 535d587..42ad0b0 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -7,6 +7,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
+#include "hw/vfio/vfio-device.h"
 #include "migration/cpr.h"
 #include "migration/misc.h"
 #include "migration/options.h"
@@ -20,13 +21,7 @@
 /*************************************************************************/
 /* cpr state container for all information to be saved. */
 
-typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
-
-typedef struct CprState {
-    CprFdList fds;
-} CprState;
-
-static CprState cpr_state;
+CprState cpr_state;
 
 /****************************************************************************/
 
@@ -127,8 +122,6 @@ int cpr_open_fd(const char *path, int flags, const char *name, int id,
 }
 
 /*************************************************************************/
-#define CPR_STATE "CprState"
-
 static const VMStateDescription vmstate_cpr_state = {
     .name = CPR_STATE,
     .version_id = 1,
@@ -136,6 +129,10 @@ static const VMStateDescription vmstate_cpr_state = {
     .fields = (VMStateField[]) {
         VMSTATE_QLIST_V(fds, CprState, 1, vmstate_cpr_fd, CprFd, next),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (const VMStateDescription * const []) {
+        &vmstate_cpr_vfio_devices,
+        NULL
     }
 };
 /*************************************************************************/
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index 7a88174..bfaf6be 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -33,6 +33,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
   'iommufd.c',
   'cpr-iommufd.c',
 ))
+system_ss.add(when: 'CONFIG_IOMMUFD', if_false: files('iommufd-stubs.c'))
 system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
 ))
-- 
1.8.3.1



  parent reply	other threads:[~2025-07-02 22:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02 21:58 [PATCH V6 00/21] Live update: vfio and iommufd Steve Sistare
2025-07-02 21:58 ` [PATCH V6 01/21] vfio-pci: preserve MSI Steve Sistare
2025-07-03  6:13   ` Cédric Le Goater
2025-07-02 21:58 ` [PATCH V6 02/21] vfio-pci: preserve INTx Steve Sistare
2025-07-03  6:13   ` Cédric Le Goater
2025-07-02 21:58 ` [PATCH V6 03/21] migration: close kvm after cpr Steve Sistare
2025-07-02 22:05   ` Steven Sistare
2025-07-04  9:50     ` Duan, Zhenzhong
2025-07-07 13:07       ` Steven Sistare
2025-07-08  3:04         ` Duan, Zhenzhong
2025-07-02 21:58 ` [PATCH V6 04/21] migration: cpr_get_fd_param helper Steve Sistare
2025-07-02 21:58 ` [PATCH V6 05/21] backends/iommufd: iommufd_backend_map_file_dma Steve Sistare
2025-07-02 21:58 ` [PATCH V6 06/21] backends/iommufd: change process ioctl Steve Sistare
2025-07-02 21:58 ` [PATCH V6 07/21] physmem: qemu_ram_get_fd_offset Steve Sistare
2025-07-02 21:58 ` [PATCH V6 08/21] vfio/iommufd: use IOMMU_IOAS_MAP_FILE Steve Sistare
2025-07-02 21:58 ` [PATCH V6 09/21] vfio/iommufd: invariant device name Steve Sistare
2025-07-02 21:58 ` [PATCH V6 10/21] vfio/iommufd: add vfio_device_free_name Steve Sistare
2025-07-02 21:58 ` [PATCH V6 11/21] vfio/iommufd: device name blocker Steve Sistare
2025-07-02 21:58 ` [PATCH V6 12/21] vfio/iommufd: register container for cpr Steve Sistare
2025-07-03  2:42   ` Duan, Zhenzhong
2025-07-02 21:58 ` Steve Sistare [this message]
2025-07-03  2:44   ` [PATCH V6 13/21] migration: vfio cpr state hook Duan, Zhenzhong
2025-07-02 21:58 ` [PATCH V6 14/21] vfio/iommufd: cpr state Steve Sistare
2025-07-02 21:58 ` [PATCH V6 15/21] vfio/iommufd: preserve descriptors Steve Sistare
2025-07-02 21:58 ` [PATCH V6 16/21] vfio/iommufd: reconstruct device Steve Sistare
2025-07-02 21:58 ` [PATCH V6 17/21] vfio/iommufd: reconstruct hwpt Steve Sistare
2025-07-02 21:58 ` [PATCH V6 18/21] vfio/iommufd: change process Steve Sistare
2025-07-02 21:58 ` [PATCH V6 19/21] iommufd: preserve DMA mappings Steve Sistare
2025-07-02 21:58 ` [PATCH V6 20/21] vfio/container: delete old cpr register Steve Sistare
2025-07-02 21:58 ` [PATCH V6 21/21] vfio: doc changes for cpr Steve Sistare
2025-07-03  6:22 ` [PATCH V6 00/21] Live update: vfio and iommufd Cédric Le Goater

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=1751493538-202042-14-git-send-email-steven.sistare@oracle.com \
    --to=steven.sistare@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=farosas@suse.de \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yi.l.liu@intel.com \
    --cc=zhenzhong.duan@intel.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).