From patchwork Wed May 29 11:18:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13678720 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2041.outbound.protection.outlook.com [40.107.93.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 732C016ABEE for ; Wed, 29 May 2024 11:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981696; cv=fail; b=G5Kw0LIz+NfwzpxJYQRlFoP4tjtS7/hQOYmmeXRQac/NGV4+6gNkUep45YFJ0ibC+UzveBx8UTKBNBbL9kkPYtkDPElUl60tcEKq/Vsq8/tEtAmC7b3hFo3YJQIh3NCl8U7dOetmat3C5X/nPmkTilNlmFDP6VVRaGLL2qDJTV4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981696; c=relaxed/simple; bh=Mkp20AOYvdVoC/PDwzRksUhD8i0/unOgNFRlVSMkSQA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HQvmlZ5FfAbONNGpsnJMM61wy8WGOc7sZoUYFWBiFkVPQhtpOSFgTW/iIcY4cjv1q11TykfJ/8fK4Gysb2kHOLFELXdlEJsbV5zidf/n4JMrmZSXUs6EbIKoSoB9VvDSPG5YJDaL1VVp15TFX5qm9BNMnhgbnQPfl69RuVP58xI= 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=uhc2tI8j; arc=fail smtp.client-ip=40.107.93.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="uhc2tI8j" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n7t3PIu3RpN37k0mbCg98WjeHl2hvortGsFv4dCc42+PHpUFIdm5LnXgG+eHEsMv9bg39Cw0AAn2EANDfpEBHl2luDkFmyP4I8QI/ur7cDrfRqN7f7x+Lvnf+nhkdaMOzhZi2Mt8eE44wyMOwkxbiMZ+mavkBk4pAiaEVcfsS7sew4yB/QMAj19Ru9sZQweyB2SD1fWQn6k5YIilGs7cA458acEcPDzrt/ik7nH6tuEtCl4Mcb/QHgjwu8IxOdOVLjIF9cegoyCSa8EcUm0pxAL6NH9jxPxAUtLyDoejd8CDxAJQ27GS3Q8t+WDlwAA8yCg0LkEEIpnQr13W3oPgJA== 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=dZgYgCu1JLqXiiyYulAcoQisO2Ajfjt3+N0Xuc1NFeo=; b=AGU3qhg2zqg+tOpKz6v2NS42vj/Bq+BEnOqsPBqt35eQLvTRo5ensHAWKEsEFk0TQOfMzla5cMGVGbYtrOeBzRNzfMQNw/CgvJAejN86EG20DFp27eeVjWJPwhHDTOSBWJnpELY8KssbWVLWFyfVefXKkrBGVvikPbVeO0Q2MkLUVeWq6S7Zj7m4HfQoaW9ivMnFmp+q7iLCeEWT3c56rkXKMFAvQQvnp6rRNIzfPKLWTfuc+Goarbuy9Ne5rn8hqb+xhhCpugDy6mJuE0a54Uxw79wNfZGsEdhkToksSCaUdJLV87g+7ACv7ELLeJ1W5NhdGVoDHiEwj1MhRPWbgw== 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=dZgYgCu1JLqXiiyYulAcoQisO2Ajfjt3+N0Xuc1NFeo=; b=uhc2tI8jO9Zb7hPKSlBhlhutf3l6805lNFjZ8labWQdL5hssRvEaiowuSyCUyQfs4aHmZDV6GYrba09GB6xPnbUMOpzrhDIsBKCfpkfHr2IJRsUOlvnGLLXZKsRFRw6tpdKmYKshGAVo7KSqbsYMN5b9DvU+ibWrPciCWcuZD506AVBCdhlJJR189s9ZS7JKY+8/FtvrDCclLn7f8uKksJ2cMGv9ze9sw0u2412LoVH3qof6B9+ZUPokbK+0JARLuvYlN/S8yQ0PC6G0fleMYWtPCqoDLQpVbUm7qequo7qdhgIPLtyVWFCBO6vNCGDaOG+sTMKW6rO3wQs+ka8n5A== Received: from SN6PR16CA0045.namprd16.prod.outlook.com (2603:10b6:805:ca::22) by PH8PR12MB6987.namprd12.prod.outlook.com (2603:10b6:510:1be::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Wed, 29 May 2024 11:21:30 +0000 Received: from SN1PEPF0002BA51.namprd03.prod.outlook.com (2603:10b6:805:ca:cafe::e9) by SN6PR16CA0045.outlook.office365.com (2603:10b6:805:ca::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.18 via Frontend Transport; Wed, 29 May 2024 11:21:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002BA51.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Wed, 29 May 2024 11:21:28 +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.1544.4; Wed, 29 May 2024 04:21:17 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 29 May 2024 04:21:13 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" Subject: [PATCH net-next 1/4] net: ipv4,ipv6: Pass multipath hash computation through a helper Date: Wed, 29 May 2024 13:18:41 +0200 Message-ID: <20240529111844.13330-2-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240529111844.13330-1-petrm@nvidia.com> References: <20240529111844.13330-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA51:EE_|PH8PR12MB6987:EE_ X-MS-Office365-Filtering-Correlation-Id: 1749f955-901a-458c-9120-08dc7fd17c3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|36860700004|376005|82310400017; X-Microsoft-Antispam-Message-Info: qqUy5MHoqkIq1ABZXTS3SqYf5zbiLG84LliTFEdTk6LlLRip4WdjdSVguN9/8WkaQ1l+Itnv5LVccnxNMxgC+bYTPxlrMjYQmfOYGtGciGlwhvkI2XXlTgy9oS4qJOU7Aj1V7wB6Hlvr5Zyi0DOB/cFtJFFpY0Bq9fxlTgLDVUGPH7MVeEuFt1IMhOxrtcpwaOn/peEvisX1B1utmxCTe6IlGMG6A+sixEQvaXOfactDsH63nHY2ysasoOxRZDm2vwDIGSOAjjHdz9cuDN3WkApIpuv03+yqx0VgEcO9cejZ+Rk6Cdj6JdXFdI8SF2SQArKCXnjHv1875BlsRYufXMnMg37F28TQIiV2igkzVTLQHz+RCnjkEpK5njs1gZ8lhsaEMBJs3k8vp+xueulKQo3VIsz69bBm6NiwY0nTZUNWxcVLfoL89d2IYMn02Yo+Ag1Xacn/jKlUEoSH319QsoUbNrzBXs+YQ4PjExAivjAhvz1h5Dh/lYrRhrA0U7gIVEi5MX3gAsh9FCCD4elOUikZagBP51Fp+WJTfW1cMKDGQD+KCKsoIslWRZ1Ulbpys8DwqQvhMfz4VJj+sRkJItJLcJFpzgi7S2dcuwWmDbEFxuAipNNH/jelLYvI62NY6z1PArTljrxj57R8yPX2I7yVGkX0T9+YeiRH5G0tIJSSdOfoSmS/LkoF7mgZViNIcakMInMkm0C/ARn5HlCLI6sraQGhPTAAfMFxCy9RWrKrOLDJXPFh0VfA1ZmOCIbOhkn6rQKnSLI6+oSSz1LhGgBTZ4pUP8DYv3J7FpDHQteQ9SFomgtXAgwacAA409tCcaKhbrhdzEjNTSoWX2pgUCII7k9r5W0LfkLZHcwyCfe9RwsBfapJbVjemmdO595IlBFZWw59lxhyz231xurmJxNhDF6p9O7H7+z0+9osf3W7PiPuiyk1EP5O4PZO95KZVcLS5ioUTGvK9qd7SRL8/febKXd/RBXUiHg8/SN7uFtPX+dlHMIqs5lQsgyduIZ53QxEadHCQbV7NaszC/AErvV7FSfRBQ0Ief1kPny/dUpxb2t933xP8m0mQP+7RL7q4rRlPUHBJD3fhRJmgIGsQ61VW6fcD5ZIwKUw7ETH/A38aPjXgoD4sjf+MpEwn33eI3yGfgBMf82AGEDBENMRBm5x6oagudSZDffq2oL5JI1SlaSUDCgguVXa2/YWmkSyCIDM/8O1nEATcOIjJYP/HdFPBk3Wg67+usJpOXQ7uqYu4vOBcdJxAKC42bs5A9r/62aio6htP4UJO3kzKHG7GbjN4J9jLh3RY5KN3q1CnkHwSQgxPDE+H6aYebkQzwKt3mFK7+9HWbmjTzbr1nBPQhGkcl9p+JGXqU/JeXWmow3cVpxHVsqR9QtIyyubKuIl 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)(1800799015)(36860700004)(376005)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2024 11:21:28.7532 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1749f955-901a-458c-9120-08dc7fd17c3b 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: SN1PEPF0002BA51.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6987 X-Patchwork-Delegate: kuba@kernel.org The following patches will add a sysctl to control multipath hash seed. On a system where the seed is not set by hand, the algorithm will need to fall back to the default system-wide flow hash. In order to centralize this dispatch, add a helper, fib_multipath_hash_from_keys(), and have all IPv4 and IPv6 route.c invocations of flow_hash_from_keys() go through this helper instead. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- include/net/ip_fib.h | 7 +++++++ net/ipv4/route.c | 12 ++++++------ net/ipv6/route.c | 12 ++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 9b2f69ba5e49..b8b3c07e8f7b 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -521,6 +521,13 @@ void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig); int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, const struct sk_buff *skb, struct flow_keys *flkeys); #endif + +static inline u32 fib_multipath_hash_from_keys(const struct net *net, + struct flow_keys *keys) +{ + return flow_hash_from_keys(keys); +} + int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope, struct netlink_ext_ack *extack); void fib_select_multipath(struct fib_result *res, int hash); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 5fd54103174f..daaccfb37802 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1930,7 +1930,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net, hash_keys.ports.dst = keys.ports.dst; *p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION); - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 fib_multipath_custom_hash_inner(const struct net *net, @@ -1979,7 +1979,7 @@ static u32 fib_multipath_custom_hash_inner(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT) hash_keys.ports.dst = keys.ports.dst; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 fib_multipath_custom_hash_skb(const struct net *net, @@ -2016,7 +2016,7 @@ static u32 fib_multipath_custom_hash_fl4(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT) hash_keys.ports.dst = fl4->fl4_dport; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } /* if skb is set it will be used and fl4 can be NULL */ @@ -2037,7 +2037,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.addrs.v4addrs.src = fl4->saddr; hash_keys.addrs.v4addrs.dst = fl4->daddr; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 1: /* skb is currently provided only when forwarding */ @@ -2071,7 +2071,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.ports.dst = fl4->fl4_dport; hash_keys.basic.ip_proto = fl4->flowi4_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 2: memset(&hash_keys, 0, sizeof(hash_keys)); @@ -2102,7 +2102,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.addrs.v4addrs.src = fl4->saddr; hash_keys.addrs.v4addrs.dst = fl4->daddr; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 3: if (skb) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index bbc2a0dd9314..9d561b9f0f75 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2372,7 +2372,7 @@ static u32 rt6_multipath_custom_hash_outer(const struct net *net, hash_keys.ports.dst = keys.ports.dst; *p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION); - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 rt6_multipath_custom_hash_inner(const struct net *net, @@ -2421,7 +2421,7 @@ static u32 rt6_multipath_custom_hash_inner(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT) hash_keys.ports.dst = keys.ports.dst; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 rt6_multipath_custom_hash_skb(const struct net *net, @@ -2460,7 +2460,7 @@ static u32 rt6_multipath_custom_hash_fl6(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT) hash_keys.ports.dst = fl6->fl6_dport; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } /* if skb is set it will be used and fl6 can be NULL */ @@ -2482,7 +2482,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6); hash_keys.basic.ip_proto = fl6->flowi6_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 1: if (skb) { @@ -2514,7 +2514,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, hash_keys.ports.dst = fl6->fl6_dport; hash_keys.basic.ip_proto = fl6->flowi6_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 2: memset(&hash_keys, 0, sizeof(hash_keys)); @@ -2551,7 +2551,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6); hash_keys.basic.ip_proto = fl6->flowi6_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 3: if (skb) From patchwork Wed May 29 11:18:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13678721 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2053.outbound.protection.outlook.com [40.107.243.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59BD217DE37; Wed, 29 May 2024 11:21:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981702; cv=fail; b=OJrtKL51YHO+AKE/mcBr7owZNhn2W463Dk9rQw8cwuiIC3RCVcF6w9ZKXNSgRcC9lBgJTYcOOqTE/45xTBWBonMFZlmaK4sWT89sDxYafu+H3l//oguUbhWwCdxdr43Re1tXJzIdmWUtxs8DpWaSvv8ISuKy3uYAqwMpnl3szt8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981702; c=relaxed/simple; bh=78YUr4DIOX54TS2ZjtIey18gr7CUo7JmbYE5LSJecNo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oEO+qyn4KT51lZk3ANWjdLisdAXgjrN9CN+t69nR14ZzAIiZ9Zh2LDlthjQOOEWd60XhYyWkfzMN0/e38Ok8VtcOVG4jjDFdXtoEW6OvHScxWAB6BAp7Kzr/QTJOJgLuJ4qe9SHlBFU/NjAlBrVZkCBscwhO52W811ENn40eCXs= 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=BS8tmEue; arc=fail smtp.client-ip=40.107.243.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="BS8tmEue" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OcyJVOTb8vwTYdKuAUd4xmaGqWi6fi6Rn8BP2XfeqpaAimcXnxa1vek7gQ2eQ0L1nqvxgc45QyiCt92ax23CWNJ4pJARpw7VTEaaZlxqxuTNgR/Li95in9yRnS41NztPJi2vUCUczG2VqK9oR3/y6H9z9cg8uuEE/XEu6SPkUtOeEZ9Ai53bLgiFL1YjD7Pj9c/Q1nuCiAbScq9VZA7YPlstG9VfuxohUIhMWQIwlDxa6CHmxqxe7x3LI4FhMY4x4CJKm/637gWW/Iu5JqGG7RfqyMDDQqukOkNsqFe0Yty9pvH7X1cAz8iP4s3pkKWMep/Ku0R44i0dxdQv5wa4Fw== 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=3hMuwaWGAHwyQ6AlcTr/S9YGiJd413bWQE+xDcdwuRU=; b=b5sO5sLRt5P69WmSL0rHmGqBza958/CCgQYin+uqcl5QS5CHM3O/s4ynC4rrFMLMjzdsGmU1QmdWwwIpJNkOVZcZwZYhggolReshTs/8rwxI1ysfWJjHcGSWjS4epmpy1yRBDNKP1z3o3AI3gcyXHZc5yT1B6jCQWYQIyzmMBPMzo3RW3wRz0anucA8Z2FKBHaoULT8VQwq8NpM1EWh++/S22QFdb7AC2buUg+wCFUHp8UuqNH/k/QmACHIylL/ph30B0huh05msIcX2bZCdjzzvaLTX4EZXMWS61AqsbrG03cXv02kPhFUPQy7VJaOh7873v8fO3Ego7TDAxomRtQ== 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=3hMuwaWGAHwyQ6AlcTr/S9YGiJd413bWQE+xDcdwuRU=; b=BS8tmEueI+7Ml1+piUKYbxHoNbVZSg7FMf0dmnfqOp8b3d6bJ3XJ/3VOAwK426BOpthb6Q6mXqSM2FxN3VlrVNJIq8gFAICjNVth/H0Ju2VgP+Tf2e+jJaPhdUXMQxXvr71PS/bkctqdZeLWyUc4MIEU0OFyyTxmBS6obJ5p8D+qzwE7K8RQ6O6MZ6mjzK5opg5rFgyfT5sjst61dkyoYEzJ6VDtMMyNlFSTke7jWyayd+oGzH5D7W91d/KHAtPQOaKETbxi0EF0G6PlsarMHL5cWocYodMyNOpjvxiPFivx5gdjD5Ltgf46roVrWFDa5CXkCGQMACaH71RT/DT1+A== Received: from BY3PR05CA0053.namprd05.prod.outlook.com (2603:10b6:a03:39b::28) by MN6PR12MB8489.namprd12.prod.outlook.com (2603:10b6:208:474::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Wed, 29 May 2024 11:21:37 +0000 Received: from SJ1PEPF00002314.namprd03.prod.outlook.com (2603:10b6:a03:39b:cafe::ec) by BY3PR05CA0053.outlook.office365.com (2603:10b6:a03:39b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.20 via Frontend Transport; Wed, 29 May 2024 11:21:36 +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 SJ1PEPF00002314.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.7633.15 via Frontend Transport; Wed, 29 May 2024 11:21:36 +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.1544.4; Wed, 29 May 2024 04:21:22 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 29 May 2024 04:21:17 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Jonathan Corbet , , Simon Horman Subject: [PATCH net-next 2/4] net: ipv4: Add a sysctl to set multipath hash seed Date: Wed, 29 May 2024 13:18:42 +0200 Message-ID: <20240529111844.13330-3-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240529111844.13330-1-petrm@nvidia.com> References: <20240529111844.13330-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00002314:EE_|MN6PR12MB8489:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c07ed15-de43-4e72-3817-08dc7fd18091 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: wiqUkWlV5b3ADbGzcQw+hA2ge4jkISMZTaWAw5WKsWqbQAL+8xJvVA6kxxYvvbZuZE4SwkK9C/f1yPMqPKUmRAOdbiL5+Zw9J7dkMWiC4w2PuM19QlhlI1ZVG9oesX591Of8yy0/y7St/QJT+E605WSZODqWuQyfW1aIBMnWRClTQIxUpjtbAf2+FGegslcSgTyRUUYrA+0YKV4O/KhYtKQWjGxrHjdPi0wlTnGhbrXMeXy3vpVMbqCK5k4Y90Gc5DvI2m7iOl6LCNxUxEOWo0+tgFumSS0Sq+jgE/OiOyKhRC/jNJ0B7yIGnPxMzSbSfQ8CSRRsmQRb491cQjs+sRdEU6hl4GC9+//qiUTMwJUmWzViIv3mwj6cGEmM7ziJzc2qQf9zYW9XdbkZZ0z40KZR0lzSojhdjZ0TjO5JHhjmaZ7YUoVaKU8v9xdAkQrHzh7IIKJbpYNyH5XQ/h8KuWOK/Sp41cZv8OszYUcbI3DSTio9t6SV1Hj+SX49LuonWILpeSsuoXRaOjwqLteVHmXPg3DrNGHKU20KcQ6S5SncP3eV+kuCEfwS9KfPb/Rf8/j7cXHs1CR4F53Rf5lEfXJxRdSeSM2LbzBxpIwFLgaL0sA49DW2rpAKjhUlNLIp9rxCF0GON+i4/nAB9/88O32srCdm+QVwMjBSFjXspbRGGK6jHf4RsEjuDMivxYW2X5crAQe+HEtC0PSvTXrOF3AdoP1oZSuNv63dHtSqf8AWXsmTbXvN+edj9oEMLbV9oP2c8QYrHQItyuf/VD6oYuM2+kcw4LGUzmRr65Ld38H6ZWTPPeEPRWCLL4R9a9Np1tAkHzd27nBtRyAF3oQrjupGg0s5NPn24QoCg6WtQqaI2aatmLrhImGBfea4RYW99SQFmP/wkyd3+0wFDNJspqXh01crkhWPYGxqE3uWt+FrqnBrAM+8An1pWTZIjhuE42t1Lf6fFOyVNO6dz1c4ouj/Tmalr787VVef7ebH1QtXM0zJk2zDVldfAiLiKgLKAnbKJtMJMEPZTREAxwfdKgmQE4vGZnBsxTCM50Zk/p53AzQzQlc7wAU/8zW3yqMdtfmLK5BVly/C2S717DaKEoegJyVVjpqeUhMw54Co+y0RuZ9iYDHAyQh1xchiF0UtgP5oS8P3c3Iw1SM1eWFrkz28E/7QT4hn6bD9cKeE7LmOWTOTeRky1W3ErK+67WW7qihYGFclOFgaRrzDg7vdrGHoqV3X310flhk30pROuzuHbxiF8Hzqfh2sNpovpC3YVKifaBLn/knyQzsNdOMAUobo6Xzg7KuOQkduZeC3KqwrzxwfELEAVmpYSCX4NY9c4YKLkgJjhK3RI4pjCH1cCr2OkgZCLpo8AkAaucp7zA8= 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)(1800799015)(376005)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2024 11:21:36.0254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c07ed15-de43-4e72-3817-08dc7fd18091 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: SJ1PEPF00002314.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8489 X-Patchwork-Delegate: kuba@kernel.org When calculating hashes for the purpose of multipath forwarding, both IPv4 and IPv6 code currently fall back on flow_hash_from_keys(). That uses a randomly-generated seed. That's a fine choice by default, but unfortunately some deployments may need a tighter control over the seed used. In this patch, make the seed configurable by adding a new sysctl key, net.ipv4.fib_multipath_hash_seed to control the seed. This seed is used specifically for multipath forwarding and not for the other concerns that flow_hash_from_keys() is used for, such as queue selection. Expose the knob as sysctl because other such settings, such as headers to hash, are also handled that way. Like those, the multipath hash seed is a per-netns variable. Despite being placed in the net.ipv4 namespace, the multipath seed sysctl is used for both IPv4 and IPv6, similarly to e.g. a number of TCP variables. The seed used by flow_hash_from_keys() is a 128-bit quantity. However it seems that usually the seed is a much more modest value. 32 bits seem typical (Cisco, Cumulus), some systems go even lower. For that reason, and to decouple the user interface from implementation details, go with a 32-bit quantity, which is then quadruplicated to form the siphash key. For locking, use RTNL instead of a custom lock. This based on feedback given to a patch from Pavel Balaev, which also aimed to introduce multipath hash seed control [0]. [0] https://lore.kernel.org/netdev/20210413.161521.2301224176572441397.davem@davemloft.net/ Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Cc: Jonathan Corbet Cc: linux-doc@vger.kernel.org Cc: Simon Horman Documentation/networking/ip-sysctl.rst | 10 ++++ include/net/flow_dissector.h | 2 + include/net/ip_fib.h | 19 +++++- include/net/netns/ipv4.h | 10 ++++ net/core/flow_dissector.c | 7 +++ net/ipv4/sysctl_net_ipv4.c | 82 ++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index bd50df6a5a42..afcf3f323965 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -131,6 +131,16 @@ fib_multipath_hash_fields - UNSIGNED INTEGER Default: 0x0007 (source IP, destination IP and IP protocol) +fib_multipath_hash_seed - UNSIGNED INTEGER + The seed value used when calculating hash for multipath routes. Applies + to both IPv4 and IPv6 datapath. Only valid for kernels built with + CONFIG_IP_ROUTE_MULTIPATH enabled. + + When set to 0, the seed value used for multipath routing defaults to an + internal random-generated one. + + Default: 0 (random) + fib_sync_mem - UNSIGNED INTEGER Amount of dirty memory from fib entries that can be backlogged before synchronize_rcu is forced. diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h index 9ab376d1a677..a5423219dee1 100644 --- a/include/net/flow_dissector.h +++ b/include/net/flow_dissector.h @@ -433,6 +433,8 @@ static inline bool flow_keys_have_l4(const struct flow_keys *keys) } u32 flow_hash_from_keys(struct flow_keys *keys); +u32 flow_hash_from_keys_seed(struct flow_keys *keys, + const siphash_key_t *keyval); void skb_flow_get_icmp_tci(const struct sk_buff *skb, struct flow_dissector_key_icmp *key_icmp, const void *data, int thoff, int hlen); diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index b8b3c07e8f7b..785c571e2cef 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -520,13 +520,30 @@ void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig); #ifdef CONFIG_IP_ROUTE_MULTIPATH int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, const struct sk_buff *skb, struct flow_keys *flkeys); -#endif +static inline u32 fib_multipath_hash_from_keys(const struct net *net, + struct flow_keys *keys) +{ + struct sysctl_fib_multipath_hash_seed *mphs; + u32 ret; + + rcu_read_lock(); + mphs = rcu_dereference(net->ipv4.sysctl_fib_multipath_hash_seed); + if (likely(!mphs)) + ret = flow_hash_from_keys(keys); + else + ret = flow_hash_from_keys_seed(keys, &mphs->seed); + rcu_read_unlock(); + + return ret; +} +#else static inline u32 fib_multipath_hash_from_keys(const struct net *net, struct flow_keys *keys) { return flow_hash_from_keys(keys); } +#endif int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope, struct netlink_ext_ack *extack); diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index c356c458b340..1f5043d32cb0 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -40,6 +40,14 @@ struct inet_timewait_death_row { struct tcp_fastopen_context; +#ifdef CONFIG_IP_ROUTE_MULTIPATH +struct sysctl_fib_multipath_hash_seed { + siphash_aligned_key_t seed; + u32 user_seed; + struct rcu_head rcu; +}; +#endif + struct netns_ipv4 { /* Cacheline organization can be found documented in * Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst. @@ -245,6 +253,8 @@ struct netns_ipv4 { #endif #endif #ifdef CONFIG_IP_ROUTE_MULTIPATH + struct sysctl_fib_multipath_hash_seed + __rcu *sysctl_fib_multipath_hash_seed; u32 sysctl_fib_multipath_hash_fields; u8 sysctl_fib_multipath_use_neigh; u8 sysctl_fib_multipath_hash_policy; diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index f82e9a7d3b37..7b3283ad5b39 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1792,6 +1792,13 @@ u32 flow_hash_from_keys(struct flow_keys *keys) } EXPORT_SYMBOL(flow_hash_from_keys); +u32 flow_hash_from_keys_seed(struct flow_keys *keys, + const siphash_key_t *keyval) +{ + return __flow_hash_from_keys(keys, keyval); +} +EXPORT_SYMBOL(flow_hash_from_keys_seed); + static inline u32 ___skb_get_hash(const struct sk_buff *skb, struct flow_keys *keys, const siphash_key_t *keyval) diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index d7892f34a15b..18fae2bf881c 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -464,6 +464,72 @@ static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write, return ret; } + +static void +proc_fib_multipath_hash_construct_seed(u32 user_seed, siphash_key_t *key) +{ + u64 user_seed_64 = user_seed; + + key->key[0] = (user_seed_64 << 32) | user_seed_64; + key->key[1] = key->key[0]; +} + +static int proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed) +{ + struct sysctl_fib_multipath_hash_seed *mphs = NULL; + struct sysctl_fib_multipath_hash_seed *old; + + if (user_seed) { + mphs = kzalloc(sizeof(*mphs), GFP_KERNEL); + if (!mphs) + return -ENOMEM; + + mphs->user_seed = user_seed; + proc_fib_multipath_hash_construct_seed(user_seed, &mphs->seed); + } + + rtnl_lock(); + old = rcu_replace_pointer_rtnl(net->ipv4.sysctl_fib_multipath_hash_seed, + mphs); + rtnl_unlock(); + + if (old) + kfree_rcu(old, rcu); + + return 0; +} + +static int proc_fib_multipath_hash_seed(struct ctl_table *table, int write, + void *buffer, size_t *lenp, + loff_t *ppos) +{ + struct sysctl_fib_multipath_hash_seed *mphs; + struct net *net = table->data; + struct ctl_table tmp; + u32 user_seed = 0; + int ret; + + rcu_read_lock(); + mphs = rcu_dereference(net->ipv4.sysctl_fib_multipath_hash_seed); + if (mphs) + user_seed = mphs->user_seed; + rcu_read_unlock(); + + tmp = *table; + tmp.data = &user_seed; + + ret = proc_douintvec_minmax(&tmp, write, buffer, lenp, ppos); + + if (write && ret == 0) { + ret = proc_fib_multipath_hash_set_seed(net, user_seed); + if (ret) + return ret; + + call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net); + } + + return ret; +} #endif static struct ctl_table ipv4_table[] = { @@ -1072,6 +1138,13 @@ static struct ctl_table ipv4_net_table[] = { .extra1 = SYSCTL_ONE, .extra2 = &fib_multipath_hash_fields_all_mask, }, + { + .procname = "fib_multipath_hash_seed", + .data = &init_net, + .maxlen = sizeof(u32), + .mode = 0644, + .proc_handler = proc_fib_multipath_hash_seed, + }, #endif { .procname = "ip_unprivileged_port_start", @@ -1557,6 +1630,15 @@ static __net_exit void ipv4_sysctl_exit_net(struct net *net) { const struct ctl_table *table; +#ifdef CONFIG_IP_ROUTE_MULTIPATH + { + struct sysctl_fib_multipath_hash_seed *mphs; + + mphs = rcu_dereference_raw(net->ipv4.sysctl_fib_multipath_hash_seed); + kfree(mphs); + } +#endif + kfree(net->ipv4.sysctl_local_reserved_ports); table = net->ipv4.ipv4_hdr->ctl_table_arg; unregister_net_sysctl_table(net->ipv4.ipv4_hdr); From patchwork Wed May 29 11:18:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13678722 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2081.outbound.protection.outlook.com [40.107.101.81]) (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 6AE4D17F367 for ; Wed, 29 May 2024 11:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981703; cv=fail; b=Dbh30U09GH/By4pUk3ld5yRRP/38fHykQ10Bmd9KZ6KeEX7+87W2TLxWlpL3SYTjYGwpvF5UE6bdlJwj/IY3bg7OJMzt5GbdFoXAKtiTR6oRWgGqjxu3yuhRIZlsxctwyo1gtegvo0YVcBTk5dtkWQKsru2kDxluGgYkuuHej88= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981703; c=relaxed/simple; bh=jjrFTJYIs4xQC98y4+qPZnF/yJGc+ueaiXyJ2sOEc2M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TDmSBecHHmbMGgo+r4WssMrGT2QxrGcS8mHA6LRJHTvtVTUorj0O7L4v0oizjX7wCfq62FfGyXOSrASSrBO2P4e0qUjjp0WvBJa3dp1B2t1ETEUiMl5VCdGPnrKwGlkpzZVWwcqnpJaHlUQYfBCanrI/1jxE/01MNPvV1zONz6c= 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=kAhRLZEX; arc=fail smtp.client-ip=40.107.101.81 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="kAhRLZEX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTtSuvBhZlqlVYoeh33d+D1YQ5Z6saWdDrugriqSqUWS7oMCfvjVANH3lXiNExLfRepg5M7n2UDn5lPvXuDetKJ7zRC1bNGDRpLem6w0P3NDDOdowKBpZ9Z7BD6x6ai9jeYkZsD5K0rNwrFqQFJgsZA8gWv88RlJDzhH9jpU0rcvjAFs6kGR3t8IVCz2ImLtIzII57J7hXaKm7AuC80e3wCTM4+djVnszRl2xYPUmugqfu2ZU8/su1kVZOE3LQWSEB4nJbf76FVWaydrLripMEXW5z26Nlc7SVOn6lrKOX+VPh/pL4deTz4SWu70mSDHzmz58Yxie5tf3IALHYsC7g== 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=pe5LIqegN5SmcDeFtsyywVi2ETeNYWoOcMo9na/Maco=; b=D8G13PvuDMaSQbpdA3NorFew6PeDs2skRPQta2LsTyCqOVuoWB3Q7qImvRF0fHAK88yco4CHyPWrQaO565tCcPDInnJkgi4cslhVr1FCsIgL3h60PJ8n0mFA+C/54rpKHeSWbdQ8/KcHpq0AJQTxi0+Sg73XIdmqQU5uYNeSetJkQBooqRYKrG1NWp0m0bnW+3fpI30I9AO1bid9ILzgZr3EQ94yQrlqSjOFr356K/+1EB5FOrjaQB1AVGbg033VFvF78cRT/GqaG0+pp//gu/Sx+DiYrt3MUkrb4oT+xxEcnQSD2XMdY59yf2aBCeA+LTdQGYFpwT4CgUm6FfFs4A== 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=pe5LIqegN5SmcDeFtsyywVi2ETeNYWoOcMo9na/Maco=; b=kAhRLZEXlUcXdzlXIVGnJo0xKrbRj9iwOVMcwwPltbp42y2VeMZ0DY+pFzdNTCb3mUXs3Trvgvz2pekq52NcSKBAlxsSGKiuFCCT/PhdfGPHVT54PwUz8Z45STP5+rR4ozYUCxgTIUOvL3Qi1kmzLHWuIjB//nW47iGD1SNfTKP2vX+WQ+0br/Oihar4u0wPy2FkrtKPW8jZouJg6YODKEBdAvv1MLNXcBk8f8sW+pQHZrGEU5iGtUSQeEz6+b7RxJFuPcFPTSEy8/d/0yKFSrp7MeJqFQAE610QceBZhbgN0mbjT/R/6p/964o+1aZ7h8WN6Tc7q8qIi01qxtYfDA== Received: from PH7P222CA0019.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:33a::22) by BY5PR12MB4291.namprd12.prod.outlook.com (2603:10b6:a03:20c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.19; Wed, 29 May 2024 11:21:39 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:510:33a:cafe::1d) by PH7P222CA0019.outlook.office365.com (2603:10b6:510:33a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.20 via Frontend Transport; Wed, 29 May 2024 11:21:39 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Wed, 29 May 2024 11:21:38 +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.1544.4; Wed, 29 May 2024 04:21:27 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 29 May 2024 04:21:22 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" Subject: [PATCH net-next 3/4] mlxsw: spectrum_router: Apply user-defined multipath hash seed Date: Wed, 29 May 2024 13:18:43 +0200 Message-ID: <20240529111844.13330-4-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240529111844.13330-1-petrm@nvidia.com> References: <20240529111844.13330-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4B:EE_|BY5PR12MB4291:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e47c9d5-49c0-42ee-31ee-08dc7fd1824d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: Tw6hNM5g0+fXAfQ0JlUKvY3oGd/VcQI/YiBnwyPKGBi0+k89wmGRu/sByi4RRubrV1NyUt3utOduQJOsjpwobOQLNqTuaJMV4ora6jn2G3D405+gBTUDdDvB3gFkXSSneLgfa+XkCEVWC4T3uMhWHouODlhassOgFnGh9z/rVBhGCeP8jmyj6zn9rcCKW0WSYz4VQdFWU+KLks4P8a18FyzY1r0VcAhY8bpJbV4gul20IG59N404HzYzXSWq76LF9i9smZ8ZX2iQGsFLJYZr7VcHmF4SF2PZ+/Q9ZJlZuoA2GUqoSqQXVttLV/RL844MMFCIfmh5pQ2A0boqsFW7SyUf9x4ulmaQzUxWVFd1sVe+c6lyLY1G2Vu1vlmafkR/LRxLLiKQD8MDsNnWLruxqNV2P658UPTZ9MsuOaWURRusF/I1TTxu46UdpxqGNAPlI17/WBGsq80j5SmS0WenfHBYQWTZ23joNjKpPH9lN59BrdBarfeeuSryUPIMaxJuvEraxl32t+04XwhZRmlAJs1sd6/JG3jCxNbHEHbQkaReefPB6MBsgXZX3WF6GF6s9LSBPiU/8rpL7iEFtIK4fA9LB2q62DGBSx2uATxezSdUYCAFIpJaEtM2UhWC+h+nf1sFOrSMFQBP4HvVzg57bWRFWAgQ2d5x+vyM6PwqVWBMFyXd8ceDEk9IXSik2tUPJ6cxtRw6yLEjiJ+erciNmQhmp7Ht7t+WlixcOlheZGut7MWtCHjStYffFrv7MGURkqsaTD11mH0opVMqZu+7odbeWG0pP715SgMbsNlT2mF1fUY3A3SiUvCWGeE4QSZj+bSc6ZO5NeiQk2qldU6yJxtuOULMNR9jFAsq2fneVKbZAnyNuox9izuup7oAL538YiFA5FckqPkN7rgNg76E/GpEVxQR03uJOtgj8sbRCdUL3j6Sr2GU50uz5RsLThuzQdOm0WyBEW8me6AyDKOXXoZ6mzMrwx74FU5FVqW0Bv+D2+rh/cJ03/GOPynZsORdWC0AM36hKO256CEjQhQC3MyDzlUBKxv/MPKKisXVlAjtmqZVevx+H2eC1JAhKG2G1UsYQ8g0hBcydwEES9E86hg8ZkaQp4AFU61le1hm7kPWFjhur2pXT46H64wCM6P9CcB2Ob6uKDwlUMkosOWB1VnKhaK9HwdHWA1/92Z8KJcWPMWH5rI6cFxmXUeCKRPBOKeUuuJcSQSIZFEfW3JAHc3q8ofyekoV/+yZi1gmf2osa2XryAywhtAl9ga1B04tlMxWeBjbB0DDM/9mQdZ1EXEH0+Qi+kGKGklT11O4YGhQplX5W01LE4G19Bp7LSB9L6uPaEYoaOxTps8H6dXVq4WPcMk6tFjlitQGPS7oIM2ILhA+1Nwijtv1g4hF+nOm 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)(82310400017)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2024 11:21:38.9351 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e47c9d5-49c0-42ee-31ee-08dc7fd1824d 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4291 X-Patchwork-Delegate: kuba@kernel.org When Spectrum machines compute hash for the purposes of ECMP routing, they use a seed specified through RECR_v2 (Router ECMP Configuration Register). Up until now mlxsw computed the seed by hashing the machine's base MAC. Now that we can optionally have a user-provided seed, use that if possible. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 40ba314fbc72..e5b669f0822d 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -11449,13 +11449,23 @@ static int mlxsw_sp_mp_hash_parsing_depth_adjust(struct mlxsw_sp *mlxsw_sp, static int mlxsw_sp_mp_hash_init(struct mlxsw_sp *mlxsw_sp) { bool old_inc_parsing_depth, new_inc_parsing_depth; + struct sysctl_fib_multipath_hash_seed *mphs; struct mlxsw_sp_mp_hash_config config = {}; + struct net *net = mlxsw_sp_net(mlxsw_sp); char recr2_pl[MLXSW_REG_RECR2_LEN]; unsigned long bit; - u32 seed; + u32 seed = 0; int err; - seed = jhash(mlxsw_sp->base_mac, sizeof(mlxsw_sp->base_mac), 0); + rcu_read_lock(); + mphs = rcu_dereference(net->ipv4.sysctl_fib_multipath_hash_seed); + if (mphs) + seed = mphs->user_seed; + rcu_read_unlock(); + + if (!seed) + seed = jhash(mlxsw_sp->base_mac, sizeof(mlxsw_sp->base_mac), 0); + mlxsw_reg_recr2_pack(recr2_pl, seed); mlxsw_sp_mp4_hash_init(mlxsw_sp, &config); mlxsw_sp_mp6_hash_init(mlxsw_sp, &config); From patchwork Wed May 29 11:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13678723 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2051.outbound.protection.outlook.com [40.107.220.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 696EE16E89B; Wed, 29 May 2024 11:21:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981710; cv=fail; b=Ukm1ddDRSBRlGLewDAPjwMJ2clPXG4DnaT9b2JqlIOIi98kDYvZAMkxtaFkOkOUeyU8F4QUIIQJbRYHB2TuyL94zhq/8y4coacl4oWzxW0qmbMX2n/C60ylshI9ayutCan/fwgM5eiKyvsxi1zgkecHcacGSEAL4u919cnEIT/Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981710; c=relaxed/simple; bh=dHTyDr4TplIayyKkWv5mluQu6AGAz7jAy+hgFtRqvXM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XGeEC6OFpGc0xTYREDbrO23I0jmuDjm73qZg3RbBHGkBh9tYtQAPrcS0cJvsV6H5gc4lTyD2hqerEmhKgPFIu6UhitoxGTuMYnb5t/1OtO0sBFN8TIrBQI/LA1mYCS7ivP0AKiWIYARI5RNbap1wqO9aFG5tmJCxyb0ERxoD1es= 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=miHTnshf; arc=fail smtp.client-ip=40.107.220.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="miHTnshf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NIk2mxKFa4M7LvD3y0BYrw7LP2bbVnghb37GX88GKWXwqos/jT0vg6PdT5NPDvNDH1r37P2I/gXAycr6w0pbK8XzymfGVBJZDrkS4vd1JiLO7dnXcCEHOaX9sqtDf6ZGhIizQGdew3PtyTqolN464Znyv/BAYw/vMQRPIc8H7gAsT86wI/QEHX2pQLcH6ue1oFGvYMCwj2bC0z0d4HcAzyY5MK8s54du5VPXP6kyyfDY2CEDovLPl5gYT4TSUpLlGCacFA3D2CZi0zdNz+FWN+N5bWNs/Ib5KRbzTvh2cmtGc9onhcY65l5GFge3ik4/t5nnDecu/VwZTrozA8DNcQ== 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=p5U0+PpsHh78Bp9LTwwLCWRzC3SIk8CvM9kMisVcwaU=; b=I/UR94s07k6aS/ENiB9M65rCDTkPO1ux3qKDgRLpQ+3Tq7isPF659BMsEcGiLQs72vbgNzAchg3rWkrVLvTLtVmTwWu7BxGm8+frooIfNI2WIXN35Dkr1Dvlmp2mljDkouKOn2SscvdUr806qFrfksN5GWo9kbvUOJZD5tNQQzCNoYdFPk+/SY/YUF5CTaxa/EcMqAN5I5gHiEdmQog7NNplnlTbEdFjs+kcCkdQO6a4okcQNLwFlvyCgtdNMYVD01wXdKzFjtQ+/TwDeAztYEbshf/pUejroDbjXXMYHl88x2UJt4IuCBMoitXGCERQfIoe6SjnXcfkyPnVUoFxtw== 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=p5U0+PpsHh78Bp9LTwwLCWRzC3SIk8CvM9kMisVcwaU=; b=miHTnshfoTiGBgk0HqBvWc1wa4TXIg/1nu+JutJnVCo2+jNRnUbzA+pjFxoRNzsn61r5ZQ1w1Fchpu0vvsOY/+QMd5gMa0IdYwpap+0Woa6KYxoxWqF8n3Dr8+Qr4ovWMSrLIkafq1IOTTzF0FjFjuD+sk/8rfgLZEIQ7HYe3KeC3QfHjceB2Xt197APwHADYMGJm+4LKQtIma7gECAxCqLJZLvEvo5zORBxsYlgFPQFkeATPtYsLEIM8sTM5jyAaOqDY78Tr1rQfKVc6qmETL+kStoPNfRucpdXkw67iqFTHWqN7O/wDn3zJ5UAoTZGqmB0lLgrmVx9cVINNEH+ig== Received: from SN4PR0501CA0034.namprd05.prod.outlook.com (2603:10b6:803:40::47) by DM6PR12MB4283.namprd12.prod.outlook.com (2603:10b6:5:211::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.30; Wed, 29 May 2024 11:21:45 +0000 Received: from SN1PEPF0002BA4C.namprd03.prod.outlook.com (2603:10b6:803:40:cafe::45) by SN4PR0501CA0034.outlook.office365.com (2603:10b6:803:40::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.18 via Frontend Transport; Wed, 29 May 2024 11:21:45 +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 SN1PEPF0002BA4C.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Wed, 29 May 2024 11:21:45 +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.1544.4; Wed, 29 May 2024 04:21:32 -0700 Received: from localhost.localdomain (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 29 May 2024 04:21:27 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Shuah Khan , Subject: [PATCH net-next 4/4] selftests: forwarding: router_mpath_hash: Add a new selftest Date: Wed, 29 May 2024 13:18:44 +0200 Message-ID: <20240529111844.13330-5-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240529111844.13330-1-petrm@nvidia.com> References: <20240529111844.13330-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4C:EE_|DM6PR12MB4283:EE_ X-MS-Office365-Filtering-Correlation-Id: c78052de-b3f5-491e-451b-08dc7fd185f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: G3N+tNPzQP6nTEI5c4oRj8mHFwRnUPl2HcQ7tU2c30HIRMTKdMgwFjp4l5bavOWGgbfvz5t9XJOb/bWkx4JFoafk2vWJVw1Js3hoJ0O7Vq+zKjWnowUgWtmgRMMX3Cp3ZJG01W/PfYxVTFM2G4epCbiEZu6svNzksdELx+vhhyZf14ek74K3hfwvxSlyvzza+nmQghXpJpjuC+3HqFH/wH0sY4vMBmnVxjx3O3E0TL/8xwLe3z3BTyqZmLQMZcY8zNFRp7QtASzzgBXUvTJtYwkeFfi/zcBsuM9chqOwmcbuN3PWkQwqHuwGYVEpIJyuRgEnq5LMPtIvYwcdjq5DB6lD54fYesi+3UWBaKksCgFo/lOZsDMW36a0iKcmF79AMTlkbKw/tUfCv3pNl3SHv3M+d7IB1xYGQzDjvcYiVyPLqTI6euI5JbJlOT+hCj4gw55oGSQJ44/F/qFr8Te+y22cmCxRuX1y/mFvwrvnJrtVEEfBFJBfzTZZuP+Q7ZZdvv4WcYC0AInAD/iCPMISPz1yLFcD5+BkHFTCf0vczpddjfwXrKfh9LmkDopgilLRoJ2qPh/2iEjnUfEpToyKNbNnO4yLmIV+v/SmBeaKAQc5XVdQCTl5i5Wak95xxj3u3Ora0uIgdyhThnnfvK7ObpQCsGDpLLo9EPS8KOGgS7orOSY2Ah5JyuRVFgDiZsJjt4cbKnHd3rxy5SN2cWQP/ImbAwaXPNin1qNG3HFAvIdhJimeaUAJD/9YJWDuBZ+5xopBfg1UruFrQ9HmQe/yW276TY2gj+do6MG8E82gMCJn4POIX45alrHlXdyM23IRN8/Fqu6xmcduO1Zywi45rl7K9i2KveRrWgl1TtH7qLQgoTdnI9fu5Fu3HIqs/jJLVsQsKKtFXfr8HNrV+vHKvwY76QgWREnMXv5HoYb1rdC5zjqOyWWlmMccOQarm8bjPowNWNRQ0O/Gqge33uddJ8vs80+ORKgsqwYMi4xRcX2KOWYcJA+TPDSnIJAKxGqnwP0Cca1YTAM9g2t/lX9NXXwxSXSUlLedVRTcUMc2+kj1dhq2Jrj2fURurjfDwaWz5QJ5Y3E3Mc9C0G5skZRuIfW5RLxCXQASxdAzDTQDigV+hecazdGbejM5lQHxn6vmFcgeCVcCve9GEchLpfCFY3UkTPbBY5La0a5mylyhfSjJXYvtFxOWokDe0qhuIN66C0Yr8lP7LlcTsuHKoR6oNUE8ccVdVw8w5EA25Z6g1GLVZwzANInZX8ItIQICUkvRvSNhKCwUUzJGGJsGlxx/uq0fCyKkVhs7SgPs8xW4TW1m8veNCQrl00kT26udt64Zvife7yOmkufVSgIaj9J2C4BT6fC/43V3jZz4PYG8po4= 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)(1800799015)(376005)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2024 11:21:45.0213 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c78052de-b3f5-491e-451b-08dc7fd185f0 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: SN1PEPF0002BA4C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4283 X-Patchwork-Delegate: kuba@kernel.org Add a selftest that exercises the sysctl added in the previous patches. Test that set/get works as expected; that across seeds we eventually hit all NHs (test_mpath_seed_*); and that a given seed keeps hitting the same NHs even across seed changes (test_mpath_seed_stability_*). Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org .../testing/selftests/net/forwarding/Makefile | 1 + .../net/forwarding/router_mpath_seed.sh | 322 ++++++++++++++++++ 2 files changed, 323 insertions(+) create mode 100755 tools/testing/selftests/net/forwarding/router_mpath_seed.sh diff --git a/tools/testing/selftests/net/forwarding/Makefile b/tools/testing/selftests/net/forwarding/Makefile index fa7b59ff4029..99576d7ecbf6 100644 --- a/tools/testing/selftests/net/forwarding/Makefile +++ b/tools/testing/selftests/net/forwarding/Makefile @@ -70,6 +70,7 @@ TEST_PROGS = bridge_fdb_learning_limit.sh \ router_broadcast.sh \ router_mpath_nh_res.sh \ router_mpath_nh.sh \ + router_mpath_seed.sh \ router_multicast.sh \ router_multipath.sh \ router_nh.sh \ diff --git a/tools/testing/selftests/net/forwarding/router_mpath_seed.sh b/tools/testing/selftests/net/forwarding/router_mpath_seed.sh new file mode 100755 index 000000000000..0ef3687da8b2 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/router_mpath_seed.sh @@ -0,0 +1,322 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# +-------------------------+ +-------------------------+ +# | H1 | | H2 | +# | $h1 + | | + $h2 | +# | 192.0.2.1/28 | | | | 192.0.2.34/28 | +# | 2001:db8:1::1/64 | | | | 2001:db8:3::2/64 | +# +-------------------|-----+ +-|-----------------------+ +# | | +# +-------------------|-----+ +-|-----------------------+ +# | R1 | | | | R2 | +# | $rp11 + | | + $rp21 | +# | 192.0.2.2/28 | | 192.0.2.33/28 | +# | 2001:db8:1::2/64 | | 2001:db8:3::1/64 | +# | | | | +# | $rp12 + | | + $rp22 | +# | 192.0.2.17/28 | | | | 192.0.2.18..27/28 | +# | 2001:db8:2::17/64 | | | | 2001:db8:2::18..27/64 | +# +-------------------|-----+ +-|-----------------------+ +# | | +# `----------' + +ALL_TESTS=" + ping_ipv4 + ping_ipv6 + test_mpath_seed_get + test_mpath_seed_ipv4 + test_mpath_seed_ipv6 + test_mpath_seed_stability_ipv4 + test_mpath_seed_stability_ipv6 +" +NUM_NETIFS=6 +source lib.sh + +h1_create() +{ + simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64 + ip -4 route add 192.0.2.32/28 vrf v$h1 nexthop via 192.0.2.2 + ip -6 route add 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::2 +} + +h1_destroy() +{ + ip -6 route del 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::2 + ip -4 route del 192.0.2.32/28 vrf v$h1 nexthop via 192.0.2.2 + simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64 +} + +h2_create() +{ + simple_if_init $h2 192.0.2.34/28 2001:db8:3::2/64 + ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.33 + ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:3::1 +} + +h2_destroy() +{ + ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:3::1 + ip -4 route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.33 + simple_if_fini $h2 192.0.2.34/28 2001:db8:3::2/64 +} + +router1_create() +{ + simple_if_init $rp11 192.0.2.2/28 2001:db8:1::2/64 + __simple_if_init $rp12 v$rp11 192.0.2.17/28 2001:db8:2::17/64 +} + +router1_destroy() +{ + __simple_if_fini $rp12 192.0.2.17/28 2001:db8:2::17/64 + simple_if_fini $rp11 192.0.2.2/28 2001:db8:1::2/64 +} + +router2_create() +{ + simple_if_init $rp21 192.0.2.33/28 2001:db8:3::1/64 + __simple_if_init $rp22 v$rp21 192.0.2.18/28 2001:db8:2::18/64 + ip -4 route add 192.0.2.0/28 vrf v$rp21 nexthop via 192.0.2.17 + ip -6 route add 2001:db8:1::/64 vrf v$rp21 nexthop via 2001:db8:2::17 +} + +router2_destroy() +{ + ip -6 route del 2001:db8:1::/64 vrf v$rp21 nexthop via 2001:db8:2::17 + ip -4 route del 192.0.2.0/28 vrf v$rp21 nexthop via 192.0.2.17 + __simple_if_fini $rp22 192.0.2.18/28 2001:db8:2::18/64 + simple_if_fini $rp21 192.0.2.33/28 2001:db8:3::1/64 +} + +nexthops_create() +{ + local i + for i in $(seq 10); do + ip nexthop add id $((1000 + i)) via 192.0.2.18 dev $rp12 + ip nexthop add id $((2000 + i)) via 2001:db8:2::18 dev $rp12 + done + + ip nexthop add id 1000 group $(seq -s / 1001 1010) hw_stats on + ip nexthop add id 2000 group $(seq -s / 2001 2010) hw_stats on + ip -4 route add 192.0.2.32/28 vrf v$rp11 nhid 1000 + ip -6 route add 2001:db8:3::/64 vrf v$rp11 nhid 2000 +} + +nexthops_destroy() +{ + local i + + ip -6 route del 2001:db8:3::/64 vrf v$rp11 nhid 2000 + ip -4 route del 192.0.2.32/28 vrf v$rp11 nhid 1000 + ip nexthop del id 2000 + ip nexthop del id 1000 + + for i in $(seq 10 -1 1); do + ip nexthop del id $((2000 + i)) + ip nexthop del id $((1000 + i)) + done +} + +setup_prepare() +{ + h1=${NETIFS[p1]} + rp11=${NETIFS[p2]} + + rp12=${NETIFS[p3]} + rp22=${NETIFS[p4]} + + rp21=${NETIFS[p5]} + h2=${NETIFS[p6]} + + sysctl_set net.ipv4.fib_multipath_hash_seed 0 + + vrf_prepare + + h1_create + h2_create + router1_create + router2_create + + forwarding_enable +} + +cleanup() +{ + pre_cleanup + + forwarding_restore + + nexthops_destroy + router2_destroy + router1_destroy + h2_destroy + h1_destroy + + vrf_cleanup + + sysctl_restore net.ipv4.fib_multipath_hash_seed +} + +ping_ipv4() +{ + ping_test $h1 192.0.2.34 +} + +ping_ipv6() +{ + ping6_test $h1 2001:db8:3::2 +} + +test_mpath_seed_get() +{ + RET=0 + + local i + for ((i = 0; i < 100; i++)); do + local seed_w=$((999331 * i)) + sysctl -qw net.ipv4.fib_multipath_hash_seed=$seed_w + local seed_r=$(sysctl -n net.ipv4.fib_multipath_hash_seed) + ((seed_r == seed_w)) + check_err $? "mpath seed written as $seed_w, but read as $seed_r" + done + + log_test "mpath seed set/get" +} + +nh_stats_snapshot() +{ + local group_id=$1; shift + + ip -j -s -s nexthop show id $group_id | + jq -c '[.[].group_stats | sort_by(.id) | .[].packets]' +} + +get_active_nh() +{ + local s0=$1; shift + local s1=$1; shift + + jq -n --argjson s0 "$s0" --argjson s1 "$s1" -f /dev/stdin <<-"EOF" + [range($s0 | length)] | + map($s1[.] - $s0[.]) | + map(if . > 8 then 1 else 0 end) | + index(1) + EOF +} + +probe_seed() +{ + local group_id=$1; shift + local seed=$1; shift + local -a mz=("$@") + + sysctl -qw net.ipv4.fib_multipath_hash_seed=$seed + + local s0=$(nh_stats_snapshot $group_id) + "${mz[@]}" + local s1=$(nh_stats_snapshot $group_id) + + get_active_nh "$s0" "$s1" +} + +test_mpath_seed() +{ + local group_id=$1; shift + local what=$1; shift + local -a mz=("$@") + local ii + + RET=0 + + local -a tally=(0 0 0 0 0 0 0 0 0 0) + for ((ii = 0; ii < 100; ii++)); do + local act=$(probe_seed $group_id $((999331 * ii)) "${mz[@]}") + ((tally[act]++)) + done + + local tally_str="${tally[@]}" + for ((ii = 0; ii < ${#tally[@]}; ii++)); do + ((tally[ii] > 0)) + check_err $? "NH #$ii not hit, tally='$tally_str'" + done + + log_test "mpath seed $what" + sysctl -qw net.ipv4.fib_multipath_hash_seed=0 +} + +test_mpath_seed_ipv4() +{ + test_mpath_seed 1000 IPv4 \ + $MZ $h1 -A 192.0.2.1 -B 192.0.2.34 -q \ + -p 64 -d 0 -c 10 -t udp +} + +test_mpath_seed_ipv6() +{ + test_mpath_seed 2000 IPv6 \ + $MZ -6 $h1 -A 2001:db8:1::1 -B 2001:db8:3::2 -q \ + -p 64 -d 0 -c 10 -t udp +} + +check_mpath_seed_stability() +{ + local seed=$1; shift + local act_0=$1; shift + local act_1=$1; shift + + ((act_0 == act_1)) + check_err $? "seed $seed: active NH moved from $act_0 to $act_1 after seed change" +} + +test_mpath_seed_stability() +{ + local group_id=$1; shift + local what=$1; shift + local -a mz=("$@") + + RET=0 + + local seed_0=0 + local seed_1=3221338814 + local seed_2=3735928559 + + local act_0_0=$(probe_seed $group_id $seed_0 "${mz[@]}") + local act_1_0=$(probe_seed $group_id $seed_1 "${mz[@]}") + local act_2_0=$(probe_seed $group_id $seed_2 "${mz[@]}") + + local act_0_1=$(probe_seed $group_id $seed_0 "${mz[@]}") + local act_1_1=$(probe_seed $group_id $seed_1 "${mz[@]}") + local act_2_1=$(probe_seed $group_id $seed_2 "${mz[@]}") + + check_mpath_seed_stability $seed_0 $act_0_0 $act_0_1 + check_mpath_seed_stability $seed_1 $act_1_0 $act_1_1 + check_mpath_seed_stability $seed_2 $act_2_0 $act_2_1 + + log_test "mpath seed stability $what" + sysctl -qw net.ipv4.fib_multipath_hash_seed=0 +} + +test_mpath_seed_stability_ipv4() +{ + test_mpath_seed_stability 1000 IPv4 \ + $MZ $h1 -A 192.0.2.1 -B 192.0.2.34 -q \ + -p 64 -d 0 -c 10 -t udp +} + +test_mpath_seed_stability_ipv6() +{ + test_mpath_seed_stability 2000 IPv6 \ + $MZ -6 $h1 -A 2001:db8:1::1 -B 2001:db8:3::2 -q \ + -p 64 -d 0 -c 10 -t udp +} + +trap cleanup EXIT + +setup_prepare +setup_wait +nexthops_create + +tests_run + +exit $EXIT_STATUS