Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6142320iog; Thu, 23 Jun 2022 12:13:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZ+4jnYAj2nwE6zm/NxRLaUBb4bW6Op0klTXRQ0ftIUUc2ejT/OEJEIgzj5wZivfKVvh/C X-Received: by 2002:a17:902:74c7:b0:16a:1be3:b7f2 with SMTP id f7-20020a17090274c700b0016a1be3b7f2mr24978566plt.42.1656011598692; Thu, 23 Jun 2022 12:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011598; cv=none; d=google.com; s=arc-20160816; b=p9KhyiPml49uXYmGE5oLRuWnl29xnnvnOsBgFnxhzECVjq1ZQCNBwZ+mSdz2LdFI6u +NKBQOa3wVhTJcZe17t2KWtn68tOGQ4vG8T/8o/yx264AH2wlE+EuIvI0wNst3bIriEn lyA979I+zRNypcbhRIiHoIaDbsnSd7/UZE2C41Ls2/rqnU6h3mz/Nh5cKIlatzguwEf1 v4yE5RrYSmHMURvL+bbiKEDOjB65ah/ICi4x37pB3hez4zEClLLVT0LVwBSGcZpF8lZA 0vtRjJ0qzF5pA4jSEDEPDtaa9pxcr74IXU+PQarccxe2iEhy2l7Sz+X8dyGlLoUOgaIM Mehg== 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=edr2zCPTGDsCfgmRtTfvkCyns+YUF1mpjY2aaPRZWSI=; b=XBdOfimmWY9aLPksT4aphGFiz4pMVdxELDHatKHXkvF4ghZLMMJZe5jrWB8dEnoHVB ooOlbracc8P6Cto3Pr5VVqiKRQine0Mq86W7m8E8VAqCzwkCicvGImV75GrqjNyxZmWR myBHFVmMZ32iLNvC8FVDzvr4PAUhtE2EAzR8CB89tHrFA1fMSFm+hgDCr4aqzci5cCri H8KAEfT/KwHLccTk1MTszGpN3zQGD6XLV3Nq5a60iyOwe9UwpkqljgrWWL9HuJTXe6T/ yurxt7stH7wjl1fbRxODb5WbLTaPptY6Iw84Li7CS+XvcxoyNB46Bk0r1hd/UHY7bz0V DLUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FGmZoijj; 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 lw3-20020a17090b180300b001ecaa96a719si1235932pjb.119.2022.06.23.12.13.06; Thu, 23 Jun 2022 12:13:18 -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=FGmZoijj; 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 S229750AbiFWRQt (ORCPT + 99 others); Thu, 23 Jun 2022 13:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233552AbiFWRM5 (ORCPT ); Thu, 23 Jun 2022 13:12:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73F4356764; Thu, 23 Jun 2022 09:58:53 -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 1A4106159B; Thu, 23 Jun 2022 16:58:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9E41C3411B; Thu, 23 Jun 2022 16:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003531; bh=8y18ODyS5jKrbM0bJiqOyZFuU4Xxbs+la5unS7om3cw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGmZoijjiL1kGxiLpQE/UiPi9iqGpjLmvtt/nnQQZ8IGQ5JlSu5ABJYxeo7upw0Hs G6kbKq46dh7FSBfxcHOH7llgweKajBPQQF7h+/Cf/myuxcfO1mAW7ZYsFgq4KLMyZD fN3SfiRuUdcMw6W3fkKKOcrJklD1nhdmqdPDnPNg= 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.9 262/264] tcp: dynamically allocate the perturb table used by source ports Date: Thu, 23 Jun 2022 18:44:15 +0200 Message-Id: <20220623164351.476645516@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@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.9: - There is no inet_hashinfo2_init(), so allocate the table in inet_hashinfo_init() when called by TCP - Adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/ipv4/inet_hashtables.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -546,7 +546,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, @@ -586,7 +587,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); @@ -691,6 +693,15 @@ void inet_hashinfo_init(struct inet_hash INIT_HLIST_NULLS_HEAD(&h->listening_hash[i].nulls_head, i + LISTENING_NULLS_BASE); } + + if (h != &tcp_hashinfo) + return; + + /* 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"); } EXPORT_SYMBOL_GPL(inet_hashinfo_init);