From patchwork Tue Nov 29 14:12:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 27264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp363098wrr; Tue, 29 Nov 2022 06:16:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7WMMhUYhCL5GIA3iciqJrbsQB2SbWoQDdg/S9zJzpUnxcZkMSR/NPdkSzv50XlQAMQpkSp X-Received: by 2002:a17:907:9a0d:b0:7c0:7a5e:f1ad with SMTP id kr13-20020a1709079a0d00b007c07a5ef1admr6922125ejc.495.1669731383551; Tue, 29 Nov 2022 06:16:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669731383; cv=pass; d=google.com; s=arc-20160816; b=Nh2OYU1LM4MLGw5raB3XmEfag11rQqbZNa4d60L0Gf0NhWe0oq1DxIBYHMlKPIe8TQ app0xVkUJ9fe6UdJdpgxr6GIqpQ1TgJTiFFpCsq1oM7lZOeyBiPBVkxu6yz9Iv7//1l6 XdQ+v9xkveu0lWv1fh0Hgy4WFYyUC79VzQoTwQsKK3uOa3cQnKOmjsXi0t7vG/lu2/np ogHxo8HzfFvYUh4g4EORG9QEAU6CCeb3ZGvqvVxGe6xnUP7Z9TsZUYLwgCXHx8HNmluB Rlf9PcuwWvn5/33Ty8+ssqMneCBh0b/ZjoqCRJ10eONhlu5V89NFg23uafSEjn6wpDck LFpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fgBNFRD0uInGu3S7+UlK0n5Nx04PgX4ka+VdUIF0XgA=; b=ti0srG94nWiwTN4PR/lwx3uYWpI+brFhKP0HZlzXjiPyCvtoMZZUW5LocXEc2qLgrB 707TeFZLn2a8kwSNd0IQwbHpaZe8pGyQClZFk3zTqAZYzxrQXqCrZLSoaWDNJM0OfuLr tsq5ZVSmD9IYB2cwwwh9K3QPKP9CeKLXdGpV6lCrU3HJI4pRjtvjpg+4vUMLCCTjSLWT mogheTzVUQYthz1l9PbRRkLiHHYJEJ/G3DKHYVVPxhyQLtSqCHgJl0cJdCLk9rSiTcEK j7tOWPebhhoAV0Ga7yeIlSr9kLu60aASfsdMY2+Bll7xOpGZ8eGhnhOr9mM2jnrjlbmD 5tDQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=sZn4Iicy; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he44-20020a1709073dac00b0078dcf11ccf7si10418909ejc.802.2022.11.29.06.15.57; Tue, 29 Nov 2022 06:16:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=sZn4Iicy; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235519AbiK2OOV (ORCPT + 99 others); Tue, 29 Nov 2022 09:14:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235173AbiK2ONg (ORCPT ); Tue, 29 Nov 2022 09:13:36 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2045.outbound.protection.outlook.com [40.107.14.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB0D362E90; Tue, 29 Nov 2022 06:13:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lQfCg052Fpy1gQmSyjWQW6JTI/ncWQQCKtizF+LTqQBUc5XE9Evmn//b1nxfDKOrPHXvRqyv5UqMGyxpkAKVl6PNHBm/RyQ4x4bjtofKxUvc7vMhm70rXotdRLQ8j6sKi2jg0HiTfoHMvYy6IznRDblbSDtf7Ln0weqvlRp9+wEIPpNlxWfb+iCTDfgM5kRmer6CUcwuStZY2TtSilv3AAblOrOp9rsg4O7ah9pPVU5RyuAuEUCkd9mDU5VSrvd7C2sKdc0SOP86pp2ips0HsW+I4V2d0+yHKcFuyiABURWCXfwTMae9dQnNXoyrTBfbrkxEjjmUQcCKqtpNzPKbVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fgBNFRD0uInGu3S7+UlK0n5Nx04PgX4ka+VdUIF0XgA=; b=jPvjZRUXjIDLUyo+Z/ijURhhULbEbmeMqCW8IL2jyalP4Qf6DZZzjyEFbPdkun3iRt8ZbywDF3mQh3aaS7YlR0WB6VSNoepcFW9K/xFxoLYwWOh+XyAKa/Jwd6Iu6N2XXub02BZqdD3hcQx8yMXAOOFL8hrwGuPUv9IlkRZvTXknL1GzwQ7yXQyiP9AFBArkWslbevUl+gfJwClVu+aAwSkOVE9vD2AAd3gXaIpNIIefcb3v3lEhwbNOsEju0ejylRSXh5wTr478RZq7XTb838SW9dDgPfdbQfUtBHOl1shok49DYM3W+bepuA+7WxoDdnFL9yHDQ5huTdt22wwsIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fgBNFRD0uInGu3S7+UlK0n5Nx04PgX4ka+VdUIF0XgA=; b=sZn4IicyjFGqix72QeKaIlxbvxAp0JVoo8k+zW/o8VXCLILVTk8f5hBz4PhEKnSujt990jyHc+mQ8dz2JGfDkCfnwo9Tw1JUKm4DBQk+pd54r/9MpFiSDyw0DpO5PBZOV9CsdP/DvxHEtKVOJGIhCPVIxGl4sFMOhWPcYvltRyA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by AS8PR04MB8724.eurprd04.prod.outlook.com (2603:10a6:20b:42b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.19; Tue, 29 Nov 2022 14:12:40 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b%7]) with mapi id 15.20.5857.023; Tue, 29 Nov 2022 14:12:40 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Ioana Ciornei , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 07/12] net: dpaa2: publish MAC stringset to ethtool -S even if MAC is missing Date: Tue, 29 Nov 2022 16:12:16 +0200 Message-Id: <20221129141221.872653-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221129141221.872653-1-vladimir.oltean@nxp.com> References: <20221129141221.872653-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR0701CA0029.eurprd07.prod.outlook.com (2603:10a6:800:90::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|AS8PR04MB8724:EE_ X-MS-Office365-Filtering-Correlation-Id: 95de62ab-bdf7-41ac-f97e-08dad213c578 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TI/PN2v5j/+g1tu6wlnMkETuFUwNPnyB8hX4FMjtiyfLGIR5YRhKfa96fkB9Xxqn77PsweXlHmyN+2tfO/zCCvGOwTRJ/YG9kKskFAEr17YHauJ5UWJcoADnGC9qxRbih54pCb8OdSiiOAK/TKCtxe/M6k3aiCx3EFMcHoKp6qFKkD6vVJEcapIUxJErt6RVqF5tGMf1ycXutDBEuEHhKLfXWGYx9vkh+jsV6X6u6MHtTxrBjQXY24hCe+s9V1kycxDYafCqs4lFEasqHNwofIysVm7wPosPP24eoXgrfnz1ZZ/kbSLzwkAjX9mhYl9r3q1EmLa8e3HLw231KSk3eqNJt1/X3gz4OSNVUzkgclCQk//JxSjUk2qbA0qF1n9g7Y5F5/aXVWK0Lm8Gx8IyeJgdLe5LkN2wrWbXTuoXLq9FV8yNUL3GnA730QKb+X7oYw6BzU8RWyfoghpA9U7DnqegDC8RxftXBfQjmSzcSgYeJCYVZby87HwUJUHUtCmSWjnQCbEj3RYroe8te1PxY80MF1sTDLvUD3CHs5sowM0jKq7X6wdmtx/Ag+JhmDu7RFc37gO19fVenWii+JlSswUE2hFl6IDCBflx27kWyDZBnTwmX0wH39rjXXPCtIGS9qYBlpnHp7TPzZ5CYO1yIvxJHJwt746YRM4UjsjlcwmIunFg768GElafCCC7Awlv X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(39860400002)(396003)(366004)(346002)(451199015)(6666004)(6506007)(6486002)(478600001)(66476007)(1076003)(36756003)(186003)(66556008)(2616005)(66946007)(8676002)(4326008)(6512007)(52116002)(5660300002)(26005)(316002)(54906003)(6916009)(86362001)(2906002)(83380400001)(41300700001)(44832011)(38350700002)(8936002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OXFvv0FKD3fZAwa5gWYVwKbzkgohl2PDdsbaJuZOv3lkpFi+WfCxcIYIW+aPaI+Dr9bthNYyZIAPSvm6o9P+lpg9LmeytlmjdxCFyEbCJMl+uZ3TpN6Dz8N7XYEWJKebNyAbHIbqosah8KNdFNNLd6ZTAdP6Ew0rZtR/OvjpLSB16LdACIp3BeyKD8cb7f4ER0Y7T2+xTjcZtxRCWFPvQot2AlZ9Wo9kRGGI3aC8/SgFs1vWz47jqbctsu30Sz1aCytsmJnHGgIRaRPRO7OAY0a5xugS1zFyPa2IZAT1M67UV78Q1BgiL4l0LHjxHdq0caiIkciDXaGSLqoNCvexv4TdCBelKY7BbfVntXAxhigitHdw6VZ4Lfi/CDGVCMxmu/wxBaZ6asG6ZCWKsXMz13yHbWuYxNjscq0v2yXn+bOl8HtkgS2smMdycW9Pt4UbGXFlgtD/67sQtOquEqrLk/9AFzzXyioYNAVdNpEwkqm7+JZp+CfvSU+B77ouqgYifdGtsz+ixxusIjjSv2V1wGyCdBz8X5rp2f1zJqmRTAr7oxHe5Au85aPx1xLn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enant-Network-Message-Id: 95de62ab-bdf7-41ac-f97e-08dad213c578 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2022 14:12:38.7628 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kAems8mHZ7/uxL61ckyvlgE+D7pzIouzLPoFVWR4Z+y7lVQFNSpRhCgjeeFfVfB26VhSFh05JfeQrOEvPAPqsg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8724 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750840255006215601?= X-GMAIL-MSGID: =?utf-8?q?1750840255006215601?= DPNIs and DPSW objects can connect and disconnect at runtime from DPMAC objects on the same fsl-mc bus. The DPMAC object also holds "ethtool -S" unstructured counters. Those counters are only shown for the entity owning the netdev (DPNI, DPSW) if it's connected to a DPMAC. The ethtool stringset code path is split into multiple callbacks, but currently, connecting and disconnecting the DPMAC takes the rtnl_lock(). This blocks the entire ethtool code path from running, see ethnl_default_doit() -> rtnl_lock() -> ops->prepare_data() -> strset_prepare_data(). This is going to be a problem if we are going to no longer require rtnl_lock() when connecting/disconnecting the DPMAC, because the DPMAC could appear between ops->get_sset_count() and ops->get_strings(). If it appears out of the blue, we will provide a stringset into an array that was dimensioned thinking the DPMAC wouldn't be there => array accessed out of bounds. There isn't really a good way to work around that, and I don't want to put too much pressure on the ethtool framework by playing locking games. Just make the DPMAC counters be always available. They'll be zeroes if the DPNI or DPSW isn't connected to a DPMAC. Signed-off-by: Vladimir Oltean Reviewed-by: Andrew Lunn --- drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c | 12 +++--------- .../ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c | 11 ++--------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c index ac3a7f2897be..bd87aa9ef686 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c @@ -185,7 +185,6 @@ static int dpaa2_eth_set_pauseparam(struct net_device *net_dev, static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset, u8 *data) { - struct dpaa2_eth_priv *priv = netdev_priv(netdev); u8 *p = data; int i; @@ -199,22 +198,17 @@ static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset, strscpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN); p += ETH_GSTRING_LEN; } - if (dpaa2_eth_has_mac(priv)) - dpaa2_mac_get_strings(p); + dpaa2_mac_get_strings(p); break; } } static int dpaa2_eth_get_sset_count(struct net_device *net_dev, int sset) { - int num_ss_stats = DPAA2_ETH_NUM_STATS + DPAA2_ETH_NUM_EXTRA_STATS; - struct dpaa2_eth_priv *priv = netdev_priv(net_dev); - switch (sset) { case ETH_SS_STATS: /* ethtool_get_stats(), ethtool_get_drvinfo() */ - if (dpaa2_eth_has_mac(priv)) - num_ss_stats += dpaa2_mac_get_sset_count(); - return num_ss_stats; + return DPAA2_ETH_NUM_STATS + DPAA2_ETH_NUM_EXTRA_STATS + + dpaa2_mac_get_sset_count(); default: return -EOPNOTSUPP; } diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c index 720c9230cab5..40ee57ef55be 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c @@ -145,14 +145,9 @@ dpaa2_switch_set_link_ksettings(struct net_device *netdev, static int dpaa2_switch_ethtool_get_sset_count(struct net_device *netdev, int sset) { - struct ethsw_port_priv *port_priv = netdev_priv(netdev); - int num_ss_stats = DPAA2_SWITCH_NUM_COUNTERS; - switch (sset) { case ETH_SS_STATS: - if (port_priv->mac) - num_ss_stats += dpaa2_mac_get_sset_count(); - return num_ss_stats; + return DPAA2_SWITCH_NUM_COUNTERS + dpaa2_mac_get_sset_count(); default: return -EOPNOTSUPP; } @@ -161,7 +156,6 @@ dpaa2_switch_ethtool_get_sset_count(struct net_device *netdev, int sset) static void dpaa2_switch_ethtool_get_strings(struct net_device *netdev, u32 stringset, u8 *data) { - struct ethsw_port_priv *port_priv = netdev_priv(netdev); u8 *p = data; int i; @@ -172,8 +166,7 @@ static void dpaa2_switch_ethtool_get_strings(struct net_device *netdev, ETH_GSTRING_LEN); p += ETH_GSTRING_LEN; } - if (port_priv->mac) - dpaa2_mac_get_strings(p); + dpaa2_mac_get_strings(p); break; } }