From patchwork Wed Mar 6 12:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584024 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061.outbound.protection.outlook.com [40.107.220.61]) (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 DB96783A17 for ; Wed, 6 Mar 2024 12:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729438; cv=fail; b=lgFr3UB/IduPMah8F/T6NoupjIhZ0zDNdZ5GY2yxxmd9nXt4eM3S2HegHE7+G5wHTT9dXJrPmiA8vkQr2vo+SwsPrqRDZasVhJKLKUd/S35JaqILsPEKfQ88GPpoHEEQRGFP9Qx+rw9BfVt6JLfctWIYAWIkic3zsIbddvOb2v4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729438; c=relaxed/simple; bh=YW+Pw2Q4sNHRqwnJt93AlWVbEKvXM3yNaERMlLYQ6m0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W1gp/uYZ6VwySuVxhvD+ZLUtcaCOsBgrifh6tn4BOJj8cX2/Rkq4BVbtpBxnTl2S55s/eCEqa2uFxW2EqwL1vuyvMoQuCDZG6Z1xsZaq+xNR78+me12DuVGttGKmTsX5b3mwgW8BSUPm3A6j65teSd6GwTgZlTYq+d1/3Z1Uulc= 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=oq+SnjVw; arc=fail smtp.client-ip=40.107.220.61 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="oq+SnjVw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtJ1C52hZy04upQjM92Y1NdphQRrPXaZWhEmH9Vhtw15rLF23iXfdNjmfyoWVgmgzIt9h7TBOnmgoYEb5YZ094H9EJ8gk9Dh7EcLc5daB9MHSML8R3T0l9hDugekLb0FtQVxz2etGADlpvXJu5Oy90sMS6Hcb/wvyUKTEoKA8qnRgBgkFQKHToDrfynY29nkKKU24XeCWy/LqwjTlI1umTiTigsbM2gg4DeJjoYwqfriO9zcBLsVV3MKqdWNQQIPd/qR3ZYFOwP6eVhyBQpUoe9VKKIXTo8sQ6yOmxASGO/nk73d5jGMu9eCobJ1cuaBtYsVH0EMfwIpZalBr1fUdA== 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=6KNiW8V5gDSRXmkjYBaDWvZMRhOtGOAMQSTMicQAHGQ=; b=DeX7p2h0OqAq9h6pOEnrPfGhknf+gajs0SzGIt42YTNF+INZbHG//Z/P1jG0dKoC6DXmk8CDot7IY8FxY7xXqJqdoVWQ3hlMS9t/7y5/YdOxnifQMSPFthL0Bllef7x9zPb5eoUxo/GLaFjQ5Fntb1bHLCIuXlLgy7nt46iHlqxUuIAcJcJwSNBk8ygX4xOyxEYUWmnIIZeUQbbvqPV4+ygiOhIGf0AD5oYCBZLWlVN/gkRXgi8tbZkcrF9QXkyppzmT9+K0pUgrNMb6pvYn54c/+/d75YwavWBFCP5xK5yDaWatYt4WjtuoWC7AJFrRTeJDOmYatKjjeqT34rRcQA== 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=6KNiW8V5gDSRXmkjYBaDWvZMRhOtGOAMQSTMicQAHGQ=; b=oq+SnjVw+UoZ77+fGeJiMLr/XOHOmSUHxk3A5sAEXpIwGcEiXi0YvhB6hxW9NUTQCp6SxdW2+AUkiCUBkuDq5rcSw6kNlaHc8LzfwMcg03BeSHAQUEtZHUPy5eLKvEiPtZ7OAvQk8j/qtZJ4b0XJedq1ZO+ONXF5YLZChkB3fZ16n8FaiJvYjmbyqgDfU1ZU4uevZvDcB4InOar19ytorqDeDgrscOeUG8fKZtCEkPMummUPV7DVMD3csy4WAwxUurM5Wjyv42G5ScgTrS1hlxPJpPseTuqLXC4IlsMLxeyZNQQxRWIx3QSLXFHaVn9SXlDG6oEIcKdLD2DBpmqVIg== Received: from BYAPR05CA0043.namprd05.prod.outlook.com (2603:10b6:a03:74::20) by PH0PR12MB7095.namprd12.prod.outlook.com (2603:10b6:510:21d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Wed, 6 Mar 2024 12:50:34 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:a03:74:cafe::b5) by BYAPR05CA0043.outlook.office365.com (2603:10b6:a03:74::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.6 via Frontend Transport; Wed, 6 Mar 2024 12:50:33 +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 MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:50:33 +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; Wed, 6 Mar 2024 04:50:08 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:03 -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 v4 1/7] net: nexthop: Adjust netlink policy parsing for a new attribute Date: Wed, 6 Mar 2024 13:49:15 +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: MWH0EPF000A672E:EE_|PH0PR12MB7095:EE_ X-MS-Office365-Filtering-Correlation-Id: 057b31f9-c1dd-48d6-900b-08dc3ddc0315 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ieIG19YpSPZZRAg+uZK7ofVVr+pvb1fa/68D7h9EW+DwqWEL6wNQax7H9poj75QiM4jKSfG1LVU8s/bCN61qBzqitDjNQULyBdpHTcby+ZhlYSdSoUk3v3DH9ZnZpy+fvKkGW9g19ZP8x2QxHHI8yhCQcG8sxJFzqjlcldQpAMZp5bENPXFzsSqY8jxzbWzVXl3TZZs1YyCiwZlMkoTPnjVsT/2EPgydGLhlNHR7h9JulFxkR6JWGzyjyXo49DWOTTjgYwK6AGRgSElkOGBdejPTrYiAY4v6HZ0v1L79b/P//Mr1qL64VzYQSdMAkmQDl98DB9phDqch6s8QwmtWdw3ITrwPja5Emh7RXl9BXXXQ8ROAcfPE2hK30VrVYUwv7KnLRYUunk0OksgoYK1BaVA7p4rAtcYK6+SSXYB3350BwYWUKv4UBw7T3kNHRXWioLwwQfYKJ5xk6Qoi2VAtGQ0ijjNQYtvY8TyJ44OeZ80LnwS9N/ZbgehLSxwrLPop5H4MugHAXQe7203lFWxX5AYgutax+47kfr7X/QDUZmINSYX72tHmcSK627nTLkUdDOasF/9wVE+YG5+zsm2eRv3M0G7cOSxZrYtBNsBFxMDL30F5jBD0k48zqypGA3RfjQc515F2yBsfbocP745LaauHsvwXySCg1G0gdZSRbB8DwObz73dSNZOM2lueZl0Cy2usPfpHbLPbzghDgWcGDdPnEaP/Jr5m3WAKxa1hWbK1Q/LNLaOoEybkjIXSRBpX 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)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:50:33.2674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 057b31f9-c1dd-48d6-900b-08dc3ddc0315 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: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7095 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 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 Wed Mar 6 12:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584025 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2063.outbound.protection.outlook.com [40.107.212.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 7F57383A17 for ; Wed, 6 Mar 2024 12:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729444; cv=fail; b=j/xA5AWHd5PDlx/IMUX81IeE1/a37mrduEQbB0t3/IBeqUHS2RVFipsImtLP0svU6473Y6YaqKfhHa4k2NmS7Cv74SIYEqmhI3Kff3HiTUOxsq29qSuNI5Nv7EC6KDCA2r+6Nu5aPFDjHi87YgMvCBH86NinOkVXFN0Wop3KtcI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729444; c=relaxed/simple; bh=gcEmvWJ2xAUpDohudtnhK2ACZt2MuDJkso9bJq/qQlw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P3oOoTgCvaGKWQBfY6rC0pza5OMHVVxFBzxTVks/x+8Dbxce7GEJJjXLu1zU6npYUV97UE0epI+2f5Xv7e4oIunTETx0mxkVNZyRd5aDfVBOGM31QCaDgaEQgpdJfd6i1aT0mK1vtiRfziluOzU33juwAIXYJWRGp7TxJ2S9Y18= 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=OE1B/9PU; arc=fail smtp.client-ip=40.107.212.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="OE1B/9PU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bK0hzIaILTnNxVxDKOOTXBO9sP3V8pE3EQhX0FMu1y24gqVxGbAcNSsvsFc7tsTY9z36AtQF36C3M5HQwpq/59gosKej90V38bMfAZPd9gsDvFBxxGoaC0h06AGOxx6gNxB15N6JYIWdbRFrmb/sGyp8pznsfN9tu8od7WYWxHtOqkzkZTinulVWwSN6KNSqKn4WSApGuAK2g4EG4WjqX354Ym8duOICuQzvbK7a6oWI3WvviQF/Il3iYVHHLrxlixvYII8MTXdI02T8lddOosO+T7wElaiNEjJnC9UMapBmF6BCs61annNNYA3eyQQmTdvU7bc1Z7eHyaA+NTVOZA== 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=aA/BOFop/K5jDNnT0tp8gmgLmajuWgwyaGXlsQNcwWQ=; b=lhMggf9TPtv+bTteuRiFSg9qIaiUSS2+Aj3btxToFY9NfvB7x21rqmDAj+ki2H8pyBEaPwDRIgUzCijbDBkHOyDokjHe+LA3j7tstIkN88fWVDMWdHNybEy4QvXmiZmMHkNhDgPz4IHKDaBMxCI8iDWsuvBlD0wB7HTXTS4X/FS+zoYX2nxZHxsXhVgN1na3z4zJ+DZ3PXqjeUodtIbuEmOYLnrBZWHQF/4wwfbTDM8ZdiJGjaaKMKv3KD8kZPKACzqM8HGlDjdRHazKQYNymJc23TftZjWdkwQJO0Xbjo/FFTcc2nr0PSIZPXhXvvQ+5hUlpMRwEZbqgtC/PLkExw== 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=aA/BOFop/K5jDNnT0tp8gmgLmajuWgwyaGXlsQNcwWQ=; b=OE1B/9PUtB2HreGJwmED/03SA8RcMJQekIwwYUgUhIyVZ2RLNj7WVEy4g7Z63dAZfb+FXeszsmho4OdYR8JIxTt819tEcc7OBmNNa4vNaceQolpSDwvCE5N+dDTi8FgWUboChrA7Axc55DLYwJUPtSLz1cfNQAKguoQCy/AUByE3aH+G4bgTxAg9/Z9Mg8Blc7iz/NeCQCbuT39Itf4Nes1D/1pHcJipS+/viodvneDGXFgG80TZq2w0PCURysV9SN61NNt6WYuvRV7prdcPZ1wWx3rZ03o2aWEBG+gDj0tMCkio4huf801z6g7KlKRRGswUtt0X6WHDmgJhPDGKUA== Received: from MW4PR03CA0220.namprd03.prod.outlook.com (2603:10b6:303:b9::15) by DS0PR12MB8502.namprd12.prod.outlook.com (2603:10b6:8:15b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Wed, 6 Mar 2024 12:50:39 +0000 Received: from MWH0EPF000A6732.namprd04.prod.outlook.com (2603:10b6:303:b9:cafe::81) by MW4PR03CA0220.outlook.office365.com (2603:10b6:303:b9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26 via Frontend Transport; Wed, 6 Mar 2024 12:50:39 +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 MWH0EPF000A6732.mail.protection.outlook.com (10.167.249.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:50:39 +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; Wed, 6 Mar 2024 04:50:13 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:08 -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 v4 2/7] net: nexthop: Add NHA_OP_FLAGS Date: Wed, 6 Mar 2024 13:49:16 +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: MWH0EPF000A6732:EE_|DS0PR12MB8502:EE_ X-MS-Office365-Filtering-Correlation-Id: 05d69c0a-4924-4547-4007-08dc3ddc069f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SYxfuVnqPOnTEkCSp3D2Fq89TD2k2fRcQq3dWJypsjjAVig8z56Wizr2ym1rIDThiiLhFsJEFm4/4fTQGnCnUaD1XfgwAKmWd5oSSlavlKBcnyrAXcKZLWXqBv1e70utLT1lCQ0T6kGApvJ23S5EiZJkAnnDEHBrHg9bVoDfXQzOqRjAI08UUyE5aCH8/yV++noFyUTb3RECn7OUk1FRwr3fp0QIcU/8KxwqSX0pIW9SNwUBAsuFdr94mqOVv+Te4YcfSv+VLs/H+Oy2WA8JRHBx0L6r/P1b4Oudw7/hAS2bxFjup0LCnnJeu7sNiJb/iyPbYLKHIZfelUatwBd6/IUjbM/8xQ04Y2r/vr1k9Volo+XqAogV0+Sz2gh0hwE3ioanFaz0ZtKRt2xT6L/uuN/SEb+3PRg89OrdbJKCJ51KJLo5BzVmVN3Rqj8+hjVuu1ImgODdFn40z9qV0YOZSFJXyPFebHbgHk7FO3SPftYu/1aU0OSdiNFHv7SpG+zflSbV6okFN/a/gZXqeuVukOXLoP4ssbnkiyzXTX1mrWUbAp6NlJIRYfhIkmPOMeqUj8j4/lVtgUpH9Wb1GWjhuHNCjUpzkx9CNDuqsgf4XbfLHFX+xCZAqcZcva0tS07CRigmgdqroEfku3H/h2wWulR/avmYbZrcgrBrft//9lSxM7EjUTQzdH+5b9Dyl6yJDPvTvBne9JVGi23sxJyFO2le0YqfRzmYTVQgwx/psP7DAfU2/7eJy89cLhQd0fsa 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)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:50:39.2029 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05d69c0a-4924-4547-4007-08dc3ddc069f 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: MWH0EPF000A6732.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8502 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 Reviewed-by: Ido Schimmel --- Notes: v4: - s/nla_get_bitfield32/nla_get_u32/ in __nh_valid_dump_req(). Not sure how this crept back in, it was correct in v2 :-/ 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..576981f4ca49 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 Wed Mar 6 12:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584026 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2067.outbound.protection.outlook.com [40.107.220.67]) (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 AB76C12C53E for ; Wed, 6 Mar 2024 12:50:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729446; cv=fail; b=Akxicl5TgbdfAQ26McjYs9fA1CzU8P/cPigJa2yCw1mzw1yLcXLeZoshXYyWZT1kreOkXIX7Q1WT88K+AIvSOg67woH2kd6Pqgb1GAi418X0Nb1ynQ/3EueQY37mQi/fkqNDo2J7hvN0cXS8nyqX/cLYLW4pj5zEJxru64oB48k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729446; c=relaxed/simple; bh=rF2k8iez4zNo5D1ysII2kXAYyb+hrVdW4Gj3QYLEGCQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nkChPHehuIcSPi1Bj4hgEwRAO2OzqBLO/xontuD29oLarBEe8e8sZatFHSkIWW80ajSonGUQasCXSGqNFhX6u4qU2eu7kbFWxvJQWaPWj3pPPIq7lItL9naUGKyjiiSGrxea+DRKATf2e25Apx0PSSiALD5xA6mCMekdDgsnevw= 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=mIHAFs5c; arc=fail smtp.client-ip=40.107.220.67 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="mIHAFs5c" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GOm6CkwAYLf1vIzrrVhM6E9myrwqJd72gFJpJ2htEtGqypfTq2OwokOnqc0mlt8mweF62+5V+ZloLCXXTDCWIGS3Ag209HiR9pP9HiPMbTvG1jqpofmKnNt9G18NRaprrMYOGVrwP63x5PVfVOV8l7x5ykqVFFtPsvL43B7Xg6ArKAu/gJodVq4Fppi4JGYU9xk+Lnrgr3TGAHYkcAALcQ9gX8lfg4fzQCBzD0rHYz+Zmhg1Zqp/ELFzoqV+9sy8Co2u/jq/CcUShl3EpuFecn/gm2WhvO9wprE53m2h+SQjkJDVbZSYmy+7LvFjicqDqRhUyj+d51MPOwRFApTN2A== 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=dXWiw2nFCTo7i0ddDdkQ/Q3QrDEBlUmug1FytdtHF/M=; b=d05UbIVHA/Cz6TYcQ7jiCel0S6fdOAHA0Le2gmAKygf/v8nCs7IOVyw2Swij+eI3krHaIfjRkaXXhudqQOWpeIG5jd2fYLJiN4my+io174nL6eD6QsMZuDjalVqmy5tk2tZl4f2/fjI4h3VWcYFavE9pmV5kuCEf0oTOqvA78mIfnP05dJuDw+/xBx7Qi2xm3kG9/aLR8ytUA0R3U2UXQwsrO5gqQA31CvxfFeQFlDtWG/srDpqGNBsUEIgi8DrLT7Jy6/1rT2EnylZsrMmGPQcFvLkVfJ7oWcR10yR1rFw7mcQnCT2FGd8EW8FTZaRlOc2SsG+skIM+6u3TpjbKfw== 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=dXWiw2nFCTo7i0ddDdkQ/Q3QrDEBlUmug1FytdtHF/M=; b=mIHAFs5cY0bELmBwVau1iX3LY3e49+ViFhagw63OOn4pIqH4tpSj3J8C2Qh/sMg8/STiKkEhAbj4CHi8FXQxXKWIf7sf0AgcGaLhTBNF+d5uhx4WwmaRTcJ3jcAklMk5IWTzmWv118Z7AqHd+7l5C1vdDY4++fOhGsT5ZFwZOSYkpvQObjLXcDEIny+h8kEgSkoDjkxCFMw6UZPLy2t8Tk03YrrlT9AjCcux00GpHnFwOLsAEbISvOlZs6PH9Z3MIRbA/ejGhMa+XxfjFv353OwHQg+3b865jbHLDHD03Y40OiDVUSklU267wnQENO07248TJtwcTnxHulrIaoQgsA== Received: from SA9PR13CA0153.namprd13.prod.outlook.com (2603:10b6:806:28::8) by IA0PR12MB7749.namprd12.prod.outlook.com (2603:10b6:208:432::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24; Wed, 6 Mar 2024 12:50:40 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:28:cafe::2f) by SA9PR13CA0153.outlook.office365.com (2603:10b6:806:28::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.6 via Frontend Transport; Wed, 6 Mar 2024 12:50:40 +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 SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:50:39 +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; Wed, 6 Mar 2024 04:50:18 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:13 -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 v4 3/7] net: nexthop: Add nexthop group entry stats Date: Wed, 6 Mar 2024 13:49:17 +0100 Message-ID: <0bb4e222c10fb1d2a84666a8b2b0725ef25d1fff.1709727981.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: SA2PEPF00001509:EE_|IA0PR12MB7749:EE_ X-MS-Office365-Filtering-Correlation-Id: 271c99ad-7b61-41e4-15c2-08dc3ddc06f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sgSKXFyAPibjkdA5XeIadW4XhtP15MSzDr5MKTHUgFYLniV29BjVP0S3pZaj9lGQ/YbLaD6+9CVM32njqxFJHQ3czW74qwG8i3cXQ/mY3/SLF2uiTWx9JjqrY81glQAsLrto5n0ivsVQLN10GgOM0rfxaQfMw22Ep3AEqyRMphh4a8K6EFlkaK9nmiGAXEVma+d04nECZsplKS0KYf4qYFgRvAfWtkzElZqn0FhnMqhnB4NL7zG5pCHeDBtSlCkefM8YtJumbE8+5xllmEHxd9ZEzjUhX3Mo7qFoDnUtVnMQVYFZlHXyyq0cAeNPVdzwMLcSUeUinWDZsQQ6y6yweqJn3uDiY3ReqUndavx34VLZcfowYGePDVTUrHadblgDC8cMzLeN/qpPwdQMj/Utl5zKbW08AQhLkf1OXZ8QV58w7LBoXf2sQBtncOnpplDdCAv8as4S/bVT0+Y00Nkv2yz6/B5vUsAGMwTvDL92oEzF7Oagz/p9GEUPhDnOzBKur1C3F4WZLgbxezX6hRAUx1jk0YDO8sz5ehblCqnwNxBI7kh8bzpHyMxXgWO8kEoxh7RMkx27/LdXhLtq24dEubRfue1UVuaaaERNpMwd+HlGGOlrmFg9k1A1gZX45KOi5OT0yD+K//Y0xEScTJdYDKMXXZ7tBsRw8W2gF9Sr0G+PcC/ctoEIay/2wbvIWfeyHn7JUxAKAws9S32DmMNcYssfyUkAU8oG3s22zTubTuOaacI2LJrN2vNEDtUOBVsm 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)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:50:39.7342 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 271c99ad-7b61-41e4-15c2-08dc3ddc06f5 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: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7749 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 */ }; Co-developed-by: Petr Machata Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- Notes: v3: - Convert to u64_stats_t v2: - Set err on nexthop_create_group() error path include/net/nexthop.h | 6 ++++++ net/ipv4/nexthop.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 77e99cba60ad..6e6a36fee51e 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_stats_t 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 576981f4ca49..92dc21a231f8 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); } @@ -660,6 +661,16 @@ static int nla_put_nh_group_res(struct sk_buff *skb, struct nh_group *nhg) return -EMSGSIZE; } +static void nh_grp_entry_stats_inc(struct nh_grp_entry *nhge) +{ + struct nh_grp_entry_stats *cpu_stats; + + cpu_stats = this_cpu_ptr(nhge->stats); + u64_stats_update_begin(&cpu_stats->syncp); + u64_stats_inc(&cpu_stats->packets); + u64_stats_update_end(&cpu_stats->syncp); +} + static int nla_put_nh_group(struct sk_buff *skb, struct nh_group *nhg) { struct nexthop_grp *p; @@ -1182,6 +1193,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) if (hash > atomic_read(&nhge->hthr.upper_bound)) continue; + nh_grp_entry_stats_inc(nhge); return nhge->nh; } @@ -1191,7 +1203,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 +1218,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; + nh_grp_entry_stats_inc(nhge); return nhge->nh; } - return rc ? : nhg->nh_entries[0].nh; + if (!nhge0) + nhge0 = &nhg->nh_entries[0]; + nh_grp_entry_stats_inc(nhge0); + return nhge0->nh; } static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash) @@ -1231,6 +1247,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); + nh_grp_entry_stats_inc(nhge); return nhge->nh; } @@ -1804,6 +1821,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 +1837,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 +2502,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 +2548,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 Wed Mar 6 12:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584028 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) (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 D431B8665F for ; Wed, 6 Mar 2024 12:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729456; cv=fail; b=ScEwnNya+iUZTyQ9hwzp0FInFWnEO4B9+Mc9URufM3CJWhU/2TY6HvBwpXlYhPEpfkxfzLY7BPplPFzAuEgo3nT0kCTpELvl+Q0SKoprQCYJHPwEobwDtuqMPTxA4OrntjFdGCP22lvQ/gSMfJGxbgQItMqj45AOWQHmemo6+OA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729456; c=relaxed/simple; bh=Pl9tCdmkaosM7DI6O6UlSVaZgcAAL6Ss0n3KRGiuSlc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LNlHyz/dmu8u02oPR/Nj4lJRqS5dBxtXmGS5TgJ7jqNBeboOncsiUhkiQu0naL8osN03/Jja8Zb2EvpOmnmvS7sDPyboAIo97x30+G9SzvMyrixDYGhau+tQUN1JhatMvT95AhaUryzYVpuXths4yTDANbFbr0+5JDl6l4Zbuwk= 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=rbWD/JwS; arc=fail smtp.client-ip=40.107.243.71 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="rbWD/JwS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dl1ea1STFYK4qpwhXFm6QkJqlUWpUSbRpRlrJJHt61JDUPBQApUSfyAuwUqiWRnL8M2xwJ67DwVXKR4FT+ed50gSbzLFNyH9fNCOlVej8jyKtfaTXAfnwSSaw7GdMJ7SemTGQMq8fsjkfZEaLB0LJ9FU8qwcX9W4c1Y3Cd5gDRN1kzL+O1xrohq37rRGAQzz+odlE0JM+ODt8yYuE0NBP+jaedw1poNYZgJbXRIEYZ5I/+qZYCDVdNwIEibf6kopfjFHqrQhZu92r81J/bPAVGhLWTVGLKUQM3QPtb81L1l4Sz8wuVOc3Zog7/xvjsGhEnaGkFfoxRlIqiCRVoDO1Q== 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=l6LnKlRwNe2MUGfiiGO3H4Y9s4ycf4tmRF16GbiTPwA=; b=KyH/jxxHvhugntSqT7/ddXREPaacr8cnkiV0cJhbJIULGtFZViefzhMgHySxmVQx9bxuZ8kUbB5LaSthds/cjwzZMRaSdmS5n0kwcAsafzjtWOG+PAiVs0W3WihElAr2CQoJQO12Bak99l5pk2HkHqSwqKpOL0anyWQKfAtiYiNQ/NS1oGaOv5Cnf8vXKzCB1r2hgmzw4Gm5iYKnzlXpVdzNfbaC7npTla+xQLFBW5fSc6rHs77GIDgI2D4NBhKzMPPZxvylI6QRCQHrZolcBA46j2rXXNxZ5cH0m3vXdiwlXxidFVsDU5hKV/iZMFa7mV8saxF6t1Fj4Sr4V8fofg== 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=l6LnKlRwNe2MUGfiiGO3H4Y9s4ycf4tmRF16GbiTPwA=; b=rbWD/JwSVMvZbemZQQTXucZz5MaexWyRFVR5v55PexfPB0aFiWlknVFCEOzy/kI+yZb2KFz036/MQIYE1i637sWuSLN0U2NujkGogEcvB+4rqDvU1GdgKjQ3AFMCRf1Fl76+bKX4exY2c8s2Mqt4qzz1AeYmmjI7bvJCUrEQSzSWONNuSAa2bHqeqNM055c37XhyQJJmUgfbBPt85j83IFpE0Huvj2KwtEwTnCgmYoSvWLI2aMRu1feTk/g27srNx19Jk4RaN6w0tl7C0VGM6VrEHYN5h2EGyCtW/YfmJwDBduKfKiHACRfMYGnQ1QNgI5cqAqd9pZvw9v0riXu53w== Received: from PR3P251CA0021.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:b5::20) by DS0PR12MB8366.namprd12.prod.outlook.com (2603:10b6:8:f9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Wed, 6 Mar 2024 12:50:51 +0000 Received: from SA2PEPF00001508.namprd04.prod.outlook.com (2603:10a6:102:b5:cafe::1f) by PR3P251CA0021.outlook.office365.com (2603:10a6:102:b5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39 via Frontend Transport; Wed, 6 Mar 2024 12:50:48 +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 SA2PEPF00001508.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:50:47 +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; Wed, 6 Mar 2024 04:50:23 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:18 -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 v4 4/7] net: nexthop: Expose nexthop group stats to user space Date: Wed, 6 Mar 2024 13:49:18 +0100 Message-ID: <2a2acab9177e68b53c45dde1a28a7436cbc41f5a.1709727981.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: SA2PEPF00001508:EE_|DS0PR12MB8366:EE_ X-MS-Office365-Filtering-Correlation-Id: 446d682a-d659-4b82-5621-08dc3ddc0be1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WbUbeOjWVS/Kid4+8JgYOU1Ntz9gob00GBQtXQTjREHOXxU5EC44MCO+2DQuQfaZaehTQsoweBsEmXS82dl9Jhty89maEUYrAFJ8HCcdU35UmqTS7yxktSEAvZ03s1V0NY/eUReN4nv43m7BsxtrTQNuY0r3hp+A4bwNNl2i98cER24Gj10LejKALFj9S0AdAltnYxezQKw1vnbSTCHmoK2+JY9UtRQ4x4rU521ZfyVCU2ujr1tws1N/YKn2+0HmjzbZwqVDfdDtOyPbeQG+SjieWJvvGO7WcGYxlPj7L0TaGxfeHSF18kqDylmJdT96jx3UFyBzkLCdJzZ80vz9w+A+J5etTkWuyjr9V0jIFckYeWlzyynYa3r8EigJ+ycRdCv9RlEfknjMk/Xpe3sDQ3lYkQnCa8pLiXLGFEhkHHfcw941/0LnXDOBmvU12gLZDWVs8bzcbbxaOyShYZoD9dn7cv2ncEE6lLMi+MEmX5t432uscre6GeuCMdAOnWPr3Xis9KJhPnLdwcW3amhGP7mmM2q3NRTx53k8ewGAu6eX0EBJgGypbJccKgVI4D5TmYr972vB8P/F6nDgpI9yGsckdBhjIIhiemkMqWEJ8wQ2CUb0EX1E+HB9wleXG3JdjTYwn2AfjRmInvr34/rwmxLAhFiHD2z3C7MUn6V51WuA0W36bJdzySSMy9Mj19Smgqv8x5Vt9qLLT2d+jU1tAqAYOPtGtPZkVnRX2fC5uNMIqww+XLyg5RfOFQV35Njx 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)(376005)(36860700004)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:50:47.9778 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 446d682a-d659-4b82-5621-08dc3ddc0be1 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: SA2PEPF00001508.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8366 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 --- Notes: v3: - Give a symbolic name to the set of all valid dump flags for the NHA_OP_FLAGS attribute. - Convert to u64_stats_t 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 | 95 +++++++++++++++++++++++++++++++++--- 2 files changed, 117 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 92dc21a231f8..3365c41eee9a 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -26,6 +26,8 @@ static void remove_nexthop(struct net *net, struct nexthop *nh, #define NH_DEV_HASHBITS 8 #define NH_DEV_HASHSIZE (1U << NH_DEV_HASHBITS) +#define NHA_OP_FLAGS_DUMP_ALL (NHA_OP_FLAG_DUMP_STATS) + static const struct nla_policy rtm_nh_policy_new[] = { [NHA_ID] = { .type = NLA_U32 }, [NHA_GROUP] = { .type = NLA_BINARY }, @@ -41,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, 0), + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, + NHA_OP_FLAGS_DUMP_ALL), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -53,7 +56,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_FLAGS_DUMP_ALL), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -671,8 +675,78 @@ static void nh_grp_entry_stats_inc(struct nh_grp_entry *nhge) u64_stats_update_end(&cpu_stats->syncp); } -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, + u64 *ret_packets) { + int i; + + *ret_packets = 0; + + 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 = u64_stats_read(&cpu_stats->packets); + } while (u64_stats_fetch_retry(&cpu_stats->syncp, start)); + + *ret_packets += packets; + } +} + +static int nla_put_nh_group_stats_entry(struct sk_buff *skb, + struct nh_grp_entry *nhge) +{ + struct nlattr *nest; + u64 packets; + + nh_grp_entry_stats_read(nhge, &packets); + + 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, 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; @@ -701,6 +775,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: @@ -708,7 +786,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; @@ -735,7 +814,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; } @@ -866,7 +945,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); @@ -3095,7 +3174,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; @@ -3265,7 +3344,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 Wed Mar 6 12:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584027 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2053.outbound.protection.outlook.com [40.107.244.53]) (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 8105C604A7 for ; Wed, 6 Mar 2024 12:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729455; cv=fail; b=K/lxJRubUXdUVLWfFFqK3WD8Oe7VnvFRXxFQsSeke7GAGIz9MEMpUnksfrQryNM+sN3IpciJUiAuqYHEwjDZXyCM34ntQaCfnOig1wdzbDRKpjeS8ROTpTFFed//1oLzqUHdpG4zyaFOQmN5OduVxxqlbv+UKsyq5IqE/QObfXg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729455; c=relaxed/simple; bh=9SkaErDpWDYqsZMglQl0Kda5QemHo8mRnHiqxYteHBc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kGXMvta1HFJlqOiraJlAh5ZtZgKGYXNSk53ZVTnQok6DssZl0OP91n/AwGu9CXHY8sZnajN+JiFjEel6GUJwMawrLRQh59DLlvaKr6M6N9XfGUijNqetqVUkrRQAtEwaSVYQS+q6DLOX62J13hqslue09I8A+JPrv8zFT7HQAHE= 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=l/t3Yxut; arc=fail smtp.client-ip=40.107.244.53 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="l/t3Yxut" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DNR6B559xcED3ckWNDUoesqaocx8N/JfXeWKnH7jcRDBl4JRTGYW1YzD+5TkBxxNcV9tFxc33+KVIFOT6FRjQHg+NnhkfCIx4sVfSoZleyHVleBk1/2GxOD5bfZBxubMPZRkN6zGDFSwbdNunYDI1hRMPr1o61CxTbWPRI4VMyC032xkQYQXt8YK0mz0cu5uOERRze68lqDc4PsLO6kIGAOcKpJ7Z/EAJLJzM+1URCGTY6DCp2zLYah3abMboqrvLqo6x1Zh9MnTpjjcA5nb6YY+/u1bdlX5BexapbrA+aknAUl0EZYK4Blj1uBWPOo2b6S+0TfXI+yo/txO2sODBg== 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=nw+sJLXBem5bwAFtxWPhmXemlktfcLhpEH53vRfdOaI=; b=SvaelNN4rziufJJP5MvrK/NaaJ8FUSDqKhO2PaC0CuUhodLBJmBdx3co6OoevHKFbpo4pGDlQMUK3WxWJGNP/A84m8spCN9n26RIOX9oTdyNrXPI2kM7UXZziwL2ZFPJWL3cJxisS/4hN+hkBBe9bJ0UB1Kt/dT/NT3eqvqcH2TL1uN7cebuqX8jTdXw5D34AIoomXc4pOMOumcjLMwMPpKm9WvMP5AZSyyNXDDUxVBvD/KZLBUW7FXPDpTk7h8ZcQyu1TZ7KkEuKl6dp/F4b3Frdqa8dTMPYqfkXl3wJHrNF3JT82qwR719YYDhy6aZq9zvI5/yvvy2mnvJrGiQUQ== 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=nw+sJLXBem5bwAFtxWPhmXemlktfcLhpEH53vRfdOaI=; b=l/t3YxutlZ6rErQvbqtwSdGIv/C4KSTrHHpx05EQ5bxPkqsR9ZlyMR13iE9y0EpgMugHdwunEMkxzybqTkrjMl2LX1VFNFLGAMqJ3HrbdOoN+33uu3wxnol+AM5NgR6aVb0dYejI7IZDIArjNTnopcflkoAW2LFrOsmp67W2aRwKet0RKS85rCHwXeJERmnN67dJexnmP4Untt6t9TqfNXGxbqvzDHvWKEWFmt0BA1FeoYrYpSEJ/jo+zXo+UK1p0O/f5osTUya99O+xLhoQHqvR9Nd8ipx/QrZhlBTSP0vGCihuuIOyH56zK50Oub0BfXuMzU+KFniNGxpN8lBEbw== Received: from SA9PR13CA0179.namprd13.prod.outlook.com (2603:10b6:806:28::34) by CH3PR12MB8912.namprd12.prod.outlook.com (2603:10b6:610:169::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Wed, 6 Mar 2024 12:50:51 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:28:cafe::c5) by SA9PR13CA0179.outlook.office365.com (2603:10b6:806:28::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26 via Frontend Transport; Wed, 6 Mar 2024 12:50:50 +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 SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:50:50 +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; Wed, 6 Mar 2024 04:50:29 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:24 -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 v4 5/7] net: nexthop: Add hardware statistics notifications Date: Wed, 6 Mar 2024 13:49:19 +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: SA2PEPF00001509:EE_|CH3PR12MB8912:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e428847-6807-4553-bb0c-08dc3ddc0d6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nLHooKKdJejg0E4vV+bVOtrDWOETHjQW6IC1vvg3A9rSnHCsQNZaGLP/PQtpPzZZzvwSDpiPl+Kk6ac1bgki1wcY5ebFtpwfxW/SiIsFcTkaQq8bEpLGIysrDklolzV5i/ogKlrgnzseOsq/gOiuipruhw3l7XuZ+0F4t2j9BIKI7C/x6gc6uCEn/Mw5ayag6/IgzcrT4aG8PG0G+FgD73TEzjMVJ3W3y8d0o76EadpRSwAUudvVB1B5ALNbLjHdYLfJOfVxqhG37hPc5rPzqGhmKVsr3/c3SYY/jtqj34pejVAezs9zKMNlAP7f/XkmwLYkn1pc+UpBSgS6ktS4tpjXSQF5RmRIx0IuMxuRCh6lPeYNRYvtkzYcCYbXGUvc12Gfii5GNLBq048BLIelvEK1KgQ+7uiFSENY+ehM/ty2g0kcaBZQD4i09hbuuZxtRHCIlFUbHgNw1AtTKfvSAfodNnJ6P3bGY0XR5JT/80OAK7Dc0LccgDVDVixrHatihUtgHr3DUMwjJJssOYri1acmIpZvyvWthkqsCZeeGFaLnAJtMj5tnwayOb/l1mhanSRPzWEiSq6HY5wt8t38igF5oWYB9BB+JFH4GWCXSMUv5WrVd4KFh/KRuXRsIemZRaLwYzAKT2T5oWjpycij4yJ14S662AKCSf6DkvzdhRHwvQo/AoeYYhZuhxlPaiTJDwc1w1YstPH6/owka5Xh0cNmZcKh4zsCjGSoRWdbaOwNjjKbnUFdpkCpCPiiIyx8 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)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:50:50.5781 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e428847-6807-4553-bb0c-08dc3ddc0d6b 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: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8912 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 Reviewed-by: David Ahern 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 6e6a36fee51e..584c37120c20 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 3365c41eee9a..c0d14e16e9c8 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -141,6 +141,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]; @@ -172,6 +173,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 Wed Mar 6 12:49:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584029 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) (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 B624F12FB28 for ; Wed, 6 Mar 2024 12:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729459; cv=fail; b=d5IphG2j+rPwXHRwTH1Azxv5R1uj0lgdqu2fnQGk9k1+H34NoUOVQDgPkH4IMWQcP6vpR73teaGF2qgH+aMIHQoUoRompkgCy55XglWNZS/+Auskv3zbWc6G5uiH5A0seqLlRIauT2/5ZaXS0rIcxa+5DMXaxDK0FvYC8ZuR2xA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729459; c=relaxed/simple; bh=m57cvvsXQ3XNKIBMR3tho7lD+6N1TRuHvhRv+qRrFU0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lMVa8rUW3DwP6j1BgrjQuS8pOacySKjCHp+VA4OmJhikW049cPAeLrugQu/ktGgE0AP1KuTO/hSbOJ+YpX90p/URynXKi8v+eIzZNZLVtyDi3N1gRlICnsojnKOyYHWK+31pmOAP8q/iTDo0TOEyJ5NI/5VbSuM5pNdwOAzxERo= 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=bYP8m+yG; arc=fail smtp.client-ip=40.107.237.69 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="bYP8m+yG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ce9N3ezY4rO4IcT0SMtJaSV1gkqIks2YEM7qSv4z7JTMibB+CUM/hL34V0/HL+t28Rnc+XaH8VN2SW0t0L0NZ6dSDjfuYi/Mo2NO1rPbe8WEi4oDoh+Qi9iUN+e1lhH4KVRducf4YsPNuLDBcLCJYNH/tFWFfMpIk3LqA4kN3aZNw0J/sEdkXem5Z0oFuUYaRRItvyE2WfAIgAyhmSadNClJF1K+v++iDLxPB4c/Wn3k/aLs4NWyAD/9ADnfIKILGOAeJTwfBUNUgElyV+7JgMXnHF6YfZB2Alh5Q3PdMIzssLMzs9/s2eoEXJCBiaRzp6i9qd4VwT8lW0udRlrHLA== 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=/ujs2KBkREBYwHAN6pLiJH9ozVpdg8TBSZx2yq62eYg=; b=c7dYjs//paNmnP7dqYvOnbKg/wB9+tIdMZxDtIuAoovNWLLy9/geOasMt5Bm5Ca4FUBlRTzLGtZNgXAuq00oGP3X9+JzEJjwkIgJpV6ebCQ9oxnsST9diNgSiRv3mJ/BsO3Px0+AqiaTo0KDhT51f9GjHn+h/LsNDBdGseXJFe8+rmFbVwjOhfSDhqynhJnbsXskIT44O4BI8C5DKdI4oKSxFXEZu7CkQDtZqC1mCKyCpc5PCgp6bkwyNL/0WKXLheSe/C2SEhAgME9yFgrxbIliC7PC0eokVYoig+5YaWvELWoWag9Jo3O4WvK0ViQx7SqPDdBvS3O8GSjTkvi49w== 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=/ujs2KBkREBYwHAN6pLiJH9ozVpdg8TBSZx2yq62eYg=; b=bYP8m+yGpLNQ5QshAhczNydORtclfDEpObLnHbhXX3++27y6RFEXC+x4fKiNaxA52GM0M8V8asB5oA7YlnoZUtc4/9/D6ZuwreJJ+jLdC1JU+MzAkGuQwr4V/WiSZpXliLxEAjWRu6AU5ZONbKClCPbndBFXbgLXZbFPY/NQ3Y37nwlrwk87FyLFvNlOW5ScKlzN7WptBdp984rT+bJ0xQlCu0XDXmmQSu+yiSrTOgVqlAkJD3k14eg1ZRZ2n2Dlq2490Wo3hM3J+a76E4KIpXBvuR/7XUMB2QnSsRyAO42RUFRAUuT5tcvispORd9tuWdmrxi/WHDAhbin2l1x4nw== Received: from SA9PR13CA0158.namprd13.prod.outlook.com (2603:10b6:806:28::13) by DM6PR12MB4468.namprd12.prod.outlook.com (2603:10b6:5:2ac::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.24; Wed, 6 Mar 2024 12:50:54 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:28:cafe::d1) by SA9PR13CA0158.outlook.office365.com (2603:10b6:806:28::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.6 via Frontend Transport; Wed, 6 Mar 2024 12:50:54 +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 SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:50:54 +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; Wed, 6 Mar 2024 04:50:34 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:29 -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 v4 6/7] net: nexthop: Add ability to enable / disable hardware statistics Date: Wed, 6 Mar 2024 13:49:20 +0100 Message-ID: <957be0d4dc6f452bca4a4cb8be348ac705d022a3.1709727981.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: SA2PEPF00001509:EE_|DM6PR12MB4468:EE_ X-MS-Office365-Filtering-Correlation-Id: d03d5ab0-1967-4f35-a46b-08dc3ddc0f7a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IaEuc8ipjYpyUfZ+cDQCKpmFTtYOpQVepGg6hqEoAtP/cklim6T3pEL73ehlpvKqSrNO9n3VeBNhqgA68GSHd3Hs7fIMa+kr3c8Dcl3Aj4i6Th1c4MN+IH58WrRXxjz6L5YjToZ6yd56As4F9c5VwJ4qqvD1KmymDQrbRUw0BjAnuMBQplWShvKGfYI/3GgjLkAbcWk5NEwp70siyioiAR+jHthIH3S5/EJdStKjwnTL7DTKBAqGj44aPfBUGFEq4zdKK9YcmDd0aJEcqFb2LR5mvkhDPCp5a/shTTc6qNFQpFKpDAwRIrhC/t6IYThibvob1lP5iZHOVkp4Zk2LRX9I7TtrcE4wDX9E6AHvka9gd8ebkp3tgfQ/LRS5fvBcplracZTTvlNPGTI6LkCX4+Pp/P1DYQ8rZ8HQbGIDmfla9yce4JyeMWV+JCBGcR/iiTcbviLB4MBToAqufTl02R28cg/UzIzxBUl3wshFk44TiJCOhjuzwzofzqkBJDi3EoCibLHLDSy9jNeOaIWkZNMOokT1A7lc0JpXWV7utQQgM/jxM1F/Y3c2LeyEiSWqKO0Xuz4oM/eNJMwA3eeTT1PmufvOMcLAZ+r4BtVnGf/Eu5+PrOrOjUfdKf0bQk6CM7iZ1JNiI9h/zuP/Wt2wEIgv7AbZIBELdtLGDcZuoz7lbgI6FicYppL8yt2YE+ixOBVfx32Jr01lhGOeHaKNSk2WirtgW/+VmKa0enTmGsahSIOc/Iotf0Y0XBE49lET 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)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:50:54.0156 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d03d5ab0-1967-4f35-a46b-08dc3ddc0f7a 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: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4468 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 Reviewed-by: David Ahern Signed-off-by: Petr Machata --- Notes: v3: - Use a named constant for the NHA_HW_STATS_ENABLE policy. 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 584c37120c20..1ba6d3668518 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 c0d14e16e9c8..e75b1aae5a81 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -39,6 +39,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, true), }; static const struct nla_policy rtm_nh_policy_get[] = { @@ -778,7 +779,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; @@ -1202,6 +1204,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: @@ -2622,6 +2625,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; @@ -2964,6 +2970,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; } @@ -3055,6 +3064,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 Wed Mar 6 12:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13584030 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2073.outbound.protection.outlook.com [40.107.220.73]) (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 197698665F for ; Wed, 6 Mar 2024 12:51:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729483; cv=fail; b=BCuOivJPiFuH9Bphtj+QbIL8kpX33ppM0L9anI7XOvzHCfWVr6AyJ8cNZ68MI+GUMEt2Qh0gOLEzbT5EEYdy816XI0wG7tkLHsAwIJq2+CGI50jmZW/ytLJ0uQTXMHxVv3G7LSS6rj72CGU7PymriCC+nqPg5NuHKBA2YXJl0aE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709729483; c=relaxed/simple; bh=gx3mjC4x7WskcRj7nLTeTYt0xx3R/zmfqX/4inP4pxo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Hu6Et32KMyMSm6Udl6polQvrESmh2DfGoSM26IiimpdE+YN/s6rMcVxQvdMenaSwdQbFJUmuBL4OSg3JoX2UWI37s5BeogcCXVasFQq5XS0AyMwy7nykvPorAZavPio7RXlGgIgKa2v5uVj62OUJ4M7y0HAHeNenlFQ4+T+Yqnc= 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=cKZGtI8U; arc=fail smtp.client-ip=40.107.220.73 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="cKZGtI8U" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iZtrooDlgzZD9Dn3+HgD1yMapH6u8MPOHi+FeDy93npYIG4fbWS69D11k6sxKLW2/SsyhXKncUmQ9zXTFheHWrOgEgygrZjJZqlAw48awDAHDNxPErQ1mBS3EwB+hig3OrdeNo4HCaisSYLcLdFQUyKw2iN4EOFQ0zM7iSX2YzabPBR3X5XXaUZrjjqUv0v0GZgLr9drlP5Zgt1Y8r8f2KOtC9Mu4QzL/+jTUFeK9GZXzkyka5LNXwXCskYmR7plirnu6kt8WzNmolAejUqh1F+A/FxhFsZe0Px7UvADB2G5vBvIAOIheQQXGaOz7MxmdnhRYRFa1trOPsh+2A6+EA== 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=tv0xZTFTn0ndA1P0o2P6qrOU8MF9n9BHSToWb2O9OdE=; b=ALiOtqYLzCacrZGeIrSKNgHA0VLGfNud6r6/OV0u2ZkhndjaiTCSJgrqs8G1H96b7G+Qy7s99OWyFei2z3rSJjKAqyntONugznmc366hvFzbsA3Df4diHTEF3g3X3b3Pep4kTaecrrxQLUM0X1VnUAM5y5Z7cKiyRIJognUKiZzGOtTRBi/IPEqj+1spPabHJaCqei+DU97U7y1/bbfNthQJIbyeSuO75ItbT9VWIB5SGw3LMg9iUEGkkk5KQpTu1j5raKl5mqXliE2sP7CieDtdgGwOBCflcIJfshyk/sw0PIzT/q8hDAsY8w1weDGtyNp9l0axfWQQR3K/4huQoA== 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=tv0xZTFTn0ndA1P0o2P6qrOU8MF9n9BHSToWb2O9OdE=; b=cKZGtI8UJ4gQyoojIE+rD84fjzCygzTBezDnkAS6AWK6zlQxOpK1A7fYM/E0wvUFa5lQKsw6xvH/J9yfZYbCdfg5xdOzzLeK8kXZsTqwk0tyD7bzQ/hsVBdPcCBNpXc3o3Us+JIOPj2VuhZ7mMTViXU75/yxPiENoM5uLeJ51kItbcZp8D46eg3ngAwCSrcNAmKbr0FXfYfvq1nrqYO38s1CmE6mxGNjXk224tPk74OjPfKh+3aQVZ/YgApOyN1DjyGJALYoldJqvHeJOyr/PWgwDh4zEGbzSy6VfAq3EE+kvzoUe1W5ee4sC+ZUPWLMh2u8WOzaMdknL/RKWDzN5g== Received: from MWH0EPF00056D12.namprd21.prod.outlook.com (2603:10b6:30f:fff2:0:1:0:15) by SN7PR12MB8059.namprd12.prod.outlook.com (2603:10b6:806:32b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.41; Wed, 6 Mar 2024 12:51:19 +0000 Received: from MWH0EPF000A6734.namprd04.prod.outlook.com (2a01:111:f403:c91d::) by MWH0EPF00056D12.outlook.office365.com (2603:1036:d20::b) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.3 via Frontend Transport; Wed, 6 Mar 2024 12:51:19 +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 MWH0EPF000A6734.mail.protection.outlook.com (10.167.249.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Wed, 6 Mar 2024 12:51:18 +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; Wed, 6 Mar 2024 04:50:40 -0800 Received: from yaviefel.mtl.com (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; Wed, 6 Mar 2024 04:50:34 -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 v4 7/7] net: nexthop: Expose nexthop group HW stats to user space Date: Wed, 6 Mar 2024 13:49:21 +0100 Message-ID: <32eba1b760d3a09258ff9189d4d6cabdef0f3607.1709727981.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: MWH0EPF000A6734:EE_|SN7PR12MB8059:EE_ X-MS-Office365-Filtering-Correlation-Id: 4237a9aa-2532-4b71-f69a-08dc3ddc1e1c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IE0i8YZE7OgvvnmlxoGkoqfco6QKsGBgKSVDmH9JAug2oaULePhUfCi26jf6BAOY8D+iid1hruccbq6vRshOqV96QPl2Rkbln/UYAsFvAY+Q6IBtffebVhXNtH07iu7NjzuKL2ALuPZEJWOgSYxhOWOp2z+3Ip+sRJDXrig4wfhwiH7/AV3Upd2a8w6CiUrs3PfqpBxY8//+aL/qwzqxIlc9aXwm+DqnQ3gkXJugs8eHgtw0LWvE3RCdpj+56lYX2MySGu+0ulE+uTBIE9fbAXwlK3BNB/XvDONa96c5lcrAEyjwy7thoE33aBuOZNe8hrYqTy6ccMmzq9sVdUC54s7QcyD4whnRkmIn0EyBENy5ygbz+4K5gdYRmn8EVE+JwHflk6YtuXAiJUU/jCib50FinDGXt7jhncV+JFALTRI7IGESkH18qPcy53NJgoQTKDCyvKQDihBGmmC8jdBrFZ0Gd1XA0l+lqW56P1B2XnOq4qppGsvyV5iT0eg7f9iy05O06gGdJ0852tMFoc1CLDNN8in6FSo2HFK74QpR/ABg0HwQtw3Ie724luhgmRrCC4p4FR3H6/UZFrA/QxHVwdJfBsT5XMlon6RQ5lzGWl4uyXYFMzKPjaNdxE0Ob+UwqyrhQZoUvVIoVODaiwHyhHt7U2BXeZ4f6eim56Oq8rJJdb8YpKXf1t31acu/xTf5hZA8iSMM0QczcfbDvmBeHL1k/6cBv+75JrJ5y1wb6g4dZUJVsItwLwHyV3UB2qiF 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)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2024 12:51:18.6144 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4237a9aa-2532-4b71-f69a-08dc3ddc1e1c 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: MWH0EPF000A6734.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8059 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 | 130 ++++++++++++++++++++++++++++++++--- 3 files changed, 149 insertions(+), 8 deletions(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 1ba6d3668518..7ec9cc80f11c 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 e75b1aae5a81..e34466751d7b 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -26,7 +26,8 @@ static void remove_nexthop(struct net *net, struct nexthop *nh, #define NH_DEV_HASHBITS 8 #define NH_DEV_HASHSIZE (1U << NH_DEV_HASHBITS) -#define NHA_OP_FLAGS_DUMP_ALL (NHA_OP_FLAG_DUMP_STATS) +#define NHA_OP_FLAGS_DUMP_ALL (NHA_OP_FLAG_DUMP_STATS | \ + NHA_OP_FLAG_DUMP_HW_STATS) static const struct nla_policy rtm_nh_policy_new[] = { [NHA_ID] = { .type = NLA_U32 }, @@ -700,8 +701,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 nlattr *nest; u64 packets; @@ -713,7 +801,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, packets)) + nla_put_uint(skb, NHA_GROUP_STATS_ENTRY_PACKETS, + 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); @@ -724,18 +818,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); @@ -743,7 +854,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, @@ -780,7 +894,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;