From patchwork Wed Nov 17 18:26:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12625213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B4E7C433FE for ; Wed, 17 Nov 2021 18:26:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C4F161A62 for ; Wed, 17 Nov 2021 18:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240021AbhKQS3k (ORCPT ); Wed, 17 Nov 2021 13:29:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:55732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239997AbhKQS3j (ORCPT ); Wed, 17 Nov 2021 13:29:39 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7EB1661BC1; Wed, 17 Nov 2021 18:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637173600; bh=izROKGtj2qGswj8IP0BBhpttn4JyaHRA3FFLjvXH5II=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dY2SlZM5kOLoZwHT19k8dHtMl2WdlYpkOIi2kN8xtLC5ziMYIvzEW3pcnP2zJv8dB dr3gj+TdWXE5Q9mNY2HkTF0qifPOddZzMSHgcmnB/ayolP+YJQ5OfOsx7Bn8bFUK59 nfJ4+LcbScXrGFTyuaH21nU7BOfKOKG2pkZ+ldUjl59xmDcBfb2VyQ1g0Ii8a/1sPV 115SjaHlKE1ND4ScrMlQFwKxYI8jabrvbueATCiYMkKIwgu2Xh/kiIvU6HFm3HyVHY LbKwEzgbzvKyUubLQJvQ5XCD/TKvqWXE/6yzvf9rlkw6pRi+zDbYZHDkMaW8jLwlbH MWr0QZ5m69SbQ== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: [PATCH net-next 1/6] devlink: Remove misleading internal_flags from health reporter dump Date: Wed, 17 Nov 2021 20:26:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Leon Romanovsky DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET command doesn't have .doit callback and has no use in internal_flags at all. Remove this misleading assignment. Fixes: e44ef4e4516c ("devlink: Hang reporter's dump method on a dumpit cb") Signed-off-by: Leon Romanovsky --- net/core/devlink.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 5ba4f9434acd..1cb2e0ae9173 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -8838,8 +8838,6 @@ static const struct genl_small_ops devlink_nl_ops[] = { GENL_DONT_VALIDATE_DUMP_STRICT, .dumpit = devlink_nl_cmd_health_reporter_dump_get_dumpit, .flags = GENL_ADMIN_PERM, - .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT | - DEVLINK_NL_FLAG_NO_LOCK, }, { .cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR, From patchwork Wed Nov 17 18:26:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12625209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93E49C433EF for ; Wed, 17 Nov 2021 18:26:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BA9361BD3 for ; Wed, 17 Nov 2021 18:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240002AbhKQS3d (ORCPT ); Wed, 17 Nov 2021 13:29:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:55478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239997AbhKQS3c (ORCPT ); Wed, 17 Nov 2021 13:29:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0897A61BD3; Wed, 17 Nov 2021 18:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637173593; bh=egTOWZok2LDjlwNFZaUiL4p9ekcH/5KxuwhLpRQVX54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qM01AiRFituJX5zzSS2GSL824fLNVYiatRUoewCIYAB3QvufLFANfD47AvKp4k6J+ ZC3KzlYBKZVJIdRgvJ+9VOWwZ1/YaKFbih6WQG6R5ehJFjUnXkTWZyV+9WYRT1swja PeDdCRerL/TO9HKwe1HWNdf73cwnN0LbyKBoSnhEuE7lXKw/DfccPOQPX8dHBzaaFc 80wYBuMTFlnwwHTjEzkjgULzLLa03ZxP7coBq9Ye3BSwmT6KgO/EPwDzX9w7CHkMB+ 07mTZYULQRTWns+UpJ4Bp0ktaw6UFrv3HTnclLYtLonPqU9p8lf8XIpw2KeQNm2KX/ XEnzzMu7Rb7sw== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: [PATCH net-next 2/6] devlink: Delete useless checks of holding devlink lock Date: Wed, 17 Nov 2021 20:26:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Leon Romanovsky The snapshot API is fully protected by devlink->lock and these internal functions are not exported directly to the code outside of the devlink.c. This makes the checks of holding devlink lock as completely redundant. Signed-off-by: Leon Romanovsky --- net/core/devlink.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 1cb2e0ae9173..dcc09c62f3e5 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -5223,8 +5223,6 @@ static int __devlink_snapshot_id_increment(struct devlink *devlink, u32 id) unsigned long count; void *p; - lockdep_assert_held(&devlink->lock); - p = xa_load(&devlink->snapshot_ids, id); if (WARN_ON(!p)) return -EINVAL; @@ -5259,8 +5257,6 @@ static void __devlink_snapshot_id_decrement(struct devlink *devlink, u32 id) unsigned long count; void *p; - lockdep_assert_held(&devlink->lock); - p = xa_load(&devlink->snapshot_ids, id); if (WARN_ON(!p)) return; @@ -5298,8 +5294,6 @@ static void __devlink_snapshot_id_decrement(struct devlink *devlink, u32 id) */ static int __devlink_snapshot_id_insert(struct devlink *devlink, u32 id) { - lockdep_assert_held(&devlink->lock); - if (xa_load(&devlink->snapshot_ids, id)) return -EEXIST; @@ -5325,8 +5319,6 @@ static int __devlink_snapshot_id_insert(struct devlink *devlink, u32 id) */ static int __devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id) { - lockdep_assert_held(&devlink->lock); - return xa_alloc(&devlink->snapshot_ids, id, xa_mk_value(1), xa_limit_32b, GFP_KERNEL); } @@ -5353,8 +5345,6 @@ __devlink_region_snapshot_create(struct devlink_region *region, struct devlink_snapshot *snapshot; int err; - lockdep_assert_held(&devlink->lock); - /* check if region can hold one more snapshot */ if (region->cur_snapshots == region->max_snapshots) return -ENOSPC; @@ -5391,8 +5381,6 @@ static void devlink_region_snapshot_del(struct devlink_region *region, { struct devlink *devlink = region->devlink; - lockdep_assert_held(&devlink->lock); - devlink_nl_region_notify(region, snapshot, DEVLINK_CMD_REGION_DEL); region->cur_snapshots--; list_del(&snapshot->list); From patchwork Wed Nov 17 18:26:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12625211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E57FC433F5 for ; Wed, 17 Nov 2021 18:26:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C34661BF4 for ; Wed, 17 Nov 2021 18:26:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240017AbhKQS3j (ORCPT ); Wed, 17 Nov 2021 13:29:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:55556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240019AbhKQS3g (ORCPT ); Wed, 17 Nov 2021 13:29:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BA27461A62; Wed, 17 Nov 2021 18:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637173596; bh=cTwcL7Q1aISIEWW27EcvXwtKYIYVbjSDJAPhiOQrv3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QmeNigGn2DCXsh2P+cdrK9YlI+5btbCu2NuMazv6QzJTvQT8Bx+wUek4RWd4f/MTz oBEIjQZdtrTeQSmQOL6Uwb0/XxMoDxcdkvtc21I/DFhnWrjz0oZTz4CWcFyduqwZQs T5l7DMG3YMU+/jg1dhnW2n4TuAbowgu83zOiwHfjsyqX4zMfF4AXT3H9IjQ5vZIkRj 90ljwF8wsjslwjKOi56Mlv+Q7kIOD6Vh5tKsQGSCrG2PKJPtT1t2bZIV8UM9Mr/eMm /JAbg91YdQf/FNs5epVv/ZyoqnjNGZQXrOZL7sP8AyrywkQaiOWKAR2D3n1mPWe/FG eFvkEMLcqb+ew== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: [PATCH net-next 3/6] devlink: Simplify devlink resources unregister call Date: Wed, 17 Nov 2021 20:26:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Leon Romanovsky The devlink_resources_unregister() used second parameter as an entry point for the recursive removal of devlink resources. None of external to devlink users needed to use this field, so lat's remove it. Signed-off-by: Leon Romanovsky --- drivers/net/ethernet/mellanox/mlxsw/core.c | 8 ++--- .../net/ethernet/mellanox/mlxsw/spectrum.c | 4 +-- drivers/net/netdevsim/dev.c | 4 +-- include/net/devlink.h | 3 +- net/core/devlink.c | 34 +++++++++++-------- net/dsa/dsa.c | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 3fd3812b8f31..0d1f08bbf631 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -160,7 +160,7 @@ static void mlxsw_ports_fini(struct mlxsw_core *mlxsw_core, bool reload) devlink_resource_occ_get_unregister(devlink, MLXSW_CORE_RESOURCE_PORTS); if (!reload) - devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL); + devlink_resources_unregister(priv_to_devlink(mlxsw_core)); kfree(mlxsw_core->ports); } @@ -2033,7 +2033,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, mlxsw_ports_fini(mlxsw_core, reload); err_ports_init: if (!reload) - devlink_resources_unregister(devlink, NULL); + devlink_resources_unregister(devlink); err_register_resources: mlxsw_bus->fini(bus_priv); err_bus_init: @@ -2099,7 +2099,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, kfree(mlxsw_core->lag.mapping); mlxsw_ports_fini(mlxsw_core, reload); if (!reload) - devlink_resources_unregister(devlink, NULL); + devlink_resources_unregister(devlink); mlxsw_core->bus->fini(mlxsw_core->bus_priv); if (!reload) devlink_free(devlink); @@ -2108,7 +2108,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, reload_fail_deinit: mlxsw_core_params_unregister(mlxsw_core); - devlink_resources_unregister(devlink, NULL); + devlink_resources_unregister(devlink); devlink_free(devlink); } EXPORT_SYMBOL(mlxsw_core_bus_device_unregister); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 5925db386b1b..6a5887aacbc0 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -3336,7 +3336,7 @@ static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core) err_policer_resources_register: err_resources_counter_register: err_resources_span_register: - devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL); + devlink_resources_unregister(priv_to_devlink(mlxsw_core)); return err; } @@ -3370,7 +3370,7 @@ static int mlxsw_sp2_resources_register(struct mlxsw_core *mlxsw_core) err_policer_resources_register: err_resources_counter_register: err_resources_span_register: - devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL); + devlink_resources_unregister(priv_to_devlink(mlxsw_core)); return err; } diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 54345c096a16..08d7b465a0de 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1622,7 +1622,7 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev) devlink_params_unregister(devlink, nsim_devlink_params, ARRAY_SIZE(nsim_devlink_params)); err_dl_unregister: - devlink_resources_unregister(devlink, NULL); + devlink_resources_unregister(devlink); err_vfc_free: kfree(nsim_dev->vfconfigs); err_devlink_free: @@ -1668,7 +1668,7 @@ void nsim_drv_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_resources_unregister(devlink, NULL); + devlink_resources_unregister(devlink); kfree(nsim_dev->vfconfigs); devlink_free(devlink); dev_set_drvdata(&nsim_bus_dev->dev, NULL); diff --git a/include/net/devlink.h b/include/net/devlink.h index aab3d007c577..f919545f5781 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1567,8 +1567,7 @@ int devlink_resource_register(struct devlink *devlink, u64 resource_id, u64 parent_resource_id, const struct devlink_resource_size_params *size_params); -void devlink_resources_unregister(struct devlink *devlink, - struct devlink_resource *resource); +void devlink_resources_unregister(struct devlink *devlink); int devlink_resource_size_get(struct devlink *devlink, u64 resource_id, u64 *p_resource_size); diff --git a/net/core/devlink.c b/net/core/devlink.c index dcc09c62f3e5..af94015b7424 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -9889,34 +9889,38 @@ int devlink_resource_register(struct devlink *devlink, } EXPORT_SYMBOL_GPL(devlink_resource_register); +static void devlink_resource_unregister(struct devlink *devlink, + struct devlink_resource *resource) +{ + struct devlink_resource *tmp, *child_resource; + + list_for_each_entry_safe(child_resource, tmp, &resource->resource_list, + list) { + devlink_resource_unregister(devlink, child_resource); + list_del(&child_resource->list); + kfree(child_resource); + } +} + /** * devlink_resources_unregister - free all resources * * @devlink: devlink - * @resource: resource */ -void devlink_resources_unregister(struct devlink *devlink, - struct devlink_resource *resource) +void devlink_resources_unregister(struct devlink *devlink) { struct devlink_resource *tmp, *child_resource; - struct list_head *resource_list; - - if (resource) - resource_list = &resource->resource_list; - else - resource_list = &devlink->resource_list; - if (!resource) - mutex_lock(&devlink->lock); + mutex_lock(&devlink->lock); - list_for_each_entry_safe(child_resource, tmp, resource_list, list) { - devlink_resources_unregister(devlink, child_resource); + list_for_each_entry_safe(child_resource, tmp, &devlink->resource_list, + list) { + devlink_resource_unregister(devlink, child_resource); list_del(&child_resource->list); kfree(child_resource); } - if (!resource) - mutex_unlock(&devlink->lock); + mutex_unlock(&devlink->lock); } EXPORT_SYMBOL_GPL(devlink_resources_unregister); diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index ea5169e671ae..d9d0d227092c 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -406,7 +406,7 @@ EXPORT_SYMBOL_GPL(dsa_devlink_resource_register); void dsa_devlink_resources_unregister(struct dsa_switch *ds) { - devlink_resources_unregister(ds->devlink, NULL); + devlink_resources_unregister(ds->devlink); } EXPORT_SYMBOL_GPL(dsa_devlink_resources_unregister); From patchwork Wed Nov 17 18:26:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12625217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61A22C433EF for ; Wed, 17 Nov 2021 18:26:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B5D461BC1 for ; Wed, 17 Nov 2021 18:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240047AbhKQS3z (ORCPT ); Wed, 17 Nov 2021 13:29:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:56022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240022AbhKQS3u (ORCPT ); Wed, 17 Nov 2021 13:29:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C5FA7630EF; Wed, 17 Nov 2021 18:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637173611; bh=Zx6bnepzAQ2wHJg4YTH9cSBpJbS0LJl3ALw5zfqVGOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJJVTXS0cB8q2/0+qVBWbuFa2ZO3OUR1YlUGpK0gGonXq8nhOB8FivtYlcGAxXYXd BSD7p8TBTZO1gum21VzUz1pmUVfvx5NmEkULwwcPBd4de4Ed0I0n7Wf7lBBQn9yBpB bEmV3gAvQb3BwO4GsQ7V4jFEA4EbBo0Ek3i2U61Se/ZRbRVgvQSPs6HbskO5F5OOn2 aDgTAse4R6CQeuwVHqeETr9fBdmWv6X49R8EkCxa5LWhieeu1RWhxPNHR7iVjOqH6W 6zEbmG5ddN5h9PKHkE7bAwRrJoJa5MHzaB2NrFB4Mb1B2IKrZrvVNMZqKAXi8P/uVJ ZWNR+wnKD0BFA== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: [PATCH net-next 4/6] devlink: Clean registration of devlink port Date: Wed, 17 Nov 2021 20:26:20 +0200 Message-Id: <9c3eb77a90a2be10d5c637981a8047160845f60f.1637173517.git.leonro@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Leon Romanovsky devlink_port_register() is in-kernel API and as such can't really fail as long as driver author didn't make a mistake by providing already existing port index. Instead of relying on various error prints from the driver, convert the existence check to be WARN_ON(), so such a mistake will be caught easier. As an outcome of this conversion, it was made clear that this function should be void and devlink->lock was intended to protect addition to port_list. Signed-off-by: Leon Romanovsky --- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 7 +--- .../freescale/dpaa2/dpaa2-eth-devlink.c | 7 +--- drivers/net/ethernet/intel/ice/ice_devlink.c | 23 ++----------- .../marvell/prestera/prestera_devlink.c | 8 +---- drivers/net/ethernet/mellanox/mlx4/main.c | 4 +-- .../ethernet/mellanox/mlx5/core/en/devlink.c | 5 ++- .../ethernet/mellanox/mlx5/core/en/devlink.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 7 +--- .../mellanox/mlx5/core/esw/devlink_port.c | 9 ++---- drivers/net/ethernet/mellanox/mlxsw/core.c | 7 ++-- drivers/net/ethernet/mscc/ocelot_net.c | 4 +-- .../net/ethernet/netronome/nfp/nfp_devlink.c | 4 +-- .../ethernet/pensando/ionic/ionic_devlink.c | 8 +---- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 14 +------- drivers/net/netdevsim/dev.c | 7 ++-- include/net/devlink.h | 6 ++-- net/core/devlink.c | 32 ++++++++----------- net/dsa/dsa2.c | 9 ++---- 18 files changed, 41 insertions(+), 122 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c index 5c464ea73576..c4a7122ee1fd 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c @@ -1209,11 +1209,7 @@ int bnxt_dl_register(struct bnxt *bp) memcpy(attrs.switch_id.id, bp->dsn, sizeof(bp->dsn)); attrs.switch_id.id_len = sizeof(bp->dsn); devlink_port_attrs_set(&bp->dl_port, &attrs); - rc = devlink_port_register(dl, &bp->dl_port, bp->pf.port_id); - if (rc) { - netdev_err(bp->dev, "devlink_port_register failed\n"); - goto err_dl_free; - } + devlink_port_register(dl, &bp->dl_port, bp->pf.port_id); rc = bnxt_dl_params_register(bp); if (rc) @@ -1225,7 +1221,6 @@ int bnxt_dl_register(struct bnxt *bp) err_dl_port_unreg: devlink_port_unregister(&bp->dl_port); -err_dl_free: devlink_free(dl); return rc; } diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c index 7fefe1574b6a..d19423780e59 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth-devlink.c @@ -226,17 +226,12 @@ int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv) { struct devlink_port *devlink_port = &priv->devlink_port; struct devlink_port_attrs attrs = {}; - int err; attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; devlink_port_attrs_set(devlink_port, &attrs); - err = devlink_port_register(priv->devlink, devlink_port, 0); - if (err) - return err; - + devlink_port_register(priv->devlink, devlink_port, 0); devlink_port_type_eth_set(devlink_port, priv->net_dev); - return 0; } diff --git a/drivers/net/ethernet/intel/ice/ice_devlink.c b/drivers/net/ethernet/intel/ice/ice_devlink.c index b9bd9f9472f6..ba4c463cb276 100644 --- a/drivers/net/ethernet/intel/ice/ice_devlink.c +++ b/drivers/net/ethernet/intel/ice/ice_devlink.c @@ -498,10 +498,6 @@ int ice_devlink_create_pf_port(struct ice_pf *pf) struct devlink_port *devlink_port; struct devlink *devlink; struct ice_vsi *vsi; - struct device *dev; - int err; - - dev = ice_pf_to_dev(pf); devlink_port = &pf->devlink_port; @@ -514,13 +510,7 @@ int ice_devlink_create_pf_port(struct ice_pf *pf) devlink_port_attrs_set(devlink_port, &attrs); devlink = priv_to_devlink(pf); - err = devlink_port_register(devlink, devlink_port, vsi->idx); - if (err) { - dev_err(dev, "Failed to create devlink port for PF %d, error %d\n", - pf->hw.pf_id, err); - return err; - } - + devlink_port_register(devlink, devlink_port, vsi->idx); return 0; } @@ -554,12 +544,9 @@ int ice_devlink_create_vf_port(struct ice_vf *vf) struct devlink_port *devlink_port; struct devlink *devlink; struct ice_vsi *vsi; - struct device *dev; struct ice_pf *pf; - int err; pf = vf->pf; - dev = ice_pf_to_dev(pf); vsi = ice_get_vf_vsi(vf); devlink_port = &vf->devlink_port; @@ -570,13 +557,7 @@ int ice_devlink_create_vf_port(struct ice_vf *vf) devlink_port_attrs_set(devlink_port, &attrs); devlink = priv_to_devlink(pf); - err = devlink_port_register(devlink, devlink_port, vsi->idx); - if (err) { - dev_err(dev, "Failed to create devlink port for VF %d, error %d\n", - vf->vf_id, err); - return err; - } - + devlink_port_register(devlink, devlink_port, vsi->idx); return 0; } diff --git a/drivers/net/ethernet/marvell/prestera/prestera_devlink.c b/drivers/net/ethernet/marvell/prestera/prestera_devlink.c index 06279cd6da67..91a4ff2e412b 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_devlink.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_devlink.c @@ -422,7 +422,6 @@ int prestera_devlink_port_register(struct prestera_port *port) struct prestera_switch *sw = port->sw; struct devlink *dl = priv_to_devlink(sw); struct devlink_port_attrs attrs = {}; - int err; attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; attrs.phys.port_number = port->fp_id; @@ -431,12 +430,7 @@ int prestera_devlink_port_register(struct prestera_port *port) devlink_port_attrs_set(&port->dl_port, &attrs); - err = devlink_port_register(dl, &port->dl_port, port->fp_id); - if (err) { - dev_err(prestera_dev(sw), "devlink_port_register failed: %d\n", err); - return err; - } - + devlink_port_register(dl, &port->dl_port, port->fp_id); return 0; } diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index b187c210d4d6..c88a586ecd8d 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -3033,9 +3033,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port) struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; int err; - err = devlink_port_register(devlink, &info->devlink_port, port); - if (err) - return err; + devlink_port_register(devlink, &info->devlink_port, port); /* Ethernet and IB drivers will normally set the port type, * but if they are not built set the type now to prevent diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c index ae52e7f38306..76326858db22 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c @@ -14,7 +14,7 @@ mlx5e_devlink_get_port_parent_id(struct mlx5_core_dev *dev, struct netdev_phys_i memcpy(ppid->id, &parent_id, sizeof(parent_id)); } -int mlx5e_devlink_port_register(struct mlx5e_priv *priv) +void mlx5e_devlink_port_register(struct mlx5e_priv *priv) { struct devlink *devlink = priv_to_devlink(priv->mdev); struct devlink_port_attrs attrs = {}; @@ -40,8 +40,7 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv) dl_port = mlx5e_devlink_get_dl_port(priv); memset(dl_port, 0, sizeof(*dl_port)); devlink_port_attrs_set(dl_port, &attrs); - - return devlink_port_register(devlink, dl_port, dl_port_index); + devlink_port_register(devlink, dl_port, dl_port_index); } void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h index 10b50feb9883..04ada8624367 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h @@ -7,7 +7,7 @@ #include #include "en.h" -int mlx5e_devlink_port_register(struct mlx5e_priv *priv); +void mlx5e_devlink_port_register(struct mlx5e_priv *priv); void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv); void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv); struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 65571593ec5c..385533dce1bb 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -5461,11 +5461,7 @@ static int mlx5e_probe(struct auxiliary_device *adev, priv->profile = profile; priv->ppriv = NULL; - err = mlx5e_devlink_port_register(priv); - if (err) { - mlx5_core_err(mdev, "mlx5e_devlink_port_register failed, %d\n", err); - goto err_destroy_netdev; - } + mlx5e_devlink_port_register(priv); err = profile->init(mdev, netdev); if (err) { @@ -5497,7 +5493,6 @@ static int mlx5e_probe(struct auxiliary_device *adev, profile->cleanup(priv); err_devlink_cleanup: mlx5e_devlink_port_unregister(priv); -err_destroy_netdev: mlx5e_destroy_netdev(priv); return err; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c index 7f9b96d9537e..d1550f661644 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c @@ -87,9 +87,7 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_ devlink = priv_to_devlink(dev); dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num); - err = devlink_port_register(devlink, dl_port, dl_port_index); - if (err) - goto reg_err; + devlink_port_register(devlink, dl_port, dl_port_index); err = devlink_rate_leaf_create(dl_port, vport); if (err) @@ -100,7 +98,6 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_ rate_err: devlink_port_unregister(dl_port); -reg_err: mlx5_esw_dl_port_free(dl_port); return err; } @@ -156,9 +153,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p devlink_port_attrs_pci_sf_set(dl_port, controller, pfnum, sfnum, !!controller); devlink = priv_to_devlink(dev); dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num); - err = devlink_port_register(devlink, dl_port, dl_port_index); - if (err) - return err; + devlink_port_register(devlink, dl_port, dl_port_index); err = devlink_rate_leaf_create(dl_port, vport); if (err) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 0d1f08bbf631..7684a86c1745 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2760,7 +2760,6 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port, &mlxsw_core->ports[local_port]; struct devlink_port *devlink_port = &mlxsw_core_port->devlink_port; struct devlink_port_attrs attrs = {}; - int err; attrs.split = split; attrs.lanes = lanes; @@ -2772,10 +2771,8 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port, attrs.switch_id.id_len = switch_id_len; mlxsw_core_port->local_port = local_port; devlink_port_attrs_set(devlink_port, &attrs); - err = devlink_port_register(devlink, devlink_port, local_port); - if (err) - memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port)); - return err; + devlink_port_register(devlink, devlink_port, local_port); + return 0; } static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 0fcf359a6975..fc534b7c3a96 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -172,8 +172,8 @@ int ocelot_port_devlink_init(struct ocelot *ocelot, int port, attrs.flavour = flavour; devlink_port_attrs_set(dlp, &attrs); - - return devlink_port_register(dl, dlp, port); + devlink_port_register(dl, dlp, port); + return 0; } void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_devlink.c b/drivers/net/ethernet/netronome/nfp/nfp_devlink.c index bea978df7713..ed53462ac9c2 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_devlink.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_devlink.c @@ -374,8 +374,8 @@ int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port) devlink_port_attrs_set(&port->dl_port, &attrs); devlink = priv_to_devlink(app->pf); - - return devlink_port_register(devlink, &port->dl_port, port->eth_id); + devlink_port_register(devlink, &port->dl_port, port->eth_id); + return 0; } void nfp_devlink_port_unregister(struct nfp_port *port) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c index 4297ed9024c0..f8c80856ca02 100644 --- a/drivers/net/ethernet/pensando/ionic/ionic_devlink.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_devlink.c @@ -80,16 +80,10 @@ int ionic_devlink_register(struct ionic *ionic) { struct devlink *dl = priv_to_devlink(ionic); struct devlink_port_attrs attrs = {}; - int err; attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; devlink_port_attrs_set(&ionic->dl_port, &attrs); - err = devlink_port_register(dl, &ionic->dl_port, 0); - if (err) { - dev_err(ionic->dev, "devlink_port_register failed: %d\n", err); - return err; - } - + devlink_port_register(dl, &ionic->dl_port, 0); devlink_port_type_eth_set(&ionic->dl_port, ionic->lif->netdev); devlink_register(dl); return 0; diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index c092cb61416a..2e3cc08da998 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -2453,24 +2453,12 @@ static int am65_cpsw_nuss_register_devlink(struct am65_cpsw_common *common) memcpy(attrs.switch_id.id, common->switch_id, attrs.switch_id.id_len); devlink_port_attrs_set(dl_port, &attrs); - ret = devlink_port_register(common->devlink, dl_port, port->port_id); - if (ret) { - dev_err(dev, "devlink_port reg fail for port %d, ret:%d\n", - port->port_id, ret); - goto dl_port_unreg; - } + devlink_port_register(common->devlink, dl_port, port->port_id); devlink_port_type_eth_set(dl_port, port->ndev); } devlink_register(common->devlink); return ret; -dl_port_unreg: - for (i = i - 1; i >= 1; i--) { - port = am65_common_get_port(common, i); - dl_port = &port->devlink_port; - - devlink_port_unregister(dl_port); - } dl_unreg: devlink_free(common->devlink); return ret; diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 08d7b465a0de..1f0c085d8f76 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1380,10 +1380,8 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ memcpy(attrs.switch_id.id, nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); attrs.switch_id.id_len = nsim_dev->switch_id.id_len; devlink_port_attrs_set(devlink_port, &attrs); - err = devlink_port_register(priv_to_devlink(nsim_dev), devlink_port, - nsim_dev_port->port_index); - if (err) - goto err_port_free; + devlink_port_register(priv_to_devlink(nsim_dev), devlink_port, + nsim_dev_port->port_index); err = nsim_dev_port_debugfs_init(nsim_dev, nsim_dev_port); if (err) @@ -1413,7 +1411,6 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ nsim_dev_port_debugfs_exit(nsim_dev_port); err_dl_port_unregister: devlink_port_unregister(devlink_port); -err_port_free: kfree(nsim_dev_port); return err; } diff --git a/include/net/devlink.h b/include/net/devlink.h index f919545f5781..bc2bdff043a3 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1511,9 +1511,9 @@ void devlink_set_features(struct devlink *devlink, u64 features); void devlink_register(struct devlink *devlink); void devlink_unregister(struct devlink *devlink); void devlink_free(struct devlink *devlink); -int devlink_port_register(struct devlink *devlink, - struct devlink_port *devlink_port, - unsigned int port_index); +void devlink_port_register(struct devlink *devlink, + struct devlink_port *devlink_port, + unsigned int port_index); void devlink_port_unregister(struct devlink_port *devlink_port); void devlink_port_type_eth_set(struct devlink_port *devlink_port, struct net_device *netdev); diff --git a/net/core/devlink.c b/net/core/devlink.c index af94015b7424..356057ea2e52 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -239,12 +239,6 @@ static struct devlink_port *devlink_port_get_by_index(struct devlink *devlink, return NULL; } -static bool devlink_port_index_exists(struct devlink *devlink, - unsigned int port_index) -{ - return devlink_port_get_by_index(devlink, port_index); -} - static struct devlink_port *devlink_port_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) { @@ -9203,30 +9197,28 @@ static void devlink_port_type_warn_cancel(struct devlink_port *devlink_port) * Note that the caller should take care of zeroing the devlink_port * structure. */ -int devlink_port_register(struct devlink *devlink, - struct devlink_port *devlink_port, - unsigned int port_index) +void devlink_port_register(struct devlink *devlink, + struct devlink_port *devlink_port, + unsigned int port_index) { - mutex_lock(&devlink->lock); - if (devlink_port_index_exists(devlink, port_index)) { - mutex_unlock(&devlink->lock); - return -EEXIST; - } - + WARN_ON(devlink_port_get_by_index(devlink, port_index)); WARN_ON(devlink_port->devlink); + devlink_port->devlink = devlink; devlink_port->index = port_index; spin_lock_init(&devlink_port->type_lock); INIT_LIST_HEAD(&devlink_port->reporter_list); mutex_init(&devlink_port->reporters_lock); - list_add_tail(&devlink_port->list, &devlink->port_list); INIT_LIST_HEAD(&devlink_port->param_list); INIT_LIST_HEAD(&devlink_port->region_list); - mutex_unlock(&devlink->lock); INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn); - devlink_port_type_warn_schedule(devlink_port); + + mutex_lock(&devlink->lock); + list_add_tail(&devlink_port->list, &devlink->port_list); + mutex_unlock(&devlink->lock); + devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); - return 0; + devlink_port_type_warn_schedule(devlink_port); } EXPORT_SYMBOL_GPL(devlink_port_register); @@ -9241,9 +9233,11 @@ void devlink_port_unregister(struct devlink_port *devlink_port) devlink_port_type_warn_cancel(devlink_port); devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_DEL); + mutex_lock(&devlink->lock); list_del(&devlink_port->list); mutex_unlock(&devlink->lock); + WARN_ON(!list_empty(&devlink_port->reporter_list)); WARN_ON(!list_empty(&devlink_port->region_list)); mutex_destroy(&devlink_port->reporters_lock); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 826957b6442b..29f39f761e05 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -504,7 +504,6 @@ static int dsa_port_devlink_setup(struct dsa_port *dp) struct devlink *dl = dp->ds->devlink; const unsigned char *id; unsigned char len; - int err; id = (const unsigned char *)&dst->index; len = sizeof(dst->index); @@ -530,12 +529,10 @@ static int dsa_port_devlink_setup(struct dsa_port *dp) } devlink_port_attrs_set(dlp, &attrs); - err = devlink_port_register(dl, dlp, dp->index); - - if (!err) - dp->devlink_port_setup = true; + devlink_port_register(dl, dlp, dp->index); + dp->devlink_port_setup = true; - return err; + return 0; } static void dsa_port_teardown(struct dsa_port *dp) From patchwork Wed Nov 17 18:26:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12625215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C2EEC433EF for ; Wed, 17 Nov 2021 18:26:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F52061BC1 for ; Wed, 17 Nov 2021 18:26:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240081AbhKQS3w (ORCPT ); Wed, 17 Nov 2021 13:29:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:55842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240040AbhKQS3n (ORCPT ); Wed, 17 Nov 2021 13:29:43 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 42EC261BD3; Wed, 17 Nov 2021 18:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637173604; bh=9GifBOLGSt92YGCLXeltZ5sxLbD7rh+yoqUpg2uHSto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kally2Xxf6HW0dc9sixj9XBFUhD0ZYcEmZeZ6/yG7ptkLtALMd+zjbI/E1Mlpd8lN +XRvcYyQQSfQ+AVZr3g7XnTwVlRGUV6tRfEe0I2ui/WxTxhpFt9xkdXT7uq7SerEjo 9mLXZWyacsRbuZdMoEIkS4M/3r5Zi1ltJBimLdxs4kYYGLFnecIoj9yXd1WkEjcrzT BLqEET89BTEGoHzsq2vvOEVCVBZixhAjr5tyWOmG5xkOIW3aSCGRsw15Enfh0TJatt daiP2YoPM9jVpqPhQ6eBhAe0XAH98x6RlBV9ltBgbjtROttUs3+t8XKxQEGkTSJ6F7 /NPaG/PI+N9aw== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: [PATCH net-next 5/6] devlink: Reshuffle resource registration logic Date: Wed, 17 Nov 2021 20:26:21 +0200 Message-Id: <6176a137a4ded48501e8a06fda0e305f9cfc787c.1637173517.git.leonro@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Leon Romanovsky The devlink->lock doesn't need to be held during whole execution of function, but only when recursive path walk and list addition are performed. So reshuffle the resource registration logic to allocate resource and configure it without lock. As part of this change, complain more louder if driver authors used already existed resource_id. It is performed outside of the locks as drivers were supposed to provide unique IDs and such error can't happen. Signed-off-by: Leon Romanovsky --- net/core/devlink.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 356057ea2e52..1dda313d6d1b 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -9833,17 +9833,9 @@ int devlink_resource_register(struct devlink *devlink, { struct devlink_resource *resource; struct list_head *resource_list; - bool top_hierarchy; int err = 0; - top_hierarchy = parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP; - - mutex_lock(&devlink->lock); - resource = devlink_resource_find(devlink, NULL, resource_id); - if (resource) { - err = -EINVAL; - goto out; - } + WARN_ON(devlink_resource_find(devlink, NULL, resource_id)); resource = kzalloc(sizeof(*resource), GFP_KERNEL); if (!resource) { @@ -9851,7 +9843,17 @@ int devlink_resource_register(struct devlink *devlink, goto out; } - if (top_hierarchy) { + resource->name = resource_name; + resource->size = resource_size; + resource->size_new = resource_size; + resource->id = resource_id; + resource->size_valid = true; + memcpy(&resource->size_params, size_params, + sizeof(resource->size_params)); + INIT_LIST_HEAD(&resource->resource_list); + + mutex_lock(&devlink->lock); + if (parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP) { resource_list = &devlink->resource_list; } else { struct devlink_resource *parent_resource; @@ -9868,14 +9870,6 @@ int devlink_resource_register(struct devlink *devlink, } } - resource->name = resource_name; - resource->size = resource_size; - resource->size_new = resource_size; - resource->id = resource_id; - resource->size_valid = true; - memcpy(&resource->size_params, size_params, - sizeof(resource->size_params)); - INIT_LIST_HEAD(&resource->resource_list); list_add_tail(&resource->list, resource_list); out: mutex_unlock(&devlink->lock); From patchwork Wed Nov 17 18:26:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 12625219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48B9EC433FE for ; Wed, 17 Nov 2021 18:26:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35FE361BC1 for ; Wed, 17 Nov 2021 18:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239997AbhKQS3z (ORCPT ); Wed, 17 Nov 2021 13:29:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:55958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240041AbhKQS3q (ORCPT ); Wed, 17 Nov 2021 13:29:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E3B161BC1; Wed, 17 Nov 2021 18:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637173608; bh=QPquNXgImB4Oa49ucF6VehzZ8a7je6X23RfNQvsdXzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h86nxP6ANuEv1VwkitSi4FJ0O0r3K7pI0qYMJcN1QtjSwHdPqbXB6F7YyFpuU/IHq 5lz2E48rFEms1S3wGaYHwO9uM1zHFS9B9eJ5L+YrXSXIu0/dkYp513cVfioStJw8Hj pehXUzI4pt3q4CrcHmXLV+CATzbzc4vM9xkUV+Ghg/E7Qd9Qzi65cqiZNoxPL02+Rr xMK8VG0mh8/g12D2wugh7bIwNyVU4xvF0/Bw96a48K1d0iQr4G2Hy4XwIcbzVaZbko 0T17NupnlXvfHHNyUOHGysABu4xDLuJ6sK+l3MtvVNmEeD9MbOdNpBYvkiD8aVNneo IL5lCJw4zmZ1A== From: Leon Romanovsky To: "David S . Miller" , Jakub Kicinski Cc: Leon Romanovsky , Alexandre Belloni , Andrew Lunn , Aya Levin , Claudiu Manoil , drivers@pensando.io, Florian Fainelli , Ido Schimmel , intel-wired-lan@lists.osuosl.org, Ioana Ciornei , Jesse Brandeburg , Jiri Pirko , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michael Chan , netdev@vger.kernel.org, oss-drivers@corigine.com, Saeed Mahameed , Shannon Nelson , Simon Horman , Taras Chornyi , Tariq Toukan , Tony Nguyen , UNGLinuxDriver@microchip.com, Vivien Didelot , Vladimir Oltean Subject: [PATCH net-next 6/6] devlink: Inline sb related functions Date: Wed, 17 Nov 2021 20:26:22 +0200 Message-Id: X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org From: Leon Romanovsky Remove useless indirection of sb related functions, which called only once and do nothing except accessing specific struct field. As part of this cleanup, properly report an programming erro if already existing sb index was supplied during SB registration. Signed-off-by: Leon Romanovsky --- net/core/devlink.c | 110 ++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 77 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 1dda313d6d1b..fb5d3ba331f8 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -361,12 +361,6 @@ static struct devlink_sb *devlink_sb_get_by_index(struct devlink *devlink, return NULL; } -static bool devlink_sb_index_exists(struct devlink *devlink, - unsigned int sb_index) -{ - return devlink_sb_get_by_index(devlink, sb_index); -} - static struct devlink_sb *devlink_sb_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) { @@ -382,16 +376,11 @@ static struct devlink_sb *devlink_sb_get_from_attrs(struct devlink *devlink, return ERR_PTR(-EINVAL); } -static struct devlink_sb *devlink_sb_get_from_info(struct devlink *devlink, - struct genl_info *info) -{ - return devlink_sb_get_from_attrs(devlink, info->attrs); -} - -static int devlink_sb_pool_index_get_from_attrs(struct devlink_sb *devlink_sb, - struct nlattr **attrs, - u16 *p_pool_index) +static int devlink_sb_pool_index_get_from_info(struct devlink_sb *devlink_sb, + struct genl_info *info, + u16 *p_pool_index) { + struct nlattr **attrs = info->attrs; u16 val; if (!attrs[DEVLINK_ATTR_SB_POOL_INDEX]) @@ -404,18 +393,11 @@ static int devlink_sb_pool_index_get_from_attrs(struct devlink_sb *devlink_sb, return 0; } -static int devlink_sb_pool_index_get_from_info(struct devlink_sb *devlink_sb, - struct genl_info *info, - u16 *p_pool_index) -{ - return devlink_sb_pool_index_get_from_attrs(devlink_sb, info->attrs, - p_pool_index); -} - static int -devlink_sb_pool_type_get_from_attrs(struct nlattr **attrs, - enum devlink_sb_pool_type *p_pool_type) +devlink_sb_pool_type_get_from_info(struct genl_info *info, + enum devlink_sb_pool_type *p_pool_type) { + struct nlattr **attrs = info->attrs; u8 val; if (!attrs[DEVLINK_ATTR_SB_POOL_TYPE]) @@ -430,16 +412,10 @@ devlink_sb_pool_type_get_from_attrs(struct nlattr **attrs, } static int -devlink_sb_pool_type_get_from_info(struct genl_info *info, - enum devlink_sb_pool_type *p_pool_type) -{ - return devlink_sb_pool_type_get_from_attrs(info->attrs, p_pool_type); -} - -static int -devlink_sb_th_type_get_from_attrs(struct nlattr **attrs, - enum devlink_sb_threshold_type *p_th_type) +devlink_sb_th_type_get_from_info(struct genl_info *info, + enum devlink_sb_threshold_type *p_th_type) { + struct nlattr **attrs = info->attrs; u8 val; if (!attrs[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE]) @@ -454,18 +430,12 @@ devlink_sb_th_type_get_from_attrs(struct nlattr **attrs, } static int -devlink_sb_th_type_get_from_info(struct genl_info *info, - enum devlink_sb_threshold_type *p_th_type) -{ - return devlink_sb_th_type_get_from_attrs(info->attrs, p_th_type); -} - -static int -devlink_sb_tc_index_get_from_attrs(struct devlink_sb *devlink_sb, - struct nlattr **attrs, - enum devlink_sb_pool_type pool_type, - u16 *p_tc_index) +devlink_sb_tc_index_get_from_info(struct devlink_sb *devlink_sb, + struct genl_info *info, + enum devlink_sb_pool_type pool_type, + u16 *p_tc_index) { + struct nlattr **attrs = info->attrs; u16 val; if (!attrs[DEVLINK_ATTR_SB_TC_INDEX]) @@ -482,16 +452,6 @@ devlink_sb_tc_index_get_from_attrs(struct devlink_sb *devlink_sb, return 0; } -static int -devlink_sb_tc_index_get_from_info(struct devlink_sb *devlink_sb, - struct genl_info *info, - enum devlink_sb_pool_type pool_type, - u16 *p_tc_index) -{ - return devlink_sb_tc_index_get_from_attrs(devlink_sb, info->attrs, - pool_type, p_tc_index); -} - struct devlink_region { struct devlink *devlink; struct devlink_port *port; @@ -1972,7 +1932,7 @@ static int devlink_nl_cmd_sb_get_doit(struct sk_buff *skb, struct sk_buff *msg; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2090,7 +2050,7 @@ static int devlink_nl_cmd_sb_pool_get_doit(struct sk_buff *skb, u16 pool_index; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2214,7 +2174,7 @@ static int devlink_nl_cmd_sb_pool_set_doit(struct sk_buff *skb, u32 size; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2305,7 +2265,7 @@ static int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb, u16 pool_index; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2435,7 +2395,7 @@ static int devlink_nl_cmd_sb_port_pool_set_doit(struct sk_buff *skb, u32 threshold; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2528,7 +2488,7 @@ static int devlink_nl_cmd_sb_tc_pool_bind_get_doit(struct sk_buff *skb, u16 tc_index; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2689,7 +2649,7 @@ static int devlink_nl_cmd_sb_tc_pool_bind_set_doit(struct sk_buff *skb, u32 threshold; int err; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2723,7 +2683,7 @@ static int devlink_nl_cmd_sb_occ_snapshot_doit(struct sk_buff *skb, const struct devlink_ops *ops = devlink->ops; struct devlink_sb *devlink_sb; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -2739,7 +2699,7 @@ static int devlink_nl_cmd_sb_occ_max_clear_doit(struct sk_buff *skb, const struct devlink_ops *ops = devlink->ops; struct devlink_sb *devlink_sb; - devlink_sb = devlink_sb_get_from_info(devlink, info); + devlink_sb = devlink_sb_get_from_attrs(devlink, info->attrs); if (IS_ERR(devlink_sb)) return PTR_ERR(devlink_sb); @@ -9636,29 +9596,24 @@ int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u16 egress_tc_count) { struct devlink_sb *devlink_sb; - int err = 0; - mutex_lock(&devlink->lock); - if (devlink_sb_index_exists(devlink, sb_index)) { - err = -EEXIST; - goto unlock; - } + WARN_ON(devlink_sb_get_by_index(devlink, sb_index)); devlink_sb = kzalloc(sizeof(*devlink_sb), GFP_KERNEL); - if (!devlink_sb) { - err = -ENOMEM; - goto unlock; - } + if (!devlink_sb) + return -ENOMEM; + devlink_sb->index = sb_index; devlink_sb->size = size; devlink_sb->ingress_pools_count = ingress_pools_count; devlink_sb->egress_pools_count = egress_pools_count; devlink_sb->ingress_tc_count = ingress_tc_count; devlink_sb->egress_tc_count = egress_tc_count; + + mutex_lock(&devlink->lock); list_add_tail(&devlink_sb->list, &devlink->sb_list); -unlock: mutex_unlock(&devlink->lock); - return err; + return 0; } EXPORT_SYMBOL_GPL(devlink_sb_register); @@ -9666,9 +9621,10 @@ void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index) { struct devlink_sb *devlink_sb; - mutex_lock(&devlink->lock); devlink_sb = devlink_sb_get_by_index(devlink, sb_index); WARN_ON(!devlink_sb); + + mutex_lock(&devlink->lock); list_del(&devlink_sb->list); mutex_unlock(&devlink->lock); kfree(devlink_sb);