From patchwork Tue Feb 27 18:17:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574263 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2060.outbound.protection.outlook.com [40.107.237.60]) (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 5F12714A4FD for ; Tue, 27 Feb 2024 18:18:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057909; cv=fail; b=B+DzJmWRXIaRavUmXEGOFBbzyxWzGdnXzaaq4Q2PNGX53MY3kTbrH7ghdp8EOhQtnkR+ZqLW7kJ+MY0yoL6i1TjfO2oT51xlooOcXHhk1Tb4PemxBDhRz2evn4/iKeagm6Jf9mcwE8AdaJyUoZairPnDmv/UQfKZy8T5lGUozcU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057909; c=relaxed/simple; bh=YcPaVQaQO/9PS4ZsnmUuvWEXupWz42NNLpx7kEpHaHM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hpf6auiujyKaOm1KCU6YJ1rMUo1sejdMwFhe8wZsmRlPcjIMYlnCBajV1N+LgWNmaQbPUNDGRXygDYVpHDJqQeWGy12mGuW+JsrYE3GO4ot56Mu3ZSSMjINKbCkCFrpheofbDUq2/2NVHfEK0/qR9Y3/i0dCyzaugoYczvea+38= 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=jVSUyOk7; arc=fail smtp.client-ip=40.107.237.60 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="jVSUyOk7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RUS2lBLXUN5HUafaHMtFlEbabqQDO3w8TiErkTfMrD7bZbBMm3qnqck4iufBQEp1HsIQOSzDBJ87I/8BlOMaIqDOrF3eLSC/u0EqhLSCSr9vyavNtYO+ixFMziaMjbBzz6DiCT1MPbi6m/vlsfjPS+pzg9etM9zRD7YndYVw06YBj2rvFA/b0YwojZqpwJQ3GMgWDvWclsFWeX16GLULuaxd/+Y0gM2rMZ+0vfbXYDOfT0EUpdq42NzDmfQ3E9fd4ACuG6380flruN/axcJENWZAWJbiaQJeAVd6rElOBgiGjSJ7RAR+TVcIWhhvdlAXVCI6cIBAgE7aB3rv+fr6XQ== 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=GQvQZQRHOhfCSa0I1LUIhik0nDtRAPowxqTn37Dpa7Y=; b=NMPMdEOoEG1szNE5rVBC9Ym0mSFqbpXndDK0ApTFGxfg7G7yKKXXi/cbdCAU/v0KYFiFwvEzhhwOvX2Vie1NvCiHvWS3ZUrn6UAuJ3zVHzQ7SVmAt4OBIFcvbb496yE9NJ+WuIWssS6iTEzge7ihd6Y5ToY8Rl/9lxvkxdqKrRTlzo/tPzh7jj1lsehX7rd0p7vsW7NYPJc4Q1sqcJTdsHw6WlXoY0zZYMdAz/PI2Slb60KtD2VkA10N7Ux60F3ARhYd3DSidJnj61/ZulQt/me06nLaeETbi66nTE8L9z6J44+N0L8SxwNAFSyW3fTtCKgbsVufsnHd9/zUBMm+NA== 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=GQvQZQRHOhfCSa0I1LUIhik0nDtRAPowxqTn37Dpa7Y=; b=jVSUyOk7LrzJHSuwLE7g3VzzhALFX085ldjNEIel+hNH4nVLacNSdwbB3yqqnNDOhu6LKRH/QW9YFXrmTO4pIE8H3KFzJqeNe62hne5ZZHyPh5c4vp7a3eIQgCjNYE7W5n/M2XpsV3YqNyoB3YAOVkNx7IoYtcyd81rqu3Wgfvp5qACDzYjVkyzi6P5F5EXGgNkjGgvPvldjsG2N3K0HMwVxoDDqFZiIZllavDcKdycfmUNiVqT1aQFI3R1ODac57eGmL5WMaHiEimBNygFlmQTlQ9jyCjOgJXa8xeNL+mYk1OlkZfz0g9DrOmCKOWCTPoEd+TjiYHPdCfi4wRMuTw== Received: from PH0PR07CA0013.namprd07.prod.outlook.com (2603:10b6:510:5::18) by CY8PR12MB7489.namprd12.prod.outlook.com (2603:10b6:930:90::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Tue, 27 Feb 2024 18:18:18 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:510:5:cafe::a3) by PH0PR07CA0013.outlook.office365.com (2603:10b6:510:5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.27 via Frontend Transport; Tue, 27 Feb 2024 18:18:16 +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 SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.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; Tue, 27 Feb 2024 18:18:15 +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; Tue, 27 Feb 2024 10:17: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; Tue, 27 Feb 2024 10:17:52 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Subject: [PATCH net-next 1/7] net: nexthop: Adjust netlink policy parsing for a new attribute Date: Tue, 27 Feb 2024 19:17:26 +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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4E:EE_|CY8PR12MB7489:EE_ X-MS-Office365-Filtering-Correlation-Id: fe65d4d4-b921-4969-241d-08dc37c077b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OyI5tGNRZd6T/CQmpxP7B2u3/zFV9wtXkUIa9xq1jUZ96yogwvNRGcckAU2JPOeOCplpEhsd4yhTJNKOG5RwFO02VGUrqauLAqM6CjekV6TB3GVhiqy1hvkXP1c052EQapKYp7eQHhaAiUT0Rz3c70p7VW+g14qftosvu4ERZdEJ1Oo2B3c7jfzMzHq9Yuh4szs/tOc2Aw10gJynO1/6CXHzdxDUErOhAJlhb2Tfbcf+kGjVqASAU8OsL5pTm/C2fn9kIOLBt15PHXZeupd0zC7JyYrtSrM3qM28itB9GKeNb8w4j6q6YqJmou2AsySQK5VXEK3M872iCtVINnn2d1sZcuJ48w23VqmTg9DcHFE/np+CHLo3B/3bFxMc+U/tsaLGsJyqWD/svhp0poESx5XvVzFooqQaitO8hsw2KZbx81hgtvXbr6OYXd2jiEVWERMxPBzsAujQKnV7nz7bBa8qE7WTMCh2uWhQNWioIHyCVdK/08f6Aa0spzQatu72j0HmUradnCxuiQiDhj8tiiTXEuMRR8P18AYteN8jsbHV30Pb7Cz3k1suA28+csyNK5Wy8vFiwefCFi9XFwGDPbysjTTAUwQ4q0/l0RH2tbx06nRktEbKZID04dPDXBP8oRjoieGgvLqvvN1o6Q3IDPH1TGWONOn7BxFYXH9SpSmjZx14qFt0ikQAmBOcDdYvD8PxQRxWAWsdkGt2bHvqLzcBBg6bKokxmUwvKgGpej6XmaMZQ66mXEnQXofq39fg 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)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2024 18:18:15.9838 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe65d4d4-b921-4969-241d-08dc37c077b3 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: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7489 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: Ido Schimmel --- 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 Tue Feb 27 18:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574262 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2063.outbound.protection.outlook.com [40.107.244.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 4A4AA14A4F0 for ; Tue, 27 Feb 2024 18:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057906; cv=fail; b=IezAX4a85kn9e0h46LWNjwvBuu23RZR8qoHu3qeuucs0C9nbkoXy4S5qe6w3dchcA9c6OVa1U3TyaSkfszjWVYtXPRK5sxPaxJ3yU6h5apj6m005CZ/KWKr1xG3GJ4GGl0TZxBi+j88+BOVjNow/AYsJ0zKcSCGb1zGW/ag0wvc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057906; c=relaxed/simple; bh=Zkj/z2ye/0nl5QOp7gsAzDDx9dDlSdLOblWG6mv1n/0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W29sUL2FgnNguvzPPaS075FkkGI5aI1eb4ruksGIatWDDspF+Qc+sAmfM1xOj/mjsR4gmGANX+hrnbFAabUmcuu+hZ3ml2sXy02yclg427aDln3mey2/46KZGhluQCTfwd/43xbJgcHBiyYy+jaSaMYF0mT25TlfdWrS5z2Qjqk= 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=dz8yUgjZ; arc=fail smtp.client-ip=40.107.244.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="dz8yUgjZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XLbq6zPKEG9GKea4l8MXHKxpdSoH9NDVUXXizvVpCOPuKv81aBPTA3PV4iaMSPwfHe5++O7ORCkehcnFdIOFe+5ezGFqAzfdovKHPtfdhq2VH/cRtdWhWuTBlOCGzeQ+MIousHYyq9VFL9uHAu83dTaTTJBvRcn+vhT8Bfd1tdwa3/eyXXojhANpq6WkbU7VvxCyBLtsedMAXiYRHdRrooD0ysb5+Hj2jm4zuszRC4gHnvEvqxe4MLC1N2XcfI5jTgAArEyUoH8fqP77c7ZJ3Rk6NvbzXBxxtc+Z6QDDLPheP0mkT6mg5j520ZmCqphH269bmgS2kiR2+0pB0ifItQ== 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=386vtyWJEsahvAYm6rqfpRN9Dnzkd/FkRxSYWx7u2Vc=; b=U9N7XNM3onkIfRC+iQOQoqtUCwNNJvGjws37Tb+WHCXl9LL9oGkmMhJIDa7U7csDAmuQ1xKRUDtVghNk8NiJ9wMhjLfZGZJEWXNF3Y4T0kNpM9cixN97nMjhEMLWPbu2xSLMU9a1Y5vAKBW4A+pCG+oH0zf4oTLLq7VMXlHtK+DImXlFDUTDyCkKgn7idIYRDZHjVoe2nTA8Z+1oaDnPDr+1K3LFrMLI1Bk3UHTe5kqAHBOdXZhNEZTckQyKlxn8CxKRd/sHxzs/jmdSJLW7dLO7YlUiv6POA+Eecblfj4sTt+B/g0ju87QRZM9tqBTAGzKhdGLdZSMtCVcbzv4LrQ== 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=386vtyWJEsahvAYm6rqfpRN9Dnzkd/FkRxSYWx7u2Vc=; b=dz8yUgjZbfgQNF3A4s1F07Zy9bJvHyxl27PLJIwtSbq+kWX5oW0d/zL3vBKyVsgEURxRddSNoZibrzcs+wYVUw+vYIqjJgq2rW4uzdlgO1TGKbAWLEAEiiA+9AvxiK4n+humobbnV4ZnTfJoujgN9tzTVJ50gI0s66Svwxa8XL4r1o4aLMxPB3K3YTSK13FiHa7W1aqU744BJumIgyQAgzuWgR6qSsUyXNtzvRtkvzEPN3luVdpA/W/57KxpNheT9F4zqb07fzoqhdO3DbIcT/HSCm3aE5insRom4RwlwHVBm/TSykGQMJT1DEqo+rzqcyfedviUzpdLruZpadXhyA== Received: from PH0PR07CA0019.namprd07.prod.outlook.com (2603:10b6:510:5::24) by CH2PR12MB4039.namprd12.prod.outlook.com (2603:10b6:610:a8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Tue, 27 Feb 2024 18:18:21 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:510:5:cafe::a5) by PH0PR07CA0019.outlook.office365.com (2603:10b6:510:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.49 via Frontend Transport; Tue, 27 Feb 2024 18:18:20 +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 SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.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; Tue, 27 Feb 2024 18:18:20 +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; Tue, 27 Feb 2024 10:17:58 -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; Tue, 27 Feb 2024 10:17:55 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Subject: [PATCH net-next 2/7] net: nexthop: Add NHA_OP_FLAGS Date: Tue, 27 Feb 2024 19:17:27 +0100 Message-ID: <4a99466c61566e562db940ea62905199757e7ef4.1709057158.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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4E:EE_|CH2PR12MB4039:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b17716a-fc60-40e7-e070-08dc37c07a36 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Rzx+zc5XOQpXhG7AlX7u16Vr9RRdCI+BgwcKb2Z4r9YqzxsIPZUF/wQs6+JcqRmg0JSmxBPFM0T4iz9Mb2yl+tEAkaCaKULQXYZ0VSH5hL94jdgG5FOl+k2Zhp93bW+UGP8zTx9aVbIckveKvqgrczRAg3g/iy+ebEWOM4scH22sgy6Q/OmbWdokrGlXMRgInmjfOqnKr3xSeLslMTj0Q9Nti8KhNIBliYXkgg6e+qG9gj0kkXWsq2vbuZWYCsZ1HjtS076uL/pO0iV6uHq4R5rPz74EYBHuEmyfFVRZlbRnTXAacCcEMweVxmD0I6LQYylhChU3CRaoD9lfsHLFBX9l6fz6nX11Ie2VV3MH0N/8Ngfj/2Xdut/niZ2uNv5KCV4AFdE50G9VfU67tUZZBNxC3AFyC/53PkIkWmtA4HsdtxukO1sNcijkbBJpL32w3+XmcK2tn7QDiSm7nfoKRW/eZcOZ6QC3iHJJp0OEDBlEf4INWGmPb8SVka6tq4tBPbKGCltFmdhfp/AZu1pvukkv4THu1zYlQY8IxnjuD9Y3+eqYHQqFylFwSp7ZOq3U6xUpHCbMoygWw3VxRNid+I0vvChzdVkSY22ErpiMUj7UZir/33mvW0OFuC/skkGbWtUvWtd9GzKWfWfRe1o4mMMmwE3ljlHtEsobRCap9faVkvAVqR/YGMnPbpuzBW+MB2HwqoxyVnGwIUroZmIeZNbtpa5ns7pz0lNWqqDs1tSLWWKHlIgLM/4uanpwqykz 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: 27 Feb 2024 18:18:20.1245 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b17716a-fc60-40e7-e070-08dc37c07a36 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: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4039 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: Ido Schimmel --- 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..0d7969911fd2 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, + /* bitfield32; operation-specific flags */ + NHA_OP_FLAGS, + __NHA_MAX, }; diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index bcd4df2f1cad..e41e4ac69aee 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_BITFIELD32(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_BITFIELD32(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_bitfield32(tb[NHA_OP_FLAGS]).value; + 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_bitfield32(tb[NHA_OP_FLAGS]).value; + 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 Tue Feb 27 18:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574261 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2058.outbound.protection.outlook.com [40.107.220.58]) (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 53D6A1487E3 for ; Tue, 27 Feb 2024 18:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057903; cv=fail; b=nor8XXvDcJh4j5LLlqG2zIgcwOIf6IjJnNYzRfLWTnbqsQylcAMZ72nVuPHjprokVXT4Uzr5du+zXMgUCvY6Be3L20RDXc/sWVjGbR/crp/uVp5Vgb+ozeuE2r3l4TQdZjR3TvZ0ey5R/d6zvMCgC2uR0n+/tCQSyi5dk/SRg+Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057903; c=relaxed/simple; bh=NK4G/DoFR69r+yTYTzyCA6bnaKk50ahtKfUj7AVuchU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DXyiCq63TsMGHZeChFWB1aRN9qQHdbhdX2ToEq35ju7+Iyg7LzSDiI87J6T83+SiPidKsS22e14By06s/0jmx4aednjtDLj92A03qPCrz3HlsfB4jEdMIhBPQzvDigFUUx4ICaQ6tXcpHXU8bhLl0bXYeWZpBkNQ9bTecqZg9is= 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=eXcf0fny; arc=fail smtp.client-ip=40.107.220.58 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="eXcf0fny" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l+SZ2NoO/a+ZQ1bkX0SZ6m6rCvyFDeCKVIw8lVfRSjIkfXpfAJWYgwD8Y0OnBl9NQhCRRD/LJNh4Mgbw2mxnvaDIDcyFEL8Aysa6C5/FQUtOHA2OMBfTmu1rqAviSTvC3ILeOQT8S1BklVf71Mil5jdY6vYOKlwZ6e1Ed0N3b3tlobU2w7FW55t1uFH+RHdHgCODfFs11VH5GNIbqLimCgFJyQexXmIEAqIAFiHKIiW665tv4qK/31SFps0kHkv+D4ZqELUwmJLqgAq9sns1jLzzstefJxVpckott/UBB1ki9qS19PKWTRYuSOu9gzk0L8e30eLxkca3N8I/fSmkAA== 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=X87g2KP+W50fI5wEti8OmUKBR8DxCkNCQAAy5JyKT60=; b=R34ZnibeSljUVe26yF+olAIJu18XX+NkRt4wE/yGGMyY9SMwL6LUJRqdeHvHwBVVU503QEXQDmPMkHIsAXHftahGhUG8onYmVGx1Km5Fi6+2K6APx8zht9MnO7OSXs++E4ysIaLOZM75QnFSf4TvFKGrLRkDKMmLPnFF9bZ3F+VFe2X2YZrloRdw3YMnYvWgJj7Zoyggji0ZIFvu1hLvx4JQB9EAhERriC+fR/YEgH9huM/avemTT8Rb2UEjCV9TACvYCMYXydVdTbe+Bavs2ldZ8lLiB2v0BRvsetzD0ITdvLVZsrxxJnDsT25IgaTK48pZgTpEcIkLDULCfG4sSA== 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=X87g2KP+W50fI5wEti8OmUKBR8DxCkNCQAAy5JyKT60=; b=eXcf0fnyJGBaHfyezIeVmrouIzI9o6b9ITZ/T+vOHceuXMlFxFYNRMXcau5iN6BFvY7tDIcTfjhi+MsksdYuEWyRGQLTZYNKlrahC1OcP0XIhD8vu8WTnTnrudnOaQSboVnDGkHwwoGbuv2fVMagS4sg+E3jD37kFFUirtzqf2WVv419t9FIqHmEYkxHYUESWJJhdKPzRszssM1d9Jd1nDaEd8uJU7VgDrJJGfaF0UdrVwvYpKWL6ZYA+dEwKcveuPAgozOkz8oKrIg3Zv4rKg5Vx24bu+xbr6dKGpXLyFxtePc3Il244rn0k4CXUjyEiOboTs1fjBIINP58LNmtsw== Received: from CH2PR08CA0020.namprd08.prod.outlook.com (2603:10b6:610:5a::30) by MN2PR12MB4176.namprd12.prod.outlook.com (2603:10b6:208:1d5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Tue, 27 Feb 2024 18:18:13 +0000 Received: from CH1PEPF0000A346.namprd04.prod.outlook.com (2603:10b6:610:5a:cafe::30) by CH2PR08CA0020.outlook.office365.com (2603:10b6:610:5a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.49 via Frontend Transport; Tue, 27 Feb 2024 18:18:13 +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 CH1PEPF0000A346.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 27 Feb 2024 18:18:12 +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; Tue, 27 Feb 2024 10:18:02 -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; Tue, 27 Feb 2024 10:17:57 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Subject: [PATCH net-next 3/7] net: nexthop: Add nexthop group entry stats Date: Tue, 27 Feb 2024 19:17:28 +0100 Message-ID: <7b6e4e106f711bf25ffeae1da887f2ef53127ce8.1709057158.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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A346:EE_|MN2PR12MB4176:EE_ X-MS-Office365-Filtering-Correlation-Id: 24177752-4c15-4fb4-abff-08dc37c075c7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2PN1ipBCCf7sJEZOig8y+Wujx/5y5syQLIz7HC9K+Lukuvm96XX3KckwNGnUt+Jycwb6p7OACByYUFQdy/Q+zrE+CErURYCoML9vWrNLFsyebUI7nnyb9AskON9H298aDRCRyPS1jekXO4QNl5mD53vUyDMtHJMBqLDwJt9O7st90sbqdHQ8aPBOuDdxZs1k6E9F+qKpNeQBjRzmStZJm48fnU8LVyXQSUCQR3WcPEMNZ7MIxxRIDOUwMl4cCwPIgUCBMqj6REnCMpENf47Q8ytkxCaa3t1KrlhWRswuqIUfgxd4xQEkXYpTU/+DrpDRwfJ3xxREGkjjFKaKAPgmbd2jWiyjZ1t5sddfEzpa3bsVZRARqCCfH1FoxhuHwt+jP1Z+uMG/xCZUGSwNXH/HwqKrPlSxFbvdczJ+Yoq8lDdbCCfW0iks4WDBdlw7wnPLFmhPtZhak5n/RpNCltA4Hx2rgBmbjcwrDVaKjfSAkayDVE6G9ViqaC9DNp5S3iaM8Wj6CqNjCEKikhkmTGId9fdAADFrVBlb0qzbHiJVtvGj5OYvAPpENm2tiNWWpCpdbcF1xnQ765zEZIOsZd4EhsnI/SZi9WzCjhKyYl0SJHgdcKdE6lcLMydbAYIgV5a21Ba1j5E6ls9C2D0NtRDxlj1OBn6gyU+dJvDuJVnXEsbXV3Ydrgvb6dkTt0kpzqzVQVzvcpVSi8GYgTdNCDLgxChCHzg4Pk6FkXpieN/mrL8TVdZm6lOxrwn3bESW/TJ2 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: 27 Feb 2024 18:18:12.7317 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24177752-4c15-4fb4-abff-08dc37c075c7 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: CH1PEPF0000A346.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4176 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 --- include/net/nexthop.h | 6 ++++++ net/ipv4/nexthop.c | 24 ++++++++++++++++++++---- 2 files changed, 26 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 e41e4ac69aee..29d0ed049b91 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,12 @@ 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) { + 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 +2537,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 Tue Feb 27 18:17:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574260 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2045.outbound.protection.outlook.com [40.107.94.45]) (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 584211487C6 for ; Tue, 27 Feb 2024 18:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057901; cv=fail; b=E6mvx4kesH7wk4nWkkyfMYEvMRegr/eHEq8sa+M+Zw19YTDUITi9svBZcYTW1xfH1bArvEZpEvH83cUGdvv0UwsWVMPikarvv1rMFHnMA92kRlf0nh2TiZntwLb39pExYIUTfDZn7i3QwSDqkCFFKNrwEqgM8wgbBbwnagnMcZI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057901; c=relaxed/simple; bh=KAKwG9HcsasfOvB7jfPzIT8FAkcCMOX28E3bmfCirsw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WaR1TNBkPiFe2+jHyvN9li3FRFd5rRYJ6fXivSfhLtwQkvr0pQkrMBsg/Em9Ln6wA3RReGWA+or9f4FEl0WF7w3FwZFHZ5CLfBu8J8VWnRqr4hVVSmno/JZNKktMA9bF4HvhOm8DEjoP9QKkyVJLAffCIR1dvfZwGvsm9E+wX3I= 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=VJT7ue5E; arc=fail smtp.client-ip=40.107.94.45 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="VJT7ue5E" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RIUtdu491rJHuBW0EyM+IWV8Eh4tpKv/cH9abJo2YZ7gO+w5YNry+7jhKPHF752/MiFBffPpmE7TeUJN+jvWvy+RagOIjdU0JiZUIUanEs7ACSzJWSyoueIrVCnMwn3hafK/ampPUrAk+/+5NseBUQwEMwfQ0JRO5NfoYH7vImwtepR5MXfSs8OZo+IEuCBMPo49oa9y02NEZUMpN1t5uTXmckrRhQUH9IgtULG27n2zasva8eHeLFhCnfv17i94tgV88KGLxSrbuXYB38enroNqWDHFU6Wq152jM5IW9M7JLa6BR+EAKD3C16vDDo5sDH8sa/52Z8/rPRMwlvGVBg== 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=hdD2FJ7mlMhUxLGOoBjzIIzqXcOrnGnuVf9w+2eA9pY=; b=Z7DgDDjmSY6JruCdaMdtvMJUDowibW6bn1UCSKR+94yP0RLKdCspisXYIicdeKLAAOKH4cWjDNzCtInYjo10ZPxAyein7nR4oog1Vn40yL3BFvBDp+0eOXPdGtb/3lkMSIodYRondQUZyTa+IWqXjiMKDNG+5z9yLHsKkf2p08KXlhgTCGGKg4/fX3IZSv6Z1HH7kwW3n04N2teGoYFYtXQj30lbnee/w750f8gEKLrvnaRZMpJTY6Ep48dYfV2JvwiUphplJ/Sw9p3ltJ5nYsn8KFxjzoBivBbdSnZBY99AsUaaSFBmqe1zeZmtoD05p/m+3pX237XOwdujc0WsyQ== 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=hdD2FJ7mlMhUxLGOoBjzIIzqXcOrnGnuVf9w+2eA9pY=; b=VJT7ue5EFsKHkhjq6Fqc2jA+/Xm33JW2ijzHu+47QLh/wh2xU4wOtmojEQLaxfsQDQRtiSIX76FRN9Q6a+3rXc6Rvo2gW7m3hZQujrL6x3V3c004RR1NYvAvPL6Tu7SruPboezuTEeC0co2/E9VWFSKTeOnUmDblUVgzmJrSGTZfxY/QCQB0lMm0ekb3SaVz/xfUgsjkwXnJ3rDcQY17Xf3kv8BwF35fEMhHddJyN46ygWMeAOggXBpXNyD7WgVkobaQpLMrupfn7dt1VkYZQvuZq2z+jWQFUZXHR60axgE2EtCxY0dsu/uG6DOszCUTKE04EVIU3ZEyURhozKenhg== Received: from CH0PR03CA0003.namprd03.prod.outlook.com (2603:10b6:610:b0::8) by DS0PR12MB7745.namprd12.prod.outlook.com (2603:10b6:8:13c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Tue, 27 Feb 2024 18:18:16 +0000 Received: from CH1PEPF0000A345.namprd04.prod.outlook.com (2603:10b6:610:b0:cafe::8f) by CH0PR03CA0003.outlook.office365.com (2603:10b6:610:b0::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.49 via Frontend Transport; Tue, 27 Feb 2024 18:18:16 +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 CH1PEPF0000A345.mail.protection.outlook.com (10.167.244.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 27 Feb 2024 18:18:16 +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; Tue, 27 Feb 2024 10:18: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; Tue, 27 Feb 2024 10:18:00 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Subject: [PATCH net-next 4/7] net: nexthop: Expose nexthop group stats to user space Date: Tue, 27 Feb 2024 19:17:29 +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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A345:EE_|DS0PR12MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: e6781402-afe0-437a-9b43-08dc37c077df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KwYMkWIV0FECpV6kmX3UTL5OoSYErNZMhP6AfvapDgOuFIx6HghJCnIDA1E2zTOCXdkuWlDWdIPh0aSUwbEHk7JOR2hM2OhpJJnnF464knEXEORLQfySnVMibJIJEtfGW2FHuQcncyEZIUEivw8diDgjGEDeGrQPN3LpbyHUV0eJT+Eprvde1uWz7paSp/TNtP5Z93WKJbcjQBAJDPvivkWBg8+20K5tynmv+rEXXUz4356LQH9ZDOkd0RCWv0CnAukax+4c2zZiy6u6wVaScxh7qp7N7RnGLy2KLiHq2CDvkKGEIVEBi20C11MzWs4IPEeLAZeK0aJNiOAvFV53DZmvMVvZf6Ucoq7BznrlASZGnxj8a8FrKlfjvxEtQBYV154uyWLLiwzrRaS3iNhUspe4imp9L9kpaecfLhOl3sct+J3nmWgEELwaXus/6lpdtC/7ivb/chzSif9E5Jb1Ep6uBs+yHkro2gY9X/uYs9VHR7HnsMLCDFdIMk5xWD71qiE64X4vvsz0zAxY5Fymz6T8uOGv2ObULs6VROkO/v8ONVJ//xgsbjjmTm1ned/OtsMfjwHnPuxHyq8vKCnNKqAV67Pwm79m0VmpJA5unFJrQgmuwgxGFXA1KhQv1ag+u19CKrtu8Ul6tjEe3S3z9cpqVLrHi1UJIshWJrl2Q5EH+7igNJZ8S1Q75NKi2NARwObIpKMdeIw3NQmFbiG9RS3LKiMX9oq3+FT2h7Z2VpA2yEEKpMyH2GjvNN6YyPGP 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: 27 Feb 2024 18:18:16.1815 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e6781402-afe0-437a-9b43-08dc37c077df 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: CH1PEPF0000A345.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7745 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 --- include/uapi/linux/nexthop.h | 32 +++++++++++++ net/ipv4/nexthop.c | 91 ++++++++++++++++++++++++++++++++---- 2 files changed, 115 insertions(+), 8 deletions(-) diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index 0d7969911fd2..b19871b7e7f5 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 { /* bitfield32; operation-specific flags */ NHA_OP_FLAGS, + /* nested; nexthop group stats */ + NHA_GROUP_STATS, + __NHA_MAX, }; @@ -104,4 +109,31 @@ 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, + /* Pad attribute for 64-bit alignment */ + NHA_GROUP_STATS_ENTRY_PAD = NHA_GROUP_STATS_ENTRY_UNSPEC, + + /* u32; nexthop id of the nexthop group entry */ + NHA_GROUP_STATS_ENTRY_ID, + + /* u64; 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 29d0ed049b91..9c7ec9f15f55 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -41,7 +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_BITFIELD32(0), + [NHA_OP_FLAGS] = NLA_POLICY_BITFIELD32(NHA_OP_FLAG_DUMP_STATS), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -53,7 +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_BITFIELD32(0), + [NHA_OP_FLAGS] = NLA_POLICY_BITFIELD32(NHA_OP_FLAG_DUMP_STATS), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -661,8 +661,78 @@ 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_u64_64bit(skb, NHA_GROUP_STATS_ENTRY_PACKETS, stats.packets, + NHA_GROUP_STATS_ENTRY_PAD)) + 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 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(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 +761,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 +772,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 +800,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 +931,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); @@ -3084,7 +3159,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; @@ -3254,7 +3329,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 Tue Feb 27 18:17:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574264 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2056.outbound.protection.outlook.com [40.107.243.56]) (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 1749914AD1E for ; Tue, 27 Feb 2024 18:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057910; cv=fail; b=JNe+6Fq8JoU4t3kPbMoovQ6Elz0/XS/KeTY0llsRQsOWP3G4qBvqB0SGTIIYsrg3ujOK7YIdzBb9eMlNmlWQGGNF2gbcbrvQ6mFwSn53Sjd4YxdY6WfDHsty/9gkl66THCD8ygtJGrGOaVR+wQG64g0DMHHXRbbfZIwho17Q4m0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057910; c=relaxed/simple; bh=wAfcksJakYsQvFpa7+LTWKCV68jyYaJA0QvKQp7uVRA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pQwnl3HHTX1IRIBEnjpdThGlu8Ui629+LD+xAZJv4W+3VU5wuUGMXnDc58nD4yBSd8wkvPEXd7yBy1fRZ4vFg2b6OqXgEUdWRhq54DGhpV1M4z0xpHY2dZO286omyfdRehuZBp0dwT3NNKqI5wlkEIp6mEZkQ87L/8BiVRkF/rY= 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=TDeQYAYh; arc=fail smtp.client-ip=40.107.243.56 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="TDeQYAYh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iX/mR2WyXpcWxBQ4lf7o5jH2MfUt4DQD/8RzJA15jPTZo44IsM+YbvXKL20oyopdl0kpU/JDioDHJfBr600SAzqpiDxOm2g72vojRuM9H1VgZBQJisk57835aDNzIMigzKLw4jg06vXtVkEg9XUG5WLUwOpbdR/o1XMSLdUFVnsN5z4/89ky5n7K5U/yxUmPbUuQajCXaPWlsQJQBGHKgmd8JoZ5i9RNCpWsFwxBBxzcfCSPC5i7EqK4vpUmByd5rQhMH1RZti3+KIJECAg9G6Q1uOqQT5MtDvHl3JWvntnVT7ylZKPz7IT+qi6dSMsZp36QjPsniK/gEEMUNIG7iA== 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=cZR8LtrFBiQI+GnFDuSdsib3iklnV0zpPs5Gb5yWvwo=; b=GFOj/DYvIAMpzhqN9QqcPFXau9OHxWM2WYJj3WCgHCvmX7P7hO3OlRI0XDXKDE1E+1PFBNRnlO0N10+/VThmiIFppEZIuWKop8ryQdxlzliTzarLGQZYm4LJ+K0r+BFbD1tpccUUHS4JaJNjoJ4ob61IpTNgNW+8OhyijTWUA/GgQ6zIM4/z5oxbEf5OOdBbIvy/y6JfAAiCWnMQ0l0yPK56da1eWZR5Se8dXV9dTemuDVWkpn4VSyEjgD22Ra0IIjHQA0BkyBK7b01SRHR4Y2Oy3TGBHSL+/B9BAN+13328cx32ru/t3giP/rftkgCwf/GBdT+PsGIGOquvUjLdVg== 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=cZR8LtrFBiQI+GnFDuSdsib3iklnV0zpPs5Gb5yWvwo=; b=TDeQYAYhyWqPZoRHDuscQJ0XCsrUc9C7e9orP3SDkC7npIcy9j0BG7nPmXGho3CCv9sKgh9snaHVN6RiFNzbWhhFTqK6XoSW42sroRtQ0+w2Zn9sKk2fKYCyu/lizCzTpS3VG/+SQrsxvYkTysJFPE2qLz5OKx/Hxl+dBe6VWMOE6fU2NU+gJp9lpR58Ad/UzwH+4l2JxOEWjtmNaU22loqDUKrNhqKYzWbovv9JQp1eLKyzhNBEuN/cShVz7l6Kfgg1SFvWAa7RostU7QOEs00S4SgooWivUSE6Bad53SsIlB3WvAr6ryF+CC3Gf6u9G2tMzHg7EGvVyOT0n8UqYg== Received: from SA1P222CA0156.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::19) by SA3PR12MB9106.namprd12.prod.outlook.com (2603:10b6:806:37e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Tue, 27 Feb 2024 18:18:26 +0000 Received: from SN1PEPF0002BA4D.namprd03.prod.outlook.com (2603:10b6:806:3c3:cafe::a) by SA1P222CA0156.outlook.office365.com (2603:10b6:806:3c3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.49 via Frontend Transport; Tue, 27 Feb 2024 18:18:26 +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 SN1PEPF0002BA4D.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 27 Feb 2024 18:18:25 +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; Tue, 27 Feb 2024 10:18:08 -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; Tue, 27 Feb 2024 10:18:02 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Subject: [PATCH net-next 5/7] net: nexthop: Add hardware statistics notifications Date: Tue, 27 Feb 2024 19:17:30 +0100 Message-ID: <26df18fdd78e2110bebca9e17e8ee0d2bb3f2bf2.1709057158.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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4D:EE_|SA3PR12MB9106:EE_ X-MS-Office365-Filtering-Correlation-Id: 27b2a63a-fff4-444e-3e34-08dc37c07d83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7R6frELm71Z5ypAnvN1Sl5kFbxJHiEgp144jQa+RNxG+snUuX1xG69CbJZJEUIXuSKsHxl7IUxUi7sQggCUU4rBkR8GRf2pVkqnsPWkR3zNJ9QSwqzafJI8+x0NL8/rLXwUvj4cAqRklYvl9/qV7rIpbku7W17jX8HiQppjhrsxSecTTRyL8G9QzjnqmegKYfIQoixp8uk/lszVlDwaZ1klnh/hgxJ66c1JplPmPmCj1Xogn4KXwoIEh4aAtns0F3dqmJvCwdTwx78w23GBYmHqQ9+p5+uVzl/ZOuFrPk5KrcjwzoWlRgUgFFunuYx5BglTTD56JV0X7jNDiHUdRDU/lekUkg4IlLPI+hGXgHS34+AUkSt4yAbHNkpO0hcdpla7RCpyxxp0sygk1+IkpGYlxxDEzKXQfWxYdrpNwbi746kJWoICroKutWUAJvVh6iMTdwr/CLK5ACaA0xYhdje1rfksWMEb+oaXXmkiiiQcaHG+J/vgpmFnm8VUU7uGlNLfDMHCZi7PRvOw1rB7S3JnFtet2StACTRww0M0/9I085ezw1OIv/4QBuVXUsfnM+xsBLkGKSv/u5dG/NDOfNEt4GNyBcxIzRwbANoqgQz4GRw35LrNQvTSrSmfSbbafRl+kgFqkZQgnNOwNud6ebQLy1dmmUC8sj4qYJJqXNXG1Yvq2qc9x7lvwWewubAkstpgwJkAYQm6nNgajOIKRW03Jzjeppkcba0oL/WM6X+SZsm08g8lcf7/VBO6UErGB 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)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2024 18:18:25.5956 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27b2a63a-fff4-444e-3e34-08dc37c07d83 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: SN1PEPF0002BA4D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9106 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 --- 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 9c7ec9f15f55..0e983be431d6 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -137,6 +137,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]; @@ -168,6 +169,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 Tue Feb 27 18:17:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574265 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2051.outbound.protection.outlook.com [40.107.212.51]) (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 E3B2314C59D for ; Tue, 27 Feb 2024 18:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057915; cv=fail; b=QRN4uoNuW843HxcJnt0Be9qoAtLhewoTTqUMnCkicNyP7W4GZun71aYRyqhgkLD+m46fglpD8QF726qraLjZ5G9NncjyuxA7w5YUlVrYwjy4pCRWYtW6GvRRInVbDbFSl63uCnBqhtOpvE1RbOJrz/LbtkcxiDavDi7Sz+XuNmc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057915; c=relaxed/simple; bh=njYE0doFl/w+iNx4kqLtHdADAdOyaa1UDj5st9OGoFU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IHV8HE6rvJk9+AIIhafSyDkFW+EV9iu+L3hDbZTt2DmwhcAVVdrEPWR+HY91WLCCekWG85k8fCdp6EkAqNP+j4ntF7LZhKqxoGv0UFOLxeKexHFX3STvIkHcf7GgJdGMR4Tx8t5gC0YENCyvHOAD7r0fIWm3wcn8HGLijWnak5g= 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=ueGOmOU8; arc=fail smtp.client-ip=40.107.212.51 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="ueGOmOU8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNrPkE2WtDO2aDMS4muE8XJUSDTiar/eDnX8tz0Nq+80aSV0UNsUsxYa78gGV+sex7Uk9PR43NVNXqgABy8SutBRUSSkSJC+ug9mkKcfZkiT0v/WvqTNeGdOzTJpC0bT3PJpTSuokvXlvQANS1NgeLEIZaxdxaG/wL1D5XhsO/uhKh/QOviqqK89sxUkGH7i236KiIf4sJudmUD/fS9N/tIX3wXQ8WUECnP08zEnuWydaEObE7g6SbulqbqUaAzDR76ztlrsTuxdPG25zs92yLjlSlHDIX1k1i7gCudX/7Lo8hjZA+95O/6hbLQfbIndgu0ena6mGqETaVGV8YxpjQ== 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=ofcbX5MBY5TsnMEQ2lVAvVHAjhraAq/cQkjnwHMpzYE=; b=AZE/erMvuSybu8SAumNMWwnfPzirkeihk4+Ug3B65RDeF/AQTcl3UkWp8eZGW6oTRuJHA6Flqr2U5BzCBtYJ18nZvZR5yOgY78SvjSAR7oRc59CipHo2414vGtEH2Vw2OD0AEBpw53c3ylMYSqEriSZ7W8v8vGfT7P0u3oQiimBt7SUHOF28k6GMVdxFfILh8TY+PaaIeFtU3YA6w3L0G0MZd7x+nszXjnTFSvRXeeVdRYB59kzs0RJCNcYjxkUl503Gnr9SJFgnzgif7J3nG5vJ1l3+HduUnwc6exDbD7JbbGEI1X9Ue1DtB2wR8yBKYlhtMSl2bkZL17tC7XS4/Q== 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=ofcbX5MBY5TsnMEQ2lVAvVHAjhraAq/cQkjnwHMpzYE=; b=ueGOmOU8fCj19wcAvZsAEbK90XNxuePE+9VjFRbrqg5k6Kl4BhQUG0ZOW4lJ5UT+sJSpl+kDTbWzwOaW2HCmXPfpM+rAsapZS8QTP9UFwUjRrEiqInFmps6CdEld0CwwTAAkfj1V+ImYPWMjqhAuHWuTy7x/zXh3X4DxgGyY7xoCjywmig1WcoN8EnI7hGwwI1wpCt8qtaX33H8zfIHBse6+M/peage3ABXGm5u1Faeaicr4Y0d5eOD+CBcWh4X00FoxzUUDDXu/c3hOS7c6YuYQk5iZB3EzFiaCH07yxS0NONbkbzSU2PpHIhmsM6Ob4neIbRgwWqo2i3aB7xJAGQ== Received: from PH0PR07CA0004.namprd07.prod.outlook.com (2603:10b6:510:5::9) by IA0PR12MB8253.namprd12.prod.outlook.com (2603:10b6:208:402::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Tue, 27 Feb 2024 18:18:29 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:510:5:cafe::37) by PH0PR07CA0004.outlook.office365.com (2603:10b6:510:5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.50 via Frontend Transport; Tue, 27 Feb 2024 18:18:29 +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 SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.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; Tue, 27 Feb 2024 18:18:29 +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; Tue, 27 Feb 2024 10:18:10 -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; Tue, 27 Feb 2024 10:18:05 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Subject: [PATCH net-next 6/7] net: nexthop: Add ability to enable / disable hardware statistics Date: Tue, 27 Feb 2024 19:17:31 +0100 Message-ID: <07dd1f166402658b59c405a0b2e7debce2c5a5b6.1709057158.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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4E:EE_|IA0PR12MB8253:EE_ X-MS-Office365-Filtering-Correlation-Id: 06b00670-7440-46e8-f286-08dc37c07f98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GjMa5LsE33/J7aqqW5mQvrUaq/1g6jIGfvh9zUgJrPLNO98xEOOQSydP+cmaHKGBOEOXg+o/GZVJnc70aAg4nocW3FkkXec+shhcUhtOhfkxnKf/OZ6P+nzXBkUag7hDdRvJSpmnzsCZtVZ8cP54fEKvS9J5Jp3av31aESo27hQbR5XU/lLgQJKRhSsrTLqMSpQgJ7sDWv3H2pJ6xrLJYdDLFWzWPIDkEw1fT1QiMPBbFqSnf442nWVVEayL/9kGXqVRjw1/maLQEUa14l4gixO5olIyishIM82jwjifvxkFcb31fxOo3smbQFij93wuwSwm7EgoBM0GDf5iXiaiq15TW8R9HQHahgEyX/tXnILcRd/npNa5S6KQi+eAPNo38Mq1Q8Y4bWE3D8yqXfkbBTVYLu7leDlAy19gmwyFsRNT5U6SgCbJcu/kFpspk7cyDC5m7PlUMEtFvDmDYqEVjQh1l/umRIrVJzvu3D0JqYflH5QYxUhRczUdtr16M0WH8d5XzBMuxvtpRyOYNHR9QU/X/FPJdt3BJa/+2xMY7s7ZVghYKsIPqUJ8pULWjVuk7LOLfArnxKrfsWCnvdVY6Q4m/Bv5EEkG3j/+7ripsozgM06akTGLfRwBs4b9OOYJn4ZSxuNYuPuPo6m+jyoKXMrXl+afxQ+mIG65blH5ZPbhiNhMEv27bmLhCQ7OmHTeLzOj/Wb3b5HHBL+p9a8fD9QCdQ4x1E3w8otIMoSELLuuRGsblKKIZyQFXqNybV8r 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)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2024 18:18:29.1715 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06b00670-7440-46e8-f286-08dc37c07f98 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: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8253 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 --- 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 b19871b7e7f5..6d5ec1c4bb05 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 0e983be431d6..2e6889245294 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[] = { @@ -764,7 +765,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; @@ -1188,6 +1190,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: @@ -2607,6 +2610,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; @@ -2949,6 +2955,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; } @@ -3040,6 +3049,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 Tue Feb 27 18:17:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13574266 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2072.outbound.protection.outlook.com [40.107.96.72]) (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 8561614C5B6 for ; Tue, 27 Feb 2024 18:18:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057918; cv=fail; b=e4Kys8jxPDEL39UjuXmyCo9w0A1KCj+TJ8V+kzIg5taWUv8V36uWNwK6qWiNxOHUf0+txA5nPzxHisJ1+p7CtJl4droASZbPTGp4tO3l/C+DpGbBSUfkZqhP1W6ocfq0xuvJWerl5sGJispE8U4jbIqpXU1znLoHasIalxsMX34= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057918; c=relaxed/simple; bh=2LnPXtvbK2RYDmPKCqVkZjB6HOVy4LsvPUgD6Vrp4WM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CPADZHbJ67Zxsqa7VsZ/2WGa9LCO2OwSzKpm/YfcIzmLjYo5r/KG6TWlE5od7sZekNYU8V8m5zHIKE1a+KrnCproJ5+NDYCO/kuYAJfMBGJVQHnz+vcxNcgSgdLvErgooylFOTDAwSzdMDQ+cRSOYfrUpxZx8hPuZKLF7W820fQ= 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=Rz3tehiW; arc=fail smtp.client-ip=40.107.96.72 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="Rz3tehiW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R5EQPGtWKqwqgeOvhTz4GpDFTGnKVtPOLQQnHgDuN5oai+e7Hvw+CqTbatxOBCcvY7IjJNvljQJ7VF1xXQznMVbL6O8akWX31fv74tUUUJWYVCLHTByXLnaPkgJ0L2RaRMWSEKCh42d/4wOeQy5y6/jtXuIS7wb7x71nhtGd+fEccQt14wmiLTYu9Cjwvo1egryaw0DlpW9WfYfmlEq418LNrk2ddmlVejjV1xtsoVaqIWT/cQkh3AalgxTkbmCsper/RfUyuC2J4uY8033cnV9CfwkChpxUX/6lHmaNa1FOMHG3DF/fT8BXQNuNkYz4abiKi+l1JlJjLriKL/jmmw== 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=Y84uQTSorBjwAI6ET1mMquQ2ABTEDRxx0EyMTjmV2hc=; b=jPcsFrD4t1Xe8YOZIAavKxaEGOtxC6OhGwzyHMwROX8Yw3TGfy03lErzPOA5fY0IfzeOprFdygBeRneqEH6BKno9TyjTMu7og+DP1uApTYMWEtDD9555oVmYIfbXH2OrAQdCQc5E1s1VzTb+jaBjpJ27ayPUmmwRHp1Sis2ryeUh6u8+vBSZ87SaqxtOkV3eU2evLiwafxgkyOBl9pBjfF/ikwTSLwI6Sm46ktJ2LoUTB2C3sor4d+pNClzzDEjsOZs8zbGE/SBWXIgUiEVQMOl6/Fhmkl/JIyWgKLkA1uZkT9YbFMxcgS/9m9XiQQCtB8AqjtLW4Aw23Y1WtfH2ow== 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=Y84uQTSorBjwAI6ET1mMquQ2ABTEDRxx0EyMTjmV2hc=; b=Rz3tehiWEAEZ+xfvMvDsB/srRpgIoPLw0zUIwij8W+dQiPf15NleVH3RhmLDK/BWc1JUxA5MkW99RjpTnwn+rPW4M50cmdyTto70q4ktetZ65aEfb997CnojRXbZR0x8044HpzGnnemKqIBC6J9Nk74bJAgu0pTfZ6FhJW+dkxGEhsj8OPamQoUA3WhwZrzkLLJAitn2YUTepKeahPVDNzuJE7PbfmNu32sNvWUGLRHJUOaiBw0CvevkHDIChsuMqZJvWEAIud6Un2N5zZV/bhxYjBhj8t1VAdsoI2vD7QhJ/rkiY1phXLU9Uh+44UfPCwqox6Il+YWYSOJ5wuxYXQ== Received: from SA1P222CA0174.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::23) by PH0PR12MB8176.namprd12.prod.outlook.com (2603:10b6:510:290::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Tue, 27 Feb 2024 18:18:31 +0000 Received: from SN1PEPF0002BA4D.namprd03.prod.outlook.com (2603:10b6:806:3c3:cafe::55) by SA1P222CA0174.outlook.office365.com (2603:10b6:806:3c3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.27 via Frontend Transport; Tue, 27 Feb 2024 18:18: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 SN1PEPF0002BA4D.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 27 Feb 2024 18:18: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; Tue, 27 Feb 2024 10:18:11 -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; Tue, 27 Feb 2024 10:18:08 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , , "Gustavo A . R . Silva" , Kees Cook Subject: [PATCH net-next 7/7] net: nexthop: Expose nexthop group HW stats to user space Date: Tue, 27 Feb 2024 19:17:32 +0100 Message-ID: <001978ea519441f0295912034d00dd1af9eb5b93.1709057158.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: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4D:EE_|PH0PR12MB8176:EE_ X-MS-Office365-Filtering-Correlation-Id: cd021f1d-c40c-48fb-ba7b-08dc37c080a6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cbJ8ZCOnFMe/lLCVRPbAEzJAGk0gYJeAd1gkK0bcQryI+ud9HS2cvgHke9x7AdmMaV6GWjzhC9u4TwiGpSt/23JdoznqUFHommwRPv3nxcpfoX5Pgj/6I/8gEMxafG59nVdPRB6zrPFuWtK2WRaMkWaaKSLj3di8LOwQBa3t+7IJM2KBM7Ay7/HOi3yxhdbWYQ6NRlOmw77qzZ5Ekys4KtnEvX8Sohx+rFNNVbgOJ+Eb1AtHPCKEvqIywo59tvTld7Qcapp415eTWG9omRE9fGEtXlul+FgDNUwBFkleE/vAIjYohM+mRQjZp543CVxupBO1p3fTy8oji11t74DFyUocChX+Nbjfe8na/luViBcYFM/EFIxOw6Sh1SNrIKcVOL/ViMTyEK2hui9O7MKCmVRWi2kWKrxpdXW/PRBETYOT9H6BzwU+Juc7l65oYJUsFPLJXIAoqfFiL4Bka7mwFOdQduHBh5l3CgLQD2Ej1W9VPFo50mcmIZvrqDIWbOgxrsFTmR3dM5mq9ZomkNd7HRV5vfdc/2H02NJTnKJyKktJLnSQiIxaydpN/NAvg4ho1YGD62vNp4uW61HAWtUkt0N9QPAaCPJbs0BDMM8ixYgKV8mCJ9iUbeK9tjvRxYS3GCplThHH9z0Tbs31RadYYHQMqCm6eqNIEh+To2hxz0UJll7FYDNcqeA3UbQzXrVf6ZWSP8qmgoZYPIvFAo+WRFhK31TA82zgrG62NgBbKSdHCrX0x9LlUj0Nx2hQcFNU 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: 27 Feb 2024 18:18:30.8926 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd021f1d-c40c-48fb-ba7b-08dc37c080a6 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: SN1PEPF0002BA4D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8176 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. Cc: Gustavo A. R. Silva Cc: Kees Cook Co-developed-by: Petr Machata Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel Reviewed-by: Kees Cook --- include/net/nexthop.h | 18 +++++ include/uapi/linux/nexthop.h | 9 +++ net/ipv4/nexthop.c | 130 ++++++++++++++++++++++++++++++++--- 3 files changed, 149 insertions(+), 8 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 6d5ec1c4bb05..37ed705fcf6d 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, }; @@ -134,6 +138,11 @@ enum { /* u64; number of packets forwarded via the nexthop group entry */ NHA_GROUP_STATS_ENTRY_PACKETS, + /* u64; 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 2e6889245294..ea2fef853337 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -42,7 +42,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_BITFIELD32(NHA_OP_FLAG_DUMP_STATS), + [NHA_OP_FLAGS] = NLA_POLICY_BITFIELD32(NHA_OP_FLAG_DUMP_STATS | + NHA_OP_FLAG_DUMP_HW_STATS), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -54,7 +55,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_BITFIELD32(NHA_OP_FLAG_DUMP_STATS), + [NHA_OP_FLAGS] = NLA_POLICY_BITFIELD32(NHA_OP_FLAG_DUMP_STATS | + NHA_OP_FLAG_DUMP_HW_STATS), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -685,8 +687,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; @@ -698,10 +787,16 @@ 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_u64_64bit(skb, NHA_GROUP_STATS_ENTRY_PACKETS, stats.packets, + nla_put_u64_64bit(skb, NHA_GROUP_STATS_ENTRY_PACKETS, + stats.packets + nhge->packets_hw, NHA_GROUP_STATS_ENTRY_PAD)) goto nla_put_failure; + if (op_flags & NHA_OP_FLAG_DUMP_HW_STATS && + nla_put_u64_64bit(skb, NHA_GROUP_STATS_ENTRY_PACKETS_HW, + nhge->packets_hw, NHA_GROUP_STATS_ENTRY_PAD)) + goto nla_put_failure; + nla_nest_end(skb, nest); return 0; @@ -710,26 +805,45 @@ 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 nla_put_failure; + + 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 hw_stats_update_fail; + + if (nla_put_u32(skb, NHA_HW_STATS_USED, hw_stats_used)) + goto nla_put_failure; + } + 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])) + if (nla_put_nh_group_stats_entry(skb, &nhg->nh_entries[i], + op_flags)) goto nla_put_failure; nla_nest_end(skb, nest); return 0; nla_put_failure: + err = -EMSGSIZE; +hw_stats_update_fail: nla_nest_cancel(skb, nest); - return -EMSGSIZE; + return err; } static int nla_put_nh_group(struct sk_buff *skb, struct nexthop *nh, @@ -766,7 +880,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;