Skip to content

Commit cbb2e10

Browse files
maciejsszmigierolegoater
authored andcommitted
vfio/migration: Use BE byte order for device state wire packets
Wire data commonly use BE byte order (including in the existing migration protocol), use it also for for VFIO device state packets. This will allow VFIO multifd device state transfer between hosts with different endianness. Although currently there is no such use case, it's good to have it now for completeness. Reviewed-by: Avihai Horon <[email protected]> Signed-off-by: Maciej S. Szmigiero <[email protected]> Link: https://lore.kernel.org/qemu-devel/dcfc04cc1a50655650dbac8398e2742ada84ee39.1741611079.git.maciej.szmigiero@oracle.com Signed-off-by: Cédric Le Goater <[email protected]>
1 parent e46b7af commit cbb2e10

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

hw/vfio/migration-multifd.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "hw/vfio/vfio-common.h"
1414
#include "migration/misc.h"
1515
#include "qapi/error.h"
16+
#include "qemu/bswap.h"
1617
#include "qemu/error-report.h"
1718
#include "qemu/lockable.h"
1819
#include "qemu/main-loop.h"
@@ -155,12 +156,16 @@ bool vfio_multifd_load_state_buffer(void *opaque, char *data, size_t data_size,
155156
return false;
156157
}
157158

159+
packet->version = be32_to_cpu(packet->version);
158160
if (packet->version != VFIO_DEVICE_STATE_PACKET_VER_CURRENT) {
159161
error_setg(errp, "%s: packet has unknown version %" PRIu32,
160162
vbasedev->name, packet->version);
161163
return false;
162164
}
163165

166+
packet->idx = be32_to_cpu(packet->idx);
167+
packet->flags = be32_to_cpu(packet->flags);
168+
164169
if (packet->idx == UINT32_MAX) {
165170
error_setg(errp, "%s: packet index is invalid", vbasedev->name);
166171
return false;
@@ -558,9 +563,9 @@ vfio_save_complete_precopy_thread_config_state(VFIODevice *vbasedev,
558563

559564
packet_len = sizeof(*packet) + bioc->usage;
560565
packet = g_malloc0(packet_len);
561-
packet->version = VFIO_DEVICE_STATE_PACKET_VER_CURRENT;
562-
packet->idx = idx;
563-
packet->flags = VFIO_DEVICE_STATE_CONFIG_STATE;
566+
packet->version = cpu_to_be32(VFIO_DEVICE_STATE_PACKET_VER_CURRENT);
567+
packet->idx = cpu_to_be32(idx);
568+
packet->flags = cpu_to_be32(VFIO_DEVICE_STATE_CONFIG_STATE);
564569
memcpy(&packet->data, bioc->data, bioc->usage);
565570

566571
if (!multifd_queue_device_state(idstr, instance_id,
@@ -610,7 +615,7 @@ vfio_multifd_save_complete_precopy_thread(SaveLiveCompletePrecopyThreadData *d,
610615
}
611616

612617
packet = g_malloc0(sizeof(*packet) + migration->data_buffer_size);
613-
packet->version = VFIO_DEVICE_STATE_PACKET_VER_CURRENT;
618+
packet->version = cpu_to_be32(VFIO_DEVICE_STATE_PACKET_VER_CURRENT);
614619

615620
for (idx = 0; ; idx++) {
616621
ssize_t data_size;
@@ -631,7 +636,7 @@ vfio_multifd_save_complete_precopy_thread(SaveLiveCompletePrecopyThreadData *d,
631636
break;
632637
}
633638

634-
packet->idx = idx;
639+
packet->idx = cpu_to_be32(idx);
635640
packet_size = sizeof(*packet) + data_size;
636641

637642
if (!multifd_queue_device_state(d->idstr, d->instance_id,

0 commit comments

Comments
 (0)