Public bug reported:

[ Impact ]

The Bluefield 5.15 kernel fails to build from source on GCC 9.

The Bluefield kernel has backported newer implementations in the
`minmax.h` header, which enforce strict compile-time checks on
`clamp_t()`. However, the legacy function `nfsd4_get_drc_mem()` in
`fs/nfsd/nfs4state.c` code contains logic where `max < min` is
theoretically possible, causing the compile-time assertions to fail.

This blocks the Bluefield 5.15 Kernel from successfully building in
environments with GCC 9 (such as Ubuntu Focal). Although GCC 9 is the
only version that fails to build with this issue, it is present
regardless, and future GCC version may be capable of identifying this
issue as well.

[ Fix ]

Apply the backport of the upstream fix. Commit: "nfsd: Replace clamp_t
in nfsd4_get_drc_mem()"

As noted in the commit description, this patch was created specifically
for LTS Kernels to permit the application of the updated `minmax.h`
header without breaking the build, by replacing the clamp usage with
open-coded if-else logic to more safely and explicitly handle cases
where `max < min`.

commit 5f4720ac8e67f41020cb39c678e4a3bdc26114fe
From: NeilBrown <[email protected]>
Date: Fri, 14 Nov 2025 16:19:22 -0500
Subject: nfsd: Replace clamp_t in nfsd4_get_drc_mem()
Link: 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=5f4720ac8e67

[ Test Plan ]

1. Setup a clean build environment with GCC 9 (for example, Ubuntu Focal)
2. Clone the `linux-bluefield` source.
3. Checkout the tag `Ubuntu-bluefield-5.15.0-1084.86`
4. Attempt to build the kernel.
5. Observe build failure at `fs/nfsd/nfs4state.c`.
6. Apply patch.
7. Attempt a clean build of the kernel.
8. Build succeeds.

[ Where problems could occur ]

The likelihood of problems occurring is very low. The upstream patch for
this issue was specifically created by upstream maintainers for this
scenario. The patch replaces the usage of the `clamp_t` macro with open-
coded logic that performs the same runtime operation, but avoids the
compile-time assertion.

[ Other Info ]

The build error that is encountered when using GCC 9 is provided below.

CC [M]  fs/nfsd/nfs4state.o
In file included from <command-line>:
In function ‘nfsd4_get_drc_mem’,
    inlined from ‘check_forechannel_attrs’ at fs/nfsd/nfs4state.c:3539:16,
    inlined from ‘nfsd4_create_session’ at fs/nfsd/nfs4state.c:3612:11:
././include/linux/compiler_types.h:334:38: error: call to 
‘__compiletime_assert_894’ declared with attribute error: clamp() low limit 
slotsize greater than high limit total_avail/scale_factor
  334 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |                                      ^
././include/linux/compiler_types.h:315:4: note: in definition of macro 
‘__compiletime_assert’
  315 |    prefix ## suffix();    \
      |    ^~~~~~
././include/linux/compiler_types.h:334:2: note: in expansion of macro 
‘_compiletime_assert’
  334 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro 
‘compiletime_assert’
   39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
      |                                     ^~~~~~~~~~~~~~~~~~
./include/linux/minmax.h:188:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
  188 |  BUILD_BUG_ON_MSG(statically_true(ulo > uhi),    \
      |  ^~~~~~~~~~~~~~~~
./include/linux/minmax.h:195:2: note: in expansion of macro ‘__clamp_once’
  195 |  __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), 
__UNIQUE_ID(h_))
      |  ^~~~~~~~~~~~
./include/linux/minmax.h:218:36: note: in expansion of macro ‘__careful_clamp’
  218 | #define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi)
      |                                    ^~~~~~~~~~~~~~~
fs/nfsd/nfs4state.c:1825:10: note: in expansion of macro ‘clamp_t’
 1825 |  avail = clamp_t(unsigned long, avail, slotsize,
      |          ^~~~~~~
make[3]: *** [scripts/Makefile.build:297: fs/nfsd/nfs4state.o] Error 1
make[2]: *** [scripts/Makefile.build:560: fs/nfsd] Error 2
make[1]: *** [Makefile:1930: fs] Error 2
make[1]: Leaving directory '/work/linux-bluefield'
make: *** [debian/rules:7: build-arch] Error 2

** Affects: linux-bluefield (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2142422

Title:
  Bluefield 5.15.0-1084.86 build failure: nfsd4_get_drc_mem assertion
  with GCC 9

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux-bluefield/+bug/2142422/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to