Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp398736rwe; Thu, 1 Sep 2022 01:04:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR42qKsuc+ChkIjhKYeImrT0YNxoEzmG7vcbJaMFx/jwYHoK+5pHU/Z54zaybBzn3SGGr6ez X-Received: by 2002:a17:906:4795:b0:73d:daa0:3cbf with SMTP id cw21-20020a170906479500b0073ddaa03cbfmr20885861ejc.693.1662019468204; Thu, 01 Sep 2022 01:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662019468; cv=none; d=google.com; s=arc-20160816; b=OIMeNYUwJUh83wimwkVtkTWD+Iz4pqOJ+q5WwvTbB93enLFuDrmV5qWG+ZS8Wj425W E8Dg9HZWH6As59erT0T9T7nQ4yttd5geMROY29xHCiuRAu4Q4OKTFLxqkgQCXVtPFVEO +rXriA2I+a72C0LVtbmIJOW0UfYJ1PGrbMhqrvQ2wwE6Z6vsj/DZVd6Zm3NIrhsiGxDP Y6fDQ9M8IEbNFUIQ4bBHG4VA736+B49ABsy8BEvgiOIKe4qYBQ+ytNyvJLDczs4EY/IG xBYTaKAn89g8ScKA6+9KkRoW+4uZxgY1zAVvtWTQFiEMtjpFTZtyGvzNPwF+y7ksGaIb KltA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Sm3uJca5H8Nr4tz7FvAFpgkUoPB3vmP8FGZ1ndyOOhU=; b=fs+2Qae9ur/VThIv8n0Vu8xku+84wzid0jyfMuEb+Edk0J+oVR3tdeEywkbcI2CjaP lqsHDBIOFZw+xnjS90BU7A0HzESmN34IoNVJ7u4moxFEZYkfoNZOWTHPLVJphincyYhk M8xHGh1Z7mUiLRjzIeOoSc7VC2P3cxW9k3kgJfDgzG2ZABW4LEbX+KEkGJwXlSRirGsj e4x4jSvIOG3Yye0sSDrM5o+SDhf8OtUxPBLJ+qe34s4SI1spZhiTjzo2hXi2xIDHh9x3 KBdjn7WEYcFSMQgb/yoibfTWo7aKjN9T5oa7yUFUewbGyi5kveRNooj8WV5MWDgi+9/p oILw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XbVWkwnZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn9-20020a1709070d0900b0073c6f3973bfsi8418069ejc.670.2022.09.01.01.04.01; Thu, 01 Sep 2022 01:04:28 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=XbVWkwnZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233781AbiIAHSZ (ORCPT + 99 others); Thu, 1 Sep 2022 03:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233719AbiIAHSK (ORCPT ); Thu, 1 Sep 2022 03:18:10 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F017125E88; Thu, 1 Sep 2022 00:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662016686; x=1693552686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MsDuuOfl+qc/+Vk8JeCf6fPZpgm3fSx5fNf5Rw0jDMw=; b=XbVWkwnZg8kgfT5qPnTNWyEFFypXqXL3aeRMv5plJtQLyLzq3L+HZyq/ mtDHOWXQRbZnkalktGJXEugSKCKo4rTxAcnD+nAPWGqswi476C68WsQYM v0l68Vxc7tLterY8bNKZdetcPyGlRIOgjaCItBATS6LERifvK/dKXan9F Bx5ayW1AXPlFWJVCW8dwNZAx4n8hdeKaoOyHqHdozbV1bQfyVNk1Gfg00 tqWmTgep996rQxDb/l5Mr5cPi9kD/XxLF/Sp1CjiKSHWS+RlOdku9Nnbq ABKiiSYyFyKcCGcASJRy4TvWWvJaXlyTcqSKPQ7zyXCd5tAx6fF4A79wy Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10456"; a="321782976" X-IronPort-AV: E=Sophos;i="5.93,280,1654585200"; d="scan'208";a="321782976" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 00:18:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,280,1654585200"; d="scan'208";a="673719941" Received: from sqa-gate.sh.intel.com (HELO michael.clx.dev.tsp.org) ([10.239.48.212]) by fmsmga008.fm.intel.com with ESMTP; 01 Sep 2022 00:17:51 -0700 From: Kevin Tian 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 , Longfang Liu , Shameer Kolothum , 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 v2 03/15] vfio/mlx5: Use the new device life cycle helpers Date: Thu, 1 Sep 2022 22:37:35 +0800 Message-Id: <20220901143747.32858-4-kevin.tian@intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20220901143747.32858-1-kevin.tian@intel.com> References: <20220901143747.32858-1-kevin.tian@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,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 From: Yi Liu mlx5 has its own @init/@release for handling migration cap. Signed-off-by: Yi Liu Signed-off-by: Kevin Tian Reviewed-by: Jason Gunthorpe --- drivers/vfio/pci/mlx5/main.c | 49 ++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index a9b63d15c5d3..168c1133e337 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -579,8 +579,35 @@ static const struct vfio_migration_ops mlx5vf_pci_mig_ops = { .migration_get_state = mlx5vf_pci_get_device_state, }; +static int mlx5vf_pci_init_dev(struct vfio_device *core_vdev) +{ + struct mlx5vf_pci_core_device *mvdev = container_of(core_vdev, + struct mlx5vf_pci_core_device, core_device.vdev); + int ret; + + ret = vfio_pci_core_init_dev(core_vdev); + if (ret) + return ret; + + mlx5vf_cmd_set_migratable(mvdev, &mlx5vf_pci_mig_ops); + + return 0; + +} + +static void mlx5vf_pci_release_dev(struct vfio_device *core_vdev) +{ + struct mlx5vf_pci_core_device *mvdev = container_of(core_vdev, + struct mlx5vf_pci_core_device, core_device.vdev); + + mlx5vf_cmd_remove_migratable(mvdev); + vfio_pci_core_release_dev(core_vdev); +} + static const struct vfio_device_ops mlx5vf_pci_ops = { .name = "mlx5-vfio-pci", + .init = mlx5vf_pci_init_dev, + .release = mlx5vf_pci_release_dev, .open_device = mlx5vf_pci_open_device, .close_device = mlx5vf_pci_close_device, .ioctl = vfio_pci_core_ioctl, @@ -598,21 +625,19 @@ static int mlx5vf_pci_probe(struct pci_dev *pdev, struct mlx5vf_pci_core_device *mvdev; int ret; - mvdev = kzalloc(sizeof(*mvdev), GFP_KERNEL); - if (!mvdev) - return -ENOMEM; - vfio_pci_core_init_device(&mvdev->core_device, pdev, &mlx5vf_pci_ops); - mlx5vf_cmd_set_migratable(mvdev, &mlx5vf_pci_mig_ops); + mvdev = vfio_alloc_device(mlx5vf_pci_core_device, core_device.vdev, + &pdev->dev, &mlx5vf_pci_ops); + if (IS_ERR(mvdev)) + return PTR_ERR(mvdev); + dev_set_drvdata(&pdev->dev, &mvdev->core_device); ret = vfio_pci_core_register_device(&mvdev->core_device); if (ret) - goto out_free; + goto out_put_vdev; return 0; -out_free: - mlx5vf_cmd_remove_migratable(mvdev); - vfio_pci_core_uninit_device(&mvdev->core_device); - kfree(mvdev); +out_put_vdev: + vfio_put_device(&mvdev->core_device.vdev); return ret; } @@ -621,9 +646,7 @@ static void mlx5vf_pci_remove(struct pci_dev *pdev) struct mlx5vf_pci_core_device *mvdev = mlx5vf_drvdata(pdev); vfio_pci_core_unregister_device(&mvdev->core_device); - mlx5vf_cmd_remove_migratable(mvdev); - vfio_pci_core_uninit_device(&mvdev->core_device); - kfree(mvdev); + vfio_put_device(&mvdev->core_device.vdev); } static const struct pci_device_id mlx5vf_pci_table[] = { -- 2.21.3