@@ -308,19 +308,19 @@ static struct mlx5_vhca_data_buffer *
308308mlx5vf_mig_file_get_stop_copy_buf (struct mlx5_vf_migration_file * migf ,
309309 u8 index , size_t required_length )
310310{
311+ u32 npages = DIV_ROUND_UP (required_length , PAGE_SIZE );
311312 struct mlx5_vhca_data_buffer * buf = migf -> buf [index ];
312313 u8 chunk_num ;
313314
314315 WARN_ON (!buf );
315316 chunk_num = buf -> stop_copy_chunk_num ;
316317 buf -> migf -> buf [index ] = NULL ;
317318 /* Checking whether the pre-allocated buffer can fit */
318- if (buf -> allocated_length >= required_length )
319+ if (buf -> npages >= npages )
319320 return buf ;
320321
321322 mlx5vf_put_data_buffer (buf );
322- buf = mlx5vf_get_data_buffer (buf -> migf , required_length ,
323- DMA_FROM_DEVICE );
323+ buf = mlx5vf_get_data_buffer (buf -> migf , npages , DMA_FROM_DEVICE );
324324 if (IS_ERR (buf ))
325325 return buf ;
326326
@@ -373,7 +373,8 @@ static int mlx5vf_add_stop_copy_header(struct mlx5_vf_migration_file *migf,
373373 u8 * to_buff ;
374374 int ret ;
375375
376- header_buf = mlx5vf_get_data_buffer (migf , size , DMA_NONE );
376+ header_buf = mlx5vf_get_data_buffer (migf , DIV_ROUND_UP (size , PAGE_SIZE ),
377+ DMA_NONE );
377378 if (IS_ERR (header_buf ))
378379 return PTR_ERR (header_buf );
379380
@@ -388,7 +389,7 @@ static int mlx5vf_add_stop_copy_header(struct mlx5_vf_migration_file *migf,
388389 to_buff = kmap_local_page (page );
389390 memcpy (to_buff , & header , sizeof (header ));
390391 header_buf -> length = sizeof (header );
391- data .stop_copy_size = cpu_to_le64 (migf -> buf [0 ]-> allocated_length );
392+ data .stop_copy_size = cpu_to_le64 (migf -> buf [0 ]-> npages * PAGE_SIZE );
392393 memcpy (to_buff + sizeof (header ), & data , sizeof (data ));
393394 header_buf -> length += sizeof (data );
394395 kunmap_local (to_buff );
@@ -437,15 +438,20 @@ static int mlx5vf_prep_stop_copy(struct mlx5vf_pci_core_device *mvdev,
437438
438439 num_chunks = mvdev -> chunk_mode ? MAX_NUM_CHUNKS : 1 ;
439440 for (i = 0 ; i < num_chunks ; i ++ ) {
440- buf = mlx5vf_get_data_buffer (migf , inc_state_size , DMA_FROM_DEVICE );
441+ buf = mlx5vf_get_data_buffer (
442+ migf , DIV_ROUND_UP (inc_state_size , PAGE_SIZE ),
443+ DMA_FROM_DEVICE );
441444 if (IS_ERR (buf )) {
442445 ret = PTR_ERR (buf );
443446 goto err ;
444447 }
445448
446449 migf -> buf [i ] = buf ;
447- buf = mlx5vf_get_data_buffer (migf ,
448- sizeof (struct mlx5_vf_migration_header ), DMA_NONE );
450+ buf = mlx5vf_get_data_buffer (
451+ migf ,
452+ DIV_ROUND_UP (sizeof (struct mlx5_vf_migration_header ),
453+ PAGE_SIZE ),
454+ DMA_NONE );
449455 if (IS_ERR (buf )) {
450456 ret = PTR_ERR (buf );
451457 goto err ;
@@ -553,7 +559,8 @@ static long mlx5vf_precopy_ioctl(struct file *filp, unsigned int cmd,
553559 * We finished transferring the current state and the device has a
554560 * dirty state, save a new state to be ready for.
555561 */
556- buf = mlx5vf_get_data_buffer (migf , inc_length , DMA_FROM_DEVICE );
562+ buf = mlx5vf_get_data_buffer (migf , DIV_ROUND_UP (inc_length , PAGE_SIZE ),
563+ DMA_FROM_DEVICE );
557564 if (IS_ERR (buf )) {
558565 ret = PTR_ERR (buf );
559566 mlx5vf_mark_err (migf );
@@ -675,8 +682,8 @@ mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)
675682
676683 if (track ) {
677684 /* leave the allocated buffer ready for the stop-copy phase */
678- buf = mlx5vf_alloc_data_buffer (migf ,
679- migf -> buf [ 0 ] -> allocated_length , DMA_FROM_DEVICE );
685+ buf = mlx5vf_alloc_data_buffer (migf , migf -> buf [ 0 ] -> npages ,
686+ DMA_FROM_DEVICE );
680687 if (IS_ERR (buf )) {
681688 ret = PTR_ERR (buf );
682689 goto out_pd ;
@@ -917,11 +924,14 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
917924 goto out_unlock ;
918925 break ;
919926 case MLX5_VF_LOAD_STATE_PREP_HEADER_DATA :
920- if (vhca_buf_header -> allocated_length < migf -> record_size ) {
927+ {
928+ u32 npages = DIV_ROUND_UP (migf -> record_size , PAGE_SIZE );
929+
930+ if (vhca_buf_header -> npages < npages ) {
921931 mlx5vf_free_data_buffer (vhca_buf_header );
922932
923- migf -> buf_header [0 ] = mlx5vf_alloc_data_buffer (migf ,
924- migf -> record_size , DMA_NONE );
933+ migf -> buf_header [0 ] = mlx5vf_alloc_data_buffer (
934+ migf , npages , DMA_NONE );
925935 if (IS_ERR (migf -> buf_header [0 ])) {
926936 ret = PTR_ERR (migf -> buf_header [0 ]);
927937 migf -> buf_header [0 ] = NULL ;
@@ -934,6 +944,7 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
934944 vhca_buf_header -> start_pos = migf -> max_pos ;
935945 migf -> load_state = MLX5_VF_LOAD_STATE_READ_HEADER_DATA ;
936946 break ;
947+ }
937948 case MLX5_VF_LOAD_STATE_READ_HEADER_DATA :
938949 ret = mlx5vf_resume_read_header_data (migf , vhca_buf_header ,
939950 & buf , & len , pos , & done );
@@ -944,12 +955,13 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
944955 {
945956 u64 size = max (migf -> record_size ,
946957 migf -> stop_copy_prep_size );
958+ u32 npages = DIV_ROUND_UP (size , PAGE_SIZE );
947959
948- if (vhca_buf -> allocated_length < size ) {
960+ if (vhca_buf -> npages < npages ) {
949961 mlx5vf_free_data_buffer (vhca_buf );
950962
951- migf -> buf [0 ] = mlx5vf_alloc_data_buffer (migf ,
952- size , DMA_TO_DEVICE );
963+ migf -> buf [0 ] = mlx5vf_alloc_data_buffer (
964+ migf , npages , DMA_TO_DEVICE );
953965 if (IS_ERR (migf -> buf [0 ])) {
954966 ret = PTR_ERR (migf -> buf [0 ]);
955967 migf -> buf [0 ] = NULL ;
@@ -1037,8 +1049,11 @@ mlx5vf_pci_resume_device_data(struct mlx5vf_pci_core_device *mvdev)
10371049 }
10381050
10391051 migf -> buf [0 ] = buf ;
1040- buf = mlx5vf_alloc_data_buffer (migf ,
1041- sizeof (struct mlx5_vf_migration_header ), DMA_NONE );
1052+ buf = mlx5vf_alloc_data_buffer (
1053+ migf ,
1054+ DIV_ROUND_UP (sizeof (struct mlx5_vf_migration_header ),
1055+ PAGE_SIZE ),
1056+ DMA_NONE );
10421057 if (IS_ERR (buf )) {
10431058 ret = PTR_ERR (buf );
10441059 goto out_buf ;
@@ -1148,7 +1163,8 @@ mlx5vf_pci_step_device_state_locked(struct mlx5vf_pci_core_device *mvdev,
11481163 MLX5VF_QUERY_INC | MLX5VF_QUERY_CLEANUP );
11491164 if (ret )
11501165 return ERR_PTR (ret );
1151- buf = mlx5vf_get_data_buffer (migf , size , DMA_FROM_DEVICE );
1166+ buf = mlx5vf_get_data_buffer (migf ,
1167+ DIV_ROUND_UP (size , PAGE_SIZE ), DMA_FROM_DEVICE );
11521168 if (IS_ERR (buf ))
11531169 return ERR_CAST (buf );
11541170 /* pre_copy cleanup */
0 commit comments