Skip to content

Commit 64ffbbb

Browse files
shamiali2008awilliam
authored andcommitted
hisi_acc_vfio_pci: Add support for precopy IOCTL
PRECOPY IOCTL in the case of HiSiIicon ACC driver can be used to perform the device compatibility check earlier during migration. Signed-off-by: Shameer Kolothum <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent ccc2a52 commit 64ffbbb

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,58 @@ hisi_acc_vf_pci_resume(struct hisi_acc_vf_core_device *hisi_acc_vdev)
764764

765765
stream_open(migf->filp->f_inode, migf->filp);
766766
mutex_init(&migf->lock);
767+
migf->hisi_acc_vdev = hisi_acc_vdev;
767768
return migf;
768769
}
769770

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+
770819
static ssize_t hisi_acc_vf_save_read(struct file *filp, char __user *buf, size_t len,
771820
loff_t *pos)
772821
{
@@ -807,6 +856,8 @@ static ssize_t hisi_acc_vf_save_read(struct file *filp, char __user *buf, size_t
807856
static const struct file_operations hisi_acc_vf_save_fops = {
808857
.owner = THIS_MODULE,
809858
.read = hisi_acc_vf_save_read,
859+
.unlocked_ioctl = hisi_acc_vf_precopy_ioctl,
860+
.compat_ioctl = compat_ptr_ioctl,
810861
.release = hisi_acc_vf_release_file,
811862
.llseek = no_llseek,
812863
};
@@ -832,6 +883,7 @@ hisi_acc_vf_stop_copy(struct hisi_acc_vf_core_device *hisi_acc_vdev)
832883

833884
stream_open(migf->filp->f_inode, migf->filp);
834885
mutex_init(&migf->lock);
886+
migf->hisi_acc_vdev = hisi_acc_vdev;
835887

836888
ret = vf_qm_state_save(hisi_acc_vdev, migf);
837889
if (ret) {

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct hisi_acc_vf_migration_file {
9191
struct mutex lock;
9292
bool disabled;
9393

94+
struct hisi_acc_vf_core_device *hisi_acc_vdev;
9495
struct acc_vf_data vf_data;
9596
size_t total_length;
9697
};

0 commit comments

Comments
 (0)