From patchwork Mon Jan 9 18:31: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: 13094088 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 D66B8C61DB3 for ; Mon, 9 Jan 2023 18:34:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234274AbjAISeR (ORCPT ); Mon, 9 Jan 2023 13:34:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237839AbjAISdp (ORCPT ); Mon, 9 Jan 2023 13:33:45 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07FFC625EF for ; Mon, 9 Jan 2023 10:31:28 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id d3so10434657plr.10 for ; Mon, 09 Jan 2023 10:31: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=eWkxqf51DO6fZmJLuJRCa74hPSD79ZonPX0qO1z4n1M=; b=X1uv5fyNIUHB33GYQJSZXzBN8X+XjxVVjYdXtHJbw6IUNGOYNLIOV6M/YjOc37oqT8 GRb4tNosLx1ldWssQMXKc+MIZlCbj1x5jKdqDuHpgEwAIVJg6hAZoUnxc1w/v/nhnYmD kAURoImpawt4tsto1yOLIobiIOiS8ckwFO156RQmux/hebCcDr7X4AcbAgb28wYAts3k egpBupjbbIHYFjR0MdKgBXuk83tJ/R+sUOjpYTCyRAoLTTbflYXGxLLMdTzS4NBGvY5g OCJ9r6WwPvEddfucRKenIai04pBG/+V8EH8adGWpsh/EjFTDJJGjPt60bD1M0DG1MRqB wCDA== 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=eWkxqf51DO6fZmJLuJRCa74hPSD79ZonPX0qO1z4n1M=; b=tzdjv+LJkXV7E79IcweI9I6AeoJBfvhmPttqu/tb1tsFbp0MYR8w60S5FTHHbH3K5c seRZJXHA/JNiPZcO4ykr29ejw27v/dzeZf3mlm+9NEjvaE0en+UfgC5x331V7siTFrNF qYDQsaxh2zm21JyCnje9rRFdJBIhFCxkLn6Ly7ypBYI/SWabfgChxpvM+8HjkVhmKccW K9vFfLo3sbmMIAN9f1WBQR0WQO0o6pfJAdaI93wgRqTJIp7UmDMi7Zb7psi0eD+1gMBk 2uCmBVTZvJHr845o5F1k2cKrUJWSkK+Q2VGnGaX/rtemEZssillfOcpbzpkmixEaqCPX +S4g== X-Gm-Message-State: AFqh2kpvAvqLchdqvsiZCYUpytCHbh6qZAIh2PqZ2Xrg0e1bLec6YX/k Sxp4Cqf/mrjq1qG8e4cGp72rGLIGg7DEKCodt4NGRQ== X-Google-Smtp-Source: AMrXdXvTGlfTzqiin8u3+VML9eWPa6qxH7FAbq4iNXkzIvsDRM2zPlRMBRUoMePUOjJV0A2u83UHfQ== X-Received: by 2002:a17:902:b407:b0:192:bdf8:1a58 with SMTP id x7-20020a170902b40700b00192bdf81a58mr27596081plr.50.1673289087923; Mon, 09 Jan 2023 10:31:27 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id s17-20020a170902c65100b001927ebc40e2sm6409718pls.193.2023.01.09.10.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:27 -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 v3 01/11] devlink: remove devlink features Date: Mon, 9 Jan 2023 19:31:10 +0100 Message-Id: <20230109183120.649825-2-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 features were introduced to disallow devlink reload calls of userspace before the devlink was fully initialized. The reason for this workaround was the fact that devlink reload was originally called without devlink instance lock held. However, with recent changes that converted devlink reload to be performed under devlink instance lock, this is redundant so remove devlink features entirely. Note that mlx5 used this to enable devlink reload conditionally only when device didn't act as multi port slave. Move the multi port check into mlx5_devlink_reload_down() callback alongside with the other checks preventing the device from reload in certain states. Signed-off-by: Jiri Pirko --- v2->v3: - removed devlink_set_features() prototype from include/net/devlink.h --- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 1 - .../hisilicon/hns3/hns3pf/hclge_devlink.c | 1 - .../hisilicon/hns3/hns3vf/hclgevf_devlink.c | 1 - drivers/net/ethernet/intel/ice/ice_devlink.c | 1 - drivers/net/ethernet/mellanox/mlx4/main.c | 1 - .../net/ethernet/mellanox/mlx5/core/devlink.c | 9 +++++---- drivers/net/ethernet/mellanox/mlxsw/core.c | 1 - drivers/net/netdevsim/dev.c | 1 - include/net/devlink.h | 2 +- net/devlink/core.c | 19 ------------------- net/devlink/devl_internal.h | 1 - net/devlink/leftover.c | 3 --- 12 files changed, 6 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c index 26913dc816d3..8b3e7697390f 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c @@ -1303,7 +1303,6 @@ int bnxt_dl_register(struct bnxt *bp) if (rc) goto err_dl_port_unreg; - devlink_set_features(dl, DEVLINK_F_RELOAD); out: devlink_register(dl); return 0; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c index 3d3b69605423..9a939c0b217f 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c @@ -114,7 +114,6 @@ int hclge_devlink_init(struct hclge_dev *hdev) priv->hdev = hdev; hdev->devlink = devlink; - devlink_set_features(devlink, DEVLINK_F_RELOAD); devlink_register(devlink); return 0; } diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c index a6c3c5e8f0ab..1b535142c65a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_devlink.c @@ -116,7 +116,6 @@ int hclgevf_devlink_init(struct hclgevf_dev *hdev) priv->hdev = hdev; hdev->devlink = devlink; - devlink_set_features(devlink, DEVLINK_F_RELOAD); devlink_register(devlink); return 0; } diff --git a/drivers/net/ethernet/intel/ice/ice_devlink.c b/drivers/net/ethernet/intel/ice/ice_devlink.c index 8286e47b4bae..026f65a4e4ca 100644 --- a/drivers/net/ethernet/intel/ice/ice_devlink.c +++ b/drivers/net/ethernet/intel/ice/ice_devlink.c @@ -1376,7 +1376,6 @@ void ice_devlink_register(struct ice_pf *pf) { struct devlink *devlink = priv_to_devlink(pf); - devlink_set_features(devlink, DEVLINK_F_RELOAD); devlink_register(devlink); } diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index 3ae246391549..5e7736be2091 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -4031,7 +4031,6 @@ static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id) goto err_params_unregister; pci_save_state(pdev); - devlink_set_features(devlink, DEVLINK_F_RELOAD); devl_unlock(devlink); devlink_register(devlink); return 0; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c index 5bd83c0275f8..67bc3ade273a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c @@ -156,6 +156,11 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change, return -EOPNOTSUPP; } + if (mlx5_core_is_mp_slave(dev)) { + NL_SET_ERR_MSG_MOD(extack, "reload is unsupported for multi port slave"); + return -EOPNOTSUPP; + } + if (pci_num_vf(pdev)) { NL_SET_ERR_MSG_MOD(extack, "reload while VFs are present is unfavorable"); } @@ -871,7 +876,6 @@ void mlx5_devlink_traps_unregister(struct devlink *devlink) int mlx5_devlink_register(struct devlink *devlink) { - struct mlx5_core_dev *dev = devlink_priv(devlink); int err; err = devlink_params_register(devlink, mlx5_devlink_params, @@ -889,9 +893,6 @@ int mlx5_devlink_register(struct devlink *devlink) if (err) goto max_uc_list_err; - if (!mlx5_core_is_mp_slave(dev)) - devlink_set_features(devlink, DEVLINK_F_RELOAD); - return 0; max_uc_list_err: diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index a0a06e2eff82..0b791706a9c1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2211,7 +2211,6 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, } if (!reload) { - devlink_set_features(devlink, DEVLINK_F_RELOAD); devl_unlock(devlink); devlink_register(devlink); } diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 738784fda117..35a0fb683801 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1609,7 +1609,6 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev) goto err_hwstats_exit; nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY; - devlink_set_features(devlink, DEVLINK_F_RELOAD); devl_unlock(devlink); return 0; diff --git a/include/net/devlink.h b/include/net/devlink.h index 425ecef431b7..8460b53bb2f6 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1646,7 +1646,7 @@ static inline struct devlink *devlink_alloc(const struct devlink_ops *ops, { return devlink_alloc_ns(ops, priv_size, &init_net, dev); } -void devlink_set_features(struct devlink *devlink, u64 features); + int devl_register(struct devlink *devlink); void devl_unregister(struct devlink *devlink); void devlink_register(struct devlink *devlink); diff --git a/net/devlink/core.c b/net/devlink/core.c index a31a317626d7..4014a01c8f3d 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -114,23 +114,6 @@ struct devlink *devlinks_xa_find_get(struct net *net, unsigned long *indexp) goto retry; } -/** - * devlink_set_features - Set devlink supported features - * - * @devlink: devlink - * @features: devlink support features - * - * This interface allows us to set reload ops separatelly from - * the devlink_alloc. - */ -void devlink_set_features(struct devlink *devlink, u64 features) -{ - WARN_ON(features & DEVLINK_F_RELOAD && - !devlink_reload_supported(devlink->ops)); - devlink->features = features; -} -EXPORT_SYMBOL_GPL(devlink_set_features); - /** * devl_register - Register devlink instance * @devlink: devlink @@ -297,7 +280,6 @@ static void __net_exit devlink_pernet_pre_exit(struct net *net) * all devlink instances from this namespace into init_net. */ devlinks_xa_for_each_registered_get(net, index, devlink) { - WARN_ON(!(devlink->features & DEVLINK_F_RELOAD)); devl_lock(devlink); err = 0; if (devl_is_registered(devlink)) @@ -307,7 +289,6 @@ static void __net_exit devlink_pernet_pre_exit(struct net *net) &actions_performed, NULL); devl_unlock(devlink); devlink_put(devlink); - if (err && err != -EOPNOTSUPP) pr_warn("Failed to reload devlink instance into init_net\n"); } diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 5d2bbe295659..82268c4579a3 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -39,7 +39,6 @@ struct devlink { struct list_head linecard_list; struct mutex linecards_lock; /* protects linecard_list */ const struct devlink_ops *ops; - u64 features; struct xarray snapshot_ids; struct devlink_dev_stats stats; struct device *dev; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 1e23b2da78cc..478b81b85f03 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -4429,9 +4429,6 @@ static int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info) u32 actions_performed; int err; - if (!(devlink->features & DEVLINK_F_RELOAD)) - return -EOPNOTSUPP; - err = devlink_resources_validate(devlink, NULL, info); if (err) { NL_SET_ERR_MSG_MOD(info->extack, "resources size validation failed"); From patchwork Mon Jan 9 18:31: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: 13094089 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 01A1DC678D5 for ; Mon, 9 Jan 2023 18:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230190AbjAISes (ORCPT ); Mon, 9 Jan 2023 13:34:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237849AbjAISdr (ORCPT ); Mon, 9 Jan 2023 13:33:47 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE57467BD2 for ; Mon, 9 Jan 2023 10:31:31 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id l1-20020a17090a384100b00226f05b9595so8598524pjf.0 for ; Mon, 09 Jan 2023 10:31:31 -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=SGF504jET0eLcfUiRzawl8U7ZjNHFb03NLMmjzaEEcg=; b=vVNbtl5gsxo/2O7OsFRcgW+mzfAlFBSE9KgTnxOfFkCizzV+RVxEGoLEKMlH47YWOV JVhqXervkM2rb4Q47UVkaVh9ULOHuyEAi7lZupKbbXBYOsdiY+cJzKV2jsviBqVWj98A uyG98XhQOh8NO7wuWyay052ZuQ6dbg16VtKHM09v3UR6xSZMb3V82tA9PGYOEv9cbJJg 7uZgpfRNEyq3NQjHKsJfM0e5zjnAaX9AJPrL12NEOFKsYhTqmouEJvjb6gyMJ98CjQjW pTo/rLpmbeTSXy5qc59oyuep3Bi2rtIYK38HRZktk/MDM0QEoOTa0bQ19uWAkJazqYF4 rlpA== 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=SGF504jET0eLcfUiRzawl8U7ZjNHFb03NLMmjzaEEcg=; b=jWvWsA2/lIhP3iD/NFIPUAJmbCpdTZ53dYT/EY0sSoorFvAWe9ZhLVy/KiyZlr5gnh nz1bCPfHtCy6EGvgjxpU2xw+jOBynaAe0krkI3JB82SbalRXs8vKtjp2CQ6v/W86EPkv JJJlRkXrtbx9gw640P58ABDlffRmgrg7fKMmNdD8f/HtSYwm41ijUBDTtQC/2RVVIHb0 6i8y/4IPvTBMfUm52FcO0dKRIOwQ08ZzzfDxczOlukptMa57P1abODc7Y9Tz3iYTlZ/7 SIBa6Fh3IpfHp0XhFxnQof/i03VqHTuTn2ERki27G1tuoVaVyKDoRvg6Qjm9Jqz7DuvF QuGw== X-Gm-Message-State: AFqh2krc1DCxUB8MfSyVKCT/4pJS5rHidlZbMWHhEESKibBojcQOw1vF K+uFHjxe0GSJO12kKWvOgEx3k896OXVB+0JOQOwnsA== X-Google-Smtp-Source: AMrXdXtzqZ/HBvvRK2MtyTdS+7COQMAiwSwTPWCzapNZZvBk3pLUTezN1EMqILogwOtBItsx5aDQnQ== X-Received: by 2002:a17:903:110d:b0:189:89e2:5406 with SMTP id n13-20020a170903110d00b0018989e25406mr112263752plh.24.1673289091415; Mon, 09 Jan 2023 10:31:31 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id w6-20020a170902e88600b00189e7cb8b89sm6414869plg.127.2023.01.09.10.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31: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 v3 02/11] devlink: remove linecards lock Date: Mon, 9 Jan 2023 19:31:11 +0100 Message-Id: <20230109183120.649825-3-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 8460b53bb2f6..7c1e47fe4f4b 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 4014a01c8f3d..d223a46fe557 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -218,7 +218,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; @@ -240,7 +239,6 @@ void devlink_free(struct devlink *devlink) { ASSERT_DEVLINK_NOT_REGISTERED(devlink); - mutex_destroy(&devlink->linecards_lock); mutex_destroy(&devlink->reporters_lock); mutex_destroy(&devlink->lock); lockdep_unregister_key(&devlink->lock_key); diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 82268c4579a3..ca49ad31027c 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -37,7 +37,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; struct xarray snapshot_ids; struct devlink_dev_stats stats; diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 478b81b85f03..4b01b15f8659 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: @@ -10225,7 +10222,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 @@ -10238,8 +10235,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; @@ -10248,17 +10245,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; @@ -10271,35 +10264,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 Mon Jan 9 18:31: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: 13094093 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 E5885C7112F for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237511AbjAISfE (ORCPT ); Mon, 9 Jan 2023 13:35:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237855AbjAISdt (ORCPT ); Mon, 9 Jan 2023 13:33:49 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F48C5C90F for ; Mon, 9 Jan 2023 10:31:35 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id jl4so10445676plb.8 for ; Mon, 09 Jan 2023 10:31:35 -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=WGH2umzstJcoUIftcaNq/0Cr9ZzBsFWtZGJU7pf21kY=; b=Uj9p43JqJqS3UGrbfc84MGNMQ/9vdkY9t6FmW3CU2al1czv3l4CfSfn8TFd2cfbqWj kOcb5wSwUh68U0NLXqHY457OSHmsEIbvBMBtgxMB+bYP1ixXU/1ODgU1uGeiWk2c3sxZ fHFsT/x1Wn3hCuUrri5JicMTsevfdnzNL9VPhv7sauQqkEaifoLz2YKFB0AQEVcbi4hS guWp+0HA0PmQNXJb7EHg02CdMGbuwt4dBg78EYBxRURg/ILgP8BM99OmzMECke0BCSEt 7t3yFmZYgb6IbmVwrz64vxprVdtUwysHZyGU0sLy8RkfR+ud5ITMu2IVKQEcHD7sOe/F QVhw== 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=WGH2umzstJcoUIftcaNq/0Cr9ZzBsFWtZGJU7pf21kY=; b=R3y+aXx/doZWUMHpgJp86gtUTuAf4M5caWNsIhAAxDBet7/RrxeM9rwQo0L7bOEkOj +nvpyEu5uh2M8ZD8VPcvg/e065OnhLZKyzslycerGQzVvoNrTV6QGHNz1IlpB96n+CzN Ubmo9ONtMS1hYOgOCtummSaTuWAG+uNmI1HdGgyn8vRrv8YZXwAB9WmJkTL0ozGqFZ5Q N1ci7racpjifIs/FtB5GJFmUMUljqgU8TRsP1ocJbr7eRmGsWbrXinzOej8jUFe0C4wb +mxK+MTmUXIUcEkgJhtYWpfTgJHtrYeBckxzeDsx6cWofYvYndunodNQMb2EdnGxjCUI /UvQ== X-Gm-Message-State: AFqh2kpWEQkmiB0mqStnEP9bNf3xwpzq2M4lRUnFkWtHh+D4brVlTjYL vzR7V1H0jiMZMSndarDa35u3vsX3ltoAxkhIH1CGjQ== X-Google-Smtp-Source: AMrXdXs+VRsaXG0kG3XIR78h+KXJWOhq0JiOwSB+Yx7a598nHrkRJnMH1Bb9wsUAQlyFuvcQPO/FBA== X-Received: by 2002:a17:902:6bc6:b0:192:c36c:f115 with SMTP id m6-20020a1709026bc600b00192c36cf115mr27323265plt.66.1673289094934; Mon, 09 Jan 2023 10:31:34 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id s6-20020a170902ea0600b001913c5fc051sm6411804plg.274.2023.01.09.10.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31: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 v3 03/11] devlink: remove linecard reference counting Date: Mon, 9 Jan 2023 19:31:12 +0100 Message-Id: <20230109183120.649825-4-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 ca49ad31027c..61c707c4f9a3 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -191,7 +191,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 4b01b15f8659..2208711b4b18 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; @@ -10268,7 +10258,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; } @@ -10284,7 +10273,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 Mon Jan 9 18:31: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: 13094094 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 C6F2DC678DF for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237711AbjAISfA (ORCPT ); Mon, 9 Jan 2023 13:35:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237859AbjAISdt (ORCPT ); Mon, 9 Jan 2023 13:33:49 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B2C21B1DC for ; Mon, 9 Jan 2023 10:31:39 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id v23so5545018plo.1 for ; Mon, 09 Jan 2023 10:31:39 -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=Sz9hOjaOb59wSDgFcaYe1lturEOo+/ZnCL76oiExNDU=; b=VjBx3d2OQUk9KXJBwRnWE4pXdpAJDEl1W0ctO+Z/MMeQE3w0jQufWA0QAzMcy38443 aIYOhwCyadKCn2P6HfcdRatKAggDJObpwXcU8cNng9GeVEEHvQJBwOQ/IuUTFN/V0ohD ADzCyOhzSwEidikRCpeRSqmDaSDe57Kir5pfWq/n10XUvdFSHsVLX2xCDbVrqq8Ty7OG j6IWgY8xXzvrhgfTk283m0fik0EaD7LHZSY75br7P1/BXVqx6YzvvB2C3hBVqXiDC88s 3SXxUtCHZA17ZqMYrneqTf2Dq6K4QPxJa3J3NP3mpT1anHeTXSnFSCuthHCnLY8DGhcn VnZw== 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=Sz9hOjaOb59wSDgFcaYe1lturEOo+/ZnCL76oiExNDU=; b=aA66bpovG9+xKIqSJAjmiY7dXMoPTN9cbkXk++5ZyW1t3o5KrNJaJe6NrNzRF9g9D0 WWietVjk9yJiW9fOl9gge1fNvl88yVH0RUoQ6rbmruH//kKvOBBe6T8jmC1usqbS/43g raHbhPq80vWRPsSZ9OI+Pngdm0Z+7xYeqxQZTRw2CYHg53ryJfahULo13RU8wFw/0NML xwM0yVdxMVBaNTbA+cN3lBAyj21sdk7FUxDP72TCNo4MRbuA2dz1krqe6UxUkH4tq4ZO 15t5ojl4kI9qGQPH3ucyuP8tl8/xvkSphTSck9HxEgblHBQxA+bLboF0ShcjbamKBGf9 GFQw== X-Gm-Message-State: AFqh2kpqbAEZCYV+Bcv5M5EzLK2EnszeTSyOaidt0Wh7qUn3zSvW4k9t Nx2vfNkOOzlBi28oWo7r0OEZKFfAa0VtdVTdoI616A== X-Google-Smtp-Source: AMrXdXt7lKNGFTrKieJFHHKgMLPs71XZmWhOd16DOozfvh/rDW4Iz97JDvxqS3shFDAB74BH6dEkTg== X-Received: by 2002:a17:902:aa4a:b0:193:1aa7:c7d9 with SMTP id c10-20020a170902aa4a00b001931aa7c7d9mr7772270plr.44.1673289098408; Mon, 09 Jan 2023 10:31:38 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id 13-20020a170902c20d00b00189c4b8ca21sm6510144pll.18.2023.01.09.10.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31: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 v3 04/11] devlink: protect health reporter operation with instance lock Date: Mon, 9 Jan 2023 19:31:13 +0100 Message-Id: <20230109183120.649825-5-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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: Ido Schimmel --- v2->v3: - split from v2 patch #4 - "devlink: remove reporters_lock", no change --- .../ethernet/mellanox/mlx5/core/en/health.c | 12 +++ .../mellanox/mlx5/core/en/reporter_rx.c | 6 +- .../mellanox/mlx5/core/en/reporter_tx.c | 6 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 8 +- drivers/net/netdevsim/health.c | 20 ++--- include/net/devlink.h | 18 +++-- net/devlink/leftover.c | 76 +++++++++++++------ 7 files changed, 97 insertions(+), 49 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/health.c b/drivers/net/ethernet/mellanox/mlx5/core/en/health.c index 6f4e6c34b2a2..acc4b1ebdfb8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/health.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/health.c @@ -137,14 +137,26 @@ int mlx5e_health_eq_diag_fmsg(struct mlx5_eq_comp *eq, struct devlink_fmsg *fmsg void mlx5e_health_create_reporters(struct mlx5e_priv *priv) { + struct devlink *devlink = priv_to_devlink(priv->mdev); + + if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) + devl_lock(devlink); mlx5e_reporter_tx_create(priv); mlx5e_reporter_rx_create(priv); + if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) + devl_unlock(devlink); } void mlx5e_health_destroy_reporters(struct mlx5e_priv *priv) { + struct devlink *devlink = priv_to_devlink(priv->mdev); + + if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) + devl_lock(devlink); mlx5e_reporter_rx_destroy(priv); mlx5e_reporter_tx_destroy(priv); + if (!(priv->mdev->priv.flags & MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW)) + devl_unlock(devlink); } void mlx5e_health_channels_update(struct mlx5e_priv *priv) 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..cdd4d2d0c876 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c @@ -739,8 +739,8 @@ void mlx5e_reporter_rx_create(struct mlx5e_priv *priv) struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv); struct devlink_health_reporter *reporter; - reporter = devlink_port_health_reporter_create(dl_port, &mlx5_rx_reporter_ops, - MLX5E_REPORTER_RX_GRACEFUL_PERIOD, priv); + reporter = devl_port_health_reporter_create(dl_port, &mlx5_rx_reporter_ops, + MLX5E_REPORTER_RX_GRACEFUL_PERIOD, priv); if (IS_ERR(reporter)) { netdev_warn(priv->netdev, "Failed to create rx reporter, err = %ld\n", PTR_ERR(reporter)); @@ -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); + devl_port_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..ad24958f7a44 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c @@ -593,8 +593,8 @@ void mlx5e_reporter_tx_create(struct mlx5e_priv *priv) struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv); struct devlink_health_reporter *reporter; - reporter = devlink_port_health_reporter_create(dl_port, &mlx5_tx_reporter_ops, - MLX5_REPORTER_TX_GRACEFUL_PERIOD, priv); + reporter = devl_port_health_reporter_create(dl_port, &mlx5_tx_reporter_ops, + MLX5_REPORTER_TX_GRACEFUL_PERIOD, priv); if (IS_ERR(reporter)) { netdev_warn(priv->netdev, "Failed to create tx reporter, err = %ld\n", @@ -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); + devl_port_health_reporter_destroy(priv->tx_reporter); priv->tx_reporter = NULL; } diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 0b791706a9c1..ab07db99eeb3 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 7c1e47fe4f4b..8b0e63f7f49e 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1864,21 +1864,29 @@ int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name, int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, const void *value, u32 value_len); +struct devlink_health_reporter * +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 * +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); -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); +void +devl_health_reporter_destroy(struct devlink_health_reporter *reporter); void devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); void -devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter); +devl_port_health_reporter_destroy(struct devlink_health_reporter *reporter); void * devlink_health_reporter_priv(struct devlink_health_reporter *reporter); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 2208711b4b18..023c6c6b5f8a 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7334,8 +7334,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 @@ -7343,12 +7343,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)) { @@ -7367,10 +7368,10 @@ devlink_port_health_reporter_create(struct devlink_port *port, mutex_unlock(&port->reporters_lock); return reporter; } -EXPORT_SYMBOL_GPL(devlink_port_health_reporter_create); +EXPORT_SYMBOL_GPL(devl_port_health_reporter_create); /** - * devlink_health_reporter_create - create devlink health reporter + * devl_health_reporter_create - create devlink health reporter * * @devlink: devlink * @ops: ops @@ -7378,12 +7379,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); @@ -7400,6 +7402,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 @@ -7426,36 +7443,51 @@ __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(devlink_port_health_reporter_destroy); +EXPORT_SYMBOL_GPL(devl_port_health_reporter_destroy); static int devlink_nl_health_reporter_fill(struct sk_buff *msg, @@ -7802,12 +7834,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) { @@ -7821,6 +7852,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; @@ -7829,10 +7861,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 Mon Jan 9 18:31: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: 13094095 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 D63D4C678DE for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237286AbjAISfB (ORCPT ); Mon, 9 Jan 2023 13:35:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237863AbjAISdu (ORCPT ); Mon, 9 Jan 2023 13:33:50 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B379625FB for ; Mon, 9 Jan 2023 10:31:42 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id e10so6481108pgc.9 for ; Mon, 09 Jan 2023 10:31:42 -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=bUsQyYY1/hLbs2LR5cy5OuPI1tMhMrmcV0LwFHVi8yg=; b=hla6sYBV/2KRcsM+db37CDWNjagEKpcApTcrxandnShQVrE8Rc6zwMSZlHtXo+F3dX NP9cFAgIeIfrC6DP7V8QRlMzmdztH1ByvImXDbG7T7pXVaIP086ZLn9r9aTMle61yh9v V+fnIdKCUPtyKt1cALx2bA0IWtY5SD9LQgNhIHCi6TnTQyswTTsg7NAomTITF/J9bl6M A7PMWuQsNUsMYokK/iiL/ilEHgxmnyEBD1RUCWQcGeLfYJe/4YD2EHdLSkwtujm4evJp +4qjxL/0SWbTVVEK2rIllKpSNhDmzP8RolC4QCBFe5SYQSkh9mgnz5MJemAwuU5RCVIE qt5w== 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=bUsQyYY1/hLbs2LR5cy5OuPI1tMhMrmcV0LwFHVi8yg=; b=Fe+4stIX7n3N+AzA8zURhUIKddqDzDs/lBQQtgjlkW9AEWO3wJtPlp++jCQDGfFoIc pWfKUiLpuUyajlIMq/dTHaLlDS58clfI8Q/qeTOcyP/ooQbbA52b684Igs8pY2Ek08EE K5vbTLfXIgnWU88oQx9rKs960MPYcnrQ/UJOBKm5/0rdyHGZe679qrHAsYdwJ8PU+5Id juCbBj7cfJJ/QEQXMNI/iAIFIIwg66AaF10DINv3KbJfZREjJlkSScUVKFUFonikajEe JtVbMdhL5v1joHBOeUi2xzeCJJbKiWGIghks3C0sGp15JkhyrTkIZSvEtq98z+kHo0F2 mv0w== X-Gm-Message-State: AFqh2kqXQf51mtqsCLdaRPaHsQ/ArcKhj3B0fXKeGeVHpR6/x3OKghYg 78CSzp4pUEaGgaMR/iQ7Egke/t8stpB0mZ02zBvtiw== X-Google-Smtp-Source: AMrXdXvNquajcq/+qS+4kEugpS/ehg/L4+KOcijyuau5J90VxA3UbQMvkE+jl8g5YTIASU7DfZhBHA== X-Received: by 2002:aa7:8b1a:0:b0:582:26bc:a75b with SMTP id f26-20020aa78b1a000000b0058226bca75bmr30507261pfd.9.1673289101890; Mon, 09 Jan 2023 10:31:41 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id b29-20020a62a11d000000b00582f222f088sm6351059pff.47.2023.01.09.10.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:41 -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 v3 05/11] devlink: remove reporters_lock Date: Mon, 9 Jan 2023 19:31:14 +0100 Message-Id: <20230109183120.649825-6-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 8b0e63f7f49e..b8ef03445b3a 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 d223a46fe557..4142b69ec680 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -217,7 +217,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; @@ -239,7 +238,6 @@ void devlink_free(struct devlink *devlink) { ASSERT_DEVLINK_NOT_REGISTERED(devlink); - mutex_destroy(&devlink->reporters_lock); mutex_destroy(&devlink->lock); lockdep_unregister_key(&devlink->lock_key); WARN_ON(!list_empty(&devlink->trap_policer_list)); diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 61c707c4f9a3..733e28c695d4 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -31,7 +31,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 023c6c6b5f8a..50ac049ee60b 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7278,12 +7278,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; @@ -7295,7 +7293,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); } @@ -7304,7 +7301,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); } @@ -7350,22 +7346,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); @@ -7386,20 +7378,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); @@ -7450,13 +7438,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); @@ -7479,13 +7463,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); @@ -7728,17 +7708,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; @@ -7838,8 +7814,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) { @@ -7851,7 +7825,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; @@ -7859,10 +7832,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++; @@ -7874,7 +7845,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; @@ -7882,7 +7852,6 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg, } idx++; } - mutex_unlock(&port->reporters_lock); } next_devlink: devl_unlock(devlink); @@ -9608,12 +9577,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); @@ -9664,7 +9630,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 Mon Jan 9 18:31: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: 13094091 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 6C784C678DB for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234784AbjAISex (ORCPT ); Mon, 9 Jan 2023 13:34:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237867AbjAISdu (ORCPT ); Mon, 9 Jan 2023 13:33:50 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC673631A8 for ; Mon, 9 Jan 2023 10:31:45 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id jn22so10424976plb.13 for ; Mon, 09 Jan 2023 10:31:45 -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=SpkI6LkrvMQIQDWSSPG6slB2MzXabzQEr2SFrWQP85E=; b=nFZkzNVHjnAGChloHy1hBbyz7x4t/xKMzySy+166SAaK5Xd16fEhMQERLxjx24YR7F vbQvhuqvUoPfmSgdLtlRVszxa9f2eJVtyet+A/cK5ASig4erXQKahduXJ2DqQhPZCSP7 eW7n2yOB68EM+qLYLZD8pVGD87PF4hOJB/lAmA5BqNosYXlrqXMEeFgu0LCC1HbezUMZ OE4KzKqHXacwa38NG77ibEeYRVa0uRoPN529SMp/E+Cj2tvcSnrQUEnkQheX7gZ5lDoj +7LQhnxaYkF0nxU3srB0zySUvncs3JF8qv61eGSC6A4XEKEYDdsb6MGqhZgVDmL/R8a0 h4Hw== 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=SpkI6LkrvMQIQDWSSPG6slB2MzXabzQEr2SFrWQP85E=; b=OrwmcEpHCYCivWwk07vmDLzdq262l5PIFteavmzog292lenQa8qp3XWvxzJAOU5TRz /XoLpTabK+58mMZJHlRnCkb5Ty0Fd49S8aVWbPVDTZRldoRKWUR3qynzL3L+2MzscTWD TVDtV/P2gCLD32Qo3PnDJNpo8M/NqVZPAPkSRFJ2lL6tlkthwDE4hhm9dEy4WX3d8M8S FKJqE72DTXAEq85QRj7s8Su3dPkh5AxDbZb9YaKeifLLB5W+DeiOV8RzKTa+oqOBeRFi vGVSoVdStWKI2qiMQ8ovC48hDE7usB11oK/01ATgpkNzdtyzFFtiGxih7bGHKwF3pnFm xrlQ== X-Gm-Message-State: AFqh2kra0JE52iPXpJeSG6d5OU0OrILEfR4jZRJpZW6eKlg5qoCVwimS 1IF0lxMmQ8RvVOAK883xD+hEAmsQPLPJZXYPOn4CcQ== X-Google-Smtp-Source: AMrXdXvq4qdHuU0Okt9/ydLLH1nQB49ikRPQINlYfr3oRg0FBKsQ170fgF+9NEQWQnsxHF7O/GoW6A== X-Received: by 2002:a17:902:c702:b0:192:666f:933e with SMTP id p2-20020a170902c70200b00192666f933emr48960979plp.1.1673289105460; Mon, 09 Jan 2023 10:31:45 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id i18-20020a170902c95200b00189a50d2a3esm6368459pla.241.2023.01.09.10.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:44 -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 v3 06/11] devlink: remove devl_port_health_reporter_destroy() Date: Mon, 9 Jan 2023 19:31:15 +0100 Message-Id: <20230109183120.649825-7-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 | 3 --- net/devlink/leftover.c | 24 ++----------------- 4 files changed, 4 insertions(+), 27 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 cdd4d2d0c876..662df2c21747 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; - devl_port_health_reporter_destroy(priv->rx_reporter); + devl_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 ad24958f7a44..a932878971ea 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; - devl_port_health_reporter_destroy(priv->tx_reporter); + devl_health_reporter_destroy(priv->tx_reporter); priv->tx_reporter = NULL; } diff --git a/include/net/devlink.h b/include/net/devlink.h index b8ef03445b3a..dc8e7684fec4 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1884,9 +1884,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_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 50ac049ee60b..70b8a9f15ac3 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7423,13 +7423,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 * @@ -7440,7 +7433,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); @@ -7455,20 +7449,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); - static int devlink_nl_health_reporter_fill(struct sk_buff *msg, struct devlink_health_reporter *reporter, From patchwork Mon Jan 9 18:31:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13094098 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 1EF6EC71130 for ; Mon, 9 Jan 2023 18:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237707AbjAISfI (ORCPT ); Mon, 9 Jan 2023 13:35:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237869AbjAISdv (ORCPT ); Mon, 9 Jan 2023 13:33:51 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E33D1C403 for ; Mon, 9 Jan 2023 10:31:49 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id s3so4306724pfd.12 for ; Mon, 09 Jan 2023 10:31:49 -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=KG0NHEiaqGtDUJf5bExR7XlbgtrQz/VrywdrXUDUVew=; b=cEv+Djbuud97xuJVMwhZd7UWYxJke00keZyPIDOBkFZWeEbDwWRsMIZTso913LvxTA l+f+lRaGJrxCSfOpbBlfGuwPJYQKQYjLvSYlJO6HfylFegsnRzm2e5SXX1XRFImaxZki 2Cs82ouKD/bVoE92EMCbzD6AHHRYU02J26ErTD0BI8HAZFWHkNAkOxwo2BiFtl5m0MIw isdRLcsZ7s/ty6vW5PspsA9jUEK6HJJOzDl17Xm0pAsxpUgeMfAbHYE+9+N9IzmUGjBp V6MSw1u9LhAhQFoHwrvS3AxhgcARmbjMFK/B1d945MjXqX+BzkPQJmz9VwcTqHAUPatY pM9A== 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=KG0NHEiaqGtDUJf5bExR7XlbgtrQz/VrywdrXUDUVew=; b=JqAdaWVuqi9WZFcZt9eF0pWtMvRfFF5eTAA1GqCmNSmG4/EPmAm22H/itL2ikTboJI 0HAEdtzWIdJgwD1F22L6Iv6V6wn2m3mCPkp3anOytce0Su9lgMXodcakOifjA2iBwLTV g6j/5oDHT3B+yqXF1jPQIjrFpttfKHlbhvs6PfHTPdpICT2LZ8Ofi+W9d4Ma7+wNtJLo PzlLqBfeq85BQ6EKhZZ63pK6sE3jl18TlUpvuMTEfYJb9SaxrYIwWXB57fe4753FlnMj JcqHvP+LfCc2AmXqzUR2HvwKNjxHhUJQ2Qh2cxpxBvgCkpYjbKqK2Z56khuVQ9b1RmjS JbXA== X-Gm-Message-State: AFqh2koU5udItFNJYFnh+Mot4G9l7SYpRTZJD6XNBVidyY8m4oHbffty g9L6GfVyoKdudjOs9feMM0BVxUq8UE1KsqGdIzkbAA== X-Google-Smtp-Source: AMrXdXvapinYGGijRlgsNkrFyfAuWPoztwrAWLfmVWJPNp7BgCw5OdbYUQMtpW0QFZZ8ZeB9GV/UBA== X-Received: by 2002:a05:6a00:4398:b0:582:7675:8b5a with SMTP id bt24-20020a056a00439800b0058276758b5amr27262631pfb.33.1673289108864; Mon, 09 Jan 2023 10:31:48 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id p29-20020aa79e9d000000b00574db8ca00fsm6344222pfq.185.2023.01.09.10.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:48 -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 v3 07/11] devlink: remove reporter reference counting Date: Mon, 9 Jan 2023 19:31:16 +0100 Message-Id: <20230109183120.649825-8-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 70b8a9f15ac3..c512ddb6bd5e 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7266,7 +7266,6 @@ struct devlink_health_reporter { u64 error_count; u64 recovery_count; u64 last_recovery_ts; - refcount_t refcount; }; void * @@ -7325,7 +7324,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; } @@ -7416,13 +7414,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 * @@ -7434,7 +7425,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); @@ -7678,7 +7669,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; @@ -7687,17 +7677,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 * @@ -7756,10 +7741,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, @@ -7767,13 +7750,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 @@ -7847,7 +7827,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) @@ -7855,15 +7834,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 = @@ -7877,11 +7853,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, @@ -7889,16 +7861,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, @@ -7913,36 +7881,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 @@ -7957,10 +7916,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); @@ -7978,8 +7936,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; } @@ -7994,15 +7950,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; } @@ -8011,21 +7964,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 Mon Jan 9 18:31:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13094092 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 99B5AC678DA for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237697AbjAISez (ORCPT ); Mon, 9 Jan 2023 13:34:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237870AbjAISdv (ORCPT ); Mon, 9 Jan 2023 13:33:51 -0500 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D93C1A069 for ; Mon, 9 Jan 2023 10:31:52 -0800 (PST) Received: by mail-pg1-x52e.google.com with SMTP id e10so6481411pgc.9 for ; Mon, 09 Jan 2023 10:31:52 -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=yGFv4w/4fbY+z3qnkfvjUK8MMxEmwI9RBZlkS0NuLmk=; b=42S78XH4Kc6xMiCGs6DRta3Wx04RfhGrvlBMH/OykEADuDx+91VNNi9sfKLpHLlE4E VR6bJWRgsLVHltaCfd4hxNTiTTCsxqOJubOQmK0vh4BzUjWv8LNnLe4dy8UZby7cFsBa ee5VjCca73rJFbHg3dbZ8r4EY+RQxmnYCYjLyhKMOf3xvssxM4sw29BeIx1/P/ljSVNE uEq+aEx51Ap9l6kFRg5IPfmqe0Ezx++u6mUze1oZIS0pB0WuTocpMuTxkLvlpJtrlrFm wHJmgspZdB/hqnxnG0a2h5jlu0wavLYh1xIdj8UNVSCk/zIvcCdB+vzvaXn9IVYO3aHB 5YNw== 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=yGFv4w/4fbY+z3qnkfvjUK8MMxEmwI9RBZlkS0NuLmk=; b=s7IMFh5A+eBbXyAXcydSraqzvUeOdqn54h6R9V5hYGcb5ID+F9ljbCrtGPido+sx2e 6JLNUs/zCVq6axFe2EZVf2djuHGkFmNng0h/SYrPi/vUNJ7ILhk7eYdvNvcmKKeVCEgY TsXGXIZEGL9jBSZLobUJjMXUkUeqDk3JkINEYIegMvLKb23gzgg0JhOIwIl+Ib0S/mhW wBWYUa0R509QSS2SlMPDexRzq7Nh10I/kzGlR0QtOxoUij9hwxPdfTY8p4LFUJXcvvHy Han+rXlulXIUbfCM0OefWbOFxnGqjc2V95cVqSbuAGXfRUkYlOmG9Bgx4yzHWDLzJP+V YCrw== X-Gm-Message-State: AFqh2krjQFh6vDzjO1KlV7Mq0i5GCB87azjIKRoz67xu/290hSc8Wwz1 /hetEnTX+QU2rws+TP1J183Rwlnjet0LexXojz6YyQ== X-Google-Smtp-Source: AMrXdXuLhDBc9Ih+X3oAnY96agjTVJZQjm1KrlRxeKqh3vpG21BAqbSc7xLJGwPjEEHDzImECey5YA== X-Received: by 2002:aa7:8809:0:b0:580:cc63:dcdc with SMTP id c9-20020aa78809000000b00580cc63dcdcmr54853970pfo.7.1673289112275; Mon, 09 Jan 2023 10:31:52 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id e11-20020a056a0000cb00b00582e4fda343sm4815672pfj.200.2023.01.09.10.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:51 -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 v3 08/11] devlink: convert linecards dump to devlink_nl_instance_iter_dump() Date: Mon, 9 Jan 2023 19:31:17 +0100 Message-Id: <20230109183120.649825-9-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 733e28c695d4..a6a6342270b7 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -165,6 +165,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 c512ddb6bd5e..c5feda997932 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) @@ -8996,7 +8988,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 Mon Jan 9 18:31:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13094097 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 0FB3AC71131 for ; Mon, 9 Jan 2023 18:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237734AbjAISfG (ORCPT ); Mon, 9 Jan 2023 13:35:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237873AbjAISdv (ORCPT ); Mon, 9 Jan 2023 13:33:51 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 627AA4D738 for ; Mon, 9 Jan 2023 10:31:56 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso13757376pjt.0 for ; Mon, 09 Jan 2023 10:31:56 -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=zVRHYOF+iKfblag+GFexRnpMuNLYonH7OYMTB4LPPx4=; b=e4OZi9eki1sckoESgC3PfjePThicFfNQVimXK6LMgviOwEDhwY9wIIv8E3OppmEN5D B+nPQqrZ/p1/EI03RRGoBMPbdDRvxIhpr5+0vPovMsLtx+H2U3uk81ZvHChy8kHuM8Tu iXQIkSNIsM/IfQYF3GUgT1fsq8fnblGrNd1EeMJVCq1aE/mMlK/ZoDfAMcbxF3wkaW5T Hz+25FxhcqwkvIfvmMGsafIS+6akISCIi0E2GGAitfDgrPqI+Q/Fk5TWllFACHObknjm oUdv+u7wwctbUKPVa0/py1FYvg4CrrCK9YK0IepHY1ptqPTIchWNWsFYZQWjBjD8K3lZ i38Q== 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=zVRHYOF+iKfblag+GFexRnpMuNLYonH7OYMTB4LPPx4=; b=VZJU55CUFTn2R8L4fBMgEN+Ti32Qx/z0l5niF9YgHhwfkMVThn1L8llkHZQe+dJ3BU 7wZo2lX1WHr0f82sWSehgdR+ARqM/BnSnYgsHi9Q/AEib79OktzLxAXe4n8GNUDsXOlc foaP12wbVPmZFcDOYuX77+lMLEvCmLI9CcNo2p5QGHMyW7wlBn1QhZSZRyQ2EY6oqJAZ GRZ7Lg9RQMC52AYPJmfeNcXwmsJmPnlNRFTo6qRoxenDOar91tWMKjazqR/Rmbbr9yqk 833HwLZeQt0+tSDJhfll0qWSoff6ZVjVlF/tx+IZ2KnptAPPTrJN0tuwCt3KOEQh2w+U xdmQ== X-Gm-Message-State: AFqh2kruPZEgCYi2boJMNaFEz8wt9W9V8oaGv1UujV1R9NpKEYnkcdzv WAOsIx1UC0eRFfKFqpNArj11xa6l4jCJbJ0qZKl52g== X-Google-Smtp-Source: AMrXdXtCVUDMuO4hkrwik0w/psDcGi0btk/3AqNxppLK+DFusHFljwckoNVyX4dhSjfsmsPUQ6pc8w== X-Received: by 2002:a17:90b:158e:b0:223:b1e4:146 with SMTP id lc14-20020a17090b158e00b00223b1e40146mr65040783pjb.37.1673289115832; Mon, 09 Jan 2023 10:31:55 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id co9-20020a17090afe8900b001ef8ab65052sm5794484pjb.11.2023.01.09.10.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:55 -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 v3 09/11] devlink: convert reporters dump to devlink_nl_instance_iter_dump() Date: Mon, 9 Jan 2023 19:31:18 +0100 Message-Id: <20230109183120.649825-10-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 a6a6342270b7..c54d51432f13 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -162,6 +162,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 c5feda997932..59fa5f543e8f 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -7749,70 +7749,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) @@ -9179,7 +9168,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 Mon Jan 9 18:31:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13094090 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 3D012C678D9 for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237450AbjAISeu (ORCPT ); Mon, 9 Jan 2023 13:34:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237874AbjAISdv (ORCPT ); Mon, 9 Jan 2023 13:33:51 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1951CE69 for ; Mon, 9 Jan 2023 10:32:00 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id o13so6169502pjg.2 for ; Mon, 09 Jan 2023 10:32:00 -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=NZVtI4stkE2bwBcBvmfyyP6v0BqvbFzF3nXeWAKBr50=; b=q+XVna3S0fJE5GPLUBgGg7vMxomoj40esgEoOnoQI/U7F+ZZRmhItdRi8gUzPC6O8Y oKtx/YLnfwCoSC6FFSDXs8RlPrZQnybpaxokVdDpUhHrPaNFl05mOy3mM+Gx6FgtcOyl 2ykAKO90aA1jcyQqj/nkvm1pmdVdMyIgNm3ZOFI0DXsN8pF4DEexPqdWe5xxwofFudlj H/K8uH+Kt0YyV1HHqAiHeq0p41FvdmEtSeFs4SjGmVv/dh+IhrYDuqSIv/vJ42lEJYUQ kkcFz0/6kLRolL/JGf04TCU3LCRHXkKu7qv3nXQAlLHl4EfnMtCsn8obSbg7mWSvANPX 6TJw== 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=NZVtI4stkE2bwBcBvmfyyP6v0BqvbFzF3nXeWAKBr50=; b=p6odtUnoYnbEk7kd9bsHY7mJpfg5ke9JeMN65ftEpHAcFDZ2EZM54nJ2ESfCR76CrP N5W7PUqw3gjwiRaa1uwsh8JhCiKKgMzEP675DTcCkhvGvj1RJOsP5HKc30v816hdKXTi Oe0vQ2YrthRpATlNlF3eOfQI7dWwAX9fjcuOzryWS0Zf4JScdk1Al02CvRHD7vFGZTP1 aTkWMSamLcvovdUIf9bLBADyUEYAFR6Q4L/foh3SNPP8JM2uRsqaqwnUD0Ft4KUIscg8 MYrtRA31y+fe7N5r7krWQ4zOk0UHM3drflvkSvNYuqHAx1/eDF2zwBiAl4YUkPR92anf v3FQ== X-Gm-Message-State: AFqh2koCgWRBNj0hkqarl1qs8XPWPG1C7OrDhjLRrZo/TVAz9NXxGATT Ew9SSwV/jVbQJEpvQx0eLnopSciCtP4eitqNLMsSMQ== X-Google-Smtp-Source: AMrXdXuobOJ6fEU0Gj5NYOhxR6YnQjstD7C5b7p6s9t47N9o2HwVD7RlOBlblsxpBAN8kA6FeGwd+Q== X-Received: by 2002:a05:6a21:1707:b0:af:7fe3:f0e7 with SMTP id nv7-20020a056a21170700b000af7fe3f0e7mr71184045pzb.31.1673289119433; Mon, 09 Jan 2023 10:31:59 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id t23-20020a17090ae51700b00226d4009505sm5819146pjy.3.2023.01.09.10.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:31:59 -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 v3 10/11] devlink: remove devlink_dump_for_each_instance_get() helper Date: Mon, 9 Jan 2023 19:31:19 +0100 Message-Id: <20230109183120.649825-11-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 c54d51432f13..647deecd1331 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -121,17 +121,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 Mon Jan 9 18:31:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13094096 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 00150C7112B for ; Mon, 9 Jan 2023 18:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237731AbjAISfF (ORCPT ); Mon, 9 Jan 2023 13:35:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237875AbjAISdv (ORCPT ); Mon, 9 Jan 2023 13:33:51 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F23B63F61 for ; Mon, 9 Jan 2023 10:32:03 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id c8-20020a17090a4d0800b00225c3614161so13675973pjg.5 for ; Mon, 09 Jan 2023 10:32:03 -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=toMP38RUz0n/Vf2/BW5zHRNWz3IaMqsFrcQNsREKqnU=; b=t1FEnjiuk6d0yNJMM3DGP4k7oW43aQQWYrdaoUo9whzkcFLnEWtZnvzOFkYJyAjFag PIj4Nsyf6jD3cE+E2DCQ9ugzztBSLvNSdL4V/NsVc4AEBWN8xdTn+q67gA4XYanayvyR sHhDfy0piu1rH3af6UUGEWrCMze7osgrKwhZXYmHJceICtneh+tBlJh/8C1AvdmvgtEf GdlMmJq9CL8DuchoFHqCE0x3G3iOvoB2GzOiuVDvxsZvX/uGQhORigog5+jI7ha3wur9 ukpmSj7YQZFHeazB0TxX/eDB5HrwW/yV4oC3oeixZGXC1XBIZADsJ0hFOggsS6G30Nm0 DjAg== 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=toMP38RUz0n/Vf2/BW5zHRNWz3IaMqsFrcQNsREKqnU=; b=Ki7tPGr5T/PLT4BAxOEoHIAmVsljmGydL+YHsIJYP0ot+aaaH6uiWT8WfEaqjRZxuE oCuZ/KJWoldrERE9/IhjyKIPqgg95ZNXagSShB5NwQn33j72rLYtyl6QVdV6B7OV2EJM 4wAKnM85QJgty3Wu+nR3jsF4SbwDLnYmDf9FLDPBF/c6KZqNHgGUq3Nwglfv0TNAfC5O xJU4ANNZwAkUoDX6Nfolq3fCTE2HOK6wB4YeCCx6K5HNTmhKm5c4Jos/dfx0Zx7TqeHH eA94J07utbVnWqxG6itVSAWBCy0ydWB5X53lTLNJ5zxISiw3p7PyKdOG1K/muoqzICHu O4+w== X-Gm-Message-State: AFqh2krV8+mHgaD/i5CSO4HC2+fdSg+x6JJJwIGQEvKb0PYST+tqJ0aV Xk/dJMBz+2AtuEHMpXq3HAWmmAUJZtjHvcAlNEDJWA== X-Google-Smtp-Source: AMrXdXuBcZcr4ln5WV1u47elCgkbHic836Lf/b7KJSnrAkBiWnnF2QdjtN4XG9U5mNk4BROch3Xkkg== X-Received: by 2002:a17:90a:1a41:b0:228:cb21:5028 with SMTP id 1-20020a17090a1a4100b00228cb215028mr130449pjl.10.1673289122901; Mon, 09 Jan 2023 10:32:02 -0800 (PST) Received: from localhost (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id y7-20020a17090a154700b002265ddfc13esm1556691pja.29.2023.01.09.10.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 10:32:02 -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 v3 11/11] devlink: add instance lock assertion in devl_is_registered() Date: Mon, 9 Jan 2023 19:31:20 +0100 Message-Id: <20230109183120.649825-12-jiri@resnulli.us> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230109183120.649825-1-jiri@resnulli.us> References: <20230109183120.649825-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 --- 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 647deecd1331..7c612c5210da 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -83,9 +83,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); }