Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp208889rwe; Wed, 31 Aug 2022 01:04:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR7NT2KLugucdcH5DSpVs99b2kky2AUKsLY+PisW1lW6pd8pIUWoafAwKDvLp7eKNtq6GSR3 X-Received: by 2002:aa7:9019:0:b0:535:fb2e:4ae9 with SMTP id m25-20020aa79019000000b00535fb2e4ae9mr24859611pfo.72.1661933048118; Wed, 31 Aug 2022 01:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661933048; cv=none; d=google.com; s=arc-20160816; b=GoxYYhCQ6XALXg5BgKh/fhKlAyzltx1UZ2JtSEpJRUAcKw+HBM6l/JIwG1KOs9Dxuz IGrsrsWcCo2nzURMN89WByc/MZkcaWSrnpE7DyzqYhHeCxL+mLAu4tgWc8sVnUDuoEv3 r1dj6huY3LDCN04c8h+1ErXSpi5o+dLeMN2oRj0h5eXdPohjULUgj94mxykvouaBUqdR fuwgHLEeu2yLHchih/KFRDwyLwLKb3r7DnmhlJUhdzDk4ldq7mVxaGmPnKQ2cPp82W9m 94o37rCzI3/7aULVYiOcJHFKf5iX9e2enmClCNVbf86rEDNRKkEnC0OHiLodKyPT1Bet XVAA== 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=9g5ZzLGAObY1PfD/41fQfLmGLRRfjGOCQGtY1zlIOoM=; b=mkaiq8W9HQZKuHMwhTgdC2u5sEUB/dgVn+VK1BfTEC6uq6csbNOTvmb8ZuUwz8/FI3 25aYTaHuworC2G7pOZ0ftKKN9teIBGfT1/ql/rfcSEbKGe65q/6RgFvHsOPbKc0NOl+k mBzDymuomN4YrhV6j6lLUV1nZE+TdKddf4q5r060vwO/hkV+OBGHdba01T9w/E5nFX35 u7fuaVGm9snJF5zfqVMCEN3hIDFXLfCOrLy7teuL7tjsklG9B8RC5n4ct9HBhW/doAqI ISHnOAYBc41xMOAjFFdRWlRgW3oinNqi8M8G6cKNgif1fRWF8l0Np02Ul+Oinpjb4bY+ uCOA== 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 w190-20020a6382c7000000b0042b77aa55fdsi3927291pgd.464.2022.08.31.01.03.57; Wed, 31 Aug 2022 01:04:08 -0700 (PDT) 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 S229847AbiHaHgJ convert rfc822-to-8bit (ORCPT + 99 others); Wed, 31 Aug 2022 03:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbiHaHgH (ORCPT ); Wed, 31 Aug 2022 03:36:07 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFFC5A98C8; Wed, 31 Aug 2022 00:36:05 -0700 (PDT) Received: from fraeml707-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MHbYs4Xj8z688fw; Wed, 31 Aug 2022 15:35:29 +0800 (CST) Received: from lhrpeml500002.china.huawei.com (7.191.160.78) by fraeml707-chm.china.huawei.com (10.206.15.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 31 Aug 2022 09:36:03 +0200 Received: from lhrpeml500005.china.huawei.com (7.191.163.240) by lhrpeml500002.china.huawei.com (7.191.160.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 31 Aug 2022 08:36:02 +0100 Received: from lhrpeml500005.china.huawei.com ([7.191.163.240]) by lhrpeml500005.china.huawei.com ([7.191.163.240]) with mapi id 15.01.2375.024; Wed, 31 Aug 2022 08:36:02 +0100 From: Shameerali Kolothum Thodi To: Kevin Tian , Zhenyu Wang , Zhi Wang , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Eric Farman , Matthew Rosato , Halil Pasic , Vineeth Vijayan , "Peter Oberparleiter" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Tony Krowiak , Jason Herne , Harald Freudenberger , Diana Craciun , "Alex Williamson" , Cornelia Huck , liulongfang , Jason Gunthorpe , "Yishai Hadas" , Eric Auger , "Kirti Wankhede" , Leon Romanovsky , Abhishek Sahu , "intel-gvt-dev@lists.freedesktop.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "linux-s390@vger.kernel.org" , "kvm@vger.kernel.org" CC: Yi Liu Subject: RE: [PATCH 04/15] vfio/hisi_acc: Use the new device life cycle helpers Thread-Topic: [PATCH 04/15] vfio/hisi_acc: Use the new device life cycle helpers Thread-Index: AQHYufp2da3qAvP1z0GEpuKhp3q5ba3Io6tw Date: Wed, 31 Aug 2022 07:36:02 +0000 Message-ID: References: <20220827171037.30297-1-kevin.tian@intel.com> <20220827171037.30297-5-kevin.tian@intel.com> In-Reply-To: <20220827171037.30297-5-kevin.tian@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.195.245.177] 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_H2,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: Kevin Tian [mailto:kevin.tian@intel.com] > Sent: 27 August 2022 18:10 > To: Zhenyu Wang ; Zhi Wang > ; Jani Nikula ; Joonas > Lahtinen ; Rodrigo Vivi > ; Tvrtko Ursulin ; > David Airlie ; Daniel Vetter ; Eric Farman > ; Matthew Rosato ; > Halil Pasic ; Vineeth Vijayan > ; Peter Oberparleiter ; > Heiko Carstens ; Vasily Gorbik ; > Alexander Gordeev ; Christian Borntraeger > ; Sven Schnelle ; Tony > Krowiak ; Jason Herne ; > Harald Freudenberger ; Diana Craciun > ; Alex Williamson > ; Cornelia Huck ; > liulongfang ; Shameerali Kolothum Thodi > ; Jason Gunthorpe > ; Yishai Hadas ; Kevin Tian > ; Eric Auger ; Kirti > Wankhede ; Leon Romanovsky ; > Abhishek Sahu ; intel-gvt-dev@lists.freedesktop.org; > intel-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org; > linux-kernel@vger.kernel.org; linux-s390@vger.kernel.org; > kvm@vger.kernel.org > Cc: Yi Liu > Subject: [PATCH 04/15] vfio/hisi_acc: Use the new device life cycle helpers > > From: Yi Liu > > Tidy up @probe so all migration specific initialization logic is moved > to migration specific @init callback. > > Remove vfio_pci_core_{un}init_device() given no user now. This looks fine to me and the probe() is indeed much cleaner now. Reviewed-by: Shameer Kolothum Thanks, Shameer > Signed-off-by: Yi Liu > Signed-off-by: Kevin Tian > --- > .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 80 +++++++++---------- > drivers/vfio/pci/vfio_pci_core.c | 30 ------- > include/linux/vfio_pci_core.h | 4 - > 3 files changed, 37 insertions(+), 77 deletions(-) > > diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c > b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c > index ea762e28c1cc..f06f9a799128 100644 > --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c > +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c > @@ -1213,8 +1213,28 @@ static const struct vfio_migration_ops > hisi_acc_vfio_pci_migrn_state_ops = { > .migration_get_state = hisi_acc_vfio_pci_get_device_state, > }; > > +int hisi_acc_vfio_pci_migrn_init_dev(struct vfio_device *core_vdev) > +{ > + struct hisi_acc_vf_core_device *hisi_acc_vdev = > container_of(core_vdev, > + struct hisi_acc_vf_core_device, core_device.vdev); > + struct pci_dev *pdev = to_pci_dev(core_vdev->dev); > + struct hisi_qm *pf_qm = hisi_acc_get_pf_qm(pdev); > + > + hisi_acc_vdev->vf_id = pci_iov_vf_id(pdev) + 1; > + hisi_acc_vdev->pf_qm = pf_qm; > + hisi_acc_vdev->vf_dev = pdev; > + mutex_init(&hisi_acc_vdev->state_mutex); > + > + core_vdev->migration_flags = VFIO_MIGRATION_STOP_COPY; > + core_vdev->mig_ops = &hisi_acc_vfio_pci_migrn_state_ops; > + > + return vfio_pci_core_init_dev(core_vdev); > +} > + > static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = { > .name = "hisi-acc-vfio-pci-migration", > + .init = hisi_acc_vfio_pci_migrn_init_dev, > + .release = vfio_pci_core_release_dev, > .open_device = hisi_acc_vfio_pci_open_device, > .close_device = hisi_acc_vfio_pci_close_device, > .ioctl = hisi_acc_vfio_pci_ioctl, > @@ -1228,6 +1248,8 @@ static const struct vfio_device_ops > hisi_acc_vfio_pci_migrn_ops = { > > static const struct vfio_device_ops hisi_acc_vfio_pci_ops = { > .name = "hisi-acc-vfio-pci", > + .init = vfio_pci_core_init_dev, > + .release = vfio_pci_core_release_dev, > .open_device = hisi_acc_vfio_pci_open_device, > .close_device = vfio_pci_core_close_device, > .ioctl = vfio_pci_core_ioctl, > @@ -1239,63 +1261,36 @@ static const struct vfio_device_ops > hisi_acc_vfio_pci_ops = { > .match = vfio_pci_core_match, > }; > > -static int > -hisi_acc_vfio_pci_migrn_init(struct hisi_acc_vf_core_device *hisi_acc_vdev, > - struct pci_dev *pdev, struct hisi_qm *pf_qm) > -{ > - int vf_id; > - > - vf_id = pci_iov_vf_id(pdev); > - if (vf_id < 0) > - return vf_id; > - > - hisi_acc_vdev->vf_id = vf_id + 1; > - hisi_acc_vdev->core_device.vdev.migration_flags = > - VFIO_MIGRATION_STOP_COPY; > - hisi_acc_vdev->pf_qm = pf_qm; > - hisi_acc_vdev->vf_dev = pdev; > - mutex_init(&hisi_acc_vdev->state_mutex); > - > - return 0; > -} > - > static int hisi_acc_vfio_pci_probe(struct pci_dev *pdev, const struct > pci_device_id *id) > { > struct hisi_acc_vf_core_device *hisi_acc_vdev; > + const struct vfio_device_ops *ops = &hisi_acc_vfio_pci_ops; > struct hisi_qm *pf_qm; > + int vf_id; > int ret; > > - hisi_acc_vdev = kzalloc(sizeof(*hisi_acc_vdev), GFP_KERNEL); > - if (!hisi_acc_vdev) > - return -ENOMEM; > - > pf_qm = hisi_acc_get_pf_qm(pdev); > if (pf_qm && pf_qm->ver >= QM_HW_V3) { > - ret = hisi_acc_vfio_pci_migrn_init(hisi_acc_vdev, pdev, pf_qm); > - if (!ret) { > - vfio_pci_core_init_device(&hisi_acc_vdev->core_device, pdev, > - &hisi_acc_vfio_pci_migrn_ops); > - hisi_acc_vdev->core_device.vdev.mig_ops = > - &hisi_acc_vfio_pci_migrn_state_ops; > - } else { > + vf_id = pci_iov_vf_id(pdev); > + if (vf_id >= 0) > + ops = &hisi_acc_vfio_pci_migrn_ops; > + else > pci_warn(pdev, "migration support failed, continue with > generic interface\n"); > - vfio_pci_core_init_device(&hisi_acc_vdev->core_device, pdev, > - &hisi_acc_vfio_pci_ops); > - } > - } else { > - vfio_pci_core_init_device(&hisi_acc_vdev->core_device, pdev, > - &hisi_acc_vfio_pci_ops); > } > > + hisi_acc_vdev = vfio_alloc_device(hisi_acc_vf_core_device, > + core_device.vdev, &pdev->dev, ops); > + if (IS_ERR(hisi_acc_vdev)) > + return PTR_ERR(hisi_acc_vdev); > + > dev_set_drvdata(&pdev->dev, &hisi_acc_vdev->core_device); > ret = vfio_pci_core_register_device(&hisi_acc_vdev->core_device); > if (ret) > - goto out_free; > + goto out_put_vdev; > return 0; > > -out_free: > - vfio_pci_core_uninit_device(&hisi_acc_vdev->core_device); > - kfree(hisi_acc_vdev); > +out_put_vdev: > + vfio_put_device(&hisi_acc_vdev->core_device.vdev); > return ret; > } > > @@ -1304,8 +1299,7 @@ static void hisi_acc_vfio_pci_remove(struct > pci_dev *pdev) > struct hisi_acc_vf_core_device *hisi_acc_vdev = > hssi_acc_drvdata(pdev); > > vfio_pci_core_unregister_device(&hisi_acc_vdev->core_device); > - vfio_pci_core_uninit_device(&hisi_acc_vdev->core_device); > - kfree(hisi_acc_vdev); > + vfio_put_device(&hisi_acc_vdev->core_device.vdev); > } > > static const struct pci_device_id hisi_acc_vfio_pci_table[] = { > diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c > index 708b61d1b364..f29d780e327e 100644 > --- a/drivers/vfio/pci/vfio_pci_core.c > +++ b/drivers/vfio/pci/vfio_pci_core.c > @@ -1860,36 +1860,6 @@ void vfio_pci_core_release_dev(struct > vfio_device *core_vdev) > } > EXPORT_SYMBOL_GPL(vfio_pci_core_release_dev); > > -void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev, > - struct pci_dev *pdev, > - const struct vfio_device_ops *vfio_pci_ops) > -{ > - vfio_init_group_dev(&vdev->vdev, &pdev->dev, vfio_pci_ops); > - vdev->pdev = pdev; > - vdev->irq_type = VFIO_PCI_NUM_IRQS; > - mutex_init(&vdev->igate); > - spin_lock_init(&vdev->irqlock); > - mutex_init(&vdev->ioeventfds_lock); > - INIT_LIST_HEAD(&vdev->dummy_resources_list); > - INIT_LIST_HEAD(&vdev->ioeventfds_list); > - mutex_init(&vdev->vma_lock); > - INIT_LIST_HEAD(&vdev->vma_list); > - INIT_LIST_HEAD(&vdev->sriov_pfs_item); > - init_rwsem(&vdev->memory_lock); > -} > -EXPORT_SYMBOL_GPL(vfio_pci_core_init_device); > - > -void vfio_pci_core_uninit_device(struct vfio_pci_core_device *vdev) > -{ > - mutex_destroy(&vdev->igate); > - mutex_destroy(&vdev->ioeventfds_lock); > - mutex_destroy(&vdev->vma_lock); > - vfio_uninit_group_dev(&vdev->vdev); > - kfree(vdev->region); > - kfree(vdev->pm_save); > -} > -EXPORT_SYMBOL_GPL(vfio_pci_core_uninit_device); > - > int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev) > { > struct pci_dev *pdev = vdev->pdev; > diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h > index 98c8c66e2400..9f10ff34b2ba 100644 > --- a/include/linux/vfio_pci_core.h > +++ b/include/linux/vfio_pci_core.h > @@ -230,13 +230,9 @@ static inline void vfio_pci_zdev_close_device(struct > vfio_pci_core_device *vdev) > void vfio_pci_core_set_params(bool nointxmask, bool is_disable_vga, > bool is_disable_idle_d3); > void vfio_pci_core_close_device(struct vfio_device *core_vdev); > -void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev, > - struct pci_dev *pdev, > - const struct vfio_device_ops *vfio_pci_ops); > int vfio_pci_core_init_dev(struct vfio_device *core_vdev); > void vfio_pci_core_release_dev(struct vfio_device *core_vdev); > int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev); > -void vfio_pci_core_uninit_device(struct vfio_pci_core_device *vdev); > void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev); > extern const struct pci_error_handlers vfio_pci_core_err_handlers; > int vfio_pci_core_sriov_configure(struct vfio_pci_core_device *vdev, > -- > 2.21.3