Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3386782iob; Mon, 16 May 2022 21:35:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVqzl8y0bPAzz4KwTY9f7nD8f8QQdOVo8xwfYSecYBBbeNMVmmauTxQgOR3VaZlub1EJB/ X-Received: by 2002:a17:906:544e:b0:6f3:bd59:1a93 with SMTP id d14-20020a170906544e00b006f3bd591a93mr17948675ejp.421.1652762105619; Mon, 16 May 2022 21:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652762105; cv=none; d=google.com; s=arc-20160816; b=T2Pwm33a5FEl1ydefa8hDLj0Jww/PlQ1gpxWKcenzTZyh+LHL6JdDezPyskZwFqzFe XNTtFSKJK+doRvqWamuZ39bo/a4gW1GmOwt0YXLHJgZZPQkYJEatNpiCYiutTLsBkR2f gL+9s2eRTavhOpRC9Ryl0XqKl/3iClWMejA3vffQPzJEd7Quc/j2uOdB89I1K+Dv+Rr5 0S5L+2sk0sJQuazzPS80mGFHm/MRg+YO1wbn8PVmPkwErfudK63rkRUI8dqJMW/HzGwt OhoDR7Pl3TQ7kGSnrVdkRRVGaZyV/SGi9bf6bNhrvEgJbfxRgm2tT/Cc42mo1OyuUQ0y y19Q== 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=X343TQn/6gYNtJmNSpsZtAFXhY+VkuP3zB8hz+e/6kA=; b=VuziQPt8JbSCPjdwEhvVSeCh1J6vsPhDfJmXXV2q8XS53Azx/K2WsZVbWh/17du+w0 j5GY4w9zB+k0ZcwLzDoUzwGrryUPgDHU2FCApeY6sQcnz+wfWMnc/c1cT8st5HNi3YGQ ItyGt6HB2OxHLkwkHyB+1ZxCr2ogMqOLIVrcSbGX2pzIqeqg99uQJ3aCa7npiayUd2Oh kSWmlgr6D7iWZhnkk9wzzC3UFv9PBM7/yiZx9cC0gYpF3KJCQ/0nUbj/6VmC4XT1Dfhw pEyaBdEztbD4Vt7bPBxPR69MENhpmS8XwGMz03LeIOt29hKcszi5cXz3CFRz/GAF4U9l ILOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UwLSSBaJ; 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 fb17-20020a1709073a1100b006f426c6f503si1323278ejc.126.2022.05.16.21.34.28; Mon, 16 May 2022 21:35:05 -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=UwLSSBaJ; 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 S1349168AbiEPUiG (ORCPT + 99 others); Mon, 16 May 2022 16:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350986AbiEPUBy (ORCPT ); Mon, 16 May 2022 16:01:54 -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 4AAFC4B872; Mon, 16 May 2022 12:56:19 -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 DDA1860FEB; Mon, 16 May 2022 19:56:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC953C385AA; Mon, 16 May 2022 19:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730978; bh=MaXGPolPz4kift9fAhWFyxiXkGWK0QfVnz1NKikV7Cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UwLSSBaJ6pMV4oJckBls7GDex1Adh4ybOy7ZxtsHY8rvdeeBk9FlKTkoJ/UKgi2R/ a7OuPGl6fArvKPrJHhCNtGQFM6DVfQkxVg/pS7qa9TB9MzYqqk898jSntGNxScg+Op J6PqPf+Lv/pSPoq9/nYUG9c8HgOiA2HQnoEoZbsw= 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.17 065/114] tcp: dynamically allocate the perturb table used by source ports Date: Mon, 16 May 2022 21:36:39 +0200 Message-Id: <20220516193627.359382931@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193625.489108457@linuxfoundation.org> References: <20220516193625.489108457@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 63bb4902f018..48ca07853068 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