From nobody Mon Jun 15 10:48:49 2026 Received: from mx07-00376f01.pphosted.com (mx07-00376f01.pphosted.com [185.132.180.163]) (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 4ACAF36CDFE for ; Thu, 9 Apr 2026 14:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.132.180.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775746712; cv=none; b=ZUBvfSMiwuzT34VDEGbyQD6qaHmkZEpoa0LkvFmCu9UV3iBbpYaSj60TwUnS6EAEZPT/QmlCwU6KP4/qzrZTH4T0GE5zs0OuKphe0Oc7boLEVA7fanRMVYpjyFPMQ64T7BTIz6qJS6UU25LwVMGgrJyWJXXUawrFOBRIelSbF9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775746712; c=relaxed/simple; bh=xvGHLrQXE2gACzE7P2oKEtZAfY3wiqPEcSs628XxgUY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:To:CC; b=DZrGML8gAWzzoHDfnbRIdvtE159MVlACUBhPIZXDogDmRcd5Zl6qZF6E1afj7KJr8GQu3HOs/gkH8mbKkJE4gbvBdLRKzPKqET7dIU38BuaajZqj6zpNYiP5fXG5cnhbQ5JoOCw7Fc+jGlLTv6v2PZAD2MF3TVDYzLQV7v3Ph1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=imgtec.com; spf=pass smtp.mailfrom=imgtec.com; dkim=pass (2048-bit key) header.d=imgtec.com header.i=@imgtec.com header.b=k++xAWLX; arc=none smtp.client-ip=185.132.180.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=imgtec.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=imgtec.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=imgtec.com header.i=@imgtec.com header.b="k++xAWLX" Received: from pps.filterd (m0168889.ppops.net [127.0.0.1]) by mx07-00376f01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6395unbi1397272; Thu, 9 Apr 2026 15:58:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imgtec.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=dk201812; bh=4Bc99TLFXFEQszZYBHxJtuX o0lDxGr5QOxOjqTE+fGg=; b=k++xAWLX1mZObMRgQ2o93MjOJr8/ZSfIkkzWVH9 gGy9LKGYWljgIdCUk/BB9lFo/bKZ+h2xH/orAFvI1HFqQ80/PmiJ5FQjdB178kM1 /jAAgfpHvNQ/6mfFYnsxLbMxqVSPZhv2v4EckiFfz1QRS9ZuJjvHHm+km+s2usxx msG53pNiwNQ/xww2mANLoWNK+JSBEdbygId6BGDE0ZRowdlkxU63Li4vhCR41Akl mz0Gy3g02AaTS9U3FWwxvthqBnheEf6qOLRaGR1nXTSP+grRMTGXZCuoNYWzxaAC fy35+seEbkYDYTbJCDr8O0sbOdyRs4xph75Ut3CwrU+9w/A== Received: from hhmail01.hh.imgtec.org (83-244-153-141.cust-83.exponential-e.net [83.244.153.141]) by mx07-00376f01.pphosted.com (PPS) with ESMTPS id 4dd4s2hw18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Apr 2026 15:58:05 +0100 (BST) Received: from HHMAIL03.hh.imgtec.org (10.44.0.121) by HHMAIL01.hh.imgtec.org (10.100.10.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Thu, 9 Apr 2026 15:58:04 +0100 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa (172.25.4.178) by HHMAIL03.hh.imgtec.org (10.44.0.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Thu, 9 Apr 2026 15:58:03 +0100 From: Matt Coster Date: Thu, 9 Apr 2026 15:57:53 +0100 Subject: [PATCH] bitfield: Fix FIELD_PREP_CONST() with __GENMASK_ULL() on gcc<14 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20260409-field-prep-fix-v1-1-f0e9ae64f63c@imgtec.com> X-B4-Tracking: v=1; b=H4sIAHC+12kC/yWMUQ5AMBBEryL7rUlbNOIq4oN2y4ogLSIRd7f4m zeTeRdEDIQRquSCgAdFWmYGlSZgh3buUZBjBi21kZnOhSecnFgDrhxP4Z23OXamVIUBPvHA9Se sm5/j3o1ot9cC9/0AIIsVt3IAAAA= X-Change-ID: 20260324-field-prep-fix-fdfc4eb68156 To: Yury Norov , Rasmus Villemoes CC: Frank Binns , Alessio Belle , Brajesh Gupta , Alexandru Dadu , , Vincent Mailhol , kernel test robot , Matt Coster X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4207; i=matt.coster@imgtec.com; h=from:subject:message-id; bh=xvGHLrQXE2gACzE7P2oKEtZAfY3wiqPEcSs628XxgUY=; b=owGbwMvMwCFWuUfy8817WRsYT6slMWRe31e96uIujo2rz/zzW851IP/lncN1C+SyLpgZd05M6 OuvCXJL7yhlYRDjYJAVU2TZscJyhdofNS2JG7+KYeawMoEMYeDiFICJXN7GyNChqC2+9s/kDy8P GMS8sixQTv/XPm/BpQm+B+PWPlu/eOU/RoYVzxf9fjJ94ub3v2fM2hn27YTJeQEGqToZwWC76si mBAlWAA== X-Developer-Key: i=matt.coster@imgtec.com; a=openpgp; fpr=05A40CFCE7269D61D97100A1747F0A9036F90DFA X-Proofpoint-GUID: psPArSeWhNl4pYq6ZDd4TPUETpGc4v09 X-Authority-Analysis: v=2.4 cv=cL/QdFeN c=1 sm=1 tr=0 ts=69d7be7d cx=c_pps a=AKOq//PuzOIrVTIF9yBwbA==:117 a=AKOq//PuzOIrVTIF9yBwbA==:17 a=vO48zYV2LvQA:10 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=kQ-hrUj2-E3RCbRHssb7:22 a=7RYWX5rxfSByPNLylY2M:22 a=mDV3o1hIAAAA:8 a=VwQbUJbxAAAA:8 a=QyXUC8HyAAAA:8 a=r_1tXGB3AAAA:8 a=_e7T1ioa-ZxF_c6fMS0A:9 a=QEXdDO2ut3YA:10 a=t8nPyN_e6usw4ciXM-Pk:22 X-Proofpoint-ORIG-GUID: psPArSeWhNl4pYq6ZDd4TPUETpGc4v09 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA5MDEzNyBTYWx0ZWRfXxlwpvLeyPFqf +W7jAsAWkrklmY+C/21gKxHjqNzzN5tJAOXQFZy2rirPkPrMS5d3rbofdEIdoirGCfl8w6OpAsU vcpDsXKj+stWGx7D78t6w5M1p7iZeTmokZOPUIo9LZhpFzhRKrs5sG67ldOw57aNd2Fta3lQNyG twOqrUp6J7WbCQfh9HrIqZVJp9jDz0ILzbCG5hCT8qZulJdyCY/duiVCL+Tq/cOOt2Zbd2O+lSs m3gVMbWdlhWWSwXAMOgZB8GxPA71Ter/QoTtLpfWY9czcOB63ZDkI1pvPXIc8EYEGSloGBgQ07i 0+0uDNuipZLETmPsC1ay0z6Xd6bH9AzT/Dyo1axyHs6KATVIqV0BxwqcfyKs+wSUvOT41rK1YQd 5wXyFsL8TheXXbJdbWKzplrvNy0zHM+L7RSYwXY4xABiizxWkperG05K8RbiIvxtF7YuqZyCr/F Et608IJgkyJxGkkxwYw== There is a bug in gcc<14[1] that causes the following minimal example to not be treated as a constant: int main() { sizeof(struct { int t : !(__builtin_ffsll(~0ULL) + 1 < 0); }); } test.c: In function 'main': test.c:3:21: error: bit-field 't' width not an integer constant 3 | int t : !(__builtin_ffsll(~0ULL) + 1 < 0); | ^ The result of this bug is a bizarre interaction between FIELD_PREP_CONST() and __GENMASK_ULL(). Note that this does not occur with GENMASK_ULL() since that has not been based on the UAPI variant since commit 104ea1c84b91 ("bits: unify the non-asm GENMASK*()"). The underlying compiler bug has been fixed in gcc since 14.1.0, but the fix appears to have been incidental in a larger change[2]. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D124699 [2]: https://gcc.gnu.org/cgit/gcc/commit/?id=3D0d00385eaf72ccacff17935b0d21= 4a26773e095f Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202603222211.A2XiR1YU-lkp@int= el.com/ Signed-off-by: Matt Coster --- Some below-the-dash thoughts: This is the most minimal workaround I could find. I'm not sure what a "real" fix would look like here so I'm open to suggestions. The reproduction case is amazing because changing almost any subtle detail of it will result in the expression correctly being parsed as constant (even raising the construct to file scope; the use of BUILD_BUG_ON_ZERO() is part of the bizarre confluence required to trigger the bug). The complexity of the associated change in gcc makes it difficult to trace what actually changed to fix the underlying bug. If I had more time, I'd have dug in further and (tried to) come up with an answer. In reality, the (long long) cast could probably just be univerally applied without the conditional compilation. My only concern with that approach is that it risks turning the workaround into an arcane incantation whose meaning will eventually have been lost to time. --- include/linux/bitfield.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 54aeeef1f0ec7..12f5c5a3c8d72 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -46,6 +46,30 @@ =20 #define __bf_shf(x) (__builtin_ffsll(x) - 1) =20 +#if defined(GCC_VERSION) && (GCC_VERSION < 140000) +/* + * This workaround is required for gcc<14. The issue is an interaction bet= ween + * FIELD_PREP_CONST() and __GENMASK_ULL() that can be boiled down this MCV= E, + * which fails to compile as GCC doesn't recognize the expression as const= ant: + * + * int main() { + * sizeof(struct { + * int t : !(__builtin_ffsll(~0ULL) + 1 < 0); + * }); + * } + * + * The underlying issue was inadvertently "fixed" (or perhaps sidestepped)= in + * commit 0d00385eaf7 ("wide-int: Allow up to 16320 bits wide_int and chan= ge + * widest_int precision to 32640 bits [PR102989]"), which first appeared in + * GCC 14.1. + * + * See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D124699 + */ +#define __const_bf_shf(x) __bf_shf((long long)(x)) +#else +#define __const_bf_shf(x) __bf_shf(x) +#endif + #define __scalar_type_to_unsigned_cases(type) \ unsigned type: (unsigned type)0, \ signed type: (unsigned type)0 @@ -157,11 +181,11 @@ /* mask must be non-zero */ \ BUILD_BUG_ON_ZERO((_mask) =3D=3D 0) + \ /* check if value fits */ \ - BUILD_BUG_ON_ZERO(~((_mask) >> __bf_shf(_mask)) & (_val)) + \ + BUILD_BUG_ON_ZERO(~((_mask) >> __const_bf_shf(_mask)) & (_val)) + \ /* check if mask is contiguous */ \ - __BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) + \ + __BF_CHECK_POW2((_mask) + (1ULL << __const_bf_shf(_mask))) + \ /* and create the value */ \ - (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask)) \ + (((typeof(_mask))(_val) << __const_bf_shf(_mask)) & (_mask)) \ ) =20 /** --- base-commit: b20a9b5f9c4baeae0b2e143046b195b910c59714 change-id: 20260324-field-prep-fix-fdfc4eb68156