Skip to content

Commit 5c066c4

Browse files
Steve Sistarelegoater
authored andcommitted
vfio/iommufd: change process
Finish CPR by change the owning process of the iommufd device in post load. 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-19-git-send-email-steven.sistare@oracle.com [ clg: Fixed missing "qemu/error-report.h" include ] Signed-off-by: Cédric Le Goater <clg@redhat.com>
1 parent 010643e commit 5c066c4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

hw/vfio/cpr-iommufd.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "qemu/osdep.h"
8+
#include "qemu/error-report.h"
89
#include "qapi/error.h"
910
#include "hw/vfio/vfio-cpr.h"
1011
#include "hw/vfio/vfio-device.h"
@@ -112,10 +113,40 @@ static bool vfio_cpr_supported(IOMMUFDBackend *be, Error **errp)
112113
return true;
113114
}
114115

116+
static int iommufd_cpr_pre_save(void *opaque)
117+
{
118+
IOMMUFDBackend *be = opaque;
119+
120+
/*
121+
* The process has not changed yet, but proactively try the ioctl,
122+
* and it will fail if any DMA mappings are not supported.
123+
*/
124+
if (!iommufd_change_process_capable(be)) {
125+
error_report("some memory regions do not support "
126+
"IOMMU_IOAS_CHANGE_PROCESS");
127+
return -1;
128+
}
129+
return 0;
130+
}
131+
132+
static int iommufd_cpr_post_load(void *opaque, int version_id)
133+
{
134+
IOMMUFDBackend *be = opaque;
135+
Error *local_err = NULL;
136+
137+
if (!iommufd_change_process(be, &local_err)) {
138+
error_report_err(local_err);
139+
return -1;
140+
}
141+
return 0;
142+
}
143+
115144
static const VMStateDescription iommufd_cpr_vmstate = {
116145
.name = "iommufd",
117146
.version_id = 0,
118147
.minimum_version_id = 0,
148+
.pre_save = iommufd_cpr_pre_save,
149+
.post_load = iommufd_cpr_post_load,
119150
.needed = cpr_incoming_needed,
120151
.fields = (VMStateField[]) {
121152
VMSTATE_END_OF_LIST()

0 commit comments

Comments
 (0)