From patchwork Mon Mar 4 20:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13581212 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) (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 1AF9C79C5 for ; Mon, 4 Mar 2024 20:52:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585535; cv=fail; b=OSG/YH1ElQrWn9PcxSpvOk6hm/yppv4MBeyeXR66xQamCEUiI6u+Ms/opFoEnuf9DxFJ0HQvleLNUaV6fw6aGO5Seu6uWJPRlY1RiYLNKsoTn3uXa6dFaNSj/VolN1ecNZ/rknYlUZ5lz7LqRR3TLxyrzHxjh6G6YA/d1SsoeJw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585535; c=relaxed/simple; bh=o83a7sm3Ibbwr9S7qDKmoULgydGq3op1OLmw/eEEdDE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rTqS6+b56Hc6GFucIcWWbBjs9GImriPP2Nc+9sGUYQmsJQvUyyW/nikS0DvLEw/N8Hi4HHVTAlFInf1E9UqH7tf24JrqSfzXi1GeOlCOCDaFbfPnPkAIhe59D4NBONQ9Gicrle/sOp8m0GjT7uoCwluo50JzOsznSxhKwRDt3DY= 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=mp7muv1i; arc=fail smtp.client-ip=40.107.237.88 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="mp7muv1i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YUawjy3/ID2W/uy4B43dS3E7StxinOydPMKS24kKGTQR3Ye8LMhgOXJkmhXD4Kv+EzH+pJfHTC4AfgULdNDOa3vEx+4quAHG4L+mRCbaWCFsygSK8Fypz/amZ5h/fmRmJZtfvRdKiIsFALKhbY80EgzzvkdQOtOxx4bWXs1BZTe59buaqKbiaBCGobe10WU8VYQZeutuQGfI+pUrmGEMpPS2eWUoHhBW3jsXxlBG1K9VanF0MW2XqajGQnZNJcPvYTsrCBdbVY0qc9cE+PmLel1kDxL+4kZzPQfWAmpPVRpddhe/qNEmv7LQVyF4yJkt08NPqSNfVsZHTQQ6zc6IdA== 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=E9kjhm+mRSPWBT1Dsit0wjle+8KfH7MUTyWXfoBnXIk=; b=aChEVTa4CmFL48w4gfZqTmZXhnMDG8bqS0GOp6YuKCvPrnncBHbMa3WuCT6tkUTmenLICWKSm8smg5oVZFfp3Ns8s0nBv8u+FK1DAaYXf3i9EVNdO3r7zX6mdJKTqk5WMfcps0UPEnHJEnaF1Cus6XniCnlDPljkesKJ2OZBEy28cvPJv2HrwoZzoX+pCTuA+uEMPm0wlM3mh27GSfDD2TvXdfbMLLXWJN0BoSc+OBWjVxbD8mUfhIuhylxZX9/R1Ty6IkpfJEoLDbMfivypnSu6/nhWnIgdzlAFd2W/RNP7HKMK5Mg7C2r+6mnTESUUdFb6OmK+8GZesVJ54Icwng== 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=E9kjhm+mRSPWBT1Dsit0wjle+8KfH7MUTyWXfoBnXIk=; b=mp7muv1iuJsnn23Yoc2HC8jU7klhx4AeDdyA7kSz0l2WJcNWxyQK8oPFHM7cRPvqBx6C8TTHrdhhehMjA0b9sxQ1DVrTiQ6HRJQhwjUOWV+1lXtc7Sre65XmJpWna13vepRvjqlAMycEW8+/DL6BatejRCe0n3pp0jgF7wPCBKtPyTqRtlJKu4uPw42e2C25NBr3rd+1O3OFCdQ32P8ZMOfcznusIO04G20LYiIyOWV2qN9f9Lxs1iyw7odpma5MCptaFjtZczC9orTLWt/A2B6AYpVtp+eJMneqdw4We0f10UQKpCK92GAIrpWLCKks/advxW02SjuIbf/zHKBi4A== Received: from BL1PR13CA0367.namprd13.prod.outlook.com (2603:10b6:208:2c0::12) by MW4PR12MB6924.namprd12.prod.outlook.com (2603:10b6:303:207::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 20:52:08 +0000 Received: from BL6PEPF0001AB75.namprd02.prod.outlook.com (2603:10b6:208:2c0:cafe::bb) by BL1PR13CA0367.outlook.office365.com (2603:10b6:208:2c0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.23 via Frontend Transport; Mon, 4 Mar 2024 20:52:08 +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 BL6PEPF0001AB75.mail.protection.outlook.com (10.167.242.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Mon, 4 Mar 2024 20:52:07 +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; Mon, 4 Mar 2024 12:51:52 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:51:48 -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 v3 1/7] net: nexthop: Adjust netlink policy parsing for a new attribute Date: Mon, 4 Mar 2024 21:51:14 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB75:EE_|MW4PR12MB6924:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e414a15-9ae6-46cb-9687-08dc3c8cf4e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H5tO8PnnWR5iuAc6R7m8Zg4/fcDIvGQGzeqcwqMbfnpHVAuXP43rQoeTW1DsKlNGa6i8jOFkwXOO1LQyKm3JKj9sc/LeNNZ5erGLeM6qpayAYRm5kYSEM8ni8MazRLU595JHVE2trVR140KiWyXxICPHhCdz9GnZtsOQ7Kms9Q4Wz+VCEmSV7zyihxNZ3SMZEQ1MlEg0qnyJBLWBT8+niDyPC2Itjgkdm2qeBOg79edBB1nnWAszMC49Y7HPhozoe+yPL97gpOnuapH5qemOAHDVVYnMDPnBwruGSJlnJchUu+WU94aaEE9+1l/4Jwu6ht03NWKqT9k7FX974s3ScPRGQ6wQHuRykaDRvzqJBUjD48qwFUfYEHpIdGwT7RaYjfoKy6YP4kTOsizXonuHzZRO6fUiKpJrEcaK39+xzyQoRhwMHyjKFWa20bUnbRQyL8ZW014EGJQDHhNA3/hHjnzewqlU5m3dSyFxdN2Mi58L8Bv0P9E/SanIAin6Rbdw3w85cNGSKJfcViDvLx1HuvBkLE6N/CbUe5iZqit+NsOrzlM4LC4fSq8zdy40Vs8GQtqF/i1yvQ01RjNrwUYiCTjXYtjgpNybhgHqGKubKA2Kx3wdj0B9yKRwpqMGrW/9Oj5ZshlOaj8WcSv38Il/KjveXTUI+/joMARjYN59XJP4LEPdt82FM97EXjHLh6YAHlV4gp9mPvvOXvgszm10hafPzk+Cta/hVugaKaBaswpNRndS69OjekoX8+n4iFCk 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: 04 Mar 2024 20:52:07.9708 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5e414a15-9ae6-46cb-9687-08dc3c8cf4e8 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: BL6PEPF0001AB75.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6924 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 Mon Mar 4 20:51: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: 13581213 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2072.outbound.protection.outlook.com [40.107.94.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 022EC101C1 for ; Mon, 4 Mar 2024 20:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585537; cv=fail; b=gpUtbVbGy8yOVoppcyUdD9u53FJmW26M/abkqanUB9rGVB9F8hFeoTGjoBcVBMTQmUlWH306ACJSBcfeHDhb3UvsGmrWy4VFlMIyYjzq0np4cMLfHDJYWpz46l6JJD2lTOmQrAVnRI/em7C0q9ltV35LzyByZvlto5B8AbC2SdE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585537; c=relaxed/simple; bh=Ey3eHc3XhgWFhKSGSj04WNITJTf+pqhOkuueOO4/cL4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lZvy8FAuQ9GGYKh+yCk9xMLUVZ4l6USYBIHFbXcnalVK+lGRk/kkM+eRpvMyYmsdAG8hTcJCXdY5oNNzZWn5mj1iL2P7akR2rVCaDPXoa/kEar6YAWTRePfvz/mvNpy4Ti61ttq4LMLhuRhXzetvGWra4EKUSngXxMOo7X3eroQ= 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=qSqAZgoB; arc=fail smtp.client-ip=40.107.94.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="qSqAZgoB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C2NLMH0zKR2m3QvylKQLmdEDP7AMbtCscZmUxKaNDIlwv0zcnW7GJpzFnGutm/XcX0t57LZhJf68D7YWKarbCx33h2e53Z0oFi8YMdU5pidMtuCc/hz6zpMohcCpT1EOR/+4081u7buMl+Jk4NDE53NR3uzp0o+2c4Cw6Ha64/5M2MqbdDqJi4IL82FtD3hBB2aki/xJnXuCZPZU1mpX3Zy3gYBTMEa2SD31iH58oOvog0GKBeZRiY7xLf0kqfkpGIYNILOeiLIyYpnpA8EBnpLUuOEwfOnsA//XOc5GKm1umdAGOjYgVRpKv3jtAT1mPnIb1HpKlDNvPnHg69pJ+Q== 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=NgqXMJMqFi8zGqcDN4D8q9rzy6s2LjxCp5LuxKnw+bg=; b=KmVpI56l4v8ZqMWzzGuH0rPtq4H/7HflhWnUQlEGF9FzYXh0REf17vlQWH+h2Aj7ku/hw3YmnT+xfIwoDientm7IcvM3940eHd3G8HkNuQILPShHY+mgwZVgH0EDEFku1pWWT0CLXoyEDq6dxWOwSZexq7HoBdB/6D03ZFBuLlPwGv9nxPkRruOET4WJrg7SdvKy1UFoOl/zTSF3lgUVgw5wAZYEdymo9ffBdwLXMzykV4KYz/OYSibf5n/RepKY2B0Hb++NA7EuutBVfW0Wo5fvd3NxfkHu7SMfhDczAKBXJK+rBNNVoWXUA4YGIi3dUTQbBN7dBCy5n6vyuE+mlw== 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=NgqXMJMqFi8zGqcDN4D8q9rzy6s2LjxCp5LuxKnw+bg=; b=qSqAZgoBh4Jkx4YbLQKeOT/UNg6uyqJ3td416QuTW52/MasYoj3XyVM4KL9BRMTKmMfjI62e8sgzFWyntBRTREXCI2YunqWbma/X++UfgjOsmz17IkN92iF6u85lAnod+ND+GIJtHTVzqjl9L29oVJmglgsLmVdVw+bXwFNFWjWgeKo4yu0MbdA9FlmCHDbDZGx34T/pqG5Cg+0I+VVfD+TUhcq5/iuwv5xIvdoha5s8OHlqqsxckRFxzozWkeBNAGkYSVp4dy9mvG9FqbL0Kwq8AlawKxgFTC5sxoJQmHvoVIfpCZyNXd1Nnr909iZ+cfpAK/bLkOe7SI7KyiFTsg== Received: from DS7PR03CA0248.namprd03.prod.outlook.com (2603:10b6:5:3b3::13) by SJ1PR12MB6267.namprd12.prod.outlook.com (2603:10b6:a03:456::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 20:52:12 +0000 Received: from DS2PEPF0000343E.namprd02.prod.outlook.com (2603:10b6:5:3b3:cafe::55) by DS7PR03CA0248.outlook.office365.com (2603:10b6:5:3b3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38 via Frontend Transport; Mon, 4 Mar 2024 20:52:11 +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 DS2PEPF0000343E.mail.protection.outlook.com (10.167.18.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; Mon, 4 Mar 2024 20:52:11 +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; Mon, 4 Mar 2024 12:51:57 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:51:52 -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 v3 2/7] net: nexthop: Add NHA_OP_FLAGS Date: Mon, 4 Mar 2024 21:51:15 +0100 Message-ID: <46fd3a32ea411c65a66193b7e25833ecf8141326.1709560395.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343E:EE_|SJ1PR12MB6267:EE_ X-MS-Office365-Filtering-Correlation-Id: 42401518-f0e7-4596-2402-08dc3c8cf6ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lmn4UMMG5TGmirHqYsBrDzeohu4SlvEoqAQKQJc+J/rNtylfbZkY4GOnUxRPoqT5oD0N/IdALX+0DWgBY+A3quzqemjSn2wcJJ1Axcm7U0i1N91sMaQfMSzQVjrltXLyHsj0gHXSzTxthpIpZ6Z7QsB+grITzLRfOtAT2aMZuXLR84Awry9jG3abzkFD0vrQW66SXqX2cvlIQnzrugGt9aHO7xPipED5qHiMrlZOZ8zvSaX2ZnZjrCQRRmQ0V9U8rCg8nSO8anZTCRpyd1ZIP1iFTQc03bpOPRueRZOLu8dQtfHCICkqTs/62s2NuS7DruxOdEM86+aZZqs6tqGVPLHz7p+nJTi0DDfi+OuYRALmOnaIKxw2+aIKPXj9OkT8AopTlD84dmaeQ1/vlshFEI0HRohJU58LQ+XdXXByma5lasEz0vg+PQVHN3I3Qsp9aUZNWQIRvrQgZBqj9gVbO2i5AJeQJvwOMfqyOl6EUtJ3BYx/pHz2vxDA2YxhTPB7hVQnSSDxtctYQvkeeQ5PAq7ne9qJc8xqcIxnBHZWEpC7rgCKGalaWODoPA306R+/qDpvnn7TkwzA+KdKsYLJ2y7tav4o2kTxY8A1x1x24E1AMtNKb6pGNun1SteNKJZjs3kHN1NtmloPtHpZSAGSE20RD+zYnPdudsFUOnbqPUiY+QbaAAu0zhgqst/lPLI/2+DgQMKJC1D20nuf+7+47BZp8tAeke3FPhLawVTrqIGvd1b4HBVAc/lrqXBxrO8Z 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)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 20:52:11.4160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42401518-f0e7-4596-2402-08dc3c8cf6ef 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: DS2PEPF0000343E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6267 X-Patchwork-Delegate: kuba@kernel.org In order to add per-nexthop statistics, but still not increase netlink message size for consumers that do not care about them, there needs to be a toggle through which the user indicates their desire to get the statistics. To that end, add a new attribute, NHA_OP_FLAGS. The idea is to be able to use the attribute for carrying of arbitrary operation-specific flags, i.e. not make it specific for get / dump. Add the new attribute to get and dump policies, but do not actually allow any flags yet -- those will come later as the flags themselves are defined. Add the necessary parsing code. Signed-off-by: Petr Machata Reviewed-by: David Ahern --- Notes: v2: - Change OP_FLAGS to u32, enforce through NLA_POLICY_MASK include/uapi/linux/nexthop.h | 3 +++ net/ipv4/nexthop.c | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/nexthop.h b/include/uapi/linux/nexthop.h index d8ffa8c9ca78..086444e2946c 100644 --- a/include/uapi/linux/nexthop.h +++ b/include/uapi/linux/nexthop.h @@ -60,6 +60,9 @@ enum { /* nested; nexthop bucket attributes */ NHA_RES_BUCKET, + /* u32; operation-specific flags */ + NHA_OP_FLAGS, + __NHA_MAX, }; diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index bcd4df2f1cad..816ae8ee3e06 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -41,6 +41,7 @@ static const struct nla_policy rtm_nh_policy_new[] = { static const struct nla_policy rtm_nh_policy_get[] = { [NHA_ID] = { .type = NLA_U32 }, + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0), }; static const struct nla_policy rtm_nh_policy_del[] = { @@ -52,6 +53,7 @@ static const struct nla_policy rtm_nh_policy_dump[] = { [NHA_GROUPS] = { .type = NLA_FLAG }, [NHA_MASTER] = { .type = NLA_U32 }, [NHA_FDB] = { .type = NLA_FLAG }, + [NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0), }; static const struct nla_policy rtm_nh_res_policy_new[] = { @@ -2971,7 +2973,7 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, } static int nh_valid_get_del_req(const struct nlmsghdr *nlh, - struct nlattr **tb, u32 *id, + struct nlattr **tb, u32 *id, u32 *op_flags, struct netlink_ext_ack *extack) { struct nhmsg *nhm = nlmsg_data(nlh); @@ -2992,6 +2994,11 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh, return -EINVAL; } + if (tb[NHA_OP_FLAGS]) + *op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); + else + *op_flags = 0; + return 0; } @@ -3007,6 +3014,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, .portid = NETLINK_CB(skb).portid, }; struct nexthop *nh; + u32 op_flags; int err; u32 id; @@ -3015,7 +3023,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, &id, extack); + err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack); if (err) return err; @@ -3036,6 +3044,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, struct nlattr *tb[NHA_MAX + 1]; struct sk_buff *skb = NULL; struct nexthop *nh; + u32 op_flags; int err; u32 id; @@ -3044,7 +3053,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, &id, extack); + err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack); if (err) return err; @@ -3080,6 +3089,7 @@ struct nh_dump_filter { bool group_filter; bool fdb_filter; u32 res_bucket_nh_id; + u32 op_flags; }; static bool nh_dump_filtered(struct nexthop *nh, @@ -3151,6 +3161,11 @@ static int __nh_valid_dump_req(const struct nlmsghdr *nlh, struct nlattr **tb, return -EINVAL; } + if (tb[NHA_OP_FLAGS]) + filter->op_flags = nla_get_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 Mon Mar 4 20:51: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: 13581214 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2065.outbound.protection.outlook.com [40.107.95.65]) (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 1ED0A1097D for ; Mon, 4 Mar 2024 20:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585539; cv=fail; b=teeXj4sOW2CovO+jauzDBoOF7/P817IFmK3P/PNz4u+uqQsVaH1Bfby4na+Z7fk17xt6PxjyTBa6bMRmmpMB3zv/IAkFFI3v4aZMLUm++lC1bNYZHwt/+oj5QBk1u8yf7w+biGyIH3RnDdx/QWOPO+QE/bPmACpzvBqND1pASbo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585539; c=relaxed/simple; bh=KROqfB89h2pIYpNKNgKyiLThUd3H2e27WvKVcd0eqoc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MOuVULiw+S6beKFxi/8he70rGwXFUHdlD1buv/V8KGClzMSNiGJIGDbEEF9hBrPDTIKjb1c1ILgzsCJVpAstUCPj3m5QalzoBOK7MY6U/3ewzGPMlIImb0vKgF4kmnmYBbjt4nWUfiQIQT4zne/jL77i+I/hPmza0jGJTiQ/gLQ= 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=HV+EA5P1; arc=fail smtp.client-ip=40.107.95.65 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="HV+EA5P1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aChjD8Yg79ERKuEcXUF20Q+oP3HeczAn+TGFANtDoEIvlTs0EAALQ0B6zEGyauD4eOwg6yCkpZ1o/xLvC3mTJ6UWS7sGNrx0eFwcdzEOLwQkcxRM0l+nv5KAjq8qIYZRRZU7ScWGVKo1er/UPMbZlDzhug4wLiM5NZfbLxX+ghP933CRcreVnudbmP3QB2PkHyl6kflQ6BoheP8A3jMFKqg3aB4EmnpjCvOFi/4YhkmuUgjJqeCG82mdpnyXd+1BVq/2VsaO1Pu59DZIBrSF/cKWCc4pwQMfMu1hYFdDPADJuci37NCv+Wn+lhib9PnKELyrT7sHuxVlpE3xo8MRnQ== 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=HwOp5EskDtM1LmUWxDStXvtDn9mFl27luCJpdhRrG4Y=; b=OXM7TZDx7nvDHa8VIok91a8+9P7YR1BjjPHXCU1YTxXcyn48Tn9wCAiLZM6Y9XzDnkRec63q0YDaJv22Ua2XkvbLsPtQuk2WheQV7RrKrdIUkJF7v9qibElMlY2kEITEcdAF65haXUlRcGG8CQaigtXtdJ01pAtRFPXA2KRQOeEE+2SBsIK4TVerFLLyOH1I0Nwhmw3yoFhV+C/vqa/c2Hy5YaMNtqwzTIPjSezTbg3hRzGJzZfpkbjjYOw3LPp/Wj+Jw/acydVIsib7dlS+gr0xBlX2D/xiIW0N/ojLmhM9w3pflthzBc/8QsajCR9JbPYhdZuCjyfYEZtq/jtrUQ== 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=HwOp5EskDtM1LmUWxDStXvtDn9mFl27luCJpdhRrG4Y=; b=HV+EA5P18T4jIhYxaR/oYPMamPLggFN9OzNLNl++eehZFGjkjSF258jm+mkN3oUGM1sZfEQEOkDy4Cd029d/bEyer1VXuf7prIo/w2ypNQj9aLzgXdZ03sIjHyV3Jzentjbs6vf9TAaqvk4n5Xuk25eeFdMiQuiPV/bWyCVOcZeWGIluDw7kGMb8Xz5TuSfAPcZ7moisPKDaIlbBpPlI3HBV5O/tDWtGudZkOVL+NYk5uA1zuHsdW3eYKnX9mbnL00UMyQk7PI9zOABWepzgtslnOzu/6TbqS76iZy42b9sDdpKYO/3k6/E7502CWUyFUzNo1izi0F9aG2p9vZWjOA== Received: from SJ0PR13CA0205.namprd13.prod.outlook.com (2603:10b6:a03:2c3::30) by SN7PR12MB8002.namprd12.prod.outlook.com (2603:10b6:806:34b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 20:52:14 +0000 Received: from DS2PEPF0000343A.namprd02.prod.outlook.com (2603:10b6:a03:2c3:cafe::2d) by SJ0PR13CA0205.outlook.office365.com (2603:10b6:a03:2c3::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.22 via Frontend Transport; Mon, 4 Mar 2024 20:52:14 +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 DS2PEPF0000343A.mail.protection.outlook.com (10.167.18.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Mon, 4 Mar 2024 20:52:14 +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; Mon, 4 Mar 2024 12:52:01 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:51:57 -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 v3 3/7] net: nexthop: Add nexthop group entry stats Date: Mon, 4 Mar 2024 21:51:16 +0100 Message-ID: <869e1f80d2c3443b168028c07eef8dd2175bb7e2.1709560395.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343A:EE_|SN7PR12MB8002:EE_ X-MS-Office365-Filtering-Correlation-Id: bab22431-f531-425a-8ff8-08dc3c8cf88f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fzXmEXtA1cifWJ+oFA0Z1XMyzj5mg5D4ajJBFzZEP/oFN3cehBfQ+IB5vomaHiN90ff8b/JV0YQPHyQFsAJaqORQPoiCgYP10EtRF3QOvcnl4uwAcMrld+RHnbA5lx6bC2plO7acFm1wTjSlfaYhK9mjH5qztNKdDPlSu8fUGwHhhaRMopH9TEigaQWLrtZqlxpTGuqV41f2Anyp3uhuXwoDjVhAzLnr3qOmvGyNBvWnmX8MfPhdF/5d4MBH0po21tVUNVn5MUdQlPizvv+tgzsroQqrlTUd4AhrfuNv/Qe7srPi/CnQC/TicL0XixSSNIBzw8VU2WSqSBWJ2KWZQCgECMnp/pK+7Moa/Zz/CjJwDP+ivOpLD+3X9AfIRBxVQytVmfNi7yGBnvUJng6jcdLaIJwh6ka/6WDOeKQKbRJ+4q4MI3XVXMqd2Hq2QoUIuhhNuJBEyoLvR9Bu1/sbfqzgL/KbTHxMHg6SExrlFnbfIzOwtcok26ssWtV/fEitMm3qB48Bt3mwi2oyZXfT9N4mZD+yvNYz5Y03pXKuVwAdJlms4fWble13Vb8wIZxp94wCojLhoZNbeP+RsvLrwZVnxQV0M/4YCPUVYCMvrrQg0h/onj/hYdFXDBgRMYHKEgT2lm+MS3SFl9Nxx6PYhGvbwjDd3Q8pdu8tiE2NbUidujCrKKmsoRsd/HUyX2CL44gZ4HPS6sxrtwfDqhs/RXT63VEHLow0B7Gvdb++0X2RSgyqvRV03hf5VXpxIS5O 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)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 20:52:14.1607 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bab22431-f531-425a-8ff8-08dc3c8cf88f 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: DS2PEPF0000343A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8002 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 816ae8ee3e06..06d65e27553d 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 Mon Mar 4 20:51: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: 13581215 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2051.outbound.protection.outlook.com [40.107.244.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 CFE46E57F for ; Mon, 4 Mar 2024 20:52:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585544; cv=fail; b=VIUj8G+S4L8poQS4ZJsYNfemkQVoXog9Z3SMTjXaUKT8teYlszr3IrAslHIVmrDVb/Ez8IMRs+yACksx1nuZPcY6tx2lCGiBzA2/EjID4A53cuKoe+qNlLOt12ISvTTJd+/hjEjkpa4bMvM35y1a+GxsiH4YmUGmD3nvTlezYhs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585544; c=relaxed/simple; bh=jbT7Zif7mgiHo/j7BVMGU707ngMXBajP2DuXRsztjpE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Jz7KUjOqEuWWiqsswARpPdqaEtS0CMn1VlQ6Bxwjr6bgYdZwouhaaz5oYtv9is+sVLcdy6I1Jmzk5R2051bcank6lQmrb2SNQWsQflN6Hqw3WpYC8MM10jBng++rNy2SmJJWFlEwgXEiHXvvnJp6o8p8GA+fhl8F0aQqikyKVuI= 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=VwsFy1RD; arc=fail smtp.client-ip=40.107.244.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="VwsFy1RD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L9uQCfytzkBrzNMB973rQUjAGgelcCpfxoafXM7z4W/B3AE4b47UWVmmRfIQh1c4fQvo80qcRmbPZfwIhSN4R5DC9NmuZl3i2VDXE7lYydP1qe9zFAG4lSY8/eHAhYoB9Uc4URApiqwpQZCDrvGTxFTvjRjPd9dzpQ6aO9XpjlNfOcwyJcIRKaHonzJaXQnNX/S6byuhFer8QpAq4BjT2rKm5efrqx+bT/PccRB8YYkhAc1F1zhHlNJ2GQ23S32CmwQwSujfUxhvpdx75doX6Yaa9rDxRS3Pl/mtXbChcVB21hn7hzLSPL6zZS/hdUqPqaLYMoklFo+/sAJBnQ8Isw== 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=rTkWYz9FY0GMnixPP7jtY38ZlKRAvKGWB8ZyIbMT5MY=; b=B6uGIDXtW4JzfXmIkmQvcf9vTaMD8kSxXCyY/btvzAymnD3gw+EecDg5thfKeA2pwa/CrFFlbxuCBXhcFDvkRAujMtrJUrs1AUCVSTL4PGgDVMwNT/2Uk8gmS2WdVdozcCMMh5+HY5nwU2bU5WNc4BsAAGG9u9j/5KPFgkpvlJUdy3+GhdWGDeelCtMsM2sUxzmP4CyiPgs5UxPnO3bPSm9gsftDqE6pID2kjA5R+qMmfpOlKnzG44tJGMJJVd+dMqV0IL9dkQvqsCDf2bvfgi9vms3FpdWQQPVTWo2JuOx81VTXZfmX1ChoK+gZSkTG0Z8Du8CHIrB3bxWVzBdQzQ== 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=rTkWYz9FY0GMnixPP7jtY38ZlKRAvKGWB8ZyIbMT5MY=; b=VwsFy1RDH6fpKJ5NkoIkV5kO4nwWIXyycQQMtXRIjnm9f2pava+quk8HGJlm1j+aPAgQzUJhFlGSuMpYJAH+srj1BdSnoyxodGTdj22mzMxn5ipDZHzhJBvynQoxYTundZrIndQDNMT7UMBSnmFqu71EIWgxPki9dOw4GlMk7VjXiPCitTXII1xyZT0N/o/hDooHgyEdBEj5rBz0UuJv5hlX5l3LKouGsdNlXg6YFVTPLvNT58Uhv4zFeDtKN+fkMvsjndnF7uSxLCA9srdQDRG+RTJts3F0JaeeHAhe7Ibyr1YDatfXN4ZBSSqW09k/pNHwOT9wxkwsEjYx62gRsA== Received: from DS7PR03CA0253.namprd03.prod.outlook.com (2603:10b6:5:3b3::18) by IA1PR12MB8405.namprd12.prod.outlook.com (2603:10b6:208:3d8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 20:52:20 +0000 Received: from DS2PEPF0000343E.namprd02.prod.outlook.com (2603:10b6:5:3b3:cafe::83) by DS7PR03CA0253.outlook.office365.com (2603:10b6:5:3b3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38 via Frontend Transport; Mon, 4 Mar 2024 20:52:19 +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 DS2PEPF0000343E.mail.protection.outlook.com (10.167.18.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; Mon, 4 Mar 2024 20:52:19 +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; Mon, 4 Mar 2024 12:52:06 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:52:02 -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 v3 4/7] net: nexthop: Expose nexthop group stats to user space Date: Mon, 4 Mar 2024 21:51:17 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343E:EE_|IA1PR12MB8405:EE_ X-MS-Office365-Filtering-Correlation-Id: c9af07d9-cb27-4581-5086-08dc3c8cfbc9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tPJUGgj7MKdqoqjr5fO4Vzlax6wEh/swGxVqqwlaFZBNpa15e0NqcjPkG2RRr+JJ4g1O8/lpQpzmdQZCnkn3BvaL0A3kBz8D5QDCL44tFTFysh1zWi7ZcIxmbQqXP4o09s5EwTGtC9CSAGkk3Mra1C2hmXS13zlO+6JFjWsNpPJmWKoAHWn2oJBYIJ2WmTHF68dzV8Xql5a5p/4LwnOqgJ6PQ8fOmec/hHUEXI/jJvljOjoB2l2Y3cv0n7WVtKa9uzwFQmLoiY4WX1EHqhpOMMQf+jaPtELF9a+q2z9oF7GVL99YZQpvP224/H2ho+JDsgyAKFCpvhQw0GfoOXB1IWHDHmShS6STRxWkcyI9SVNmMHJJewLlk75TobHxz6QBeXt1qgD8cmMdentcmp09D3IWWg1Qsshmb9e0nfBUpHBXDg0lzz/7c9OS3T52bhSgkQoR3qEesKE99GeUDGl9BSXs2CvidwEH0dqFivLrYyATxWPsaxQ94YSOMimyAJoZsWFtVtCz6nzcSu0CJnbJCCV75gor9G7+lbE0IczlosnY4rnCHEuwWQEpNXbIcqOXDOiZsu2dakZq3uoLgXe7HLdfuyrvOjWBVmZ0UyKwnaLaUxhQE9dwa8pgHrRJSDhuah9WeCRMxvf/9EGvlp9Zl211B34VQpBnEKraJcXK8RNqQNrzsVqZgcqNipjK7BszRcueRR9JI5tXPATacYZuFldiV80q5i0w4wzbyXst5lNoH/n23FqfeUV+B2UhQlxu 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)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 20:52:19.5724 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c9af07d9-cb27-4581-5086-08dc3c8cfbc9 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: DS2PEPF0000343E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8405 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 06d65e27553d..68ba60a1bad9 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 Mon Mar 4 20:51: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: 13581216 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2068.outbound.protection.outlook.com [40.107.244.68]) (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 96AACE54D for ; Mon, 4 Mar 2024 20:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585557; cv=fail; b=odIdeeqANfcldg34PyIrzDbz7SXIZAV9fRheU8V5MvtHYPzsM4ABglksF6Pfite6scJA0vUlZWgJ2hhFtQGAfgmxNNQYBdb/51YB1pPPctXuZM50nTXFwI0XFBxvJ/zJT/279LaNuQ/9snnCFRcWEn78DXbkytEOuHXsRRlLOhc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585557; c=relaxed/simple; bh=hs1b5NN6gANbDd8xHOzS3g8RgH20v5KiXmMpoBAZEV4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZlAaKgtfqU+dyFM+p4VIqzOKG0tSIKx7s+iZNucUYnNaJF3Vm4rXFSQa2Vix/VkLw6YLPXdLBy7kbfABet8W9lSqnTXl/8oMPIrofuxqnWPGukR3N36pN7wB7hIz2g6IfKxwNfgcHyIQltqFOGnMR4kJrjrX7yVIxRi0uzdpiQM= 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=FfOQUNqA; arc=fail smtp.client-ip=40.107.244.68 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="FfOQUNqA" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aSUBLDiX0LWXqDDk0SjYJoWKaX0vqrAd9Wzq+nd9UUng/QlFUIICWkjCF1g9bjQq8R509KZ1PPLUI8z7x2zgErCbKIJhDicdQqUoVlBnXxPQmx2pN97IW7DTlfvqQTJyy4cFw0lzr4h94WNzrW5rOsUxW/zRM1tFz80nKdNaRZmouoe6lcUA+UXaA8QHqjmGpCieDfMg9FEcN2gtM7LG2vDHILjr3Qm3sY2gFXMvNhnE6aFJnuMNrHFlZdZXycAc3wSU5Ta9G1NL+2J8zJnf6dBuk0txcU1Cx93Ady9wZIjRH0z6YgLYTTo8SoBBuNWp+uQDStCjccrVbB2S7gvpBg== 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=aFQC7Xfxcx1JxmvXv/62NNWug6jyA9fPBDoLD6NFe6o=; b=MTqrCp8tztwU3o1YdndnbNEipGmEZTzNk3LaJ1fmPYHMrLHALBTsEH4Q5M19r8qvSYiqoP23C/GtgKPQ6XjcKvhXBrwZU5Xu1pdnt68ZDpndU18NvyKQqAbIgdOFqA4J3Sk2rUYISy1jGtY6LJPXQzsNIPIIYr+3DvNoFYaUGVEJewh+VjBXMcwHZMW7BXeaPa7KI4fGITIT27sd0QVkfVA/CDj9XbwqorApVr8r+we4yDuyGY8WNGBl3tgIXzbIB08X1ewGwZD9XJyqQROaiARFuDYa7/YdtzrckUOrnDgXciBqKJBJ4gWKiIE7Xaah1pK2mFz0PAtz8rt/9sNOSA== 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=aFQC7Xfxcx1JxmvXv/62NNWug6jyA9fPBDoLD6NFe6o=; b=FfOQUNqAgqhJ/mKNusC+FU0zrLu0nt4jxLxxAkCWDbpFfKCnyccp6S3TTRgTYpTD5NxKLlTq7dO+Ifz7vjax4Ut/cfkph4kX3OHnhscfGbTYDUpHbbbvcN3Y2tmmVStB93Yf0Ga2WcqYnwSoCDeqwUYrK4yCAYxy42tNF2UC/s0BsizYkMCvLJ6go02DTjwL0wWNKSRatdU51+r1edvO1A9ZV5ri8TXeh51oJRft43W2q8ltxfWqrD3Htlw0DS0d0AlxFoB6ThMosIsYVV+5SF8Rytz4jksyB7GQArcPvX59JmXBiD4VUexeYU0PoHixrXKy7+jGXAQULKtv76HooQ== Received: from MN2PR22CA0008.namprd22.prod.outlook.com (2603:10b6:208:238::13) by MW3PR12MB4476.namprd12.prod.outlook.com (2603:10b6:303:2d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Mon, 4 Mar 2024 20:52:32 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:238:cafe::ed) by MN2PR22CA0008.outlook.office365.com (2603:10b6:208:238::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39 via Frontend Transport; Mon, 4 Mar 2024 20:52:32 +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 BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Mon, 4 Mar 2024 20:52:31 +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; Mon, 4 Mar 2024 12:52:10 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:52:06 -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 v3 5/7] net: nexthop: Add hardware statistics notifications Date: Mon, 4 Mar 2024 21:51:18 +0100 Message-ID: X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB78:EE_|MW3PR12MB4476:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c971465-e93d-4b77-5132-08dc3c8d031f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: riTvoT/Xvh8VjTkhy86aCjE+MsW/V04IkDN3t7a2xZPTwxBuM6w4Gh8UHLlo4PoVKt8RBO6XX9jwMxSjcIO8B7TUxwY4gBGxJE6x2ieUuANOGLMVATlbk2QqlVuf3U+zuGC3pmQ5OBjEUPG3ecXVfI5VXnseXvCYCI37VQTNYsKgVhSlnv97g09ykHzU/Ra4G67bR3ZUtj5DDnmrlPgiSMv3d1lKHDw1snKxI3NTpu3+o/fS57ZblM7JgLTFA8mi8iMvnRkA8BcQpHX4CQgaR5x/Y4ZPaFhKyoXU7YPRXjz+S+I4T+B6m2ag4Q/JCSIrjxRQdDdPGodEGEUKqjlCM1ZnwLHWsd9G0WrL8Z0WDDasdyPUpoYxILvKTtA1XCWmHbOxuGeg5/T/rjR4JoCijFEb1+sHen6/MhV289lGjZaqv/zyv//m46ZqNF9RmXjmGRA0IJ4BNHahaeyvncPpXE2EMIHSlXiRx2IjHCzwGLYkFAYipkUsgSkO5KuMPuK/SoNiMQOeK7odbHIcoqIbWNohUKzY+Q5qub4CBdT9TEgTuaTUEQ7fUb3C5C4qJtLBnFVvmGUXC1CAJh0PrVYbMkHIgnxzmmSAblU7Ac1tawA3lhKH7IY6mvVna9Xi2KKEitZ1EkWW6eRVWKeszYnuT+yJV/8YbyOKpN9ebMTL2jOGgfh2TmDi6XRuJ6keMnhBG6EirkjttHW8WOQxxBwYperO5XvGRrTaQ1NLjFh2URpgMANwT7jL2BiPwNxO1PmD 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)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2024 20:52:31.8175 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c971465-e93d-4b77-5132-08dc3c8d031f 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: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4476 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 68ba60a1bad9..22efb7d11179 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 Mon Mar 4 20:51: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: 13581218 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061.outbound.protection.outlook.com [40.107.94.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 2E424FC1B for ; Mon, 4 Mar 2024 20:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585561; cv=fail; b=qo5tuhmQ+2hq10dW9I4V/405Engp6jGcc536QY7CCM9UAMukp9SB6OW+GWRQwvuZVVrpOQkFwWa/pzBRw1DlCBRvxv5dGnnvPapgn+hwd4fZk70Jc8HoklxG2SMq0jSlQZ3Ovw5ppHP5YQLZdMUw1gFRZe+1ycLSMisBVGogyIU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585561; c=relaxed/simple; bh=JdVzaPYHPL+r43q4VywVGu4SexKtQbR7GV5tSx19HbM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=END1QogDtjAoIXxL/SKt/Si6WhothIy+7ZRpCeS2QFdExLDriHy5h9csZbBtcL/kOUV3FZReY1mFGG8NSkxQjmxgl736M+HG7aZ7Vs+niUL/njWOXxoIrNk/kzCcDkA/y/LX0vw94YVP+oqYqbo4ubpH7lxi5ou+SIXogjVbk14= 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=c/82QBnb; arc=fail smtp.client-ip=40.107.94.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="c/82QBnb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QlUDCIX4ac6mC4xB9Ea8akJ3JfVpjhRua4+A2/4gZly3Mz+f9WdSZ8hZswKlenRAawPU75Co9YVMTzwNWxQJuLByu9U+xZZe6U0GWDEHRLKZNDf7UJ4cMUWK9Kdezfup5vlPgF6gwy4t3KVBnM766a+nhL6V3D/YhIA2hjXTzZNR4PXRY9DOygzqR9GiF30GarKTkvP25CMbVOXw4OmesZORGG7cB7sPt//7OvvLv64HFT28eGkgqi4Hmys2qzcEVOMRb+p+pbqPvpGy9Jv2r7Q0cO64IkJ/OD2eetPpB84kqYQpgS8U3btxdKTHMOeOjdHkRxPDNfMiAJW9SldqpA== 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=QjGLNIUEvQyZzq1n96njwIm/LYQnpq6zgLJ7Sgw8jC4=; b=oHC1UoLsBI0E/kMMLUat44mShIV7ZlGI37lO//U2K10wTIx/BVl6M5fd9TFdExCu/pd4R8HMSxZxijPQbYcZw8sLPy82FyyCTMYgbbOXHzv+VmqyBr6tmsT6oMkpAOej4lrOX4oMVgs5zIj/NTVk7Uz24sSrBPvGw6B8J7Ytb9EzXgp7ozna7kW7Bsot6XkJfPwgC/b+GNplHMNphYv3WwbT/Ute79pCcgw8nbitI/ENRbc2NPt8JYujWDtmVb+GkHEOqxqZCvB5zJ4PEuY/lFirbBC1Kl2CMaj9OSSVqe2A6sMcu02QZAB1bJ9ueAXkFJNIZgbBj4YQA8uByYKruA== 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=QjGLNIUEvQyZzq1n96njwIm/LYQnpq6zgLJ7Sgw8jC4=; b=c/82QBnbMqSBFsTcwA8gJ5QFFQBAn+7XkSDjG3UhuLdfcsXOv1TTEOz0M7OWOYWI376y2IzOKzU/uwCbKVFdYNSsOxd7OTIr7NgySgzGNpKUqwcWUiZDvezEdGukWpfP5fjX/nMcgA4no9a3S7B2Jl5bqvJqLjntj8fHKPvx1EV3Puxr70JBNVrGjlFE7wa6R7GUSyhmG5SxP2WZieH5ySW02oMgN4Esb6Mv0EI0yby71ByV1lurZ2C6FEYi5wDySOuWRfNhIEVG4jxZUDwuyXFBOE73oN2oxRGgrOXTRoCzkfy7kwfntgB4PuMC7RhC8Cjm7OCnvgghb7sEntzpJg== Received: from MN2PR22CA0012.namprd22.prod.outlook.com (2603:10b6:208:238::17) by IA1PR12MB6602.namprd12.prod.outlook.com (2603:10b6:208:3a2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Mon, 4 Mar 2024 20:52:37 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:208:238:cafe::4e) by MN2PR22CA0012.outlook.office365.com (2603:10b6:208:238::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39 via Frontend Transport; Mon, 4 Mar 2024 20:52:37 +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 BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.11 via Frontend Transport; Mon, 4 Mar 2024 20:52:37 +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; Mon, 4 Mar 2024 12:52:15 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:52:11 -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 v3 6/7] net: nexthop: Add ability to enable / disable hardware statistics Date: Mon, 4 Mar 2024 21:51:19 +0100 Message-ID: <9c3763308b14b9385e80e3893777f536904b210d.1709560395.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB78:EE_|IA1PR12MB6602:EE_ X-MS-Office365-Filtering-Correlation-Id: 19843b0c-ab07-49c4-58bf-08dc3c8d064c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6ZsubEbgUwA6gEp1gZTjApsJq5qx6nfRIW3jU6XoDo+qmpCoUN57VhsTZVWcJzF0orGyHPlDcdkKPvFUr6uayUV/iRNwLTtEjocTY/VrBHuQcVV2YP5VhKrrbOEPUwC8ICdX0H5H3GVDAC3IamXsa1FFI0l1F6Au99KQaqG88Gewbv4ncLBXuTLuVHaCHpY8wcXB/KK5OmSRZR4BFpw71hbr5e7cBEjuM4D2A8RNF9JTRXjTvrN4ntPMpxZumayQ9lJreB4T0fM9to0XsV27C5T5vWKKxPI29xG+jr+7ZCLNfbFySCf7Y2oK8eNvOSSHItbmiFTnPohuiUI+lfYJgI5+o9isZjvfU7hwqH8MS1j4GrcoDuRqJ2bQSNmZweAcg9Z+lJabCrrzeKLd/6yf9LoRA2KJVJ39tR01h8v6FXiSi2Nzx4MhtDl9pAZpzMb+OF/mAOmVamZb0GB5JJUONSSGUJHKdlJxkVM1pykK5yFuzW3tEo50rjdW4E5oJXVXkMjIJw1GVzLLGXICiVWDHDS/Nqfi+5a1iut9SfrAYht/aZ0rNvLkLFFRqCIVGN1y4NkFJUHpRTmEtmLV7Sqvj4lVacyy3BUcQc+51LmV31Te+v5sd6v9x3OLfiVZ0CFdlrM6XlNv2bLG3ZZGORE0g5U+qgedCz6vkTq5mQdmvW7/J8aCF5yn1xo+KD44du884JSoDkc0cOJgOd+rNuC6iWrTQKiGt2rAl1r+F0cw5TX8y2XT8T8PiWGdn4qEJkbi 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: 04 Mar 2024 20:52:37.1458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 19843b0c-ab07-49c4-58bf-08dc3c8d064c 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: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6602 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 22efb7d11179..acd27bcdecc5 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 Mon Mar 4 20:51: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: 13581217 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C291101E3 for ; Mon, 4 Mar 2024 20:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585561; cv=fail; b=jyKPn9KggcHowD8d5GIoHv3ns9DiEkjMk1+rOQYk+6IjNHzIzXBwAweZVYRWjIUq2knfDIiR4qQRAQxMFenaW1b/ftPLcWapG2KsMQxvrIozjAoarAVgvqbVEOXIlpNJ0CK8iCH43aUUYLqfMxlbYA7BRQBwekAIIeUnw8E/D9g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709585561; c=relaxed/simple; bh=rkkp4+zdWnSg2tJpQ2Z2nQ7g6FH30cs7dDXFwBiKyNg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UDlc4GwM1IZoIs3cPM3aYUhZ3/qlXUnj0yZdLPi4JfBRQdbdRPKjJBSEPSKXeCX8CKbbeMI2y0xno1XtKFQOYsNMnhhq636NAWrNQzcNcakJyflCHHETXiAbxZ2NIGeomyWWn/DtQPGGVpOh95xAiKFerSaPXzjw0l1qc89xqww= 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=qK1T79vp; arc=fail smtp.client-ip=40.107.236.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="qK1T79vp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NZseLONbxWRCrwHJIvGmSR7+5foVjOd+8wME/CRyj60sm/oEnvsHAezE0YTLbSua1/Ru1GSlgV1waXhyKUio9r6/Wd97LlR7aqaYZTIKsB2syNjoAevZFYGwRnWB7hrJo6CjgKLULZEmv7UVq9mRSyr3+ff79c8I15EBq7NMdq2aBXImXIpokm2g1IpxDl6zFLaLVJPE5d7nSoMQAsa8/NuuFZQDhldsWTGhHJxsMkbkQoV6H5kSbuiOBNqCBgrkUd9geGhqiwQTdxrKpf5j1PxWnnRtqBiEEOkaZjuH/WV5UXv93LTQziKPiNQ/tyXu2Y++OzoKwlZA2fqRCTvOpg== 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=d9SR15RXf6Uz+g2kzimo6ZbabEgjtQ8q09YbmSD9t5o=; b=YcG2kmg+Hl2Wmu/+SUpuAkR17H+X6+ehiR+YfywevqT0CmqEu49UKEHiBCuf/2Jy7tM8qI2qTKWgFhB0/Z4+/uf0AWOizWsBqfCKOxqGeGz1A7pgjACAzY4Y4IZfnhohRRCvX8Xo/eQKm7g8PLWYw2QCu/nU+gv9eY256Oz7meOnKLR2Y7AMLeNc7AfyM/Zm+/EMKwucvOU0b9EWPkZ0QN/n6EbNB7iIzQEL0eyv6i+y5c5Z5krFTi3j1tmcyzfTCA5P/+6aqQzCV2p5kW0plo1TztdzR2Mq4RjqJAp/CTKt4osjGrBmt0eUpTEy5wXHtHZbLV1sxPb3yMZYIuwUVw== 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=d9SR15RXf6Uz+g2kzimo6ZbabEgjtQ8q09YbmSD9t5o=; b=qK1T79vpdJw1/pu7vnhShKty2lFHsDGeMEQGaKm26PHKvgGhgue/kTUPOpxLtkmr+1wISW5gfibH8WYV4QZnYs/hq7KuLOFnxApX8aJBuN5Zn/kv4P5Oru8YWluGlm56175eXvmpzLCwvtombzL2eU1C4N+kPHCxFT3zOt/wZrb0jL5f0VfgH2HMB/4078Wtv0hRC5ix1U51It4/HJk8cvnKRoz5qqxUnEL4Kcd2feVq3JAqCfYxo1Ulj2RwZo4Yxh7LUy017+G7dGKjAOQmFTY08CFu1wMLMoh/AERHx9pQI9m7fetZjPSXx/vaUDdReJj8/olQXvDLHR1qar20Wg== Received: from DS7PR03CA0248.namprd03.prod.outlook.com (2603:10b6:5:3b3::13) by CY8PR12MB7706.namprd12.prod.outlook.com (2603:10b6:930:85::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38; Mon, 4 Mar 2024 20:52:36 +0000 Received: from DS2PEPF0000343E.namprd02.prod.outlook.com (2603:10b6:5:3b3:cafe::cb) by DS7PR03CA0248.outlook.office365.com (2603:10b6:5:3b3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38 via Frontend Transport; Mon, 4 Mar 2024 20:52:36 +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 DS2PEPF0000343E.mail.protection.outlook.com (10.167.18.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; Mon, 4 Mar 2024 20:52:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 4 Mar 2024 12:52:20 -0800 Received: from yaviefel.mtl.com (10.126.231.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; Mon, 4 Mar 2024 12:52:15 -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 v3 7/7] net: nexthop: Expose nexthop group HW stats to user space Date: Mon, 4 Mar 2024 21:51:20 +0100 Message-ID: <40715b7655ddd9aa72e17bca1439c84ffa7dea05.1709560395.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF0000343E:EE_|CY8PR12MB7706:EE_ X-MS-Office365-Filtering-Correlation-Id: 609de226-4d6a-48d8-0a71-08dc3c8d059f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X7akrbXSpqmeSPS2VoHYvtjkADHD0AM3+VVz8CeGSnKNE9fpnFDFOph49w3iGkZR+AK3QUKJDGJyNYI/3g0a2CZmUSByGX55lVGeoSUMZJNbHWTU6qz6qyYZODYDhYZMVzLVpgwCyvBg6k6sDQIk223E7m9ICgxYI10KP7FxOVr3c80O2MFSGExUtZ+TSV4JNJDbJhRuIo+2/ZVbN4ifRhK9ctsuKqPAdXxwDuDq/TtBbM5zx2GyDfgRplQj0yCOCenoAwSlMCIP4+lPomYVNJP7F9bySQ69imchKoQmS6YJ+ygIupxmVkDXmeQMqThPpx0yNeEPZpqvxPjxJyN+DBtVs39FW6EXAkqK6l9DLyUgQujHWrfPmExJUxukR552UYmmXLEH7um496Brs7L6OrDwWElwSK/anawfEipAc/J+KRmRAnyRm4yOCitgxJ+ecWbAFMK9puH3ZVXFHD9DMpkl6J7YqQgU9FKu2SooOHLWp8FjTfpkInATdePsv12ABvbp2hVL3eu2zHXKOD4EbsNisnHZBiKZEkQ8ENVasuxsRpw7EQjKiRTzDAP/gLB6Mhn443BXLVooVXjIJoD7yVTnvBE18ekgBqpksTB0uiE6CHv8Tmk9wPcFXJDipqhPalux1xc469+7IHklpr68d10UMIFWom6bnHdnBybScG+pyGLl/BEgW9PTl4HDgmx8wiItFXJWzxOv6fi27e8dTQ1DCCjVNgSAYpRxjCzGlQ7gQFKfE9hJr/D5TAAqyluU 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: 04 Mar 2024 20:52:36.0569 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 609de226-4d6a-48d8-0a71-08dc3c8d059f 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: DS2PEPF0000343E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7706 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 acd27bcdecc5..fbf7f268038c 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;