Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3035528pxm; Mon, 28 Feb 2022 10:40:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwl+CrkDqXgJGEJ86+DVOBtPG/5m/7KTDgkDzCUdHxxYLzaGnPGXfL4dWaLSyaTYarhqavX X-Received: by 2002:a05:6402:55:b0:413:2822:2928 with SMTP id f21-20020a056402005500b0041328222928mr20843900edu.174.1646073656681; Mon, 28 Feb 2022 10:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646073656; cv=none; d=google.com; s=arc-20160816; b=xRQghh+y3G1hOKpic8JMI/a5y1zT7RaqtArdjwaLEWRFfEE3OWgppS60P5/NDA9OzR ea4kSqjztfC5GWYPyQxfhZYo1hyZFz2sylt34QlgKCLMYVlls4HLpmQwDGOUbgbJtU9E El7KL8J5rMWzsckEPAQ4XdOkV6tOjSsgOkWX6n/ljN5Tw1N7JrpMa+CKUNChedMFBIfO iHlD032Xryb7DexD2XObdbethg3fktAqpF0wqE3F39Q2ATQRGIGi8+t/Ep2rrdGqnpuv m2mXXIhsOjIHCEusz99ouIghu8FblX/mBERTHY4W4SZ19i+0sfiVe5Cmnrrr3fKLPqee bE1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=NLtzjqfk8+TY051ORJSCm841Sd2PKe+LhzlkW09agV8=; b=shVI6aTBfj4eVWqRaOA9Kqc/ZxoIVWYakbr09VsaIc7RCLwfLXiNFU2yRQt8cCu2jJ gjy5lW1gDoj8icOpfzxLGvguygBWdYSEXlROUE95A1a/fTBGC4NXr0Wo5OC3Hy8i/UHP DhEgbqqfBcwJOuxI1FERs8pjdRdmWyoETaB+B3nB/W4r1eSdqPPuachKb1FSzu6jfTyL 4LMOHa6UMBKZunmr6pnZHDoMwO9cDep7o2X/8w3SGkNBsTsCWZ1q/O8HMraBlJ3+zC7a /QTivwx9ShOTZIXjg0tla/hDkiwBBQaAabqYnAzEiayxzuCEFc3QYiJ9ugwdLuzGgNz4 LtqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p2-20020a170906a00200b006a5a719c3c1si6346867ejy.243.2022.02.28.10.40.34; Mon, 28 Feb 2022 10:40:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240608AbiB1SXk convert rfc822-to-8bit (ORCPT + 99 others); Mon, 28 Feb 2022 13:23:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240559AbiB1SX0 (ORCPT ); Mon, 28 Feb 2022 13:23:26 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F1C699EF6; Mon, 28 Feb 2022 10:01:59 -0800 (PST) Received: from fraeml740-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4K6p8314Lpz67yk2; Tue, 1 Mar 2022 02:00:35 +0800 (CST) Received: from lhreml715-chm.china.huawei.com (10.201.108.66) by fraeml740-chm.china.huawei.com (10.206.15.221) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 28 Feb 2022 19:01:45 +0100 Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml715-chm.china.huawei.com (10.201.108.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Mon, 28 Feb 2022 18:01:45 +0000 Received: from lhreml710-chm.china.huawei.com ([169.254.81.184]) by lhreml710-chm.china.huawei.com ([169.254.81.184]) with mapi id 15.01.2308.021; Mon, 28 Feb 2022 18:01:44 +0000 From: Shameerali Kolothum Thodi To: Jason Gunthorpe 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 , liulongfang , "Zengtao (B)" , Jonathan Cameron , "Wangzhou (B)" Subject: RE: [PATCH v6 09/10] hisi_acc_vfio_pci: Add support for VFIO live migration Thread-Topic: [PATCH v6 09/10] hisi_acc_vfio_pci: Add support for VFIO live migration Thread-Index: AQHYLIIBaGfq6jzuvUWvoNXYZoVi1qypDgGAgAAyBYA= Date: Mon, 28 Feb 2022 18:01:44 +0000 Message-ID: <58fa5572e8e44c91a77bd293b2ec6e33@huawei.com> References: <20220228090121.1903-1-shameerali.kolothum.thodi@huawei.com> <20220228090121.1903-10-shameerali.kolothum.thodi@huawei.com> <20220228145731.GH219866@nvidia.com> In-Reply-To: <20220228145731.GH219866@nvidia.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.47.94.1] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Jason Gunthorpe [mailto:jgg@nvidia.com] > Sent: 28 February 2022 14:58 > To: Shameerali Kolothum Thodi > 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 > ; liulongfang ; Zengtao (B) > ; Jonathan Cameron > ; Wangzhou (B) > 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