Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3311390iob; Mon, 16 May 2022 19:01:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeHxjKyY7wmW20Ax8d9csQJ72F5biFf9sPhi38etMPUP4sp0U7dXfifwPTbpKvxp/t6WUw X-Received: by 2002:a17:907:948c:b0:6f5:183f:eb6 with SMTP id dm12-20020a170907948c00b006f5183f0eb6mr17177426ejc.112.1652752870364; Mon, 16 May 2022 19:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652752870; cv=none; d=google.com; s=arc-20160816; b=D8C6qjv4w3EJUJ/FswCeyTDmU6TgBiWsGucnDkuR8S+3zHe7A+0yfkOvl1Q9OP/WDT z2GIjCfydyTuAaggwt4F7UZOkkXUVq27fJEpbCQs8y8M/NYwV1Ir5iSDHMgtqdiUsEMQ U3sB6Mqbt0RkZFGsAFM3oD70cqMbsZ62iAnf2FerWm5xjHRTTq1rfHMoH3gWuFTdz/Ix wVPW5gAutkz4bVNJLYMEf1tiA9OYFecFh9UhrhL7J6hIMljHY8JVl3Hgrd/G6HvwPaJ5 +8KEklH4ATtb1skeUU0hvH7Rt8V4SICfpljXFqFtCfoSZT76mXDgRGpHcALmqFUwFLGe 1atA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0IekTda8dZc29mgcY6tzuuqR+31NMLXeG8vwmsGrsqE=; b=zazg/W5SQ7g2kQojcbOi//K9FuYmLA4gYhBcrgyokOhwvvxFAyuR0Ap8Up/EMDTjFR 6QIaBKujr+AfZAqUbUL3te4hLnIIhyqVCh/4Wn/CFcQ6foRDUECRIaQbQae81ZdZa78K /LYilsZ+qN0vQd9ArVw91kMMdDCq5+H0ytitpi1cHjAYfkZvxg+++rXvDp6l/zQAkddu bUzlIOeyfn7KskTSbXuABZ7Pd/zHALJZMslbMrZ0FydDws94wmYKpKM+h5z8DLazKOIC cCcBXyIHzIaa/j+vbdFS0xLUhj6LhHt8Kcnc1Ekt/pjLZJISH+UlbQ5lM4YtBOf9dV/W yJvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dSF7S1IC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc13-20020a1709078a0d00b006f398daeb92si1132907ejc.5.2022.05.16.19.00.45; Mon, 16 May 2022 19:01:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dSF7S1IC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347885AbiEPUW2 (ORCPT + 99 others); Mon, 16 May 2022 16:22:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348910AbiEPT7D (ORCPT ); Mon, 16 May 2022 15:59:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC789369D2; Mon, 16 May 2022 12:52:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5AF1260AB8; Mon, 16 May 2022 19:52:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65424C385AA; Mon, 16 May 2022 19:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730759; bh=GXv6tY1AebcHyT6RQTdWPQMx6r8FXPGYTvF7mOdzci8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dSF7S1ICAvZ2Hk3FubSwlZgbYcPAehho38Zjwpf/SQyIBzcf8oukQbOP6JrD/2FA+ uX2JCy3rHpMRVIb4LQOr0XEVOBIMR3l/FOIFMkZYZBBr+hEQgj3YbBXR5v/sV4UPOS NSvGPtJHeCxHt+jSnzNFzIDFtJojaxEHUzwXIIec= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Moshe Kol , Yossi Gilad , Amit Klein , Eric Dumazet , Willy Tarreau , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 059/102] tcp: dynamically allocate the perturb table used by source ports Date: Mon, 16 May 2022 21:36:33 +0200 Message-Id: <20220516193625.690924902@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193623.989270214@linuxfoundation.org> References: <20220516193623.989270214@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willy Tarreau [ Upstream commit e9261476184be1abd486c9434164b2acbe0ed6c2 ] We'll need to further increase the size of this table and it's likely that at some point its size will not be suitable anymore for a static table. Let's allocate it on boot from inet_hashinfo2_init(), which is called from tcp_init(). Cc: Moshe Kol Cc: Yossi Gilad Cc: Amit Klein Reviewed-by: Eric Dumazet Signed-off-by: Willy Tarreau Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/inet_hashtables.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 573a7e66ebc8..763395e30c77 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -731,7 +731,8 @@ EXPORT_SYMBOL_GPL(inet_unhash); * privacy, this only consumes 1 KB of kernel memory. */ #define INET_TABLE_PERTURB_SHIFT 8 -static u32 table_perturb[1 << INET_TABLE_PERTURB_SHIFT]; +#define INET_TABLE_PERTURB_SIZE (1 << INET_TABLE_PERTURB_SHIFT) +static u32 *table_perturb; int __inet_hash_connect(struct inet_timewait_death_row *death_row, struct sock *sk, u64 port_offset, @@ -774,7 +775,8 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, if (likely(remaining > 1)) remaining &= ~1U; - net_get_random_once(table_perturb, sizeof(table_perturb)); + net_get_random_once(table_perturb, + INET_TABLE_PERTURB_SIZE * sizeof(*table_perturb)); index = hash_32(port_offset, INET_TABLE_PERTURB_SHIFT); offset = READ_ONCE(table_perturb[index]) + (port_offset >> 32); @@ -912,6 +914,12 @@ void __init inet_hashinfo2_init(struct inet_hashinfo *h, const char *name, low_limit, high_limit); init_hashinfo_lhash2(h); + + /* this one is used for source ports of outgoing connections */ + table_perturb = kmalloc_array(INET_TABLE_PERTURB_SIZE, + sizeof(*table_perturb), GFP_KERNEL); + if (!table_perturb) + panic("TCP: failed to alloc table_perturb"); } int inet_hashinfo2_init_mod(struct inet_hashinfo *h) -- 2.35.1