From patchwork Wed Mar 2 16:31:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766267 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 425F1C433EF for ; Wed, 2 Mar 2022 16:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242189AbiCBQcw (ORCPT ); Wed, 2 Mar 2022 11:32:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242163AbiCBQcn (ORCPT ); Wed, 2 Mar 2022 11:32:43 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2073.outbound.protection.outlook.com [40.107.223.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3445CD5C2 for ; Wed, 2 Mar 2022 08:32:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dKP1+q1avn9Z5UOXTBuPgfARmGVE2lJLxSwbty6zUXwnJcWoRQgC3Qyw9WYfyHTzQVcgiF7ZVZOY+vnOlzv8xcI0cX+lOsYFpwsH1CfFVcuCWgEiG7CEH7ntC1O/dmnUgTWQ1rtNc8Kmw2rp8ldB7q882OyVSRnPAQjEmC6rawENC9OCYJe/jH5PJrdEUUmWHkcaKoB2iTn72Ro4DYsjKxdtAdjb7ZvIlZEcE18Z2qnr93reQEC9SlfMwDDfsIcm2sEoNPXOL/aoTzQvKmrJ3xGiIVvQN8mMDpNncSIMfxS8gvqHj8sphWIXFTgu4sXLW7g0VIEPAeeq1zH6UmAEPQ== 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=ZiGt8fndYh6d19TtG42nSQw2AWXWMYNSHSuyQlhVvXQ=; b=jhMp58RBhL+DlRHUbF3ztpAzf/dMVIheWghPcWFO2O3SId7mr34cv9F1XBw5QWAvIw/RKm/zj8T6FJ2KsgRHHKdmKvAOoUdL1GGEOwMKEUo5Uc9/8g2aDBo7A2qewctF3BIibonBKBxnvufwehHeY5s5iFQ112PA+XjsLQhDuhvT/z5q1UnP83en7JCpE8TOzqV7nR54fZ9EIdmxIPwIKRx4iIlr4wPOe3Q4yIElynFtUzI4jtMd7esHzsng3B4W9WF2+EsNAWElLS9ubhDJE3WHkyU9HLq1t9cwpiS0h093feGqregkWxnR8/VL5E3JO3ed3g9Q6SAUWvUpgM449Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZiGt8fndYh6d19TtG42nSQw2AWXWMYNSHSuyQlhVvXQ=; b=MuQnJvLo3TsqJJvho5Qa5Ujo5+xglUjQTv6P5XSerDqf8JHbihlUQtsuMOUvz/f2rSIULCK4LOxiRjkMFwjwRng2OB6zIZTG7Z7/vnikHL8jzdxnLo2mnCFMgr2316J4PqBkSGLDFRs05nJhIAsPOBE1TBkGG030TPPKLbIea8SWsuWPpsUSt3I2qCUjJ0NLO+bVHnNczs0A29dKDBdhIHtcBFmsWbfTiOsWkVRrf8GFuEspwe0H12z6+MctyWpM1OB1wBb9GVcwyOskRrP1bCEDdkdUH6hW64yRp7mi6cdkRwUO/EiXmHdWbzUd4dEEdks19uzDxrvZBgqqGPm5+A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by CY4PR12MB1942.namprd12.prod.outlook.com (2603:10b6:903:128::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 2 Mar 2022 16:31:58 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:31:58 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 01/14] net: rtnetlink: Namespace functions related to IFLA_OFFLOAD_XSTATS_* Date: Wed, 2 Mar 2022 18:31:15 +0200 Message-Id: <20220302163128.218798-2-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR06CA0171.eurprd06.prod.outlook.com (2603:10a6:803:c8::28) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0a2c4dd1-660e-4005-c829-08d9fc6a2be4 X-MS-TrafficTypeDiagnostic: CY4PR12MB1942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8fu9PB/DeVXgXzaQ3AL+jSr/1NA/4o4NP7zGZfaganQmiRmXGJu05G2KRCtaDA8MCrvLnEvAqyugjaTfslc+FXnE0n0r58B3tDPJ+lPxrw2ajz4WRVIAe8DcAnkJfnttcsFT1DyEF8/Yqd8yx/nGlylQcNE5HdJzKQPwFO2xZ/9QKzV4TIqWjwHdMEANomaLiJpc1A3TAQX/qbv7u7ptIOqCq1icX1wtfFksvoeGFxCbbDP/J0QkCJ48ja6mAidZxoHwcXR/iiHYatk1z9D9KbOLc3KKWlzlDJrUrIslxLWgkC8EuuIH5MpZu46FMM2zJyXx4e+5J6Z/RUQCjaBCGzJoM4ljnw4a3ZsQNr6H7FLGQcqusm/3Xdv8yo2fuQO+cUdN+NjpqwklcmabYvRHWzLVOXuVvHqDO1yu+0MZWoZf+gwca6GijskOyY7eI1nrtQDQaWHNORI7C/mw2+MoFQN9VFvZPixzifUvbDkhFCNhJxo5Wqm6KAgomENrHtvU4t7sFH2m0f4he15hfMs4Spw5KscW6a1jX68ozGW2wU2zTTbNg+of77YfV8dPOG3xBB0JxYI6/x29D6JZ5iFLipKGg1TehvjNq/s9DYHU8gXDKLDioEkYE0/nl+vzzZISRlZUM+eX/exBd24rVrZ3vQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(36756003)(2616005)(86362001)(26005)(186003)(1076003)(6916009)(316002)(107886003)(4326008)(6666004)(66476007)(6506007)(66946007)(6512007)(66556008)(8676002)(6486002)(508600001)(2906002)(83380400001)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vRbQrIckhzd6WWyOXvGDMaaMnqFzwRtI3cz0F90Mpsh+qyLff6RExN6DILpTcGWSDZU6lqjfqg8Mx/DyvOKdQlzJgxK4FSioQhj7rVwmqZZwzU1FqiBYu83hpclaaTWVlBxcrjHfISTCzGoNfbqWAjX6cwQ1hE0sMNFxbGQxXJiysacx2sA/ciDAkA8YYK6S7ZoDUVKJ7JCAJW9ww+7Tme6tTJaZ23mCt6iCz4KvYQa3ivJmM7lkTRvlxBu6kqwX0rZbITyRidzfJdKOR9PCJmLrq6r8j/QQBJwN5Zf4Wq8unLAopc5ZWKjLifsGQNbWmQaYDlQc+XX6hx/X3EpLIyNFLjlkj543AgKPYll0rud935BNvJprEbTDVQ96R2+wOlA3O8uuXV3X6FZVmAux7Rfc6wfBWeMbVLalJaR07MLEU22Z1gZfNqKc1cY9gqqxCTgGfmdhbbNSyPsPe7SMJvIiPKLd0npUn0uO6d4lAZLOZPwgg7TR8fORTKCOLQb2EnNto2S1ccItpOJ9MLAdNXHENCWNy2tI8SsLn9vZVYjpmHvNM7mGcKd063A1l/+VFY2DmlK7oYXs9y8uRGorRUrttU1ieKOA5pjNBB2cjaKxMjWniPS0xP5eF2dkprXVWvU3ZakX0LLNiNuQfxpCiwkiQDCiQyX+ArTrDWJmeavuBERYEqIA8fNt5u9E5O8otdwdnen0VgopxGUw2FCS6vcNpBm8kqEPwBCnHGnu8NP+U23yvyyANyWfpp3owIjWst7FqmknLfAeH0rWXJ7AzxSz+PfYW8SI+QwTrVfcOXE7myEbIn1ZBGGmZOtXvowZO0uWLX4oiAMKdp729AORM6ctfp/Pe7QvNMa5LXIRJR9NJxLr95xhXsmh6UjMWaQtIkTZx6/tlU5uIBPrUgp8ym4LBuf0mvskKxs3JWut2csFU296kRJSJm3I7d/74MHAbWM4EY8mnLAC6OeOPOFGsOqm94wvv6Lj1LDkGrq5no7pMDlGiPLdOW22ofiJeZp9ZLOk5Nm2PvSL5Ai0+UN1EhkRiFgOtR5HFfqNUMCoARUMh3eek+dkjME27BCMQMOZzqZsDLqylMaBJKCx97OD5ezYAiE9WysS2QblnspdR7EO81yBAKY5RStXzwfYDQwFCAmGTIsEPLjspqs0/RM36YOlQG+27C0y1NjCuF+ks/jhPg9kaeUBup8CkjEZf29RCAGQ7tF7Lx5Ku6SMxfCVN196djHPhRc96MTvxMP6rf5yQ7WHbZ93izcCtd2+RoUenWZcNi0mJe30oLkAoiXT4asClQeZ0q/XLt+Jps7NuV3GebgaILrtVbRRmuxi3T5noQaze2t7QByyvsRgJFUaz7szQyQ0OFt3hH8+avXHMoRtt8bGjJKUC8QNt7vF5WiVk43njHzsY1VtwTYeHNVYZHgyNRwW9hpxZj0cFdZJlbSDHzWo+DkoWeTxcm8lZCoKWioEmza/7kNHh6yH1venioDcZdd/lvleDuuRZYIW3N55m/wo5vfpRJjflU+x1Uw9aF/idtwd83rAdpoSGHwanV0Zwb6cvghpTnET6Y0ggoadlya+MQmti2YECw7jdihE2JeU/5Bz0ZxQOiLm4jBplfe8KTjb85wJ4gEIh4K1+Bw= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a2c4dd1-660e-4005-c829-08d9fc6a2be4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:31:58.4943 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ATebPQHG9ALkvZcZiHELmaqZS6WmvyynF9602OhCyfLtdGxHP3gKAV8bpTAfiIKA3fzsh0+2tCxA+6zT/CFFLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1942 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The currently used names rtnl_get_offload_stats() and rtnl_get_offload_stats_size() do not clearly show the namespace. The former function additionally seems to have been named this way in accordance with the NDO name, as opposed to the naming used in the rtnetlink.c file (and indeed elsewhere in the netlink handling code). As more and differently-flavored attributes are introduced, a common clear prefix is needed for all related functions. Rename the functions to follow the rtnl_offload_xstats_* naming scheme. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- net/core/rtnetlink.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 20a9e1686453..c484bf27f0b4 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5059,8 +5059,8 @@ static int rtnl_get_offload_stats_attr_size(int attr_id) return 0; } -static int rtnl_get_offload_stats(struct sk_buff *skb, struct net_device *dev, - int *prividx) +static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, + int *prividx) { struct nlattr *attr = NULL; int attr_id, size; @@ -5109,7 +5109,7 @@ static int rtnl_get_offload_stats(struct sk_buff *skb, struct net_device *dev, return err; } -static int rtnl_get_offload_stats_size(const struct net_device *dev) +static int rtnl_offload_xstats_get_size(const struct net_device *dev) { int nla_size = 0; int attr_id; @@ -5219,7 +5219,7 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, if (!attr) goto nla_put_failure; - err = rtnl_get_offload_stats(skb, dev, prividx); + err = rtnl_offload_xstats_fill(skb, dev, prividx); if (err == -ENODATA) nla_nest_cancel(skb, attr); else @@ -5323,7 +5323,7 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev, } if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, 0)) - size += rtnl_get_offload_stats_size(dev); + size += rtnl_offload_xstats_get_size(dev); if (stats_attr_valid(filter_mask, IFLA_STATS_AF_SPEC, 0)) { struct rtnl_af_ops *af_ops; From patchwork Wed Mar 2 16:31:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766266 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 5FCCFC433FE for ; Wed, 2 Mar 2022 16:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242163AbiCBQcx (ORCPT ); Wed, 2 Mar 2022 11:32:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237188AbiCBQcu (ORCPT ); Wed, 2 Mar 2022 11:32:50 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2075.outbound.protection.outlook.com [40.107.223.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4945FC6255 for ; Wed, 2 Mar 2022 08:32:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OMexoc8FPD74q0VZl5EAbIqyM5TtA8ddus8ii85ufOQnIwKCelPMainffHtVXA9QiDdb9/en7I7qgZiLW9VNCp1rtiO6pv6iERWu7y5NCBoTZ2jyr70T1tvd/9M1GQ7XsIFFEHBBM/+pKX1Ae3AseLolA5q10tIhTteDQRdWGl9krZOihPzwFE8UbnHNgimbW9dsMWNL78dlTqKU2jdqwlHDhLwzKsfJY+RIUqonXbj5+IK2ptkzfLpwg6KAnk4pNYpPMjZvaMlDUdTLy8uoXLyhtE5obqwVOIXmFW3KgFe+WtcuYlKi11x90HFSGthcUKxYXst77tyPgnJUBsNXDw== 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=CdVn9CNIrqb8EQczWFGD0fpiwKDt9kaDIODFtQdatHs=; b=FG6UYcgBmSnc/02w5kkA8wOIj3WV8ZH8jxlZGF0uf9Lx9KoFx1AOYHf0pCVYrAWryNNuXKxbqEZZ2nqI0fZf8cATN8Z4QZE2wVy1BLjpBd22uvjjMWEyUswNUnAliLzNq3+3F0/ukjwVFr85qJ0RYyrB386I0/FOS/qoWwXZ4UaWUHtBQDG3CZbmhYA3oiiFLQDOSRutiSIe0vDvvqfLX4jaWM5oxR29DzvAd4LdiGUSwP6uGGnb7VRT+O2Xl5p4OuGEyl1bAT86m8r1Tk6s1W64mXUG71k+BOvOCnX+m0H4Iu4Z3qlqj6iEajjOOogpeMrNLRHG11kd0AUN5tYrlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CdVn9CNIrqb8EQczWFGD0fpiwKDt9kaDIODFtQdatHs=; b=F1CHiIClCfKqMKEeKk8u1kGWv9VkMFJpHp2M7TMVO80AoKYQZ7IYehiPAnU6b74mTM7uUkC5JWvR8ey9hZm9UophxnAEU41pAkiF8bfl8lq/omkbJ4AdHZXLDtYeCq2F4Wfqx1PX/2qyXFZFVZeXhVzxznG7KuacTY+rgKIy0KbMH74Ta8eFfv2HPbXh0MNFGwECK7M0aq6gyR0RU2vC7+6idFpfZlFF1t4Pq/gusplXa9Zt+D8cdI78hlTC//UBC5zii+qeCIzbBpr54lKjJU50mB3DOUfnlK3iAxBY26qwjKLh76tEBacSulpmuzxZ4hUSIXQttDU0KwfFBcCTWA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by CY4PR12MB1942.namprd12.prod.outlook.com (2603:10b6:903:128::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 2 Mar 2022 16:32:05 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:05 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 02/14] net: rtnetlink: Stop assuming that IFLA_OFFLOAD_XSTATS_* are dev-backed Date: Wed, 2 Mar 2022 18:31:16 +0200 Message-Id: <20220302163128.218798-3-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR06CA0223.eurprd06.prod.outlook.com (2603:10a6:802:2c::44) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 057db0b6-505b-4007-4096-08d9fc6a2fc9 X-MS-TrafficTypeDiagnostic: CY4PR12MB1942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EWz3CoZFLptjL7/KzUvMR5rj88YGx0jBjZ+VrXUj4vQ6ZVKxIZnyVdnXMWMzPtjmAPrxT8FmIipMnIF/nlDCmb8fP021IwszcfqT2C4d5Kd+iF6nwPUDRi4JMpVRKJ7j/2zDMWOmOb37Rkaqfghh3LY2h7iMn/WkYu/Ihxt9JkkQXZBjvDehDGBje0bKFrzgN/+Uf0FzHRo7jv+JYmHhMyu71a3+XCbMkITscr8W0QQhZWNPoSKSh1P/wsjCUzz8TjlqkArQMGSLU2Nim5smnB5TSnKg6b0hwHxCPYuhqUM7rtNU2in4BmiA5xK2RGrZL5eS+NvgTByNmNGsw7W7qbu2kk0pI/OLGMIoIWifyOZNK+rNRxqvXWUlnO+D4f2Z9SEBnco7MdmhRVmx3zxL0WKUr8Ta+gSEPc/tqRXS+PWJm9ywx9TXuzPlJ99GTuCN6HyvqJw73Ae8tkm/M2uLsO1YdZx0MBl/PrsTo8vO+oWvPblNSaeY36DNapfa/csKvX7nEhnedSB2MobqYBp+bpeCSAfHRooRXNWrpRWwYrdmh2A3jb0AzCqYZg0gMVR7nV8CtNurBLR7tyCbDXLdfFCE0oqRMEm4ATucuZNP94d1TkLxS+newGh/fo7/0x3Nzu/+Zu/hoKxGnRPhnj6Byw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(36756003)(2616005)(86362001)(26005)(186003)(1076003)(6916009)(316002)(107886003)(4326008)(6666004)(66476007)(6506007)(66946007)(6512007)(66556008)(8676002)(6486002)(508600001)(2906002)(83380400001)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BI5ym2g7HuUFbUiR80vh/mRP0kN5xThdwF+yIUo5ki260GJtCWAIoj/E+WtD7ZUoK9n7rHg3+WtJAPLIHCL/AwWAPAzAFb/HAuyjPcyq6Lsnb1a+RFU1GOU6AXlw9Pv0vq0WfA/UvjOOhD+hN8WqZ1a2p+HsQO1yNV/1u+ckWxXDs+9ZMTXW4GsEGnwa5sjown7yrY0X8gbZQFa3Aq2aXUsWBw0EkysDVAQbFlp+YvrpBG11tq6R757DSb9Ub4Yg0xrBCqfqBHZgFf4oq1WQvYFgsdNUeeB6SSUxlIAmnBh9cuP9ex1kgSsZgixtAxv4eCcRjAJdxrEnTuuv067GaifEONauBorWCyMu92QvE1ycCjFt7mZribmjI92BV2ysb9YiJh2EwumW9tDjSjAl+YP84o1m6/18PZkCj2KhpX1HgbO9MxKA0GhUZClFZtty/R+ozWDZUURfJV3/bDgPMdrSDu+D/9aRTAj6IR2VOEQLOl1VsYXCmmjiMR5l2krI6LjXUMY27gNhUXx0o0KeFJHA0eFtbhVaEFLwJGgKiGNtldsv7WxVKt1eNKTVYzd3nbCvlU1HOmKxLjjw3628UIRhdvkKWt4ENBfsF4ULsDAuJt440G9dpe8+Sj363cJSxllJJqA0j41XptnvwkMqKRh9ByVH6zGzS8XNZdgPOjNVQW2Ac5h1r7qd3r9oqRayOxBv65E3Ftxg991Ll1UAhNb3P9jWwHSyKNhvY7FaYya07IHSpgJmR4giwA/oLeLWIkKZmHvY/dqQtnUtKCB2aYUOxKY/aEfmeYpHhFvPFSGnjPgDWPv8083iNSHFdNantB+JPflYdLUWO8bhQCADpyJJKx/aLYbVkm5ZNTMf+T0WstgkusHUNlpJc3CZd3bIRBnUqcXu4XYeTg2X43U2gMSwr2vNzqg0rhAVjK3vBODvUP80hIx9Wdf79rkCT/aI45/5AB6TcG3h+LDuJk7STk6kV8z9TkLB/m14rwdRqUuguAxLFEVXVJyAuoWRgfo/qmjwc/kfN7PnIFoVpNEWzak+7SiJBhlUwG0Z2TKqy7dzxQcN1tHs68i4ZmZRuwfcepMt3KOpj5CuXqCiKGsMLShmw2I8xBjFXBQU53Vjwq7TV1uR5jiUTUAz4NsDofiSxdEJDdV+ALGVhb7rIN0FWUjuKOtaPpzqn09mspLpuzf9xNqKGkr4DY7eZkd8lZv7IvtK1WSUxSAq4R5LhGpc0N9uMpEdL6I5ao6LFuqG5X3QH7XfdMyhJSA+tTaz/BJG3tHNWST4JiZtHVL63EmK/IixwiCeJf/MktiCa7ueRhafWagVs6QJPsrxQ1cRN1Im9LhgbgGCJCQ8jIQ7Y2xq4aPu2QeFFg/cPRHVytSatSwryEeb2T+OodPilP5N0iJutauAGMENrtWqGhoI3d991tEchUUtvwb87CAtQoKvYMgLQWODBToh97iR1Tf6lrmo3Q4GX0nHBLA3vI/UxoIBHwVF+UQiEBGuVMftG8e8vFToGePGnnqgyeMgV36Ob9EIN3H7kX34EtwuGJaw7RcpYZpManuQe8xSfluckYLZdj9nLetfJjq3A5uBhVKh6MXnGUEfVVUir8O4zf5ihUx6mOrpQz/5j5m9oY9gBRFo6B0= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 057db0b6-505b-4007-4096-08d9fc6a2fc9 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:05.0274 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9LZn0ADo3L0SeHSzVloQp0B2FNBo98N8iU4HesdpvX/H7acshfEQiE+uzajWM2PE4Z4wsn09DgtK80vT3MZprQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1942 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The IFLA_STATS_LINK_OFFLOAD_XSTATS attribute is a nest whose child attributes carry various special hardware statistics. The code that handles this nest was written with the idea that all these statistics would be exposed by the device driver of a physical netdevice. In the following patches, a new attribute is added to the abovementioned nest, which however can be defined for some soft netdevices. The NDO-based approach to querying these does not work, because it is not the soft netdevice driver that exposes these statistics, but an offloading NIC driver that does so. The current code does not scale well to this usage. Simply rewrite it back to the pattern seen in other fill-like and get_size-like functions elsewhere. Extract to helpers the code that is concerned with handling specifically NDO-backed statistics so that it can be easily reused should more such statistics be added. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- net/core/rtnetlink.c | 97 +++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index c484bf27f0b4..ad858799fd93 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5048,84 +5048,81 @@ static bool stats_attr_valid(unsigned int mask, int attrid, int idxattr) (!idxattr || idxattr == attrid); } -#define IFLA_OFFLOAD_XSTATS_FIRST (IFLA_OFFLOAD_XSTATS_UNSPEC + 1) -static int rtnl_get_offload_stats_attr_size(int attr_id) +static bool +rtnl_offload_xstats_have_ndo(const struct net_device *dev, int attr_id) { - switch (attr_id) { - case IFLA_OFFLOAD_XSTATS_CPU_HIT: - return sizeof(struct rtnl_link_stats64); - } + return dev->netdev_ops && + dev->netdev_ops->ndo_has_offload_stats && + dev->netdev_ops->ndo_get_offload_stats && + dev->netdev_ops->ndo_has_offload_stats(dev, attr_id); +} - return 0; +static unsigned int +rtnl_offload_xstats_get_size_ndo(const struct net_device *dev, int attr_id) +{ + return rtnl_offload_xstats_have_ndo(dev, attr_id) ? + sizeof(struct rtnl_link_stats64) : 0; } -static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, - int *prividx) +static int +rtnl_offload_xstats_fill_ndo(struct net_device *dev, int attr_id, + struct sk_buff *skb) { + unsigned int size = rtnl_offload_xstats_get_size_ndo(dev, attr_id); struct nlattr *attr = NULL; - int attr_id, size; void *attr_data; int err; - if (!(dev->netdev_ops && dev->netdev_ops->ndo_has_offload_stats && - dev->netdev_ops->ndo_get_offload_stats)) + if (!size) return -ENODATA; - for (attr_id = IFLA_OFFLOAD_XSTATS_FIRST; - attr_id <= IFLA_OFFLOAD_XSTATS_MAX; attr_id++) { - if (attr_id < *prividx) - continue; + attr = nla_reserve_64bit(skb, attr_id, size, + IFLA_OFFLOAD_XSTATS_UNSPEC); + if (!attr) + return -EMSGSIZE; - size = rtnl_get_offload_stats_attr_size(attr_id); - if (!size) - continue; + attr_data = nla_data(attr); + memset(attr_data, 0, size); - if (!dev->netdev_ops->ndo_has_offload_stats(dev, attr_id)) - continue; + err = dev->netdev_ops->ndo_get_offload_stats(attr_id, dev, attr_data); + if (err) + return err; - attr = nla_reserve_64bit(skb, attr_id, size, - IFLA_OFFLOAD_XSTATS_UNSPEC); - if (!attr) - goto nla_put_failure; + return 0; +} - attr_data = nla_data(attr); - memset(attr_data, 0, size); - err = dev->netdev_ops->ndo_get_offload_stats(attr_id, dev, - attr_data); - if (err) - goto get_offload_stats_failure; +static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, + int *prividx) +{ + int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; + bool have_data = false; + int err; + + if (*prividx <= attr_id_cpu_hit) { + err = rtnl_offload_xstats_fill_ndo(dev, attr_id_cpu_hit, skb); + if (!err) { + have_data = true; + } else if (err != -ENODATA) { + *prividx = attr_id_cpu_hit; + return err; + } } - if (!attr) + if (!have_data) return -ENODATA; *prividx = 0; return 0; - -nla_put_failure: - err = -EMSGSIZE; -get_offload_stats_failure: - *prividx = attr_id; - return err; } static int rtnl_offload_xstats_get_size(const struct net_device *dev) { + int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; int nla_size = 0; - int attr_id; int size; - if (!(dev->netdev_ops && dev->netdev_ops->ndo_has_offload_stats && - dev->netdev_ops->ndo_get_offload_stats)) - return 0; - - for (attr_id = IFLA_OFFLOAD_XSTATS_FIRST; - attr_id <= IFLA_OFFLOAD_XSTATS_MAX; attr_id++) { - if (!dev->netdev_ops->ndo_has_offload_stats(dev, attr_id)) - continue; - size = rtnl_get_offload_stats_attr_size(attr_id); - nla_size += nla_total_size_64bit(size); - } + size = rtnl_offload_xstats_get_size_ndo(dev, attr_id_cpu_hit); + nla_size += nla_total_size_64bit(size); if (nla_size != 0) nla_size += nla_total_size(0); From patchwork Wed Mar 2 16:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766268 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 2E9D7C4332F for ; Wed, 2 Mar 2022 16:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242205AbiCBQdJ (ORCPT ); Wed, 2 Mar 2022 11:33:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242353AbiCBQc5 (ORCPT ); Wed, 2 Mar 2022 11:32:57 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AA62CD331 for ; Wed, 2 Mar 2022 08:32:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cmWJ03hGGLvfSPKwK0CsBYjm7PoSs5k+IM7oanmG6TL43A5SWau6KpCl31Mqx7K+oCdZyY0R3yyR+AzV6FBH0GVBZ674T6CmaAv26G8nXsEUf7fble2y7+70zsEWYTXSMprVptUAn6ftcl623PYuf1Giu9TK4JYIIGxmFrjwXc+jKAPh4NJgYZt6fvSxvPE+8CVZYQUKmkt4QBp1VKgr/PX+IWZBl5SbGoq3/KzIROLhw1cVT/+s8VvASbiCzT7GmqCbGDsFgLTDBKRXzhC5lNlxqWiX6n/XyE0bGUQJeXTva7/NEsOwf7Zy8O1kLiyqtqHEbkGgadaRgV7g0MoGUQ== 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=GwrRhRVma3ZW3GvPTWuaYKBI+oAyrQkLndkcbmTOmT0=; b=eAbJB5rIHqsp5RNyP/oOLrtBESI5BQiyCmM0EgWdIxmY1yDCoEAcUduWZ41swIrdSiYx7Z4AnS+2D3IrtKDuxeyfJHITcqI/smbeHNEYgim+pEZ2j6N3Lx7w1McyVkFjVHVGZZbV8gpF0Iw6s5hC3MVcV8DyOoInSca+KMf02sqI3c85T17q12Mtc7cOrEO0oafX6jquPKj3xCHTdDSd26TR+ir2L4douQ5KkQ40Tdt+5UCYZg8VVef2iyWkZjgk1dBvMe9I0k58BhL1I6A1GUnWtaH0FgJPo+oT0QJRbBXbdyZV0fucMItzRfwedJ0HOld7GrdlaOeLhi8ahWZXMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GwrRhRVma3ZW3GvPTWuaYKBI+oAyrQkLndkcbmTOmT0=; b=i5NH4YgFjrJkGoy2fwd9ow2xQ5ky8t+X3TiRdEQkvbPiCzv44CNajCgRZ4c5vBmUeCy/+CrpXOc6aYwsBrunEo5HdLIE+SNrbJuki9K/WY+toBzy/g2yty/Z8G0NNx3a1NLVTVNRX05LXzfRP0YuUPQPnTIL7P7XWcdXhM7HbpNLQbN2wx9KzGISaO3dmALHi56+OiotC31zUHPwzh4ikhnuc6qCq+UubAxqq8R4gwatnLWRLiZviRFwxSzPdDCfAMvfzGR4bNdhXZlt2Gv3+oQUvZ5loF663Q/csCuI8Zd6z0MnvacBkHJxkwCjHP+1Q5iqnuESRh7oJq6J5WwOYQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by CY4PR12MB1942.namprd12.prod.outlook.com (2603:10b6:903:128::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 2 Mar 2022 16:32:11 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:11 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 03/14] net: rtnetlink: RTM_GETSTATS: Allow filtering inside nests Date: Wed, 2 Mar 2022 18:31:17 +0200 Message-Id: <20220302163128.218798-4-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR08CA0142.eurprd08.prod.outlook.com (2603:10a6:800:d5::20) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2516ecf6-c44c-457f-97cb-08d9fc6a336b X-MS-TrafficTypeDiagnostic: CY4PR12MB1942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RlNSURkRojD40f99ZK2Q61uR7hebaW6MpYh+LDxMq/LC+ErfSbgmVW7UA5l/0LwVQgiFkzwFRjTFB7di1J1rvYRXpD9j4biV63w3dssH5WhFVejL6ng3XuE1kDO6ZdDYqeWN28YMtMNYsvWNHKisxBn60xoj0iRm0tX4wE5otwXlzLic694cMFmuAQ+9JAioEkwe8uUGyusJGgBaAAXRhkjB/GAyCMfdv3N2BTXj39S7C7zLfa/l91Eyiwifc2+SS8O+weI/beV68Sy6vR2DBnBSlVZAgrKKSVaTBp1snVvMLwr0ATGfVuzJy4lpKE+ySdZ0lIvaF6dBpmOXyGGauOIpyqyg0OKvJak1Vz5LNi7crztLh5eKmPf5mb88DYVyloTOO5hdnrT9d8c8xHeX+tRwlm+Zc2kz1PCJ8Obn7qhoXxxBZl/IebQKDKC5RNdzIrx0D1KMK1Ke1xBhC1JTGCVLxG5PMPiJAiux+fVxWAVUdeZIMfgjTR/gbKiGRcLtY7TvO2j0ZswWQCzIfvCmo+66BnbBC+W8QIBXL7jamZztw0oontqmXCJ8TkZ8YOLhiMqvZwlRDeXMkavIm3m3qv88vOXR2V+zivjRU21iGCpCyuaYdoeQu1n93kZnE1mVrEbQPT8QswiDDmdbq32rnNYQZ7TGgD8iDCb9Ya6zBKpNKG1BDpWIWP79XRpJrJQLVSreVleYvW4fFU3MZnMpZQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(36756003)(2616005)(86362001)(26005)(186003)(1076003)(6916009)(316002)(107886003)(4326008)(66476007)(6506007)(66946007)(6512007)(66556008)(8676002)(6486002)(508600001)(2906002)(83380400001)(30864003)(8936002)(5660300002)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0QVMsRpZEiGsXbWLxI0KwYo57aHe69gy5LjawqN3EpPkxswjoN+80vcXN/cdJIixoVn1dzOQ2jdYYz6Cq3prtVS//ClOsD3r0wVA1TRm/5CqgdbHeeLgejlgfD93Ej0hGSg8ej5wodF05bbHmz+iVEm9iCA2G60vEm/1QlllAnU59+HCmy9BU2gaqZbqMNMZCpJ7giR9IjhPFNZ+nRkgKGZlMy9OIeBxKhuDhssWLve7h37bwGcmuynQNnmtayRW4oVhmOfgyk189W5RIbPzANA0wicuFGzDoAeCfkrol4AZ/UT2SQyKNTzMg6nyMaGox8vECDb7+pYpSV7fTf6eaSCMlYhEj25PJp2uSjLyb2Rfbso34BMShYroGPlWht3lCvA1+Pvuh9wjEa1JiguitJZnLCSmEEN7d2RRfLhtDXP/R+x50E4a/ggs3/daVQtW6GE6XqtcgrTkMHxugyrcLeX2fcJ2Kosuly0F0Cm3maGoFo/1oEwZSRGIhqm9JYZ2N8wbnxcYsILnvy3UVk1v5wuyorvMFfyBIJhlwm/LWFzpwmUK0T+oLtEzlOTTb1mbGCB3Hzp7ePJd6jENH/Rjhj4ggj1OUoQYZyfNQbifmrnTPvrVx7C0XW/V8j9uI/+gqquZhH2dqGVeGjvs11Kl1f1MOn1kKHnPyThI4jziTfe6fmAWwMsKeJt09aj13znGDRxbbrdkXnCgfLcnJP6h9+E/KCQ32qG4bhnUFjWmdKjkv5aHlLSZd9RLtpiWP+okE1equx6q9D/YfU3uVxHNUTfYi9b9l+LmkQ1bP1nhOspltc183U+ne5WVUUcFGQMF8CknyvqglAVKK2srHczog9pyXTPHguWdadoySm77+115HRo/pvR07Xl/kH2LA0KibB07t7J/c4u/akqJLy+SuUuEA4o2I6T12IvyiMaPDmll/59hNxJBMnWOYujvqgHXz9M0Mzi3TXYuGoIDIipQKItjYgwY+5/JvYtOKZNCgZ3OFavxFXzcS2YomqMiR7z0Qz6N+A2zXOkseuwLI4VHIfq2nvkpY/NafPJuRg5RABbmYbC0aQK2luf8IRgNz2DUnGf8p3z7zMJt5EKrIme9id+4YhwJdTnbt9UM0rzmzkW9k3abUjBPq/o+aL4R/Z1PT/jCuDW7r3La8MTv2SnOpfJgNlHHGsfOGPbBSOXSKzhi7Nn/dIK7EvbkYBUuuqaC5HkpIN8dxFAWmRzkyX2KjN9PMDIdgtFfKP9QGqnM78oJECZiGQcJFMqVMatQqh/NPt5OkjFQSZugiDsSYjlznoCSw859LgJc0uVG2OIwDwcmHzi0f2lMAK59cT2j2qB8Kguipgequpdx0BnJDas+hbqN+BDzsrTFQqiM4aR5BlpIA7ecJfCeesqNGQKuPCFB6Gr6ddn7cF234KvJaPu4NF/sjnFFv3WNaQ9T/VhI9ySnLCWgs6hvlnXWVAOZL04uAX6tA47F4ewAkNaMLoibxC8DrTQTZAsXDVIucJ17FQi0rsCMv6Tp2J74tqigi0fPsTEpYyk4yxWyaILixg2yOTWp5uce/whoZr42ltN7H0qhyWHfCK1B1S+fwmn4fCKUOY+PjlYmKIyDxtSQGKyh0X2svUToP0M79LSAqOvIbgE= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2516ecf6-c44c-457f-97cb-08d9fc6a336b X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:11.1557 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1GAEBcU6rLbpJUpu80EYE7oTD5SWx+eUDyB1lYt4jx5P9b1NH+zEgd52qmQYSNuQB/gPP/DzqJgzXAq/GyRLdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1942 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The filter_mask field of RTM_GETSTATS header determines which top-level attributes should be included in the netlink response. This saves processing time by only including the bits that the user cares about instead of always dumping everything. This is doubly important for HW-backed statistics that would typically require a trip to the device to fetch the stats. So far there was only one HW-backed stat suite per attribute. However, IFLA_STATS_LINK_OFFLOAD_XSTATS is a nest, and will gain a new stat suite in the following patches. It would therefore be advantageous to be able to filter within that nest, and select just one or the other HW-backed statistics suite. Extend rtnetlink so that RTM_GETSTATS permits attributes in the payload. The scheme is as follows: - RTM_GETSTATS - struct if_stats_msg - attr nest IFLA_STATS_GET_FILTERS - attr IFLA_STATS_LINK_OFFLOAD_XSTATS - u32 filter_mask This scheme reuses the existing enumerators by nesting them in a dedicated context attribute. This is covered by policies as usual, therefore a gradual opt-in is possible. Currently only IFLA_STATS_LINK_OFFLOAD_XSTATS nest has filtering enabled, because for the SW counters the issue does not seem to be that important. rtnl_offload_xstats_get_size() and _fill() are extended to observe the requested filters. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- include/uapi/linux/if_link.h | 10 +++ net/core/rtnetlink.c | 141 +++++++++++++++++++++++++++++------ 2 files changed, 128 insertions(+), 23 deletions(-) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index e315e53125f4..4d62ea6e1288 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -1207,6 +1207,16 @@ enum { #define IFLA_STATS_FILTER_BIT(ATTR) (1 << (ATTR - 1)) +enum { + IFLA_STATS_GETSET_UNSPEC, + IFLA_STATS_GET_FILTERS, /* Nest of IFLA_STATS_LINK_xxx, each a u32 with + * a filter mask for the corresponding group. + */ + __IFLA_STATS_GETSET_MAX, +}; + +#define IFLA_STATS_GETSET_MAX (__IFLA_STATS_GETSET_MAX - 1) + /* These are embedded into IFLA_STATS_LINK_XSTATS: * [IFLA_STATS_LINK_XSTATS] * -> [LINK_XSTATS_TYPE_xxx] diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index ad858799fd93..31aa26062070 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5092,13 +5092,15 @@ rtnl_offload_xstats_fill_ndo(struct net_device *dev, int attr_id, } static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, - int *prividx) + int *prividx, u32 off_filter_mask) { int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; bool have_data = false; int err; - if (*prividx <= attr_id_cpu_hit) { + if (*prividx <= attr_id_cpu_hit && + (off_filter_mask & + IFLA_STATS_FILTER_BIT(attr_id_cpu_hit))) { err = rtnl_offload_xstats_fill_ndo(dev, attr_id_cpu_hit, skb); if (!err) { have_data = true; @@ -5115,14 +5117,18 @@ static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, return 0; } -static int rtnl_offload_xstats_get_size(const struct net_device *dev) +static int rtnl_offload_xstats_get_size(const struct net_device *dev, + u32 off_filter_mask) { int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; int nla_size = 0; int size; - size = rtnl_offload_xstats_get_size_ndo(dev, attr_id_cpu_hit); - nla_size += nla_total_size_64bit(size); + if (off_filter_mask & + IFLA_STATS_FILTER_BIT(attr_id_cpu_hit)) { + size = rtnl_offload_xstats_get_size_ndo(dev, attr_id_cpu_hit); + nla_size += nla_total_size_64bit(size); + } if (nla_size != 0) nla_size += nla_total_size(0); @@ -5130,11 +5136,20 @@ static int rtnl_offload_xstats_get_size(const struct net_device *dev) return nla_size; } +struct rtnl_stats_dump_filters { + /* mask[0] filters outer attributes. Then individual nests have their + * filtering mask at the index of the nested attribute. + */ + u32 mask[IFLA_STATS_MAX + 1]; +}; + static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, int type, u32 pid, u32 seq, u32 change, - unsigned int flags, unsigned int filter_mask, + unsigned int flags, + const struct rtnl_stats_dump_filters *filters, int *idxattr, int *prividx) { + unsigned int filter_mask = filters->mask[0]; struct if_stats_msg *ifsm; struct nlmsghdr *nlh; struct nlattr *attr; @@ -5210,13 +5225,17 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, *idxattr)) { + u32 off_filter_mask; + + off_filter_mask = filters->mask[IFLA_STATS_LINK_OFFLOAD_XSTATS]; *idxattr = IFLA_STATS_LINK_OFFLOAD_XSTATS; attr = nla_nest_start_noflag(skb, IFLA_STATS_LINK_OFFLOAD_XSTATS); if (!attr) goto nla_put_failure; - err = rtnl_offload_xstats_fill(skb, dev, prividx); + err = rtnl_offload_xstats_fill(skb, dev, prividx, + off_filter_mask); if (err == -ENODATA) nla_nest_cancel(skb, attr); else @@ -5281,9 +5300,10 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, } static size_t if_nlmsg_stats_size(const struct net_device *dev, - u32 filter_mask) + const struct rtnl_stats_dump_filters *filters) { size_t size = NLMSG_ALIGN(sizeof(struct if_stats_msg)); + unsigned int filter_mask = filters->mask[0]; if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_64, 0)) size += nla_total_size_64bit(sizeof(struct rtnl_link_stats64)); @@ -5319,8 +5339,12 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev, } } - if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, 0)) - size += rtnl_offload_xstats_get_size(dev); + if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, 0)) { + u32 off_filter_mask; + + off_filter_mask = filters->mask[IFLA_STATS_LINK_OFFLOAD_XSTATS]; + size += rtnl_offload_xstats_get_size(dev, off_filter_mask); + } if (stats_attr_valid(filter_mask, IFLA_STATS_AF_SPEC, 0)) { struct rtnl_af_ops *af_ops; @@ -5344,6 +5368,74 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev, return size; } +#define RTNL_STATS_OFFLOAD_XSTATS_VALID ((1 << __IFLA_OFFLOAD_XSTATS_MAX) - 1) + +static const struct nla_policy +rtnl_stats_get_policy_filters[IFLA_STATS_MAX + 1] = { + [IFLA_STATS_LINK_OFFLOAD_XSTATS] = + NLA_POLICY_MASK(NLA_U32, RTNL_STATS_OFFLOAD_XSTATS_VALID), +}; + +static const struct nla_policy +rtnl_stats_get_policy[IFLA_STATS_GETSET_MAX + 1] = { + [IFLA_STATS_GET_FILTERS] = + NLA_POLICY_NESTED(rtnl_stats_get_policy_filters), +}; + +static int rtnl_stats_get_parse_filters(struct nlattr *ifla_filters, + struct rtnl_stats_dump_filters *filters, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[IFLA_STATS_MAX + 1]; + int err; + int at; + + err = nla_parse_nested(tb, IFLA_STATS_MAX, ifla_filters, + rtnl_stats_get_policy_filters, extack); + if (err < 0) + return err; + + for (at = 1; at <= IFLA_STATS_MAX; at++) { + if (tb[at]) { + if (!(filters->mask[0] & IFLA_STATS_FILTER_BIT(at))) { + NL_SET_ERR_MSG(extack, "Filtered attribute not enabled in filter_mask"); + return -EINVAL; + } + filters->mask[at] = nla_get_u32(tb[at]); + } + } + + return 0; +} + +static int rtnl_stats_get_parse(const struct nlmsghdr *nlh, + u32 filter_mask, + struct rtnl_stats_dump_filters *filters, + struct netlink_ext_ack *extack) +{ + struct nlattr *tb[IFLA_STATS_GETSET_MAX + 1]; + int err; + int i; + + filters->mask[0] = filter_mask; + for (i = 1; i < ARRAY_SIZE(filters->mask); i++) + filters->mask[i] = -1U; + + err = nlmsg_parse(nlh, sizeof(struct if_stats_msg), tb, + IFLA_STATS_GETSET_MAX, rtnl_stats_get_policy, extack); + if (err < 0) + return err; + + if (tb[IFLA_STATS_GET_FILTERS]) { + err = rtnl_stats_get_parse_filters(tb[IFLA_STATS_GET_FILTERS], + filters, extack); + if (err) + return err; + } + + return 0; +} + static int rtnl_valid_stats_req(const struct nlmsghdr *nlh, bool strict_check, bool is_dump, struct netlink_ext_ack *extack) { @@ -5366,10 +5458,6 @@ static int rtnl_valid_stats_req(const struct nlmsghdr *nlh, bool strict_check, NL_SET_ERR_MSG(extack, "Invalid values in header for stats dump request"); return -EINVAL; } - if (nlmsg_attrlen(nlh, sizeof(*ifsm))) { - NL_SET_ERR_MSG(extack, "Invalid attributes after stats header"); - return -EINVAL; - } if (ifsm->filter_mask >= IFLA_STATS_FILTER_BIT(IFLA_STATS_MAX + 1)) { NL_SET_ERR_MSG(extack, "Invalid stats requested through filter mask"); return -EINVAL; @@ -5381,12 +5469,12 @@ static int rtnl_valid_stats_req(const struct nlmsghdr *nlh, bool strict_check, static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { + struct rtnl_stats_dump_filters filters; struct net *net = sock_net(skb->sk); struct net_device *dev = NULL; int idxattr = 0, prividx = 0; struct if_stats_msg *ifsm; struct sk_buff *nskb; - u32 filter_mask; int err; err = rtnl_valid_stats_req(nlh, netlink_strict_get_check(skb), @@ -5403,19 +5491,22 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh, if (!dev) return -ENODEV; - filter_mask = ifsm->filter_mask; - if (!filter_mask) { + if (!ifsm->filter_mask) { NL_SET_ERR_MSG(extack, "Filter mask must be set for stats get"); return -EINVAL; } - nskb = nlmsg_new(if_nlmsg_stats_size(dev, filter_mask), GFP_KERNEL); + err = rtnl_stats_get_parse(nlh, ifsm->filter_mask, &filters, extack); + if (err) + return err; + + nskb = nlmsg_new(if_nlmsg_stats_size(dev, &filters), GFP_KERNEL); if (!nskb) return -ENOBUFS; err = rtnl_fill_statsinfo(nskb, dev, RTM_NEWSTATS, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, - 0, filter_mask, &idxattr, &prividx); + 0, &filters, &idxattr, &prividx); if (err < 0) { /* -EMSGSIZE implies BUG in if_nlmsg_stats_size */ WARN_ON(err == -EMSGSIZE); @@ -5431,12 +5522,12 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) { struct netlink_ext_ack *extack = cb->extack; int h, s_h, err, s_idx, s_idxattr, s_prividx; + struct rtnl_stats_dump_filters filters; struct net *net = sock_net(skb->sk); unsigned int flags = NLM_F_MULTI; struct if_stats_msg *ifsm; struct hlist_head *head; struct net_device *dev; - u32 filter_mask = 0; int idx = 0; s_h = cb->args[0]; @@ -5451,12 +5542,16 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) return err; ifsm = nlmsg_data(cb->nlh); - filter_mask = ifsm->filter_mask; - if (!filter_mask) { + if (!ifsm->filter_mask) { NL_SET_ERR_MSG(extack, "Filter mask must be set for stats dump"); return -EINVAL; } + err = rtnl_stats_get_parse(cb->nlh, ifsm->filter_mask, &filters, + extack); + if (err) + return err; + for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { idx = 0; head = &net->dev_index_head[h]; @@ -5466,7 +5561,7 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) err = rtnl_fill_statsinfo(skb, dev, RTM_NEWSTATS, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 0, - flags, filter_mask, + flags, &filters, &s_idxattr, &s_prividx); /* If we ran out of room on the first message, * we're in trouble From patchwork Wed Mar 2 16:31:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766269 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 52AB2C43219 for ; Wed, 2 Mar 2022 16:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242403AbiCBQdM (ORCPT ); Wed, 2 Mar 2022 11:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242580AbiCBQdC (ORCPT ); Wed, 2 Mar 2022 11:33:02 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2087.outbound.protection.outlook.com [40.107.94.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB1F3CD33A for ; Wed, 2 Mar 2022 08:32:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H/6wFgWjSx5ke+FOOLAjFiZ4q/D4lCv6Fj1Z2lfDqIRSVcr7FeRpihe8vMn8Ic7IFVI5KR6v/KlNkLZWUUHtJ7I/HV84l/yAQN8zjhzCzDL2ZspX5C2GGqKEHwCzHdLozvxc4qTkAI0Rv7lSaLdOOkudPkIDmlvAlY2JbyWafzxGLrbHxfJ9FzZWvxXwAGKl5jeOtJ/ssuQftjLqRl9DIemJMtFLpOpEumaAv7oDX21bjwdZsvcDl7Gi311XOhuIItPAcXci6IhY0CVaFIOJ7CnHxtV+x7ofAqoJl2YlH9NfZJ/llre9TLAQKfApc10HWEODTAMAgSPxQjvZOP1Qsw== 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=rHqjnoH/JZq+goiRWF8FpvScZ7Bv3IHryMtDQKet7oE=; b=cbxXv5Ih1u4jhxFaGYOuYDs4sKrjcnrj3Z5V8RTpdMGx6pjErXrQdjyKG+Otmf4HyIX752SbJXlv/8ewdkfdhNBSWwAIxg2PzwS6BTPvZD9ATsosYxxYhOrFbolLnV/oYmaU4csaPeXIhe1EoQh//F00iES/QyTA5e8/UXkxM1hQd0muCzNeqlc1PAHt6AE5ht40s2a6ioMN8oBR/ET/ys6VkcQ3dOmyB6BWETli6ylvkS2YqW9vBS+XwOBv+1C/Sbl4sClHD5ER1ACNpXcKEU04lOPD/wK91Lyisb604eq6qBqMqA60seLANRzC3fvFHbND74oC/iPtkGyipZC0Fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rHqjnoH/JZq+goiRWF8FpvScZ7Bv3IHryMtDQKet7oE=; b=sgIr0dCbonqe3fQG5mbj/YMyR2fc4onbXnKTAr6Ckh8DwRYzYTtBq5Y1fDKOO6HIdchOmCvxLtcVREl7PjUj0YUJh7iHGVoCmr4mtx7hWizGOTA8rYncypXcHruMUzNbkBVeXCMR3fxuEOk2NrB4+pam/nHjv3vZN1HhI1Ml3YZy4fBAg2Bs3V3vhOeRLJZVn0NlWn7QCSFkXN2R/ZrYZ7IkSdu5DbIsxzRkHC22TpPEifJtsCswAH3N6s+btEdBEVt07C5FjV2yk/zh8+AM2SJ28q2DT9/bfWgYmvL9Ud1h8vpy/LvEFmPy74urxiHYOrOQT4wiSm1czONLUGDKsw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by CY4PR12MB1942.namprd12.prod.outlook.com (2603:10b6:903:128::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 2 Mar 2022 16:32:18 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:17 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 04/14] net: rtnetlink: Propagate extack to rtnl_offload_xstats_fill() Date: Wed, 2 Mar 2022 18:31:18 +0200 Message-Id: <20220302163128.218798-5-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VE1PR08CA0019.eurprd08.prod.outlook.com (2603:10a6:803:104::32) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db316f0b-cc9c-429b-5d21-08d9fc6a3780 X-MS-TrafficTypeDiagnostic: CY4PR12MB1942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bu6vJdeAe08KxoH2rnOPpid71+58twDWmej87uQ48c/meBDIw/M26/YOIF0cmIMwU30LJMxUGjXLrdDFj2LfZoI5MDA7Ye9D1ZwjbkItA+JGkrztF3ESazPd/tqeqUnaYTVq/N7fVCtctG7USTu/S994VhJuJRFjJE2Lzsz+VbiVe+tUuKTMFnFugJiZ0QGqZtrgqKs8MvT9xfoAyGymYZ/aYrMumpRbrq0sbcnsJgYYuYcwA9n1W5UuVp462pYO4ckfGDrQDmbvtFzPqULNLwO8sreXQ09Ojn2RLNDgddTUPdmDyoRcMGpP3Bl7baj+feD27fe3ve09bFHw7Bl1va+/fhI5AugIiVD1qVKV2PpXOZIWU+LLSvgmoKq0tKMlgI3w1pGMNo9XPVoAEmj6yN4XAywLnrNEcNk+eLp/Z+ghvSvygySms2d447FheXOT4gkwI9gtYVngc0BSFowmmBL8ErKZ39xHSZB+fXY4oQgvWkYWaO1luLruvWY7ItBL00+xBBW1Pl53AceYPo3CqFXialW4cYhITUypM2Hls7RPUu8RyA/Vd9vupALbbA75eyVwC8DpUbjRPH7aqOafuLojIo6TNSpEP31RzTM6IczhvhM66ppakdOUYLgtU2DLa9sB5Zy+VPpp/cLKKRe75w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(36756003)(2616005)(86362001)(26005)(186003)(1076003)(6916009)(316002)(107886003)(4326008)(66476007)(6506007)(66946007)(6512007)(66556008)(8676002)(6486002)(508600001)(2906002)(83380400001)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dWKxdB4bA6X9EYIoUMfWvddW6i3jTLzH5SOisXb26j9BAs+pTHlcZnbo0M1gbmV335lDDIyrSJ+Iw6iWY9La4E4N0yzAhsEV/7oSHDfAg0Tb/N+T++dXLqj3IoDwt0zS3bCSOCRGWz8jFE9d2s+kuoSdX1uXnJ4apB3tbE33TZqSHbucSyFYNxhnLITgd4ReGN/IN9zXLYEkpOg9PSnguVA2SqGHCSnO/BvRrzuCfnr79uru3urbGsIDagVKOGnuIsbgdKNQVf/sRcgsmOWqvP/+gUVwqZZPVf8NumPMYp41dsT7ybEOcU8q9y+zDF4zojNO5aHLrofevCZY9A0YfAO9aoWg8HsRvI/2xIH6D/0ijbVSnuWnhvF44mJftk9byhZGrSZXpUf6ETiLpBc1UGDwpi/Yw9lqBI2798LPVE9oYqGSVBaq54M9gcKIUTSu7rUu1hxoBuqhXFSL3dfFEOIaATGXaKb8SYNQznqzivoOXXTr6iUTEeecaNLxUzVU6tOJG6mgGcEXnoy6o9Tjek+Qv6BGj5MlFkbhqMq6F3JZWo0xFVB/revcvO6fuv2S+9ZMAP6sRoITIMPY37efaKplj6j0/0E4jrj7CiLDEokcemNBYoPZplKF3BhCBiy23UKwyg7cm6KXxZOIbmCFDqckuThPE4GlfoBRzDSBTQzeg099fMyXjqq7s7e3zZ66UDn7BLgUPeSBs60TVcWh8Skl1KVuLZ1sorfKpkdniZWD1tDVbVtqGNsW8BJRdz1EF2e9aGPoSkii+XmwKuT2zXFa/oPo75ZNn/1ChiH0n5huwEbCyaTwyDJQB8Y/ORFotBo0jie8iN5g3k0FdaumILqhRZayo1YWwABrjl/5IUc3b8EhDG9Yu1lvBgHh6RDTCy2wt/qlNRtwqmFnONEsvnwTjh1xe/NPGkMnuoG54f0MQuxx6IdV6Mrm9Eat47ccvaivsHpBlJT9Q+J8AH1F6/O8yOn8UrCE/eXrsJxcidnPhhHhyyOKXx7xkq5yxRs3/o+kQJQtaHcKMKCsySPT5SQ16MFageTrr1M5lwjkrpOPabTHF76HHxGiZIG8xnaPCrDkFR8KnwNCOJfvnXstq+dvyjL0IKQptrswEuq1oQ6o7PqqwgcD3eFvJok00tJcrXx3DXAXy6pU/VRGk9RKwWwXaTvi3mCxlmW0gdPfM/DzIk0fZMItbEE+Kt9cZqc8oi9zOmeusv+6IsRWpZqXEoZK1xERQayD62Dmf1k/h2mn9ifowca3TQHXXvO9lESRSBxA6vFTLjF101dp0NkwWFN2mTNuzSriV/rABXXONxm2Z317UcdHKglCTeEBkQsYPuqZ56y7Ezc8yQpEJPALJRYFEMCi6yGx+fxNuIp0tsJynu7HZ3x5Hr29v2rX5Nu38QspJPc7gRlWY2ObaypqbRFaGIhnGe32TB/cmSM/1h4KL+xNmf5jjuBLVI96m/SIqFsnoeG4mIlWWvr+KE3oMLZhaeeHqVqRA/f+aakF+pGcsYp7+HjS0twGRyFUbjU0k8BLfDRYxkIw94MfIuZBHNeHaRa48wm2CyrzlNz7OFrhdPspFOaN0B1ZR8y51nXmooeFxkr57VKUgln9GY1NMZ9ICJfWvJ1075v4565ca+Q= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: db316f0b-cc9c-429b-5d21-08d9fc6a3780 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:17.8465 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yjH+l3RY2TFjzs57kLMUVea0CWK+BQzdRVYzyi9bZWfya0HLVWYE0MFGAxBPQ41mGi9N1Hoo4ha7FFaSpdfkjQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1942 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Later patches add handlers for more HW-backed statistics. An extack will be useful when communicating HW / driver errors to the client. Add the arguments as appropriate. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- net/core/rtnetlink.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 31aa26062070..594aba321f42 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5092,7 +5092,8 @@ rtnl_offload_xstats_fill_ndo(struct net_device *dev, int attr_id, } static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, - int *prividx, u32 off_filter_mask) + int *prividx, u32 off_filter_mask, + struct netlink_ext_ack *extack) { int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; bool have_data = false; @@ -5147,7 +5148,8 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, int type, u32 pid, u32 seq, u32 change, unsigned int flags, const struct rtnl_stats_dump_filters *filters, - int *idxattr, int *prividx) + int *idxattr, int *prividx, + struct netlink_ext_ack *extack) { unsigned int filter_mask = filters->mask[0]; struct if_stats_msg *ifsm; @@ -5235,7 +5237,7 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, goto nla_put_failure; err = rtnl_offload_xstats_fill(skb, dev, prividx, - off_filter_mask); + off_filter_mask, extack); if (err == -ENODATA) nla_nest_cancel(skb, attr); else @@ -5506,7 +5508,7 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh, err = rtnl_fill_statsinfo(nskb, dev, RTM_NEWSTATS, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, - 0, &filters, &idxattr, &prividx); + 0, &filters, &idxattr, &prividx, extack); if (err < 0) { /* -EMSGSIZE implies BUG in if_nlmsg_stats_size */ WARN_ON(err == -EMSGSIZE); @@ -5562,7 +5564,8 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 0, flags, &filters, - &s_idxattr, &s_prividx); + &s_idxattr, &s_prividx, + extack); /* If we ran out of room on the first message, * we're in trouble */ From patchwork Wed Mar 2 16:31:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766270 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 B1E8DC433F5 for ; Wed, 2 Mar 2022 16:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242288AbiCBQdi (ORCPT ); Wed, 2 Mar 2022 11:33:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242506AbiCBQdW (ORCPT ); Wed, 2 Mar 2022 11:33:22 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2044.outbound.protection.outlook.com [40.107.94.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A9792191 for ; Wed, 2 Mar 2022 08:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BxSmWyJKYDZxboNmPLaClrVJUbaEfjZkImtw3cL0hdNgc0kx2f0FoQA1pHS8gzLM6OCEWrsKGG3bG2PZaNA3VQ/Sv2DqM8qG13w6liIGdJpVlew/BWw4DcadGtqNEVUxbkiYPb3mFU2K92L2Kjsqc2eHJX1xNJJfsKE4FIBG+cdM4OjzixfnienIVOqOUXOoFeGirj1QFcHD01tFkE+3Z6mTti+PMoKDA6DCWQp+/BlFb73Hrnw7yQd4ZDkuiiB8V6ejsqOPz3ON/BkqYfokrGtGQiUsDhzGD2FQSrwwGp9mxOPRM2CUpxg/JFE4QwoxZqU4qifrKIOyI0UM+CmcOg== 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=uypNV7VZLUKScYpCApHFh6bts3FMc9rCq4/iJyLDu6o=; b=bvZsgzm8mFe1wHkWM7iz+qrurII1J0Z5uG/Yo7WRZjqFKMoJ7BCOKJCs8B3PI/3cdoHANaQ7wD4h6JIITGK9ev0MMB4g32xyykV9F5FfD8jXUmrm+NgJapo2/spYFXgLsZQWQMFDor/tKvf4Cwv09V7ZQlVL1mpA/lnPWUmYuipA3aOSZcHWfhMf8rGK97i0+atrA8tNeRQMiliyXJx68fbjTJJ1ISx5ep+ymAnFXq33UKLuIwu5OVWfSg+KFM1AC6B0+VFhPC0g/qfpbis2EmcpXiytQEwF05x02EB57gK0KP6f8QavvsYnIeZETzC2ukYhkdhjFIAlLXvObYhPDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uypNV7VZLUKScYpCApHFh6bts3FMc9rCq4/iJyLDu6o=; b=W/b+bv3cbXvWbm5vN7HMBEyMoR3lZrUHJVQ3yPWY3NL/8K7NDwMj9hpPYtqdZ2mykouBT4p3aNJTLSAJ1mwjjtclrYrfBXntM2yOlA5xX3IN22OvZ01OILCo27bDXjg33x8UM82oXLwEPv2L9IcWYTOpGT7skzu62ACwVoKrYT9VTDlZSTIEV9U5IY/RY00ie40BNGKeLhih1kMhnd1tEzwj5I5/VNjP2OL+W8jaemsL0bPi/CNOpfzpyGAFY6yHOoIvYs7KZglWe4B3dOyHpg3wyb2ZXL2e3zy2D9UB2m9QnSfI/Oz4QG3dEUpPLWkjZnbJtNqmz/gbIPoBj2vVSg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by CY4PR12MB1942.namprd12.prod.outlook.com (2603:10b6:903:128::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 2 Mar 2022 16:32:24 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:24 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 05/14] net: rtnetlink: rtnl_fill_statsinfo(): Permit non-EMSGSIZE error returns Date: Wed, 2 Mar 2022 18:31:19 +0200 Message-Id: <20220302163128.218798-6-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0501CA0009.eurprd05.prod.outlook.com (2603:10a6:800:92::19) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6af9a791-67c9-482b-b397-08d9fc6a3b9f X-MS-TrafficTypeDiagnostic: CY4PR12MB1942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wXBA2KRF+kUHibiYNwv7NOfP5bjQKMXBGFNqU7X2g9WQAwZqu0PWTy2Nkgd/pACfLumAQR8ZL6Rhv2+c2FCO8D7L01RW+gSO0K+0dPvKLJVv8tyCpG/b60nY+2MZJSKzhgTrk5RvynD+upEaewQiUmOhW8g+W4vRUfFIchjRXyUTv6cHfKLsueS3Y0MCYqULrwSzzDRQ6wdVa3iz8ehiMyoDw2IFz8eYDggCp7LcsL+XymQ0WbTsK17b1DDqq6l4IDIyok6bDkfT4pO7piEvAFqVlz3xugkdVSxLLj+/KjAXYxp0IVqQchdHUP01imJc6qP4MobHUzD0J9qpgpsR5P8Uw+Uuu4due8MhR6iMNphn0xCSm+3SC2Q/KayOHGaRQYaTi8eP1DClOYjULsZmcVL3CjApDW44OWB3evxKAp8z7Bmp199TjBZAsJKSttmT/lZFAvf6acgpJHIJK2lU3L3dmw0WsO3Tkg5KH2dU7xFiwZtMR5vQDHUo0HsHdqak1jkF2pYjCAORGSh1c7sYLoSyVTQ8c9/n8+jtFZBQ1PGOPmtZ9ijfMshXWm8HdEY5jRIZEjF50Go7X6fSUXCny3tDV2egZYMLgr3Qxx/wDTJEMylBqEQez5abBxqs76e6ddP5JU9wbc5r5tvAa2PPDQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(36756003)(2616005)(86362001)(26005)(186003)(1076003)(6916009)(316002)(107886003)(4326008)(6666004)(66476007)(6506007)(66946007)(6512007)(66556008)(8676002)(6486002)(508600001)(2906002)(83380400001)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GBFcEtX15rpC3eSZ+BFkTITOAmR0TUuO5ZaKCUvlRGPEDQnRLqIgMnhqr+tmNBNDhe2pEk8d6zB97+DsobSXvZfwM2exn6LdsqBTWhPjSG/qoHS6XF13P6Okmsly2RbDwrVdlca2NrkIF+a0cfgKVkHMpDgXHLfr6ImeA9DXlyU9OxM/4lvCoNhFwfnGz92dNdvD64R+obz6QoN6ZZpazm+/mUN1ttcE7oaOnrQugOJ2Ij8UfL6xOQDmGKNr/9SvDzF2i6nygPZQ3yhVFe11WiU2p3HNxdIwj4Odc4m34YFxCNXgjGGMIwNUX0Z6lcaItShI3X2axSCaH6AgcmhJs8tMAxd47J18q+WdAwI5rUt331lajJ54TbUmfQOZsThWXy7hdmikxB9N2gPNYoGS1S8q+lsskiQAxyQTL009yMXNpxvsyCaLfZS5slfUMd9hen5X8NqSfkICxGfadPCp3ID29I5SK0AQeH4cN2sEWuXhPpd0Bq1wuEEqhXTb6cPU9oDpipMAxRKr5IZ191k/K7HorrGMqzk2icS8kl0+VCZLadykDko0O8ZhLqjhwMhxOkkU+GPGjt0AcS8W2j4klCWSHF8iXCpOR+LU6B6RtIm94yw8oskgRcGZ+fEQ93XcVqPrhz6wMrncscK70O+1TEElvIeKkHgEHKf5N+agUUv9c3yaubB1xBdODDin1wfwHzafY5Hhp3Ba5lvOTSB111vohI0MN3jgrq2L6+8zFHFzfLizd0kHb/ke2XZ3fNQswttGPTmQbearfg+jIPKaxmqJE58wSoMGQq1ttEBFW4WmLdT6CsapIZohYaDB8GPhXa9V0NsyyZEQjmY1wS2IoGq2jJA3i3u8yCGx8INvFH1ikTeAxdfbnSExGYAX17X0+jW2ND9nIKpQFLNJo+MogjIWXHJJLn2j2rMlnoIV1fSPi22tAS11xko9FcFV3v48nnu7NXXs55lZMNio4Acsc5pYM8HlM1NLzgOm0l6JxXAZAK4jaSoEJTZjtq0Fxcu5z/CfEtvesyqd8cT/Uo9MCkoSKPZUHL4Tj0FuYMfKypcBvnh1mZkq9iixIYyauw0gj6AiespMlnZCNzTsppeymNBeN/xc3KvKYvD9vO1XTFebaiRucfLYgjF5WNqbx6GvJgLRveipJmNyA2kmVLBq/7YwEq2SparyPxp5wOYe10nVHktoiJnBsdNSfTrq75Omxbc9k6SBmPyJFHWfEs2kN0F7q1SPHDAg/CVN5f+5JnBuS7WTMdAB9OU86XUs2pWYY/fxGd+rh+gBFUrmRJe41cXYQK4wCdqoNZFyAFYiM3fVGpQHK6JIe2+mNdhDlR6KK9UY39I/CoNv3VJHFVrZpSrDqfCSIGcfCc6QCESTwLNiBsCtPfl3wOGMe+ZxjeiqHzvneKt3+izrrjDHXbj/f0ikjQa/75bXycYOahYhseGB7C0Nh7kcE2UJxenITXcSquDFF2kGMXZ+RqlHZUdIBxWqI4Q4bk1eX6ZaWltiRrsw/JUS3DpyekY1r05Z7r0h+Mv21+3f/norSFbM6OarAU5Gx8TxKOuN6BnMLhzTm55jHgHSVGxXsjL91O8lX6hmd71dLWvcXHBDtqE0cXyihN2MZoQ8xP2ApQ1CcgiwXDk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6af9a791-67c9-482b-b397-08d9fc6a3b9f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:24.7486 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xe2If2tiXEAM+xhcBKWWomtSjTb7d5vxAcgKaWfv1HcYmZxRsIKG5YqiKOpkBASoX3q+0+1c+s8f+15tf6ak1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1942 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Obtaining stats for the IFLA_STATS_LINK_OFFLOAD_XSTATS nest involves a HW access, and can fail for more reasons than just netlink message size exhaustion. Therefore do not always return -EMSGSIZE on the failure path, but respect the error code provided by the callee. Set the error explicitly where it is reasonable to assume -EMSGSIZE as the failure reason. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- net/core/rtnetlink.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 594aba321f42..4db1d6c01a7d 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5177,8 +5177,10 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, attr = nla_reserve_64bit(skb, IFLA_STATS_LINK_64, sizeof(struct rtnl_link_stats64), IFLA_STATS_UNSPEC); - if (!attr) + if (!attr) { + err = -EMSGSIZE; goto nla_put_failure; + } sp = nla_data(attr); dev_get_stats(dev, sp); @@ -5191,8 +5193,10 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, *idxattr = IFLA_STATS_LINK_XSTATS; attr = nla_nest_start_noflag(skb, IFLA_STATS_LINK_XSTATS); - if (!attr) + if (!attr) { + err = -EMSGSIZE; goto nla_put_failure; + } err = ops->fill_linkxstats(skb, dev, prividx, *idxattr); nla_nest_end(skb, attr); @@ -5214,8 +5218,10 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, *idxattr = IFLA_STATS_LINK_XSTATS_SLAVE; attr = nla_nest_start_noflag(skb, IFLA_STATS_LINK_XSTATS_SLAVE); - if (!attr) + if (!attr) { + err = -EMSGSIZE; goto nla_put_failure; + } err = ops->fill_linkxstats(skb, dev, prividx, *idxattr); nla_nest_end(skb, attr); @@ -5233,8 +5239,10 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, *idxattr = IFLA_STATS_LINK_OFFLOAD_XSTATS; attr = nla_nest_start_noflag(skb, IFLA_STATS_LINK_OFFLOAD_XSTATS); - if (!attr) + if (!attr) { + err = -EMSGSIZE; goto nla_put_failure; + } err = rtnl_offload_xstats_fill(skb, dev, prividx, off_filter_mask, extack); @@ -5253,8 +5261,10 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, *idxattr = IFLA_STATS_AF_SPEC; attr = nla_nest_start_noflag(skb, IFLA_STATS_AF_SPEC); - if (!attr) + if (!attr) { + err = -EMSGSIZE; goto nla_put_failure; + } rcu_read_lock(); list_for_each_entry_rcu(af_ops, &rtnl_af_ops, list) { @@ -5298,7 +5308,7 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev, else nlmsg_end(skb, nlh); - return -EMSGSIZE; + return err; } static size_t if_nlmsg_stats_size(const struct net_device *dev, From patchwork Wed Mar 2 16:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766271 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 88A47C433EF for ; Wed, 2 Mar 2022 16:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242482AbiCBQdj (ORCPT ); Wed, 2 Mar 2022 11:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242308AbiCBQdg (ORCPT ); Wed, 2 Mar 2022 11:33:36 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2066.outbound.protection.outlook.com [40.107.223.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B2D62B1AC for ; Wed, 2 Mar 2022 08:32:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P25V26XmmqgCRcLEPkR4BilIpKRXAED3y4GWWcqyg0S/WF/fnqZhmgRwtvdATvxzjlCkniZdPWhzVwFK6UHq9aaBo7ZCoQEvkkULn1BhKRp9L9PrEa3aPqbJPuhAr89MET/auxSqab+PDOhRGMCu/52zQLmsr2wJDVJdzBZnxspidCYXqHueuuaAH7NeOZrFGFN3a4RJyuUNJzXC+brUnu3nwaZmg1sagLXOKdWQydhQRdHXEU0ZFq+NMXP1MJujAwkCx/Mc4EVwo0wBnnxQHCrS9HNhYlq9Uy2CIBz7+FWPcl2OGzmGWHHIkt+iG6VOHFXA8ZeWql+QJerDf14b1Q== 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=kgAyiuAA5HBNrmgZfNzyawMC0iUSmKq7GZHmgWT4f80=; b=mlCWrD43eienweUFyos6ydimHhPFlmJki3ByY/DknVznypZB4XwVDBMidRShWcCUenX42V50ibMDYdn0WHPqFWuBiCOuuyTm4TVMDrWRRw8Eujto91A6gslv69rWPnKQnEMIWfKZZV+SBC2FefW+pAjCzk2zZptCD1Yx+aGtNQS3JfrJnUuZRVgwhdvKv7DJ4/Br5YtpmPoeQ4A72RmGwre2LOwxSn656Uf16qD1hJiUg03ybgfLuMeN6qC3T9Zn11wXx5zXFOX5afDM9v0aZxSyb8fSG4lkIG+K6E2zLj2dGgTvvPoJDvUOUVruM6xwWoHpf8/IDwleMyKYbAfvsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kgAyiuAA5HBNrmgZfNzyawMC0iUSmKq7GZHmgWT4f80=; b=cBQChLOvx+1EqmjjsADqapFzvhrMSpErYjlh2myzDc2mMTwhWjeT+5RiY5XGOG9QMczk3sNImu/59Uqs4xtbzoW/3IwM/qynk2YK6QRGLxQBWoYaA5vUyO3WwOIfJrki5MqPq/3VqfYzsfKGfI9Zz4FHJ3e8ZBfLtw/DWOl7Q2jrTSfsK+TZaHSLtkzB+e2JUmMihkq+XjsTk68P7ZaYuhKL70LNQ7A1AYJCIHSNqB0u2gV5bTHLbR40S6Lp7FheCIuEKaCtsvgArbWE8eC3rFpCVJJ4vjXMZm0GkFQqyZkBfBsi+H5tVNAkJJIwNcH398wz6sVyVoMP/vxCGRvAHw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by CY4PR12MB1942.namprd12.prod.outlook.com (2603:10b6:903:128::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 2 Mar 2022 16:32:32 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:32 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 06/14] net: dev: Add hardware stats support Date: Wed, 2 Mar 2022 18:31:20 +0200 Message-Id: <20220302163128.218798-7-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0102CA0102.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::43) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fc0e826a-7aba-4e01-fac8-08d9fc6a3fdb X-MS-TrafficTypeDiagnostic: CY4PR12MB1942:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nI95pFOWMddPIqmWuHXBFIHW1fkWayX+a/V1E91hRZ/HevGhmNy4RzysUd6HMN44GYiB/fTbTjFDn67bDY4WJCF/L7QK1v8f55hX8rVGeJxxkvOr7s9dFSatBpEBVojpCbJePJ7ZOHo0RZKX7LH8Y4GBfdd6APHTcWy4suGvwF+X5tJrLSGeVv0lMn7QJ/2YD2wm2/J+6m9tsdJvDL7G1yq95CYiL9Dkl1xye+sdyqZFGUQA72pKUOYeCv5AnFKKnYqbpVVegSvdHzzk22MFeofMeBHTKd2258M1eQ9FkCq0bPoesE4MspZvrfuReM8MWDIy34tu54cUWdqN0ANLRFlHu6qZCX0N67QjL3XlCLodr9qEFjVx7owDscuD8KzfLpSXoPy1zZy/xusCZchykx+TCwcHlV+MxOuGIkO8uqmOLeaTYWOyRL3nQYtSSQJvIswdMmpfnTRymh0SaypNidBGT6TYWw3bKkEyD8AQYmuJwLOFqRp8zqFA17te3lXhh4mvfBIDLcaxFmMOZm4xYjEMHxSL2LVFXBwt2T07iWe0xR518qr4SAcZ8pKGuoMPvuYV0GTtwfjFrW4X+MpaBY874SfAUGKYP/OUPM3oYu48J3Ylcn6LOyYwYZ0QJMEo1wqCWH+c4sJ0F6UMTVmlew== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(38100700002)(36756003)(2616005)(86362001)(26005)(186003)(1076003)(6916009)(316002)(107886003)(4326008)(66574015)(6666004)(66476007)(6506007)(66946007)(6512007)(66556008)(8676002)(6486002)(508600001)(2906002)(83380400001)(30864003)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yXyzxgqj4iXkYvOFdAXf1QdB/QwbJ4Bg+ovJpLlpAkDQirYollfWHr6H41nVjJ4VtFcHzSQAPJ8pdfAITwvzY/vm7usXAtfPx34aCmrsW9AFap7oTY4ze3KDj1/FZFYlktLFAZOLq9TR/tHc9jZTKJnfQonW+j0x0My9rbwwiQX+y2IPoMWWHYIZJ6obGTul98tGp/SE43DCF84AX4KFss8sSLyu9JpU8CxoN+OOY62/oW0JzOwpSgdz0m1UAbHwHaFz1XzOFlFY6lqcFXk+aohA9TUq+SSmi3yrgIuKptKuIG+jGag2QlvWeYOSEUD4U5Z3TB3gjp+sq35/fENBXybMCNRwtcxMzo2eZje6AtgLskiTVPoQT0mZ1WYA4dxecxKfBayBJ+DxfX+hEIHJWeJZ9ValgwZmNIMzcD59pvzFiw1zzX87DUiAnsS4h/zPDMv+ejlm0Lx9aXL5OssaWP/GOoWFFrbxEVBAei09P8prhNHnV7RQoGE4RHa9Lv4YAsuRaMxo9Txf0GADGeJs6vvlXn1Wskb0iZ2CvppbZB4Bb4zv6eEmTX2Au0RZD3TtPPyHcwqFoSo4UGzjg1DGMyPIUzBfl7MwqmEPOjAC/sH199jQVroU+Vb0H+ZfGGTrz/rFLYqPkjsN688O64ANoWQLWk3p5JbqJs9tN8JkveIKNuZQq+fe1Z4WRshXSsVSOCAGcbnGPI37KxlGXzkrpJe7vuWv1QPdINqy72oiqe5c81mX/6gJg6l6Hm8rf0yOUsmwyFOtzTyV7B0P1Rj+q7PTRRNtorgGaCQr/pQQWGZfeVWO3cadiWvGvIvuWm41f+l8FU6F7Ph8B5XxKCbzE9DFB0wsAipMWtPNuonl65Cwv5imUoYz3/GoVbYV1vnwRkzveLw4NGY82rp2wqMW8nbeJk7hgaRU80RCr05SkKO7Rm2ho1Ox5QUV39WorILMWYzMG3bONufQym/bpgYQYFSEx/YwsW1lsveGcyFsLuP/Lgea0IwRkmHrZdebn5L/SOrOTZ47biH6lgeVcUfVD4hhluF5v/xpeBD9rh0KEEFuC13OrkVtUDg2qlH55ly0TrneGOkH/UFOSlXfTS12mm3e2GjwOPjtjgx1V5LXLlkJ+KLqVi5MzsQl0569jQ3meNie6iimZcILGpl4nn4WP0fnpwT0i860mFb7dxBtM8dQB9QENHxw2Gch+xxe7qQWSJyPwW3sk9lUzItrORsYmEZeOeSao6HAogohogs48r942MppUnoJdmUHgmS08bDWJZfyWmxjpyECRlTOhYq+RvAUpJe4tkfurfQK4ev9ynIT1BAtd3p4dbJ8044jr7fKEoILObBgTxSQjxH1/ZCFGAkqzb/Z8TlUXElubAteB2PPq+sZwDCdAd0143Bu2Fa9rVQnJsBzhangNgloms8HRdiBJT4jCK/TdhGD/me6ZpxYGgQE5slAL5iPOxwQXfl0LBcDuVr0uKlrpa4U8kRgRFkfAkrePzopLzueo5xRoZWG5eMInq0ZEPiG5AOIaPwwNXZWbeKR5d14gI79m0CReo32DTYOrTpBByz1fqLetwwtprslIG5pGbHo8fiYh3XpI+2b64nUV0CaKCUthgRV8raH7avm5rvverRzAcUPJwM= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc0e826a-7aba-4e01-fac8-08d9fc6a3fdb X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:32.1343 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xAqXcVxkMLo3xR5G+hP1amUnEfbcM+OLfVAR/lxgPQ7Hw8Pvw3GkBIZSSfgBh2wiNhIwjxuY9TF1uHf7oksuDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1942 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Offloading switch device drivers may be able to collect statistics of the traffic taking place in the HW datapath that pertains to a certain soft netdevice, such as VLAN. Add the necessary infrastructure to allow exposing these statistics to the offloaded netdevice in question. The API was shaped by the following considerations: - Collection of HW statistics is not free: there may be a finite number of counters, and the act of counting may have a performance impact. It is therefore necessary to allow toggling whether HW counting should be done for any particular SW netdevice. - As the drivers are loaded and removed, a particular device may get offloaded and unoffloaded again. At the same time, the statistics values need to stay monotonic (modulo the eventual 64-bit wraparound), increasing only to reflect traffic measured in the device. To that end, the netdevice keeps around a lazily-allocated copy of struct rtnl_link_stats64. Device drivers then contribute to the values kept therein at various points. Even as the driver goes away, the struct stays around to maintain the statistics values. - Different HW devices may be able to count different things. The motivation behind this patch in particular is exposure of HW counters on Nvidia Spectrum switches, where the only practical approach to counting traffic on offloaded soft netdevices currently is to use router interface counters, and count L3 traffic. Correspondingly that is the statistics suite added in this patch. Other devices may be able to measure different kinds of traffic, and for that reason, the APIs are built to allow uniform access to different statistics suites. - Because soft netdevices and offloading drivers are only loosely bound, a netdevice uses a notifier chain to communicate with the drivers. Several new notifiers, NETDEV_OFFLOAD_XSTATS_*, have been added to carry messages to the offloading drivers. - Devices can have various conditions for when a particular counter is available. As the device is configured and reconfigured, the device offload may become or cease being suitable for counter binding. A netdevice can use a notifier type NETDEV_OFFLOAD_XSTATS_REPORT_USED to ping offloading drivers and determine whether anyone currently implements a given statistics suite. This information can then be propagated to user space. When the driver decides to unoffload a netdevice, it can use a newly-added function, netdev_offload_xstats_report_delta(), to record outstanding collected statistics, before destroying the HW counter. This patch adds a helper, call_netdevice_notifiers_info_robust(), for dispatching a notifier with the possibility of unwind when one of the consumers bails. Given the wish to eventually get rid of the global notifier block altogether, this helper only invokes the per-netns notifier block. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- include/linux/netdevice.h | 42 ++++++ include/uapi/linux/if_link.h | 15 ++ net/core/dev.c | 267 ++++++++++++++++++++++++++++++++++- 3 files changed, 323 insertions(+), 1 deletion(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index c79ee2296296..19a27ac361ef 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1950,6 +1950,7 @@ enum netdev_ml_priv_type { * @watchdog_dev_tracker: refcount tracker used by watchdog. * @dev_registered_tracker: tracker for reference held while * registered + * @offload_xstats_l3: L3 HW stats for this netdevice. * * FIXME: cleanup struct net_device such that network protocol info * moves out. @@ -2287,6 +2288,7 @@ struct net_device { netdevice_tracker linkwatch_dev_tracker; netdevice_tracker watchdog_dev_tracker; netdevice_tracker dev_registered_tracker; + struct rtnl_hw_stats64 *offload_xstats_l3; }; #define to_net_dev(d) container_of(d, struct net_device, dev) @@ -2727,6 +2729,10 @@ enum netdev_cmd { NETDEV_CVLAN_FILTER_DROP_INFO, NETDEV_SVLAN_FILTER_PUSH_INFO, NETDEV_SVLAN_FILTER_DROP_INFO, + NETDEV_OFFLOAD_XSTATS_ENABLE, + NETDEV_OFFLOAD_XSTATS_DISABLE, + NETDEV_OFFLOAD_XSTATS_REPORT_USED, + NETDEV_OFFLOAD_XSTATS_REPORT_DELTA, }; const char *netdev_cmd_to_name(enum netdev_cmd cmd); @@ -2777,6 +2783,42 @@ struct netdev_notifier_pre_changeaddr_info { const unsigned char *dev_addr; }; +enum netdev_offload_xstats_type { + NETDEV_OFFLOAD_XSTATS_TYPE_L3 = 1, +}; + +struct netdev_notifier_offload_xstats_info { + struct netdev_notifier_info info; /* must be first */ + enum netdev_offload_xstats_type type; + + union { + /* NETDEV_OFFLOAD_XSTATS_REPORT_DELTA */ + struct netdev_notifier_offload_xstats_rd *report_delta; + /* NETDEV_OFFLOAD_XSTATS_REPORT_USED */ + struct netdev_notifier_offload_xstats_ru *report_used; + }; +}; + +int netdev_offload_xstats_enable(struct net_device *dev, + enum netdev_offload_xstats_type type, + struct netlink_ext_ack *extack); +int netdev_offload_xstats_disable(struct net_device *dev, + enum netdev_offload_xstats_type type); +bool netdev_offload_xstats_enabled(const struct net_device *dev, + enum netdev_offload_xstats_type type); +int netdev_offload_xstats_get(struct net_device *dev, + enum netdev_offload_xstats_type type, + struct rtnl_hw_stats64 *stats, bool *used, + struct netlink_ext_ack *extack); +void +netdev_offload_xstats_report_delta(struct netdev_notifier_offload_xstats_rd *rd, + const struct rtnl_hw_stats64 *stats); +void +netdev_offload_xstats_report_used(struct netdev_notifier_offload_xstats_ru *ru); +void netdev_offload_xstats_push_delta(struct net_device *dev, + enum netdev_offload_xstats_type type, + const struct rtnl_hw_stats64 *stats); + static inline void netdev_notifier_info_init(struct netdev_notifier_info *info, struct net_device *dev) { diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 4d62ea6e1288..ef6a62a2e15d 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -245,6 +245,21 @@ struct rtnl_link_stats64 { __u64 rx_nohandler; }; +/* Subset of link stats useful for in-HW collection. Meaning of the fields is as + * for struct rtnl_link_stats64. + */ +struct rtnl_hw_stats64 { + __u64 rx_packets; + __u64 tx_packets; + __u64 rx_bytes; + __u64 tx_bytes; + __u64 rx_errors; + __u64 tx_errors; + __u64 rx_dropped; + __u64 tx_dropped; + __u64 multicast; +}; + /* The struct should be in sync with struct ifmap */ struct rtnl_link_ifmap { __u64 mem_start; diff --git a/net/core/dev.c b/net/core/dev.c index 2d6771075720..c9e54e5ad48d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1622,7 +1622,8 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd) N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN) N(CVLAN_FILTER_PUSH_INFO) N(CVLAN_FILTER_DROP_INFO) N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO) - N(PRE_CHANGEADDR) + N(PRE_CHANGEADDR) N(OFFLOAD_XSTATS_ENABLE) N(OFFLOAD_XSTATS_DISABLE) + N(OFFLOAD_XSTATS_REPORT_USED) N(OFFLOAD_XSTATS_REPORT_DELTA) } #undef N return "UNKNOWN_NETDEV_EVENT"; @@ -1939,6 +1940,32 @@ static int call_netdevice_notifiers_info(unsigned long val, return raw_notifier_call_chain(&netdev_chain, val, info); } +/** + * call_netdevice_notifiers_info_robust - call per-netns notifier blocks + * for and rollback on error + * @val_up: value passed unmodified to notifier function + * @val_down: value passed unmodified to the notifier function when + * recovering from an error on @val_up + * @info: notifier information data + * + * Call all per-netns network notifier blocks, but not notifier blocks on + * the global notifier chain. Parameters and return value are as for + * raw_notifier_call_chain_robust(). + */ + +static int +call_netdevice_notifiers_info_robust(unsigned long val_up, + unsigned long val_down, + struct netdev_notifier_info *info) +{ + struct net *net = dev_net(info->dev); + + ASSERT_RTNL(); + + return raw_notifier_call_chain_robust(&net->netdev_chain, + val_up, val_down, info); +} + static int call_netdevice_notifiers_extack(unsigned long val, struct net_device *dev, struct netlink_ext_ack *extack) @@ -7728,6 +7755,242 @@ void netdev_bonding_info_change(struct net_device *dev, } EXPORT_SYMBOL(netdev_bonding_info_change); +static int netdev_offload_xstats_enable_l3(struct net_device *dev, + struct netlink_ext_ack *extack) +{ + struct netdev_notifier_offload_xstats_info info = { + .info.dev = dev, + .info.extack = extack, + .type = NETDEV_OFFLOAD_XSTATS_TYPE_L3, + }; + int err; + int rc; + + dev->offload_xstats_l3 = kzalloc(sizeof(*dev->offload_xstats_l3), + GFP_KERNEL); + if (!dev->offload_xstats_l3) + return -ENOMEM; + + rc = call_netdevice_notifiers_info_robust(NETDEV_OFFLOAD_XSTATS_ENABLE, + NETDEV_OFFLOAD_XSTATS_DISABLE, + &info.info); + err = notifier_to_errno(rc); + if (err) + goto free_stats; + + return 0; + +free_stats: + kfree(dev->offload_xstats_l3); + dev->offload_xstats_l3 = NULL; + return err; +} + +int netdev_offload_xstats_enable(struct net_device *dev, + enum netdev_offload_xstats_type type, + struct netlink_ext_ack *extack) +{ + ASSERT_RTNL(); + + if (netdev_offload_xstats_enabled(dev, type)) + return -EALREADY; + + switch (type) { + case NETDEV_OFFLOAD_XSTATS_TYPE_L3: + return netdev_offload_xstats_enable_l3(dev, extack); + } + + WARN_ON(1); + return -EINVAL; +} +EXPORT_SYMBOL(netdev_offload_xstats_enable); + +static void netdev_offload_xstats_disable_l3(struct net_device *dev) +{ + struct netdev_notifier_offload_xstats_info info = { + .info.dev = dev, + .type = NETDEV_OFFLOAD_XSTATS_TYPE_L3, + }; + + call_netdevice_notifiers_info(NETDEV_OFFLOAD_XSTATS_DISABLE, + &info.info); + kfree(dev->offload_xstats_l3); + dev->offload_xstats_l3 = NULL; +} + +int netdev_offload_xstats_disable(struct net_device *dev, + enum netdev_offload_xstats_type type) +{ + ASSERT_RTNL(); + + if (!netdev_offload_xstats_enabled(dev, type)) + return -EALREADY; + + switch (type) { + case NETDEV_OFFLOAD_XSTATS_TYPE_L3: + netdev_offload_xstats_disable_l3(dev); + return 0; + } + + WARN_ON(1); + return -EINVAL; +} +EXPORT_SYMBOL(netdev_offload_xstats_disable); + +static void netdev_offload_xstats_disable_all(struct net_device *dev) +{ + netdev_offload_xstats_disable(dev, NETDEV_OFFLOAD_XSTATS_TYPE_L3); +} + +static struct rtnl_hw_stats64 * +netdev_offload_xstats_get_ptr(const struct net_device *dev, + enum netdev_offload_xstats_type type) +{ + switch (type) { + case NETDEV_OFFLOAD_XSTATS_TYPE_L3: + return dev->offload_xstats_l3; + } + + WARN_ON(1); + return NULL; +} + +bool netdev_offload_xstats_enabled(const struct net_device *dev, + enum netdev_offload_xstats_type type) +{ + ASSERT_RTNL(); + + return netdev_offload_xstats_get_ptr(dev, type); +} +EXPORT_SYMBOL(netdev_offload_xstats_enabled); + +struct netdev_notifier_offload_xstats_ru { + bool used; +}; + +struct netdev_notifier_offload_xstats_rd { + struct rtnl_hw_stats64 stats; + bool used; +}; + +static void netdev_hw_stats64_add(struct rtnl_hw_stats64 *dest, + const struct rtnl_hw_stats64 *src) +{ + dest->rx_packets += src->rx_packets; + dest->tx_packets += src->tx_packets; + dest->rx_bytes += src->rx_bytes; + dest->tx_bytes += src->tx_bytes; + dest->rx_errors += src->rx_errors; + dest->tx_errors += src->tx_errors; + dest->rx_dropped += src->rx_dropped; + dest->tx_dropped += src->tx_dropped; + dest->multicast += src->multicast; +} + +static int netdev_offload_xstats_get_used(struct net_device *dev, + enum netdev_offload_xstats_type type, + bool *p_used, + struct netlink_ext_ack *extack) +{ + struct netdev_notifier_offload_xstats_ru report_used = {}; + struct netdev_notifier_offload_xstats_info info = { + .info.dev = dev, + .info.extack = extack, + .type = type, + .report_used = &report_used, + }; + int rc; + + WARN_ON(!netdev_offload_xstats_enabled(dev, type)); + rc = call_netdevice_notifiers_info(NETDEV_OFFLOAD_XSTATS_REPORT_USED, + &info.info); + *p_used = report_used.used; + return notifier_to_errno(rc); +} + +static int netdev_offload_xstats_get_stats(struct net_device *dev, + enum netdev_offload_xstats_type type, + struct rtnl_hw_stats64 *p_stats, + bool *p_used, + struct netlink_ext_ack *extack) +{ + struct netdev_notifier_offload_xstats_rd report_delta = {}; + struct netdev_notifier_offload_xstats_info info = { + .info.dev = dev, + .info.extack = extack, + .type = type, + .report_delta = &report_delta, + }; + struct rtnl_hw_stats64 *stats; + int rc; + + stats = netdev_offload_xstats_get_ptr(dev, type); + if (WARN_ON(!stats)) + return -EINVAL; + + rc = call_netdevice_notifiers_info(NETDEV_OFFLOAD_XSTATS_REPORT_DELTA, + &info.info); + + /* Cache whatever we got, even if there was an error, otherwise the + * successful stats retrievals would get lost. + */ + netdev_hw_stats64_add(stats, &report_delta.stats); + + if (p_stats) + *p_stats = *stats; + *p_used = report_delta.used; + + return notifier_to_errno(rc); +} + +int netdev_offload_xstats_get(struct net_device *dev, + enum netdev_offload_xstats_type type, + struct rtnl_hw_stats64 *p_stats, bool *p_used, + struct netlink_ext_ack *extack) +{ + ASSERT_RTNL(); + + if (p_stats) + return netdev_offload_xstats_get_stats(dev, type, p_stats, + p_used, extack); + else + return netdev_offload_xstats_get_used(dev, type, p_used, + extack); +} +EXPORT_SYMBOL(netdev_offload_xstats_get); + +void +netdev_offload_xstats_report_delta(struct netdev_notifier_offload_xstats_rd *report_delta, + const struct rtnl_hw_stats64 *stats) +{ + report_delta->used = true; + netdev_hw_stats64_add(&report_delta->stats, stats); +} +EXPORT_SYMBOL(netdev_offload_xstats_report_delta); + +void +netdev_offload_xstats_report_used(struct netdev_notifier_offload_xstats_ru *report_used) +{ + report_used->used = true; +} +EXPORT_SYMBOL(netdev_offload_xstats_report_used); + +void netdev_offload_xstats_push_delta(struct net_device *dev, + enum netdev_offload_xstats_type type, + const struct rtnl_hw_stats64 *p_stats) +{ + struct rtnl_hw_stats64 *stats; + + ASSERT_RTNL(); + + stats = netdev_offload_xstats_get_ptr(dev, type); + if (WARN_ON(!stats)) + return; + + netdev_hw_stats64_add(stats, p_stats); +} +EXPORT_SYMBOL(netdev_offload_xstats_push_delta); + /** * netdev_get_xmit_slave - Get the xmit slave of master device * @dev: device @@ -10417,6 +10680,8 @@ void unregister_netdevice_many(struct list_head *head) dev_xdp_uninstall(dev); + netdev_offload_xstats_disable_all(dev); + /* Notify protocols, that we are about to destroy * this device. They should clean all the things. */ From patchwork Wed Mar 2 16:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766272 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 907DAC433F5 for ; Wed, 2 Mar 2022 16:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242249AbiCBQdl (ORCPT ); Wed, 2 Mar 2022 11:33:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242652AbiCBQdi (ORCPT ); Wed, 2 Mar 2022 11:33:38 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D48BD3EBAD for ; Wed, 2 Mar 2022 08:32:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZmWqFpLqKFH1OGucN+CKdefB0QtUyM4vwk2dfE5N5SV3kvi1wa+CdaotnhpmxTDf+3GaKwpdQ73rkWxibJyIcFdcrwNMuOexJcAaFBr3tT7xYr+ZLezZ+zIqG9VkFWNfyeySkpf0FAgZT4wyMaNQFv+c1825sQxqh6fvOeDR11wzyGBBIE84FlssjgJd8R7PxP94t62sA2V53YT44Lidg7Se+mCnDvU/9yXs1kdJmvfVJVg2pqgR+r5uxme+/7JC9LMfUdnq2m1sczUs8SV98mwLRhYG4zau916jr8ecaNiNfaYU0jC2uy+w5eP/6G9cBJ0gHkmkBtKePkHNYIO4KA== 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=4RT8+Di9h6DqcuvqzvwtaniGNfHINMhBtbS49HHCR4E=; b=dvOZneq2YsQ426A6JgOKQurKHKi+3d4UakcibO511bI/mVW/GFmMJDr+ws+x3ZYZP/SpB9GTloqNngYLeyi0aMnfarQ87ulDYq+lqbs/gfavImpEMwCHzemhtUwpN9X1IL7axw7owRHwVMjLFt0yYzHjGEKRIp6n+gWEAuJFqaisENiOchqiGyXbA5NX/cn1o036LCYFaHI7m6CSu0+upLyUvgR/QxOXVsdKAu6HhLIeGxJ7l9bZE5O2gExARCAYGIQqO1dPS0UiHki7H3W8y4mDG6RfewhTN+tzDT5t8+noCkV7db/2Pe4wm5w5fpVL1biE43Sq95jb9rVeExNAZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4RT8+Di9h6DqcuvqzvwtaniGNfHINMhBtbS49HHCR4E=; b=dRzg8LtLjG192tZ6je4mg6o+MDcUx6l6aIwuwxTKAp//BoA4CDxAwJvzlpK2SR9jTDX+LHLDUs6QrvOJLVcMmCoS+KssnFv5CaC7CR+AkOQ5Z0FPwV8j/Uvp5tr59BPULU/6NChu+MLTToZybLbqF6DsbpfF+ceXMjkAO78slLiq8LBBgvW4/9js66diuyvRvw4xmZbwN4gb6yZZ7u5m8fG9PvYvYX/4RQ3oFGH1/+jYiZa+dNQ5obFvtYxHfYPGjAZ2G5mdpGOHK9PROFveHMedOwVhWBqU57v5cYDlyPD1Ow2qdCgl1efpF36gVwdH3FKvaFgRWyjaYpsfNY3rIw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3998.namprd12.prod.outlook.com (2603:10b6:208:16d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23; Wed, 2 Mar 2022 16:32:38 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:38 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 07/14] net: rtnetlink: Add UAPI for obtaining L3 offload xstats Date: Wed, 2 Mar 2022 18:31:21 +0200 Message-Id: <20220302163128.218798-8-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR07CA0286.eurprd07.prod.outlook.com (2603:10a6:800:130::14) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e93c8ca-f68e-4993-a0bc-08d9fc6a43ad X-MS-TrafficTypeDiagnostic: MN2PR12MB3998:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XEIFWGQ1qby818ouRFeUA5hiCEDODXcGDaxAqSYTcqOCbiZ7JE9coFINhMhQzWvMVMMFN2gIGATHJ5mC8cW7yKc+Uxx1LgAk+uV5CcEOvZbnk6WmNQO62ctR/bb9P/jqSbp6dUQsqNNdL/bFN+DMrBJ2r6YTpbp0uhS+FsjV7rT9shgijIgVSiYbgALEoDlKdpGEXDQwUBhHdxRc07+X0/q25fihIqU5n5Uc+GSFf71eelW8Ukner25lsis5xL7EdAYUA9KGCjTVf/qTV30UbpnAszufmhN5xrV/OlaFrhS2HFy7YJpcVX2/PgWZ9Be2al634mAXK4qHL6qc1ZLoeUGMsGcrOI73JB7BZQFSTNP9stOt6aen4oUeil8HuK0w+tktSBgkCX4eeI6OYQJfKV6TVgXrgSSsbU6RE78yV2zKEPFmWRvfqFsJK8knGhYJSP+Yz8pShMj6JdjBiyDIdMwvP8ID809I+Ykzq5HupGdhjoksMXnCI7WjdVZH+1GMJl536e7V0tIHtcXUCMgiXMGzg1qow4r0Xftv9BRi9rOGEN4z05CEg9WUbrNGF9lLnkZqQKLOXQbSD1C44tDhJ+5p4dDPz3inbPMzXxldeKaU2MX23oaeStBqrJERrx6uetqyqELLn0K7x4QjtFbjEA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(86362001)(66574015)(2616005)(316002)(6916009)(6506007)(6666004)(26005)(1076003)(186003)(6512007)(107886003)(83380400001)(38100700002)(8676002)(66556008)(4326008)(66476007)(2906002)(508600001)(66946007)(6486002)(5660300002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: moLfRKAD24aOXkRwBNVbJ+WsEqIhwccu/4OKNs9Ei8Z0GC3HN9wtl6GGHDDrIDKXev6mksxjbXBB5ZZy+d5LXUsN0HjJq34jAU5pp4f9E7e5e1R6N35V2lYNQEqSwBu/VwP35+7oVMCl3mTUI/wVksi30pL6nbYLkk8l8dfVc9d/V4Ma4bWGx4PIaMp9/ywySe8PHjYdXZGFKOuzfxT/W0nK6+WQ/d4ELmdL08yzHJIA3nS/Y9DQpqA5XL+MayaRc8TEXjiCDzOD60cVcGm89qo6uifFw+gyNFau16JGVo2Ykse2YKEoh66DIpUiGBy5adjEn2PzPD53Krn+VCw+TtOFeC5XXGmgjQNnnnMVOAIKmOICLr+ijT+w6kWbn+qNz2MPlEk5sRi3CpB+ihW/c3SJLaQVo8nDUvNwcKDjB4E2QCZ8J1IX2iwMPRsH9ndQOP5UrAYboyZiiP4nrTA11G0USJxYjsDYl1CONSCWRGt3lrjCPdBOH/KjXkbPGQwOpi5UOPZNtSgeFFtOabeaOCls21OVxMLhzyII34CpX3/E5nQMbe39zt/Ni0GK8JmXb8Usimhhl+Pwnxa+X0KH2+T8V0OS6TteynxEXvr4j9E1qe7x/DTHA+OItPYjPQ3/H6ai09k3fDAqim0U1LrXSP9rKduV9b/fVJwy0rBGgkQHUvuH7hKCmIK79Pu+IiMf+d7D0XEToVVMAo8TWThGy5/oBvaKOkxFT9iGq+yGJvuwz6mZFrpwdHnZ9T/rp9UwVz/KDn99iHjOtAYKVvjH17jQOO5QB394QC8VS/gw5Qe7H2qHYYXnjIguF0+P3jvYD5gn9s7rDoTK5FSNaZtdG9+WoHmVGie18DKm64FxSWSDLAlvM4SF97DoFGh6kssL2+NVCcUuuplf53tzriE392tx/KHzt228bT7kXsaxJ3GFqBcd/y30CpvsWKc2/Zrh4RbBjepHtlxPZA8OXPw0hog1Cut/clZ3l38jJAH6f5riUYKxGa5HKAbwQurX4Dy9lQ0KWN2WnAnMy0CXRsr7Hvd2cyyS0hQRIYGqAaeEkge9a7m9u195Tvi3QHRNGRXEVVRwMfeX0E1EurK7aheRvwK0orVJBOcPi1P9r7bniPRjC62cnXzfiJELiK5qG5ELNLTQvBtb3VTsdoQAyPeFSkvrhajqIm67rk64BDrtnFpwfyBEVPJL1+IoOw99oVYJlP+JJv/LVgzeCbigVY4G3qg5l4Q4rAOmFtQAWm66DezpVEcBLf/NMtXpZJdBTZ3fjDwC4wf1dxkz/+S1A8XyP07cILOHFIGknUE21NoQTz9RBSHzZPYEUhBGPDE58HpsUyHP79pCBI5vGF4uSYupVddAAeYbZ6a6YJwfO3TZUzQYEFnYONZ0q3Z2wM0KAXhY4JrQZXRIUsZ4ge3dvlEY2R0JARwRQk51OMdom8vWj32ome2zKGKNXrY0HG3lzcQpylghatwhsctcVrqgc75+Zy8Jo8ZXZP7xL1lrAtE7F15oqRcXoU/UCFla+aB5+ThY31L6tKFr6PAK2qrqSXW1MYxQAR5+VvEJAuDhmJhPxDdWWfAPwAU6+FPgyrmoFm/HWEDDmCfKpYvBF7GZUMjR8IPTULbH9fep+xHvOEg69dk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e93c8ca-f68e-4993-a0bc-08d9fc6a43ad X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:38.3227 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IGxCFMF4Xxa+3wZYJ8+VEQb24bvUWx8ABpxnEWZfAciD+kaYFtj2EtQtpmiXCySxKTeumLCBKBNZwrk2ryzsTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3998 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Add a new IFLA_STATS_LINK_OFFLOAD_XSTATS child attribute, IFLA_OFFLOAD_XSTATS_L3_STATS, to carry statistics for traffic that takes place in a HW router. The offloaded HW stats are designed to allow per-netdevice enablement and disablement. Additionally, as a netdevice is configured, it may become or cease being suitable for binding of a HW counter. Both of these aspects need to be communicated to the userspace. To that end, add another child attribute, IFLA_OFFLOAD_XSTATS_HW_S_INFO: - attr nest IFLA_OFFLOAD_XSTATS_HW_S_INFO - attr nest IFLA_OFFLOAD_XSTATS_L3_STATS - attr IFLA_OFFLOAD_XSTATS_HW_S_INFO_REQUEST - {0,1} as u8 - attr IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED - {0,1} as u8 Thus this one attribute is a nest that can be used to carry information about various types of HW statistics, and indexing is very simply done by wrapping the information for a given statistics suite into the attribute that carries the suite is the RTM_GETSTATS query. At the same time, because _HW_S_INFO is nested directly below IFLA_STATS_LINK_OFFLOAD_XSTATS, it is possible through filtering to request only the metadata about individual statistics suites, without having to hit the HW to get the actual counters. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- include/uapi/linux/if_link.h | 11 +++ net/core/rtnetlink.c | 170 +++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index ef6a62a2e15d..b1031f481d2f 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -1249,10 +1249,21 @@ enum { enum { IFLA_OFFLOAD_XSTATS_UNSPEC, IFLA_OFFLOAD_XSTATS_CPU_HIT, /* struct rtnl_link_stats64 */ + IFLA_OFFLOAD_XSTATS_HW_S_INFO, /* HW stats info. A nest */ + IFLA_OFFLOAD_XSTATS_L3_STATS, /* struct rtnl_hw_stats64 */ __IFLA_OFFLOAD_XSTATS_MAX }; #define IFLA_OFFLOAD_XSTATS_MAX (__IFLA_OFFLOAD_XSTATS_MAX - 1) +enum { + IFLA_OFFLOAD_XSTATS_HW_S_INFO_UNSPEC, + IFLA_OFFLOAD_XSTATS_HW_S_INFO_REQUEST, /* u8 */ + IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED, /* u8 */ + __IFLA_OFFLOAD_XSTATS_HW_S_INFO_MAX, +}; +#define IFLA_OFFLOAD_XSTATS_HW_S_INFO_MAX \ + (__IFLA_OFFLOAD_XSTATS_HW_S_INFO_MAX - 1) + /* XDP section */ #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 4db1d6c01a7d..9ce894a9454c 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5091,10 +5091,110 @@ rtnl_offload_xstats_fill_ndo(struct net_device *dev, int attr_id, return 0; } +static unsigned int +rtnl_offload_xstats_get_size_stats(const struct net_device *dev, + enum netdev_offload_xstats_type type) +{ + bool enabled = netdev_offload_xstats_enabled(dev, type); + + return enabled ? sizeof(struct rtnl_hw_stats64) : 0; +} + +struct rtnl_offload_xstats_request_used { + bool request; + bool used; +}; + +static int +rtnl_offload_xstats_get_stats(struct net_device *dev, + enum netdev_offload_xstats_type type, + struct rtnl_offload_xstats_request_used *ru, + struct rtnl_hw_stats64 *stats, + struct netlink_ext_ack *extack) +{ + bool request; + bool used; + int err; + + request = netdev_offload_xstats_enabled(dev, type); + if (!request) { + used = false; + goto out; + } + + err = netdev_offload_xstats_get(dev, type, stats, &used, extack); + if (err) + return err; + +out: + if (ru) { + ru->request = request; + ru->used = used; + } + return 0; +} + +static int +rtnl_offload_xstats_fill_hw_s_info_one(struct sk_buff *skb, int attr_id, + struct rtnl_offload_xstats_request_used *ru) +{ + struct nlattr *nest; + + nest = nla_nest_start(skb, attr_id); + if (!nest) + return -EMSGSIZE; + + if (nla_put_u8(skb, IFLA_OFFLOAD_XSTATS_HW_S_INFO_REQUEST, ru->request)) + goto nla_put_failure; + + if (nla_put_u8(skb, IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED, ru->used)) + goto nla_put_failure; + + nla_nest_end(skb, nest); + return 0; + +nla_put_failure: + nla_nest_cancel(skb, nest); + return -EMSGSIZE; +} + +static int +rtnl_offload_xstats_fill_hw_s_info(struct sk_buff *skb, struct net_device *dev, + struct netlink_ext_ack *extack) +{ + enum netdev_offload_xstats_type t_l3 = NETDEV_OFFLOAD_XSTATS_TYPE_L3; + struct rtnl_offload_xstats_request_used ru_l3; + struct nlattr *nest; + int err; + + err = rtnl_offload_xstats_get_stats(dev, t_l3, &ru_l3, NULL, extack); + if (err) + return err; + + nest = nla_nest_start(skb, IFLA_OFFLOAD_XSTATS_HW_S_INFO); + if (!nest) + return -EMSGSIZE; + + if (rtnl_offload_xstats_fill_hw_s_info_one(skb, + IFLA_OFFLOAD_XSTATS_L3_STATS, + &ru_l3)) + goto nla_put_failure; + + nla_nest_end(skb, nest); + return 0; + +nla_put_failure: + nla_nest_cancel(skb, nest); + return -EMSGSIZE; +} + static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, int *prividx, u32 off_filter_mask, struct netlink_ext_ack *extack) { + enum netdev_offload_xstats_type t_l3 = NETDEV_OFFLOAD_XSTATS_TYPE_L3; + int attr_id_hw_s_info = IFLA_OFFLOAD_XSTATS_HW_S_INFO; + int attr_id_l3_stats = IFLA_OFFLOAD_XSTATS_L3_STATS; int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; bool have_data = false; int err; @@ -5111,6 +5211,40 @@ static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, } } + if (*prividx <= attr_id_hw_s_info && + (off_filter_mask & IFLA_STATS_FILTER_BIT(attr_id_hw_s_info))) { + *prividx = attr_id_hw_s_info; + + err = rtnl_offload_xstats_fill_hw_s_info(skb, dev, extack); + if (err) + return err; + + have_data = true; + *prividx = 0; + } + + if (*prividx <= attr_id_l3_stats && + (off_filter_mask & IFLA_STATS_FILTER_BIT(attr_id_l3_stats))) { + unsigned int size_l3; + struct nlattr *attr; + + *prividx = attr_id_l3_stats; + + size_l3 = rtnl_offload_xstats_get_size_stats(dev, t_l3); + attr = nla_reserve_64bit(skb, attr_id_l3_stats, size_l3, + IFLA_OFFLOAD_XSTATS_UNSPEC); + if (!attr) + return -EMSGSIZE; + + err = rtnl_offload_xstats_get_stats(dev, t_l3, NULL, + nla_data(attr), extack); + if (err) + return err; + + have_data = true; + *prividx = 0; + } + if (!have_data) return -ENODATA; @@ -5118,9 +5252,35 @@ static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, return 0; } +static unsigned int +rtnl_offload_xstats_get_size_hw_s_info_one(const struct net_device *dev, + enum netdev_offload_xstats_type type) +{ + bool enabled = netdev_offload_xstats_enabled(dev, type); + + return nla_total_size(0) + + /* IFLA_OFFLOAD_XSTATS_HW_S_INFO_REQUEST */ + nla_total_size(sizeof(u8)) + + /* IFLA_OFFLOAD_XSTATS_HW_S_INFO_USED */ + (enabled ? nla_total_size(sizeof(u8)) : 0) + + 0; +} + +static unsigned int +rtnl_offload_xstats_get_size_hw_s_info(const struct net_device *dev) +{ + enum netdev_offload_xstats_type t_l3 = NETDEV_OFFLOAD_XSTATS_TYPE_L3; + + return nla_total_size(0) + + /* IFLA_OFFLOAD_XSTATS_L3_STATS */ + rtnl_offload_xstats_get_size_hw_s_info_one(dev, t_l3) + + 0; +} + static int rtnl_offload_xstats_get_size(const struct net_device *dev, u32 off_filter_mask) { + enum netdev_offload_xstats_type t_l3 = NETDEV_OFFLOAD_XSTATS_TYPE_L3; int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT; int nla_size = 0; int size; @@ -5131,6 +5291,16 @@ static int rtnl_offload_xstats_get_size(const struct net_device *dev, nla_size += nla_total_size_64bit(size); } + if (off_filter_mask & + IFLA_STATS_FILTER_BIT(IFLA_OFFLOAD_XSTATS_HW_S_INFO)) + nla_size += rtnl_offload_xstats_get_size_hw_s_info(dev); + + if (off_filter_mask & + IFLA_STATS_FILTER_BIT(IFLA_OFFLOAD_XSTATS_L3_STATS)) { + size = rtnl_offload_xstats_get_size_stats(dev, t_l3); + nla_size += nla_total_size_64bit(size); + } + if (nla_size != 0) nla_size += nla_total_size(0); From patchwork Wed Mar 2 16:31:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766273 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 B4E4BC433FE for ; Wed, 2 Mar 2022 16:33:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242596AbiCBQdn (ORCPT ); Wed, 2 Mar 2022 11:33:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242703AbiCBQdi (ORCPT ); Wed, 2 Mar 2022 11:33:38 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 303F34477C for ; Wed, 2 Mar 2022 08:32:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=khKI7SvYHXHxrOH47Xwls+NhbdpsnUOlJnD8rYKau5q2F2u+QHYBtbIIZrqPwDTmXhj/KAzHQG2gsGEXJbfWGfkjUesK19ZdyRmPB0g3HeEgJ5aJT9JivMxVLLBgrFA1MRZV+BCymb/HHD9z2GpSiLzxB0ieUo3R/APj3G4mcSlQqBQuQAL71wCkmDhHYMY0ZORx8oDmAHvoLxu5fyF+9+g3wj9XcOKTUhFOejwo081vVPV+LPCa3dYq+46//diTV3GYhrtj6fooQ1hxKLGrguUpgvr/91NXpX7mkx5HbqNFpM9yRI3QXQBa8x6IhenRjn6cgP2SE3vF0Rdm5ZULPQ== 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=GnMId5Dt96gJcgd6j8kKg1opGcT6em7rqjwA6F2glRs=; b=P9Td9ugQj2BebMelK8N+jRP6nQc/Dzf9Sqxy1sN88HeVQeH7zTlJZgG9mioVaDCqVg9OYq4Sx5pWmpHz7hG8USJj1vSo0oxQu8cMERizctr7aT8Yw0IONPirISJ58VawTPtoRTAlgKDQsvHNJI8jZkvP9sdfnQYNdDVcAc/64B6bUqOpq0WP1zqR3h+prpsp109goobcughqJk0Qnf0cLJALucj6fK2PHk0wTE+R2N9nEBYqQtAaGAW0yHUu1357nijHTmO8KXbOHijRYpD36lKr2Ox/e0exc/d5oMyFWIGe0gmJE41gx1qip1jBqNbQadQBc0CvYtSuC3MCERoQtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GnMId5Dt96gJcgd6j8kKg1opGcT6em7rqjwA6F2glRs=; b=Af1moQqvgYsqyLWzc1eSPBMunmQgR0b1Os2CWTO44uCgwQYQgPY1pkDuvzeNy51E0FG0a+TzN/JrQOzfTwCmVSP6kDV1TOdIX6ahrvhLcNMF/VPMMzfeXqt0WCj1j4xlthxJoKyqa5ZrPX6bu2odPTN+D9MOsTjGyEq1f29wApppCpj7FO3b34nAY68QCCac8T5RW2tAj7fJMvSTdGdqX65tbHXIP0RlU4caEC7xL24/8aYaR08V5PzBvdipzOY143FXNbxMfoZa9LfcRY4C2GQPlNCI1HP7hhxDPworQrCj32SUm7FTlQBpqM7aTh0OVpGhEOpyU8BktMFEupy1lg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3998.namprd12.prod.outlook.com (2603:10b6:208:16d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23; Wed, 2 Mar 2022 16:32:45 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:45 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 08/14] net: rtnetlink: Add RTM_SETSTATS Date: Wed, 2 Mar 2022 18:31:22 +0200 Message-Id: <20220302163128.218798-9-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0801CA0073.eurprd08.prod.outlook.com (2603:10a6:800:7d::17) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b32c26a-6fb2-4119-c486-08d9fc6a47c4 X-MS-TrafficTypeDiagnostic: MN2PR12MB3998:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gWBbrCVtqqXdTelc/bm40JgZcKoZ3mfEwApdVEnnjqZWu6Jm1ezM9WSJ04dAYVKBH/r+Qy2ZwMO9fl0D5xRUCCUUmVst0fZj5mLMF4QajFOwV9M9oZDq7Jpsu4/ogXWMryMED6vnsEUQ2svb/+nfOT4U6QK9iDsCPF+Edmdpfq42SYFBFXS05kgnR4K1NEUpwjJHKbz0Gci4w8NoIIrJgKOswI133i0P/HqpG83WIYCbaHfcsJ6KjJpCgFtwooSUXf5U0Iojm7s5ora0V04l+3aIkeDXzvCNFOwKP12G49igWiwjzzkx59dkr0mbYDULhqhNK7FWOsMecXmX5CHLKw5oNQALNZ2x94OockRcPRjtFAYdJPvFXyy/44Qut0R2+38iO+Cs7yCz2PaDMi//GNLkeXdgDUyMgcrWRrEOMe2iJFXW66vZ3Kr4iJkWJQ8WACKvDNN0SET9qxK2AtPIamHkyUg7vsnblVU0nxlA/FEBqhVf6Rpz8fT+0+CoumdNXH0yUUD/ZyuG0W5rRCQh5YO/FKRD7I97UCBNAlFs+39joBiRvt2Jw+49M9OrHoY6wonyQCYlidWzQFhGbuoD+sDB6w6T3ldWdHsehSfkMLu9KwbfIKSn0yB0hGQ5dk9Y3T71OF+27xKek8brwS+73Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(86362001)(2616005)(316002)(6916009)(6506007)(6666004)(26005)(1076003)(186003)(6512007)(107886003)(83380400001)(38100700002)(8676002)(66556008)(4326008)(66476007)(2906002)(508600001)(66946007)(6486002)(5660300002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rRupLE00jacbI1HAsEhP+yFHHAaoknhUs0TMgGMSve5U47uit23t+WuvDSrzpHyabFgOMQERbgGGRKAVNo+fsyhsC9DO37CkJQ3ZDcwMARTlD0kd6nY20fOxcGS71gE0gDilmUZzNYzvM1RXoWfBKvKvwmV7WMdm2ImAV5rN68fIfYHP4+vRffhTwUUKeWKk9tQagePNssqLzNIdBCYB6W0N0U9fZWnNA31wGHBuTtbs9dAKqDHBMJ++7CAMqQERbBsXFlE5mTU8UqRlMIsBcuYVNZCwfBgYqjuXx30BIkTIR+0nAZSFkr6jUt931iDjQYLaibecAAQBTo/R3IDSAuhmAUuZo6fsypeuiTdbjG6q5W8HtcAC0flfdl43N3/I/ggIIX+6rUCRSXZ4zpaHDnoAHlIKuaQdyA/x2tck1mqfgv9crPFe0Fbyde+6s6kQIX4/7Eyi1ib4fLZBuIDcREelxMfZZNLBQTXiPfg2962NwxSkz+gsRaLyfiAAtDRVUUyK57qA7ZpUni6z4/EzS3jlFqMoOBPuk1fvWoCJnBzzHeS3P6JsibFLkiAzJlYLnvwH1goANi0f8q5KsJGfOaHxpr53P+LvphlLuLHZadIsVdi4rx0KuBbtPfOM1C/MxFl8d5v+qwpMg4NDsGpNXlXTw2lowZ40DgKyiC28JPhX/neEKm0aidozhiYf+iCRQ+4iFA9ERmDI4gBPCAKqBNmytf6kdEpFSH/kfEI/poCaZLhy9V4HHBA8vXespo9KBM76s3+l/fGPDFKC6r4OEPcRozj2lsbLiucrXJ93EfWiA3obnhX874a7fOQ92Th+Gmo58zSH5ETMgvhfX6iUN16O8DGonA8AdxWA7QAVL2aNPRFOqefxW5Dl0KapeUNWx6cxbJ/Rt3i59++kGh+QUoH/u2QfXUEq97DkTw3eiUf3/+8kKnBtDdWi69jt33p9P8jTO6Zk45iFZN+vC3WpXnv6NDnV3hM1KFAayNEotCk/SlAldeXsOwuV/UA7CRaVGpqMpA7cYjX1p8xC8TPUGIdYaj3bArQ8GabXURKHswdItQZFaY1g9K4vcxA4nMbgzdtVyWH3KuQ6vtXsCGwrQ6+iYYlXEwcIxb4UirtlpRsyzjfMLV3du3cgbUghJn5MjKD5c287WvMYR2k7M5n/eifq+OIwI75hgg0M60BJSnlRRxyQVjZiWZ4WqADuDIOPApLiHx710730asHfG8smx50p1CPyJueHaKdG0/C7suemYQow2uffbYVoX94NpksaezPXpA0hZepyvIino3TD+jomAqe2RpWnZa0aSbCwViSffzplbYGZf8CJwOA/naCtnunzYu3t2AdPFRJbkQj2n41q2IeZxt5paAOzLxTjvy629a7l3rzfRy0i1coLrvwtbWUznPG1EV6yxqXUARfL9CHkFhC7r2CNeuSO6KTmcoVtIASdTZ4sDMVvUL2zp7X/52990uoO00IV1vdL9pXSYD3IbbNjZDJ1z34lOmiRbxtoMv07HZ0mxfkjzvzW/egEQ0aGzTjZNBsdqX57pKjbI2fclVPrDxTNx99V6cXW6BVdldD5kxGGUBM0+Sn0zOGIZhxK8iGaxUoGBnodwtDmlBL+hAjZavf33WsMsxj+qCA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b32c26a-6fb2-4119-c486-08d9fc6a47c4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:45.2321 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kQYTOmjKQ5y8cODsLCDIxBEz6jwjAq4T+lI+BuD45PBLF4CBnC37E1gKp3mhO+AzPYKM18jZSsFSahicMyg07Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3998 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The offloaded HW stats are designed to allow per-netdevice enablement and disablement. These stats are only accessible through RTM_GETSTATS, and therefore should be toggled by a RTM_SETSTATS message. Add it, and the necessary skeleton handler. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- include/uapi/linux/rtnetlink.h | 2 ++ net/core/rtnetlink.c | 66 ++++++++++++++++++++++++++++++++++ security/selinux/nlmsgtab.c | 1 + 3 files changed, 69 insertions(+) diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index 0970cb4b1b88..14462dc159fd 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -146,6 +146,8 @@ enum { #define RTM_NEWSTATS RTM_NEWSTATS RTM_GETSTATS = 94, #define RTM_GETSTATS RTM_GETSTATS + RTM_SETSTATS, +#define RTM_SETSTATS RTM_SETSTATS RTM_NEWCACHEREPORT = 96, #define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 9ce894a9454c..d09354514355 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5564,6 +5564,10 @@ rtnl_stats_get_policy[IFLA_STATS_GETSET_MAX + 1] = { NLA_POLICY_NESTED(rtnl_stats_get_policy_filters), }; +static const struct nla_policy +ifla_stats_set_policy[IFLA_STATS_GETSET_MAX + 1] = { +}; + static int rtnl_stats_get_parse_filters(struct nlattr *ifla_filters, struct rtnl_stats_dump_filters *filters, struct netlink_ext_ack *extack) @@ -5769,6 +5773,67 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int rtnl_stats_set(struct sk_buff *skb, struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct rtnl_stats_dump_filters response_filters = {}; + struct nlattr *tb[IFLA_STATS_GETSET_MAX + 1]; + struct net *net = sock_net(skb->sk); + struct net_device *dev = NULL; + int idxattr = 0, prividx = 0; + struct if_stats_msg *ifsm; + struct sk_buff *nskb; + int err; + + err = rtnl_valid_stats_req(nlh, netlink_strict_get_check(skb), + false, extack); + if (err) + return err; + + ifsm = nlmsg_data(nlh); + if (ifsm->family != AF_UNSPEC) { + NL_SET_ERR_MSG(extack, "Address family should be AF_UNSPEC"); + return -EINVAL; + } + + if (ifsm->ifindex > 0) + dev = __dev_get_by_index(net, ifsm->ifindex); + else + return -EINVAL; + + if (!dev) + return -ENODEV; + + if (ifsm->filter_mask) { + NL_SET_ERR_MSG(extack, "Filter mask must be 0 for stats set"); + return -EINVAL; + } + + err = nlmsg_parse(nlh, sizeof(*ifsm), tb, IFLA_STATS_GETSET_MAX, + ifla_stats_set_policy, extack); + if (err < 0) + return err; + + nskb = nlmsg_new(if_nlmsg_stats_size(dev, &response_filters), + GFP_KERNEL); + if (!nskb) + return -ENOBUFS; + + err = rtnl_fill_statsinfo(nskb, dev, RTM_NEWSTATS, + NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, + 0, &response_filters, &idxattr, &prividx, + extack); + if (err < 0) { + /* -EMSGSIZE implies BUG in if_nlmsg_stats_size */ + WARN_ON(err == -EMSGSIZE); + kfree_skb(nskb); + } else { + err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid); + } + + return err; +} + /* Process one rtnetlink message. */ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, @@ -5994,4 +6059,5 @@ void __init rtnetlink_init(void) rtnl_register(PF_UNSPEC, RTM_GETSTATS, rtnl_stats_get, rtnl_stats_dump, 0); + rtnl_register(PF_UNSPEC, RTM_SETSTATS, rtnl_stats_set, NULL, 0); } diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c index 6ad3ee02e023..d8ceee9e0d6f 100644 --- a/security/selinux/nlmsgtab.c +++ b/security/selinux/nlmsgtab.c @@ -76,6 +76,7 @@ static const struct nlmsg_perm nlmsg_route_perms[] = { RTM_GETNSID, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_NEWSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_SETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_NEWCACHEREPORT, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_NEWCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_DELCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, From patchwork Wed Mar 2 16:31:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766274 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 E262AC433EF for ; Wed, 2 Mar 2022 16:33:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242502AbiCBQd6 (ORCPT ); Wed, 2 Mar 2022 11:33:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242446AbiCBQdj (ORCPT ); Wed, 2 Mar 2022 11:33:39 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2052.outbound.protection.outlook.com [40.107.223.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 037C52191 for ; Wed, 2 Mar 2022 08:32:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U0i+MFwWobSqzMXiVoSkcpYyDYpYqdVWewiWnR2GrXIQH+wE9RROfy542+SvB/CGZePrtzqH5sgLvdVBVO6WZPIb8oKfo63W3TJU1vLeSWIqeiTEDaZN+mJHDZzd/36OuztRo2Tql3Bt3npSAGhdm/JWx7lwdGbgciAarq9PQVww1qEAlDebCnApdaqGz7GI0FhQB3IXu9K4qF2F6vw1JZQzpzUkRMow0+N26+Sg6bw5dNMAMcAM/cu82tpcU5Tf+ueQk3ji7EbTDh6WWZZdpPg3wj/iumXEa7QJR5ypyiJF6riM+vndKbYEEkU0ME4rDrn3Kbp8U0HvB5XRo38q0Q== 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=xqWbRTTi+2VDNTs2GUwsZGvraIsdsdKpZTgVRCtqLcE=; b=V77ezCo+Shr3Yuqq9vUFWSoag1CNLDvluo+u41tMdbbhbyyHd2X+SYG4S8dywKHPa+7TY0rr4i654rpnDlj46VlsCgG2uwQcubVG21nVNaxXVsCtX55Wsy3nR8JJqGFMZAOG8tnEb04LTI7j4ieTLtqPqnMbdqGV1yzKgYjRHYQNtK7D0nMp4Vv0iR820cSf7av/+q/Sz+n7C+f0acuPeok4DIn1+36l3+IHEKtmz67VrFhfrAQp2XYdKbcEMjKORzWUmxJXpwG9PUz6RbhdxiVtiwiKpUBUKskBNDOuQ146xslbckiT1RlAW95kAC25VBDOWHXFJ2NxRvlemIjW8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xqWbRTTi+2VDNTs2GUwsZGvraIsdsdKpZTgVRCtqLcE=; b=gSy+4o3s6V15RDn/mob4dN9na9+nlCTuU1JIu4YfJA7aJokSJbPozHvwNXAdPBXDezdSz5jicYbsn+2djzJVj+loj6MF85+9baNWRdk7GbT+uGR6K+97QHDkU5eI4L5hgDSvv8TizhcyVTZsJaEMtKeYIkqGBnrS39O/fgCigc7ys/9oES4MSIRgJGQfIWDbWH+im54fdkKcPsygLC4SokX2XOtYbFPNVyG7xDF5fP7Ar/khe1BvWukcw6gCXiEHx0+9jSTVidMn6K62OJ36NzpzpTy3a/0fsxpuWJffT0IKWKjsmRoPMipNd1ZvKjrAS2N/qt+nnBXCsPRs9hm+PQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BN8PR12MB3057.namprd12.prod.outlook.com (2603:10b6:408:64::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Wed, 2 Mar 2022 16:32:52 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:52 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 09/14] net: rtnetlink: Add UAPI toggle for IFLA_OFFLOAD_XSTATS_L3_STATS Date: Wed, 2 Mar 2022 18:31:23 +0200 Message-Id: <20220302163128.218798-10-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR09CA0062.eurprd09.prod.outlook.com (2603:10a6:802:28::30) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0338816b-f7dd-40f8-62c2-08d9fc6a4c09 X-MS-TrafficTypeDiagnostic: BN8PR12MB3057:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MOC/ksm7hj0+R4i9i2GJnRjH5xBpr5TtRDeS5a9jVy8kWmuj1/5P5VAqKvug1vbk3q/DsEW8RHkyCUD5DCKPvXF97AJgUzbtmhY+9vhqXo6BJHExBcHBlEiGsbVDp5j60gW6kc9YyIrVew4i+f+UIYDEsGmaRAfe5B5rIcwqoAj8v6N/DBhvNJWFegRnD8ZYPMeEe0NgodvVzgVju2GXA6AihlUmpapr6FUtBeKGtFwaqYkw1RpQn01eEpzSRNwyKqe9cFHCAKPC9YdLPGkcq6+7Qi2hoNpjzSPDErJbzAbn43Q38goSlD1TRTMhDQosoiyaXUoq6si26ml/4E4SpyoYMLdnTWxQkAuEOeI7tH7kMZKLP1AsNkeN7I13HJBf/3kMgXP1teGiCAspfuZwl+d9KheNU+G8KM8N3gUqJIOVCeqBYlMjOYKuJwL6j3Mpf1VzqSpPaas27sP2aAmrfWwv2BZ7ZRzbbH/X+m9QecCSw+o0/SK3wm3azPk5MH4nsCb+ADsPcdfDkyzbVPoCteE1g3x+kHSxRM/EFymGxxfzITLcMmME2KR1MqIt8IW+GgaEjKZ25jxqV5+//wBMuZofTiqePBuxmxo+DY+0hso9/u0bCENCOPQAhUfPI7pdBJZfjeC5sh0cWbcw668WXCtlFnGjNrF1DtAgoHYbwRfKoWoSHw0K8HW2GQCRwzE9ETUWj4gkBCIqypm8BTT8kA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(6486002)(6666004)(6506007)(36756003)(38100700002)(83380400001)(508600001)(6916009)(2616005)(6512007)(1076003)(107886003)(316002)(8936002)(86362001)(5660300002)(26005)(186003)(66476007)(66946007)(8676002)(66556008)(2906002)(4326008)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: efg1/RM9atkZFyvsD3Mrye84KdPxoZ3XPPN3pU9gn3+OIaXtYCrRIbpEDz9PLTeY4QjwONAnDOGTnYHVMQ6HSZMp66nrjSaLPg1dE4eHdw14qnKpr7n29K7cpDdeMy7SET6yiMTfJuvZtgrWcG8KsGD764IDKNroNhcvLM+GFSXcOrpKQBp30nQTo9zrZ/U8JOE/mZ48TGe1H6feYfHyhNFqWQWHOFz+7P+uXGMBL5Bbasx1/t4sbwGi6s5Kfe1eonupmGBkkubhnpud+wakOl6GXGdqAaunruY5o+tp1C1BinCm60Wco1fPRh6I64zlqKzGSrxpK+tHbD1qJSz8kdv332TOhPZ1uGgVVPZrlQVvCyxoR6/E1CswA9VumKu6YBNXTAl3cKn8IG7B0a6o3EYOy9TjYiCwX+YAMlAJfHLHVzY4cSmM/R/aEWswvLPSjb/xv1fz5hiuzN/qpsN0n/gKy0dPU0mLIoHGg/uFuPi8GvM7JYMm80wmHYhq1L1nml4smgo5U8Re2+Bv8T5VFIIu4e8lUWVYvf8leeKg5Vzc2vczdgcz0CLzNnQj0AFdOZTmOd95EU1vChu+YqU9OQ3TWsyOgcwlYg3K0hUrIIECSieyR0LjoPlaS0Q/IBhXZYDpYkpZbeteVzlzQXh2GqMmWDDyMrctLwFJHrlvkjnSAU2YWptv89pmGG5ZfOiE5EVVwVwXCY3RXiFF9X7ZI0bAbZciw4sQKL32mE9ugDpLwNv2OlNKgxSudievYXSg0avoj2ycYnhS66hEdh/2uJLQDMEwkRrCmXEoA4UZ2ucOoT4VWUXvvbp7VAhFNiGC54U1ohGGJgT1wt47gSzAQu9Cz2xaxFWxWPR6aBU/KkJlT3j76TjhcYXdJVuiCZuyZ/+dBxXirG28W840LCN9fCmrR9ok1UDLujuT1+KU+zbZKBZQPHIksVOfNacNdPFdaocHaRtfZEPOE+4KJ54fesWaeLMW3rmNqKXOmqTkNF5qDSNzqOcjj/1fexS/l2Cv2CvpsMRqOEjq/Oxxo5NxhzG1L/ckJOlVQfWdA9COOpzlcMTUtynvI5PJw6wHUASGv8cycVdWu7qQEz0ZGWdykEng1IFiSWq7V9tlKVFSHeTyYGWOQpzbeZh2moWjvlah2f1ucLP+Wl6q8P7FyYyF0f8fNFVdsFisZwMO05c1iXlF9CLOhtWaIRV/Fdx2RzziAAw+2jBT8FeTC+I4QEZOnuyQfzSZrpW33uo0p2Vdhl9huERjhhZmmE3egfJuMT5O1KEo+R5W5iXCct9TFbjZLh11oKXQPcLaTeMnlLQH/DO5al+dJaO4/DGL712wughJbUzteAId+GARDf0VK+nqTURWtsBZsC+dOkIKFJBDttkpawTFgm/tQNkSIhRaQVdh5XI1o53niOlzefymwjW32H8es5U5f5ThmT7X4uy4jIhdZwBPAYP5WSPhNV8NLgXpUiMzCeTDeid3V+S0TBzR5qYCUr18U/si4V7sw1kddrRz4IZUSM7Cb76cb+WCh9BBE/Gf4FiM9FkXsyy93kc14ShBdXiU1uDqjz683U/DXh6DBr19sg3kYb38sSYsBlOIPuKRillVaUOmoURH4+WjiRDfnz7oeYKAAa8p9tR5GDo= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0338816b-f7dd-40f8-62c2-08d9fc6a4c09 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:52.4708 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CcU20QnMuN+069M74NgKzIDIWpyDqsYL1qN5OU0+tL7ThJITR5YY2GLSPP4xkU8QXDbiKus0uC5UkmPtFk4dLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3057 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The offloaded HW stats are designed to allow per-netdevice enablement and disablement. Add an attribute, IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS, which should be carried by the RTM_SETSTATS message, and expresses a desire to toggle L3 offload xstats on or off. As part of the above, add an exported function rtnl_offload_xstats_notify() that drivers can use when they have installed or deinstalled the counters backing the HW stats. At this point, it is possible to enable, disable and query L3 offload xstats on netdevices. (However there is no driver actually implementing these.) Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- include/linux/rtnetlink.h | 3 ++ include/uapi/linux/if_link.h | 1 + include/uapi/linux/rtnetlink.h | 2 + net/core/rtnetlink.c | 75 ++++++++++++++++++++++++++-------- 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index bb9cb84114c1..7f970b16da3a 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -134,4 +134,7 @@ extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, int (*vlan_fill)(struct sk_buff *skb, struct net_device *dev, u32 filter_mask)); + +extern void rtnl_offload_xstats_notify(struct net_device *dev); + #endif /* __LINUX_RTNETLINK_H */ diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index b1031f481d2f..ddca20357e7e 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -1227,6 +1227,7 @@ enum { IFLA_STATS_GET_FILTERS, /* Nest of IFLA_STATS_LINK_xxx, each a u32 with * a filter mask for the corresponding group. */ + IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS, /* 0 or 1 as u8 */ __IFLA_STATS_GETSET_MAX, }; diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index 14462dc159fd..51530aade46e 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -767,6 +767,8 @@ enum rtnetlink_groups { #define RTNLGRP_MCTP_IFADDR RTNLGRP_MCTP_IFADDR RTNLGRP_TUNNEL, #define RTNLGRP_TUNNEL RTNLGRP_TUNNEL + RTNLGRP_STATS, +#define RTNLGRP_STATS RTNLGRP_STATS __RTNLGRP_MAX }; #define RTNLGRP_MAX (__RTNLGRP_MAX - 1) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index d09354514355..a66b6761b88b 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5566,6 +5566,7 @@ rtnl_stats_get_policy[IFLA_STATS_GETSET_MAX + 1] = { static const struct nla_policy ifla_stats_set_policy[IFLA_STATS_GETSET_MAX + 1] = { + [IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS] = NLA_POLICY_MAX(NLA_U8, 1), }; static int rtnl_stats_get_parse_filters(struct nlattr *ifla_filters, @@ -5773,16 +5774,51 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +void rtnl_offload_xstats_notify(struct net_device *dev) +{ + struct rtnl_stats_dump_filters response_filters = {}; + struct net *net = dev_net(dev); + int idxattr = 0, prividx = 0; + struct sk_buff *skb; + int err = -ENOBUFS; + + ASSERT_RTNL(); + + response_filters.mask[0] |= + IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_OFFLOAD_XSTATS); + response_filters.mask[IFLA_STATS_LINK_OFFLOAD_XSTATS] |= + IFLA_STATS_FILTER_BIT(IFLA_OFFLOAD_XSTATS_HW_S_INFO); + + skb = nlmsg_new(if_nlmsg_stats_size(dev, &response_filters), + GFP_KERNEL); + if (!skb) + goto errout; + + err = rtnl_fill_statsinfo(skb, dev, RTM_NEWSTATS, 0, 0, 0, 0, + &response_filters, &idxattr, &prividx, NULL); + if (err < 0) { + kfree_skb(skb); + goto errout; + } + + rtnl_notify(skb, net, 0, RTNLGRP_STATS, NULL, GFP_KERNEL); + return; + +errout: + rtnl_set_sk_err(net, RTNLGRP_STATS, err); +} +EXPORT_SYMBOL(rtnl_offload_xstats_notify); + static int rtnl_stats_set(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { + enum netdev_offload_xstats_type t_l3 = NETDEV_OFFLOAD_XSTATS_TYPE_L3; struct rtnl_stats_dump_filters response_filters = {}; struct nlattr *tb[IFLA_STATS_GETSET_MAX + 1]; struct net *net = sock_net(skb->sk); struct net_device *dev = NULL; - int idxattr = 0, prividx = 0; struct if_stats_msg *ifsm; - struct sk_buff *nskb; + bool notify = false; int err; err = rtnl_valid_stats_req(nlh, netlink_strict_get_check(skb), @@ -5814,24 +5850,29 @@ static int rtnl_stats_set(struct sk_buff *skb, struct nlmsghdr *nlh, if (err < 0) return err; - nskb = nlmsg_new(if_nlmsg_stats_size(dev, &response_filters), - GFP_KERNEL); - if (!nskb) - return -ENOBUFS; + if (tb[IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS]) { + u8 req = nla_get_u8(tb[IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS]); - err = rtnl_fill_statsinfo(nskb, dev, RTM_NEWSTATS, - NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, - 0, &response_filters, &idxattr, &prividx, - extack); - if (err < 0) { - /* -EMSGSIZE implies BUG in if_nlmsg_stats_size */ - WARN_ON(err == -EMSGSIZE); - kfree_skb(nskb); - } else { - err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid); + if (req) + err = netdev_offload_xstats_enable(dev, t_l3, extack); + else + err = netdev_offload_xstats_disable(dev, t_l3); + + if (!err) + notify = true; + else if (err != -EALREADY) + return err; + + response_filters.mask[0] |= + IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_OFFLOAD_XSTATS); + response_filters.mask[IFLA_STATS_LINK_OFFLOAD_XSTATS] |= + IFLA_STATS_FILTER_BIT(IFLA_OFFLOAD_XSTATS_HW_S_INFO); } - return err; + if (notify) + rtnl_offload_xstats_notify(dev); + + return 0; } /* Process one rtnetlink message. */ From patchwork Wed Mar 2 16:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766275 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 CCB23C433F5 for ; Wed, 2 Mar 2022 16:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230164AbiCBQeA (ORCPT ); Wed, 2 Mar 2022 11:34:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242730AbiCBQdp (ORCPT ); Wed, 2 Mar 2022 11:33:45 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2083.outbound.protection.outlook.com [40.107.236.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E52A4B877 for ; Wed, 2 Mar 2022 08:33:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFFasxMwhh43nDXGyNh6ia2jSeSpHGqPiN/vOZgbxlnn+/CMsA8mBCA4tXkzKnlwkyrx5wKnQGfbsUiD4DVixJxdoBP4eTg+bSWwEevpyGnsf29pBf9dCsJx3KTZhYr9EWMO/ymuP0QU2baE9VyN2Lmy/sqkUinX82+fvepkU0i4j/C3zKaBfUevyZ2AO94jf++rDC/hoJKRKY85DC3ovYnMqJ8B8tq4gWowgGodz8xZ0/LoYBZSw1JWrUKVBm4cPKjhU6RmfJLEV9ABbwBSfsg3qSFrB27kq/I4B4kCFyaTW8LR/CMhCttyPEzp2W+OeEM1auUg0UXvcqOwnR/M/A== 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=yJ5oktitWkDDvYvGVIfZD4g1vVPTE6/bC7VtpIdZvWY=; b=PxRq9LlokolFGtj1cDelOUOfqB9y9njQBVQYlPE3R5XciyLKiyvnjYpfMxyySIYrCkwT9mE8Qj34/4eb8S7I0Uv509hfs1Am0yeqrRa0MkndHvoPjH3l5OuYvRoQQrY6dez82FRnUe8gllHQnwuFkT4epfO0mkNRDDmlyvTAgaYrkvAypGpA4h59i/cnXbd/o6abwHOn4yaAJj3X0l9+LI2HLo/XnS3CtuedWZbC+qqKfpSNIWcEb3eo7NqTt1x38EM5hyJnxA4b+Z0oOEnFggmWzlG4CGqZREZpwywlUxZV+PWnLnIMF6bhZ/nNyrLPSNBGxkHwAPT2sg6kqx7nDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yJ5oktitWkDDvYvGVIfZD4g1vVPTE6/bC7VtpIdZvWY=; b=Yt/yqxMWXtQsGHvtyu0ck5DCKxtyi2HbEh2eZzbzuW/yupmnuEqKqJvW4jS7e1x+ntPYkQIhkDJlk1tlWfwpe3Phx1BMakxTuMj5wrxh7DSMCivYs6rSQ61XDCcab5pieSi1ho5mQLZht5BfeJEsg23jOy88d74AOUj4tMPnOwBOdU/6hgPXBkGhUBI4ry8LNXx/5z6At/ftlOBqM0Os2p64bKWbDB+ppaWI1ijS8hMveCAUJ+3LhgDvNskblvhc3QC0/HuBTKdc4/8tTXVUPNOMBQSKVUFRB9kKc2e7375F2BSssB8FoxazOf+D2WGqi6ziBONA7sSrUS5Xh9BWmA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BYAPR12MB3208.namprd12.prod.outlook.com (2603:10b6:a03:13b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25; Wed, 2 Mar 2022 16:32:58 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:58 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 10/14] mlxsw: reg: Fix packing of router interface counters Date: Wed, 2 Mar 2022 18:31:24 +0200 Message-Id: <20220302163128.218798-11-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P189CA0029.EURP189.PROD.OUTLOOK.COM (2603:10a6:802:2a::42) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bbbab3a3-c04e-44da-138f-08d9fc6a4fb3 X-MS-TrafficTypeDiagnostic: BYAPR12MB3208:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5jUONqpac9/2wfYqRNsD91JonPr3IlI/yKQJUS5ucjq9NTbC7+CHPzahIUa01wTn/Xh2SpOzjs8W3sAfZrEvdUOnFLmrc/QtECnzCUyDxHPQa+29avz+scKDBg0NkU6RDBx1ZJwnp2plxmvV/z5Igrtn8y2DW87B2h6bAZ2YalNyplu94GvldIeuTwj+1pgkLFaLHF06k+fZnqjr/EkA1qOliv6ySfWuVpbdcJ69IuNoz9zo4We0PXOhETR9QmhJGu9D7/Y+FVUaFZymUE3/l3TTWXIT/E67n6AXa3m8LfKx28ijaCGLfPaaUD5SE43eG35Ei6wuQ/sbxxPZmphETiVcYCt19Lz50Kl972UxLRQRmusYs7VxJUWnxu+0k2ItJ6lTS+80nzihT31RO4cxddjrBtSSp7ceJIACnrFscT6L/NYM0S3pvvH/EQPKR7E10eEXucOYrI+5MWMHyzJW2qhZOKpF0bCDQL46OLduYpe1qs8aLuKQXxEXvXpho6i+kkefMGfQFS9woayAlOL1tij+eYz/eZBJdnzPgxNbvfAaXU7lFUAyZ8N0e0dEx+kqmOfHUWRqEKXYazU/Ol7uJkAKwn0M5eWaJfHolNIV7iEFDyLXArdHC8aWj9GrTHgHWf2nV+2qljXDmlXv6Kmpkg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(66574015)(6512007)(107886003)(4326008)(66946007)(66476007)(38100700002)(66556008)(2616005)(2906002)(86362001)(5660300002)(8676002)(26005)(83380400001)(186003)(6666004)(36756003)(6486002)(508600001)(316002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /dfswdcCmJ6WhJoSCEGDsvglMVlyO8wywemVq3Sy2MW0yrtZ45S4+sApn7PjgRgPcy4QVcBYE+h1DzjYqDsw+BPVfz2Jj6YuiCS4vZA6nBxQnT5aGC7j0h63JWriYa5CspmBiI6Egmg5ne/LDdO2Z6FFUcr9kSEN9HTW3WDoixa42u2s/QfCNAdl/3RmCzHM/JDd/nn9R/vY/T4+xx4iUeq+fQ+T4wSyDxppEQ1OBQKThTbE5S3n9GVdsgt9PTVw7yTrw0OfN4YbXUbQRyb9OTAGf0W0z3sUUOJ6pAxlmLu2Ryqk4AEZCR7/BcMFdFto1e67HJ79xXp8Vb43qhJm+BkmhihrzAjM/K2ghh8PghTYuGotRrjwV8SOTKiPmaxGmCwiG9MxKWUbyLPQeReuKQnh28J8dvY5AUtGBiS6RNvsOUGjSuG8BaLyjDqisFP1scuT1GsnGk0lqdBJBItRAc4N37X5hfTZNk7M4V6Rq4+4snr8As6LSuD5Wz8dxnis5ZMdRIn6ppW8jtGAzg/Qh25C6rpQcWs0ofYZhJlPz2AgCDuh0RZPk4t4a7LNIGP0WqBO6MwYoDlGxugplOicMkdjRSRUpztFBiont4Qmp4NwJb1BZDdfrfeyhVM3t2H3cCT77Je2VLS0EmfAa4eXJR+DOcPdmgUjrJ7VFdJrsUYR7/D2uo3zOP3D1NhaBiY3wWmCxEmdpFo0p8QL5Bqqi+2IJLH8f0E7dvRbo+h9XlE9C7HfzvYr4iEqqiwj7SsV4jh/PN8yhpXjQu06eQqcGgcdrnq/NGFe6BP3awcEUHMgijYvu/x/0hK74lobDkZypSNu2RijRCFPX0QUkH9DG3giyCTSjEJtLSm6rgmVkMOS98dlf5HOvXwgOqHYI9raboYkeh1JxBxGiVD12nMtV9ToYATWs+tkvENqAXYmjpaNQa7HzGTP4zlEOJx3Z96gfYPJzO4MPS3P9/u6xSOk2ehKMWNyqmDC2H7mJdYGEOHmhxH58k22Ho4uTQgVYYdLRkolKZ+nczfu/w2603NYSQ70rJgR3jYwqTc3kJWP7PpTZ97Az1gmI6BY2TvsywW2qNRYAVTYz5ghRPYK30sQAtb1BSBFgoB6VLH7g7u7OjfTXzGCTyxOOnOKpGKmPkiWtLjr2knyRAnPjbu5A2yg3e8aIHYrmidv8sPekctPL9GZfCQFtVYarNlcimmPHuAAf8571rCHF33WPUWypWEzpb5+T9LrKG77UvyGaIjM/DZvB6X/qwuegeij53QGaI2J8a/1ny6EhK/dL2QCA8kS1TiLpX6Z6LZ/VOia9fwme35FMNHTlTJCJqbnMOUHYvO6Z6cVO2ZCCz9JCI+1dvjoM4a3CEKQA+5kf52M5weVOgS+gS8oKyBsVlkNl6ngyQEHbV3O0LkAS344SQLzkxtjCSwhFrnIvZ2me00AK5DJloxPW3HZ+4tX6krVfRB1ALMCbsOVWywX85UTZLShTb4dTGVc58ErWyVm24pzo2sMh2bBsxn2otejkuJWqeXBIsFjdBpOFb1mcMJSeedNDnywUitF/1j470eKAPMbQHAz8Wwcjv3axa98yeo1+QNXN7dtXRhARe0cbb/4e+YWWYsS3+uHgjsMA7rQG4H/cUwheL4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbbab3a3-c04e-44da-138f-08d9fc6a4fb3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:58.6316 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: B3cxnygTZw1J1TXPa0EVNUa7VlMAhQhFc1bpAd21oAIkRSmbB7uYuqR/r1VPSoBySjC1oURGraTk0+pe0YVOYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3208 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The function mlxsw_reg_ritr_counter_pack() formats a register to configure a router interface (RIF) counter. The parameter `egress' determines whether an ingress or egress counter is to be configured. RITR, the register in question, has two sets of counter-related fields: one for ingress, one for egress. When setting values of the fields, the function sets the proper counter index field, but when setting the counter type, it always sets the egress field. Thus configuration of ingress counters is broken, and in fact an attempt to configure an ingress counter mangles a previously configured egress counter. This was never discovered, because there is currently no way to enable ingress counters on a router interface, only the egress one. Fix in an obvious way. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/reg.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index dce21daaf330..67b1a2f8397f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -6784,12 +6784,14 @@ static inline void mlxsw_reg_ritr_counter_pack(char *payload, u32 index, set_type = MLXSW_REG_RITR_COUNTER_SET_TYPE_BASIC; else set_type = MLXSW_REG_RITR_COUNTER_SET_TYPE_NO_COUNT; - mlxsw_reg_ritr_egress_counter_set_type_set(payload, set_type); - if (egress) + if (egress) { + mlxsw_reg_ritr_egress_counter_set_type_set(payload, set_type); mlxsw_reg_ritr_egress_counter_index_set(payload, index); - else + } else { + mlxsw_reg_ritr_ingress_counter_set_type_set(payload, set_type); mlxsw_reg_ritr_ingress_counter_index_set(payload, index); + } } static inline void mlxsw_reg_ritr_rif_pack(char *payload, u16 rif) From patchwork Wed Mar 2 16:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766276 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 EBEBBC433FE for ; Wed, 2 Mar 2022 16:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242864AbiCBQeJ (ORCPT ); Wed, 2 Mar 2022 11:34:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242798AbiCBQd4 (ORCPT ); Wed, 2 Mar 2022 11:33:56 -0500 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2082.outbound.protection.outlook.com [40.107.212.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F104DF77 for ; Wed, 2 Mar 2022 08:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jgKkrSV7CPpfJHA92Z7/ZGAVvsTY//IQouD6kMoYGGYvDMZpEaHH/B4Y5GbQj/lYPnjCaoFI4RMD5XTbKvpxLIcI9h2tvRHtT+VfA2EN4TQXQVhkWDxROkgFBdtxT+ZKlvp278LZth0FKUoL/2kl0xxcpYkJdBe1wjXLZyWrAf5mlCcxRoHuWmzOpa1dPJUx0jQCUUceDsKS0I3aYQKqlgjVlM7PHfB6a4EToSf5nREC6ZuZQLtbDfr8aRoIBO5rVgXlO9cOHdPrdbrfn5eBu+kfitmEwRyR2EJV4sOixjiHAT1HUHhnnF5Q3wMPMbF7iCko9JpUhwPBY7pSOA4Scg== 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=gc78/ds/Dz1icWPRVPiybRT/Ox7juhxiIjIzctKkwc0=; b=bVTEUr0S/H/+A3+cCiI533frPOt15NwstBCwjGo67O+2k0E3hGKjUkMvx7YwpodAyVKrsSl6055fUKX0zyvm1krrYJpFMu81M3YbNAfOlG3/CAvTjC6YJlXQzFd0DkExBgrKMwhf3QL8xIgXPIkjhFK+6FfbetBgiSdql0YyjyH3XRc7hY12exd55yMoRfthPCcoVfsxugFBXKuEsUMk0TI4+mu4oLq7uZtf8BzqO8cdWbdWrSr4Eybu0hcvz1O66z+w/QWsiTaocgolCGDmvCu/gBeOTbT7WRkoyKtc8/+59NRsmFBk7uF/h4tHNrhFaYdEM0fdrMAOvBV1K4A58A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gc78/ds/Dz1icWPRVPiybRT/Ox7juhxiIjIzctKkwc0=; b=Oh7ltvrKVJsuSImaGEvmxZXcWvYyd4TDUQFWQlwmlPwyv0GPPiubMO0Ln1hJseQ74CPo8xfDjYnfM5YeS26gbVXNhxofFEKNhcG8j61dMWs/nSsuTWlo1nB+JcKPw36lcoxVSd38vVhdO0o3BpboCeDYI/NwjtQ3+YgYP5079ZT0a8iEH4LVzgXo9Ikds1DQKBFH7lWQZW25ei1Ja7frvceF51L4yFjcJEn8zi4MiZdHORsRju87geJ5RiTTGYPxkaDs5+x0etqAKJK39+COfYgllSW8yDuuF8qMQg1mwODTyGpbdEDln/MVLg5eG1arq35YwFRLO9+fdabaLaQ3fw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BYAPR12MB3208.namprd12.prod.outlook.com (2603:10b6:a03:13b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25; Wed, 2 Mar 2022 16:33:05 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:33:04 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 11/14] mlxsw: spectrum_router: Drop mlxsw_sp arg from counter alloc/free functions Date: Wed, 2 Mar 2022 18:31:25 +0200 Message-Id: <20220302163128.218798-12-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR06CA0109.eurprd06.prod.outlook.com (2603:10a6:803:8c::38) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9487123e-4d65-490b-f4a2-08d9fc6a5378 X-MS-TrafficTypeDiagnostic: BYAPR12MB3208:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 86n/rUP80jvDaBog7XrPTndh0p5Un7f/yL08i4xOY1DWjiEGxe/pU796+SFfpr1Tyu60Zw0Ki8+Qwnc4BWeFTfOerQTbg9zbyb3EEnv1M1cbnzXHx4LY3TgigLJJZJzLaNoK6c4BzuQ0VtbNNkCyxviuxtVsZWhiu1opaTsbrjpqemU8rLXAiqhQP1ggNBRMLVVt1FFE4b2WpmKrhXZhYtPpfYxMhf27IeESrcRDnpAeq4bdzGiqJKcYVpokrT8QuhboyCs8eDubXUUIRNB3QWh9BI8nDcaFa+tmHH323dT0l+yk2luQW4TtfNG7+1JGWW+G0MHSy8VCZrskqudKEU1mX5ZNiaNQWZ16uAQdsbKXciJmtNynrTXkBCn3TRSI9bdTBJEiL7KZhYF7W6fT1zFRy0OZG0aN2MV3vC+nX8Ja3psTCMYKd3FVNsORuZpfUC2kp6nZVWgSBLYtUpWpl9s4wjjDW0VUwpTP7URunOGu1MBKRCNQIhIECXvVyfPBjb18CpbYmLh+sTHyZz3rUkkXMdzd2h7HqGUteBbmmmK6/OH5YUqkB3C2ijLxld9QC3VN0mTAqONhkDo3WrGDn9UjLzVBur4ZkSfyMYeQe3k9298wwh/W0TmiL1OHjIJ8QOrp1kbWD7NPk2dd2q8vCA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(66574015)(6512007)(107886003)(4326008)(66946007)(66476007)(38100700002)(66556008)(2616005)(2906002)(86362001)(5660300002)(8676002)(26005)(83380400001)(186003)(6666004)(36756003)(6486002)(508600001)(316002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EEyyoNnBFj3QDHwAalu5vb8mfj5TF1+tKUPdaxwKdHFXrk8BAgeilKFjyAvmUXAsJcyWIU5z+kcAVbfRw/9x+hZoe8Idb9DOK8P8lrB6uJwcZlofAyVZV1BMSyevyMgZxx1MVmlvu0Ph51byPfivrYi5wyInF9mjtlUOKMAI8fC2M/pBk6R9HgzgeMuCspQwaqggru21AmUDT8l9WljYmpJDl9w17y79c6oAUd7NIQLKnWYzLoLq1HChQ/zel6v5fvFJ6PMBFGhe8FV5XJG8MPxmi4OrKTeXraEsoXa2fVAom9T4t7q3XYnP5A+6bpTHWcViWF7CMDx1mXJry26ADrApX53a4LpO7pIbYVUJgxqfRNlYKzv/HTe+SNA8OuQtK2+gmDJmeL4o/+kudgIF9IBi6VGRHtUxFYlG62EKCykg3Z4YOZso0aceaBiSPAkpryzCVqZ7ZMkYLylQU5Ughyb6dXilmlWHnmll6TZ0oerGn/RHPE0flvRcpsm/Qh9iQXuaTcjUcNxtf68RH2akXSLxO/ATZBppq71otwfsxjGOGAee4qsPwIr8avI+MJE/ZrPgNkNTR3bhUDWrgRJnzX+lgIAZhhrZ3shptKivrInu8hA645LRAJBUIgcRFAgElsREOK+PnvXBaLTcAqWFV3bn578QsycEamYFCwsxjX5id/0kZFI8CawTJidwEfLkZEdXNz3jB/9LFuufsJqUg/zATEq2ikQXkI/yqU6QoY68KU7lobCYOyxsTF0owizNw6LNxqQrSqgP4ZEBcIjRJKV157lJdH7D6VGOqY/07H541d+NUplPGFhFz8EA7eJ+uZvTDSV1/B8uaHiIVO2pqmBPjhXiTKM1rAjHduL2xrewpwLrv+iLjnrFn4rwc2I5VpbbpU6psL1WV+auMD+igWDQ4MRjK27gKQu1Gdkw3NmpLIOp2DCehBt6lkXcV52HA1mdy8h4h7T42KYahI8rr4vNpawodDIhMV4vlDfxzOWLRrc1YdM1Owg2QwyWl33A2YbFjQKpSBl8B8SWvpMVlIQujRgClmLfr1CQadcE5nLxFy3ZvOVzHOM/k5vqg0DsNd0brtwLiOz0oDQqbEDvvyXDgRZXRwygcmq3GsfbjPQN3l3BFb0VTxV/1PZxaggure5iLHpkLWQuZnVs0PxcygJFXNfLErFKKMBc5cbniOxQMbnyDV+IGMV/SR6lpKdC28joISgQ3lIkrzv0l9pVEX/iXd5dlP2oIrxeh1kbsk2AeHBp1ptLFKen5UxRS1nWAPHeRJCwZJCM4Lanblo1ekshKzyP5ib0V0ROiv3nI8Ty/P0niBuKCL/Pumj724HlAyKm38avCqUMiMZ5dnd/P6JH5l00QStR4Xm6MLoxbDpayrC7iH0aRWSmq4zGYlaFlY9rvBbYloDthaZlJFVr2tNqqU4CWVhTdWb/4OcFZFTJF5VSZHq6kx9kWzOQtgmHVChBGPhbOoBk8Xu284qnYzvAU9r0wq14zEK5cdy8qkDmg4yODxRcaLOrY9wYeKDO1v21W+cO/5sgmk5zrGDayVuXVPbbCarVg6Yox+AjlYFqghS3cyQmr4LJ9ZFsHgC20DWgmosE8iRjMQGKPUj29fPXVk3+d5oogyuaikK9fmk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9487123e-4d65-490b-f4a2-08d9fc6a5378 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:33:04.7741 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MNadQejofePOVTiZf16Hqaj8BVge4SXB6csVPMLPgEh2qC0wwTjk0SF2DomzL6pqQuWLQ5ugICnNd8XfpglEOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3208 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The mlxsw_sp reference is carried by the mlxsw_sp_rif object that is passed to these functions as well. Just deduce the former from the latter, and drop the explicit mlxsw_sp parameter. Adapt callers. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/spectrum_dpipe.c | 4 ++-- .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 14 ++++++-------- .../net/ethernet/mellanox/mlxsw/spectrum_router.h | 6 ++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c index 1a2fef2a5379..5d494fabf93d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c @@ -266,10 +266,10 @@ static int mlxsw_sp_dpipe_table_erif_counters_update(void *priv, bool enable) if (!rif) continue; if (enable) - mlxsw_sp_rif_counter_alloc(mlxsw_sp, rif, + mlxsw_sp_rif_counter_alloc(rif, MLXSW_SP_RIF_COUNTER_EGRESS); else - mlxsw_sp_rif_counter_free(mlxsw_sp, rif, + mlxsw_sp_rif_counter_free(rif, MLXSW_SP_RIF_COUNTER_EGRESS); } mutex_unlock(&mlxsw_sp->router->lock); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index d40762cfc453..2b21fea3b37d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -235,10 +235,10 @@ static int mlxsw_sp_rif_counter_clear(struct mlxsw_sp *mlxsw_sp, return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ricnt), ricnt_pl); } -int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_rif *rif, +int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp_rif *rif, enum mlxsw_sp_rif_counter_dir dir) { + struct mlxsw_sp *mlxsw_sp = rif->mlxsw_sp; unsigned int *p_counter_index; int err; @@ -268,10 +268,10 @@ int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp, return err; } -void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_rif *rif, +void mlxsw_sp_rif_counter_free(struct mlxsw_sp_rif *rif, enum mlxsw_sp_rif_counter_dir dir) { + struct mlxsw_sp *mlxsw_sp = rif->mlxsw_sp; unsigned int *p_counter_index; if (!mlxsw_sp_rif_counter_valid_get(rif, dir)) @@ -296,14 +296,12 @@ static void mlxsw_sp_rif_counters_alloc(struct mlxsw_sp_rif *rif) if (!devlink_dpipe_table_counter_enabled(devlink, MLXSW_SP_DPIPE_TABLE_NAME_ERIF)) return; - mlxsw_sp_rif_counter_alloc(mlxsw_sp, rif, MLXSW_SP_RIF_COUNTER_EGRESS); + mlxsw_sp_rif_counter_alloc(rif, MLXSW_SP_RIF_COUNTER_EGRESS); } static void mlxsw_sp_rif_counters_free(struct mlxsw_sp_rif *rif) { - struct mlxsw_sp *mlxsw_sp = rif->mlxsw_sp; - - mlxsw_sp_rif_counter_free(mlxsw_sp, rif, MLXSW_SP_RIF_COUNTER_EGRESS); + mlxsw_sp_rif_counter_free(rif, MLXSW_SP_RIF_COUNTER_EGRESS); } #define MLXSW_SP_PREFIX_COUNT (sizeof(struct in6_addr) * BITS_PER_BYTE + 1) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h index 99e8371a82a5..fa829658a11b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h @@ -159,11 +159,9 @@ int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_rif *rif, enum mlxsw_sp_rif_counter_dir dir, u64 *cnt); -void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_rif *rif, +void mlxsw_sp_rif_counter_free(struct mlxsw_sp_rif *rif, enum mlxsw_sp_rif_counter_dir dir); -int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp, - struct mlxsw_sp_rif *rif, +int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp_rif *rif, enum mlxsw_sp_rif_counter_dir dir); struct mlxsw_sp_neigh_entry * mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif, From patchwork Wed Mar 2 16:31:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766277 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 1FFE4C433EF for ; Wed, 2 Mar 2022 16:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242308AbiCBQeN (ORCPT ); Wed, 2 Mar 2022 11:34:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242593AbiCBQeB (ORCPT ); Wed, 2 Mar 2022 11:34:01 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6006248393 for ; Wed, 2 Mar 2022 08:33:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ik4Hrzy15ATaipSqMOKBycfL32la8NAVSvNXwpgmx+Ozp0PHg2YpZ/7X0sZx/xtP5t1UpFpwxjmEnMm+mXgqRIYjxof+QP8nh/I81PCosJ5URxenXaPF37EExm2Sic3lRu+1QBeWmr6LrJY/Q4IfoWSzsBPHduXZrT9DMofPRV26IWS8aMucGQ4VvSMWZz3cVXVw/b8XDy0KDXiQeVYf139yvquvRWMqbgWR4aajVOi4RgOEyZVGraBdJceiJdc3BVaJQfaZBYKVFTgGkkrP8ETAU3Wt0mXSdwpTL9Ve5znVouqetkupTfHBmMEp3PXNUvedWqg83zlhzC0GY/kRUg== 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=Ba52Y8UsqBq5t6xftkEOKhp3rZxCpaTjAN9biOb6TuI=; b=Z2O+A8oHHYO12prLA8YjP3sdei+3GD3m94quXn5MtPjRmEKSNKHMAZhw4egkTpnsTkwZt4oq9qPtK4xYFCeIvAbQS55TWWXBLwpUrvAhzWtTg6vxCe1757SkO5lSrD6qPJkveZlO2Y/otso9sOtb44mClE5LI4g3xoLwjyx1oq+J2VzH3dlBguuNHIddr48/7tUJE8/Iqlu+qqEIyHAzV3RkirIBDw0Q4ufg4N2EvzYFXC4q0R8IKn9iYGAvhmqdLnNq4cD1Va+fVwkfPeVKW0Kv5kmFLqN7+v8TXJeAjKx1JP57SdEgsp+RvQjWQwaXoSHoHEtCXhRrsLs9PEIrBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ba52Y8UsqBq5t6xftkEOKhp3rZxCpaTjAN9biOb6TuI=; b=lzeyAig1HRifxZQ1KryNt+lLDzd2V/9Dh9nfdHKMx2LIG6wn9x2iJew/HZKFzz+YMPbswLbYGXZZ1rqf2Z12lcFW1bidKvh4bSey0Rw93haw4p6p2DsEJkMzOQdomX/5eJ4T6QftNOo44cBxMa0hldc9Q9ji7KDq9VkuV+a41qEKuOF4vMhpe1u/bds7Mci/QM2DiQVIDd0aey3lOuQZXT22eWTuH+o/eTb0+DOAI0YyMR0AoxVzqT1JUKM46x3JO846+0bqVJcTSy7r5R1SAp0vcDRM2nmfrrfAFOSGHvVPJOEMlM/FvaT+8IKmEDMe1Iu9mCTjxvYqvZXWuu0S3w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BYAPR12MB3208.namprd12.prod.outlook.com (2603:10b6:a03:13b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25; Wed, 2 Mar 2022 16:33:11 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:33:11 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 12/14] mlxsw: Extract classification of router-related events to a helper Date: Wed, 2 Mar 2022 18:31:26 +0200 Message-Id: <20220302163128.218798-13-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR09CA0165.eurprd09.prod.outlook.com (2603:10a6:800:120::19) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5efbdf8c-381d-4526-42ca-08d9fc6a57aa X-MS-TrafficTypeDiagnostic: BYAPR12MB3208:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eSog5GbLUghoQmZEKPWGseyRcCp6bfo/lRIMmg+65o/CO0FCInK9FpYRlGn8xLwXbgJy/ne9UNDnVn1DXSaNYeL53de8C9TmtmgirJQZbLmUNRKuadj0JiigKmYlYq+aqB2cXp/d4TkrGb5LuVvAb3n3AWR1szg0ib1+/Ej1sT439x1op/M0DpaKw5a2mjFIv2W1fIha1KBd64OXgzSflph3/74+WioB6TP+04RLszZyBnITWSS0/FBLfWvwVdTRYeaHiXDOcUwRTDTZ6a09cVIuJp9chQBLA8Vp8gbHHQhWBPY4piMmb2iXbaxptVlsl6W0XTG/Ni4BeFRn7qCvKunIZatY4RGIqenMv2tMH1sViAMhTf0pgLltfvdFH/evzYcII4tNSScuB1jnHHVSs8q081sV7PTksKwDsq4/NC/renpuPMVMDJDV3lmPECZdHOgesyAfQTTulI6dZbzk5f9mkb5GG+DKdObZLcllBV6rZ6b8e9hD2Jx4rzbZlRrH0v58R1IPKg6RhwVgqOxEFNdV95I7DaXMmPiD6wYJ8ia6DLfQuHrLP//1qtsSN9K9Wa+z5vGJWaXPY+vA3I869EM7p+IQwpTKEDROYSMR0VeE4PGVQwWbx/MCGPppdHpAw8mLTN10W0cbiEmUF0/Fzw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(66574015)(6512007)(107886003)(4326008)(66946007)(66476007)(38100700002)(66556008)(2616005)(2906002)(86362001)(5660300002)(8676002)(26005)(83380400001)(186003)(6666004)(36756003)(6486002)(508600001)(316002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1PF4BPmpbYtWLtXxX0aB9amgFUCvUBk2bvo6Ly2m0UUsmk7oWYyqydh94RgRFaxocIFgZVBoyTZwLRlvAUR5P3yr1OQ2wwUAVfPwOuCHElzfGaYo2nqi1bNcCvpFYC4hLBZJirHGr5lr9NcMRH7eviWQkqJQXsx4evZMc8HpCalnLQMLCHZFYHAJ2IwL7JdzzWyNWL36USJ7x1nVbhyB3zUa7Ja8O1hp4k0rypzCqK9qrapJ7gcaQe2hQq1IVwmLMO5UZY5T+J1g88cvhem0xRptdNPVaFRaJObdNCFda8tBEo9i95g9KX3143Otm8WgnxjlT3fBwIpiQ6kaGiW8J1/EP9cPvRdNjkuW1S4UY22S746rggGoKeWtUrIN1N106u2tXNXJXitLUMAqemoXJQNjyiXZIvbkF/3NjQZccotuNbZh5lnJQ86nV4Ae8VR2go5V/FOfHTGmlfNL/Ox4zPEKyvcf3O9SIC+caf0QNcrWr8h3tWp3G2z5TDCHC6wiJ1LyPuHXZaXq2zWqaZncW9xyq4AqlPuQix7Vo7HHVHgTAzfl7QKiQSZR8uw53W2RejkznZEBU3fTLCay5dPj3m3wWzFRSrjoIyRqueHQ3yMbl6Ij1UL0V4jiMSrIUHTAAFODz8nqDox85GM3s7H0gZDJYklAWQV1uxJzG3pszom52ZjNlL8cl0ITwSKW0c42RJ6JeG1xX8nKq6ff5SHf5cLAjjZthS7Lov1zw883w9wWCSBVKNY6C3YTlqrg4zJ5SX7zfcY65ltB0UWZI2jVo2OOLKSI3ioAoH8FjEqMXBUwxiGum783B7SJnRrDMR2PGtUdKdM8U2D+WK9Q9Dm8jfRrXbWd5Qt7PbgRJ6M0618MJ41r4+uTAWSypr3s+mgErMi8/7gnzvyvxabmGeozkcagMVyxk4VDrP4mtFtyfwkZsRIrvIpqVFfOeZiX/hEDIUON1xWvTm0VqSnMUQ2cVNSf5KXr+vc0nzzOikfdic2SevoAD0kzYzXWcN6ooMHrUVNfhENANR9AMEYIeinIIx6Uo6WAPGmsYsiIVtXXL3ePmAKHrrDgR1FFZEKJIZNzGBqMoQQvJE5miGdpNNwzSieZmwbR0oPqUxI+fYnxHCTkxaagduW50oClfZ6lYoPb+TIx+LbuC/mNGL7roqcbFuuipQbMCW2+UayNox8F9txfJ/2rn+lvXyPcLIrysw5qf3GxR+UW8V77cVKK5+UrEksxxJc/Q7sTH5r/JrOOkTBvssEGQftDG3OQJsVQu3Q3mAzpRNtlhzEkZfwCZ3rqZjCREWhdC1Pxiq2zCzVOkVpXdkqcRnHxvYN2Mqkx8tF+EkvVQ7qf8S+uc4jdui/uBJMU1EcoGny66YyR4Cus8jaPjqUGrsql/dsftuZTzR2yaCjsPYNrAptPq6U+oHa/mR9GqPvU1WUIifjQmBPzNH51F/RT+T0xqp4t+vyn3MwZWpaoZTG8V7EXfbDBqU6jqlWFLos+ucAeZQzTN7lQ7k4/iU5yTPi252OlFmYJ1x/5Wim2IE+jAZfP+upQgrQkMK+NtvPUEJq2w3DbjKQHRr3L6WbKnFJBZHs3fwAJ5Give3gKkJtCaF4R5saYad6H1gsxowrbd1ZOifgBC7JxmT8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5efbdf8c-381d-4526-42ca-08d9fc6a57aa X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:33:11.7769 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yYDV5FhYNnLCufi8kvl7Ys9aVEdl0lR5npl1k4YCA2YJsr5/WLa0K3+dlxT7ha9sh9pCsMYKBMjnfkRVQ64Giw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3208 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Several more events are coming in the following patches, and extending the if statement is getting awkward. Instead, convert it to a switch. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 4880521b11a7..10f32deea158 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4823,6 +4823,18 @@ static int mlxsw_sp_netdevice_vxlan_event(struct mlxsw_sp *mlxsw_sp, return 0; } +static bool mlxsw_sp_netdevice_event_is_router(unsigned long event) +{ + switch (event) { + case NETDEV_PRE_CHANGEADDR: + case NETDEV_CHANGEADDR: + case NETDEV_CHANGEMTU: + return true; + default: + return false; + } +} + static int mlxsw_sp_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { @@ -4847,9 +4859,7 @@ static int mlxsw_sp_netdevice_event(struct notifier_block *nb, else if (mlxsw_sp_netdev_is_ipip_ul(mlxsw_sp, dev)) err = mlxsw_sp_netdevice_ipip_ul_event(mlxsw_sp, dev, event, ptr); - else if (event == NETDEV_PRE_CHANGEADDR || - event == NETDEV_CHANGEADDR || - event == NETDEV_CHANGEMTU) + else if (mlxsw_sp_netdevice_event_is_router(event)) err = mlxsw_sp_netdevice_router_port_event(dev, event, ptr); else if (mlxsw_sp_is_vrf_event(event, ptr)) err = mlxsw_sp_netdevice_vrf_event(dev, event, ptr); From patchwork Wed Mar 2 16:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766279 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 2DDBCC433FE for ; Wed, 2 Mar 2022 16:33:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240132AbiCBQeT (ORCPT ); Wed, 2 Mar 2022 11:34:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242758AbiCBQeG (ORCPT ); Wed, 2 Mar 2022 11:34:06 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2080.outbound.protection.outlook.com [40.107.236.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E03905FF2A for ; Wed, 2 Mar 2022 08:33:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cF+6mp0y3MHw5e2GAfbmraRav4bWcWdxiLioK/4PDQPakyhsqpV2lmVRlNnq95FAuWm/6iUHNHTeg7+3PAxWnmLaMm3rONeJRlW89UZ7zgVBn7ew6NlbL7usPri3TzNk2aLlzd8AdZ+PtROjz1Mf+t/Vd3gqV385GVMVMlZX4VUmDO04vfMaQSV2A8VjKCBgZ+TMo1cRgmhELJd5oy1KrkIBZ/vhF35UvwL45tyNisocYE0OUL2fbdpbZlklMXDH+Qr9aDeuDaum7EGBrBeAnpAecqPjTCPZWJ/liCUpFxXh2GeiPOkEyopPDMIyn6+r9xS5N0MQ043HB4GKArFBZw== 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=We5xE4gOZ1xGGBwPHj5nybSkjFWbTzilh011wifo59M=; b=PFsfy9eOuPrj5KgreaH70Ju/M/jJz5881Ah/vsz0BEK47Vp9IoQrOa32tsuMtn1fIScoVyLbbZf3Z+9u1ub5FU17zWTc7WijLz6WHVINRdZJW5ofEueczxPEfn2y7uZNVHYoUTHSx+TpVsHj+epoZg0LRsGgu0PTBb0NAOmSkYcD1pfpTBF2FEqEYTNZ/TlEHy6qxPgcyiD3CofrJ1p4W8sIWi0E31g6MjyUkZqPtHjf0cM2lWv8n38bETPum2jaogMbzmoluKK3smbaV24N5oZz+knAjWK/31Q8fhbWF9nH6ONC9C1beo2GC+MfV6UuZny3yKvwJ6I660waQcV/Vw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=We5xE4gOZ1xGGBwPHj5nybSkjFWbTzilh011wifo59M=; b=dsJt7+afsIb35OXdc1CP4qdaJSZ8iTTpfocByS3okFKrwlfUgEk07hbxryU0dvGqI6Z8zgibkNRihr2fVUhDX7nMFhieFJjuaEI9h91n6buW7QRP84b9KayRbnTiKEKUoO2U72PXNBcQf/MK/8DxbcOv78x/NX+1X2fO3frGIPvOqK8fBh9s31NGPPzGe8oRRXSzztdkbLpTqLVrvDrkv6y+pssEcRq7OJMn3UD3P1Lv4NiyckFsjp9yDVRsdwf5LEJIiwG4u1ei88v25Y6F4prBOI7aGfWx5kn8SQpRlM3npuZWmWTRDAbP0lTfEARRlo6glqda+9klQhcDUkvDNQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BYAPR12MB3208.namprd12.prod.outlook.com (2603:10b6:a03:13b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25; Wed, 2 Mar 2022 16:33:19 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:33:19 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 13/14] mlxsw: Add support for IFLA_OFFLOAD_XSTATS_L3_STATS Date: Wed, 2 Mar 2022 18:31:27 +0200 Message-Id: <20220302163128.218798-14-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1P195CA0082.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:59::35) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a013942-2e1e-48ed-0b2c-08d9fc6a5bf1 X-MS-TrafficTypeDiagnostic: BYAPR12MB3208:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WowaH7EYmybw+llnk21TDp83Lhjt4cP0VZi/vUezZFbnrGMg0yK+0mAYBmMsChiVQdcZ6ZKIp5hI5NtS7UWeVCgT5lakpEJK/5uHY5gMZYJQ2cgw5lmUuRtH4QjT1rZ2gLN4044ZnBx1OIb5y2B6MyxRVOgOblYtkZc8pipreL1LDy5D5FpsIU1BKleaga9TKzt90kZ9RO5v6EonRUwLu03wZcTIyyv1r4p2bv0sbRwIwHM6/NC8HB8Pu82PAuLV9cTbvVXbFMxEwR0bDyGfGccKMWGXwnevK9uZhHJBOv+co1RFjzndgEPOvQY1KAcateKmcr7BsdUAWZf7WUWYCAQvFQa2rSIhrV6p3GpdMtv/wbxMnEgWfVvVQdXPnk510mZoxBP6Y5KKTlnmDgvrom7c4liNUTQy0QiMuLZ6XT+vfUNAjoyZh5sXNoXwTxhOWEz4pnR5hS78GWF8x01ueSCbxZNH0z75H8dmjGlJ+HBwnlJgF1bZNxmzc8zpgfu+GIMRiHDWUspDamsE4JSMSusotB5ZLjt+g7HEBACm1xLwWr5AWWAZFeqZvtwdloBgjmCcKR/ISYF6FG9TtPmCPSOWDThQwFl8jYdSmI/XQg3GuU8wxYg2H7pEurhPcHfBK2EV3bLEYv3sbuPjh0ckew== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(30864003)(8936002)(66574015)(6512007)(107886003)(4326008)(66946007)(66476007)(38100700002)(66556008)(2616005)(2906002)(86362001)(5660300002)(8676002)(26005)(83380400001)(186003)(6666004)(36756003)(6486002)(508600001)(316002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dl/7tX9bbsTfOAL6qCGImjjQcIk/4RQnr9qITyPbC+PtsfS0fEeSNHDFrV/bBnCl/zbv+RDc2efXnXe0rXZyjzcB+32wfVAniBaGsQJxznEpIkSZ5rF8qfs83BP1JvKTMyq5EhcSC3YR/8p+dwxu86iHgcFJlw0YyWlIhtMyy+3nbCtaVz2dGyQVnwM63/WYVhFw52mX8XGf2VdK8IxXVWNKauDjKpGFa1hw4pGAThxxSCRA+VAqWDa9eM9jSIwNeQmOuL7QG00qrdCsHUMPpGKqIkt9a+pXjBoCHPvcqxNnZkvDDqt/Qz2jPlm0MAsG2CHdaDrsg8lNxSs87nK53RV2Ee1eC4UcO62RVr+1/Gl/uD6pMxOKTRdHiPWa8/Kpvz/3mZSbBjtUgPOZVD7s8Ss5eCLhmcwzSOd7Qf9m0s5NjA/iGoabZ3+e/8l8O3hgV8ByOtLPZsbDT6QQuW7QOt8f6T5APS+UNEGicQ/1VU2yIkMuYUc0PDczIgzufJPfQnhTNqTTJjaSnvePySQRvZw6+fb7c8N+57VTEBRjanONdAdadgPH0RuWErrFe0Es1+krcJYJsee9Vl8xXVc/PA3wN/IpY4gaMX+QlWMtiLGW+Pzfn+iw59jExpomCo3aQalAiBG39RvcEt+MV9kRW1r423vuHkJbJX3OCqkChlTNTcyaTtw5z7Ecr3OzRWxFFeq6n622+Edm7OlUXEEIKUM7KXY8trVYifiON7Cvb/XjA2XxJC00mIrqnPswAfdK/CqZyA5WSNCwfX/0UHyWNtS22trt6Vwx7b04dYkKFUDoA0mcqnL4kCCXkTIBPHVG5qRv+Qa0L+A+duuY5ZhEX9Y88e9OojO5tFo/tKS9n1BSU1cFBE36S4Bymavza/zjIrkLRtJThKn7PXezKdmnBAK81+JDOUfKgelMDQlze5d1+/wLKbWkfrsKZhcxj6Vm9HDLy7TWzM+UzH5XTxAI7idbA7WVTp6rsfceJQH09iS0EoRCeOl39m6CCsXG5y7HhZTyIAzkLbeiwUs1PSmR4xlWsUh3SRTog9b+PGtB0pu5MJC4N5jlcUHlIlwEuSnYKID15vSvlz4wUyr3n+pYQPxx64mLtjvipubWpLFKXoDdKQQAR2hbKzmNPtBLF+BtKCRzYprtU3HZvKgBn/oBg/KK1uWo6ayza3hfcV2WYcLoJtN+mKTqkoFuR9uxGNflyEyCfvemUkfBxArzGvV6nMbdpjDTSslSTrDHASJdvEdIpCuNzKJN9fHMV4m/PkRQtu4ucny/73Hig5REjvPuMrMGutUyXPocZXQrbiM00lnZFpWSdTlMpZ+vz8cOIDdcsdUuvYQiqUtrNGB7LMA1pKT6rHFK8o0O4benwxN8tZ1S2xXK+lki04IvGPUTaF4pPGZ0BFNIqqGKkAByJ51uflNOkLd6d6ezT6zz+oO0YNzwg1H8wXDmcfqFkHLo32Bm6RWavtxil0QfbtaUgX8cHBkdvleRfD7rL3R9IjCMH9ekx7GjHFMDD+883IX1u3X3t0iuVPgs0v/O/eGzbWJrfBWfnNvTzcIqsCW7TexzYCrUUHZeUbnZcTE9bT0ragxLNNXGCZmFp9Gy76TlTYDFLBVVAR5nBxBEI5l3rdwJuuI= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a013942-2e1e-48ed-0b2c-08d9fc6a5bf1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:33:18.9829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VPHDCUEPovmMvV3z1R/iyNAmxdHRNeWufCwJziwoL4y1SJbM0ssJGSnog23ZjSSUHd6El20IW9XX6J8QMU5Rzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3208 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Spectrum machines support L3 stats by binding a counter to a RIF, a hardware object representing a router interface. Recognize the netdevice notifier events, NETDEV_OFFLOAD_XSTATS_*, to support enablement, disablement, and reporting back to core. As a netdevice gains a RIF, if L3 stats are enabled, install the counters, and ping the core so that a userspace notification can be emitted. Similarly, as a netdevice loses a RIF, push the as-yet-unreported statistics to the core, so that they are not lost, and ping the core to emit userspace notification. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/spectrum.c | 4 + .../ethernet/mellanox/mlxsw/spectrum_router.c | 291 +++++++++++++++++- 2 files changed, 293 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 10f32deea158..7b7b17183d10 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4829,6 +4829,10 @@ static bool mlxsw_sp_netdevice_event_is_router(unsigned long event) case NETDEV_PRE_CHANGEADDR: case NETDEV_CHANGEADDR: case NETDEV_CHANGEMTU: + case NETDEV_OFFLOAD_XSTATS_ENABLE: + case NETDEV_OFFLOAD_XSTATS_DISABLE: + case NETDEV_OFFLOAD_XSTATS_REPORT_USED: + case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA: return true; default: return false; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 2b21fea3b37d..79deb19e3a19 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -225,6 +225,64 @@ int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp, return 0; } +struct mlxsw_sp_rif_counter_set_basic { + u64 good_unicast_packets; + u64 good_multicast_packets; + u64 good_broadcast_packets; + u64 good_unicast_bytes; + u64 good_multicast_bytes; + u64 good_broadcast_bytes; + u64 error_packets; + u64 discard_packets; + u64 error_bytes; + u64 discard_bytes; +}; + +static int +mlxsw_sp_rif_counter_fetch_clear(struct mlxsw_sp_rif *rif, + enum mlxsw_sp_rif_counter_dir dir, + struct mlxsw_sp_rif_counter_set_basic *set) +{ + struct mlxsw_sp *mlxsw_sp = rif->mlxsw_sp; + char ricnt_pl[MLXSW_REG_RICNT_LEN]; + unsigned int *p_counter_index; + int err; + + if (!mlxsw_sp_rif_counter_valid_get(rif, dir)) + return -EINVAL; + + p_counter_index = mlxsw_sp_rif_p_counter_get(rif, dir); + if (!p_counter_index) + return -EINVAL; + + mlxsw_reg_ricnt_pack(ricnt_pl, *p_counter_index, + MLXSW_REG_RICNT_OPCODE_CLEAR); + err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(ricnt), ricnt_pl); + if (err) + return err; + + if (!set) + return 0; + +#define MLXSW_SP_RIF_COUNTER_EXTRACT(NAME) \ + (set->NAME = mlxsw_reg_ricnt_ ## NAME ## _get(ricnt_pl)) + + MLXSW_SP_RIF_COUNTER_EXTRACT(good_unicast_packets); + MLXSW_SP_RIF_COUNTER_EXTRACT(good_multicast_packets); + MLXSW_SP_RIF_COUNTER_EXTRACT(good_broadcast_packets); + MLXSW_SP_RIF_COUNTER_EXTRACT(good_unicast_bytes); + MLXSW_SP_RIF_COUNTER_EXTRACT(good_multicast_bytes); + MLXSW_SP_RIF_COUNTER_EXTRACT(good_broadcast_bytes); + MLXSW_SP_RIF_COUNTER_EXTRACT(error_packets); + MLXSW_SP_RIF_COUNTER_EXTRACT(discard_packets); + MLXSW_SP_RIF_COUNTER_EXTRACT(error_bytes); + MLXSW_SP_RIF_COUNTER_EXTRACT(discard_bytes); + +#undef MLXSW_SP_RIF_COUNTER_EXTRACT + + return 0; +} + static int mlxsw_sp_rif_counter_clear(struct mlxsw_sp *mlxsw_sp, unsigned int counter_index) { @@ -242,9 +300,13 @@ int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp_rif *rif, unsigned int *p_counter_index; int err; + if (mlxsw_sp_rif_counter_valid_get(rif, dir)) + return 0; + p_counter_index = mlxsw_sp_rif_p_counter_get(rif, dir); if (!p_counter_index) return -EINVAL; + err = mlxsw_sp_counter_alloc(mlxsw_sp, MLXSW_SP_COUNTER_SUB_POOL_RIF, p_counter_index); if (err) @@ -8146,6 +8208,166 @@ u16 mlxsw_sp_ipip_lb_ul_rif_id(const struct mlxsw_sp_rif_ipip_lb *lb_rif) return lb_rif->ul_rif_id; } +static bool +mlxsw_sp_router_port_l3_stats_enabled(struct mlxsw_sp_rif *rif) +{ + return mlxsw_sp_rif_counter_valid_get(rif, + MLXSW_SP_RIF_COUNTER_EGRESS) && + mlxsw_sp_rif_counter_valid_get(rif, + MLXSW_SP_RIF_COUNTER_INGRESS); +} + +static int +mlxsw_sp_router_port_l3_stats_enable(struct mlxsw_sp_rif *rif) +{ + int err; + + err = mlxsw_sp_rif_counter_alloc(rif, MLXSW_SP_RIF_COUNTER_INGRESS); + if (err) + return err; + + /* Clear stale data. */ + err = mlxsw_sp_rif_counter_fetch_clear(rif, + MLXSW_SP_RIF_COUNTER_INGRESS, + NULL); + if (err) + goto err_clear_ingress; + + err = mlxsw_sp_rif_counter_alloc(rif, MLXSW_SP_RIF_COUNTER_EGRESS); + if (err) + goto err_alloc_egress; + + /* Clear stale data. */ + err = mlxsw_sp_rif_counter_fetch_clear(rif, + MLXSW_SP_RIF_COUNTER_EGRESS, + NULL); + if (err) + goto err_clear_egress; + + return 0; + +err_clear_egress: + mlxsw_sp_rif_counter_free(rif, MLXSW_SP_RIF_COUNTER_EGRESS); +err_alloc_egress: +err_clear_ingress: + mlxsw_sp_rif_counter_free(rif, MLXSW_SP_RIF_COUNTER_INGRESS); + return err; +} + +static void +mlxsw_sp_router_port_l3_stats_disable(struct mlxsw_sp_rif *rif) +{ + mlxsw_sp_rif_counter_free(rif, MLXSW_SP_RIF_COUNTER_EGRESS); + mlxsw_sp_rif_counter_free(rif, MLXSW_SP_RIF_COUNTER_INGRESS); +} + +static void +mlxsw_sp_router_port_l3_stats_report_used(struct mlxsw_sp_rif *rif, + struct netdev_notifier_offload_xstats_info *info) +{ + if (!mlxsw_sp_router_port_l3_stats_enabled(rif)) + return; + netdev_offload_xstats_report_used(info->report_used); +} + +static int +mlxsw_sp_router_port_l3_stats_fetch(struct mlxsw_sp_rif *rif, + struct rtnl_hw_stats64 *p_stats) +{ + struct mlxsw_sp_rif_counter_set_basic ingress; + struct mlxsw_sp_rif_counter_set_basic egress; + int err; + + err = mlxsw_sp_rif_counter_fetch_clear(rif, + MLXSW_SP_RIF_COUNTER_INGRESS, + &ingress); + if (err) + return err; + + err = mlxsw_sp_rif_counter_fetch_clear(rif, + MLXSW_SP_RIF_COUNTER_EGRESS, + &egress); + if (err) + return err; + +#define MLXSW_SP_ROUTER_ALL_GOOD(SET, SFX) \ + ((SET.good_unicast_ ## SFX) + \ + (SET.good_multicast_ ## SFX) + \ + (SET.good_broadcast_ ## SFX)) + + p_stats->rx_packets = MLXSW_SP_ROUTER_ALL_GOOD(ingress, packets); + p_stats->tx_packets = MLXSW_SP_ROUTER_ALL_GOOD(egress, packets); + p_stats->rx_bytes = MLXSW_SP_ROUTER_ALL_GOOD(ingress, bytes); + p_stats->tx_bytes = MLXSW_SP_ROUTER_ALL_GOOD(egress, bytes); + p_stats->rx_errors = ingress.error_packets; + p_stats->tx_errors = egress.error_packets; + p_stats->rx_dropped = ingress.discard_packets; + p_stats->tx_dropped = egress.discard_packets; + p_stats->multicast = ingress.good_multicast_packets + + ingress.good_broadcast_packets; + +#undef MLXSW_SP_ROUTER_ALL_GOOD + + return 0; +} + +static int +mlxsw_sp_router_port_l3_stats_report_delta(struct mlxsw_sp_rif *rif, + struct netdev_notifier_offload_xstats_info *info) +{ + struct rtnl_hw_stats64 stats = {}; + int err; + + if (!mlxsw_sp_router_port_l3_stats_enabled(rif)) + return 0; + + err = mlxsw_sp_router_port_l3_stats_fetch(rif, &stats); + if (err) + return err; + + netdev_offload_xstats_report_delta(info->report_delta, &stats); + return 0; +} + +struct mlxsw_sp_router_hwstats_notify_work { + struct work_struct work; + struct net_device *dev; +}; + +static void mlxsw_sp_router_hwstats_notify_work(struct work_struct *work) +{ + struct mlxsw_sp_router_hwstats_notify_work *hws_work = + container_of(work, struct mlxsw_sp_router_hwstats_notify_work, + work); + + rtnl_lock(); + rtnl_offload_xstats_notify(hws_work->dev); + rtnl_unlock(); + dev_put(hws_work->dev); + kfree(hws_work); +} + +static void +mlxsw_sp_router_hwstats_notify_schedule(struct net_device *dev) +{ + struct mlxsw_sp_router_hwstats_notify_work *hws_work; + + /* To collect notification payload, the core ends up sending another + * notifier block message, which would deadlock on the attempt to + * acquire the router lock again. Just postpone the notification until + * later. + */ + + hws_work = kzalloc(sizeof(*hws_work), GFP_KERNEL); + if (!hws_work) + return; + + INIT_WORK(&hws_work->work, mlxsw_sp_router_hwstats_notify_work); + dev_hold(dev); + hws_work->dev = dev; + mlxsw_core_schedule_work(&hws_work->work); +} + int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif) { return rif->dev->ifindex; @@ -8156,6 +8378,16 @@ const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif) return rif->dev; } +static void mlxsw_sp_rif_push_l3_stats(struct mlxsw_sp_rif *rif) +{ + struct rtnl_hw_stats64 stats = {}; + + if (!mlxsw_sp_router_port_l3_stats_fetch(rif, &stats)) + netdev_offload_xstats_push_delta(rif->dev, + NETDEV_OFFLOAD_XSTATS_TYPE_L3, + &stats); +} + static struct mlxsw_sp_rif * mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp, const struct mlxsw_sp_rif_params *params, @@ -8216,10 +8448,19 @@ mlxsw_sp_rif_create(struct mlxsw_sp *mlxsw_sp, goto err_mr_rif_add; } - mlxsw_sp_rif_counters_alloc(rif); + if (netdev_offload_xstats_enabled(rif->dev, + NETDEV_OFFLOAD_XSTATS_TYPE_L3)) { + err = mlxsw_sp_router_port_l3_stats_enable(rif); + if (err) + goto err_stats_enable; + mlxsw_sp_router_hwstats_notify_schedule(rif->dev); + } else { + mlxsw_sp_rif_counters_alloc(rif); + } return rif; +err_stats_enable: err_mr_rif_add: for (i--; i >= 0; i--) mlxsw_sp_mr_rif_del(vr->mr_table[i], rif); @@ -8249,7 +8490,15 @@ static void mlxsw_sp_rif_destroy(struct mlxsw_sp_rif *rif) mlxsw_sp_router_rif_gone_sync(mlxsw_sp, rif); vr = &mlxsw_sp->router->vrs[rif->vr_id]; - mlxsw_sp_rif_counters_free(rif); + if (netdev_offload_xstats_enabled(rif->dev, + NETDEV_OFFLOAD_XSTATS_TYPE_L3)) { + mlxsw_sp_rif_push_l3_stats(rif); + mlxsw_sp_router_port_l3_stats_disable(rif); + mlxsw_sp_router_hwstats_notify_schedule(rif->dev); + } else { + mlxsw_sp_rif_counters_free(rif); + } + for (i = 0; i < MLXSW_SP_L3_PROTO_MAX; i++) mlxsw_sp_mr_rif_del(vr->mr_table[i], rif); ops->deconfigure(rif); @@ -9126,6 +9375,35 @@ static int mlxsw_sp_router_port_pre_changeaddr_event(struct mlxsw_sp_rif *rif, return -ENOBUFS; } +static int +mlxsw_sp_router_port_offload_xstats_cmd(struct mlxsw_sp_rif *rif, + unsigned long event, + struct netdev_notifier_offload_xstats_info *info) +{ + switch (info->type) { + case NETDEV_OFFLOAD_XSTATS_TYPE_L3: + break; + default: + return 0; + } + + switch (event) { + case NETDEV_OFFLOAD_XSTATS_ENABLE: + return mlxsw_sp_router_port_l3_stats_enable(rif); + case NETDEV_OFFLOAD_XSTATS_DISABLE: + mlxsw_sp_router_port_l3_stats_disable(rif); + return 0; + case NETDEV_OFFLOAD_XSTATS_REPORT_USED: + mlxsw_sp_router_port_l3_stats_report_used(rif, info); + return 0; + case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA: + return mlxsw_sp_router_port_l3_stats_report_delta(rif, info); + } + + WARN_ON_ONCE(1); + return 0; +} + int mlxsw_sp_netdevice_router_port_event(struct net_device *dev, unsigned long event, void *ptr) { @@ -9151,6 +9429,15 @@ int mlxsw_sp_netdevice_router_port_event(struct net_device *dev, case NETDEV_PRE_CHANGEADDR: err = mlxsw_sp_router_port_pre_changeaddr_event(rif, ptr); break; + case NETDEV_OFFLOAD_XSTATS_ENABLE: + case NETDEV_OFFLOAD_XSTATS_DISABLE: + case NETDEV_OFFLOAD_XSTATS_REPORT_USED: + case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA: + err = mlxsw_sp_router_port_offload_xstats_cmd(rif, event, ptr); + break; + default: + WARN_ON_ONCE(1); + break; } out: From patchwork Wed Mar 2 16:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766278 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 EE193C433EF for ; Wed, 2 Mar 2022 16:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238592AbiCBQeS (ORCPT ); Wed, 2 Mar 2022 11:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238954AbiCBQeM (ORCPT ); Wed, 2 Mar 2022 11:34:12 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2087.outbound.protection.outlook.com [40.107.236.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 040324ECFD for ; Wed, 2 Mar 2022 08:33:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZoaFb9Uty+DavASSgmU9X5DiCdXOx2gBabQrUGcnecuWktnG0D2KDWauP7FwovWAwnJdswXmchoMDFHuS/Zyt4HTWpgu/Pzlv7jQF9hmv5EgUHa1YMpa3jtpxmQLBMgd9G0W2HuMq+oyDHtvf5hpDaarMnSVQpjnHS5m/BP/Hca7S7xzNIw9WhN342EC8wzFRGM4oaEmovEjx60vwWyji5YSj1YIDJbBgFAdwzBDY/kQrbwCTHPSXq3gDuuenAG91bSDNmXLLeI/XX9rbFV2+TafZb3WqDg1cKGpTyuxqoMDD6z5jj51P1KjUP3kDEYI85d3uPeO3Lo4FlA4x6auPg== 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=aZyb0/RB3ubDePc05dNyTsmJjNBnynRcl5rLNzwG+SQ=; b=gkOweHVZRga48AyDEKrSMb3lNCDZ4NAJTYh8Yl0yot9VUzYUDQfaK/FpsrjHJ9qKnx6refnEgyYkN9kMfMzdyiwiXmMO7fntt+D7uR0XTT5ZRh4gJQyCYIAZyVAYX9p4hly+LaD2DxXue2GDYVWvuuG6OzGCYAJBUV3vYRtJe88h1UQvagNqEPNZbo0e9P91p/uDhihkWQl51R9YwZ7yw/E4Jx6GDOUvNe1G+yXfsq1YDDdEVHPgG3atuwAtYhcw5Fa4rSiYpKvSMeAw71dnWqLvcAV4jrOJgzoQrENdQILUFegrpTYJbfvT/ou9aF7wVHXN9t8WLezXj0ulx9PX4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aZyb0/RB3ubDePc05dNyTsmJjNBnynRcl5rLNzwG+SQ=; b=HKWQgHWz/mExQrYzVXfYwMF4JdyMMkx4MCoSKu1EEeNRJvOExSlU4xE1LW3WvzvBRRsyzN2oXir3V6On60tMNq/tmSD3kpPBv61oPZXDZqhJ4dEpdvslTiTLiH7UomiIwm+YbaK1e0TNp42IVUj4SmLkDOv1/u4DXb9KAtmrETTvE/nDmjwJkJxVEZ687vEswmSn6ELPpDQwtfXi9KKNEqCRAX4wUVa6fxXgiNQXREpjLq49imZUc2FfMTTXtYiZTWciPqZGrvvBJTcLQBlz0Dzjjpn480MwyVfv90HJsz1Nwtq9TtGsHrYvwp5lZbzDfNx8y1ySRva2m04qVtwUfA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by BYAPR12MB3208.namprd12.prod.outlook.com (2603:10b6:a03:13b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25; Wed, 2 Mar 2022 16:33:25 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:33:25 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 14/14] selftests: forwarding: hw_stats_l3: Add a new test Date: Wed, 2 Mar 2022 18:31:28 +0200 Message-Id: <20220302163128.218798-15-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR09CA0052.eurprd09.prod.outlook.com (2603:10a6:802:28::20) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 847f1338-f9e5-4552-19c6-08d9fc6a5fca X-MS-TrafficTypeDiagnostic: BYAPR12MB3208:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 34uEtObxWWThSbM+0f7UCCh4Oo6N8yqpy/LLZluH2CvzYJvHVNLqiJ0Xppko/Fr75UqFCSx/75xN4qyY+sWE+QIPQ9AOdcFSL/tEPHtBbrXijQ1rErKHQvTzn1s/Km5wVH+twXhW0brzyv7l08C+Jw5PP0JaBsCXHV4gh2RsG46Anwzd29bHwpOsX/7Sxcr67NkedlLBHvNEnkRj9Y5u4fdjHJesB71ggYuPF4CxZ1DAQFjNLnEXTOnuwjpLSMzMbDsQkFX/UALljWMk9E3zExR3dZmpVCH/mLyTHGq0Qa8Vcq+hTofd1w3UoF6e05sa82px2+K5yHgYC4M0vHfuxzQfLTkpcklBbAU5dqhDUnZ1ZJB6iqLgMIZ5Ni1qGBNqptnHG6/KTR4z77pHCYDqQ644VfLErd+b1jxV71pdjMLpnbVnonA2Io5H6ZqxzV4JqFrfynk7j9RlpXHNB238aDhxQ5xnniZ29Y+ZT5PYwCpGuSXMpjMWkr0dddgRprelVBQ4Eaor1Skqw+BQTKNCA6dOYWUqAQ7A1FELgG7iazNIewNmLuwjefHueWIzRipKoD6jNmfumCWsNgQu3iskjSrJHYF/o+vTvVB78kL0rptip4SUL1BJoB0dY344XDT+1RxVNZ0NALsdOnvVTfuiwvlWelFVVmUBdcIU42xhloxokHZI1xP5SmBrR43GUeNM4RVLb1HB5WRHwiiXB+NOgw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(66574015)(6512007)(107886003)(4326008)(66946007)(66476007)(38100700002)(66556008)(2616005)(2906002)(86362001)(5660300002)(8676002)(26005)(83380400001)(186003)(36756003)(6486002)(508600001)(316002)(6916009)(6506007)(1076003)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8xYnTmMgd4zkKEDkhEsc+WR7hOMWCnesZrs4GIApijunLnz4Ie3ac4B6Z5wiAwaCGs2JY2vkACB4i5sD38JGNwUH6HDrB6/VeCuahc78bAI17N26XO2m2zFA6dUnw3MbG2ELrJKVJb9sw3Z8x3AI01tPEgdOPypOFXYzb8ox3bW3aFNFdOmhpj8MahdGUB7WDl2Qt2vFFJ1wOjkfYVginOQIh9dsPn8Shnjdy0uP7URgBH433p5v6yFJupQhR8XcgDC0+9h+URIvIjSaOKfzLVgqqggrJD+B2bOtjjQyCtb+b2UAMVxwRHTdIoFF340TYofPox97fKW5/SnH6Uf8fDJksz5WQILe01EjWOSLoR4hrseMYd9ViQAzX//Z/GYQjyd7Uv2NScrYX6VEOTPr2cLD/dPvtXiZBEu93nPxV8s0yx/8VhwFx4ljwjQFtTsnAX0G5HGYDQl2nAnvzKz2VvQKF3pU0m2fa6DC+fqdF7pcx612KTOMABg8XnMvCnnrV4pTBE4b0Ulwkkw0zGQG1QpZuilG4iI6TXnnhaxbYlDmdE55AXOEa58+GF3/HdPNfRt/Sr9L64bDDR1iar0NzmC0SL9GOqqLmkORKPX1ggAJ1+iPOTHu0CdXd8QHKyNbz0llnUNKFdQ24mojzqFR6+bIklcMEG+wocETKBuAARCB6+BSutY/Ggtdv4vCi9UlJwZbzKI28ISJl5eaHauB3R3p8sXbbDhvBNTR6Q2cvMTy5xWGfyc9K5HbWuzISXR5sh8pCVJjNZ7Yb5YkyhbFDePNDEITsQ0dugW4GMv2Z9mE+mfbc8aor/3mLAFLJNDfDhF5elrydqv1bNav9YYzKBF62dfFE+Zcu9ySfnGgQIqWrW57RRnX2HLRPSZVVZ2zoWVyWtsQpSGMQEVDH8ie53kPDfduCspY9qfEwx5Jj6J7y+fYRb125K8yJfb1ZdmrXi5+rBKDVhbrAb4TDfUx3GYFFGUcD/cOA18we07hc7Vf2ODHX8DUwUJUbx2jfamBz8kUS6iMgBQlHfgOUabqU4Kvt8MHDWqb8p4S5kPJaieSG0uKcn37xswzMXKQzryOriZw9w/dUo75kydIoaZlIFUdOob9es033v/Wyc+n9DnZr9OkItd1Sv1QyajzIoyY1S+fHBOn4oKuPiAmjw0m7qk3JPosjqaHdzCyKSd1437pLKloJo89/1SlMQuU+Dv0wwlrvCr4qGxdFWi/CIlYOVBxARlwyvmTmTL1OuIdu7LKyYvFCnblqXvWuLxzPh7I28yWkcVKuCLdW3Xx8IQJrSxH8RRSDo7ZJAzeEfpzZpqKqkp3OHKhpy/BZQJ/KcE2MUfoWYCOGOn+PTkbwuhpxzxqyfuEECaRw0WpwKshXuM6Khh8sJcQ+gPrhC1wgQfw+8KK9UvgT6gbbMp9G0yT9bel6ayg+BR+M+MBpsF2d+fL6qhjVfPw6JEuJvTzfl2b4ajGah9C15z9/rzZu2SQ+PyXiPnMuwUMHe8wP9oQhAlOgLR5YLIlZIXSE4K6On1BgXogHk4V9n78Hck4Nk7ACEmaNVoWoKatGkQwGstFsddFRu6LtGrhhgnKc4+RZZG+WImeCRj1net/otB8VNU28iPWy7igqYDHDDLl2Ka5Ht8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 847f1338-f9e5-4552-19c6-08d9fc6a5fca X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:33:25.4232 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Udh8OSN6Kq+zk3bAFBkOyYZXnXpoLoQIrMaPXhQ5K08AV0cJIhzHdi6wPU/1kFf+eUff8uOufULW8ooDjIC4wQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3208 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata Add a test that verifies operation of L3 HW statistics. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- .../selftests/net/forwarding/hw_stats_l3.sh | 332 ++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100755 tools/testing/selftests/net/forwarding/hw_stats_l3.sh diff --git a/tools/testing/selftests/net/forwarding/hw_stats_l3.sh b/tools/testing/selftests/net/forwarding/hw_stats_l3.sh new file mode 100755 index 000000000000..1c11c4256d06 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/hw_stats_l3.sh @@ -0,0 +1,332 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# +--------------------+ +----------------------+ +# | H1 | | H2 | +# | | | | +# | $h1.200 + | | + $h2.200 | +# | 192.0.2.1/28 | | | | 192.0.2.18/28 | +# | 2001:db8:1::1/64 | | | | 2001:db8:2::1/64 | +# | | | | | | +# | $h1 + | | + $h2 | +# | | | | | | +# +------------------|-+ +-|--------------------+ +# | | +# +------------------|-------------------------|--------------------+ +# | SW | | | +# | | | | +# | $rp1 + + $rp2 | +# | | | | +# | $rp1.200 + + $rp2.200 | +# | 192.0.2.2/28 192.0.2.17/28 | +# | 2001:db8:1::2/64 2001:db8:2::2/64 | +# | | +# +-----------------------------------------------------------------+ + +ALL_TESTS=" + ping_ipv4 + ping_ipv6 + test_stats_rx_ipv4 + test_stats_tx_ipv4 + test_stats_rx_ipv6 + test_stats_tx_ipv6 + respin_enablement + test_stats_rx_ipv4 + test_stats_tx_ipv4 + test_stats_rx_ipv6 + test_stats_tx_ipv6 + reapply_config + ping_ipv4 + ping_ipv6 + test_stats_rx_ipv4 + test_stats_tx_ipv4 + test_stats_rx_ipv6 + test_stats_tx_ipv6 + test_stats_report_rx + test_stats_report_tx + test_destroy_enabled + test_double_enable +" +NUM_NETIFS=4 +source lib.sh + +h1_create() +{ + simple_if_init $h1 + vlan_create $h1 200 v$h1 192.0.2.1/28 2001:db8:1::1/64 + ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2 + ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2 +} + +h1_destroy() +{ + ip -6 route del 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2 + ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2 + vlan_destroy $h1 200 + simple_if_fini $h1 +} + +h2_create() +{ + simple_if_init $h2 + vlan_create $h2 200 v$h2 192.0.2.18/28 2001:db8:2::1/64 + ip route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17 + ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::2 +} + +h2_destroy() +{ + ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::2 + ip route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17 + vlan_destroy $h2 200 + simple_if_fini $h2 +} + +router_rp1_200_create() +{ + ip link add name $rp1.200 up \ + link $rp1 addrgenmode eui64 type vlan id 200 + ip address add dev $rp1.200 192.0.2.2/28 + ip address add dev $rp1.200 2001:db8:1::2/64 + ip stats set dev $rp1.200 l3_stats on +} + +router_rp1_200_destroy() +{ + ip stats set dev $rp1.200 l3_stats off + ip address del dev $rp1.200 2001:db8:1::2/64 + ip address del dev $rp1.200 192.0.2.2/28 + ip link del dev $rp1.200 +} + +router_create() +{ + ip link set dev $rp1 up + router_rp1_200_create + + ip link set dev $rp2 up + vlan_create $rp2 200 "" 192.0.2.17/28 2001:db8:2::2/64 +} + +router_destroy() +{ + vlan_destroy $rp2 200 + ip link set dev $rp2 down + + router_rp1_200_destroy + ip link set dev $rp1 down +} + +setup_prepare() +{ + h1=${NETIFS[p1]} + rp1=${NETIFS[p2]} + + rp2=${NETIFS[p3]} + h2=${NETIFS[p4]} + + rp1mac=$(mac_get $rp1) + rp2mac=$(mac_get $rp2) + + vrf_prepare + + h1_create + h2_create + + router_create + + forwarding_enable +} + +cleanup() +{ + pre_cleanup + + forwarding_restore + + router_destroy + + h2_destroy + h1_destroy + + vrf_cleanup +} + +ping_ipv4() +{ + ping_test $h1.200 192.0.2.18 " IPv4" +} + +ping_ipv6() +{ + ping_test $h1.200 2001:db8:2::1 " IPv6" +} + +get_l3_stat() +{ + local selector=$1; shift + + ip -j stats show dev $rp1.200 group offload subgroup l3_stats | + jq '.[0].stats64.'$selector +} + +send_packets_rx_ipv4() +{ + # Send 21 packets instead of 20, because the first one might trap and go + # through the SW datapath, which might not bump the HW counter. + $MZ $h1.200 -c 21 -d 20msec -p 100 \ + -a own -b $rp1mac -A 192.0.2.1 -B 192.0.2.18 \ + -q -t udp sp=54321,dp=12345 +} + +send_packets_rx_ipv6() +{ + $MZ $h1.200 -6 -c 21 -d 20msec -p 100 \ + -a own -b $rp1mac -A 2001:db8:1::1 -B 2001:db8:2::1 \ + -q -t udp sp=54321,dp=12345 +} + +send_packets_tx_ipv4() +{ + $MZ $h2.200 -c 21 -d 20msec -p 100 \ + -a own -b $rp2mac -A 192.0.2.18 -B 192.0.2.1 \ + -q -t udp sp=54321,dp=12345 +} + +send_packets_tx_ipv6() +{ + $MZ $h2.200 -6 -c 21 -d 20msec -p 100 \ + -a own -b $rp2mac -A 2001:db8:2::1 -B 2001:db8:1::1 \ + -q -t udp sp=54321,dp=12345 +} + +___test_stats() +{ + local dir=$1; shift + local prot=$1; shift + + local a + local b + + a=$(get_l3_stat ${dir}.packets) + send_packets_${dir}_${prot} + "$@" + b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \ + get_l3_stat ${dir}.packets) + check_err $? "Traffic not reflected in the counter: $a -> $b" +} + +__test_stats() +{ + local dir=$1; shift + local prot=$1; shift + + RET=0 + ___test_stats "$dir" "$prot" + log_test "Test $dir packets: $prot" +} + +test_stats_rx_ipv4() +{ + __test_stats rx ipv4 +} + +test_stats_tx_ipv4() +{ + __test_stats tx ipv4 +} + +test_stats_rx_ipv6() +{ + __test_stats rx ipv6 +} + +test_stats_tx_ipv6() +{ + __test_stats tx ipv6 +} + +# Make sure everything works well even after stats have been disabled and +# reenabled on the same device without touching the L3 configuration. +respin_enablement() +{ + log_info "Turning stats off and on again" + ip stats set dev $rp1.200 l3_stats off + ip stats set dev $rp1.200 l3_stats on +} + +# For the initial run, l3_stats is enabled on a completely set up netdevice. Now +# do it the other way around: enabling the L3 stats on an L2 netdevice, and only +# then apply the L3 configuration. +reapply_config() +{ + log_info "Reapplying configuration" + + router_rp1_200_destroy + + ip link add name $rp1.200 link $rp1 addrgenmode none type vlan id 200 + ip stats set dev $rp1.200 l3_stats on + ip link set dev $rp1.200 up addrgenmode eui64 + ip address add dev $rp1.200 192.0.2.2/28 + ip address add dev $rp1.200 2001:db8:1::2/64 +} + +__test_stats_report() +{ + local dir=$1; shift + local prot=$1; shift + + local a + local b + + RET=0 + + a=$(get_l3_stat ${dir}.packets) + send_packets_${dir}_${prot} + ip address flush dev $rp1.200 + b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \ + get_l3_stat ${dir}.packets) + check_err $? "Traffic not reflected in the counter: $a -> $b" + log_test "Test ${dir} packets: stats pushed on loss of L3" + + ip stats set dev $rp1.200 l3_stats off + ip link del dev $rp1.200 + router_rp1_200_create +} + +test_stats_report_rx() +{ + __test_stats_report rx ipv4 +} + +test_stats_report_tx() +{ + __test_stats_report tx ipv4 +} + +test_destroy_enabled() +{ + RET=0 + + ip link del dev $rp1.200 + router_rp1_200_create + + log_test "Destroy l3_stats-enabled netdev" +} + +test_double_enable() +{ + RET=0 + ___test_stats rx ipv4 \ + ip stats set dev $rp1.200 l3_stats on + log_test "Test stat retention across a spurious enablement" +} + +trap cleanup EXIT + +setup_prepare +setup_wait + +tests_run + +exit $EXIT_STATUS