From patchwork Wed Jan 18 15:21:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106530 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31CACC38159 for ; Wed, 18 Jan 2023 15:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231672AbjARPYH (ORCPT ); Wed, 18 Jan 2023 10:24:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjARPXo (ORCPT ); Wed, 18 Jan 2023 10:23:44 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E72D333456 for ; Wed, 18 Jan 2023 07:21:20 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id ud5so84109285ejc.4 for ; Wed, 18 Jan 2023 07:21:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HPs5boUXNfH/ofTeAQzPqRAbf1LNlPZ1Nmt3yv9fFqY=; b=Y592FF9dVeUtRnFdK8ZKA3uxxdZ+4VzxHRLp2P0iuwFELNtRuaq95wX/ayvKH3WmyC dNIRW2BgKBxQ6/zAcesJkUMIDLaKUsa0PlJFe3DGlNtSG1Aj9CbhkK3VdmLv+RSlxuAs RQGqS9mic9BQWSMZN3VY2eAUZxrg8hXz5WmCaeV/0AqBjoTTXaJOEC8Bpuo3q2YD3AK3 WkiUq8RtgZlUxly9NSW/pt5KbRXwZn02opZiHqiGyTyw/W4SLOXv08BFHJIvSlBJMWnr CqRMkc4iMRlJ5Fey9B/sTpQgufZCImOIPa4Tk5G/SlcHqkPy8U+62tAxhBWgMc2XGEh/ AgEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HPs5boUXNfH/ofTeAQzPqRAbf1LNlPZ1Nmt3yv9fFqY=; b=keBb+iOmAtAP/3o869SeUBV1tmApCC9ay+sV8l3gFxKEZNa3S6cWawC54Acdlc/XR0 eS2o/Zy1QOsYTzjMXruplCD6koQfnp/K/V18l0vWuX695bGUJV09Yof9yeUzJXdHWLyP +0+bsns5tJHU9QrvRObNOxAZ6qK/Gh++iTcB7vuadQzDNCaV/yQ8JeGG4dFLyKqev8IK EROq10dBe+WpaPlKCKf0WRIceKQwpNIfeUYR0jqm1ge98KN03GyGw3KpuFFqn+6P/5JQ yOBvmfqad3UiFg+xMHH2wPlDwKZ8vrOV7PsAlshdPtdMDYxiWTkXhe+bc0YetcLw2JhX ybJA== X-Gm-Message-State: AFqh2kohIGvJXAgPYweD55k9qULSrKnTGfNJy8/xHOzE1fKZSWEQAmA7 AxdizArutmWUqTKWvTluuzMNzMMNZwnJmYJIdgB18A== X-Google-Smtp-Source: AMrXdXtveRUbFS+PaYyzK7UBZMbMq7Asah5Vut+YZluMkJfuuvI/CBtff87ThWRdyg6LgkINNIVWWA== X-Received: by 2002:a17:906:774f:b0:870:94e:13f9 with SMTP id o15-20020a170906774f00b00870094e13f9mr7279292ejn.0.1674055279290; Wed, 18 Jan 2023 07:21:19 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id l9-20020a1709060cc900b007b839689adesm14607877ejh.166.2023.01.18.07.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:18 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 01/12] devlink: remove linecards lock Date: Wed, 18 Jan 2023 16:21:04 +0100 Message-Id: <20230118152115.1113149-2-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Similar to other devlink objects, convert the linecards list to be protected by devlink instance lock. Alongside with that rename the create/destroy() functions to devl_* to indicate the devlink instance lock needs to be held while calling them. Signed-off-by: Jiri Pirko Reviewed-by: Ido Schimmel Reviewed-by: Jacob Keller --- v2->v3: fixed typo in patch description --- .../ethernet/mellanox/mlxsw/core_linecards.c | 8 ++-- include/net/devlink.h | 6 +-- net/devlink/core.c | 2 - net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 41 +++++++------------ 5 files changed, 21 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c index 83d2dc91ba2c..025e0db983fe 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c @@ -1259,9 +1259,9 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core, linecard->linecards = linecards; mutex_init(&linecard->lock); - devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core), - slot_index, &mlxsw_linecard_ops, - linecard); + devlink_linecard = devl_linecard_create(priv_to_devlink(mlxsw_core), + slot_index, &mlxsw_linecard_ops, + linecard); if (IS_ERR(devlink_linecard)) return PTR_ERR(devlink_linecard); @@ -1285,7 +1285,7 @@ static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core, if (linecard->active) mlxsw_linecard_active_clear(linecard); mlxsw_linecard_bdev_del(linecard); - devlink_linecard_destroy(linecard->devlink_linecard); + devl_linecard_destroy(linecard->devlink_linecard); mutex_destroy(&linecard->lock); } diff --git a/include/net/devlink.h b/include/net/devlink.h index 425ecef431b7..d7c9572e5bea 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1687,9 +1687,9 @@ void devl_rate_nodes_destroy(struct devlink *devlink); void devlink_port_linecard_set(struct devlink_port *devlink_port, struct devlink_linecard *linecard); struct devlink_linecard * -devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, - const struct devlink_linecard_ops *ops, void *priv); -void devlink_linecard_destroy(struct devlink_linecard *linecard); +devl_linecard_create(struct devlink *devlink, unsigned int linecard_index, + const struct devlink_linecard_ops *ops, void *priv); +void devl_linecard_destroy(struct devlink_linecard *linecard); void devlink_linecard_provision_set(struct devlink_linecard *linecard, const char *type); void devlink_linecard_provision_clear(struct devlink_linecard *linecard); diff --git a/net/devlink/core.c b/net/devlink/core.c index 60beca2df7cc..dfc5b58c0464 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -247,7 +247,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, mutex_init(&devlink->lock); lockdep_set_class(&devlink->lock, &devlink->lock_key); mutex_init(&devlink->reporters_lock); - mutex_init(&devlink->linecards_lock); refcount_set(&devlink->refcount, 1); return devlink; @@ -269,7 +268,6 @@ void devlink_free(struct devlink *devlink) { ASSERT_DEVLINK_NOT_REGISTERED(devlink); - mutex_destroy(&devlink->linecards_lock); mutex_destroy(&devlink->reporters_lock); WARN_ON(!list_empty(&devlink->trap_policer_list)); WARN_ON(!list_empty(&devlink->trap_group_list)); diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index e724e4c2a4ff..32f0adc40c18 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -38,7 +38,6 @@ struct devlink { struct list_head trap_group_list; struct list_head trap_policer_list; struct list_head linecard_list; - struct mutex linecards_lock; /* protects linecard_list */ const struct devlink_ops *ops; u64 features; struct xarray snapshot_ids; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index bf5e0b1c0422..6ba1baab80d3 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -282,13 +282,10 @@ devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) u32 linecard_index = nla_get_u32(attrs[DEVLINK_ATTR_LINECARD_INDEX]); struct devlink_linecard *linecard; - mutex_lock(&devlink->linecards_lock); linecard = devlink_linecard_get_by_index(devlink, linecard_index); - if (linecard) - refcount_inc(&linecard->refcount); - mutex_unlock(&devlink->linecards_lock); if (!linecard) return ERR_PTR(-ENODEV); + refcount_inc(&linecard->refcount); return linecard; } return ERR_PTR(-EINVAL); @@ -2129,7 +2126,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, devlink_dump_for_each_instance_get(msg, state, devlink) { int idx = 0; - mutex_lock(&devlink->linecards_lock); + devl_lock(devlink); if (!devl_is_registered(devlink)) goto next_devlink; @@ -2147,7 +2144,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, cb->extack); mutex_unlock(&linecard->state_lock); if (err) { - mutex_unlock(&devlink->linecards_lock); + devl_unlock(devlink); devlink_put(devlink); state->idx = idx; goto out; @@ -2155,7 +2152,7 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, idx++; } next_devlink: - mutex_unlock(&devlink->linecards_lock); + devl_unlock(devlink); devlink_put(devlink); } out: @@ -10223,7 +10220,7 @@ static void devlink_linecard_types_fini(struct devlink_linecard *linecard) } /** - * devlink_linecard_create - Create devlink linecard + * devl_linecard_create - Create devlink linecard * * @devlink: devlink * @linecard_index: driver-specific numerical identifier of the linecard @@ -10236,8 +10233,8 @@ static void devlink_linecard_types_fini(struct devlink_linecard *linecard) * Return: Line card structure or an ERR_PTR() encoded error code. */ struct devlink_linecard * -devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, - const struct devlink_linecard_ops *ops, void *priv) +devl_linecard_create(struct devlink *devlink, unsigned int linecard_index, + const struct devlink_linecard_ops *ops, void *priv) { struct devlink_linecard *linecard; int err; @@ -10246,17 +10243,13 @@ devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, !ops->types_count || !ops->types_get)) return ERR_PTR(-EINVAL); - mutex_lock(&devlink->linecards_lock); - if (devlink_linecard_index_exists(devlink, linecard_index)) { - mutex_unlock(&devlink->linecards_lock); + if (devlink_linecard_index_exists(devlink, linecard_index)) return ERR_PTR(-EEXIST); - } + linecard = kzalloc(sizeof(*linecard), GFP_KERNEL); - if (!linecard) { - mutex_unlock(&devlink->linecards_lock); + if (!linecard) return ERR_PTR(-ENOMEM); - } linecard->devlink = devlink; linecard->index = linecard_index; @@ -10269,35 +10262,29 @@ devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, if (err) { mutex_destroy(&linecard->state_lock); kfree(linecard); - mutex_unlock(&devlink->linecards_lock); return ERR_PTR(err); } list_add_tail(&linecard->list, &devlink->linecard_list); refcount_set(&linecard->refcount, 1); - mutex_unlock(&devlink->linecards_lock); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); return linecard; } -EXPORT_SYMBOL_GPL(devlink_linecard_create); +EXPORT_SYMBOL_GPL(devl_linecard_create); /** - * devlink_linecard_destroy - Destroy devlink linecard + * devl_linecard_destroy - Destroy devlink linecard * * @linecard: devlink linecard */ -void devlink_linecard_destroy(struct devlink_linecard *linecard) +void devl_linecard_destroy(struct devlink_linecard *linecard) { - struct devlink *devlink = linecard->devlink; - devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); - mutex_lock(&devlink->linecards_lock); list_del(&linecard->list); devlink_linecard_types_fini(linecard); - mutex_unlock(&devlink->linecards_lock); devlink_linecard_put(linecard); } -EXPORT_SYMBOL_GPL(devlink_linecard_destroy); +EXPORT_SYMBOL_GPL(devl_linecard_destroy); /** * devlink_linecard_provision_set - Set provisioning on linecard From patchwork Wed Jan 18 15:21:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106531 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE9EAC32793 for ; Wed, 18 Jan 2023 15:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbjARPYI (ORCPT ); Wed, 18 Jan 2023 10:24:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbjARPXt (ORCPT ); Wed, 18 Jan 2023 10:23:49 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED6B19A for ; Wed, 18 Jan 2023 07:21:22 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id ss4so76772543ejb.11 for ; Wed, 18 Jan 2023 07:21:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=So4EKtIsktS/ZgvQoRytqRmzbbbN8XW/1NYDBhCSUKQ=; b=1LhjN28L7AIwR4Ad9/g2dys33aKCF1lwf0b4JZ9c0dX7JV/KgE6L/+5pWlaha1o6O3 0gayp/UGSky6OZ+kftxTS4WU5TIWridFd+SM2a8pneasmDxRpnoqvRUMjPNlgLtNdibQ q7g2NTgfYviW11ibhQjM7QXgCoyH6MvPZZevCv/JEx/hvvvWLdXvNkXgKIZaPebuefHW WuQLtbk+8bOsCxcIV+EP5fvATMrzsTxqxQizXgNEcKOUtXYn9xRURdWqjpCm60lhCXG3 m4eEUUjPMLgK/bcfvlAhGyLPrx+REwq/Ol2EsyG/wHqRZvHd3ad4YoAeCg+Ywil6xAdi 8p/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=So4EKtIsktS/ZgvQoRytqRmzbbbN8XW/1NYDBhCSUKQ=; b=NQ4s6/1OZXJ31VMU2NquizKEHj7Pa50b1X2zo5zp9p/pw7T+IJIvH43FFRBgWZRpka 1tpy6sT+UCcmtOxY50uecq3lgdycNyKx7oJU+dRZj7h9VLvw9hU9hRSKOgDSBPsb/MaP 3XQW9daxdvWCfTR+Z30pDQRdYz9D5aCPlbobB+zAEE1IgIcKUvFmmJqdFS9T20YnPaBi HWm1ffxDXsVo+gPv1vdzrcOvoxjofTiIgK3l7NlJv2u3YT3U6jnOT+eqYERCxM2yqmM+ 4uodzWEk1XRmYuqTi9e7JrgROx3ZANeBTxO0K4rm/ChLExZA6QPPumDoXP9xTnYB865k +Tlg== X-Gm-Message-State: AFqh2kr9iGVYtp+VACY1CWG8GEF9mqojVXefSNRhQZAeWJj64AvtqaKr JkgGeCk+WeN9nWrPySPC0eHyWXiDAdYXbWRd9f1eoA== X-Google-Smtp-Source: AMrXdXsd6CdjBzDvM3Dth7f/9XQn2OiykP9j9kSx5J4Zpt6eKa4ZQj5h0bcrvPPE926h/TmIhoRwcg== X-Received: by 2002:a17:907:1107:b0:870:e329:5f2f with SMTP id qu7-20020a170907110700b00870e3295f2fmr7154150ejb.51.1674055281289; Wed, 18 Jan 2023 07:21:21 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id 10-20020a170906218a00b0073d796a1043sm14594830eju.123.2023.01.18.07.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:20 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 02/12] devlink: remove linecard reference counting Date: Wed, 18 Jan 2023 16:21:05 +0100 Message-Id: <20230118152115.1113149-3-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko As long as the linecard life time is protected by devlink instance lock, the reference counting is no longer needed. Remove it. Signed-off-by: Jiri Pirko Reviewed-by: Ido Schimmel Reviewed-by: Jacob Keller --- v2->v3: - removed devlink_linecard_put() prototype from devl_internal.h - fixed typo in patch description --- net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 14 ++------------ net/devlink/netlink.c | 5 ----- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 32f0adc40c18..dd4e2c37cf07 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -193,7 +193,6 @@ struct devlink_linecard; struct devlink_linecard * devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info); -void devlink_linecard_put(struct devlink_linecard *linecard); /* Rates */ extern const struct devlink_gen_cmd devl_gen_rate_get; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 6ba1baab80d3..c92bc04bc25c 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -37,7 +37,6 @@ struct devlink_linecard { struct list_head list; struct devlink *devlink; unsigned int index; - refcount_t refcount; const struct devlink_linecard_ops *ops; void *priv; enum devlink_linecard_state state; @@ -285,7 +284,6 @@ devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) linecard = devlink_linecard_get_by_index(devlink, linecard_index); if (!linecard) return ERR_PTR(-ENODEV); - refcount_inc(&linecard->refcount); return linecard; } return ERR_PTR(-EINVAL); @@ -297,14 +295,6 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info) return devlink_linecard_get_from_attrs(devlink, info->attrs); } -void devlink_linecard_put(struct devlink_linecard *linecard) -{ - if (refcount_dec_and_test(&linecard->refcount)) { - mutex_destroy(&linecard->state_lock); - kfree(linecard); - } -} - struct devlink_sb { struct list_head list; unsigned int index; @@ -10266,7 +10256,6 @@ devl_linecard_create(struct devlink *devlink, unsigned int linecard_index, } list_add_tail(&linecard->list, &devlink->linecard_list); - refcount_set(&linecard->refcount, 1); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); return linecard; } @@ -10282,7 +10271,8 @@ void devl_linecard_destroy(struct devlink_linecard *linecard) devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); list_del(&linecard->list); devlink_linecard_types_fini(linecard); - devlink_linecard_put(linecard); + mutex_destroy(&linecard->state_lock); + kfree(linecard); } EXPORT_SYMBOL_GPL(devl_linecard_destroy); diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index b5b8ac6db2d1..3f2ab4360f11 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -170,14 +170,9 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, static void devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { - struct devlink_linecard *linecard; struct devlink *devlink; devlink = info->user_ptr[0]; - if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_LINECARD) { - linecard = info->user_ptr[1]; - devlink_linecard_put(linecard); - } devl_unlock(devlink); devlink_put(devlink); } From patchwork Wed Jan 18 15:21:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106532 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00777C46467 for ; Wed, 18 Jan 2023 15:24:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbjARPYL (ORCPT ); Wed, 18 Jan 2023 10:24:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231311AbjARPXu (ORCPT ); Wed, 18 Jan 2023 10:23:50 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD30111E93 for ; Wed, 18 Jan 2023 07:21:24 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id bk15so26554076ejb.9 for ; Wed, 18 Jan 2023 07:21:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=odPPuqhbkSzx9BlQTBtjL2BqDQLkQZtr7pY/M4AKmrs=; b=gwub6lj5ti4DuWeVQKuJ4NtFekIQJgFSiD9gJHWt3MUP4ytimCQw7dlidE2JCb/Xiy 2QS7b3JlrKmomhiXecuW/SjyLWgOaWJf0zeff8Ea6DVCcmEOZ/4TLKwfACHGwKdXXY4p MNdKAqD0LgluXpSRaDoBCT0jp1AsO93EBpWJjEqurHRCN19Sr8Yu7j0C6GbhrsFHxbFJ NsT3y/EnIpFSpXd16DiaP5MwLE9BpnfWfGo6E2LXAlMO+s42ee8rdYQlfE5RVLfxrsR0 OP62sWLEObboAyIKww1EQTK72mlOI4UJ/KInrL4GWYa/gMAymKkvvYYePj994Ex8631h u1UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=odPPuqhbkSzx9BlQTBtjL2BqDQLkQZtr7pY/M4AKmrs=; b=BRQc5BoijMjPn8h0jJq/mz/ov9XvPWJfzXiPktI7IwuB4wKwwHnD+blTvcOMh3+5DP 4HhHQlygvA1evVaZ77ehXlvy5dPemEw8gCYusbW0WiXR8oQA37xN3BmVaKGZg1KBXyt9 2CBBjRYvzuX+1YesJquJYOmd3CgAWC/LC7yq+i2uGeIqqTRIouTkwcxNenaf+ZtTL5/V Paf7caErvInSipwhw/fxn6LMIxVf88bKTgphdThF9D29lqSxal+SSqDcHYfB1IIaBKqr wA3Ysa8cZ9VVQEsdGumdihFbDu4qzFLput2f2l6FqRtad35RD0j1z1lTDsoBEpBTrH2l xubw== X-Gm-Message-State: AFqh2kqqaa7uclXyklix/W3dHClJyb1nVPfcKkTHqkePVYMlJDySYMEU OuuB+TL7D2AYgWuUiYtDszER2Gspju+MzUOXBqC85A== X-Google-Smtp-Source: AMrXdXtkpLOlV/HS4q4oVlUN/CETEzHsL6yTTB/9pxz1NvZ45hFp2+l0IsNKTgN49cmINAW/C36c8w== X-Received: by 2002:a17:907:8b97:b0:84d:39ba:368b with SMTP id tb23-20020a1709078b9700b0084d39ba368bmr8667447ejc.75.1674055283288; Wed, 18 Jan 2023 07:21:23 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id m24-20020a1709066d1800b0084d4b8f5889sm11940110ejr.102.2023.01.18.07.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:22 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 03/12] net/mlx5e: Create separate devlink instance for ethernet auxiliary device Date: Wed, 18 Jan 2023 16:21:06 +0100 Message-Id: <20230118152115.1113149-4-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The fact that devlink instance lock is held over mlx5 auxiliary devices probe and remove routines brought a need to conditionally take devlink instance lock there. The code is checking a MLX5E_LOCKED_FLOW flag in mlx5 priv struct. This is racy and may lead to access devlink objects without holding instance lock or deadlock. To avoid this, the only lock-wise sane solution is to make the devlink entities created by the auxiliary device independent on the original pci devlink instance. Create devlink instance for the auxiliary device and put the uplink port instance there alongside with the port health reporters. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v4->v5: - new patch --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 ++ .../ethernet/mellanox/mlx5/core/en/devlink.c | 44 ++++++++++++------- .../ethernet/mellanox/mlx5/core/en/devlink.h | 5 ++- .../net/ethernet/mellanox/mlx5/core/en_main.c | 25 ++++++++--- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 82573ac722d1..da58322cbc3a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -971,6 +971,10 @@ struct mlx5e_priv { struct dentry *dfs_root; }; +struct mlx5e_dev { + struct mlx5e_priv *priv; +}; + struct mlx5e_rx_handlers { mlx5e_fp_handle_rx_cqe handle_rx_cqe; mlx5e_fp_handle_rx_cqe handle_rx_cqe_mpwqe; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c index 83adaabf59f5..03ad3b61dfc7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c @@ -4,6 +4,29 @@ #include "en/devlink.h" #include "eswitch.h" +static const struct devlink_ops mlx5e_devlink_ops = { +}; + +struct mlx5e_dev *mlx5e_create_devlink(struct device *dev) +{ + struct mlx5e_dev *mlx5e_dev; + struct devlink *devlink; + + devlink = devlink_alloc(&mlx5e_devlink_ops, sizeof(*mlx5e_dev), dev); + if (!devlink) + return ERR_PTR(-ENOMEM); + devlink_register(devlink); + return devlink_priv(devlink); +} + +void mlx5e_destroy_devlink(struct mlx5e_dev *mlx5e_dev) +{ + struct devlink *devlink = priv_to_devlink(mlx5e_dev); + + devlink_unregister(devlink); + devlink_free(devlink); +} + static void mlx5e_devlink_get_port_parent_id(struct mlx5_core_dev *dev, struct netdev_phys_item_id *ppid) { @@ -14,14 +37,14 @@ 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) +int mlx5e_devlink_port_register(struct mlx5e_dev *mlx5e_dev, + struct mlx5e_priv *priv) { - struct devlink *devlink = priv_to_devlink(priv->mdev); + struct devlink *devlink = priv_to_devlink(mlx5e_dev); struct devlink_port_attrs attrs = {}; struct netdev_phys_item_id ppid = {}; struct devlink_port *dl_port; unsigned int dl_port_index; - int ret; if (mlx5_core_is_pf(priv->mdev)) { attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; @@ -42,23 +65,12 @@ int mlx5e_devlink_port_register(struct mlx5e_priv *priv) memset(dl_port, 0, sizeof(*dl_port)); devlink_port_attrs_set(dl_port, &attrs); - if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) - devl_lock(devlink); - ret = devl_port_register(devlink, dl_port, dl_port_index); - if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) - devl_unlock(devlink); - - return ret; + return devlink_port_register(devlink, dl_port, dl_port_index); } void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv) { struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv); - struct devlink *devlink = priv_to_devlink(priv->mdev); - if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) - devl_lock(devlink); - devl_port_unregister(dl_port); - if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) - devl_unlock(devlink); + devlink_port_unregister(dl_port); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h index 4f238d4fff55..19b1d8e9634e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.h @@ -7,7 +7,10 @@ #include #include "en.h" -int mlx5e_devlink_port_register(struct mlx5e_priv *priv); +struct mlx5e_dev *mlx5e_create_devlink(struct device *dev); +void mlx5e_destroy_devlink(struct mlx5e_dev *mlx5e_dev); +int mlx5e_devlink_port_register(struct mlx5e_dev *mlx5e_dev, + struct mlx5e_priv *priv); void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv); static inline struct devlink_port * diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 6bb0fdaa5efa..1e0afaa31dd0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -5876,7 +5876,8 @@ void mlx5e_destroy_netdev(struct mlx5e_priv *priv) static int mlx5e_resume(struct auxiliary_device *adev) { struct mlx5_adev *edev = container_of(adev, struct mlx5_adev, adev); - struct mlx5e_priv *priv = auxiliary_get_drvdata(adev); + struct mlx5e_dev *mlx5e_dev = auxiliary_get_drvdata(adev); + struct mlx5e_priv *priv = mlx5e_dev->priv; struct net_device *netdev = priv->netdev; struct mlx5_core_dev *mdev = edev->mdev; int err; @@ -5899,7 +5900,8 @@ static int mlx5e_resume(struct auxiliary_device *adev) static int mlx5e_suspend(struct auxiliary_device *adev, pm_message_t state) { - struct mlx5e_priv *priv = auxiliary_get_drvdata(adev); + struct mlx5e_dev *mlx5e_dev = auxiliary_get_drvdata(adev); + struct mlx5e_priv *priv = mlx5e_dev->priv; struct net_device *netdev = priv->netdev; struct mlx5_core_dev *mdev = priv->mdev; @@ -5917,21 +5919,28 @@ static int mlx5e_probe(struct auxiliary_device *adev, struct mlx5_adev *edev = container_of(adev, struct mlx5_adev, adev); const struct mlx5e_profile *profile = &mlx5e_nic_profile; struct mlx5_core_dev *mdev = edev->mdev; + struct mlx5e_dev *mlx5e_dev; struct net_device *netdev; pm_message_t state = {}; struct mlx5e_priv *priv; int err; + mlx5e_dev = mlx5e_create_devlink(&adev->dev); + if (IS_ERR(mlx5e_dev)) + return PTR_ERR(mlx5e_dev); + auxiliary_set_drvdata(adev, mlx5e_dev); + netdev = mlx5e_create_netdev(mdev, profile); if (!netdev) { mlx5_core_err(mdev, "mlx5e_create_netdev failed\n"); - return -ENOMEM; + err = -ENOMEM; + goto err_devlink_unregister; } mlx5e_build_nic_netdev(netdev); priv = netdev_priv(netdev); - auxiliary_set_drvdata(adev, priv); + mlx5e_dev->priv = priv; priv->profile = profile; priv->ppriv = NULL; @@ -5939,7 +5948,7 @@ static int mlx5e_probe(struct auxiliary_device *adev, priv->dfs_root = debugfs_create_dir("nic", mlx5_debugfs_get_dev_root(priv->mdev)); - err = mlx5e_devlink_port_register(priv); + err = mlx5e_devlink_port_register(mlx5e_dev, priv); if (err) { mlx5_core_err(mdev, "mlx5e_devlink_port_register failed, %d\n", err); goto err_destroy_netdev; @@ -5978,12 +5987,15 @@ static int mlx5e_probe(struct auxiliary_device *adev, err_destroy_netdev: debugfs_remove_recursive(priv->dfs_root); mlx5e_destroy_netdev(priv); +err_devlink_unregister: + mlx5e_destroy_devlink(mlx5e_dev); return err; } static void mlx5e_remove(struct auxiliary_device *adev) { - struct mlx5e_priv *priv = auxiliary_get_drvdata(adev); + struct mlx5e_dev *mlx5e_dev = auxiliary_get_drvdata(adev); + struct mlx5e_priv *priv = mlx5e_dev->priv; pm_message_t state = {}; mlx5e_dcbnl_delete_app(priv); @@ -5993,6 +6005,7 @@ static void mlx5e_remove(struct auxiliary_device *adev) mlx5e_devlink_port_unregister(priv); debugfs_remove_recursive(priv->dfs_root); mlx5e_destroy_netdev(priv); + mlx5e_destroy_devlink(mlx5e_dev); } static const struct auxiliary_device_id mlx5e_id_table[] = { From patchwork Wed Jan 18 15:21:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106533 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D473EC32793 for ; Wed, 18 Jan 2023 15:24:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbjARPYN (ORCPT ); Wed, 18 Jan 2023 10:24:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbjARPXv (ORCPT ); Wed, 18 Jan 2023 10:23:51 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 824301CAD7 for ; Wed, 18 Jan 2023 07:21:26 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id kt14so25165751ejc.3 for ; Wed, 18 Jan 2023 07:21:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=06eQ4ecK7MZQkmWCPPXkPy1meyk03G3e4fyXRAsTdFs=; b=lrL3RqtzHuANDGCVpcvUi99lxIAh36mLnJxKgLE45X5IxJoRoSOfJo1addphmeOGW6 8LjWpGJKWthMfobysVQDH5NP/rF2UdvNVhkX3Vvrnzr+yEca20W4U7rmc4uZi4wvgODb 88/FtmzEaQpi0L7nxcjxJX/NFNtJmcqoHdbGI7JNCjDrnhKjaI0unAx5+yaYlDbDVpvc yRfOV055V2tG9mAreookG315Bc1p0NEseeucWH8C0YS9MMJDjXF77sSDO6IOYqz6r32A Q27w5QaHLB249XIKF4JXnOJ43jTzZpwqB3cKFAmWrjIMq7tIgI/sJHfhg5DsPotyMHiC /nBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=06eQ4ecK7MZQkmWCPPXkPy1meyk03G3e4fyXRAsTdFs=; b=KiBG5WugC4w9o7GrnIWkvmIvOqkrWfVy7uip1lFI/6xNG1zoPIz1W2H4tVh9WhBm/R ATXPsmQO4ZejvkIw+3FX+E0YY8HwHYzIi0s4ni2BAttxWe9b+SZqnYIWmpA6RHag6rcH f6Fp17gfx0I3jIaNdFMgZnblJdza3WfscKKK594MXCIG022DYzLmmLTRIHHCnazDNQSo 25uFQ9iEOwklA9CaDJPpi7DMHDD6XTBm3Tw1WGKgJ6TDD6T/3Fqj+85TkbvW3GupTuL1 OAgTmCfD2uF5MkVPz7zExpDXswTAe8w0eeebZ+q8ANIe7iH2DTX8cDDTyFEP/7SyOxxv EXkg== X-Gm-Message-State: AFqh2kpLkQS7tYvMJ6nyFUH42rIOzIMqwfE5JJq9dU2SIHk7QECHxxTR 7OCi883gFUoz0pea1USsndfKVJ26zEn4aTwHp3sdFg== X-Google-Smtp-Source: AMrXdXt7uWuL2vv0tf+13Fj9m1fRJEKmwjk5GnvecYAmaUJD8nG1bDZl7wXIdUWa+OKfb1ATdOkZlg== X-Received: by 2002:a17:906:81b:b0:869:a799:1f85 with SMTP id e27-20020a170906081b00b00869a7991f85mr20701560ejd.76.1674055285110; Wed, 18 Jan 2023 07:21:25 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id n12-20020a1709062bcc00b007ae38d837c5sm15152923ejg.174.2023.01.18.07.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:24 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 04/12] net/mlx5: Remove MLX5E_LOCKED_FLOW flag Date: Wed, 18 Jan 2023 16:21:07 +0100 Message-Id: <20230118152115.1113149-5-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The MLX5E_LOCKED_FLOW flag is not checked anywhere now so remove it entirely. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v4->v5: - new patch --- drivers/net/ethernet/mellanox/mlx5/core/dev.c | 14 ++------------ include/linux/mlx5/driver.h | 4 ---- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/dev.c b/drivers/net/ethernet/mellanox/mlx5/core/dev.c index 5b6b0b126e52..2b444fb12388 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/dev.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/dev.c @@ -349,7 +349,6 @@ int mlx5_attach_device(struct mlx5_core_dev *dev) devl_assert_locked(priv_to_devlink(dev)); mutex_lock(&mlx5_intf_mutex); priv->flags &= ~MLX5_PRIV_FLAGS_DETACH; - priv->flags |= MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW; for (i = 0; i < ARRAY_SIZE(mlx5_adev_devices); i++) { if (!priv->adev[i]) { bool is_supported = false; @@ -397,7 +396,6 @@ int mlx5_attach_device(struct mlx5_core_dev *dev) break; } } - priv->flags &= ~MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW; mutex_unlock(&mlx5_intf_mutex); return ret; } @@ -412,7 +410,6 @@ void mlx5_detach_device(struct mlx5_core_dev *dev) devl_assert_locked(priv_to_devlink(dev)); mutex_lock(&mlx5_intf_mutex); - priv->flags |= MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW; for (i = ARRAY_SIZE(mlx5_adev_devices) - 1; i >= 0; i--) { if (!priv->adev[i]) continue; @@ -441,7 +438,6 @@ void mlx5_detach_device(struct mlx5_core_dev *dev) del_adev(&priv->adev[i]->adev); priv->adev[i] = NULL; } - priv->flags &= ~MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW; priv->flags |= MLX5_PRIV_FLAGS_DETACH; mutex_unlock(&mlx5_intf_mutex); } @@ -540,22 +536,16 @@ static void delete_drivers(struct mlx5_core_dev *dev) int mlx5_rescan_drivers_locked(struct mlx5_core_dev *dev) { struct mlx5_priv *priv = &dev->priv; - int err = 0; lockdep_assert_held(&mlx5_intf_mutex); if (priv->flags & MLX5_PRIV_FLAGS_DETACH) return 0; - priv->flags |= MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW; delete_drivers(dev); if (priv->flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV) - goto out; - - err = add_drivers(dev); + return 0; -out: - priv->flags &= ~MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW; - return err; + return add_drivers(dev); } bool mlx5_same_hw_devs(struct mlx5_core_dev *dev, struct mlx5_core_dev *peer_dev) diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index b957b8f22a6b..44167760ff29 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -554,10 +554,6 @@ enum { * creation/deletion on drivers rescan. Unset during device attach. */ MLX5_PRIV_FLAGS_DETACH = 1 << 2, - /* Distinguish between mlx5e_probe/remove called by module init/cleanup - * and called by other flows which can already hold devlink lock - */ - MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW = 1 << 3, }; struct mlx5_adev { From patchwork Wed Jan 18 15:21:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106536 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9399C32793 for ; Wed, 18 Jan 2023 15:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230075AbjARPYT (ORCPT ); Wed, 18 Jan 2023 10:24:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbjARPXv (ORCPT ); Wed, 18 Jan 2023 10:23:51 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 827062C656 for ; Wed, 18 Jan 2023 07:21:28 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id mp20so37469462ejc.7 for ; Wed, 18 Jan 2023 07:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fdu/LMMDVPw+M4xLbPQuOn5+SEPJaDu97WWN+/EPaeo=; b=378BynuS84deh4NaaaV+A0BvTYwmhCtYLrOK1MYwM5SVH5qo/KtP2kYGB+YaBOipBZ svWwu+TkIIoV49Yy78M7MTOH9AX+lgtt7rS+y6aI+j1uf7oX185HdgonIF3IzNt3UlJm ha7SJPx5nye+urpuxhCDnBYRYLioqWGWBtjPk1PI+3irl+oOeHyYJ1PCG2zHSwHqDudi 3d9mkD1rvSnLxGn52PrMhsUSCLjeryjntiTuXjfQeQiEUWJr9B7nzR6MZGinpOvGddsB m14kCYp8jNkRY/yB6XN7o8oQvi1FcNvnp1jmXnl2x8Ots9kNrMKSfdS6Jdj5+m2X/DQ+ eZWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fdu/LMMDVPw+M4xLbPQuOn5+SEPJaDu97WWN+/EPaeo=; b=Yy7Ll7GcBvgEeRbfOaY8X1KGLO1ks+UUDij1WphiZNWlBXRb6NOYox4QzXhiV8GPpD O/wiq6224ET41Sh4QDU6eMRe3d1hbXMd0cW7Pou68yluX5tCRw7IJbBBTNex2u7Z86TD F4GFzKr8PEWJtNXAV2oriGZN3erOGi3AqlPX+4bd05v0kdXfV5HYTXZz5FrwjDoW2KSM NfIopXRLoXK4kDmQXmCOlAD8F7ap30gn1Sztfs+QHMqbZziF3sEUoQ5SSF5Okgu34De6 vpepDGPh61R2qXWPbrQ0E+KOrBe4ltD3i6qr4M2pDsx8967yV0Wo38xgCDK7zIAAk4N1 /3aA== X-Gm-Message-State: AFqh2kpMtTOKqcNJCILeCFpKsVCTqUQZhPqzVL7n7+KRM4oletGMWUxa umLDpOSV8dMwPKGnIVUvxrzMKsXzLUZQZVYVQo5O0Q== X-Google-Smtp-Source: AMrXdXuDSmm4mkJ3zMycxifqtRjAXe6iB3kf8ToLi3phEh6G/gFDLV4Nc7dvlAArwyMzyS84fx7Cpg== X-Received: by 2002:a17:906:1918:b0:7ad:ca80:5669 with SMTP id a24-20020a170906191800b007adca805669mr7695499eje.64.1674055287027; Wed, 18 Jan 2023 07:21:27 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id i12-20020aa7dd0c000000b0047021294426sm14214462edv.90.2023.01.18.07.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:26 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 05/12] devlink: protect health reporter operation with instance lock Date: Wed, 18 Jan 2023 16:21:08 +0100 Message-Id: <20230118152115.1113149-6-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Similar to other devlink objects, protect the reporters list by devlink instance lock. Alongside add unlocked versions of health reporter create/destroy functions and use them in drivers on call paths where the instance lock is held. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v4->v5: - changed mlx5 bits due to changed locking scheme - added locked versions of port reporter create/destroy functions v2->v3: - split from v2 patch #4 - "devlink: remove reporters_lock", no change --- drivers/net/ethernet/mellanox/mlxsw/core.c | 8 +- drivers/net/netdevsim/health.c | 20 ++--- include/net/devlink.h | 22 ++++- net/devlink/leftover.c | 99 +++++++++++++++++----- 4 files changed, 110 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index a0a06e2eff82..33ef726e4d54 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2051,8 +2051,8 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core) if (!(mlxsw_core->bus->features & MLXSW_BUS_F_TXRX)) return 0; - fw_fatal = devlink_health_reporter_create(devlink, &mlxsw_core_health_fw_fatal_ops, - 0, mlxsw_core); + fw_fatal = devl_health_reporter_create(devlink, &mlxsw_core_health_fw_fatal_ops, + 0, mlxsw_core); if (IS_ERR(fw_fatal)) { dev_err(mlxsw_core->bus_info->dev, "Failed to create fw fatal reporter"); return PTR_ERR(fw_fatal); @@ -2072,7 +2072,7 @@ static int mlxsw_core_health_init(struct mlxsw_core *mlxsw_core) err_fw_fatal_config: mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_core_health_listener, mlxsw_core); err_trap_register: - devlink_health_reporter_destroy(mlxsw_core->health.fw_fatal); + devl_health_reporter_destroy(mlxsw_core->health.fw_fatal); return err; } @@ -2085,7 +2085,7 @@ static void mlxsw_core_health_fini(struct mlxsw_core *mlxsw_core) mlxsw_core_trap_unregister(mlxsw_core, &mlxsw_core_health_listener, mlxsw_core); /* Make sure there is no more event work scheduled */ mlxsw_core_flush_owq(); - devlink_health_reporter_destroy(mlxsw_core->health.fw_fatal); + devl_health_reporter_destroy(mlxsw_core->health.fw_fatal); } static void mlxsw_core_irq_event_handler_init(struct mlxsw_core *mlxsw_core) diff --git a/drivers/net/netdevsim/health.c b/drivers/net/netdevsim/health.c index aa77af4a68df..eb04ed715d2d 100644 --- a/drivers/net/netdevsim/health.c +++ b/drivers/net/netdevsim/health.c @@ -233,16 +233,16 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink) int err; health->empty_reporter = - devlink_health_reporter_create(devlink, - &nsim_dev_empty_reporter_ops, - 0, health); + devl_health_reporter_create(devlink, + &nsim_dev_empty_reporter_ops, + 0, health); if (IS_ERR(health->empty_reporter)) return PTR_ERR(health->empty_reporter); health->dummy_reporter = - devlink_health_reporter_create(devlink, - &nsim_dev_dummy_reporter_ops, - 0, health); + devl_health_reporter_create(devlink, + &nsim_dev_dummy_reporter_ops, + 0, health); if (IS_ERR(health->dummy_reporter)) { err = PTR_ERR(health->dummy_reporter); goto err_empty_reporter_destroy; @@ -266,9 +266,9 @@ int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink) return 0; err_dummy_reporter_destroy: - devlink_health_reporter_destroy(health->dummy_reporter); + devl_health_reporter_destroy(health->dummy_reporter); err_empty_reporter_destroy: - devlink_health_reporter_destroy(health->empty_reporter); + devl_health_reporter_destroy(health->empty_reporter); return err; } @@ -278,6 +278,6 @@ void nsim_dev_health_exit(struct nsim_dev *nsim_dev) debugfs_remove_recursive(health->ddir); kfree(health->recovered_break_msg); - devlink_health_reporter_destroy(health->dummy_reporter); - devlink_health_reporter_destroy(health->empty_reporter); + devl_health_reporter_destroy(health->dummy_reporter); + devl_health_reporter_destroy(health->empty_reporter); } diff --git a/include/net/devlink.h b/include/net/devlink.h index d7c9572e5bea..0d64feaef7cb 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1865,18 +1865,34 @@ int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, const void *value, u32 value_len); struct devlink_health_reporter * -devlink_health_reporter_create(struct devlink *devlink, - const struct devlink_health_reporter_ops *ops, - u64 graceful_period, void *priv); +devl_port_health_reporter_create(struct devlink_port *port, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv); struct devlink_health_reporter * devlink_port_health_reporter_create(struct devlink_port *port, const struct devlink_health_reporter_ops *ops, u64 graceful_period, void *priv); +struct devlink_health_reporter * +devl_health_reporter_create(struct devlink *devlink, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv); + +struct devlink_health_reporter * +devlink_health_reporter_create(struct devlink *devlink, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv); + +void +devl_health_reporter_destroy(struct devlink_health_reporter *reporter); + void devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); +void +devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter); + void devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index c92bc04bc25c..0fc374140e6a 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7337,8 +7337,8 @@ __devlink_health_reporter_create(struct devlink *devlink, } /** - * devlink_port_health_reporter_create - create devlink health reporter for - * specified port instance + * devl_port_health_reporter_create - create devlink health reporter for + * specified port instance * * @port: devlink_port which should contain the new reporter * @ops: ops @@ -7346,12 +7346,13 @@ __devlink_health_reporter_create(struct devlink *devlink, * @priv: priv */ struct devlink_health_reporter * -devlink_port_health_reporter_create(struct devlink_port *port, - const struct devlink_health_reporter_ops *ops, - u64 graceful_period, void *priv) +devl_port_health_reporter_create(struct devlink_port *port, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv) { struct devlink_health_reporter *reporter; + devl_assert_locked(port->devlink); mutex_lock(&port->reporters_lock); if (__devlink_health_reporter_find_by_name(&port->reporter_list, &port->reporters_lock, ops->name)) { @@ -7370,10 +7371,26 @@ devlink_port_health_reporter_create(struct devlink_port *port, mutex_unlock(&port->reporters_lock); return reporter; } +EXPORT_SYMBOL_GPL(devl_port_health_reporter_create); + +struct devlink_health_reporter * +devlink_port_health_reporter_create(struct devlink_port *port, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv) +{ + struct devlink_health_reporter *reporter; + struct devlink *devlink = port->devlink; + + devl_lock(devlink); + reporter = devl_port_health_reporter_create(port, ops, + graceful_period, priv); + devl_unlock(devlink); + return reporter; +} EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create); /** - * devlink_health_reporter_create - create devlink health reporter + * devl_health_reporter_create - create devlink health reporter * * @devlink: devlink * @ops: ops @@ -7381,12 +7398,13 @@ EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create); * @priv: priv */ struct devlink_health_reporter * -devlink_health_reporter_create(struct devlink *devlink, - const struct devlink_health_reporter_ops *ops, - u64 graceful_period, void *priv) +devl_health_reporter_create(struct devlink *devlink, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv) { struct devlink_health_reporter *reporter; + devl_assert_locked(devlink); mutex_lock(&devlink->reporters_lock); if (devlink_health_reporter_find_by_name(devlink, ops->name)) { reporter = ERR_PTR(-EEXIST); @@ -7403,6 +7421,21 @@ devlink_health_reporter_create(struct devlink *devlink, mutex_unlock(&devlink->reporters_lock); return reporter; } +EXPORT_SYMBOL_GPL(devl_health_reporter_create); + +struct devlink_health_reporter * +devlink_health_reporter_create(struct devlink *devlink, + const struct devlink_health_reporter_ops *ops, + u64 graceful_period, void *priv) +{ + struct devlink_health_reporter *reporter; + + devl_lock(devlink); + reporter = devl_health_reporter_create(devlink, ops, + graceful_period, priv); + devl_unlock(devlink); + return reporter; +} EXPORT_SYMBOL_GPL(devlink_health_reporter_create); static void @@ -7429,35 +7462,61 @@ __devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) } /** - * devlink_health_reporter_destroy - destroy devlink health reporter + * devl_health_reporter_destroy - destroy devlink health reporter * * @reporter: devlink health reporter to destroy */ void -devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) +devl_health_reporter_destroy(struct devlink_health_reporter *reporter) { struct mutex *lock = &reporter->devlink->reporters_lock; + devl_assert_locked(reporter->devlink); + mutex_lock(lock); __devlink_health_reporter_destroy(reporter); mutex_unlock(lock); } +EXPORT_SYMBOL_GPL(devl_health_reporter_destroy); + +void +devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) +{ + struct devlink *devlink = reporter->devlink; + + devl_lock(devlink); + devl_health_reporter_destroy(reporter); + devl_unlock(devlink); +} EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy); /** - * devlink_port_health_reporter_destroy - destroy devlink port health reporter + * devl_port_health_reporter_destroy - destroy devlink port health reporter * * @reporter: devlink health reporter to destroy */ void -devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter) +devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter) { struct mutex *lock = &reporter->devlink_port->reporters_lock; + devl_assert_locked(reporter->devlink); + mutex_lock(lock); __devlink_health_reporter_destroy(reporter); mutex_unlock(lock); } +EXPORT_SYMBOL_GPL(devl_port_health_reporter_destroy); + +void +devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter) +{ + struct devlink *devlink = reporter->devlink; + + devl_lock(devlink); + devl_port_health_reporter_destroy(reporter); + devl_unlock(devlink); +} EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy); static int @@ -7805,12 +7864,11 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, unsigned long port_index; int idx = 0; + devl_lock(devlink); + if (!devl_is_registered(devlink)) + goto next_devlink; + mutex_lock(&devlink->reporters_lock); - if (!devl_is_registered(devlink)) { - mutex_unlock(&devlink->reporters_lock); - devlink_put(devlink); - continue; - } list_for_each_entry(reporter, &devlink->reporter_list, list) { @@ -7824,6 +7882,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, NLM_F_MULTI); if (err) { mutex_unlock(&devlink->reporters_lock); + devl_unlock(devlink); devlink_put(devlink); state->idx = idx; goto out; @@ -7832,10 +7891,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, } mutex_unlock(&devlink->reporters_lock); - devl_lock(devlink); - if (!devl_is_registered(devlink)) - goto next_devlink; - xa_for_each(&devlink->ports, port_index, port) { mutex_lock(&port->reporters_lock); list_for_each_entry(reporter, &port->reporter_list, list) { From patchwork Wed Jan 18 15:21:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106535 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D19EC38159 for ; Wed, 18 Jan 2023 15:24:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbjARPYQ (ORCPT ); Wed, 18 Jan 2023 10:24:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbjARPXw (ORCPT ); Wed, 18 Jan 2023 10:23:52 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C354222E4 for ; Wed, 18 Jan 2023 07:21:30 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id v6so41058652ejg.6 for ; Wed, 18 Jan 2023 07:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z/WYyDhgWvrQAugwjSVOnozL10LttT+AspbQZ1z+SNw=; b=I4oZ2WT7MZR9mI/2prX40NJUd3DB0x9PM6uoDOyUBCi0unToVaXxJRkLedpX51MRpd KaVi657JOoi2TlZE36wz86z8wXPR/0iu0CGC3TWX+jMRQNLI5+b+1vssYsmrzsQ53AR0 oXeXcrP8Isz/YM1CboVjBzBCRk+imkRfvrp+X9VjoiWWT3Lon+Ix2UdKszyKX3zhgQ5O U8mDZc0bwHj5UJtyOMJ0wjcGV4xlicSLQISNrRGaIySONouAiXyRd3MEsjgkV6UeghRr zZHrspOAe1pAPSdqEVPwh04J0STSwiTEb71m9hp5v4NH00ftkOVOA430ldNxoDwcAKPM e+Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z/WYyDhgWvrQAugwjSVOnozL10LttT+AspbQZ1z+SNw=; b=72Jvneu28YvJ5Rn7UvefRBohFIfyXKjNlkxU0Kj+OVRvILzfckRN15BIyVzqfH6Ye/ h8oFz4VpvrwLRtya46wINdPbg2ipFAgcixvSBoPUZ6eD8NSmTrTpVG9rK+juO5rt+un0 GMCibz1KTvxA2/K1Bs8CoqGwNrRHmczo4sMr3+yVqY7FgK6KHdisGzvdukMQamCpeUV6 V6pdyiNy3Pt6PBvGJQswNJv9JuRSNjki+EdChY3TGnu0JvxCMJRVBITUIstZMa2IZk3K WK40XYUlJp2fcH7wOXCPwplBPjVm7DRnfuQP+wXVBP/hON1PhxqXoU7TYiLOvO9rQvDg xnyw== X-Gm-Message-State: AFqh2kpj2kdyye1d72ioIkZDeVzabsMV2NBFWk6ZpQQeFdr/0eeZbAUY WEoSEoo7K85T+nkxdEd6/1AoCufwsQdjfsv1yXIU/A== X-Google-Smtp-Source: AMrXdXtbbPG8vFhlnbzJIhpwMTT52/Rd5edMqFVZtTXn2B5Uxnc8FvWiw4heFxrUllmJO/d5nDPsxg== X-Received: by 2002:a17:907:cc8a:b0:7ad:d62d:9d31 with SMTP id up10-20020a170907cc8a00b007add62d9d31mr2835303ejc.67.1674055288989; Wed, 18 Jan 2023 07:21:28 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id cf23-20020a170906b2d700b007aef930360asm10395071ejb.59.2023.01.18.07.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:28 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 06/12] devlink: remove reporters_lock Date: Wed, 18 Jan 2023 16:21:09 +0100 Message-Id: <20230118152115.1113149-7-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Similar to other devlink objects, rely on devlink instance lock and remove object specific reporters_lock. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v4->v5: - rebased on top of the mutex destroy fix v2->v3: - split from v2 patch #4 - "devlink: remove reporters_lock", no change --- include/net/devlink.h | 1 - net/devlink/core.c | 2 -- net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 53 +++++++------------------------------ 4 files changed, 9 insertions(+), 48 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 0d64feaef7cb..d9ea76bea36e 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -146,7 +146,6 @@ struct devlink_port { initialized:1; struct delayed_work type_warn_dw; struct list_head reporter_list; - struct mutex reporters_lock; /* Protects reporter_list */ struct devlink_rate *devlink_rate; struct devlink_linecard *linecard; diff --git a/net/devlink/core.c b/net/devlink/core.c index dfc5b58c0464..6c0e2fc57e45 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -246,7 +246,6 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, lockdep_register_key(&devlink->lock_key); mutex_init(&devlink->lock); lockdep_set_class(&devlink->lock, &devlink->lock_key); - mutex_init(&devlink->reporters_lock); refcount_set(&devlink->refcount, 1); return devlink; @@ -268,7 +267,6 @@ void devlink_free(struct devlink *devlink) { ASSERT_DEVLINK_NOT_REGISTERED(devlink); - mutex_destroy(&devlink->reporters_lock); WARN_ON(!list_empty(&devlink->trap_policer_list)); WARN_ON(!list_empty(&devlink->trap_group_list)); WARN_ON(!list_empty(&devlink->trap_list)); diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index dd4e2c37cf07..bdb83014b4b5 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -32,7 +32,6 @@ struct devlink { struct list_head param_list; struct list_head region_list; struct list_head reporter_list; - struct mutex reporters_lock; /* protects reporter_list */ struct devlink_dpipe_headers *dpipe_headers; struct list_head trap_list; struct list_head trap_group_list; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 0fc374140e6a..29e2351ee752 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7281,12 +7281,10 @@ EXPORT_SYMBOL_GPL(devlink_health_reporter_priv); static struct devlink_health_reporter * __devlink_health_reporter_find_by_name(struct list_head *reporter_list, - struct mutex *list_lock, const char *reporter_name) { struct devlink_health_reporter *reporter; - lockdep_assert_held(list_lock); list_for_each_entry(reporter, reporter_list, list) if (!strcmp(reporter->ops->name, reporter_name)) return reporter; @@ -7298,7 +7296,6 @@ devlink_health_reporter_find_by_name(struct devlink *devlink, const char *reporter_name) { return __devlink_health_reporter_find_by_name(&devlink->reporter_list, - &devlink->reporters_lock, reporter_name); } @@ -7307,7 +7304,6 @@ devlink_port_health_reporter_find_by_name(struct devlink_port *devlink_port, const char *reporter_name) { return __devlink_health_reporter_find_by_name(&devlink_port->reporter_list, - &devlink_port->reporters_lock, reporter_name); } @@ -7353,22 +7349,18 @@ devl_port_health_reporter_create(struct devlink_port *port, struct devlink_health_reporter *reporter; devl_assert_locked(port->devlink); - mutex_lock(&port->reporters_lock); + if (__devlink_health_reporter_find_by_name(&port->reporter_list, - &port->reporters_lock, ops->name)) { - reporter = ERR_PTR(-EEXIST); - goto unlock; - } + ops->name)) + return ERR_PTR(-EEXIST); reporter = __devlink_health_reporter_create(port->devlink, ops, graceful_period, priv); if (IS_ERR(reporter)) - goto unlock; + return reporter; reporter->devlink_port = port; list_add_tail(&reporter->list, &port->reporter_list); -unlock: - mutex_unlock(&port->reporters_lock); return reporter; } EXPORT_SYMBOL_GPL(devl_port_health_reporter_create); @@ -7405,20 +7397,16 @@ devl_health_reporter_create(struct devlink *devlink, struct devlink_health_reporter *reporter; devl_assert_locked(devlink); - mutex_lock(&devlink->reporters_lock); - if (devlink_health_reporter_find_by_name(devlink, ops->name)) { - reporter = ERR_PTR(-EEXIST); - goto unlock; - } + + if (devlink_health_reporter_find_by_name(devlink, ops->name)) + return ERR_PTR(-EEXIST); reporter = __devlink_health_reporter_create(devlink, ops, graceful_period, priv); if (IS_ERR(reporter)) - goto unlock; + return reporter; list_add_tail(&reporter->list, &devlink->reporter_list); -unlock: - mutex_unlock(&devlink->reporters_lock); return reporter; } EXPORT_SYMBOL_GPL(devl_health_reporter_create); @@ -7469,13 +7457,9 @@ __devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) void devl_health_reporter_destroy(struct devlink_health_reporter *reporter) { - struct mutex *lock = &reporter->devlink->reporters_lock; - devl_assert_locked(reporter->devlink); - mutex_lock(lock); __devlink_health_reporter_destroy(reporter); - mutex_unlock(lock); } EXPORT_SYMBOL_GPL(devl_health_reporter_destroy); @@ -7498,13 +7482,9 @@ EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy); void devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter) { - struct mutex *lock = &reporter->devlink_port->reporters_lock; - devl_assert_locked(reporter->devlink); - mutex_lock(lock); __devlink_health_reporter_destroy(reporter); - mutex_unlock(lock); } EXPORT_SYMBOL_GPL(devl_port_health_reporter_destroy); @@ -7758,17 +7738,13 @@ devlink_health_reporter_get_from_attrs(struct devlink *devlink, reporter_name = nla_data(attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]); devlink_port = devlink_port_get_from_attrs(devlink, attrs); if (IS_ERR(devlink_port)) { - mutex_lock(&devlink->reporters_lock); reporter = devlink_health_reporter_find_by_name(devlink, reporter_name); if (reporter) refcount_inc(&reporter->refcount); - mutex_unlock(&devlink->reporters_lock); } else { - mutex_lock(&devlink_port->reporters_lock); reporter = devlink_port_health_reporter_find_by_name(devlink_port, reporter_name); if (reporter) refcount_inc(&reporter->refcount); - mutex_unlock(&devlink_port->reporters_lock); } return reporter; @@ -7868,8 +7844,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, if (!devl_is_registered(devlink)) goto next_devlink; - mutex_lock(&devlink->reporters_lock); - list_for_each_entry(reporter, &devlink->reporter_list, list) { if (idx < state->idx) { @@ -7881,7 +7855,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI); if (err) { - mutex_unlock(&devlink->reporters_lock); devl_unlock(devlink); devlink_put(devlink); state->idx = idx; @@ -7889,10 +7862,8 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, } idx++; } - mutex_unlock(&devlink->reporters_lock); xa_for_each(&devlink->ports, port_index, port) { - mutex_lock(&port->reporters_lock); list_for_each_entry(reporter, &port->reporter_list, list) { if (idx < state->idx) { idx++; @@ -7904,7 +7875,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI); if (err) { - mutex_unlock(&port->reporters_lock); devl_unlock(devlink); devlink_put(devlink); state->idx = idx; @@ -7912,7 +7882,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, } idx++; } - mutex_unlock(&port->reporters_lock); } next_devlink: devl_unlock(devlink); @@ -9633,12 +9602,9 @@ int devl_port_register(struct 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); err = xa_insert(&devlink->ports, port_index, devlink_port, GFP_KERNEL); - if (err) { - mutex_destroy(&devlink_port->reporters_lock); + if (err) return err; - } INIT_DELAYED_WORK(&devlink_port->type_warn_dw, &devlink_port_type_warn); devlink_port_type_warn_schedule(devlink_port); @@ -9689,7 +9655,6 @@ void devl_port_unregister(struct devlink_port *devlink_port) devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_DEL); xa_erase(&devlink_port->devlink->ports, devlink_port->index); WARN_ON(!list_empty(&devlink_port->reporter_list)); - mutex_destroy(&devlink_port->reporters_lock); devlink_port->registered = false; } EXPORT_SYMBOL_GPL(devl_port_unregister); From patchwork Wed Jan 18 15:21:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106534 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14C3EC38147 for ; Wed, 18 Jan 2023 15:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbjARPYP (ORCPT ); Wed, 18 Jan 2023 10:24:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbjARPXw (ORCPT ); Wed, 18 Jan 2023 10:23:52 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3720E234C8 for ; Wed, 18 Jan 2023 07:21:32 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id qx13so25687460ejb.13 for ; Wed, 18 Jan 2023 07:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7+v+ljnAZIqf6DLtGNKKMGQkrRt/mSk8P4aJZcppwUk=; b=LEWVSnCOR/jup7H/fbvl3OWRmQMbNYP2JimhQELcE4UvD+nSYwAGno12PbzMmfmdCo CG/3yAq2sDPbC/aCmFh9cZjB+EMzL/G8iroJ1DjnnHCr09uQVzbSjiAtpaY4nQ71C2KU y6d/QBZQKrs2+fZJxbmJR/irW6saU/O5BYzDC/3swkiv8hFlrwP7eMqtQjeb/l3llfWp m5iZgVm10KMg4v7Agoefri71WL5fzv6pLBApxCdpu+WBxt/Hd0qejPnQdQfYZyq0oIvR UlDEOnNvi5SBWfUc4nHo3a3sNPoftrfyzPnu7k60i0+oBWCH1NxuHmPRjZ/qsaEuMxdl jioQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7+v+ljnAZIqf6DLtGNKKMGQkrRt/mSk8P4aJZcppwUk=; b=IViXEdnJSMKwWQpaDLrV7MYUDRvvggXZI3/7tlLSPHsmIs8JV9WxrCD42viSrAgB5W E/28m96CiXuOgtFcENK+pgZqwK198/Wpx4ecLxRz1xe4yMDBXqw5n6tLRFW6AX1qgRJo 0vV+Nm8MgaWpF/pNv2aBFOBFFU/iQOgLlHyQ4SbeDpQWfzGVxCYXF/lcIkDHL/7GBn0I ilGUqLNadbNJC73j3eBJiQQGHaKFXrrl3YYKm16qR5Ex4Yam70QS8a5HcnFSFFgSfneh ToZD+OKajjD9/OoHM1ng8xC3lGQkYViivEyfK3TXe830xdb3M8X8ubmnxM/ukOEaOLUl vMXA== X-Gm-Message-State: AFqh2krJ2ESJ8CV5yo95lfbww/RJAaCPQSxxIJKJIK8cEy5d18xgNKJb HpeR9LRDP4vrqG38iVoqPadkVastl16tCrxaEYscbA== X-Google-Smtp-Source: AMrXdXt1WycGvX3CU2HE01MeUyhyWYy6nP+LyiuMok9h8F6BV0Dzils7JtmcBUyHqok1un4pGYQVgw== X-Received: by 2002:a17:906:71a:b0:7c1:6344:84a with SMTP id y26-20020a170906071a00b007c16344084amr7440961ejb.5.1674055290796; Wed, 18 Jan 2023 07:21:30 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id ss5-20020a170907038500b00856ad9108e7sm10594967ejb.70.2023.01.18.07.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:30 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 07/12] devlink: remove devl*_port_health_reporter_destroy() Date: Wed, 18 Jan 2023 16:21:10 +0100 Message-Id: <20230118152115.1113149-8-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Remove port-specific health reporter destroy function as it is currently the same as the instance one so no longer needed. Inline __devlink_health_reporter_destroy() as it is no longer called from multiple places. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v4->v5: - changed mlx5 bits a bit due to changed locking scheme - added removal of locked port reporter destroy function v2->v3: - split from v2 patch #4 - "devlink: remove reporters_lock", no change --- .../mellanox/mlx5/core/en/reporter_rx.c | 2 +- .../mellanox/mlx5/core/en/reporter_tx.c | 2 +- include/net/devlink.h | 6 ---- net/devlink/leftover.c | 35 ++----------------- 4 files changed, 4 insertions(+), 41 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c index 1ae15b8536a8..95edab4a1732 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c @@ -754,6 +754,6 @@ void mlx5e_reporter_rx_destroy(struct mlx5e_priv *priv) if (!priv->rx_reporter) return; - devlink_port_health_reporter_destroy(priv->rx_reporter); + devlink_health_reporter_destroy(priv->rx_reporter); priv->rx_reporter = NULL; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c index 60bc5b577ab9..b195dbbf6c90 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c @@ -609,6 +609,6 @@ void mlx5e_reporter_tx_destroy(struct mlx5e_priv *priv) if (!priv->tx_reporter) return; - devlink_port_health_reporter_destroy(priv->tx_reporter); + devlink_health_reporter_destroy(priv->tx_reporter); priv->tx_reporter = NULL; } diff --git a/include/net/devlink.h b/include/net/devlink.h index d9ea76bea36e..608a0c198be8 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1889,12 +1889,6 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter); void devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); -void -devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter); - -void -devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter); - void * devlink_health_reporter_priv(struct devlink_health_reporter *reporter); int devlink_health_report(struct devlink_health_reporter *reporter, diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 29e2351ee752..a56dd70a10e0 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7442,13 +7442,6 @@ devlink_health_reporter_put(struct devlink_health_reporter *reporter) devlink_health_reporter_free(reporter); } -static void -__devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) -{ - list_del(&reporter->list); - devlink_health_reporter_put(reporter); -} - /** * devl_health_reporter_destroy - destroy devlink health reporter * @@ -7459,7 +7452,8 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter) { devl_assert_locked(reporter->devlink); - __devlink_health_reporter_destroy(reporter); + list_del(&reporter->list); + devlink_health_reporter_put(reporter); } EXPORT_SYMBOL_GPL(devl_health_reporter_destroy); @@ -7474,31 +7468,6 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) } EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy); -/** - * devl_port_health_reporter_destroy - destroy devlink port health reporter - * - * @reporter: devlink health reporter to destroy - */ -void -devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter) -{ - devl_assert_locked(reporter->devlink); - - __devlink_health_reporter_destroy(reporter); -} -EXPORT_SYMBOL_GPL(devl_port_health_reporter_destroy); - -void -devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter) -{ - struct devlink *devlink = reporter->devlink; - - devl_lock(devlink); - devl_port_health_reporter_destroy(reporter); - devl_unlock(devlink); -} -EXPORT_SYMBOL_GPL(devlink_port_health_reporter_destroy); - static int devlink_nl_health_reporter_fill(struct sk_buff *msg, struct devlink_health_reporter *reporter, From patchwork Wed Jan 18 15:21:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106537 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60323C38147 for ; Wed, 18 Jan 2023 15:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbjARPYU (ORCPT ); Wed, 18 Jan 2023 10:24:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbjARPXx (ORCPT ); Wed, 18 Jan 2023 10:23:53 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C0711A970 for ; Wed, 18 Jan 2023 07:21:34 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id u19so84003167ejm.8 for ; Wed, 18 Jan 2023 07:21:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e+HKDcAyKjTAUcx44xJMfm/g/IX8ETh/jVwJCpJOZwM=; b=F3q6qMK7ca7srBEeXipzyKgO+2AzX2v38VLPB6gdhG8AIqVNvc8Bi5hN6nJy8vZrVt hwZKEbO0pcCAGmF2ql0FwDxv9fd4doYR22mSf4HgWmV4FXc9Cy1cuWXs/TPtPf0fb2Jt f/vH5IQmqLwrFgJv2nPczZeV4adqRFekfeRB0jrwopWyQ8OR51oPlQUy6JWlFj628eH7 mPVL7Jb/sO0lyvrDtmt/Vl+0Tc6kC/qSXfUAkBZlAx+e0tTZTALe1wNsb/Wb9eIDvDvt 3QJOkJC1QoSFzpjqgq8CAJa8DrI3Cct/upiv9Xl3gANYJl8UJ6AJVzDW/dy+d9ZF82Ma lSbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e+HKDcAyKjTAUcx44xJMfm/g/IX8ETh/jVwJCpJOZwM=; b=1enck8SljOYbe4/96l+J7qgpgS1Ebh1csavl66nfgMgxLKRvNDZeCVbV6babSopfVe MaI/IbI5VS67q2RFpo83dfsDzS1vpnBXErrPAJKjSbv4xU9wx0bKpwNQcQl+lWtYtVnw BJY3LuuuozDeryPlOqWPju7AYWJq1j4Z9yP/Jm6AZcmmoz5XAicxNBGh+yqVfuj0iXPC VxbXAW6xSU/sCQyLnUoND8JYBvei+IpzFqIgXvvHZww4OQGv79uhP0XedcfnF9TPxrxr Y8qkAY8l3mRDh6yZBms5lijY6yqa+1MvsSdmQ/XyQYA8uQ7P2MI1ZEoWsVu85fCgJSRG FhSg== X-Gm-Message-State: AFqh2ko/LDKSA1kPXSJ8ClYRVFrGZevxVZghYCW1EUhDcAW/ANr+E9AI eKxAsOXflWc01AMPlcjiafFAbEd6eCw/XpHZ7rb5Xg== X-Google-Smtp-Source: AMrXdXvObJeie/U1dOWYet/cYR27BoafEW5mYZ3cpk0p48CcVnTvEtQ4d3j5mDMOgEsRxCZn0VpkKQ== X-Received: by 2002:a17:907:6d21:b0:805:1e6e:6777 with SMTP id sa33-20020a1709076d2100b008051e6e6777mr27949408ejc.23.1674055292726; Wed, 18 Jan 2023 07:21:32 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id 11-20020a170906300b00b008675df83251sm7865548ejz.34.2023.01.18.07.21.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:32 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 08/12] devlink: remove reporter reference counting Date: Wed, 18 Jan 2023 16:21:11 +0100 Message-Id: <20230118152115.1113149-9-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko As long as the reporter life time is protected by devlink instance lock, the reference counting is no longer needed. Remove it. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v2->v3 - fixed typo in patch description --- net/devlink/leftover.c | 113 +++++++++++------------------------------ 1 file changed, 30 insertions(+), 83 deletions(-) diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index a56dd70a10e0..70eebf4a61c8 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7269,7 +7269,6 @@ struct devlink_health_reporter { u64 error_count; u64 recovery_count; u64 last_recovery_ts; - refcount_t refcount; }; void * @@ -7328,7 +7327,6 @@ __devlink_health_reporter_create(struct devlink *devlink, reporter->auto_recover = !!ops->recover; reporter->auto_dump = !!ops->dump; mutex_init(&reporter->dump_lock); - refcount_set(&reporter->refcount, 1); return reporter; } @@ -7435,13 +7433,6 @@ devlink_health_reporter_free(struct devlink_health_reporter *reporter) kfree(reporter); } -static void -devlink_health_reporter_put(struct devlink_health_reporter *reporter) -{ - if (refcount_dec_and_test(&reporter->refcount)) - devlink_health_reporter_free(reporter); -} - /** * devl_health_reporter_destroy - destroy devlink health reporter * @@ -7453,7 +7444,7 @@ devl_health_reporter_destroy(struct devlink_health_reporter *reporter) devl_assert_locked(reporter->devlink); list_del(&reporter->list); - devlink_health_reporter_put(reporter); + devlink_health_reporter_free(reporter); } EXPORT_SYMBOL_GPL(devl_health_reporter_destroy); @@ -7697,7 +7688,6 @@ static struct devlink_health_reporter * devlink_health_reporter_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) { - struct devlink_health_reporter *reporter; struct devlink_port *devlink_port; char *reporter_name; @@ -7706,17 +7696,12 @@ devlink_health_reporter_get_from_attrs(struct devlink *devlink, reporter_name = nla_data(attrs[DEVLINK_ATTR_HEALTH_REPORTER_NAME]); devlink_port = devlink_port_get_from_attrs(devlink, attrs); - if (IS_ERR(devlink_port)) { - reporter = devlink_health_reporter_find_by_name(devlink, reporter_name); - if (reporter) - refcount_inc(&reporter->refcount); - } else { - reporter = devlink_port_health_reporter_find_by_name(devlink_port, reporter_name); - if (reporter) - refcount_inc(&reporter->refcount); - } - - return reporter; + if (IS_ERR(devlink_port)) + return devlink_health_reporter_find_by_name(devlink, + reporter_name); + else + return devlink_port_health_reporter_find_by_name(devlink_port, + reporter_name); } static struct devlink_health_reporter * @@ -7775,10 +7760,8 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, return -EINVAL; msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - err = -ENOMEM; - goto out; - } + if (!msg) + return -ENOMEM; err = devlink_nl_health_reporter_fill(msg, reporter, DEVLINK_CMD_HEALTH_REPORTER_GET, @@ -7786,13 +7769,10 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, 0); if (err) { nlmsg_free(msg); - goto out; + return err; } - err = genlmsg_reply(msg, info); -out: - devlink_health_reporter_put(reporter); - return err; + return genlmsg_reply(msg, info); } static int @@ -7866,7 +7846,6 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, { struct devlink *devlink = info->user_ptr[0]; struct devlink_health_reporter *reporter; - int err; reporter = devlink_health_reporter_get_from_info(devlink, info); if (!reporter) @@ -7874,15 +7853,12 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, if (!reporter->ops->recover && (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] || - info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])) { - err = -EOPNOTSUPP; - goto out; - } + info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER])) + return -EOPNOTSUPP; + if (!reporter->ops->dump && - info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]) { - err = -EOPNOTSUPP; - goto out; - } + info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]) + return -EOPNOTSUPP; if (info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD]) reporter->graceful_period = @@ -7896,11 +7872,7 @@ devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, reporter->auto_dump = nla_get_u8(info->attrs[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP]); - devlink_health_reporter_put(reporter); return 0; -out: - devlink_health_reporter_put(reporter); - return err; } static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb, @@ -7908,16 +7880,12 @@ static int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb, { struct devlink *devlink = info->user_ptr[0]; struct devlink_health_reporter *reporter; - int err; reporter = devlink_health_reporter_get_from_info(devlink, info); if (!reporter) return -EINVAL; - err = devlink_health_reporter_recover(reporter, NULL, info->extack); - - devlink_health_reporter_put(reporter); - return err; + return devlink_health_reporter_recover(reporter, NULL, info->extack); } static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, @@ -7932,36 +7900,27 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, if (!reporter) return -EINVAL; - if (!reporter->ops->diagnose) { - devlink_health_reporter_put(reporter); + if (!reporter->ops->diagnose) return -EOPNOTSUPP; - } fmsg = devlink_fmsg_alloc(); - if (!fmsg) { - devlink_health_reporter_put(reporter); + if (!fmsg) return -ENOMEM; - } err = devlink_fmsg_obj_nest_start(fmsg); if (err) - goto out; + return err; err = reporter->ops->diagnose(reporter, fmsg, info->extack); if (err) - goto out; + return err; err = devlink_fmsg_obj_nest_end(fmsg); if (err) - goto out; - - err = devlink_fmsg_snd(fmsg, info, - DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0); + return err; -out: - devlink_fmsg_free(fmsg); - devlink_health_reporter_put(reporter); - return err; + return devlink_fmsg_snd(fmsg, info, + DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, 0); } static int @@ -7976,10 +7935,9 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, if (!reporter) return -EINVAL; - if (!reporter->ops->dump) { - err = -EOPNOTSUPP; - goto out; - } + if (!reporter->ops->dump) + return -EOPNOTSUPP; + mutex_lock(&reporter->dump_lock); if (!state->idx) { err = devlink_health_do_dump(reporter, NULL, cb->extack); @@ -7997,8 +7955,6 @@ devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb, DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET); unlock: mutex_unlock(&reporter->dump_lock); -out: - devlink_health_reporter_put(reporter); return err; } @@ -8013,15 +7969,12 @@ devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb, if (!reporter) return -EINVAL; - if (!reporter->ops->dump) { - devlink_health_reporter_put(reporter); + if (!reporter->ops->dump) return -EOPNOTSUPP; - } mutex_lock(&reporter->dump_lock); devlink_health_dump_clear(reporter); mutex_unlock(&reporter->dump_lock); - devlink_health_reporter_put(reporter); return 0; } @@ -8030,21 +7983,15 @@ static int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb, { struct devlink *devlink = info->user_ptr[0]; struct devlink_health_reporter *reporter; - int err; reporter = devlink_health_reporter_get_from_info(devlink, info); if (!reporter) return -EINVAL; - if (!reporter->ops->test) { - devlink_health_reporter_put(reporter); + if (!reporter->ops->test) return -EOPNOTSUPP; - } - - err = reporter->ops->test(reporter, info->extack); - devlink_health_reporter_put(reporter); - return err; + return reporter->ops->test(reporter, info->extack); } struct devlink_stats { From patchwork Wed Jan 18 15:21:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106538 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C20CBC32793 for ; Wed, 18 Jan 2023 15:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbjARPYV (ORCPT ); Wed, 18 Jan 2023 10:24:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231184AbjARPXx (ORCPT ); Wed, 18 Jan 2023 10:23:53 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21B892387F for ; Wed, 18 Jan 2023 07:21:36 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id v13so15974659eda.11 for ; Wed, 18 Jan 2023 07:21:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zATwc450yXsToqEuc8W2qcmYj93ecT95/D0Oxce2p+w=; b=TZAcz3OdMJ4AP/XI9KREtLebgQ0Rz0vBK0qgOSBIzHLTIOUTuOgXENv1IIGXMePISW BUdYJbw9LQlVWhE0t0aWZUbhlxj8ujAE6ONITYHzWXmBfyV4QB5K0KiGrisfpkfr52gT W/8Y4Vf2rKR7xEc+AMaLz8m7XXEg0e4CEO2B5ZTQ6Aa89e+EkI1TIV1k+1koeDyRNgCX HuRz2HH4NE5krDEH4hsND/e4V8H/LY5x0Y12Oqxg04mfYKNaoAYiOFFWBR84c7OsRwsM ZQ+CD1PFqSKqB7pj7HOc6paeJnl8n9zsSMOe1bIex4wRbJGYafYNUMlEyrvriULgTJCX 8MSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zATwc450yXsToqEuc8W2qcmYj93ecT95/D0Oxce2p+w=; b=OhhDYmegO721xrEFV3ss0XfacxjwUSnqgXq3T/YspDpSoserYGBKbVa6+1o68MUKIc 6wO7ByZZyxjZ3snvsy+JcXWHULbAUu05NQ+3SqLiBxamOa7juu1ZdpjcsZGyhmD5uC9W Kwh1VM+NRrtPcRX5P/hDgPd3MyAsI5u8OCA6SVF8F0up8Omu+XC+MWoITJOowFQAm7Sd JvE35Qx0hnhFaGNSuXAo6FinBEykFCIGTwhQ8XtvQYujzsa7OMByXdunHrV3o6w4e1k8 jSSTipyKOviGJ36qbOmk+DaPxmS9Y8OLr+TktrKCboY+aTqJ6zlE21YDR1e65eqljyp3 EsKA== X-Gm-Message-State: AFqh2kqJGDMq/fEVJVGFMc3TxOtwT8xNJRShaajpHOQ4ukLm932En2b7 TZjNxjliVdAdQX5/dPYrPryGNKQgExnkAwwAgTn06Q== X-Google-Smtp-Source: AMrXdXvvH0QcbgYgMgfhQ9I5LdIbp9OMxyysUd2r3G96JZnbAIkpPYgaAu3BG6bWhPflLBy+ak4xWw== X-Received: by 2002:a05:6402:2b97:b0:479:ab7d:1dad with SMTP id fj23-20020a0564022b9700b00479ab7d1dadmr7909400edb.32.1674055294605; Wed, 18 Jan 2023 07:21:34 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id cq22-20020a056402221600b00499703df898sm12404976edb.69.2023.01.18.07.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:34 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 09/12] devlink: convert linecards dump to devlink_nl_instance_iter_dump() Date: Wed, 18 Jan 2023 16:21:12 +0100 Message-Id: <20230118152115.1113149-10-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Benefit from recently introduced instance iteration and convert linecards .dumpit generic netlink callback to use it. Signed-off-by: Jiri Pirko Reviewed-by: Ido Schimmel Reviewed-by: Jacob Keller --- net/devlink/devl_internal.h | 1 + net/devlink/leftover.c | 64 ++++++++++++++++--------------------- net/devlink/netlink.c | 1 + 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index bdb83014b4b5..d8f8e4bff5b4 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -167,6 +167,7 @@ extern const struct devlink_gen_cmd devl_gen_info; extern const struct devlink_gen_cmd devl_gen_trap; extern const struct devlink_gen_cmd devl_gen_trap_group; extern const struct devlink_gen_cmd devl_gen_trap_policer; +extern const struct devlink_gen_cmd devl_gen_linecard; /* Ports */ int devlink_port_netdevice_event(struct notifier_block *nb, diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 70eebf4a61c8..8bb4c2710688 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -2105,50 +2105,42 @@ static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, return genlmsg_reply(msg, info); } -static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) +static int devlink_nl_cmd_linecard_get_dump_one(struct sk_buff *msg, + struct devlink *devlink, + struct netlink_callback *cb) { struct devlink_nl_dump_state *state = devlink_dump_state(cb); struct devlink_linecard *linecard; - struct devlink *devlink; - int err; - - devlink_dump_for_each_instance_get(msg, state, devlink) { - int idx = 0; - - devl_lock(devlink); - if (!devl_is_registered(devlink)) - goto next_devlink; + int idx = 0; + int err = 0; - list_for_each_entry(linecard, &devlink->linecard_list, list) { - if (idx < state->idx) { - idx++; - continue; - } - mutex_lock(&linecard->state_lock); - err = devlink_nl_linecard_fill(msg, devlink, linecard, - DEVLINK_CMD_LINECARD_NEW, - NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, - NLM_F_MULTI, - cb->extack); - mutex_unlock(&linecard->state_lock); - if (err) { - devl_unlock(devlink); - devlink_put(devlink); - state->idx = idx; - goto out; - } + list_for_each_entry(linecard, &devlink->linecard_list, list) { + if (idx < state->idx) { idx++; + continue; } -next_devlink: - devl_unlock(devlink); - devlink_put(devlink); + mutex_lock(&linecard->state_lock); + err = devlink_nl_linecard_fill(msg, devlink, linecard, + DEVLINK_CMD_LINECARD_NEW, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + NLM_F_MULTI, + cb->extack); + mutex_unlock(&linecard->state_lock); + if (err) { + state->idx = idx; + break; + } + idx++; } -out: - return msg->len; + + return err; } +const struct devlink_gen_cmd devl_gen_linecard = { + .dump_one = devlink_nl_cmd_linecard_get_dump_one, +}; + static struct devlink_linecard_type * devlink_linecard_type_lookup(struct devlink_linecard *linecard, const char *type) @@ -9010,7 +9002,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { { .cmd = DEVLINK_CMD_LINECARD_GET, .doit = devlink_nl_cmd_linecard_get_doit, - .dumpit = devlink_nl_cmd_linecard_get_dumpit, + .dumpit = devlink_nl_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, /* can be retrieved by unprivileged users */ }, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 3f2ab4360f11..b18e216e09b0 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -191,6 +191,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = { [DEVLINK_CMD_TRAP_GET] = &devl_gen_trap, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_gen_trap_group, [DEVLINK_CMD_TRAP_POLICER_GET] = &devl_gen_trap_policer, + [DEVLINK_CMD_LINECARD_GET] = &devl_gen_linecard, [DEVLINK_CMD_SELFTESTS_GET] = &devl_gen_selftests, }; From patchwork Wed Jan 18 15:21:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106539 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25824C32793 for ; Wed, 18 Jan 2023 15:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbjARPYZ (ORCPT ); Wed, 18 Jan 2023 10:24:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjARPXx (ORCPT ); Wed, 18 Jan 2023 10:23:53 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF4648580 for ; Wed, 18 Jan 2023 07:21:37 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id bk15so26555732ejb.9 for ; Wed, 18 Jan 2023 07:21:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T2vGRu8XUhbE4fgFydtufsYQZylZVxI3gUDWpNsQ2rQ=; b=gC8nAdpOZuc7OeLzjrYICzaLce1t89M8Z9DpzixVIJZcYRSrllCrGguAyhrjfXgj13 fePX2auvlSEehpPNXQe/x+lM4W2p1P6qJFYyMBPnJW/dzIidwhlXcTR8uPCYeTPR436G XYeqNasyK+Qm/6jqk2sKF4/cc450c9PxcPi2iR8u5OY1u+8UE1jbG3wAC1k9w5pluQaT DfxkRF5z3bEFE5ap3ysDSPiTL9fn9vhrPwMAAkCOp0OC80WAfv6lWH3EH17IbNOzyA90 jDV51rJY8BAN0XUGZrjB7bth6SQg41KyT2btApjv1QyZXwjWcIiSLm+8Jsrooj5HFrnT daog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T2vGRu8XUhbE4fgFydtufsYQZylZVxI3gUDWpNsQ2rQ=; b=dgaEvrHwCTVcJ2DTNJkrcUCT7o+1WKCqVEtHYXsAYi9ed9Zaid+XbZc9rMWQMTijef p2wgjM7WOWS5d/Y3wKqYUZWYD4K8Ees8cTyYJrjyIcxX5VrV9heckOUj1XqY2Qh4/NO2 EhHbDwq1DNmUgi5hdoxEhTLbCsOnv/QY8NUhQTjXlFhpSkhYSBuwIL7J0/YITEntoKqP tf0vQkV1C79FApJ7Z7TV+w/ScSfjlw0TBzeAYAEl4nsYAtnp2Oqz3SsgD/WvkX9MNWwl PIYfRgn5RADPCQSMsKFNxlLp67AuW16VARhadJMULxKclhcpkXu2+EH2DED3NneMAQM6 cN2g== X-Gm-Message-State: AFqh2kq++ae0jtWoetgFeWJSXCCNTFWBJoYDMitZ4Z7vBKoHFFivXdgC tL8vxBqpKgKHlAnQb8NZByhCy/qWESkKIIPQ5tHkNw== X-Google-Smtp-Source: AMrXdXsmcvg2zoS+toF5JN1JcjoTiVi81iqbIyZrwG43vOBMVsWzkOWBJxyzn7ZW0TnxHJFzuT9R8w== X-Received: by 2002:a17:907:8b08:b0:860:c12c:14fd with SMTP id sz8-20020a1709078b0800b00860c12c14fdmr8216482ejc.76.1674055296485; Wed, 18 Jan 2023 07:21:36 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id n4-20020a170906164400b007c11e5ac250sm15084956ejd.91.2023.01.18.07.21.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:35 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 10/12] devlink: convert reporters dump to devlink_nl_instance_iter_dump() Date: Wed, 18 Jan 2023 16:21:13 +0100 Message-Id: <20230118152115.1113149-11-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Benefit from recently introduced instance iteration and convert reporters .dumpit generic netlink callback to use it. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v1->v2: - unsquashed the next patch (devlink: remove devlink_dump_for_each_instance_get() helper) from this one --- net/devlink/devl_internal.h | 1 + net/devlink/leftover.c | 87 ++++++++++++++++--------------------- net/devlink/netlink.c | 1 + 3 files changed, 40 insertions(+), 49 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index d8f8e4bff5b4..10975e4ea2f4 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -164,6 +164,7 @@ extern const struct devlink_gen_cmd devl_gen_selftests; extern const struct devlink_gen_cmd devl_gen_param; extern const struct devlink_gen_cmd devl_gen_region; extern const struct devlink_gen_cmd devl_gen_info; +extern const struct devlink_gen_cmd devl_gen_health_reporter; extern const struct devlink_gen_cmd devl_gen_trap; extern const struct devlink_gen_cmd devl_gen_trap_group; extern const struct devlink_gen_cmd devl_gen_trap_policer; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 8bb4c2710688..2825995704c4 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7768,70 +7768,59 @@ static int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, } static int -devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) +devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg, + struct devlink *devlink, + struct netlink_callback *cb) { struct devlink_nl_dump_state *state = devlink_dump_state(cb); - struct devlink *devlink; + struct devlink_health_reporter *reporter; + struct devlink_port *port; + unsigned long port_index; + int idx = 0; int err; - devlink_dump_for_each_instance_get(msg, state, devlink) { - struct devlink_health_reporter *reporter; - struct devlink_port *port; - unsigned long port_index; - int idx = 0; - - devl_lock(devlink); - if (!devl_is_registered(devlink)) - goto next_devlink; - - list_for_each_entry(reporter, &devlink->reporter_list, - list) { + list_for_each_entry(reporter, &devlink->reporter_list, list) { + if (idx < state->idx) { + idx++; + continue; + } + err = devlink_nl_health_reporter_fill(msg, reporter, + DEVLINK_CMD_HEALTH_REPORTER_GET, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + NLM_F_MULTI); + if (err) { + state->idx = idx; + return err; + } + idx++; + } + xa_for_each(&devlink->ports, port_index, port) { + list_for_each_entry(reporter, &port->reporter_list, list) { if (idx < state->idx) { idx++; continue; } - err = devlink_nl_health_reporter_fill( - msg, reporter, DEVLINK_CMD_HEALTH_REPORTER_GET, - NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, - NLM_F_MULTI); + err = devlink_nl_health_reporter_fill(msg, reporter, + DEVLINK_CMD_HEALTH_REPORTER_GET, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + NLM_F_MULTI); if (err) { - devl_unlock(devlink); - devlink_put(devlink); state->idx = idx; - goto out; + return err; } idx++; } - - xa_for_each(&devlink->ports, port_index, port) { - list_for_each_entry(reporter, &port->reporter_list, list) { - if (idx < state->idx) { - idx++; - continue; - } - err = devlink_nl_health_reporter_fill( - msg, reporter, - DEVLINK_CMD_HEALTH_REPORTER_GET, - NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, NLM_F_MULTI); - if (err) { - devl_unlock(devlink); - devlink_put(devlink); - state->idx = idx; - goto out; - } - idx++; - } - } -next_devlink: - devl_unlock(devlink); - devlink_put(devlink); } -out: - return msg->len; + + return 0; } +const struct devlink_gen_cmd devl_gen_health_reporter = { + .dump_one = devlink_nl_cmd_health_reporter_get_dump_one, +}; + static int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, struct genl_info *info) @@ -9193,7 +9182,7 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_health_reporter_get_doit, - .dumpit = devlink_nl_cmd_health_reporter_get_dumpit, + .dumpit = devlink_nl_instance_iter_dump, .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT, /* can be retrieved by unprivileged users */ }, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index b18e216e09b0..d4539c1aedea 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -187,6 +187,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = { [DEVLINK_CMD_PARAM_GET] = &devl_gen_param, [DEVLINK_CMD_REGION_GET] = &devl_gen_region, [DEVLINK_CMD_INFO_GET] = &devl_gen_info, + [DEVLINK_CMD_HEALTH_REPORTER_GET] = &devl_gen_health_reporter, [DEVLINK_CMD_RATE_GET] = &devl_gen_rate_get, [DEVLINK_CMD_TRAP_GET] = &devl_gen_trap, [DEVLINK_CMD_TRAP_GROUP_GET] = &devl_gen_trap_group, From patchwork Wed Jan 18 15:21:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106541 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5002C38159 for ; Wed, 18 Jan 2023 15:25:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjARPZC (ORCPT ); Wed, 18 Jan 2023 10:25:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbjARPXy (ORCPT ); Wed, 18 Jan 2023 10:23:54 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393CA4859D for ; Wed, 18 Jan 2023 07:21:38 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id u19so84003890ejm.8 for ; Wed, 18 Jan 2023 07:21:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HpNdatRerecj0n8ypH1v/511GR4bTe0lvpgJSEFGqsE=; b=ghhkqrGCWLu1nYIsGVHNpmk+W1fm/FU4o/Ten1G77QtHlOoxmYqcLs3qPLGKSpTvSn Gj8W0SRkC4go0eKMdASzXneSotM49qH4nudakGUv70A/UbJnrKnMjx5ddBeERk2jeTNu WtBLwazn2pi6jF2glJ99V4gH5itI0Qt4HKhoFMI4GQJ4ja6TWeHK05JlOhrrSDtobMT3 b+mpvKmGn+XcWrOarxVJL/Pckj4JykYdLGJa745VGb9+CMQo4cDQryawy0n/GIG+XPGE NVJb430iqKo0qohBZuJ7Uvi0cu8MUC1Nh4h+FOdKORPYe6ZS0BnGr6fMvs0oVCknNxiM PVCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HpNdatRerecj0n8ypH1v/511GR4bTe0lvpgJSEFGqsE=; b=N0d4IZQkqzXl98G72DDIz25fCwboQnDXTjB1yqkw4sxHBIGbcc/i7j4QIVux/cawwK 8+6brY3aSk1p3HIAv4mLICcwKBXcu5olFP3WPHF1AjAiseysVobkonETW1MfTYQKevln R/i7NjsCBXVzfZnY6gcYlN77uvjpfUInP6bcyxekMfwHKcFRam83aTxr/5Y3b++Roy7s VStLQWOnBPhois5XT9/ySeQ9M8xfsvBSwKzSqAkRhyrXA4/2sBjZmagII65bEFiWB7mT Vze/FtwDaoNbDpjAppAc2eJAljK0NU4skiDkzZsvVOLcVRfd8nv3PzIavBDNEVvucTW/ X2og== X-Gm-Message-State: AFqh2kpDU/SzvtrLoZOIRBEe2yGbNxcrEf1KBVw332HJG5Y5bl8IlhqI SqZnX+sOG/XYyKnP7yS3QTZ9ueIn3dFlNpUE4HwjjQ== X-Google-Smtp-Source: AMrXdXsSiTKIxMjbclQsL5lYqVXLqm1y6W6K73wL13iNhO1LVQ7el5fYSZE1SlKkrZuAD2/T7novEQ== X-Received: by 2002:a17:907:20f6:b0:84d:21b2:735a with SMTP id rh22-20020a17090720f600b0084d21b2735amr7573325ejb.54.1674055298465; Wed, 18 Jan 2023 07:21:38 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id 17-20020a170906059100b007933047f923sm14806691ejn.118.2023.01.18.07.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:37 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 11/12] devlink: remove devlink_dump_for_each_instance_get() helper Date: Wed, 18 Jan 2023 16:21:14 +0100 Message-Id: <20230118152115.1113149-12-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko devlink_dump_for_each_instance_get() is currently called from a single place in netlink.c. As there is no need to use this helper anywhere else in the future, remove it and call devlinks_xa_find_get() directly from while loop in devlink_nl_instance_iter_dump(). Also remove redundant idx clear on loop end as it is already done in devlink_nl_instance_iter_dump(). Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- v1->v2: new patch, unsquashed from the previous one --- net/devlink/devl_internal.h | 11 ----------- net/devlink/netlink.c | 5 ++++- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 10975e4ea2f4..75752f8c4a26 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -123,17 +123,6 @@ struct devlink_gen_cmd { struct netlink_callback *cb); }; -/* Iterate over registered devlink instances for devlink dump. - * devlink_put() needs to be called for each iterated devlink pointer - * in loop body in order to release the reference. - * Note: this is NOT a generic iterator, it makes assumptions about the use - * of @state and can only be used once per dumpit implementation. - */ -#define devlink_dump_for_each_instance_get(msg, state, devlink) \ - for (; (devlink = devlinks_xa_find_get(sock_net(msg->sk), \ - &state->instance)); \ - state->instance++, state->idx = 0) - extern const struct genl_small_ops devlink_nl_ops[56]; struct devlink * diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index d4539c1aedea..3f44633af01c 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -207,7 +207,8 @@ int devlink_nl_instance_iter_dump(struct sk_buff *msg, cmd = devl_gen_cmds[info->op.cmd]; - devlink_dump_for_each_instance_get(msg, state, devlink) { + while ((devlink = devlinks_xa_find_get(sock_net(msg->sk), + &state->instance))) { devl_lock(devlink); if (devl_is_registered(devlink)) @@ -221,6 +222,8 @@ int devlink_nl_instance_iter_dump(struct sk_buff *msg, if (err) break; + state->instance++; + /* restart sub-object walk for the next instance */ state->idx = 0; } From patchwork Wed Jan 18 15:21:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13106540 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C169C32793 for ; Wed, 18 Jan 2023 15:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231142AbjARPYw (ORCPT ); Wed, 18 Jan 2023 10:24:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231259AbjARPXz (ORCPT ); Wed, 18 Jan 2023 10:23:55 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00D7D49958 for ; Wed, 18 Jan 2023 07:21:41 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id vm8so84027146ejc.2 for ; Wed, 18 Jan 2023 07:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F3D2rOW0PtnstTqBQ9TFwrlqB8EOa2WTC5VIOo9/5xE=; b=Wrv2nft2StJMF4BfDHMiuDIZ7YwztmYYPAglLab9B6+yfxUHaQpYbLo24Nk8+8Wud1 8H3CecBX2YMkFR/uGgX5bcIcrydhVnIrPfxDwa5VZHqpKxQakVpNgnhxJnnH+bTazDf+ tGAOq9HQXwO7NtBfwfmIgzxN4+wdXEM221els/SbfAiRHibWL3bYG4VilnHxfJq7mAZC lgkCQFOOZq5y/K4m0HfSqNOkYxE+jOYeYP77govBR3wSWoeQO600qEMkdW7+MaJIk2bl i5lY4hWD5MqTKCFbq7sM6dcBEOxu/Yb+JnDEVNHSrHO/o7YTA6T19hBSPHIBMO0kUdPp jHZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F3D2rOW0PtnstTqBQ9TFwrlqB8EOa2WTC5VIOo9/5xE=; b=DtJqX4G+xIV8DbsUgXY7xoTwqOiQjlTQ7HhCGQDjkBkytVjv3qWBgI3ijdfxc33vDj UpLTSIZA3FiM3b+46PtnNxZZrWmxAIcm5KI5zGfsUFnV/yvqFpNw6/R4RzOwxrYwAKrO qXCD/8w/RgeXFEAHUgLuaYDkepMmLt4zXTizwUl9RJxw3ww2yAz0smsLpYPZ25xda81Y wFlMPlX67r7249aPOn2DeVR7+MaxiEtPvdM6DowMVWOHH52YWPZy2dUTvUoGi6QxnheZ pyZwvBJBKQjE738Vn85+DPEU1Ek8z1jrM41oCmQENtpF3iV+d8YqqIcsdsON2o65mZrD fUCw== X-Gm-Message-State: AFqh2kppoIX0QAZooh+gaFoDdWKkUlociSOUCPrYfJ4RUo+lJZMNxrFM 3n5HbntRKUfLFjWcvpbyNDgOInsR+eE7q9c8QugEwg== X-Google-Smtp-Source: AMrXdXsSKouW2ZisPh8+mtmTzxJ8CrdTdCJpKXYCgo8pYXjSWZzqH6eq3g5lAWeaI0o2VFuQV0uftA== X-Received: by 2002:a17:906:78b:b0:7c1:9b07:32cd with SMTP id l11-20020a170906078b00b007c19b0732cdmr7540415ejc.39.1674055300490; Wed, 18 Jan 2023 07:21:40 -0800 (PST) Received: from localhost ([217.111.27.204]) by smtp.gmail.com with ESMTPSA id d9-20020a1709063ec900b0084c2065b388sm14690462ejj.128.2023.01.18.07.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 07:21:39 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, michael.chan@broadcom.com, yisen.zhuang@huawei.com, salil.mehta@huawei.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, idosch@nvidia.com, petrm@nvidia.com, mailhol.vincent@wanadoo.fr, jacob.e.keller@intel.com, gal@nvidia.com Subject: [patch net-next v5 12/12] devlink: add instance lock assertion in devl_is_registered() Date: Wed, 18 Jan 2023 16:21:15 +0100 Message-Id: <20230118152115.1113149-13-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118152115.1113149-1-jiri@resnulli.us> References: <20230118152115.1113149-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko After region and linecard lock removals, this helper is always supposed to be called with instance lock held. So put the assertion here and remove the comment which is no longer accurate. Signed-off-by: Jiri Pirko Reviewed-by: Jacob Keller --- net/devlink/devl_internal.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 75752f8c4a26..1aa1a9549549 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -85,9 +85,7 @@ struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp); static inline bool devl_is_registered(struct devlink *devlink) { - /* To prevent races the caller must hold the instance lock - * or another lock taken during unregistration. - */ + devl_assert_locked(devlink); return xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED); }