From patchwork Wed Jul 19 13:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 13319028 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 90E70EB64DA for ; Wed, 19 Jul 2023 13:57:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjGSN5c (ORCPT ); Wed, 19 Jul 2023 09:57:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbjGSN53 (ORCPT ); Wed, 19 Jul 2023 09:57:29 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2050.outbound.protection.outlook.com [40.107.92.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A041BF5; Wed, 19 Jul 2023 06:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yrtmbe4o94yrI2Sly2digJt5GyCs28ixFN3WwlHLOGFDBUZWU+5j5SFfadkh1KOEUUUQh9NzSHMA3kQYN+czX4Fi0xB7aLKJ8BQ4Pm74xStK8GTsxnTphrcMitHtRJ8LY8RoLqcjMEWabkehXoCdIzK+5OrWp7NgQVx6IHveG/Bi/YFbsjC7sQ+RgDImuBAqAr064Eqq4n+rr+ShBbyfTFFAiwCjpi9gZ5FgHgudhf213v0C9xDPkB+8yIOaCkRmd6Z1RFGYkSAqSUxSvMCYT8nK8Cx62pKc7k1AFsTXwhstiUu2VIIihnzn6ww0AXRqGoTl+c+C+5Ik4lJSaMguVQ== 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=xxpO4bcWuo1MgkT2NiTuTmmshEYXt3etyzvEDEnQDdc=; b=KXeFyAMV53etekt76F0m6VpNOdd1g2qhclpP5r0ePB7caO7VdWrbcizTWRXfhpQfzssJJNKLdhhDM6ZvFIbHuYojL8p1A8D1YlVZ38FTyD3JSTC8PI2yom9/f7RvugFHoOwcLWy6Wui1IuPCKWrE38xbVqBthrmV+itP+b5GTddsLf2e9+62XTprBFOJzbX1TmPvMaIbwRKBDXLaDxdKODFAJ2b3X8+44nA4d85Qu1hZwsDnRViQbA08b0XaOGHVSJ0CzxNvsOI8IaBYWgfpnvlypcg0r25gWjXxOiDc5MaKzQwObERsTe68akodF8lV6/Ks5MS9L85SEFLRcUaE0A== 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=xxpO4bcWuo1MgkT2NiTuTmmshEYXt3etyzvEDEnQDdc=; b=M/QqG0RHUJ0mOgTGuSUhQwrO5g7m+/dfWUcagmAqyOqQlmhpJI5dA45PJBFk4u7q+Q7fMBmDZ4wbAf0H13Jz6TLvbzAP7NTBAgI1y/YFf9/7D+BwV/3jP9je3eX/tR+cibAK5YwZyHORiQdSUnQMRyNnH0CNyidkruDnflHqgaycatSn+YOc2q33gwD8rWw5JeE78nEWcYqile9KYhMCGn9Ks6A5y2cPBpc6YBFG801Htk7hvo95fc60ZtwWs/feCgzg7xjT73uUkqBSFCEM9VLBe0TFGZ7YK14L0DWh89L1nieKqBWcXdI4fxl7EBb4nU7zcmqMCmpd1+rS8s7qSw== Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by SJ0PR12MB6687.namprd12.prod.outlook.com (2603:10b6:a03:47a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Wed, 19 Jul 2023 13:57:22 +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:22 +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 3/4] nexthop: Do not return invalid nexthop object during multipath selection Thread-Topic: [PATCH net-next v2 3/4] nexthop: Do not return invalid nexthop object during multipath selection Thread-Index: Adm6SPCTjLnm6ZDF2UuYdzGvm4mP9w== Date: Wed, 19 Jul 2023 13:57:22 +0000 Message-ID: <20230719-nh_select-v2-3-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: YQXP288CA0028.CANP288.PROD.OUTLOOK.COM (2603:10b6:c00:41::40) 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_|SJ0PR12MB6687:EE_ x-ms-office365-filtering-correlation-id: 1b305924-6441-45d3-f67b-08db88601311 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 9SrbSJxm0ffRrFOZu2eWUcL5lVO6wXLc73ytkiYB+nmL874YjRJh0J7BmDRlYwY3JgaxdgeQgOdGhzqBrEWpks0SJKR0SwQoorAW5tS8G+qUdyxDX7HJ2SSfYDOPaKRcNTxAxLhyo/1FEnNgs8O8jjWODd8deMLbs7u2MWcOBmOzhZ/w7lpDelrOaKt+fxypL9Wh3C6HmtLve8EIHlTFZQGxxctZfXXlP6DR6XWk1GPq3kIbrpt4IfV8VIQUpuDhx+jKMok3rtj1n/qCNONsqUemS32NSCBnllyTXoQ7rNJI/RMMiNMjgRnReIm07Bzx5f7mJzeuapAheonhepFrNOg4+jgvePasOEtTVYRGOggxfBySciPMz/7cOGeU0nSbs2pwzpWw6dJeXtAPKi/UhbozSDZYIqr2ahbFV3tLzG5vEWyKI8Ye8+9yQPraox0HUiyq3gdBQd0/fl5BjFV8GqDs6eahfTjVN1wE9h2XDWm6FlO4moLiCz78c5R9zFfQod8qLUHIjwbz56QQB7lF/mOXZKaQcjyf2Xu3qQo+c+KTZO3jWYW4Cur8aVwj3v5Q 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)(376002)(366004)(136003)(346002)(39860400002)(396003)(451199021)(71200400001)(107886003)(38100700002)(122000001)(2906002)(6512007)(6486002)(2616005)(83380400001)(36756003)(186003)(6506007)(26005)(86362001)(64756008)(478600001)(4326008)(66446008)(41300700001)(8936002)(8676002)(54906003)(110136005)(66556008)(66476007)(316002)(66946007)(5660300002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?fxk8FmSI8xb0bBtxbxXc9nRnFL21?= =?utf-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q?T5HKz3mlmky8tyl2nD3/Q2WYyhjxphvPgdqx6HHAsMxF4dt8lGw3z1O5qbW58TfBO?= =?utf-8?q?r8qau9NVEZHuwXKpnE6GRDovhK9eW1v17GDVS5OONZ5IMR1CPem+e6utHrafMNytd?= =?utf-8?q?7lgFDnrWb1dY3hGPm1PJ4qvjaBs8JCja82vkwW/JCwmJuKoo9Qzzcqa1dujVvjx5O?= =?utf-8?q?oNR892K/E3s8G97AMHaEIT/zKrk6LrTo/tl7CqIRMeH3m044yRya+njgJckE+u9vv?= =?utf-8?q?r7Vk5krlALl14S2qLT4uccYa6EPcmFDWS+RT85HZ0vqUplC6IBDooskeQUCPhSoij?= =?utf-8?q?ztMSD4k0WCPzNPYv1v2JPOEB8GG4IMLMpApYSm0rk6JOX9nPcRQpafsCTeg0LHg3v?= =?utf-8?q?5OmQBEljeEVA7qv6FLtW8YgRYGxHuU76xWA+iwCLXctTG/XI9z0GHNdA9dQ/ojajR?= =?utf-8?q?HDcdjua5tQf87HWGQQoCNJ63pi1x/Pm92bpZtRBkjGDyXo9bTTzb9TPRWMI9V5aIt?= =?utf-8?q?DHlUvLwl0aWG26tNTMCK3qP2ZrHzfPD2SfnA9IlSArgb8jVAxf5P7YC9xk+inDjKg?= =?utf-8?q?29+uRSPV0TLTD4f8EYrweVtN19IayG6KQBfFKgXFv3uy/d/dO4VCJx5z4XGGvn11s?= =?utf-8?q?lyk90C4F656s?= Content-ID: 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: 1b305924-6441-45d3-f67b-08db88601311 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 13:57:22.1009 (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: CFRE29vqlxDz3Z86gHnSe3hJ4JNyZ37NqhkAjrkUcg7ckagKEYODgck26oEOoKRFL3Y+SEYWaW7P2B+13M7aQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6687 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org With legacy nexthops, when net.ipv4.fib_multipath_use_neigh is set, fib_select_multipath() will never set res->nhc to a nexthop that is not good (as per fib_good_nh()). OTOH, with nexthop objects, nexthop_select_path_hthr() may return a nexthop that failed the nexthop_is_good_nh() test even if there was one that passed. Refactor nexthop_select_path_hthr() to follow a selection logic more similar to fib_select_multipath(). The issue can be demonstrated with the following sequence of commands. The first block shows that things work as expected with legacy nexthops. The last sequence of `ip rou get` in the second block shows the problem case - some routes still use the .2 nexthop. sysctl net.ipv4.fib_multipath_use_neigh=1 ip link add dummy1 up type dummy ip rou add 198.51.100.0/24 nexthop via 192.0.2.1 dev dummy1 onlink nexthop via 192.0.2.2 dev dummy1 onlink for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh add 192.0.2.1 dev dummy1 nud failed echo ".1 failed:" # results should not use .1 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh del 192.0.2.1 dev dummy1 ip neigh add 192.0.2.2 dev dummy1 nud failed echo ".2 failed:" # results should not use .2 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip link del dummy1 ip link add dummy1 up type dummy ip nexthop add id 1 via 192.0.2.1 dev dummy1 onlink ip nexthop add id 2 via 192.0.2.2 dev dummy1 onlink ip nexthop add id 1001 group 1/2 ip rou add 198.51.100.0/24 nhid 1001 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh add 192.0.2.1 dev dummy1 nud failed echo ".1 failed:" # results should not use .1 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh del 192.0.2.1 dev dummy1 ip neigh add 192.0.2.2 dev dummy1 nud failed echo ".2 failed:" # results should not use .2 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip link del dummy1 Signed-off-by: Ido Schimmel Signed-off-by: Benjamin Poirier Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index c12acbf39659..93f14d39fef6 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1194,20 +1194,22 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) 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; - /* nexthops always check if it is good and does * not rely on a sysctl for this behavior */ - if (nexthop_is_good_nh(nhge->nh)) - return nhge->nh; + if (!nexthop_is_good_nh(nhge->nh)) + continue; if (!rc) rc = nhge->nh; + + if (hash > atomic_read(&nhge->hthr.upper_bound)) + continue; + + return nhge->nh; } - return rc; + return rc ? : nhg->nh_entries[0].nh; } static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash)