From nobody Sat Feb 7 17:55:12 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FB1E354AD9; Fri, 14 Nov 2025 21:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763155165; cv=none; b=NkStSJp4sjnP2xxRNC8YXSH95hVRr6o4cwPtfUVaBgmSymMZ4RfSjm16MdVveCGg9hkn5zs7ULzkCDoup6vEokV61034z42WEKXSy/MpZHGHzkTKGddYRTnZRLItlt9FsSqir0Lmz5SoQq1rJRY3RPIuI4mZU0AAkeyX6hB9WWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763155165; c=relaxed/simple; bh=fRjsJ4ILbYmevq3A+UeisJRyRN2VEPlnEnUDonmJ7qM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=P+PzrsTdADrEplh0J8nnX8I1T2ZX/CTayhw8GDHez2f/YZGuS+9vzH9Y5wZCZ0I3/5uCTINhcfesgjzfguFkL5xvsGXZGFqNb0yug2cQV8gpYZr+ltSokc/qxO1KnIRlrT4o+F7swJBaFYDYzt8ADZ7aG8BNUSjZVFZPj8DuP4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s1Nvo7a7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s1Nvo7a7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73D9DC4CEF5; Fri, 14 Nov 2025 21:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763155165; bh=fRjsJ4ILbYmevq3A+UeisJRyRN2VEPlnEnUDonmJ7qM=; h=From:To:Cc:Subject:Date:From; b=s1Nvo7a7jVB2YQHXt6n19VTBwfq4OyQLXNtpFNlIL2dOadX6HhGMNvMlzIB9aeqXX rASJGWKe/zUwB6374x0ZsPdhm3hUxCIyKXo/zmxyZKaEGzoY7Ecyw+bFRH8Pqenq0P IPO8m9huLSpXqX9S1qPsbopYylLVmx09vjLCM9ljvVCFzCsnCaHrHjEIoW3bHGqHtl dxiIGIhnEUQihcCTIj9gm0NPVT/5EraEE1H1hf0rOOXxd06X1AxDyAlYsjHbrwd10B QLxcKDQfnOjVuuNyteT0wB9f+x1IbK7htoHRIk5k9gWBcrCIVGg3dbcGkTyCPHH48d xu8NjtPKL/eWw== From: Chuck Lever To: Andrew Morten , david.laight.linux@gmail.com, NeilBrown , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: , , , speedcracker@hotmail.com Subject: [PATCH v1 v6.12.y] nfsd: Replace clamp_t in nfsd4_get_drc_mem() Date: Fri, 14 Nov 2025 16:19:22 -0500 Message-ID: <20251114211922.6312-1-cel@kernel.org> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: NeilBrown A recent change to clamp_t() in 6.1.y caused fs/nfsd/nfs4state.c to fail to compile with gcc-9. The code in nfsd4_get_drc_mem() was written with the assumption that when "max < min", clamp(val, min, max) would return max. This assumption is not documented as an API promise and the change caused a compile failure if it could be statically determined that "max < min". The relevant code was no longer present upstream when commit 1519fbc8832b ("minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp()") landed there, so there is no upstream change to nfsd4_get_drc_mem() to backport. There is no clear case that the existing code in nfsd4_get_drc_mem() is functioning incorrectly. The goal of this patch is to permit the clean application of commit 1519fbc8832b ("minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp()"), and any commits that depend on it, to LTS kernels without affecting the ability to compile those kernels. This is done by open-coding the __clamp() macro sans the built-in type checking. Closes: https://bugzilla.kernel.org/show_bug.cgi?id=3D220745#c0 Signed-off-by: NeilBrown Stable-dep-of: 1519fbc8832b ("minmax.h: use BUILD_BUG_ON_MSG() for the lo <= hi test in clamp()") Signed-off-by: Chuck Lever --- fs/nfsd/nfs4state.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) Changes since Neil's post: * Editorial changes to the commit message * Attempt to address David's review comments * Applied to linux-6.12.y, passed NFSD upstream CI suite This patch is intended to be applied to linux-6.12.y, and should apply cleanly to other LTS kernels since nfsd4_get_drc_mem hasn't changed since v5.4. diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 7b0fabf8c657..41545933dd18 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1983,8 +1983,10 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_at= trs *ca, struct nfsd_net *nn */ scale_factor =3D max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads); =20 - avail =3D clamp_t(unsigned long, avail, slotsize, - total_avail/scale_factor); + if (avail > total_avail / scale_factor) + avail =3D total_avail / scale_factor; + else if (avail < slotsize) + avail =3D slotsize; num =3D min_t(int, num, avail / slotsize); num =3D max_t(int, num, 1); nfsd_drc_mem_used +=3D num * slotsize; --=20 2.51.0