From: David Laight <david.laight.linux@gmail.com>
To: Chuck Lever <cel@kernel.org>
Cc: Andrew Morten <akpm@linux-foundation.org>,
NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
<linux-nfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<stable@vger.kernel.org>,
speedcracker@hotmail.com
Subject: Re: [PATCH v1 v6.12.y] nfsd: Replace clamp_t in nfsd4_get_drc_mem()
Date: Fri, 14 Nov 2025 22:14:41 +0000 [thread overview]
Message-ID: <20251114221441.49481cec@pumpkin> (raw)
In-Reply-To: <20251114211922.6312-1-cel@kernel.org>
On Fri, 14 Nov 2025 16:19:22 -0500
Chuck Lever <cel@kernel.org> wrote:
> From: NeilBrown <neil@brown.name>
>
> 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=220745#c0
> Signed-off-by: NeilBrown <neil@brown.name>
> Stable-dep-of: 1519fbc8832b ("minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp()")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed_by: David Laight <david.laight.linux@gmail.com>
> ---
> 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_attrs *ca, struct nfsd_net *nn
> */
> scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads);
>
> - avail = clamp_t(unsigned long, avail, slotsize,
> - total_avail/scale_factor);
> + if (avail > total_avail / scale_factor)
> + avail = total_avail / scale_factor;
> + else if (avail < slotsize)
> + avail = slotsize;
> num = min_t(int, num, avail / slotsize);
> num = max_t(int, num, 1);
> nfsd_drc_mem_used += num * slotsize;
next prev parent reply other threads:[~2025-11-14 22:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 21:19 [PATCH v1 v6.12.y] nfsd: Replace clamp_t in nfsd4_get_drc_mem() Chuck Lever
2025-11-14 22:14 ` David Laight [this message]
2025-12-01 19:28 ` Chuck Lever
2025-12-02 15:51 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114221441.49481cec@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cel@kernel.org \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=speedcracker@hotmail.com \
--cc=stable@vger.kernel.org \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).