Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1443319rwn; Thu, 8 Sep 2022 20:49:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR5emoh6nTX80SbjGEbPsmRgXnpz9qHPEBLAAjmb5JM173bAD2bN8TOvrT/rSXysO5TRb9+B X-Received: by 2002:a19:f246:0:b0:493:50d:6bb with SMTP id d6-20020a19f246000000b00493050d06bbmr3501079lfk.461.1662695367478; Thu, 08 Sep 2022 20:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662695367; cv=none; d=google.com; s=arc-20160816; b=FZql0n33uG6AJ5SCU8Ms3sUKKNWNSmRv0JUi/vckNHcHkjxfmiajrN0hbq6URueN4v TbS5urEbA+a9fDYKE7Mz32Un8lDkGoxTxifA14/KtWZp2Zh/MkPm4cOx47VVfWpyl3rj z6t6pZnEKsYQXAW/Gr/3Ct/0kyianiEhXc1S6dqbFxWb623gK2q8UtmoKLZrXv9yUhH5 YXNaxdnM/+oK5iQLOUZfCI9Fg3JV16ETR5WNVggLgAvl9zPM8MkYYIk991Hh+qNX02mA rXHUpBaYVeM/rTUPRdDDPoiKwPnJ8fmN0Gly8ij+BG18UuoWPpg4q/BxZ8QKE0ppR8QV Ev8w== 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=1UnTPEfC056froLRzsoNQVQX1yQ7M9/8CMRF5xxkfQw=; b=GJBqPK+ork3LQmpcY33NLNtOQBjy8RKwOEaceKCHhOUlwXWYitQbxnp0U6L4rlIhX+ 3E5+DP0LgeLCzK+ToU1obKIM4ov7bk9RvZCPol+jP8xxS4dY+KXNEcFgtON+R7gqDyZ7 dNX11KL4HhF978x8cg/bYVM5QbTD/TFd1FOapEG0qHMy/RiFiUD5LpTwcB1Q4G7blm2j muXgqVBXinMwGb+KNuetQ/4BL63udThjOFSXxlXFHRg4WhBRd4aSYJAB5lkP7AWn75v6 usEfuSxb5I0rxd/wMfaXAKFYvTJ7Pgt3jm/e2uX8ElIz1Ty8xAt83dfBJiXplMixuxyy T7wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Y53TV8YH; 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 r8-20020ac25f88000000b004947c4c8fc7si298997lfe.80.2022.09.08.20.48.38; Thu, 08 Sep 2022 20:49:27 -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=Y53TV8YH; 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 S230025AbiIIDEX (ORCPT + 99 others); Thu, 8 Sep 2022 23:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229908AbiIIDEU (ORCPT ); Thu, 8 Sep 2022 23:04:20 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7781011EA45; Thu, 8 Sep 2022 20:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662692659; x=1694228659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+yssjGnk2Zp3MQF/9zrQ2m7m/7YA8Wye4MlvVDEJ0Mk=; b=Y53TV8YHV/0BH9NDcxLQKO3GsDcj9JzTRPfm+QFYmWfBSqUaUs+a7dlq FMJEQakljcXOfdHV4DTvsQmWTOxphMyW1MjlDLo0PVrtHAUCkzBLKSljL ybvTW26UG/r8/4PO454Uk3AcjRq7T5AVXlnwnJXTRx70H8cR8iIeZPXy7 h9Bh7Hb+qpg/rZcjDCHtu/wkAzi9edxpkO/xXPhhLitK/K0MXsv9yvC1U 87TerDDOsoEPF1dpXzsAb0sagsLsWRTcPWgHNeTGZEDsrwIaJVgQAUKs2 HI3swNhiTdyxH4GXC2ymGUuekjRfd+Ag1NhhqkiA9IzD88EnpQSFuRBjn g==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="296118436" X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="296118436" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2022 20:04:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="740908636" Received: from sqa-gate.sh.intel.com (HELO michael.clx.dev.tsp.org) ([10.239.48.212]) by orsmga004.jf.intel.com with ESMTP; 08 Sep 2022 20:03:54 -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 , Christoph Hellwig , 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 v3 03/15] vfio/mlx5: Use the new device life cycle helpers Date: Fri, 9 Sep 2022 18:22:35 +0800 Message-Id: <20220909102247.67324-4-kevin.tian@intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20220909102247.67324-1-kevin.tian@intel.com> References: <20220909102247.67324-1-kevin.tian@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 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_MED,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 | 50 ++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c index 759a5f5f7b3f..fd6ccb8454a2 100644 --- a/drivers/vfio/pci/mlx5/main.c +++ b/drivers/vfio/pci/mlx5/main.c @@ -585,8 +585,35 @@ static const struct vfio_log_ops mlx5vf_pci_log_ops = { .log_read_and_clear = mlx5vf_tracker_read_and_clear, }; +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, + &mlx5vf_pci_log_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, @@ -604,22 +631,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, - &mlx5vf_pci_log_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; } @@ -628,9 +652,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