Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp850347pxm; Thu, 3 Mar 2022 05:52:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOnjHXDX3kN1T3zH2xZtqqLDXpzvTu0a1CqY+cLvVtuhesRv7DaEwzUcuIieN3IRkQeMB0 X-Received: by 2002:a17:90b:19c7:b0:1bc:6002:7c5a with SMTP id nm7-20020a17090b19c700b001bc60027c5amr5482873pjb.179.1646315578421; Thu, 03 Mar 2022 05:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646315578; cv=none; d=google.com; s=arc-20160816; b=NwtQMUto/fRs1pT7kFxazzz4KoMzA0Pwqjs/YzdKOhwu8wJNmTyO/Bc3S6eMguy7hP j2GUm7kkNTnyLE12plRkz+ehVu/p3bATvxmlrfHBgaUheV9UKvXoeCAdcTbokbAPcr7P inL17iLznPtYXwrawk3y8urj6sBV32ZCSosBAd301T0sX+VmP5f9AdhiigpxhWOCo5Aw gI9vwYEx8yiw+yU7LMEjPtTtgl5Ml4a8w2QHozqkLze2iLiNYZzOVOjYPe5nXoqi5d8R z1RQy9PDn9TW/TnJaZiLQiKDDwh7bmuA0DVpvNcM+b8lsGI25NPA9b2UsbTuu849IidH qDpg== 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=6p/sx9phlNKbsCGvnTzMF9b3ZdLBKtrD84d9GDGmLnw=; b=AA2f3WyNcbXs8y5OZBNCi1NOYmsx6O8ugvXqn6LA24w8YXt08N43D9EiX6Z2wNc8uf Ncn7SKMt9Wt18wiKbnLip/BSJBwm7kq4GFppQWkAb2GNre712HGNpWVFYFZ/6Ky/9gnE gtjE2QUXKyteLHM7TBQAH36kZzSY4C7DzS2s/pf7XjaMN2d29YaJooZZ2VOPL0+o6dR6 +UcAeX5yZebAU6Zuc+btzTjhF5gSc0FEGRHHFMf7Az3mnOj4dzDn4zYvAKGh/mm+6i4b i9VdoE/gVOLuwUMVSPS8VYyhzuO1E8a+POQ6zfyizISN7kMgLQLhQEChvsBpa9KIcksH 75NA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 62-20020a630341000000b003655f0c14c6si2165732pgd.557.2022.03.03.05.52.34; Thu, 03 Mar 2022 05:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S230193AbiCCNR4 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 3 Mar 2022 08:17:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbiCCNRz (ORCPT ); Thu, 3 Mar 2022 08:17:55 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3D521704CD; Thu, 3 Mar 2022 05:17:08 -0800 (PST) Received: from fraeml701-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4K8Wh76J62z67r9d; Thu, 3 Mar 2022 21:15:51 +0800 (CST) Received: from lhreml714-chm.china.huawei.com (10.201.108.65) by fraeml701-chm.china.huawei.com (10.206.15.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.21; Thu, 3 Mar 2022 14:17:05 +0100 Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml714-chm.china.huawei.com (10.201.108.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 3 Mar 2022 13:17:05 +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; Thu, 3 Mar 2022 13:17:05 +0000 From: Shameerali Kolothum Thodi To: Jason Gunthorpe CC: "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-pci@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 v7 09/10] hisi_acc_vfio_pci: Add support for VFIO live migration Thread-Topic: [PATCH v7 09/10] hisi_acc_vfio_pci: Add support for VFIO live migration Thread-Index: AQHYLltL2nbHr5hFZkexUhHVpQU6TqyszJkAgADNzBCAAAc9gIAAApOw Date: Thu, 3 Mar 2022 13:17:05 +0000 Message-ID: References: <20220302172903.1995-1-shameerali.kolothum.thodi@huawei.com> <20220302172903.1995-10-shameerali.kolothum.thodi@huawei.com> <20220303002142.GE1026713@nvidia.com> <19e294814f284755b207be3ba7054ec2@huawei.com> <20220303130411.GY219866@nvidia.com> In-Reply-To: <20220303130411.GY219866@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.82.4] 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-crypto@vger.kernel.org > -----Original Message----- > From: Jason Gunthorpe [mailto:jgg@nvidia.com] > Sent: 03 March 2022 13:04 > To: Shameerali Kolothum Thodi > Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org; > linux-crypto@vger.kernel.org; linux-pci@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 v7 09/10] hisi_acc_vfio_pci: Add support for VFIO live > migration > > On Thu, Mar 03, 2022 at 12:57:29PM +0000, Shameerali Kolothum Thodi > wrote: > > > > > > > From: Jason Gunthorpe [mailto:jgg@nvidia.com] > > > Sent: 03 March 2022 00:22 > > > To: Shameerali Kolothum Thodi > > > > Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org; > > > linux-crypto@vger.kernel.org; linux-pci@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 v7 09/10] hisi_acc_vfio_pci: Add support for VFIO live > > > migration > > > > > > On Wed, Mar 02, 2022 at 05:29:02PM +0000, Shameer Kolothum wrote: > > > > +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; > > > > + struct hisi_acc_vf_core_device *hisi_acc_vdev = container_of(migf, > > > > + struct hisi_acc_vf_core_device, saving_migf); > > > > + loff_t *pos = &filp->f_pos; > > > > + struct vfio_precopy_info info; > > > > + unsigned long minsz; > > > > + int ret; > > > > + > > > > + if (cmd != VFIO_MIG_GET_PRECOPY_INFO) > > > > + return -ENOTTY; > > > > + > > > > + minsz = offsetofend(struct vfio_precopy_info, dirty_bytes); > > > > + > > > > + if (copy_from_user(&info, (void __user *)arg, minsz)) > > > > + return -EFAULT; > > > > + if (info.argsz < minsz) > > > > + return -EINVAL; > > > > + > > > > + mutex_lock(&hisi_acc_vdev->state_mutex); > > > > + if (hisi_acc_vdev->mig_state != VFIO_DEVICE_STATE_PRE_COPY) { > > > > + mutex_unlock(&hisi_acc_vdev->state_mutex); > > > > + return -EINVAL; > > > > + } > > > > > > IMHO it is easier just to check the total_length and not grab this > > > other lock > > > > The problem with checking the total_length here is that it is possible that > > in STOP_COPY the dev is not ready and there are no more data to be > transferred > > and the total_length remains at QM_MATCH_SIZE. > > Tthere is a scenario that transfers only QM_MATCH_SIZE in stop_copy? > This doesn't seem like a good idea, I think you should transfer a > positive indication 'this device is not ready' instead of truncating > the stream. A truncated stream should not be a valid stream. > > ie always transfer the whole struct. We could add a 'qm_state' and return the whole struct. But the rest of the struct is basically invalid if qm_state = QM_NOT_REDAY. > > > Looks like setting the total_length = 0 in STOP_COPY is a better > > solution(If there are no other issues with that) as it will avoid > > grabbing the state_mutex as you mentioned above. > > That seems really weird, I wouldn't recommend doing that.. Does that mean we don't support a zero data transfer in STOP_COPY? The concern is if we always transfer the whole struct, we end up reading and writing the whole thing even if most of the data is invalid. Thanks, Shameer