Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6131502iog; Thu, 23 Jun 2022 12:01:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tqbZpDflncW0Ia3D64kmuMRcP2Ut0ZBRtOdEZ76fMk5Z4DI/Lye9MZi0I2C+FN6CAnN7/B X-Received: by 2002:a17:907:7e9c:b0:722:f974:4c5f with SMTP id qb28-20020a1709077e9c00b00722f9744c5fmr7775842ejc.419.1656010888052; Thu, 23 Jun 2022 12:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010888; cv=none; d=google.com; s=arc-20160816; b=CLGHXsvf1pWsxvQUeBwiHR0pVLGyAcoyc9re8doAqcFDrz+NwRRvSOLZTmnVaG0Wk3 KAoDXieph3qvklKw5s83CaQTXEpymf7gwe5b61jyxjR2L8OXLd9FhDlZ8fRW1KI03rx2 LtsLfzHSzu3py746DkoRCSOcPCqb9x43W2TeuYJmossVmAxptXKVCOoSeuKwLNoJ4Ome Jrp1Nac17gpNQ51Mvi+wCaF7m9I2ZdgTIhkfEol52kb7HVSQcCStMNMTJTxi+H2rgfLI 4/KZ+zJCKKx8Zk85GuERgw9KTh6EpDOCPR+ZC/7aCCxNnGoghlWoF/AE7jXx6+8Lo+DU qfOQ== 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=ov4ZLYN9L6UXsxrPV2gvynZMvg/nWNDjxrRQEyGDoRU=; b=Qd4detJBorcCqfb6xOaQC9G3sgpCmtC3HFw9I4jaNCT8iqjsVhAUa3pJKi5cUpbW5m y2GuMZ9CtSaw8WMDF7M9ZrMgd3ergFKcChqFHZ0tVmFG1VxVfBNj6yB3QwGBESWXRFhb Ua5tz+EtFbemvVkwrmmO3IRxIeZXPrAzQqhntEDVwUJhbVE1xD7koJ2riOqFJ0Mu9/3e O9JLVWTVRBvVvwG2QBGGWRilkec7OlcfDe6yOty8mrwzMiqaL7NOxANzvu3dzuhSBmXi dLo+qG8fAwB1V7hQT7XQu+lgKQ4zLcdKUazvEnb+qzEntOM7WrJtuMpEc5lZdTLIIv+E 0axA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XydSAgaB; 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 hp40-20020a1709073e2800b0071200c979b1si1477992ejc.644.2022.06.23.12.01.02; Thu, 23 Jun 2022 12:01:28 -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=XydSAgaB; 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 S237080AbiFWSVF (ORCPT + 99 others); Thu, 23 Jun 2022 14:21:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237000AbiFWSRj (ORCPT ); Thu, 23 Jun 2022 14:17:39 -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 26F84647BA; Thu, 23 Jun 2022 10:23:59 -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 50D3C61EE4; Thu, 23 Jun 2022 17:23:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35691C341C7; Thu, 23 Jun 2022 17:23:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656005038; bh=7nsl9GovbJsxy3FTR4xXXKXp55mXNprgLuRHJ6qk/8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XydSAgaBSHJ9pbTZezJFUpCvdZOgtU10Og4ZHeu5XgQRRqCCALe57IS3XQlNTYuCT jwt+tjvyi98OjNknXF2JlO1iEBAeiBNBG1Q7fulkfLRkNyl6RM7hob3LPXMwsheJc9 7QdP6B7AvC8/mocwK+8yxldaKv8vVmVlfXnbQIvA= 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 , Ben Hutchings Subject: [PATCH 4.19 231/234] tcp: dynamically allocate the perturb table used by source ports Date: Thu, 23 Jun 2022 18:44:58 +0200 Message-Id: <20220623164349.586866484@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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.7 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 commit e9261476184be1abd486c9434164b2acbe0ed6c2 upstream. 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 [bwh: Backported to 4.19: adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/ipv4/inet_hashtables.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -723,7 +723,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, @@ -763,7 +764,8 @@ int __inet_hash_connect(struct inet_time 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); @@ -896,6 +898,12 @@ void __init inet_hashinfo2_init(struct i INIT_HLIST_HEAD(&h->lhash2[i].head); h->lhash2[i].count = 0; } + + /* 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_ehash_locks_alloc(struct inet_hashinfo *hashinfo)