On 28.02.2025 09:09, Cédric Le Goater wrote:
On 2/26/25 22:04, Maciej S. Szmigiero wrote:
On 26.02.2025 11:43, Cédric Le Goater wrote:
On 2/19/25 21:34, Maciej S. Szmigiero wrote:
From: "Maciej S. Szmigiero" <maciej.szmigi...@oracle.com>

The multifd received data needs to be reassembled since device state
packets sent via different multifd channels can arrive out-of-order.

Therefore, each VFIO device state packet carries a header indicating its
position in the stream.
The raw device state data is saved into a VFIOStateBuffer for later
in-order loading into the device.

The last such VFIO device state packet should have
VFIO_DEVICE_STATE_CONFIG_STATE flag set and carry the device config state.

Signed-off-by: Maciej S. Szmigiero <maciej.szmigi...@oracle.com>
---
  hw/vfio/migration-multifd.c | 103 ++++++++++++++++++++++++++++++++++++
  hw/vfio/migration-multifd.h |   3 ++
  hw/vfio/migration.c         |   1 +
  hw/vfio/trace-events        |   1 +
  4 files changed, 108 insertions(+)

diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
index c2defc0efef0..5d5ee1393674 100644
--- a/hw/vfio/migration-multifd.c
+++ b/hw/vfio/migration-multifd.c
@@ -42,6 +42,11 @@ typedef struct VFIOStateBuffer {
  } VFIOStateBuffer;
  typedef struct VFIOMultifd {
+    VFIOStateBuffers load_bufs;
+    QemuCond load_bufs_buffer_ready_cond;
+    QemuMutex load_bufs_mutex; /* Lock order: this lock -> BQL */
+    uint32_t load_buf_idx;
+    uint32_t load_buf_idx_last;
  } VFIOMultifd;
  static void vfio_state_buffer_clear(gpointer data)
@@ -87,15 +92,113 @@ static VFIOStateBuffer 
*vfio_state_buffers_at(VFIOStateBuffers *bufs, guint idx)
      return &g_array_index(bufs->array, VFIOStateBuffer, idx);
  }

this routine expects load_bufs_mutex to be locked ? May be say so.

I guess the comment above pertains to the vfio_load_state_buffer_insert()
below.

Do you mean it should have a comment that it expects to be called
under load_bufs_mutex?

Just a one liner like :

/* called with load_bufs_mutex locked */

?

It's good to have for the future generations.

Okay, done.


+static bool vfio_load_state_buffer_insert(VFIODevice *vbasedev,

could you pass VFIOMultifd* instead  ?

No, it needs vbasedev->migration_max_queued_buffers too (introduced
in later patch).
> Also, most of VFIO routines (besides very small helpers/wrappers)
take VFIODevice *.

OK. It's minor but I prefer when parameters are limited to the minimum.
Having 'VFIODevice *' opens doors to a lot of state.


Thanks,

C.


Thanks.
Maciej


Reply via email to