Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6142703iog; Thu, 23 Jun 2022 12:13:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t+8A/05nW6UhClYCnxi701oIayAqQdkxZPoCIWusRs7uukIbr2Do6AM1xHNjTrKmMLqJGN X-Received: by 2002:a05:6a00:21c8:b0:4c4:4bd:dc17 with SMTP id t8-20020a056a0021c800b004c404bddc17mr42393541pfj.57.1656011633342; Thu, 23 Jun 2022 12:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011633; cv=none; d=google.com; s=arc-20160816; b=Rjpedmmno6DPpIbycDTqBdQpmRWYzfsoFAbjNrV7cdSTOij83OeGv1+JlbDKd2KpEg 4kDz1EA/J3kxCQZxHfBOsaxtsvxuZWcn2oGKejGvKWnP5qUbKPfNIU7ZsijhSVXjcb4m Bb0l7WEvPLOqklzXqfHhNs5nIJPXPTIQA7ci9SN6bPQzLhaJEE7sPbIkL9N55Zsqn7Tx xR0W2yza8uCFfU/H7R8CrgID/QSvJyJ+4Dbm5uLAfwq6KykqIH+cTLGUp8Dxuc9B61Wf l3iAKQe6HlcJ/olYUNQhDg7iidRWMvWh7Ua34TL+IG8f8d+hskChA8KK6EM+VM3y89mZ 27Dw== 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=8l2ZgC88xPososII8P50L3W/L9RSHoT2YGjg1ZrbNB8=; b=nYzinwhPy5vokjm1UUXYl2aVAysTbwkOpSdmvyMw7RZgT05zedvwHudSkMnS9g2SjM uw9emDzBlMYXqYFbUvMjs0m/BqEuW1+HgNG4nYktUfruFMGLywEbSTEFWmSxYp812NOR hhdzQI369lxjYnINrClu+B4uuMV88cNsBRTJaB2EB33VRt7/pxHaP1R1MduuT45etXJz vPZpH7ProfSkr6nGmwzNYirE+Jl4fAC5/nW5L0BTeNxaqi3t8+aucm9v9TE4/SBml3M0 PL3xZaSNx7BQ0kxw+RH1zd1rrqKH8h9FJ0X48dQxwQmqQgH5hsPpFXpkm93sVF/fg+cE T7+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=riS+em0i; 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 f10-20020a056a001aca00b0050e0a0b03afsi30903100pfv.362.2022.06.23.12.13.40; Thu, 23 Jun 2022 12:13:53 -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=riS+em0i; 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 S237408AbiFWSWl (ORCPT + 99 others); Thu, 23 Jun 2022 14:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234933AbiFWSSe (ORCPT ); Thu, 23 Jun 2022 14:18:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A0DF68021; Thu, 23 Jun 2022 10:24:58 -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 999CA61F06; Thu, 23 Jun 2022 17:24:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 760EDC341C5; Thu, 23 Jun 2022 17:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656005096; bh=wp9EquvNPqrrsJ/Y1NFOY6uknM5N6T0rAZv5vmCLvqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=riS+em0i3Fjo8zyg1AkKiULncZBRZqtFCiL7gktucAlYTRSKTJtsqea1PdfSxUwBt bIp5Lfr61de6wc4YmOROhO9sqs7gNEQdF1ZWS5X0QytwOMZnagaCCtjuU30w5gJaaU dzMoHo4e6TnC90G3DFY+5Zf1SDj7JIv6kPWFplNU= 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 5.4 07/11] tcp: dynamically allocate the perturb table used by source ports Date: Thu, 23 Jun 2022 18:45:11 +0200 Message-Id: <20220623164321.412902424@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164321.195163701@linuxfoundation.org> References: <20220623164321.195163701@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 Cc: 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 @@ -680,7 +680,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, @@ -723,7 +724,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); @@ -861,6 +863,12 @@ void __init inet_hashinfo2_init(struct i 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)