@@ -764,9 +764,58 @@ hisi_acc_vf_pci_resume(struct hisi_acc_vf_core_device *hisi_acc_vdev)
764
764
765
765
stream_open (migf -> filp -> f_inode , migf -> filp );
766
766
mutex_init (& migf -> lock );
767
+ migf -> hisi_acc_vdev = hisi_acc_vdev ;
767
768
return migf ;
768
769
}
769
770
771
+ static long hisi_acc_vf_precopy_ioctl (struct file * filp ,
772
+ unsigned int cmd , unsigned long arg )
773
+ {
774
+ struct hisi_acc_vf_migration_file * migf = filp -> private_data ;
775
+ struct hisi_acc_vf_core_device * hisi_acc_vdev = migf -> hisi_acc_vdev ;
776
+ loff_t * pos = & filp -> f_pos ;
777
+ struct vfio_precopy_info info ;
778
+ unsigned long minsz ;
779
+ int ret ;
780
+
781
+ if (cmd != VFIO_MIG_GET_PRECOPY_INFO )
782
+ return - ENOTTY ;
783
+
784
+ minsz = offsetofend (struct vfio_precopy_info , dirty_bytes );
785
+
786
+ if (copy_from_user (& info , (void __user * )arg , minsz ))
787
+ return - EFAULT ;
788
+ if (info .argsz < minsz )
789
+ return - EINVAL ;
790
+
791
+ mutex_lock (& hisi_acc_vdev -> state_mutex );
792
+ if (hisi_acc_vdev -> mig_state != VFIO_DEVICE_STATE_PRE_COPY ) {
793
+ mutex_unlock (& hisi_acc_vdev -> state_mutex );
794
+ return - EINVAL ;
795
+ }
796
+
797
+ mutex_lock (& migf -> lock );
798
+
799
+ if (migf -> disabled ) {
800
+ ret = - ENODEV ;
801
+ goto out ;
802
+ }
803
+
804
+ if (* pos > migf -> total_length ) {
805
+ ret = - EINVAL ;
806
+ goto out ;
807
+ }
808
+
809
+ info .dirty_bytes = 0 ;
810
+ info .initial_bytes = migf -> total_length - * pos ;
811
+
812
+ ret = copy_to_user ((void __user * )arg , & info , minsz ) ? - EFAULT : 0 ;
813
+ out :
814
+ mutex_unlock (& migf -> lock );
815
+ mutex_unlock (& hisi_acc_vdev -> state_mutex );
816
+ return ret ;
817
+ }
818
+
770
819
static ssize_t hisi_acc_vf_save_read (struct file * filp , char __user * buf , size_t len ,
771
820
loff_t * pos )
772
821
{
@@ -807,6 +856,8 @@ static ssize_t hisi_acc_vf_save_read(struct file *filp, char __user *buf, size_t
807
856
static const struct file_operations hisi_acc_vf_save_fops = {
808
857
.owner = THIS_MODULE ,
809
858
.read = hisi_acc_vf_save_read ,
859
+ .unlocked_ioctl = hisi_acc_vf_precopy_ioctl ,
860
+ .compat_ioctl = compat_ptr_ioctl ,
810
861
.release = hisi_acc_vf_release_file ,
811
862
.llseek = no_llseek ,
812
863
};
@@ -832,6 +883,7 @@ hisi_acc_vf_stop_copy(struct hisi_acc_vf_core_device *hisi_acc_vdev)
832
883
833
884
stream_open (migf -> filp -> f_inode , migf -> filp );
834
885
mutex_init (& migf -> lock );
886
+ migf -> hisi_acc_vdev = hisi_acc_vdev ;
835
887
836
888
ret = vf_qm_state_save (hisi_acc_vdev , migf );
837
889
if (ret ) {
0 commit comments