From patchwork Sat Dec 14 17:30:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13908563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6ABCE7716A for ; Sat, 14 Dec 2024 17:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=GdcIoMV9rDgh/h7XI/XexxU3pMPlgPu8UDf7JNbHBG0=; b=ZJGdD6txREPpH87OQIHUdthGqr H79bLvAJEqVwubdSr+CJZWjFPQXpfdJE1eNoRufqOu54Snof8OYmmr2TTNhDpfonwPX+x02N8qbZv Y3fZeVfvli0fLokGFocMwpQtMNVb5RSvFCXl6XrTNNcDb6sxNLTTO0qYDuiudzqnw77ZCW4oAxv4a gUVBt1ZRiIq9o/DZsH4T36AjE1hkxiXTJnxhc53nKyt1b65IpHXjnYn3XFuY6Yv8tFV12KZsIcSuY aKpl93yPYdDkmwvWcLq+NB+CsME831qG64pGWdpkQQCis1X6ga7feWnI1OAvd5sIrRLmWPDb1Ml8Y oS0OgIbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tMW7t-00000006jK4-3aOx; Sat, 14 Dec 2024 17:40:25 +0000 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tMVzg-00000006hen-2TGN for linux-arm-kernel@lists.infradead.org; Sat, 14 Dec 2024 17:31:59 +0000 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-312-61ot2vfuOIOCZzeUwr6qww-1; Sat, 14 Dec 2024 17:31:50 +0000 X-MC-Unique: 61ot2vfuOIOCZzeUwr6qww-1 X-Mimecast-MFC-AGG-ID: 61ot2vfuOIOCZzeUwr6qww Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 14 Dec 2024 17:30:53 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sat, 14 Dec 2024 17:30:53 +0000 From: David Laight To: "'netdev@vger.kernel.org'" , 'Naresh Kamboju' , 'Dan Carpenter' , 'Julian Anastasov' , "'pablo@netfilter.org'" , Andrew Morton CC: 'open list' , "'lkft-triage@lists.linaro.org'" , "'Linux Regressions'" , 'Linux ARM' , "'netfilter-devel@vger.kernel.org'" , 'Arnd Bergmann' , "'Anders Roxell'" , 'Johannes Berg' , "'toke@kernel.org'" , 'Al Viro' , "'kernel@jfarr.cc'" , "'kees@kernel.org'" Subject: [PATCH net-next] Fix clamp() of ip_vs_conn_tab on small memory systems. Thread-Topic: [PATCH net-next] Fix clamp() of ip_vs_conn_tab on small memory systems. Thread-Index: AdtOTfU+VQ/Jz9m3Sa6gMqrna34atA== Date: Sat, 14 Dec 2024 17:30:53 +0000 Message-ID: <24a6bfd0811b4931b6ef40098b33c9ee@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MSKn14niWZ14IiVGDT6r2oSEzcDvHwdn8oR5qTi_huA_1734197509 X-Mimecast-Originator: aculab.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241214_093156_896783_4B36F6BB X-CRM114-Status: GOOD ( 13.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 'max_avail' value is calculated from the system memory size using order_base_2(). order_base_2(x) is defined as '(x) ? fn(x) : 0'. The compiler generates two copies of the code that follows and then expands clamp(max, min, PAGE_SHIFT - 12) (11 on 32bit). This triggers a compile-time assert since min is 5. In reality a system would have to have less than 512MB memory for the bounds passed to clamp to be reversed. Swap the order of the arguments to clamp() to avoid the warning. Replace the clamp_val() on the line below with clamp(). clamp_val() is just 'an accident waiting to happen' and not needed here. Detected by compile time checks added to clamp(), specifically: minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp() Reported-by: Linux Kernel Functional Testing Closes: https://lore.kernel.org/all/CA+G9fYsT34UkGFKxus63H6UVpYi5GRZkezT9MRLfAbM3f6ke0g@mail.gmail.com/ Fixes: 4f325e26277b ("ipvs: dynamically limit the connection hash table") Tested-by: Bartosz Golaszewski Reviewed-by: Bartosz Golaszewski Signed-off-by: David Laight Acked-by: Julian Anastasov --- Julian seems to be waiting for a 'v2' from me. Changed target tree to 'net-next'. I've re-written the commit message. Copied Andrew Morton - he might want to take the change through the 'mm' tree. Plausibly the 'fixes' tag should refer to the minmax.h change? This will need back-porting if the minmax set get back-ported. I'm not sure whether there ought to be an attribution to Dan Carpenter net/netfilter/ipvs/ip_vs_conn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c index 98d7dbe3d787..c0289f83f96d 100644 --- a/net/netfilter/ipvs/ip_vs_conn.c +++ b/net/netfilter/ipvs/ip_vs_conn.c @@ -1495,8 +1495,8 @@ int __init ip_vs_conn_init(void) max_avail -= 2; /* ~4 in hash row */ max_avail -= 1; /* IPVS up to 1/2 of mem */ max_avail -= order_base_2(sizeof(struct ip_vs_conn)); - max = clamp(max, min, max_avail); - ip_vs_conn_tab_bits = clamp_val(ip_vs_conn_tab_bits, min, max); + max = clamp(max_avail, min, max); + ip_vs_conn_tab_bits = clamp(ip_vs_conn_tab_bits, min, max); ip_vs_conn_tab_size = 1 << ip_vs_conn_tab_bits; ip_vs_conn_tab_mask = ip_vs_conn_tab_size - 1;