Skip to content

Commit a6f2f9c

Browse files
Steve Sistarelegoater
authored andcommitted
migration: vfio cpr state hook
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> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/1751493538-202042-14-git-send-email-steven.sistare@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
1 parent 06c6a65 commit a6f2f9c

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

hw/vfio/cpr-iommufd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "system/iommufd.h"
1515
#include "vfio-iommufd.h"
1616

17+
const VMStateDescription vmstate_cpr_vfio_devices; /* TBD in a later patch */
18+
1719
static bool vfio_cpr_supported(IOMMUFDBackend *be, Error **errp)
1820
{
1921
if (!iommufd_change_process_capable(be)) {

hw/vfio/iommufd-stubs.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* SPDX-License-Identifier: GPL-2.0-or-later
5+
*/
6+
7+
#include "qemu/osdep.h"
8+
#include "migration/cpr.h"
9+
#include "migration/vmstate.h"
10+
11+
const VMStateDescription vmstate_cpr_vfio_devices = {
12+
.name = CPR_STATE "/vfio devices",
13+
.version_id = 1,
14+
.minimum_version_id = 1,
15+
.fields = (const VMStateField[]){
16+
VMSTATE_END_OF_LIST()
17+
}
18+
};

hw/vfio/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
3333
'iommufd.c',
3434
'cpr-iommufd.c',
3535
))
36+
system_ss.add(when: 'CONFIG_IOMMUFD', if_false: files('iommufd-stubs.c'))
3637
system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
3738
'display.c',
3839
))

include/hw/vfio/vfio-cpr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void vfio_cpr_delete_vector_fd(struct VFIOPCIDevice *vdev, const char *name,
7575
int nr);
7676

7777
extern const VMStateDescription vfio_cpr_pci_vmstate;
78+
extern const VMStateDescription vmstate_cpr_vfio_devices;
7879

7980
void vfio_cpr_add_kvm_notifier(void);
8081

include/migration/cpr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@
99
#define MIGRATION_CPR_H
1010

1111
#include "qapi/qapi-types-migration.h"
12+
#include "qemu/queue.h"
1213

1314
#define MIG_MODE_NONE -1
1415

1516
#define QEMU_CPR_FILE_MAGIC 0x51435052
1617
#define QEMU_CPR_FILE_VERSION 0x00000001
18+
#define CPR_STATE "CprState"
19+
20+
typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
21+
typedef QLIST_HEAD(CprVFIODeviceList, CprVFIODevice) CprVFIODeviceList;
22+
23+
typedef struct CprState {
24+
CprFdList fds;
25+
CprVFIODeviceList vfio_devices;
26+
} CprState;
27+
28+
extern CprState cpr_state;
1729

1830
void cpr_save_fd(const char *name, int id, int fd);
1931
void cpr_delete_fd(const char *name, int id);

migration/cpr.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "qemu/osdep.h"
99
#include "qapi/error.h"
10+
#include "hw/vfio/vfio-device.h"
1011
#include "migration/cpr.h"
1112
#include "migration/misc.h"
1213
#include "migration/options.h"
@@ -20,13 +21,7 @@
2021
/*************************************************************************/
2122
/* cpr state container for all information to be saved. */
2223

23-
typedef QLIST_HEAD(CprFdList, CprFd) CprFdList;
24-
25-
typedef struct CprState {
26-
CprFdList fds;
27-
} CprState;
28-
29-
static CprState cpr_state;
24+
CprState cpr_state;
3025

3126
/****************************************************************************/
3227

@@ -127,15 +122,17 @@ int cpr_open_fd(const char *path, int flags, const char *name, int id,
127122
}
128123

129124
/*************************************************************************/
130-
#define CPR_STATE "CprState"
131-
132125
static const VMStateDescription vmstate_cpr_state = {
133126
.name = CPR_STATE,
134127
.version_id = 1,
135128
.minimum_version_id = 1,
136129
.fields = (VMStateField[]) {
137130
VMSTATE_QLIST_V(fds, CprState, 1, vmstate_cpr_fd, CprFd, next),
138131
VMSTATE_END_OF_LIST()
132+
},
133+
.subsections = (const VMStateDescription * const []) {
134+
&vmstate_cpr_vfio_devices,
135+
NULL
139136
}
140137
};
141138
/*************************************************************************/

0 commit comments

Comments
 (0)