On Sun, Nov 06, 2022 at 07:46:28PM +0200, Yishai Hadas wrote: > +start_over: > if (migf->allocated_length < requested_length) { > - done = mlx5vf_add_migration_pages( > + ret = mlx5vf_add_migration_pages( > migf, > DIV_ROUND_UP(requested_length - migf->allocated_length, > PAGE_SIZE), &migf->table); > - if (done) > + if (ret) > + goto out_unlock; > + } This really wants to be coded as a state machine, not a tangle of gotos > + > + if (VFIO_PRE_COPY_SUPP(migf->mvdev)) { > + if (!migf->header_read) > + mlx5vf_recv_sw_header(migf, pos, &buf, &len, &done); > + if (done < 0) > goto out_unlock; And when you make it into a FSM then we can pre-allocate the required sg_table space based on the header instead of having to stream Jason