From patchwork Fri Mar 17 05:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Elmously X-Patchwork-Id: 1758095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=CmNDhwIk; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PdF8j6ZFkz2473 for ; Fri, 17 Mar 2023 17:48:52 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pd3tE-0002fV-Ty; Fri, 17 Mar 2023 06:48:36 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pd2LG-0005Li-Nd for kernel-team@lists.ubuntu.com; Fri, 17 Mar 2023 05:09:26 +0000 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 24655445A2 for ; Fri, 17 Mar 2023 05:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1679029766; bh=KuwR+8CXFBTXHEAfCJGHsxpzGo2X8OwCchRa3RX+oAM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=CmNDhwIkJs92PHx+gJU1i59vBkT2VVOy8oT7UHEZUtU7ool9gLQeduX4xo5ZgwegS 5ah9ccU5DwsNEuhDXsm19/hXvwicVZBtkZgUs3e+6/eZTaQQqoEag/LMZZgbnnOusj mKh9pMNyzo9yuc/P4D/bBxQ5REd+KQBIH7G2BNqyiTpQ8KNF8r6aV/G8wjOWKXNbLd 9QOQaMfMqGcx4nvKeVPsNpcEyFDiWA0ygVRi7/YdQgNv6aTkBjprPDS4UJRdG1WmHE ePQ5cv7tWG55tLvjKiheCVvmuY+Si1mGhUEsfmvQTSvRESUyYeGj+hIPTUnJmXyreA MGDcnqhntBAzQ== Received: by mail-il1-f197.google.com with SMTP id b9-20020a926709000000b00322ffd64968so1892079ilc.13 for ; Thu, 16 Mar 2023 22:09:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679029763; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KuwR+8CXFBTXHEAfCJGHsxpzGo2X8OwCchRa3RX+oAM=; b=Zo7g41nqWZTKM8gWQ8lPOkZ3L62gwQq1qdFRaoi8Kh8GCJw6nGWGShyhs7WkMWSc2l mBUYyqkV8v1zL2ZX9mzOCQlzyxOXeymlnKD/jOzHDGieR2y77XMgEaSSmh+ME8rJwRjX Pm9oQZ2lwH2Mxq5z/wnuWEnw55vO2DLSf6TXPJzlsF5pPdnpe4UKxFn6aIaYjl/jopGR TKnN+dfAxb82jnQoadA6qzQ8kEfGZKKBNzmbiQpZjhIBgfc2VzKkGOyrB4CbKOV01xRk U5qm4E/CRC880ryjizPgn7k267Be2bwzDQTM/rHp1RRc0LPamBAhmQdKPdJy51buP9Gd ip8Q== X-Gm-Message-State: AO0yUKWFcSGAC3xkuG/xFe6lZUTeX6O2IxYeac8srX3oyd+6Kf1P9iSx Il4QJ1XLj3kB7t2Sl0WcRwKuxeLUJ3KLirv9Q73cmRuty7ozIUViAy9rrEAiQQCoVuzV5aG77Wl EyH/MV3V9aPUXROl1IvK53W47w8yhXH+zuXHfUOTGbbPZdcbFGDD+ X-Received: by 2002:a05:6e02:1c81:b0:31f:ba63:382 with SMTP id w1-20020a056e021c8100b0031fba630382mr10398000ill.30.1679029763713; Thu, 16 Mar 2023 22:09:23 -0700 (PDT) X-Google-Smtp-Source: AK7set+hOG2kJGrnDiygqQoNXSIX6wlkOVuqbJpIcn540zMfMqCQBKxFky4CDFXjRAV8m2D8HUvunA== X-Received: by 2002:a05:6e02:1c81:b0:31f:ba63:382 with SMTP id w1-20020a056e021c8100b0031fba630382mr10397992ill.30.1679029763446; Thu, 16 Mar 2023 22:09:23 -0700 (PDT) Received: from k2.fuzzbuzz.org ([38.147.253.184]) by smtp.gmail.com with ESMTPSA id q7-20020a02b047000000b004050baff59fsm398458jah.26.2023.03.16.22.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 22:09:22 -0700 (PDT) From: Khalid Elmously To: kernel-team@lists.ubuntu.com Subject: [SRU][v3][J][K][L][PATCH] netfilter: conntrack: adopt safer max chain length Date: Fri, 17 Mar 2023 01:09:19 -0400 Message-Id: <20230317050919.2569401-1-khalid.elmously@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Eric Dumazet BugLink: https://bugs.launchpad.net/bugs/2011616 Customers using GKE 1.25 and 1.26 are facing conntrack issues root caused to commit c9c3b6811f74 ("netfilter: conntrack: make max chain length random"). Even if we assume Uniform Hashing, a bucket often reachs 8 chained items while the load factor of the hash table is smaller than 0.5 With a limit of 16, we reach load factors of 3. With a limit of 32, we reach load factors of 11. With a limit of 40, we reach load factors of 15. With a limit of 50, we reach load factors of 24. This patch changes MIN_CHAINLEN to 50, to minimize risks. Ideally, we could in the future add a cushion based on expected load factor (2 * nf_conntrack_max / nf_conntrack_buckets), because some setups might expect unusual values. Fixes: c9c3b6811f74 ("netfilter: conntrack: make max chain length random") Signed-off-by: Eric Dumazet Signed-off-by: Pablo Neira Ayuso (cherry picked from commit c77737b736ceb50fdf150434347dbd81ec76dbb1) Signed-off-by: Khalid Elmously Acked-by: Tim Gardner Acked-by: Cengiz Can --- net/netfilter/nf_conntrack_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index ead11a9c261f..19e3afb23fda 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -96,8 +96,8 @@ static DEFINE_MUTEX(nf_conntrack_mutex); #define GC_SCAN_MAX_DURATION msecs_to_jiffies(10) #define GC_SCAN_EXPIRED_MAX (64000u / HZ) -#define MIN_CHAINLEN 8u -#define MAX_CHAINLEN (32u - MIN_CHAINLEN) +#define MIN_CHAINLEN 50u +#define MAX_CHAINLEN (80u - MIN_CHAINLEN) static struct conntrack_gc_work conntrack_gc_work;