hisi_acc_vfio_pci: Move the dev compatibility tests for early check
authorShameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Wed, 23 Nov 2022 11:32:35 +0000 (11:32 +0000)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 6 Dec 2022 19:37:11 +0000 (12:37 -0700)
Instead of waiting till data transfer is complete to perform dev
compatibility, do it as soon as we have enough data to perform the
check. This will be useful when we enable the support for PRE_COPY.

Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Link: https://lore.kernel.org/r/20221123113236.896-4-shameerali.kolothum.thodi@huawei.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.h

index c8658636a84c03b84ea56bacb2adf314fc09876c..9a51f41e1d2aa361400281dc4fbba4afd7183d00 100644 (file)
@@ -360,8 +360,8 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev,
        u32 que_iso_state;
        int ret;
 
-       if (migf->total_length < QM_MATCH_SIZE)
-               return -EINVAL;
+       if (migf->total_length < QM_MATCH_SIZE || hisi_acc_vdev->match_done)
+               return 0;
 
        if (vf_data->acc_magic != ACC_DEV_MAGIC) {
                dev_err(dev, "failed to match ACC_DEV_MAGIC\n");
@@ -406,6 +406,7 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_device *hisi_acc_vdev,
        }
 
        hisi_acc_vdev->vf_qm_state = vf_data->vf_qm_state;
+       hisi_acc_vdev->match_done = true;
        return 0;
 }
 
@@ -493,10 +494,6 @@ static int vf_qm_state_save(struct hisi_acc_vf_core_device *hisi_acc_vdev,
        struct device *dev = &vf_qm->pdev->dev;
        int ret;
 
-       ret = vf_qm_get_match_data(hisi_acc_vdev, vf_data);
-       if (ret)
-               return ret;
-
        if (unlikely(qm_wait_dev_not_ready(vf_qm))) {
                /* Update state and return with match data */
                vf_data->vf_qm_state = QM_NOT_READY;
@@ -673,12 +670,6 @@ static int hisi_acc_vf_load_state(struct hisi_acc_vf_core_device *hisi_acc_vdev)
        struct hisi_acc_vf_migration_file *migf = hisi_acc_vdev->resuming_migf;
        int ret;
 
-       /* Check dev compatibility */
-       ret = vf_qm_check_match(hisi_acc_vdev, migf);
-       if (ret) {
-               dev_err(dev, "failed to match the VF!\n");
-               return ret;
-       }
        /* Recover data to VF */
        ret = vf_qm_load_data(hisi_acc_vdev, migf);
        if (ret) {
@@ -732,6 +723,10 @@ static ssize_t hisi_acc_vf_resume_write(struct file *filp, const char __user *bu
        *pos += len;
        done = len;
        migf->total_length += len;
+
+       ret = vf_qm_check_match(migf->hisi_acc_vdev, migf);
+       if (ret)
+               done = -EFAULT;
 out_unlock:
        mutex_unlock(&migf->lock);
        return done;
index 11d51345f5b511db16397699ba066f886c5191f6..dcabfeec6ca19d4334e746536c5e15a3572972d5 100644 (file)
@@ -98,6 +98,7 @@ struct hisi_acc_vf_migration_file {
 
 struct hisi_acc_vf_core_device {
        struct vfio_pci_core_device core_device;
+       u8 match_done:1;
        u8 deferred_reset:1;
        /* For migration state */
        struct mutex state_mutex;