Skip to content

Commit a899cac

Browse files
Yishai Hadasawilliam
authored andcommitted
vfio/mlx5: Add support for READING in chunk mode
Add support for READING in chunk mode. In case the last SAVE command recognized that there was still some image to be read, however, there was no available chunk to use for, this task was delayed for the reader till one chunk will be consumed and becomes available. In the above case, a work will be executed to read in the background the next image from the device. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20230911093856.81910-9-yishaih@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 67135f2 commit a899cac

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

drivers/vfio/pci/mlx5/main.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,41 @@ mlx5vf_get_data_buff_from_pos(struct mlx5_vf_migration_file *migf, loff_t pos,
160160
return found ? buf : NULL;
161161
}
162162

163+
static void mlx5vf_buf_read_done(struct mlx5_vhca_data_buffer *vhca_buf)
164+
{
165+
struct mlx5_vf_migration_file *migf = vhca_buf->migf;
166+
167+
if (vhca_buf->stop_copy_chunk_num) {
168+
bool is_header = vhca_buf->dma_dir == DMA_NONE;
169+
u8 chunk_num = vhca_buf->stop_copy_chunk_num;
170+
size_t next_required_umem_size = 0;
171+
172+
if (is_header)
173+
migf->buf_header[chunk_num - 1] = vhca_buf;
174+
else
175+
migf->buf[chunk_num - 1] = vhca_buf;
176+
177+
spin_lock_irq(&migf->list_lock);
178+
list_del_init(&vhca_buf->buf_elm);
179+
if (!is_header) {
180+
next_required_umem_size =
181+
migf->next_required_umem_size;
182+
migf->next_required_umem_size = 0;
183+
migf->num_ready_chunks--;
184+
}
185+
spin_unlock_irq(&migf->list_lock);
186+
if (next_required_umem_size)
187+
mlx5vf_mig_file_set_save_work(migf, chunk_num,
188+
next_required_umem_size);
189+
return;
190+
}
191+
192+
spin_lock_irq(&migf->list_lock);
193+
list_del_init(&vhca_buf->buf_elm);
194+
list_add_tail(&vhca_buf->buf_elm, &vhca_buf->migf->avail_list);
195+
spin_unlock_irq(&migf->list_lock);
196+
}
197+
163198
static ssize_t mlx5vf_buf_read(struct mlx5_vhca_data_buffer *vhca_buf,
164199
char __user **buf, size_t *len, loff_t *pos)
165200
{
@@ -195,12 +230,8 @@ static ssize_t mlx5vf_buf_read(struct mlx5_vhca_data_buffer *vhca_buf,
195230
copy_len -= page_len;
196231
}
197232

198-
if (*pos >= vhca_buf->start_pos + vhca_buf->length) {
199-
spin_lock_irq(&vhca_buf->migf->list_lock);
200-
list_del_init(&vhca_buf->buf_elm);
201-
list_add_tail(&vhca_buf->buf_elm, &vhca_buf->migf->avail_list);
202-
spin_unlock_irq(&vhca_buf->migf->list_lock);
203-
}
233+
if (*pos >= vhca_buf->start_pos + vhca_buf->length)
234+
mlx5vf_buf_read_done(vhca_buf);
204235

205236
return done;
206237
}

0 commit comments

Comments
 (0)