From patchwork Thu Feb 29 18:16:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577532 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2059.outbound.protection.outlook.com [40.107.94.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74FB670AD9 for ; Thu, 29 Feb 2024 18:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230818; cv=fail; b=kXm+RYn09JF9cjvAJd46NPNYPAzuR/JPmB6x99+hLwFRJ1rUL4eg4fHmAOrD6C4Rcs7N4yMMhAWEDfa1eQrVh4B7qVo+GI5dxQGhu5XH4mgxo/lnz0ryi7Hj8XybWKxXRo+EXlsqa/1elscLJM7JXTusSsCN5o2+q3jsj6ivLUM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230818; c=relaxed/simple; bh=w4MhmrSRMwWDJxa3Tu4LEoQcqiPeRWLSwzn63vA4Als=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LCAELaG1KcGMkTx0XBak5qPcPT7J7b2uv5ms1KPYUofANzsC9UTb+p6Wx1Us8JTbBFwFX6ZT2VxyQkrezRvleBoF63tQBNJo/3/+HrWGswOFuNa0oRkaccFBuDct8SOmnjZPUYBwk7E4NEGcf/tsp8enJx3BYHqyod/nAMfpHDQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=aIp8EZs4; arc=fail smtp.client-ip=40.107.94.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="aIp8EZs4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bMqSkdyHyjxND+LriOfCe4vdwamL28Y/VlbRnzgLQC1gWSJS8LCZaTUCmEZHt6KAXtvh8+zfPAdCOmeIISLDdsZtZcvN7DrCK7zEchavl9G5p+fV6FHqVV8huEC/2zCHLwViRhrfNW8qhU9Zp45orbELVm8azDhuEzpf6gIDxooSzlDZykYxyd+NKujcBMTiZ1guadJKlHbEc0nQ+v0PGUFMOdZSx5Rgw0p6P7+UqeAheDsthpv9grCdZoJH2mQl2Qt08+LvFiL1dhr97CqUTa37kjZDQArtAR4VAwuPdYx9dCfwTTwXEPcPJ5hVCfeC4ojC/5SXZ1Zgtdjek7HRGg== 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=d24wMTkB4u1gW66C+ptM52WAY90TJulmmW8ZN3nU32k=; b=GXd67Rwz6D2GrQDj0ql3xYkEhQ15nvfzonlOz1ETbmA6S5JoASb8syjZkkAk9dBd0HsRs4V+JBQm5DOkIYMp5+oNSj+uQ7iowyyOyzXAbBNIbiGbBv9riGSrCPlji+Wk/ePMY63pji5jBXfx8iUPjCwbM5pZAllFyYVoqOIgUq5uD/pOxMrSF+pucLG2kxmiYD2Qgcnz1rW6+B4qDXW8lf7TODkWRjOYMLm+eCz8SJGcdMxa9MXdC97bOmto9binoEUgYZ1iBpJz/7ia9mBSazEqDdgnUxiV5RpfIBReTh2iY9cpMARs73d62Fahx+0zwucJkIB27DFNji5lOfazXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=d24wMTkB4u1gW66C+ptM52WAY90TJulmmW8ZN3nU32k=; b=aIp8EZs48hYULKsvP7gzp9kHiMlPcHYdXQJPKZNpmcECB1sp7oxH3wA/PfcMCdAeTTcJgk/uBE/nFQADJaLwIMCMthyNdo6K8TbXdkoPI7RhCiMrz4TrJdNJD2UM81079dBFMyIDd28eqck/WpHvmO1fIUhfqF3NU+WeJYZ8a4gxscyWtxsCqK5rctwW/XPSTTyy6vbgJdBxAigDTyrzMV600h9JKcR7L4mnJJyghEkmKNNPDjJGIe5H7bBOHqcqfbjjLuhBRKpy+trqC7j16guCRhGVlH2MW7+WFECPbOr0Por+5zNtOJzxd9irkKqFX62w6TnYjRvLXVwKj4Hjbg== Received: from BN1PR12CA0016.namprd12.prod.outlook.com (2603:10b6:408:e1::21) by MN0PR12MB5737.namprd12.prod.outlook.com (2603:10b6:208:370::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Thu, 29 Feb 2024 18:20:10 +0000 Received: from BN1PEPF00004687.namprd05.prod.outlook.com (2603:10b6:408:e1:cafe::a7) by BN1PR12CA0016.outlook.office365.com (2603:10b6:408:e1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.32 via Frontend Transport; Thu, 29 Feb 2024 18:20:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF00004687.mail.protection.outlook.com (10.167.243.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:10 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:19:50 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:19:46 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , Subject: [PATCH net-next v2 1/7] net: nexthop: Adjust netlink policy parsing for a new attribute Date: Thu, 29 Feb 2024 19:16:34 +0100 Message-ID: <410a56b273484e34ece228e9aec0008ece6b96b3.1709217658.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004687:EE_|MN0PR12MB5737:EE_ X-MS-Office365-Filtering-Correlation-Id: 01b8d514-8148-48be-e69b-08dc395310c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ugMRcv9KItZ/liSgeKN519LIscy0V4aXgceEQbwZkoUs6nWQk1KFZKiVAsoTOV/jDvtMNViULeMDfmZR1HAQmmqY6bln3l1x15p9F/NT92zvpCS/YGWdiaM9je3CQfSZe+TRl8NX5OZM6DCwK/KGxWvpyCYv5+QEtm3lnelIaN4n2Ce4eT2536z3vaBAkq1XQXS4znOXd4hxAA5tkDp+n7S4oxspCE9ZHNwM+5zgGpRQ2Ab6YOqkCn1A8mtonHBBNvoVIJvtxZ783bs7XqrycDjKsnZftfYeJSwl3cAx65qLr2Lsfja1+Z3vS6NLyYzgs/d5QZeggfWb//2gU8RYgMN1Kb8NXhmNHmO5nbrClEPgbpRYygL4369dSEG6zQTtGtADCyHFpMAxFej5yRc7AXfPkOHZyhopda/bwETzeS2QhV/ptCzkwAaeQWKTw9osAgCofG4SW/bjG0yzcm0CPPhfUsLPChmZSUqHRLSuiTKtuYz/vcMjh5fl8+47jbn+wZtphzhg8xPTAe999IORKznqCgnnik9nVD4wcxIafepsrgsaIkxsKcrrlFrvVJog4psC8IvYSW4G6tpfscQZD/g/dNsm/B88MDclLdERrQD9tnHtegOX60MxyUbqQZxGtL/hVluv5KKpkNOw2pWpgBCrhF12+jiCS6LcAkXzfgzjAarKXNu4SJ1w62qi/bSHjz/LdWIYBrRhe8wsUJObxWqoN4/22zlqALEBEmR6ZBU1d13OxkUbka6oos3ebavi X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:10.3519 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 01b8d514-8148-48be-e69b-08dc395310c4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004687.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5737 X-Patchwork-Delegate: kuba@kernel.org A following patch will introduce a new attribute, op-specific flags to adjust the behavior of an operation. Different operations will recognize different flags. - To make the differentiation possible, stop sharing the policies for get and del operations. - To allow querying for presence of the attribute, have all the attribute arrays sized to NHA_MAX, regardless of what is permitted by policy, and pass the corresponding value to nlmsg_parse() as well. Signed-off-by: Petr Machata Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 58 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 70509da4f080..bcd4df2f1cad 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -43,6 +43,10 @@ static const struct nla_policy rtm_nh_policy_get[] = { [NHA_ID] = { .type = NLA_U32 }, }; +static const struct nla_policy rtm_nh_policy_del[] = { + [NHA_ID] = { .type = NLA_U32 }, +}; + static const struct nla_policy rtm_nh_policy_dump[] = { [NHA_OIF] = { .type = NLA_U32 }, [NHA_GROUPS] = { .type = NLA_FLAG }, @@ -2966,9 +2970,9 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, return err; } -static int __nh_valid_get_del_req(const struct nlmsghdr *nlh, - struct nlattr **tb, u32 *id, - struct netlink_ext_ack *extack) +static int nh_valid_get_del_req(const struct nlmsghdr *nlh, + struct nlattr **tb, u32 *id, + struct netlink_ext_ack *extack) { struct nhmsg *nhm = nlmsg_data(nlh); @@ -2991,26 +2995,12 @@ static int __nh_valid_get_del_req(const struct nlmsghdr *nlh, return 0; } -static int nh_valid_get_del_req(const struct nlmsghdr *nlh, u32 *id, - struct netlink_ext_ack *extack) -{ - struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)]; - int err; - - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, - ARRAY_SIZE(rtm_nh_policy_get) - 1, - rtm_nh_policy_get, extack); - if (err < 0) - return err; - - return __nh_valid_get_del_req(nlh, tb, id, extack); -} - /* rtnl */ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct net *net = sock_net(skb->sk); + struct nlattr *tb[NHA_MAX + 1]; struct nl_info nlinfo = { .nlh = nlh, .nl_net = net, @@ -3020,7 +3010,12 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, int err; u32 id; - err = nh_valid_get_del_req(nlh, &id, extack); + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, + rtm_nh_policy_del, extack); + if (err < 0) + return err; + + err = nh_valid_get_del_req(nlh, tb, &id, extack); if (err) return err; @@ -3038,12 +3033,18 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct net *net = sock_net(in_skb->sk); + struct nlattr *tb[NHA_MAX + 1]; struct sk_buff *skb = NULL; struct nexthop *nh; int err; u32 id; - err = nh_valid_get_del_req(nlh, &id, extack); + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, + rtm_nh_policy_get, extack); + if (err < 0) + return err; + + err = nh_valid_get_del_req(nlh, tb, &id, extack); if (err) return err; @@ -3157,11 +3158,10 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh, struct nh_dump_filter *filter, struct netlink_callback *cb) { - struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump)]; + struct nlattr *tb[NHA_MAX + 1]; int err; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, - ARRAY_SIZE(rtm_nh_policy_dump) - 1, + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, rtm_nh_policy_dump, cb->extack); if (err < 0) return err; @@ -3300,11 +3300,10 @@ static int nh_valid_dump_bucket_req(const struct nlmsghdr *nlh, struct netlink_callback *cb) { struct nlattr *res_tb[ARRAY_SIZE(rtm_nh_res_bucket_policy_dump)]; - struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump_bucket)]; + struct nlattr *tb[NHA_MAX + 1]; int err; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, - ARRAY_SIZE(rtm_nh_policy_dump_bucket) - 1, + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, rtm_nh_policy_dump_bucket, NULL); if (err < 0) return err; @@ -3474,16 +3473,15 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh, u32 *id, u16 *bucket_index, struct netlink_ext_ack *extack) { - struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get_bucket)]; + struct nlattr *tb[NHA_MAX + 1]; int err; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, - ARRAY_SIZE(rtm_nh_policy_get_bucket) - 1, + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, rtm_nh_policy_get_bucket, extack); if (err < 0) return err; - err = __nh_valid_get_del_req(nlh, tb, id, extack); + err = nh_valid_get_del_req(nlh, tb, id, extack); if (err) return err; From patchwork Thu Feb 29 18:16:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577533 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2075.outbound.protection.outlook.com [40.107.102.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 900EC7A124 for ; Thu, 29 Feb 2024 18:20:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230820; cv=fail; b=d4CV80uphdmFzsSZslASuGwaTb/DEm3rSsJE3P5Ey6tiU4nhV7ieBgQ4Mx9PMZb4zV8dBv7DuBIZ7POrX3P+XNgKnP7lBjNvGnia7B/S5v9Bgy/zFVDnKRaTZG7acNACSJxYp5tOhmnCZfJUBuvuos1vUGsRoXR4THRCq1HgraM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230820; c=relaxed/simple; bh=PQKle3U0+edSxspTEEJGtqwlSNRVMRkIddBuPe6R7SU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MXG2j5x3PxvEd/gwLeg7nc2jZbGECUItPpIKwAC+6FtWuUK7y0LZ/0w/sO7KdGUvdwkNzE+KV6DN/ibUvl9u7zFf949zSTz7c3zhap1dWyICjjLHiru5ifw/nvqMwpXDT4FqYTj59++D67S6/3vzZt8o5wTV+tOifEVzJWl46uE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Gmaaz3Sl; arc=fail smtp.client-ip=40.107.102.75 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Gmaaz3Sl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S6+t1sNb60LXOjy58iz9PJO8UeuW2k0g0lYK3fdtDGNqoyEJE0NYCmXZlywxMPJ107NrN2K0eZ4uTjPgCDifcfg8eRoorW8zzEyveC9LrB8hM7lc4KduuDkbw62cLGyQF2tdtgaHT1dcvKETQOGf1uyAoLB+e76KLkSzeWxM0whfZf6q95KJkKX29j63QLs2nJZBMaCcqurCxYYIftYrw5zxZwopRYDBnu/umT2CptKf4GVVCwwq/XXXbqgetEpyJXmeioc5Fag3MzxLRObFpcvL8tYoBk4bLXxq+GSt3DLZmrLPoDvdDZTfqFFGPgpTjVDj4zPLvNibwiD9QeYfqQ== 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=jQE+iwVEmpiJ3lU38lH8fkutr0EoST8pwu6NRyKGhg0=; b=NqwaZZOKe6jvua0a+K9yRrNMN8QhE1AyKlhfjGiNQN3ND7fuyLZW/jTFWNwAILUKd8iPJSo+fK4lY/J01LJZ44sXGxZcu6OkdlOjZj1AYKTnEmU/HTFhKd4zs+MzH1A04Af3S+UDmzDeLYsUBd3Xn23O4RktW3ke9G9EDDcipiBlGH3ihYexxTlRw1vvSWuGvHUXTYPdqbhluZVFtbe1MkXCbsz0DGk9o+UX8Plg+4BjTaPGKY+fHfJP5sUIxW9SAuetTddv9Z/Py854etwh4vBACRmifyyBCJ5jh+9Rmwh+huHtCug0fx+0AauCSgmRj9pGXgQW5EXiXQQ9fhYskw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=jQE+iwVEmpiJ3lU38lH8fkutr0EoST8pwu6NRyKGhg0=; b=Gmaaz3Sl4qzbXcONH0NX9aYpqvXZSD9usfDvmjBAX94fJOQZbvbWobQOlGNsuUrBnQQ8U3Y3h2yLhdwKq81g6M0jDDpOclQLDHTBNdxRs/VviCxr7NTX1nyYjdktZQklgp7r0aBpBEtehWAjxbiWJ+trYEzzLz+U3YpLlnDM1CzMrPe19qYC3DPyWAjSo764/HRA3zqYDpAc+HQYSmINiwrFWae4XiCu+/8vain5oFkmuzhfh87gFXbUpyEbihg1S6LtVDRZJvuQTFKCuIzcPkiNP6e7Mzru+v8avpodHm338EcQzyZtHxYlYaFQkpUZgCHyV23BQfqKWZxLlemKEw== Received: from BY3PR10CA0027.namprd10.prod.outlook.com (2603:10b6:a03:255::32) by PH8PR12MB6961.namprd12.prod.outlook.com (2603:10b6:510:1bc::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Thu, 29 Feb 2024 18:20:11 +0000 Received: from MWH0EPF000971E6.namprd02.prod.outlook.com (2603:10b6:a03:255:cafe::53) by BY3PR10CA0027.outlook.office365.com (2603:10b6:a03:255::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.32 via Frontend Transport; Thu, 29 Feb 2024 18:20:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by MWH0EPF000971E6.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:11 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:19:55 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:19:50 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , Subject: [PATCH net-next v2 2/7] net: nexthop: Add NHA_OP_FLAGS Date: Thu, 29 Feb 2024 19:16:35 +0100 Message-ID: <0aa48cb15c1dbece33b6d090ff47f444852900e1.1709217658.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E6:EE_|PH8PR12MB6961:EE_ X-MS-Office365-Filtering-Correlation-Id: e1c35cc4-f9f0-4486-0424-08dc39531111 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0UeBsMd9TbWztn6nC/glfVBCT99jdBv4DfiFAFwEXDUeUnRDHm3kGRV06+/4YqxzKqxt1OZ1HwGxPT8AZfEFF+D5HpiTWPeIasakPRvKeZ9A9X1DDA5uT1ARFeJYq2t2L3UAjF9n1ob36J40fcGISI/MnMkmVkZ62+qLQ3/Fp4DQX3lJtFHMYhKIBoFpKcYRnm+pvsL9kMgK9Ee2ksShXSX5On9EHrWKfqW4+Z+Ows7PFw8ZGst26iyAIFWGQY4oKPYVNkInzlfiWlhJKAOwtivDJk/dWEqmnWRaYuVPbOcuBhcidID583xx+VReU08TDI0l8NCuOWgvReGHcMTOHBx3vPlN8SJ9p18dM8PVxDjxtgYPrNsOnEMPIW6bD3cpTy3RVE4IqNVjI/qQUVHNoCH1WbHN7heUtBwLa9TDGznNPh8MuhDPuuDVwEb9LbOhbQ6IiVH/PK5HHx87H7fVLTs1Ykhb96OJ79oDEBdloBZYqrlzVU/I+y9/2n2JvbTFpLX89hPoz9Ql2j7pGqHnaL510xNBb3ctPoXPis194nomBYD/rEMERA1ZHy/JaHMtzlM0i6b7lrg+0mDf964BXZ3yaS8WXWki8loXmZo5FS7EcAoMsWWRLxJqSTPECscam3FOIAv7wj2mef46z9bxvsEvPni91knwxkfQevKvE4h6TfqVbuJKJMd3TCFL1wBcmSmVSO/C08Loz+kiDqGu+i3SQG7+3ajAVbHfvC+dOO9MIhIxrtL9vKgbpvfttNfK X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:11.0070 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1c35cc4-f9f0-4486-0424-08dc39531111 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6961 X-Patchwork-Delegate: kuba@kernel.org In order to add per-nexthop statistics, but still not increase netlink message size for consumers that do not care about them, there needs to be a toggle through which the user indicates their desire to get the statistics. To that end, add a new attribute, NHA_OP_FLAGS. The idea is to be able to use the attribute for carrying of arbitrary operation-specific flags, i.e. not make it specific for get / dump. Add the new attribute to get and dump policies, but do not actually allow any flags yet -- those will come later as the flags themselves are defined. Add the necessary parsing code. Signed-off-by: Petr Machata Reviewed-by: David Ahern --- Notes: v2: - Change OP_FLAGS to u32, enforce through NLA_POLICY_MASK include/uapi/linux/nexthop.h | 3 +++ net/ipv4/nexthop.c | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index d8ffa8c9ca78..086444e2946c 100644 --- a/include/uapi/linux/nexthop.h +++ b/include/uapi/linux/nexthop.h @@ -60,6 +60,9 @@ enum { /* nested; nexthop bucket attributes */ NHA_RES_BUCKET, + /* u32; operation-specific flags */ + NHA_OP_FLAGS, + __NHA_MAX, }; diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index bcd4df2f1cad..816ae8ee3e06 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -41,6 +41,7 @@ static const struct nla_policy rtm_nh_policy_new[] = { static const struct nla_policy rtm_nh_policy_get[] = { [NHA_ID] = { .type = NLA_U32 }, + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -52,6 +53,7 @@ static const struct nla_policy rtm_nh_policy_dump[] = { [NHA_GROUPS] = { .type = NLA_FLAG }, [NHA_MASTER] = { .type = NLA_U32 }, [NHA_FDB] = { .type = NLA_FLAG }, + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -2971,7 +2973,7 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, } static int nh_valid_get_del_req(const struct nlmsghdr *nlh, - struct nlattr **tb, u32 *id, + struct nlattr **tb, u32 *id, u32 *op_flags, struct netlink_ext_ack *extack) { struct nhmsg *nhm = nlmsg_data(nlh); @@ -2992,6 +2994,11 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh, return -EINVAL; } + if (tb[NHA_OP_FLAGS]) + *op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); + else + *op_flags = 0; + return 0; } @@ -3007,6 +3014,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, .portid = NETLINK_CB(skb).portid, }; struct nexthop *nh; + u32 op_flags; int err; u32 id; @@ -3015,7 +3023,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, &id, extack); + err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack); if (err) return err; @@ -3036,6 +3044,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, struct nlattr *tb[NHA_MAX + 1]; struct sk_buff *skb = NULL; struct nexthop *nh; + u32 op_flags; int err; u32 id; @@ -3044,7 +3053,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, &id, extack); + err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack); if (err) return err; @@ -3080,6 +3089,7 @@ struct nh_dump_filter { bool group_filter; bool fdb_filter; u32 res_bucket_nh_id; + u32 op_flags; }; static bool nh_dump_filtered(struct nexthop *nh, @@ -3151,6 +3161,11 @@ static int __nh_valid_dump_req(const struct nlmsghdr *nlh, struct nlattr **tb, return -EINVAL; } + if (tb[NHA_OP_FLAGS]) + filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); + else + filter->op_flags = 0; + return 0; } @@ -3474,6 +3489,7 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct nlattr *tb[NHA_MAX + 1]; + u32 op_flags; int err; err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, @@ -3481,7 +3497,7 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, id, extack); + err = nh_valid_get_del_req(nlh, tb, id, &op_flags, extack); if (err) return err; From patchwork Thu Feb 29 18:16:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577534 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2042.outbound.protection.outlook.com [40.107.92.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64C7E7A13D for ; Thu, 29 Feb 2024 18:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230823; cv=fail; b=cQ+Qaabgv/bRUrLur1hv1asWhI/SKJTe0In+qo82O4pjPAmNSrN6Q9gb8KYUhHNCOdjMR7hHyl6rcVFLo8hE/DaBFGrp4d/SMbArrx2qnDII+lVmt1yR09safGopTfp5+JoENSGIP1/Lg0cfHgUDQEauerAB0BBFWNmz6EGOq4c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230823; c=relaxed/simple; bh=FWh5LmZomI4Pt2FKSNazSD8I18Ye2XQ+nI12KavlIgk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PWC1UgTUYqwxShtSd+Q0KV/aX635522RhWxccf28uv9W1j6/2rfXqUiau9oWUoiQPkQV+PdzH4N3G5inbdQQoeIqMSCZ13UdJE4PM0WIjxBBjdA5GNQhshHCvMxoNFSpXJBco2Z6Eyuv5BS4jJmDOtW8JVZ1+w4x+fnNkguMX58= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=VfnbuOOh; arc=fail smtp.client-ip=40.107.92.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="VfnbuOOh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X8P9HmEU4Z3l+97EwYcBrg5wlu6Z2H6qvhJzTKIBw/I8BwBggF2J6u3f0QFMNn6NTOgs6NWmX9RSexOBjCp99wDS0I91ZeHh48zOlcwqWL4Xuo0ttcmyrzY4HMx0SDrzMaIm4nFfsNUOFMmpYdoAMsiHVYfnkWPoGxXISVt7X45s8g0hHx2+7CKOxdiFlHGJpUmk2KLUZtBp4X1X0vLPKK4dYhDAkaxB0o2db50Z17KoW8/iVbhKJsrIBKc9E4BgpI3bVMRdHEhgmxLMVNSS4yLyhNHGAEGSD0wV7KSzV+l3qj5RmrcJOkF4XYlERYKbNOYTEFY/F25f/RXhBa+wVg== 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=UH8gGQvzZ7a+lPhVkpsMU4+V3heBZ9HVGQPV85oVceg=; b=eu2H3mZImMfJ8S7xx09JT0h1dxTRgP9g3pWGQal1oehW0h9k4jAFbg2ca7QUACAs/Y3HgDsolFKOe3dd/AAknzUggwnrLHph+ElO0mz3pLNpheF7iRdwXL64n9MMo3sri8VWaE89hxe9y8ytFGJGr+C6ORQPTxwlt7argm3aXfjqLO4dAeDdWQX+zP3qrfuAfQv+agAEVNtaswR7dOsYnf3MqPR16PNBPeMcmQa6qUAp4N/thFf4D8XW2mn2HXs09X3Bo06kgeFzglMcA9IPPMSFnUfG1Z7tyjHcyIHm4MHejZIjqSWf9qXNwgOMtIWCq28fZggEz0ISsFZBYfsbRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=UH8gGQvzZ7a+lPhVkpsMU4+V3heBZ9HVGQPV85oVceg=; b=VfnbuOOh7iAqWe3ZKpqWWfncnTOXdADg32UEpnOe6V0+CBr1mtPCrS8rso603NKAmxh76LWw5rcpW8GoKyS2jhAycNRQ56LVIg4J479hwghufZ97nFKp8/xwTha4wjqNk5afBTAJR3XMbB9IO327s2byuThMP8dy+Yk5PtLSWzptxE4Q/vjOdvMcecfUrxCB3q4mQUY50pRC3zOpOyJVXMOFPoggCc2ycrSNyGMEo+qtkJYFIfR1s2Z7asuRp2j5sI5mX1XQSc3eQrtdSrreGxqYQ+M/zUSz7yfCMU3dMLKIewnGrJjrNBRsVsDvZXVISg4oZtttsRTLEPSlWfdn6A== Received: from BY3PR10CA0029.namprd10.prod.outlook.com (2603:10b6:a03:255::34) by DS7PR12MB6359.namprd12.prod.outlook.com (2603:10b6:8:94::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Thu, 29 Feb 2024 18:20:15 +0000 Received: from MWH0EPF000971E6.namprd02.prod.outlook.com (2603:10b6:a03:255:cafe::80) by BY3PR10CA0029.outlook.office365.com (2603:10b6:a03:255::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.28 via Frontend Transport; Thu, 29 Feb 2024 18:20:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by MWH0EPF000971E6.mail.protection.outlook.com (10.167.243.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:20:00 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:19:55 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , Subject: [PATCH net-next v2 3/7] net: nexthop: Add nexthop group entry stats Date: Thu, 29 Feb 2024 19:16:36 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E6:EE_|DS7PR12MB6359:EE_ X-MS-Office365-Filtering-Correlation-Id: ffd6f906-7bf8-4f55-4935-08dc3953139e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fWt5ORo361kmXZTirKUc9VQRA8E1Rb10Q3+CJSEgzvp7LmMyBq1C5fhB8fFRTWFbByMS3Xt9nNKYj7qIp2b+PFRt1PXSoxvjHkewxH3Y78SF6Gk3C2rS+KF4rKW/Qos6/mMQuaVUeNbA6brlTOXIHCGthBqh5roexo7amJic4Zt7KQIqOZLrUhAc5LcqPeP2IVT7v4l1xchTINdvgdrXWg/0kDnQ7yKGKac6/j3gPupBNjEmxRBUO+gr8aDC5EnKKgd07K0VQ/GW90RLFnBuJL0klL4V0FjZllPeADAeUg+LKgEZmvBR2nSrH5UbG18AlLk9+G55V26OTIrL5GDl+IhjRIfdjSIK4c6TkLg4vVz0QnyUU4NjBhQ1ATOXVxt/ou46/7LVT/RhcI8EmEhpjtK0d85Hoct5kwREb1wzzq1HId/BaFC8qbMDqPpHLSUnImKkYXvWHlkbnLupkw3JTGtwStnEm3mPtUksjkKeD9lwIv16mxQX/ZNN7MtaLWHL8hzsiuTOUmY7dj4fjkjc3IS88l1gozZ/031kLFkzWKTeYn+FDdi3UQHJG66JdJ1dkYF3jM9tMBPlvmRsP6oV5LHyT7tQIiPw/DFfazjp3jHVDYnhk/cSmHP8q1gQP/M9bDg5/87KPZeeyU1G5T2iMowitBK17vL+GGKWNmAP7dDC+ZpEkO+mEiBkB0x615yj75l3JHby3TCdDLUV3xf40pP6QXGIFDoNchTRLeh4OxF22ouDhwiDyMhymZHOfs6P X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:15.2883 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ffd6f906-7bf8-4f55-4935-08dc3953139e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6359 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Add nexthop group entry stats to count the number of packets forwarded via each nexthop in the group. The stats will be exposed to user space for better data path observability in the next patch. The per-CPU stats pointer is placed at the beginning of 'struct nh_grp_entry', so that all the fields accessed for the data path reside on the same cache line: struct nh_grp_entry { struct nexthop * nh; /* 0 8 */ struct nh_grp_entry_stats * stats; /* 8 8 */ u8 weight; /* 16 1 */ /* XXX 7 bytes hole, try to pack */ union { struct { atomic_t upper_bound; /* 24 4 */ } hthr; /* 24 4 */ struct { struct list_head uw_nh_entry; /* 24 16 */ u16 count_buckets; /* 40 2 */ u16 wants_buckets; /* 42 2 */ } res; /* 24 24 */ }; /* 24 24 */ struct list_head nh_list; /* 48 16 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct nexthop * nh_parent; /* 64 8 */ /* size: 72, cachelines: 2, members: 6 */ /* sum members: 65, holes: 1, sum holes: 7 */ /* last cacheline: 8 bytes */ }; Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: David Ahern --- Notes: v2: - Set err on nexthop_create_group() error path include/net/nexthop.h | 6 ++++++ net/ipv4/nexthop.c | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 77e99cba60ad..4bf1875445d8 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -95,8 +95,14 @@ struct nh_res_table { struct nh_res_bucket nh_buckets[] __counted_by(num_nh_buckets); }; +struct nh_grp_entry_stats { + u64 packets; + struct u64_stats_sync syncp; +}; + struct nh_grp_entry { struct nexthop *nh; + struct nh_grp_entry_stats __percpu *stats; u8 weight; union { diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 816ae8ee3e06..4be66622e24f 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -480,6 +480,7 @@ static void nexthop_free_group(struct nexthop *nh) struct nh_grp_entry *nhge = &nhg->nh_entries[i]; WARN_ON(!list_empty(&nhge->nh_list)); + free_percpu(nhge->stats); nexthop_put(nhge->nh); } @@ -1182,6 +1183,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) if (hash > atomic_read(&nhge->hthr.upper_bound)) continue; + this_cpu_inc(nhge->stats->packets); return nhge->nh; } @@ -1191,7 +1193,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) { - struct nexthop *rc = NULL; + struct nh_grp_entry *nhge0 = NULL; int i; if (nhg->fdb_nh) @@ -1206,16 +1208,20 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) if (!nexthop_is_good_nh(nhge->nh)) continue; - if (!rc) - rc = nhge->nh; + if (!nhge0) + nhge0 = nhge; if (hash > atomic_read(&nhge->hthr.upper_bound)) continue; + this_cpu_inc(nhge->stats->packets); return nhge->nh; } - return rc ? : nhg->nh_entries[0].nh; + if (!nhge0) + nhge0 = &nhg->nh_entries[0]; + this_cpu_inc(nhge0->stats->packets); + return nhge0->nh; } static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash) @@ -1231,6 +1237,7 @@ static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash) bucket = &res_table->nh_buckets[bucket_index]; nh_res_bucket_set_busy(bucket); nhge = rcu_dereference(bucket->nh_entry); + this_cpu_inc(nhge->stats->packets); return nhge->nh; } @@ -1804,6 +1811,7 @@ static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge, newg->has_v4 = true; list_del(&nhges[i].nh_list); + new_nhges[j].stats = nhges[i].stats; new_nhges[j].nh_parent = nhges[i].nh_parent; new_nhges[j].nh = nhges[i].nh; new_nhges[j].weight = nhges[i].weight; @@ -1819,6 +1827,7 @@ static void remove_nh_grp_entry(struct net *net, struct nh_grp_entry *nhge, rcu_assign_pointer(nhp->nh_grp, newg); list_del(&nhge->nh_list); + free_percpu(nhge->stats); nexthop_put(nhge->nh); /* Removal of a NH from a resilient group is notified through @@ -2483,6 +2492,13 @@ static struct nexthop *nexthop_create_group(struct net *net, if (nhi->family == AF_INET) nhg->has_v4 = true; + nhg->nh_entries[i].stats = + netdev_alloc_pcpu_stats(struct nh_grp_entry_stats); + if (!nhg->nh_entries[i].stats) { + err = -ENOMEM; + nexthop_put(nhe); + goto out_no_nh; + } nhg->nh_entries[i].nh = nhe; nhg->nh_entries[i].weight = entry[i].weight + 1; list_add(&nhg->nh_entries[i].nh_list, &nhe->grp_list); @@ -2522,6 +2538,7 @@ static struct nexthop *nexthop_create_group(struct net *net, out_no_nh: for (i--; i >= 0; --i) { list_del(&nhg->nh_entries[i].nh_list); + free_percpu(nhg->nh_entries[i].stats); nexthop_put(nhg->nh_entries[i].nh); } From patchwork Thu Feb 29 18:16:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577535 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12D3578270 for ; Thu, 29 Feb 2024 18:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230829; cv=fail; b=DCFLDzbZ4uzwih6igkP1rKEiT4Xz03zEJH7pXSTZ3AszLI58fePZ7N408EDQS9AzZwg9uKSCbccKJtbio2FavUOM8fwRRr4EIYiglZe0g5thh86wAJ5N/uHwK0HbG2JrsSf4ev6HOfHTdhI5vw59scJbsnAfUFAvbukzy4Rn5pY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230829; c=relaxed/simple; bh=4DAxoF8ABk9xzPv7cODQo3rqilaw/7vkjaRAlRpRTGw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UPoRW6TBMZfvw1gK/K7Jae4bseqafS2Rj+YUsaeyyCtZZ5jqdmTjWq6Fmc4eQjA5LAylqUK0R2nSgaZBB/fq1INV+hFgRPum+F+D6wQdVmCyLMSyioiRu7iKE85eX+G8M3kJAkqZEIbtyPrxzAf3Opio2/+mxxGyDb3MeoaVh/g= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=aG1O2e+j; arc=fail smtp.client-ip=40.107.92.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="aG1O2e+j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NgdgYEkCrSLe64/EtNYWNvSr6y6YRE6lrg+/HDdtRP8F2W1m/sNZ6ZgH+ziQNjUXRbKPG4GTWZnakvh+Ia34kBiatJz6ZmWOG4FC/fkLOkbGAiJ14yemxfzccggAeUaRkRnOmn8gAVXE5jY9hAWUgm2CP1LtNFX7NYeNbdjF9scuB7aBnHf0y+IFfMaz1cyfCRwwF0qyWsrwawvt6kj/7AcrS+PK6tyS/gQSDClvjNKbZ1J5JbRqH5UiSk/BmjmPpj9+dOc3O/hkkZRsNIEq4RmiiSHFX6gpO3aTt8CwQXMsCdZQ1Q/2pBgwHuiG3qjalCuYsek74W4dFWNUMphCEA== 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=d+TrQKGJqcEn3M9zo24X7IfHkt6aMgOZZeWjS79qX7U=; b=KSTarh6dtqUip/mqChO2ZicjwT9KRlXHO0VO+e1vklsOFjCe8oERGF7ZEMiUuIA2eNGUBViYbQaMILtmHw1yaPsDCaxihC49ebE5bfFFcsqE+fBPxUhZrNGXutLko9vMx+gIl6GZr2Gr2cdaJACIL20gLkTPz5qP6T3FAFrWudUGGkn+UAQCWr9ijDX42F43inj5It5lpkkm1HiNv02djKh9ulwzWF5P+Fa0/C5HSgnvYfrzj5C6F+qCozKdAGsiheowqc+kG1QcPXFzrBjQyTCPtZTaLEjstFTEuVhFARfLI+c9oo0pe30FDzrqLdCtg3kwaipZAS7tIUKRPlM1Bw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=d+TrQKGJqcEn3M9zo24X7IfHkt6aMgOZZeWjS79qX7U=; b=aG1O2e+jSvJB4IkY8JH8ox1qEuZZdYYNEvwZQnLOMXFdkg0oM4a6odsKJsDxvbVHhEK3/JpfgZCAc9Q3tOJtsdIXVqF0JyclhHRQ3z097oULyJp9+Cvx5FEzQRJX+ZgrcLGZen2OU0wucatnePeoMqMfjbZFTsGes+oyGFQ/pCre/nZnFq19Clg58QA0r7Km+LtHx+rNaexomNff7waHiG9XCdhv9k8FBXSvyGAUYv85QyTlIaG5IUG5bkW6KyMXFotoLEhpHK7RTwsstx8uIEdgkIZAriUlyInuR6d6GMt7Pm7ub7YOr5LGLRXecs+MKcBybUh5qF3hnzyimkXEcQ== Received: from MW4PR03CA0351.namprd03.prod.outlook.com (2603:10b6:303:dc::26) by DM4PR12MB8452.namprd12.prod.outlook.com (2603:10b6:8:184::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Thu, 29 Feb 2024 18:20:22 +0000 Received: from MWH0EPF000971E9.namprd02.prod.outlook.com (2603:10b6:303:dc:cafe::28) by MW4PR03CA0351.outlook.office365.com (2603:10b6:303:dc::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.28 via Frontend Transport; Thu, 29 Feb 2024 18:20:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by MWH0EPF000971E9.mail.protection.outlook.com (10.167.243.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:22 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:20:05 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:20:00 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , Subject: [PATCH net-next v2 4/7] net: nexthop: Expose nexthop group stats to user space Date: Thu, 29 Feb 2024 19:16:37 +0100 Message-ID: <223614cb8fbe91c6050794762becdd9a3c3b689a.1709217658.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E9:EE_|DM4PR12MB8452:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d1b3c89-5b5e-4b08-7f3b-08dc395317c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BFDkAt0XarG7bu/3ukxZC7irZ1h2GCYFsQTAZrMe0wjyxhr1fuBZRnMRbvn8pJN2BlfIazP8qtk3sFPVlKWmjlolfGUea/cfkNIflkuyU6XFvn4Ah0LLusydBjSdBtEN3f0DX+XcCtgQgNZ2sIFqXkLRDjMsQ0T24sA4wU8KMGSeB+z2gt4fMaWWnAps5DKCOBVJt3OARiaeruPXpQsN7m50j/wqUD8iZJlobiXN1tg4zNUSWqQo9dWMchJK9poMF9jU1xqjBXFGKB6ziqmjqGEn/ZyL5FwsLa42vV7GdeSDvcxBretMAYFw3pv44hodEEw4nwiDGyfgR7+7sfOXc7mQAxS6iDLPz5oEDO+0ukgZXAkFWnbUowLG25o/Cnv+q7GLWPUEGw25GCzbs3YqU86LQcrcd736qL/Jf9YcRA6vn8GRcKLBVs8otK64QBEHNrXO5eF5A4PZMbSer4sW7+iPdcEMddramb/zZzXe7npn+Uw/G+Mu6guIIk8xbG7lhT7MTY9e9lwUqyLywRBf6UGeH7AztolLz3ZOanAhVFnL/V5DJCcju9FN3ZosP5Pnw7701bMap/EepPUTmCK+Btl2pZH49MlfKvldh4IE7x8AGf/QiTsOfm8Bsaqwn+f352+46Q5mw97TSMD9sLsaC8gBD6sZz35YaL3QY+Kc+diNk9dyalRNKdNVroENO0jJtgmtHRka5zqFC+WeVpt1dgZQOQn2sNKyIYCMAyoditHTbywslDdrDKJeYi0oIgr0 X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:22.1599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d1b3c89-5b5e-4b08-7f3b-08dc395317c7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8452 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Add netlink support for reading NH group stats. This data is only for statistics of the traffic in the SW datapath. HW nexthop group statistics will be added in the following patches. Emission of the stats is keyed to a new op_stats flag to avoid cluttering the netlink message with stats if the user doesn't need them: NHA_OP_FLAG_DUMP_STATS. Co-developed-by: Petr Machata Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel Reviewed-by: David Ahern --- Notes: v2: - Use uint to encode NHA_GROUP_STATS_ENTRY_PACKETS - Rename jump target in nla_put_nh_group_stats() to avoid having to rename further in the patchset. include/uapi/linux/nexthop.h | 30 ++++++++++++ net/ipv4/nexthop.c | 92 ++++++++++++++++++++++++++++++++---- 2 files changed, 114 insertions(+), 8 deletions(-) diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index 086444e2946c..f4db63c17085 100644 --- a/include/uapi/linux/nexthop.h +++ b/include/uapi/linux/nexthop.h @@ -30,6 +30,8 @@ enum { #define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1) +#define NHA_OP_FLAG_DUMP_STATS BIT(0) + enum { NHA_UNSPEC, NHA_ID, /* u32; id for nexthop. id == 0 means auto-assign */ @@ -63,6 +65,9 @@ enum { /* u32; operation-specific flags */ NHA_OP_FLAGS, + /* nested; nexthop group stats */ + NHA_GROUP_STATS, + __NHA_MAX, }; @@ -104,4 +109,29 @@ enum { #define NHA_RES_BUCKET_MAX (__NHA_RES_BUCKET_MAX - 1) +enum { + NHA_GROUP_STATS_UNSPEC, + + /* nested; nexthop group entry stats */ + NHA_GROUP_STATS_ENTRY, + + __NHA_GROUP_STATS_MAX, +}; + +#define NHA_GROUP_STATS_MAX (__NHA_GROUP_STATS_MAX - 1) + +enum { + NHA_GROUP_STATS_ENTRY_UNSPEC, + + /* u32; nexthop id of the nexthop group entry */ + NHA_GROUP_STATS_ENTRY_ID, + + /* uint; number of packets forwarded via the nexthop group entry */ + NHA_GROUP_STATS_ENTRY_PACKETS, + + __NHA_GROUP_STATS_ENTRY_MAX, +}; + +#define NHA_GROUP_STATS_ENTRY_MAX (__NHA_GROUP_STATS_ENTRY_MAX - 1) + #endif diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 4be66622e24f..0ede8777bd66 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -41,7 +41,8 @@ static const struct nla_policy rtm_nh_policy_new[] = { static const struct nla_policy rtm_nh_policy_get[] = { [NHA_ID] = { .type = NLA_U32 }, - [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0), + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, + NHA_OP_FLAG_DUMP_STATS), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -53,7 +54,8 @@ static const struct nla_policy rtm_nh_policy_dump[] = { [NHA_GROUPS] = { .type = NLA_FLAG }, [NHA_MASTER] = { .type = NLA_U32 }, [NHA_FDB] = { .type = NLA_FLAG }, - [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0), + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, + NHA_OP_FLAG_DUMP_STATS), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -661,8 +663,77 @@ static int nla_put_nh_group_res(struct sk_buff *skb, struct nh_group *nhg) return -EMSGSIZE; } -static int nla_put_nh_group(struct sk_buff *skb, struct nh_group *nhg) +static void nh_grp_entry_stats_read(struct nh_grp_entry *nhge, + struct nh_grp_entry_stats *stats) { + int i; + + memset(stats, 0, sizeof(*stats)); + for_each_possible_cpu(i) { + struct nh_grp_entry_stats *cpu_stats; + unsigned int start; + u64 packets; + + cpu_stats = per_cpu_ptr(nhge->stats, i); + do { + start = u64_stats_fetch_begin(&cpu_stats->syncp); + packets = cpu_stats->packets; + } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); + + stats->packets += packets; + } +} + +static int nla_put_nh_group_stats_entry(struct sk_buff *skb, + struct nh_grp_entry *nhge) +{ + struct nh_grp_entry_stats stats; + struct nlattr *nest; + + nh_grp_entry_stats_read(nhge, &stats); + + nest = nla_nest_start(skb, NHA_GROUP_STATS_ENTRY); + if (!nest) + return -EMSGSIZE; + + if (nla_put_u32(skb, NHA_GROUP_STATS_ENTRY_ID, nhge->nh->id) || + nla_put_uint(skb, NHA_GROUP_STATS_ENTRY_PACKETS, stats.packets)) + goto nla_put_failure; + + nla_nest_end(skb, nest); + return 0; + +nla_put_failure: + nla_nest_cancel(skb, nest); + return -EMSGSIZE; +} + +static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh) +{ + struct nh_group *nhg = rtnl_dereference(nh->nh_grp); + struct nlattr *nest; + int i; + + nest = nla_nest_start(skb, NHA_GROUP_STATS); + if (!nest) + return -EMSGSIZE; + + for (i = 0; i < nhg->num_nh; i++) + if (nla_put_nh_group_stats_entry(skb, &nhg->nh_entries[i])) + goto cancel_out; + + nla_nest_end(skb, nest); + return 0; + +cancel_out: + nla_nest_cancel(skb, nest); + return -EMSGSIZE; +} + +static int nla_put_nh_group(struct sk_buff *skb, struct nexthop *nh, + u32 op_flags) +{ + struct nh_group *nhg = rtnl_dereference(nh->nh_grp); struct nexthop_grp *p; size_t len = nhg->num_nh * sizeof(*p); struct nlattr *nla; @@ -691,6 +762,10 @@ static int nla_put_nh_group(struct sk_buff *skb, struct nh_group *nhg) if (nhg->resilient && nla_put_nh_group_res(skb, nhg)) goto nla_put_failure; + if (op_flags & NHA_OP_FLAG_DUMP_STATS && + nla_put_nh_group_stats(skb, nh)) + goto nla_put_failure; + return 0; nla_put_failure: @@ -698,7 +773,8 @@ static int nla_put_nh_group(struct sk_buff *skb, struct nh_group *nhg) } static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh, - int event, u32 portid, u32 seq, unsigned int nlflags) + int event, u32 portid, u32 seq, unsigned int nlflags, + u32 op_flags) { struct fib6_nh *fib6_nh; struct fib_nh *fib_nh; @@ -725,7 +801,7 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh, if (nhg->fdb_nh && nla_put_flag(skb, NHA_FDB)) goto nla_put_failure; - if (nla_put_nh_group(skb, nhg)) + if (nla_put_nh_group(skb, nh, op_flags)) goto nla_put_failure; goto out; } @@ -856,7 +932,7 @@ static void nexthop_notify(int event, struct nexthop *nh, struct nl_info *info) if (!skb) goto errout; - err = nh_fill_node(skb, nh, event, info->portid, seq, nlflags); + err = nh_fill_node(skb, nh, event, info->portid, seq, nlflags, 0); if (err < 0) { /* -EMSGSIZE implies BUG in nh_nlmsg_size() */ WARN_ON(err == -EMSGSIZE); @@ -3085,7 +3161,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, goto errout_free; err = nh_fill_node(skb, nh, RTM_NEWNEXTHOP, NETLINK_CB(in_skb).portid, - nlh->nlmsg_seq, 0); + nlh->nlmsg_seq, 0, op_flags); if (err < 0) { WARN_ON(err == -EMSGSIZE); goto errout_free; @@ -3255,7 +3331,7 @@ static int rtm_dump_nexthop_cb(struct sk_buff *skb, struct netlink_callback *cb, return nh_fill_node(skb, nh, RTM_NEWNEXTHOP, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, NLM_F_MULTI); + cb->nlh->nlmsg_seq, NLM_F_MULTI, filter->op_flags); } /* rtnl */ From patchwork Thu Feb 29 18:16:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577536 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2063.outbound.protection.outlook.com [40.107.220.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E9567829C for ; Thu, 29 Feb 2024 18:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230835; cv=fail; b=Z2KmhEeaknzrCHpzVbNevlB2lF3fyy+EFmKhm1zNlQp49HCdj/D4zZJTXGiYg9XoQ8g7TNCMA1r/gEoVF5Z1+1MipVKc0ZfGekobN73l09TPALkk0MLNDpRxClvzTOIagjoJwH3IqmuPhds6DfXyX6gvlBOERUhUbIw6ArHdDgA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230835; c=relaxed/simple; bh=oMol7ZPh4TW8ywgq6cE3aO78LQOn6yzeZWVfYU+71pg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VGcZuFOjAku5DJ6qioyD29sug+Cy7Pg4JgD/hWEfO6rEP/9eVDmyv9EaEH//ThBw3fqGj7Q1u9PZnQySdcK9U6B0PSkslxsCeb30Q3puvqRThkDE8eFy98E5qIhjMw6CgsPdKquqKXy+CwPkuTc5I5Kmobf5eZHbbIkmdSSoT0E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=jFyoqesB; arc=fail smtp.client-ip=40.107.220.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="jFyoqesB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SnOxUNOUB/8iytRX3p3TqxxsiF7X9Fbbx3HZtIMLelqBBz1aN5x4aMbWif/qO+xHL6mu7NMcrXCL7ia8QQ9A8l1sY45C9z0u5yU2vUqlEEJ5uzR1u9hjwveCwx1FSquyu/r+6cuAE9Ohu8J+FhXxbAZG3zpCnfYU7MIAMGVh9+f/D9k/p7OMLvcGBSC4N4hCYhmKz7AzLvswMqw5/1QXBC3WFR+Lplbyen2Van6yV9mBEKuTMX3PEQgo8ziNC7mcDKLDJAjmcvq4Rpf/MxB5F9dIObW5cxNvnB0TWiKXCbrstDWpS1o7Ij/wka1zPoxX3J8aVR6mjACDwe5QZpsewA== 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=497krsbvHFHYkp+FPPg+VoxQBPyND7HmcIpbBC3KGAM=; b=LPyGiBUPPplIz6UWrjt+OOhVwAI9ZliLXMhjOfyNcaUmZ/UyJ1jn/1UyY5DH6vjoX5XOYzqR3VcDfeKpBf9p0/SXEXjz1sR+NVN30d37oQXn4BI4QuRidT4gVL3UtWbNI9Jem0LC+5NCnwM9Z0x+q6OWTp2afYEQGPJUXQUjzCul62rrz8sEiXQejpbhwMzltE/3KgJo0pbytQV6tJgbCxIyaBoe7RBSlus8a9cQDzCc08ZP34Q/zyZREnopUl4+1a71luU8sqh95ai0fkkv2McRqRv6hd9FdQELsjfbybOAMAhw56CISBPRL6vdHk0c/zh88i8KqDbOryt7vE4RzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=497krsbvHFHYkp+FPPg+VoxQBPyND7HmcIpbBC3KGAM=; b=jFyoqesBcf7nM1nq3tAe4KVvy262zMaAVZxSER8jDcbHPw+1UiTNHx5M/9rQ8/EQafU/fh6YkXdYaEgwIlyDAzkMuLb9J/EifU0iWnoQptIhT0DPc1m6kQEkh9kAYIGNbfvKdUlelhVkStBwezEvPf6ZMg8w+0mXuzOQ52DMikC/UauwDNqeP46DnzJ+ZLVa3AFyemCMYtofrPzVajUvzH9eepYEN+gKHFA6vAx22/AR8fWrnve59jMpHdmBhXlhDAaqkQO7nJk48zS3SsSkAnDDkwgBoHEquesDIu0HpLVpc1sKuGvoXPgxhRcSJSNQWYgjp+dPPd7Ej3AcY7IRuA== Received: from BN9PR03CA0532.namprd03.prod.outlook.com (2603:10b6:408:131::27) by MN2PR12MB4110.namprd12.prod.outlook.com (2603:10b6:208:1dd::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Thu, 29 Feb 2024 18:20:31 +0000 Received: from BN1PEPF0000468C.namprd05.prod.outlook.com (2603:10b6:408:131:cafe::a4) by BN9PR03CA0532.outlook.office365.com (2603:10b6:408:131::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.30 via Frontend Transport; Thu, 29 Feb 2024 18:20:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF0000468C.mail.protection.outlook.com (10.167.243.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:30 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:20:12 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:20:04 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , Subject: [PATCH net-next v2 5/7] net: nexthop: Add hardware statistics notifications Date: Thu, 29 Feb 2024 19:16:38 +0100 Message-ID: <91689768570fd58a973e1be388d2ebdc62438d29.1709217658.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF0000468C:EE_|MN2PR12MB4110:EE_ X-MS-Office365-Filtering-Correlation-Id: d130a44d-8aaa-49d4-5137-08dc39531c99 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6yMQvkrg7ZaV9AkYHndkKa6bgAC/EQVNbg1yB3BB74fDzCQUfopu+JvHCD4hEL2HfHpMDRYQOCNQ4s5vGyE7ueDkAwxAGVAgvqpJbKaU8TBBRDuF60MhvT3z5zpUrZ8rcfqLFNyubDKt9Ym3k39F2J1Of2KJh9MvoyjUkQd4RGePXpFGxwpNRcif/ZF4fjxW2P0I4h9gOJmdYL+aVdFAnDA1lzyN+Ks2I0s/g62iCMi7Hw9WRTxJkBucyVsC07YjLintaWyHwUuia8ZKMbfIrlUGx4Hw3yDoNQsfxpJiiBBQ5IkYuj2tUzkFZgHYT5M6Cb4HkDXAPNrbTCTLvxENs43kCgSZKuSOtorswebVfhC3rwTBYPH83jGS//nIZXAZHOHplPjyujLeROAK2dsFjdoAI31XxDcSBiqCYrMmvMsvGHZY2PqJb3wfyWbqckhmbR5Whz31yomYVsUjKGwjzYSmi6tGxqE8BuC1nkVxEDL7h9Evt+xpZbYK4BgF06SqSoaobn8jvJGFKZ49l3k5isVNfeETpv1ZEwGVOmx8lAAFqb1oBeOO6YVIsejJ/oqcjh4IdyhEdB3bEjVYOn2MiP7v3rCq5qw0UP9Y2sZh/Cab3ib9oWfQgDtlzwKiCENUKXl87UqYCIzsILg2PQ6Aba0bwGIpII2kHcC8fmPwy2edX/Fclp8n10trI5/43WT+SUGj4znIjRqUHHdPmfL+qJP4y1pmHxccaNhhdzoAGx94fJz/hp8dlwfr4PYPeBx/ X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:30.2458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d130a44d-8aaa-49d4-5137-08dc39531c99 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF0000468C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4110 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Add hw_stats field to several notifier structures to communicate to the drivers that HW statistics should be configured for nexthops within a given group. Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: David Ahern --- include/net/nexthop.h | 3 +++ net/ipv4/nexthop.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 4bf1875445d8..a8dad8f48ca8 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -130,6 +130,7 @@ struct nh_group { bool resilient; bool fdb_nh; bool has_v4; + bool hw_stats; struct nh_res_table __rcu *res_table; struct nh_grp_entry nh_entries[] __counted_by(num_nh); @@ -193,6 +194,7 @@ struct nh_notifier_grp_entry_info { struct nh_notifier_grp_info { u16 num_nh; bool is_fdb; + bool hw_stats; struct nh_notifier_grp_entry_info nh_entries[] __counted_by(num_nh); }; @@ -206,6 +208,7 @@ struct nh_notifier_res_bucket_info { struct nh_notifier_res_table_info { u16 num_nh_buckets; + bool hw_stats; struct nh_notifier_single_info nhs[] __counted_by(num_nh_buckets); }; diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 0ede8777bd66..02629ba7a75d 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -139,6 +139,7 @@ static int nh_notifier_mpath_info_init(struct nh_notifier_info *info, info->nh_grp->num_nh = num_nh; info->nh_grp->is_fdb = nhg->fdb_nh; + info->nh_grp->hw_stats = nhg->hw_stats; for (i = 0; i < num_nh; i++) { struct nh_grp_entry *nhge = &nhg->nh_entries[i]; @@ -170,6 +171,7 @@ static int nh_notifier_res_table_info_init(struct nh_notifier_info *info, return -ENOMEM; info->nh_res_table->num_nh_buckets = num_nh_buckets; + info->nh_res_table->hw_stats = nhg->hw_stats; for (i = 0; i < num_nh_buckets; i++) { struct nh_res_bucket *bucket = &res_table->nh_buckets[i]; From patchwork Thu Feb 29 18:16:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577537 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4BD778286 for ; Thu, 29 Feb 2024 18:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230839; cv=fail; b=pmY6L27xqVggzO4itnbQ4qlhmmX7/btIn2ix90/U09UDXntSg4VhwmGRJCeSwWcg/sS8dJ4hVQBW83JuxPLsgGzCYDPF6WpU9FZQvll9OSOUmn0edYR8iWPfeA6kaSCiL8hjfAOs8XAwdUVPhuoSEonWLt1pjXWBXuGLe2blMRo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230839; c=relaxed/simple; bh=35mYSa4ZgiJSFdzmXb8QxoKLYdSwhtP5NQB/bk7a5m4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YM/MmM+EZSLr/gNfVLd6lA8fedecICinH34RO3Qg3SYXkHs4VQdl7VtRTMBgiWeEdKoBuRrwm4O4ljPGDP4dowBW3XBzCA6T9jYu0sIaHXqnu4qTrEaY2L8hbDd5wQjh2gB8vHV6oO8pj6/OyDZllltA+htsYcrLLtqQNrnqdgE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=OH5PUDsy; arc=fail smtp.client-ip=40.107.236.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="OH5PUDsy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BX6m4dFTxCIKUf61PHFknT7sw/JOL1bLyXanKL6X23MpX7BJrrH4/iAPyAzcGTDHibUK5NdN+gRJYXlXjqkox9f760ueI0HarsXzd0D/dlcIUQequN34XrxR+lJly43M4t08zMpVZJ2yxFCq/yOzMkkmse9+GNtJk6Ydw5QrTPJVH1OUS6bbc9Rpn+QCQcwcQtfeG+4kSmETnBHxPjBja9Oo4iXoTKGeFVrZLMt86rfkuj1vOC6o2QXXv9YLYUdFmlClKNgaJ2SyApDseoOZwRC96nsvf6f2OCX3SFZbfwSVtYg+BFdXEnQ6MyEgtXfa2rhCcFl/JNo4U8jnCLzI/g== 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=c6ZIWhxWNq5KxVsPVGsgGs9xVWmMe+DbSa9pUn/HCMw=; b=l7c9J15j2F6vWtgRWv8AOQwcdNphZO/GI1O75OrRy0/Yehh461OMXnzo1Y7CDbrFoPONdmfLE3vPrF18a8dtGIlGbqRVCIj6bF2os/Vg5OTkmkn6MGXjTFa8HLKibwH1zhMxKq3sYsJl3FVaaqOzGGE58Zo1mS4iiL2M6OYWXyDC6waiZztn9Zpdu1uAcKBy3sOVoURQJDjzJ7MBnBOSk4K6X7xx040KuSgJ8eNNNgaZdw9XS2wTmLR+bbogMDziOYFdSpaDNgA1tVtRNiyFNS2qzWkFioUEGVGf0/5zcCJ/k20AI6+Sq6NLunRnnmTW0FED1LpWUx7v13VgZfoIEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=c6ZIWhxWNq5KxVsPVGsgGs9xVWmMe+DbSa9pUn/HCMw=; b=OH5PUDsy1lzl483hoAYZboYFNTEfOCDC03iwVCzO+Zgbtz9B2VEx/Fek4f7DGYmdA/S+uAuOG0pj6s1AMrVdAvbbdIkO3UrrHQ5KpuAIo+mGBT6EjWdfC7RyP0/lq4v1JNKDH2Aij3hxnQM4TFSMiRTor8sSwLdXAafSs5eTyVAroed+xkOkmIymMrOBLJ1ec2QEEcfoQPTsdY+SZpm1avhKXqSqwk9+pED/OE50v5//2bph6bcd74XoOkzfW2PjFTbHiZpvMtxk4TYMq7dmZCYvK2bXnjpVd/oUsW/r8bp58TqAX041I6Z1/gHll1YySCE2TnNhcqmbUBqG2B6Hpg== Received: from MW4PR03CA0343.namprd03.prod.outlook.com (2603:10b6:303:dc::18) by PH7PR12MB9173.namprd12.prod.outlook.com (2603:10b6:510:2ee::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Thu, 29 Feb 2024 18:20:35 +0000 Received: from MWH0EPF000971E9.namprd02.prod.outlook.com (2603:10b6:303:dc:cafe::fa) by MW4PR03CA0343.outlook.office365.com (2603:10b6:303:dc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.32 via Frontend Transport; Thu, 29 Feb 2024 18:20:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by MWH0EPF000971E9.mail.protection.outlook.com (10.167.243.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:34 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:20:15 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:20:09 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , Subject: [PATCH net-next v2 6/7] net: nexthop: Add ability to enable / disable hardware statistics Date: Thu, 29 Feb 2024 19:16:39 +0100 Message-ID: <5766037d73a81ddc72106cde93943bbca9289ae2.1709217658.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E9:EE_|PH7PR12MB9173:EE_ X-MS-Office365-Filtering-Correlation-Id: ea054b38-2ee2-41fe-ee8a-08dc39531f4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 51aoOu0nN6YRtlrMaEcEfeNkiFM1zncjNHnVwFYnb/MamPy0SAeYV3ZvQr6LOjLWYNdEDEIA59rnG9pg7bLItFHUgNE3DW8IhO49M4Qync/4b2y/3ef97NvhZnUTOHIw+SnhnHimT+rvD4jNE3P1wsfGFFLEjHyauzJOzSBO4Yf6gpyW+rZEVBy5jh+oDe/b9kdh7gktTD3HGGPKWWlyIPxkggv2r9ZmkDbxEf9QSKEs5d4nCIttOoi1/8cad7fLbzj1cqVJT+eGtRkDIKoJ+mFmRIGS5UyyZqfkv0AiVuwgNNh5YbDEe21+T8LE1dQ1hTBuNiDVUNYYBgoPPBexRRA8TZxamG25dfq5MKMl1FPa0VPhwbnAzj3N3rXgGirg+4HV8MTTA6LSZSWMC6H/dN/6QjFz5U49+lAptbPn4MQQMkBFIGR/n02GBbqUb+VWUtu/+kPLcS1UAd+tOaljFNQAmfvABr8hiyrPLtqk4fizwau/J4PiIkR5jrdpNGYAMNoEMx+LpT30/5EHU734QCWpP4+OJ65AjEe4FhIDBdqWIu+R5ihT6yw0LurZU/Sbtz1KexyBCe5Fx8Go/EghKetqMzO/ePRypAnqcF8/NUbT5mO9BOHsbHwxa8xp9//7Ew8mX+T7CMrtPq+L8Oi4h4wTRAAMiC8C0t3KJoMfidrZbzHhCXqpQMPvVsOc9il5j03L+okB/CgspmpOhC/5ewsNnGAsumxjo4MpPWIuJxmvq/fA2jlHjnfLboxVn+AO X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:34.9100 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea054b38-2ee2-41fe-ee8a-08dc39531f4d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000971E9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9173 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Add netlink support for enabling collection of HW statistics on nexthop groups. Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: David Ahern --- include/net/nexthop.h | 2 ++ include/uapi/linux/nexthop.h | 3 +++ net/ipv4/nexthop.c | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index a8dad8f48ca8..20cd337b4a9c 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -47,6 +47,8 @@ struct nh_config { bool nh_grp_res_has_idle_timer; bool nh_grp_res_has_unbalanced_timer; + bool nh_hw_stats; + struct nlattr *nh_encap; u16 nh_encap_type; diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index f4db63c17085..b86af80d4e09 100644 --- a/include/uapi/linux/nexthop.h +++ b/include/uapi/linux/nexthop.h @@ -68,6 +68,9 @@ enum { /* nested; nexthop group stats */ NHA_GROUP_STATS, + /* u32; nexthop hardware stats enable */ + NHA_HW_STATS_ENABLE, + __NHA_MAX, }; diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 02629ba7a75d..15f108c440ae 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -37,6 +37,7 @@ static const struct nla_policy rtm_nh_policy_new[] = { [NHA_ENCAP] = { .type = NLA_NESTED }, [NHA_FDB] = { .type = NLA_FLAG }, [NHA_RES_GROUP] = { .type = NLA_NESTED }, + [NHA_HW_STATS_ENABLE] = NLA_POLICY_MAX(NLA_U32, 1), }; static const struct nla_policy rtm_nh_policy_get[] = { @@ -765,7 +766,8 @@ static int nla_put_nh_group(struct sk_buff *skb, struct nexthop *nh, goto nla_put_failure; if (op_flags & NHA_OP_FLAG_DUMP_STATS && - nla_put_nh_group_stats(skb, nh)) + (nla_put_u32(skb, NHA_HW_STATS_ENABLE, nhg->hw_stats) || + nla_put_nh_group_stats(skb, nh))) goto nla_put_failure; return 0; @@ -1189,6 +1191,7 @@ static int nh_check_attr_group(struct net *net, if (!tb[i]) continue; switch (i) { + case NHA_HW_STATS_ENABLE: case NHA_FDB: continue; case NHA_RES_GROUP: @@ -2609,6 +2612,9 @@ static struct nexthop *nexthop_create_group(struct net *net, if (cfg->nh_fdb) nhg->fdb_nh = 1; + if (cfg->nh_hw_stats) + nhg->hw_stats = true; + rcu_assign_pointer(nh->nh_grp, nhg); return nh; @@ -2951,6 +2957,9 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, err = rtm_to_nh_config_grp_res(tb[NHA_RES_GROUP], cfg, extack); + if (tb[NHA_HW_STATS_ENABLE]) + cfg->nh_hw_stats = nla_get_u32(tb[NHA_HW_STATS_ENABLE]); + /* no other attributes should be set */ goto out; } @@ -3042,6 +3051,10 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, goto out; } + if (tb[NHA_HW_STATS_ENABLE]) { + NL_SET_ERR_MSG(extack, "Cannot enable nexthop hardware statistics for non-group nexthops"); + goto out; + } err = 0; out: From patchwork Thu Feb 29 18:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13577538 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2048.outbound.protection.outlook.com [40.107.244.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AC197D3E0 for ; Thu, 29 Feb 2024 18:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230841; cv=fail; b=l63g/a9WCdWuODMXSaDqwQCKmw6zWgvnRqe6haU6gXixptDli7uT44yrn4r2iI6lKJixLnvJ0zyqo5qNDFNCJ54fOog9DBCOogS5+Eh5mulNekn7V3XaXZjb39ZsTL6ztavcencO8hVVcfyrIOW3IMGrc9dojAz6GtkiJofwg1Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709230841; c=relaxed/simple; bh=yQD2PevC7A8paCooMwERTtTJV2QPdJjWjCcLOEV4DJc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XvkNqkviRUDUoBDp45zHcLRBeipQao/lhsHRz1TU+ITqFNsLrpieltmfICD8adHJ/v6/zZx3gKCIh+sMTkk8/hg6A/nqAOhF0GsRen+0GGt5dXdUQZB6pppJ5GtAsCeNJ4U99JJV+OiFRqX0fkGbSJk1xZ9JM3gepCCm2tqNX8o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=QI0kwNJb; arc=fail smtp.client-ip=40.107.244.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="QI0kwNJb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n8MS1M47FrMPG6uKZUQHscIbsJLt2qp2yK9bIcacTqkZwMshp7pLKJ330V8s3slD5RG7pmL3XqnmcvuHiGX9urfdqAIMb82L+cb1IrFfE/TA1ziEel8E4qXVWPPDV5E4EwefkuHSHVCkIZUgshUF5Vp/7yJgJHD4zYO0zJ0y/gDNXLpqVRz4hq+rkOaL0dH+vS2QGm+ki1msh/BUz42f7lcMNv/H09vXg5eJZR0it2y7G+kA9EvLg/T0YP+R5HRIfubs7+FA4b85CEN6JjHQ9a9STRDtgBVNogAdvCNCiDSkhaMqrSXpSBiZaOkeFx0QhmufuUjVa0ysorRVz4iMVA== 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=4ny4BpFqM1tMjHk7PGgamoDwn+QhuyGxG2y0NMqm98U=; b=Z+KO3WE5q+5U1YcGOblbEF7epsrZN3mScPlOaXV4oQpz0az8Nc6yE5jNEKqkwf+NBKt+2rv7k0HsgFezLjB9gpL/pu7W1bnBify3c0YNKyIFGEaUOrI9u+hM0W67b4yqr0cjZhrcyBQGeaKKFfHK9Wak7phtjfhNf3Ii2O2lNiLHjgA6en+VBrfMTX9fkWlNIgwIb4OKjkFQgC0kbssm39rY8dK+W8p6Zi7k2oaUqw730801aOciYJVpgYb9w4WInukFmoKUsT1Fb0tneMf9hHTUIaRpWMr1zOuoJS83yKeUu0rKtc7Zn0bsHY2N5Y7x7Rik8khSbBB0P0ttkvQ8GQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=4ny4BpFqM1tMjHk7PGgamoDwn+QhuyGxG2y0NMqm98U=; b=QI0kwNJbVaVpziD9fBKyoaON9cZRfj+yj8nOwJXcjcFxav7FsX3xtpe9Txvd5b2ak0f70wqLUiCOr9o8lmfHfMpR7SAOeKVbmWgyde3upbkgjbmYcbXjq4M34AbSRXHcByZ/P0Bdf5yhHyBhpQGba7CdHrqMJMFs8+hMt3HBochipN3rSOzYSrofgdJWqvvmTCknpbWSdjWAaitugSrfE0JI0anYDQSEdDT4dqxsh8J9GDe8UAsDuWGVhCtD9MyVvmnU/pFI4Njwu29sT+vNdNv9/eQ/j20tgMeRbeUEiSy0bzWDiBOify5dLSLbzptdQZf9hNZ7TSOF2TBRRirnIA== Received: from BN0PR04CA0079.namprd04.prod.outlook.com (2603:10b6:408:ea::24) by DM4PR12MB6374.namprd12.prod.outlook.com (2603:10b6:8:a3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Thu, 29 Feb 2024 18:20:37 +0000 Received: from BN1PEPF00004689.namprd05.prod.outlook.com (2603:10b6:408:ea:cafe::bf) by BN0PR04CA0079.outlook.office365.com (2603:10b6:408:ea::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.31 via Frontend Transport; Thu, 29 Feb 2024 18:20:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN1PEPF00004689.mail.protection.outlook.com (10.167.243.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Thu, 29 Feb 2024 18:20:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Thu, 29 Feb 2024 10:20:19 -0800 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Thu, 29 Feb 2024 10:20:13 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Simon Horman , , Kees Cook Subject: [PATCH net-next v2 7/7] net: nexthop: Expose nexthop group HW stats to user space Date: Thu, 29 Feb 2024 19:16:40 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00004689:EE_|DM4PR12MB6374:EE_ X-MS-Office365-Filtering-Correlation-Id: a853b468-f7bd-4083-ae4c-08dc3953207c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BxRo0W0eCu9wZmvY/Fqx7IMHuEILOH7Khh7ilJzZlF1U3m6af0b9luEPYM9Sju7/S1Z7RZaRx4XDMhpUuTEi03N6fta2khnFMLgJbQ8vAGZiRY1kDnIxzWVcKn/gkYr8xICBrn1pneu3KcQfmoIywxqJy+g1roRHokBgQT5xhnktJ0EeUuz3t6dKJRRSU6Ux8fQY9q33OODPY/X3x7Pql5YcltNGKd/GSNiIpopCaeVF0/7aU9vdtACLuCcQ3wHa3xZPtQdA3aFlTSLEkl0Hlh02eWTW3IaNYjk5MjKrP5I6a2u8xCtZxEy8AdNt290CQZXJU0VQMcw9HJfD1T9kXPrPxnKybdWjwZh2WiiJ4BmMPOHx/BCtZN6nW+QP/3gHzgCe7i84ZVyy0902Ctwe6mSt2ANEPItqqLqVL54svY6EZTtGPOR5bZCezrK9kCs8Ah068MHTMQ85YqnnSUhOipGtE3xWFVnT+X76N7q3op1l71y5TKtpdYRFsLFCvigvsXD++Mn+DRtm78731iDU7dF15i8BXWIsMKMEPwfvtAu5nZKI3kSCNm1J6Ten6DSd15L0MLTqlBC9k2/QGcdYzYtsuSuJqxrDN9e4wq0Xda2Qau5AITfc2PrtgdcsL+t8MUeOnwgmUA30q/VsK/4n4UmJNKqM7maoTfvxYWuFM04iraryXIeOwClCc49mK3az5m6XL6Pt6TQ7Jd31X2DejmQ/wMQYkz9fpG8c0ny52KnvgTmYHr4xjIn1XWntfVf8 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 18:20:36.7066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a853b468-f7bd-4083-ae4c-08dc3953207c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00004689.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6374 X-Patchwork-Delegate: kuba@kernel.org From: Ido Schimmel Add netlink support for reading NH group hardware stats. Stats collection is done through a new notifier, NEXTHOP_EVENT_HW_STATS_REPORT_DELTA. Drivers that implement HW counters for a given NH group are thereby asked to collect the stats and report back to core by calling nh_grp_hw_stats_report_delta(). This is similar to what netdevice L3 stats do. Besides exposing number of packets that passed in the HW datapath, also include information on whether any driver actually realizes the counters. The core can tell based on whether it got any _report_delta() reports from the drivers. This allows enabling the statistics at the group at any time, with drivers opting into supporting them. This is also in line with what netdevice L3 stats are doing. So as not to waste time and space, tie the collection and reporting of HW stats with a new op flag, NHA_OP_FLAG_DUMP_HW_STATS. Co-developed-by: Petr Machata Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel Reviewed-by: Kees Cook # For the __counted_by bits Reviewed-by: David Ahern --- Notes: v2: - Use uint to encode NHA_GROUP_STATS_ENTRY_PACKETS_HW - Do not cancel outside of nesting in nla_put_nh_group_stats() include/net/nexthop.h | 18 +++++ include/uapi/linux/nexthop.h | 9 +++ net/ipv4/nexthop.c | 133 ++++++++++++++++++++++++++++++++--- 3 files changed, 151 insertions(+), 9 deletions(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 20cd337b4a9c..235f94ab16a8 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -122,6 +122,7 @@ struct nh_grp_entry { struct list_head nh_list; struct nexthop *nh_parent; /* nexthop of group with this entry */ + u64 packets_hw; }; struct nh_group { @@ -166,6 +167,7 @@ enum nexthop_event_type { NEXTHOP_EVENT_REPLACE, NEXTHOP_EVENT_RES_TABLE_PRE_REPLACE, NEXTHOP_EVENT_BUCKET_REPLACE, + NEXTHOP_EVENT_HW_STATS_REPORT_DELTA, }; enum nh_notifier_info_type { @@ -173,6 +175,7 @@ enum nh_notifier_info_type { NH_NOTIFIER_INFO_TYPE_GRP, NH_NOTIFIER_INFO_TYPE_RES_TABLE, NH_NOTIFIER_INFO_TYPE_RES_BUCKET, + NH_NOTIFIER_INFO_TYPE_GRP_HW_STATS, }; struct nh_notifier_single_info { @@ -214,6 +217,17 @@ struct nh_notifier_res_table_info { struct nh_notifier_single_info nhs[] __counted_by(num_nh_buckets); }; +struct nh_notifier_grp_hw_stats_entry_info { + u32 id; + u64 packets; +}; + +struct nh_notifier_grp_hw_stats_info { + u16 num_nh; + bool hw_stats_used; + struct nh_notifier_grp_hw_stats_entry_info stats[] __counted_by(num_nh); +}; + struct nh_notifier_info { struct net *net; struct netlink_ext_ack *extack; @@ -224,6 +238,7 @@ struct nh_notifier_info { struct nh_notifier_grp_info *nh_grp; struct nh_notifier_res_table_info *nh_res_table; struct nh_notifier_res_bucket_info *nh_res_bucket; + struct nh_notifier_grp_hw_stats_info *nh_grp_hw_stats; }; }; @@ -236,6 +251,9 @@ void nexthop_bucket_set_hw_flags(struct net *net, u32 id, u16 bucket_index, bool offload, bool trap); void nexthop_res_grp_activity_update(struct net *net, u32 id, u16 num_buckets, unsigned long *activity); +void nh_grp_hw_stats_report_delta(struct nh_notifier_grp_hw_stats_info *info, + unsigned int nh_idx, + u64 delta_packets); /* caller is holding rcu or rtnl; no reference taken to nexthop */ struct nexthop *nexthop_find_by_id(struct net *net, u32 id); diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index b86af80d4e09..dd8787f9cf39 100644 --- a/include/uapi/linux/nexthop.h +++ b/include/uapi/linux/nexthop.h @@ -31,6 +31,7 @@ enum { #define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1) #define NHA_OP_FLAG_DUMP_STATS BIT(0) +#define NHA_OP_FLAG_DUMP_HW_STATS BIT(1) enum { NHA_UNSPEC, @@ -71,6 +72,9 @@ enum { /* u32; nexthop hardware stats enable */ NHA_HW_STATS_ENABLE, + /* u32; read-only; whether any driver collects HW stats */ + NHA_HW_STATS_USED, + __NHA_MAX, }; @@ -132,6 +136,11 @@ enum { /* uint; number of packets forwarded via the nexthop group entry */ NHA_GROUP_STATS_ENTRY_PACKETS, + /* uint; number of packets forwarded via the nexthop group entry in + * hardware + */ + NHA_GROUP_STATS_ENTRY_PACKETS_HW, + __NHA_GROUP_STATS_ENTRY_MAX, }; diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 15f108c440ae..169a003cc855 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -43,7 +43,8 @@ static const struct nla_policy rtm_nh_policy_new[] = { static const struct nla_policy rtm_nh_policy_get[] = { [NHA_ID] = { .type = NLA_U32 }, [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, - NHA_OP_FLAG_DUMP_STATS), + NHA_OP_FLAG_DUMP_STATS | + NHA_OP_FLAG_DUMP_HW_STATS), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -56,7 +57,8 @@ static const struct nla_policy rtm_nh_policy_dump[] = { [NHA_MASTER] = { .type = NLA_U32 }, [NHA_FDB] = { .type = NLA_FLAG }, [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, - NHA_OP_FLAG_DUMP_STATS), + NHA_OP_FLAG_DUMP_STATS | + NHA_OP_FLAG_DUMP_HW_STATS), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -687,8 +689,95 @@ static void nh_grp_entry_stats_read(struct nh_grp_entry *nhge, } } +static int nh_notifier_grp_hw_stats_init(struct nh_notifier_info *info, + const struct nexthop *nh) +{ + struct nh_group *nhg; + int i; + + ASSERT_RTNL(); + nhg = rtnl_dereference(nh->nh_grp); + + info->id = nh->id; + info->type = NH_NOTIFIER_INFO_TYPE_GRP_HW_STATS; + info->nh_grp_hw_stats = kzalloc(struct_size(info->nh_grp_hw_stats, + stats, nhg->num_nh), + GFP_KERNEL); + if (!info->nh_grp_hw_stats) + return -ENOMEM; + + info->nh_grp_hw_stats->num_nh = nhg->num_nh; + for (i = 0; i < nhg->num_nh; i++) { + struct nh_grp_entry *nhge = &nhg->nh_entries[i]; + + info->nh_grp_hw_stats->stats[i].id = nhge->nh->id; + } + + return 0; +} + +static void nh_notifier_grp_hw_stats_fini(struct nh_notifier_info *info) +{ + kfree(info->nh_grp_hw_stats); +} + +void nh_grp_hw_stats_report_delta(struct nh_notifier_grp_hw_stats_info *info, + unsigned int nh_idx, + u64 delta_packets) +{ + info->hw_stats_used = true; + info->stats[nh_idx].packets += delta_packets; +} +EXPORT_SYMBOL(nh_grp_hw_stats_report_delta); + +static void nh_grp_hw_stats_apply_update(struct nexthop *nh, + struct nh_notifier_info *info) +{ + struct nh_group *nhg; + int i; + + ASSERT_RTNL(); + nhg = rtnl_dereference(nh->nh_grp); + + for (i = 0; i < nhg->num_nh; i++) { + struct nh_grp_entry *nhge = &nhg->nh_entries[i]; + + nhge->packets_hw += info->nh_grp_hw_stats->stats[i].packets; + } +} + +static int nh_grp_hw_stats_update(struct nexthop *nh, bool *hw_stats_used) +{ + struct nh_notifier_info info = { + .net = nh->net, + }; + struct net *net = nh->net; + int err; + + if (nexthop_notifiers_is_empty(net)) + return 0; + + err = nh_notifier_grp_hw_stats_init(&info, nh); + if (err) + return err; + + err = blocking_notifier_call_chain(&net->nexthop.notifier_chain, + NEXTHOP_EVENT_HW_STATS_REPORT_DELTA, + &info); + + /* Cache whatever we got, even if there was an error, otherwise the + * successful stats retrievals would get lost. + */ + nh_grp_hw_stats_apply_update(nh, &info); + *hw_stats_used = info.nh_grp_hw_stats->hw_stats_used; + + nh_notifier_grp_hw_stats_fini(&info); + return notifier_to_errno(err); +} + static int nla_put_nh_group_stats_entry(struct sk_buff *skb, - struct nh_grp_entry *nhge) + struct nh_grp_entry *nhge, + u32 op_flags) { struct nh_grp_entry_stats stats; struct nlattr *nest; @@ -700,7 +789,13 @@ static int nla_put_nh_group_stats_entry(struct sk_buff *skb, return -EMSGSIZE; if (nla_put_u32(skb, NHA_GROUP_STATS_ENTRY_ID, nhge->nh->id) || - nla_put_uint(skb, NHA_GROUP_STATS_ENTRY_PACKETS, stats.packets)) + nla_put_uint(skb, NHA_GROUP_STATS_ENTRY_PACKETS, + stats.packets + nhge->packets_hw)) + goto nla_put_failure; + + if (op_flags & NHA_OP_FLAG_DUMP_HW_STATS && + nla_put_uint(skb, NHA_GROUP_STATS_ENTRY_PACKETS_HW, + nhge->packets_hw)) goto nla_put_failure; nla_nest_end(skb, nest); @@ -711,18 +806,35 @@ static int nla_put_nh_group_stats_entry(struct sk_buff *skb, return -EMSGSIZE; } -static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh) +static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh, + u32 op_flags) { struct nh_group *nhg = rtnl_dereference(nh->nh_grp); struct nlattr *nest; + bool hw_stats_used; + int err; int i; + if (nla_put_u32(skb, NHA_HW_STATS_ENABLE, nhg->hw_stats)) + goto err_out; + + if (op_flags & NHA_OP_FLAG_DUMP_HW_STATS && + nhg->hw_stats) { + err = nh_grp_hw_stats_update(nh, &hw_stats_used); + if (err) + goto out; + + if (nla_put_u32(skb, NHA_HW_STATS_USED, hw_stats_used)) + goto err_out; + } + nest = nla_nest_start(skb, NHA_GROUP_STATS); if (!nest) - return -EMSGSIZE; + goto err_out; for (i = 0; i < nhg->num_nh; i++) - if (nla_put_nh_group_stats_entry(skb, &nhg->nh_entries[i])) + if (nla_put_nh_group_stats_entry(skb, &nhg->nh_entries[i], + op_flags)) goto cancel_out; nla_nest_end(skb, nest); @@ -730,7 +842,10 @@ static int nla_put_nh_group_stats(struct sk_buff *skb, struct nexthop *nh) cancel_out: nla_nest_cancel(skb, nest); - return -EMSGSIZE; +err_out: + err = -EMSGSIZE; +out: + return err; } static int nla_put_nh_group(struct sk_buff *skb, struct nexthop *nh, @@ -767,7 +882,7 @@ static int nla_put_nh_group(struct sk_buff *skb, struct nexthop *nh, if (op_flags & NHA_OP_FLAG_DUMP_STATS && (nla_put_u32(skb, NHA_HW_STATS_ENABLE, nhg->hw_stats) || - nla_put_nh_group_stats(skb, nh))) + nla_put_nh_group_stats(skb, nh, op_flags))) goto nla_put_failure; return 0;