From: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"cohuck@redhat.com" <cohuck@redhat.com>,
"mgurtovoy@nvidia.com" <mgurtovoy@nvidia.com>,
"yishaih@nvidia.com" <yishaih@nvidia.com>,
Linuxarm <linuxarm@huawei.com>,
liulongfang <liulongfang@huawei.com>,
"Zengtao (B)" <prime.zeng@hisilicon.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
"Wangzhou (B)" <wangzhou1@hisilicon.com>
Subject: RE: [PATCH v6 09/10] hisi_acc_vfio_pci: Add support for VFIO live migration
Date: Mon, 28 Feb 2022 18:01:44 +0000 [thread overview]
Message-ID: <58fa5572e8e44c91a77bd293b2ec6e33@huawei.com> (raw)
In-Reply-To: <20220228145731.GH219866@nvidia.com>
> -----Original Message-----
> From: Jason Gunthorpe [mailto:jgg@nvidia.com]
> Sent: 28 February 2022 14:58
> To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
> Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org;
> linux-crypto@vger.kernel.org; alex.williamson@redhat.com;
> cohuck@redhat.com; mgurtovoy@nvidia.com; yishaih@nvidia.com; Linuxarm
> <linuxarm@huawei.com>; liulongfang <liulongfang@huawei.com>; Zengtao (B)
> <prime.zeng@hisilicon.com>; Jonathan Cameron
> <jonathan.cameron@huawei.com>; Wangzhou (B) <wangzhou1@hisilicon.com>
> Subject: Re: [PATCH v6 09/10] hisi_acc_vfio_pci: Add support for VFIO live
> migration
>
> On Mon, Feb 28, 2022 at 09:01:20AM +0000, Shameer Kolothum wrote:
>
> > +static int hisi_acc_vf_stop_copy(struct hisi_acc_vf_core_device
> *hisi_acc_vdev,
> > + struct hisi_acc_vf_migration_file *migf)
> > +{
> > + struct acc_vf_data *vf_data = &migf->vf_data;
>
> This now needs to hold the migf->lock
>
> > +
> > + if ((cur == VFIO_DEVICE_STATE_STOP || cur ==
> VFIO_DEVICE_STATE_PRE_COPY) &&
> > + new == VFIO_DEVICE_STATE_RUNNING) {
> > + hisi_acc_vf_start_device(hisi_acc_vdev);
>
> This should be two stanzas STOP->RUNNING should do start_device
>
> And PRE_COPY->RUNNING should do disable_fds, and presumably nothing
> else - the device was never stopped.
>
Ok. I will take care of all the above.
> > + } else if (cmd == VFIO_DEVICE_MIG_PRECOPY) {
> > + struct vfio_device_mig_precopy precopy;
> > + enum vfio_device_mig_state curr_state;
> > + unsigned long minsz;
> > + int ret;
> > +
> > + minsz = offsetofend(struct vfio_device_mig_precopy, dirty_bytes);
> > +
> > + if (copy_from_user(&precopy, (void __user *)arg, minsz))
> > + return -EFAULT;
> > + if (precopy.argsz < minsz)
> > + return -EINVAL;
> > +
> > + ret = hisi_acc_vfio_pci_get_device_state(core_vdev, &curr_state);
> > + if (!ret && curr_state == VFIO_DEVICE_STATE_PRE_COPY) {
> > + precopy.initial_bytes = QM_MATCH_SIZE;
> > + precopy.dirty_bytes = QM_MATCH_SIZE;
>
> dirty_bytes should be 0
>
> initial_bytes should be calculated based on the current file
> descriptor offset.
>
> The use of curr_state should be eliminated
>
> This ioctl should be on the saving file_operations, not here
>
> + * This ioctl is used on the migration data FD in the precopy phase of the
> + * migration data transfer. It returns an estimate of the current data sizes
>
> I see there is a bug in the qemu version:
>
> @@ -215,12 +218,13 @@ static void vfio_save_precopy_pending(QEMUFile
> *f, void *>
> uint64_t *res_postcopy_only)
> {
> VFIODevice *vbasedev = opaque;
> + VFIOMigration *migration = vbasedev->migration;
> struct vfio_device_mig_precopy precopy = {
> .argsz = sizeof(precopy),
> };
> int ret;
>
> - ret = ioctl(vbasedev->fd, VFIO_DEVICE_MIG_PRECOPY, &precopy);
> + ret = ioctl(migration->data_fd, VFIO_DEVICE_MIG_PRECOPY, &precopy);
> if (ret) {
> return;
> }
>
> I'll update my github.
Ok. Thanks for that.
And for the VFIO_DEVICE_MIG_PRECOPY ioctl, this is what I have now,
+static long hisi_acc_vf_save_unl_ioctl(struct file *filp,
+ unsigned int cmd, unsigned long arg)
+{
+ struct hisi_acc_vf_migration_file *migf = filp->private_data;
+ loff_t *pos = &filp->f_pos;
+ struct vfio_device_mig_precopy precopy;
+ unsigned long minsz;
+
+ if (cmd != VFIO_DEVICE_MIG_PRECOPY)
+ return -EINVAL;
+
+ minsz = offsetofend(struct vfio_device_mig_precopy, dirty_bytes);
+
+ if (copy_from_user(&precopy, (void __user *)arg, minsz))
+ return -EFAULT;
+ if (precopy.argsz < minsz)
+ return -EINVAL;
+
+ mutex_lock(&migf->lock);
+ if (*pos > migf->total_length) {
+ mutex_unlock(&migf->lock);
+ return -EINVAL;
+ }
+
+ precopy.dirty_bytes = 0;
+ precopy.initial_bytes = migf->total_length - *pos;
+ mutex_unlock(&migf->lock);
+ return copy_to_user((void __user *)arg, &precopy, minsz) ? -EFAULT : 0;
+}
+
I had a quick run with the above Qemu changes, and looks ok. Please let me know.
Thanks,
Shameer
next prev parent reply other threads:[~2022-02-28 18:23 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-28 9:01 [PATCH v6 00/10] vfio/hisilicon: add ACC live migration driver Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 01/10] crypto: hisilicon/qm: Move the QM header to include/linux Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 02/10] crypto: hisilicon/qm: Move few definitions to common header Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 03/10] hisi_acc_qm: Move PCI device IDs " Shameer Kolothum
2022-02-28 17:33 ` Alex Williamson
2022-02-28 20:12 ` Bjorn Helgaas
2022-02-28 20:23 ` Alex Williamson
2022-02-28 20:55 ` Bjorn Helgaas
2022-02-28 9:01 ` [PATCH v6 04/10] hisi_acc_vfio_pci: add new vfio_pci driver for HiSilicon ACC devices Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 05/10] hisi_acc_vfio_pci: Restrict access to VF dev BAR2 migration region Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 06/10] hisi_acc_vfio_pci: Add helper to retrieve the struct pci_driver Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 07/10] vfio: Extend the device migration protocol with PRE_COPY Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 08/10] crypto: hisilicon/qm: Set the VF QM state register Shameer Kolothum
2022-02-28 9:01 ` [PATCH v6 09/10] hisi_acc_vfio_pci: Add support for VFIO live migration Shameer Kolothum
2022-02-28 14:57 ` Jason Gunthorpe
2022-02-28 18:01 ` Shameerali Kolothum Thodi [this message]
2022-02-28 18:05 ` Jason Gunthorpe
2022-02-28 20:16 ` Alex Williamson
2022-02-28 20:29 ` Jason Gunthorpe
2022-02-28 21:20 ` Alex Williamson
2022-02-28 23:47 ` Jason Gunthorpe
2022-03-01 4:41 ` Alex Williamson
2022-03-01 13:15 ` Jason Gunthorpe
2022-03-01 19:30 ` Alex Williamson
2022-03-01 20:39 ` Jason Gunthorpe
2022-03-01 22:44 ` Alex Williamson
2022-03-02 0:03 ` Jason Gunthorpe
2022-03-02 9:07 ` Shameerali Kolothum Thodi
2022-02-28 9:01 ` [PATCH v6 10/10] hisi_acc_vfio_pci: Use its own PCI reset_done error handler Shameer Kolothum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=58fa5572e8e44c91a77bd293b2ec6e33@huawei.com \
--to=shameerali.kolothum.thodi@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=jgg@nvidia.com \
--cc=jonathan.cameron@huawei.com \
--cc=kvm@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=liulongfang@huawei.com \
--cc=mgurtovoy@nvidia.com \
--cc=prime.zeng@hisilicon.com \
--cc=wangzhou1@hisilicon.com \
--cc=yishaih@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).