From patchwork Tue Aug 10 13:37:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 494781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05C17C4320A for ; Tue, 10 Aug 2021 13:38:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE13360F41 for ; Tue, 10 Aug 2021 13:38:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237711AbhHJNia (ORCPT ); Tue, 10 Aug 2021 09:38:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:48724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241610AbhHJNiJ (ORCPT ); Tue, 10 Aug 2021 09:38:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1521360EE9; Tue, 10 Aug 2021 13:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628602667; bh=3F30XzjiCuima9za1pGO/IygpzGxwpDwxQ6IcD1Gfqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d54uKdcqBwcVwNJbDlLrnz2TlsCXGwlG8wR4ZEm2SsHEPFrNjJrAV85HQO1ZXwQL0 OQe1UZ9LMq4XIBhyot87XoiSlofZayKJIBbt2ZczO97lIJiO7/Gp1NGRFO0DfpVMIH QSTt0jQKq0E+HdZAlGIHX6uyv2ebM2G2UJijsgCq77edwgtKEsCs93uin6hna/HSQC gS3c60cHuxKepUazPDccTAtfhFyHhE6RGDzbDq/GZvynZ2irVLJob/QMp6DQej3k7V PlhuWK0P1e5e3tC8PnbaWMK4jeIOak50QhFi405pn5NXy4Kr0EWA3GzNbxZlcAUGnY T1wpFedrQ4eoQ== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Guangbin Huang , Ido Schimmel , Jiri Pirko , linux-kernel@vger.kernel.org, Michael Guralnik , netdev@vger.kernel.org, Saeed Mahameed , Salil Mehta , Tariq Toukan , Yisen Zhuang , Yufeng Mo Subject: [PATCH net-next 2/5] net/mlx4: Move devlink_register to be the last initialization command Date: Tue, 10 Aug 2021 16:37:32 +0300 Message-Id: <9fe3b30cc86f80881e4a1fa161dc58d4a6a2a9f1.1628599239.git.leonro@nvidia.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Leon Romanovsky Refactor the code to make sure that devlink_register() is the last command during initialization stage. Signed-off-by: Leon Romanovsky --- drivers/net/ethernet/mellanox/mlx4/main.c | 38 ++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index 7267c6c6d2e2..7005c32195a3 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -3996,6 +3996,8 @@ static const struct devlink_ops mlx4_devlink_ops = { .reload_up = mlx4_devlink_reload_up, }; +static void _mlx4_remove_one(struct pci_dev *pdev); + static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id) { struct devlink *devlink; @@ -4024,28 +4026,29 @@ static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id) mutex_init(&dev->persist->interface_state_mutex); mutex_init(&dev->persist->pci_status_mutex); - ret = devlink_register(devlink); - if (ret) - goto err_persist_free; ret = devlink_params_register(devlink, mlx4_devlink_params, ARRAY_SIZE(mlx4_devlink_params)); if (ret) - goto err_devlink_unregister; + goto err_persist_free; mlx4_devlink_set_params_init_values(devlink); ret = __mlx4_init_one(pdev, id->driver_data, priv); if (ret) goto err_params_unregister; devlink_params_publish(devlink); - devlink_reload_enable(devlink); pci_save_state(pdev); + + ret = devlink_register(devlink); + if (ret) { + _mlx4_remove_one(pdev); + return ret; + } + devlink_reload_enable(devlink); return 0; err_params_unregister: devlink_params_unregister(devlink, mlx4_devlink_params, ARRAY_SIZE(mlx4_devlink_params)); -err_devlink_unregister: - devlink_unregister(devlink); err_persist_free: kfree(dev->persist); err_devlink_free: @@ -4141,7 +4144,7 @@ static void mlx4_unload_one(struct pci_dev *pdev) priv->removed = 1; } -static void mlx4_remove_one(struct pci_dev *pdev) +static void _mlx4_remove_one(struct pci_dev *pdev) { struct mlx4_dev_persistent *persist = pci_get_drvdata(pdev); struct mlx4_dev *dev = persist->dev; @@ -4149,8 +4152,6 @@ static void mlx4_remove_one(struct pci_dev *pdev) struct devlink *devlink = priv_to_devlink(priv); int active_vfs = 0; - devlink_reload_disable(devlink); - if (mlx4_is_slave(dev)) persist->interface_state |= MLX4_INTERFACE_STATE_NOWAIT; @@ -4185,11 +4186,26 @@ static void mlx4_remove_one(struct pci_dev *pdev) mlx4_pci_disable_device(dev); devlink_params_unregister(devlink, mlx4_devlink_params, ARRAY_SIZE(mlx4_devlink_params)); - devlink_unregister(devlink); kfree(dev->persist); devlink_free(devlink); } +static void mlx4_remove_one(struct pci_dev *pdev) +{ + struct mlx4_dev_persistent *persist = pci_get_drvdata(pdev); + struct devlink *devlink; + struct mlx4_priv *priv; + struct mlx4_dev *dev; + + dev = persist->dev; + priv = mlx4_priv(dev); + devlink = priv_to_devlink(priv); + + devlink_reload_disable(devlink); + devlink_unregister(devlink); + _mlx4_remove_one(pdev); +} + static int restore_current_port_types(struct mlx4_dev *dev, enum mlx4_port_type *types, enum mlx4_port_type *poss_types) From patchwork Tue Aug 10 13:37:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 494780 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06E63C4338F for ; Tue, 10 Aug 2021 13:38:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB90B60FDA for ; Tue, 10 Aug 2021 13:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241660AbhHJNiq (ORCPT ); Tue, 10 Aug 2021 09:38:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:48854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241647AbhHJNiQ (ORCPT ); Tue, 10 Aug 2021 09:38:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B20C36101E; Tue, 10 Aug 2021 13:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628602674; bh=TvoQojqsY59TCrvQ8l2JACkOs5SoYXc6V5jqqVTGCQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tDXm4IgUlJoezrUCuAzKv0mLdZjMaHw3eemrJSton4hIxatOqfX/HztjxyHagWG7G Vx4yuhqYBegEORxsgnnxjW7fJ8jvLfwdtxNaTg8ayepFGtau3zB7UVfyl1JJymtSHf 208YurRn9eFewDC1axQRco32NLl1gbc2ply5FHSIkxWoUijmWrEMDgsE2BJ52BM5Rs 5JcVsRpNkogkQ9umAiflG7n3ZHBfIHGEinH3x//myCUvGMsBNiky3Mxw68HTpw1XrD KeBjsYRV0tuHd/b2UTvYDyqmsZX7gXog2GVirYWB8xTgOujg6eOlAoeikySJdJtkHs keFvigv/0CFuQ== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Guangbin Huang , Ido Schimmel , Jiri Pirko , linux-kernel@vger.kernel.org, Michael Guralnik , netdev@vger.kernel.org, Saeed Mahameed , Salil Mehta , Tariq Toukan , Yisen Zhuang , Yufeng Mo Subject: [PATCH net-next 5/5] netdevsim: Delay user access till probe is finished Date: Tue, 10 Aug 2021 16:37:35 +0300 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Leon Romanovsky Don't publish supported user space accessible ops till probe is finished. Signed-off-by: Leon Romanovsky --- drivers/net/netdevsim/dev.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 54313bd57797..181258bd72f2 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1470,14 +1470,10 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) if (err) goto err_devlink_free; - err = devlink_register(devlink); - if (err) - goto err_resources_unregister; - err = devlink_params_register(devlink, nsim_devlink_params, ARRAY_SIZE(nsim_devlink_params)); if (err) - goto err_dl_unregister; + goto err_resources_unregister; nsim_devlink_set_params_init_values(nsim_dev, devlink); err = nsim_dev_dummy_region_init(nsim_dev, devlink); @@ -1515,10 +1511,17 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) goto err_psample_exit; devlink_params_publish(devlink); - devlink_reload_enable(devlink); nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY; + err = devlink_register(devlink); + if (err) + goto err_port_del_all; + + devlink_reload_enable(devlink); return 0; +err_port_del_all: + devlink_params_unpublish(devlink); + nsim_dev_port_del_all(nsim_dev); err_psample_exit: nsim_dev_psample_exit(nsim_dev); err_bpf_dev_exit: @@ -1536,8 +1539,6 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) err_params_unregister: devlink_params_unregister(devlink, nsim_devlink_params, ARRAY_SIZE(nsim_devlink_params)); -err_dl_unregister: - devlink_unregister(devlink); err_resources_unregister: devlink_resources_unregister(devlink, NULL); err_devlink_free: @@ -1573,6 +1574,7 @@ void nsim_dev_remove(struct nsim_bus_dev *nsim_bus_dev) struct devlink *devlink = priv_to_devlink(nsim_dev); devlink_reload_disable(devlink); + devlink_unregister(devlink); nsim_dev_reload_destroy(nsim_dev); @@ -1580,7 +1582,6 @@ void nsim_dev_remove(struct nsim_bus_dev *nsim_bus_dev) nsim_dev_debugfs_exit(nsim_dev); devlink_params_unregister(devlink, nsim_devlink_params, ARRAY_SIZE(nsim_devlink_params)); - devlink_unregister(devlink); devlink_resources_unregister(devlink, NULL); devlink_free(devlink); }