From patchwork Wed Jul 19 13:57:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 704786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D03DCC001DE for ; Wed, 19 Jul 2023 13:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbjGSN5P (ORCPT ); Wed, 19 Jul 2023 09:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231303AbjGSN5O (ORCPT ); Wed, 19 Jul 2023 09:57:14 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2075.outbound.protection.outlook.com [40.107.92.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8760912C; Wed, 19 Jul 2023 06:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I62xG8eX7qsyxlAsn7pH+uR8Y9LLdWY7b9HEG7yKKwo1a1EmZyJHJ3Y2QizASdSbS9KrGQNK+uYMOQAfnEQ3yCVTau2ifBssMFuN74CjmmYPH4X3FHRzRRCNyYPZVbhLPbhPPcjSSdLgqhv0J3quXwhm04foP+cdRi3TvRlquxPPCkclGrjyiJLkXAl0IL0LYqYEDmE4JkD0R4RbehbBKzKlCIOynMn5FOgtbGlgVsdZIV0NOGtiOu8URqBymEELIY4kURANuLbFJO7Ktu/EVCJcdf2XnWbZyN8ZhLgmXXlGXSnFrorrFjx1ar4GGSYSjA2JDiyYCgf0pDWG0rW+hw== 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=tUeV8oIuvHrSih9x/1pXMDjhs4xpnIKANIY1SsSmAiE=; b=mE0BwpAAqQHjPAr5cHA2rmlGpav2jvYayl1CW84ozB0KsOuZbFAcMNTGk9TNRU4F1Fy8aQVhnWijWWc37TsxLs71n4a9LuEna09kJ29pX0WxNhXGK6Zzj6JiR7rrBvWc8Y7O1MWTahX/ocWtXu4CWAdkDry3XpzZft3mH/ymtH9q6sw1xWkiBGvqwuqiRseF4tYvthT5gY9zfpWvTIl65doImMeBZgF+KW2I7OyNXM4netzk0Qm7+wOtjGbcB2nTJE4J1+7xwIC6qBidW315JKCWwk5QHdWKnyhV9f6IuULL8z+p+l4lvE0wwqaTuBPZLB9/hbOUQElbZzr1eFa0qA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tUeV8oIuvHrSih9x/1pXMDjhs4xpnIKANIY1SsSmAiE=; b=aUiWmK2/wyWjNwxBqRm+mVkC69aYaM5QzZKfJ2I7tFoJ0/xoI59ZalAWTa3eIK3Sdg4DOyr1AKd4JN7uqLhMWpCkd5nhkjKNNx5U1vhBZQVhe7InWenDj8p4DSsR16dz+gmWNqIKdNuXlXWASuU7dQX3M0ETiZ1Zpc9Faz50mDukHLMRehGeoYlzsxJimuK7v+sRJ7H2I5vdtTauNU63VNJbgLjvWXkZXV8Y/BO1/HW1iQtzpAf/iyqcEcgACPxdwAnJDWJzg/NU4giqQNy4+obenMb9u7/mNBc0N2uMuD/rvks2+7S2/FcrNpXNA4OLk+iivtPd1oKlIkizS0vTPQ== Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by SA1PR12MB6994.namprd12.prod.outlook.com (2603:10b6:806:24d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.23; Wed, 19 Jul 2023 13:57:11 +0000 Received: from MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::982f:232b:f4af:29ec]) by MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::982f:232b:f4af:29ec%5]) with mapi id 15.20.6609.022; Wed, 19 Jul 2023 13:57:11 +0000 From: Benjamin Poirier To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , Ido Schimmel Subject: [PATCH net-next v2 1/4] nexthop: Factor out hash threshold fdb nexthop selection Thread-Topic: [PATCH net-next v2 1/4] nexthop: Factor out hash threshold fdb nexthop selection Thread-Index: Adm6SOo2pRJ1b9JTe0qaFpcgHytNCA== Date: Wed, 19 Jul 2023 13:57:11 +0000 Message-ID: <20230719-nh_select-v2-1-04383e89f868@nvidia.com> References: <20230719-nh_select-v2-0-04383e89f868@nvidia.com> In-Reply-To: <20230719-nh_select-v2-0-04383e89f868@nvidia.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: YQBPR01CA0111.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:1::11) To MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) x-mailer: b4 0.12.2 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB4373:EE_|SA1PR12MB6994:EE_ x-ms-office365-filtering-correlation-id: 0179fdf1-1668-4f01-79d8-08db88600cb3 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wbZ2KqZq0jkWSbxmd2wET4D2USkpHJ0X7keB/s4+Boo7TVRtRbZ/Ve8b/1PPG2bff+XRaqo0QOxunpQBHnYNLlj/QMbkzlOQAkmVkdMpFn7qIZ/GlnsWy9+hOtJoL9zHPNwfj6OtyBUBdL964J//JG/dYlgu0kzarfLKlDn+3LvadTENXS4eQ3ZN0Xy0/pARBiCYt52onele1lVxIuZEwesTU85R+2k6DzVU7AbOsh5Deg+oKJioJO50bn6nImoSbU/VhW52xm6GCel5T2C5jP4h7LYff7Am/HB8wlJQmSD1+Cj+Cuf/sDEIq9JBVWw2scwCCd6iwdNbZN5dGo6as9HmTjS9G0cZn++0elo8oH4LZFYXpFcQyg1mvLFn5WjeNbhQ3stV6ObrMRGnPnH1LshIkLf9cpyba6jMYfSZwAH20u0/oIiIcvJuf2x5qhzGhoVTTu82wQPHUTwGOtNwPFeNBOId1VglGjY0IPkKa4DFuAehtOF9lvu5lRd7B3364bQAjTMWMrGCC/60WoR0LieQeKLB2SmeklbwSBIH32CzNTas7wX5cJh4EQgYJm/K x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR12MB4373.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(346002)(366004)(136003)(39860400002)(376002)(396003)(451199021)(316002)(41300700001)(66476007)(64756008)(4326008)(66946007)(66446008)(66556008)(5660300002)(8676002)(8936002)(2616005)(83380400001)(86362001)(38100700002)(122000001)(186003)(26005)(6486002)(36756003)(6512007)(6506007)(107886003)(110136005)(54906003)(478600001)(71200400001)(2906002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?AhoaCay1JuwoEgwfu307iAbMrfFK?= =?utf-8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-8?q?MJeRNH8QPRn/voaLAq5rbE0XbCFDxOhCj5PrcEXn7h2vmAwqlzGRbhDlerxbOGIpY?= =?utf-8?q?fI9SdZlFCqCmuKV2e9S+L5SYMIB3JuFvXv9GomQS5C8zZId0cvtF8e2LA4kMRpp3C?= =?utf-8?q?P50XtHi+wHXPqrhvx+79LHjxrE1Wkvj5endTRha4BDRxA2AiOzOLtvJpKB9VzZ6L2?= =?utf-8?q?dyFNwb5zO5BfAfs9iEP9WqVq4IkmOcyXwcOQFqAGWDQlYTT5q0eDRfHV03L3oVh8G?= =?utf-8?q?OyR31jkTn3f0H+NvQs8+cgXE9p2PIf8oB+3eZ6glwvm4FNGiQjwoeB5mYRfZ4f9yD?= =?utf-8?q?nF7s8ilbOouPp8jkPPWz3BM1GIj6jx8bZh402cBNX6jZNItQEp57Ii4++3KLOawpl?= =?utf-8?q?eWHOaJVNrOQJup2f0HB0LUCpvNzCdmOTnBwPHSDZrRlIaTGxJtah+aCEViktEIIru?= =?utf-8?q?TBEI/zrBnzBr5Z1NU0njXrmXwbk8Ll3rmtuG7n2In9YzEA44hahvCdatxzqeiKyun?= =?utf-8?q?mYWwBPxnweC66MghAQEIHBfNMySHy7ujKMDV00UKhYk/bftg0ymt+Un0mNyXxfjk8?= =?utf-8?q?7z0AHt40rdbkWkYqF13hfBS9/hGQcPzKqZo7d0+7x0kaLaiF8A0EiJ4Qkq91i2Zwh?= =?utf-8?q?5LkB6gvZTKJY?= Content-ID: <3226475388E5084BB5AAC618C3FD29AA@namprd12.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0179fdf1-1668-4f01-79d8-08db88600cb3 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 13:57:11.4082 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rcJb5PL7M9me788VnfNIwydHdacLzuF7J/dmujJ0sJ1vpOmfZVCwHMgY+Z+GfxKXrrKaQJkKiGtnzgTuEejmfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6994 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The loop in nexthop_select_path_hthr() includes code to check for neighbor validity. Since this does not apply to fdb nexthops, simplify the loop by moving the fdb nexthop selection to its own function. Signed-off-by: Ido Schimmel Signed-off-by: Benjamin Poirier Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index f95142e56da0..27089dea0ed0 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1152,11 +1152,31 @@ static bool ipv4_good_nh(const struct fib_nh *nh) return !!(state & NUD_VALID); } +static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) +{ + int i; + + for (i = 0; i < nhg->num_nh; i++) { + struct nh_grp_entry *nhge = &nhg->nh_entries[i]; + + if (hash > atomic_read(&nhge->hthr.upper_bound)) + continue; + + return nhge->nh; + } + + WARN_ON_ONCE(1); + return NULL; +} + static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) { struct nexthop *rc = NULL; int i; + if (nhg->fdb_nh) + return nexthop_select_path_fdb(nhg, hash); + for (i = 0; i < nhg->num_nh; ++i) { struct nh_grp_entry *nhge = &nhg->nh_entries[i]; struct nh_info *nhi; @@ -1165,8 +1185,6 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) continue; nhi = rcu_dereference(nhge->nh->nh_info); - if (nhi->fdb_nh) - return nhge->nh; /* nexthops always check if it is good and does * not rely on a sysctl for this behavior