mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] Fix the x86 defconfig build with GCC 17
@ 2026-11-04 16:07 Vineet Gupta
  2026-11-04 16:07 ` [PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1 Vineet Gupta
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Vineet Gupta @ 2026-11-04 16:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström
  Cc: Vineet Gupta, H. Peter Anvin, Xin Li (Intel),
	Brian Gerst, Nikolay Borisov, linux-kernel, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, Robin Murphy, iommu, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, intel-gfx,
	dri-devel, intel-xe, llvm

Fix build warnings and failures (CONFIG_WERROR=y) with a GCC 17 build.
GCC 17 adds -Wconstant-logical-operand which is strict about operands
of && or || that fold to a constant other than 0 or 1.

In the past similar fixes have been done for clang, e.g.

  93f56de25937 2017-04-06 mac80211: Fix clang warning about constant operand in logical operation  [v4.12-rc1]
  ...
  dd7fe5d9fd6a 2024-01-17 rtc: max31335: Fix comparison in max31335_volatile_reg()                 [v6.8-rc1]

The reason this trips only with gcc is that clang's toggle is more
permissive:
 - it checks RHS only, not constant LHS.
 - Macros are not checked.

Fix is to effectively make a macro or condition return 0 or 1.

The patches are split up per subsystem and can go independently via
respective trees:

  1/4 x86/cpufeatures: the awk-generated *_MASK_BIT_SET() returns 0 or 1.
  2/4 wait: ___wait_is_interruptible() with a constant state.
  3/4 iommupt: PT_SUPPORTED_FEATURE() in the fvalog2_*() helpers.
  4/4 drm/i915: IS_POWER_OF_2() in reg_bits.h, and two Kconfig timeouts.

Tested on x86 defconfig with CONFIG_WERROR=y, at each patch:

 - GCC 17 trunk (20261103): each patch removes only its own errors. The
   build has no warnings after 4/4.
 - GCC 16.1: the build has no warnings. The .text of each object file
   does not change. The only differences come from the build timestamp
   and the release string.

Vineet Gupta (4):
  x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1
  wait: Make ___wait_is_interruptible() return 0 or 1
  iommupt: Make PT_SUPPORTED_FEATURE() return 0 or 1
  drm/i915: Avoid -Wconstant-logical-operand with GCC 17

 arch/x86/tools/cpufeaturemasks.awk          | 4 ++--
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
 drivers/gpu/drm/i915/i915_config.c          | 2 +-
 drivers/iommu/generic_pt/pt_defs.h          | 2 +-
 include/drm/intel/reg_bits.h                | 2 +-
 include/linux/wait.h                        | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)

-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1
  2026-11-04 16:07 [PATCH 0/4] Fix the x86 defconfig build with GCC 17 Vineet Gupta
@ 2026-11-04 16:07 ` Vineet Gupta
  2026-11-04 16:07 ` [PATCH 2/4] wait: Make ___wait_is_interruptible() " Vineet Gupta
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2026-11-04 16:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström
  Cc: Vineet Gupta, H. Peter Anvin, Xin Li (Intel),
	Brian Gerst, Nikolay Borisov, linux-kernel

GCC 17 adds -Wconstant-logical-operand to -Wall. It warns when an operand
of && or || folds to a constant other than 0 or 1. An x86 defconfig build
with CONFIG_WERROR=y now fails in prepare0:

  arch/x86/include/asm/cpufeature.h:72:36: error: use of logical '&&' with constant operand '4194304' [-Werror=constant-logical-operand]

The *_MASK_BIT_SET() macros used to be || chains of
CHECK_BIT_IN_MASK_WORD(), so the result was 0 or 1.

Commit da414d34b555 ("x86/cpufeatures: Use AWK to generate
{REQUIRED|DISABLED}_MASK_BIT_SET in <asm/cpufeaturemasks.h>") changed
them to a ternary chain masked with (1U << bit). The result is now the
raw bit value. cpu_feature_enabled(), cpu_has() and this_cpu_has() use
this value as an && operand. clang has the same warning, but it does not
check an operator that comes from a macro expansion.

Wrap the generated expression in !!() to restore the 0 or 1 result. All
users test the value as a truth value, so the generated code does not
change.

Fixes: da414d34b555 ("x86/cpufeatures: Use AWK to generate {REQUIRED|DISABLED}_MASK_BIT_SET in <asm/cpufeaturemasks.h>")
Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
---
 arch/x86/tools/cpufeaturemasks.awk | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/tools/cpufeaturemasks.awk b/arch/x86/tools/cpufeaturemasks.awk
index 173d5bf2d999..a7856f874a6b 100755
--- a/arch/x86/tools/cpufeaturemasks.awk
+++ b/arch/x86/tools/cpufeaturemasks.awk
@@ -75,13 +75,13 @@ END {
 			printf "#define %s_MASK%d\t0x%08xU\n", s, i, masks[i];
 
 		printf "\n#define %s_MASK_BIT_SET(x)\t\t\t\\\n", s;
-		printf "\t((\t\t\t\t\t";
+		printf "\t(!!((\t\t\t\t\t";
 		for (i = 0; i < ncapints; i++) {
 			if (masks[i])
 				printf "\t\\\n\t\t((x) >> 5) == %2d ? %s_MASK%d :", i, s, i;
 		}
 		printf " 0\t\\\n";
-		printf "\t) & (1U << ((x) & 31)))\n\n";
+		printf "\t) & (1U << ((x) & 31))))\n\n";
 	}
 
 	printf "#endif /* _ASM_X86_CPUFEATUREMASKS_H */\n";
-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] wait: Make ___wait_is_interruptible() return 0 or 1
  2026-11-04 16:07 [PATCH 0/4] Fix the x86 defconfig build with GCC 17 Vineet Gupta
  2026-11-04 16:07 ` [PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1 Vineet Gupta
@ 2026-11-04 16:07 ` Vineet Gupta
  2026-11-04 16:07 ` [PATCH 3/4] iommupt: Make PT_SUPPORTED_FEATURE() " Vineet Gupta
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2026-11-04 16:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström
  Cc: Vineet Gupta, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, K Prateek Nayak, linux-kernel

GCC 17 adds -Wconstant-logical-operand to -Wall. It warns when an operand
of && or || folds to a constant other than 0 or 1. With a constant state
such as TASK_KILLABLE, ___wait_is_interruptible() breaks the build with
CONFIG_WERROR=y:

  include/linux/wait.h:285:39: error: use of logical '||' with constant operand '256' [-Werror=constant-logical-operand]

clang has the same warning, but it does not check an operator that comes
from a macro expansion.

Compare the masked state against 0. All callers test the result as a
truth value, so the behaviour does not change.

Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
---
 include/linux/wait.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index c2af98b0074d..ebabdfb5b30c 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -283,7 +283,7 @@ static inline void wake_up_pollfree(struct wait_queue_head *wq_head)
 
 #define ___wait_is_interruptible(state)						\
 	(!__builtin_constant_p(state) ||					\
-	 (state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
+	 (state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)) != 0)
 
 extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
 
-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/4] iommupt: Make PT_SUPPORTED_FEATURE() return 0 or 1
  2026-11-04 16:07 [PATCH 0/4] Fix the x86 defconfig build with GCC 17 Vineet Gupta
  2026-11-04 16:07 ` [PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1 Vineet Gupta
  2026-11-04 16:07 ` [PATCH 2/4] wait: Make ___wait_is_interruptible() " Vineet Gupta
@ 2026-11-04 16:07 ` Vineet Gupta
  2026-11-04 16:07 ` [PATCH 4/4] drm/i915: Avoid -Wconstant-logical-operand with GCC 17 Vineet Gupta
  2026-11-04 16:27 ` [PATCH 0/4] Fix the x86 defconfig build " Borislav Petkov
  4 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2026-11-04 16:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström
  Cc: Vineet Gupta, Robin Murphy, iommu, linux-kernel

GCC 17 adds -Wconstant-logical-operand to -Wall. It warns when an operand
of && or || folds to a constant other than 0 or 1. PT_SUPPORTED_FEATURE()
returns the raw feature bit, and the fvalog2_*() helpers use it as an &&
operand. The build fails with CONFIG_WERROR=y:

  drivers/iommu/generic_pt/fmt/../pt_defs.h:255:51: error: use of logical '&&' with constant operand '2' [-Werror=constant-logical-operand]

clang has the same warning, but it checks only a constant right operand.

Compare the masked value against 0. All users test the result as a truth
value, so the behaviour does not change.

Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
---
 drivers/iommu/generic_pt/pt_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/generic_pt/pt_defs.h b/drivers/iommu/generic_pt/pt_defs.h
index 707b3b0282fa..51a9c1c5fcc9 100644
--- a/drivers/iommu/generic_pt/pt_defs.h
+++ b/drivers/iommu/generic_pt/pt_defs.h
@@ -200,7 +200,7 @@ static inline bool pt_table_install32(struct pt_state *pts, u32 table_entry)
 	return ret;
 }
 
-#define PT_SUPPORTED_FEATURE(feature_nr) (PT_SUPPORTED_FEATURES & BIT(feature_nr))
+#define PT_SUPPORTED_FEATURE(feature_nr) ((PT_SUPPORTED_FEATURES & BIT(feature_nr)) != 0)
 
 static __always_inline bool pt_feature(const struct pt_common *common,
 			      unsigned int feature_nr)
-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/4] drm/i915: Avoid -Wconstant-logical-operand with GCC 17
  2026-11-04 16:07 [PATCH 0/4] Fix the x86 defconfig build with GCC 17 Vineet Gupta
                   ` (2 preceding siblings ...)
  2026-11-04 16:07 ` [PATCH 3/4] iommupt: Make PT_SUPPORTED_FEATURE() " Vineet Gupta
@ 2026-11-04 16:07 ` Vineet Gupta
  2026-11-04 16:27 ` [PATCH 0/4] Fix the x86 defconfig build " Borislav Petkov
  4 siblings, 0 replies; 8+ messages in thread
From: Vineet Gupta @ 2026-11-04 16:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström
  Cc: Vineet Gupta, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, intel-gfx, dri-devel, linux-kernel, intel-xe, llvm

GCC 17 adds -Wconstant-logical-operand to -Wall. It warns when an operand
of && or || folds to a constant other than 0 or 1. Three places break the
build with CONFIG_WERROR=y:

  include/drm/intel/reg_bits.h:27:48: error: use of logical '&&' with constant operand '256' [-Werror=constant-logical-operand]
  drivers/gpu/drm/i915/i915_config.c:13:43: error: use of logical '&&' with constant operand '10000' [-Werror=constant-logical-operand]
  drivers/gpu/drm/i915/gem/i915_gem_context.c:999:45: error: use of logical '&&' with constant operand '20000' [-Werror=constant-logical-operand]

clang has the same warning, but it checks only a constant right operand
outside a macro. Here each constant is a left operand, and
IS_POWER_OF_2() is also a macro.

Commit 1a839e016e49 ("drm/i915: remove IS_ACTIVE") moved
CONFIG_DRM_I915_FENCE_TIMEOUT to the left of && to avoid the clang
warning. That does not help with GCC 17.

Compare each constant against 0, as commit aeedd3a82678 ("drm/i915: Avoid
-Wconstant-logical-operand in nsecs_to_jiffies_timeout()") did.

Signed-off-by: Vineet Gupta <vineet.gupta@linux.dev>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
 drivers/gpu/drm/i915/i915_config.c          | 2 +-
 include/drm/intel/reg_bits.h                | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index c58ffa5a8fa6..1639639dd290 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -996,7 +996,7 @@ static int intel_context_set_gem(struct intel_context *ce,
 	    intel_engine_has_semaphores(ce->engine))
 		__set_bit(CONTEXT_USE_SEMAPHORES, &ce->flags);
 
-	if (CONFIG_DRM_I915_REQUEST_TIMEOUT &&
+	if (CONFIG_DRM_I915_REQUEST_TIMEOUT != 0 &&
 	    ctx->i915->params.request_timeout_ms) {
 		unsigned int timeout_ms = ctx->i915->params.request_timeout_ms;
 
diff --git a/drivers/gpu/drm/i915/i915_config.c b/drivers/gpu/drm/i915/i915_config.c
index 9e13b1be407c..9bbebe0a6a70 100644
--- a/drivers/gpu/drm/i915/i915_config.c
+++ b/drivers/gpu/drm/i915/i915_config.c
@@ -10,7 +10,7 @@
 
 unsigned long i915_fence_context_timeout(u64 context)
 {
-	if (CONFIG_DRM_I915_FENCE_TIMEOUT && context)
+	if (CONFIG_DRM_I915_FENCE_TIMEOUT != 0 && context)
 		return msecs_to_jiffies_timeout(CONFIG_DRM_I915_FENCE_TIMEOUT);
 
 	return 0;
diff --git a/include/drm/intel/reg_bits.h b/include/drm/intel/reg_bits.h
index 2a9066e1d808..f913c3e61f39 100644
--- a/include/drm/intel/reg_bits.h
+++ b/include/drm/intel/reg_bits.h
@@ -24,7 +24,7 @@
 /*
  * Local integer constant expression version of is_power_of_2().
  */
-#define IS_POWER_OF_2(__x)		((__x) && (((__x) & ((__x) - 1)) == 0))
+#define IS_POWER_OF_2(__x)		((__x) != 0 && (((__x) & ((__x) - 1)) == 0))
 
 /**
  * REG_FIELD_PREP8() - Prepare a u8 bitfield value
-- 
2.53.0-Meta


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/4] Fix the x86 defconfig build with GCC 17
  2026-11-04 16:07 [PATCH 0/4] Fix the x86 defconfig build with GCC 17 Vineet Gupta
                   ` (3 preceding siblings ...)
  2026-11-04 16:07 ` [PATCH 4/4] drm/i915: Avoid -Wconstant-logical-operand with GCC 17 Vineet Gupta
@ 2026-11-04 16:27 ` Borislav Petkov
  2026-11-04 18:05   ` Vineet Gupta
  4 siblings, 1 reply; 8+ messages in thread
From: Borislav Petkov @ 2026-11-04 16:27 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström, H. Peter Anvin, Xin Li (Intel),
	Brian Gerst, Nikolay Borisov, linux-kernel, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, Robin Murphy, iommu, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, intel-gfx,
	dri-devel, intel-xe, llvm

On Wed, Nov 04, 2026 at 08:07:17AM -0800, Vineet Gupta wrote:
> Fix build warnings and failures (CONFIG_WERROR=y) with a GCC 17 build.
> GCC 17 adds -Wconstant-logical-operand which is strict about operands
> of && or || that fold to a constant other than 0 or 1.

Just from looking at it, my initial reaction would be to disable that option.

Because, frankly, I don't see the point.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/4] Fix the x86 defconfig build with GCC 17
  2026-11-04 16:27 ` [PATCH 0/4] Fix the x86 defconfig build " Borislav Petkov
@ 2026-11-04 18:05   ` Vineet Gupta
  2026-11-04 21:18     ` Borislav Petkov
  0 siblings, 1 reply; 8+ messages in thread
From: Vineet Gupta @ 2026-11-04 18:05 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström, H. Peter Anvin, Xin Li (Intel),
	Brian Gerst, Nikolay Borisov, linux-kernel, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, Robin Murphy, iommu, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, intel-gfx,
	dri-devel, intel-xe, llvm, Jakub Jelinek

+CC Jakub

On 11/4/26 8:27 AM, Borislav Petkov wrote:
> On Wed, Nov 04, 2026 at 08:07:17AM -0800, Vineet Gupta wrote:
>> Fix build warnings and failures (CONFIG_WERROR=y) with a GCC 17 build.
>> GCC 17 adds -Wconstant-logical-operand which is strict about operands
>> of && or || that fold to a constant other than 0 or 1.
> Just from looking at it, my initial reaction would be to disable that option.
>
> Because, frankly, I don't see the point.

Here's my 2 cents:

I wondered if this brings any codegen improvements, since we are telling 
the compiler that something is 0 or 1 vs. some other range before. And 
it doesn't, because of the way it is used. So focusing on just 1/4.

- Constant bit: __builtin_constant_p(bit) && MASK_BIT_SET(bit) folds at 
compile time to the same truth value, with or without the !! bool 
conversion.
- Variable bit: __builtin_constant_p(bit) is 0, so && short-circuits and 
the mask is never evaluated.

Basically, the masked value never reaches generated code, so compiler 
gets nothing new to work with.

So I did some digging, and turns out that it can be helpful to catch 
bugs in the source code itself. In fact GCC implemented the toggle at 
all, when Jakub spotted an issue with a typo: (data->flags && 
ff_genericize) vs. (data->flags & ff_genericize).

In kernel, the predicate like *_BIT_SET() not returning a bool is not 
clean IMO and it used to return 0/1 before anyway so its not like we are 
going out of the way here.

I'm mildly in the favor of keeping the warning, but ultimately your 
call, I can respin with it disabled.

Thx,
-Vineet

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/4] Fix the x86 defconfig build with GCC 17
  2026-11-04 18:05   ` Vineet Gupta
@ 2026-11-04 21:18     ` Borislav Petkov
  0 siblings, 0 replies; 8+ messages in thread
From: Borislav Petkov @ 2026-11-04 21:18 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, Peter Zijlstra,
	Juri Lelli, Vincent Guittot, Joerg Roedel (AMD),
	Will Deacon, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Matthew Brost,
	Thomas Hellström, H. Peter Anvin, Xin Li (Intel),
	Brian Gerst, Nikolay Borisov, linux-kernel, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak, Robin Murphy, iommu, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, intel-gfx,
	dri-devel, intel-xe, llvm, Jakub Jelinek

On November 4, 2026 6:05:27 PM UTC, Vineet Gupta <vineet.gupta@linux.dev> wrote:
>+CC Jakub
>
>On 11/4/26 8:27 AM, Borislav Petkov wrote:
>> On Wed, Nov 04, 2026 at 08:07:17AM -0800, Vineet Gupta wrote:
>>> Fix build warnings and failures (CONFIG_WERROR=y) with a GCC 17 build.
>>> GCC 17 adds -Wconstant-logical-operand which is strict about operands
>>> of && or || that fold to a constant other than 0 or 1.
>> Just from looking at it, my initial reaction would be to disable that option.
>> 
>> Because, frankly, I don't see the point.
>
>Here's my 2 cents:
>
>I wondered if this brings any codegen improvements, since we are telling the compiler that something is 0 or 1 vs. some other range before. And it doesn't, because of the way it is used. So focusing on just 1/4.
>
>- Constant bit: __builtin_constant_p(bit) && MASK_BIT_SET(bit) folds at compile time to the same truth value, with or without the !! bool conversion.
>- Variable bit: __builtin_constant_p(bit) is 0, so && short-circuits and the mask is never evaluated.
>
>Basically, the masked value never reaches generated code, so compiler gets nothing new to work with.
>
>So I did some digging, and turns out that it can be helpful to catch bugs in the source code itself. In fact GCC implemented the toggle at all, when Jakub spotted an issue with a typo: (data->flags && ff_genericize) vs. (data->flags & ff_genericize).
>
>In kernel, the predicate like *_BIT_SET() not returning a bool is not clean IMO and it used to return 0/1 before anyway so its not like we are going out of the way here.
>
>I'm mildly in the favor of keeping the warning, but ultimately your call, I can respin with it disabled.
>
>Thx,
>-Vineet

You might wanna look at the W= switches we have for less popular and more noisy options
-- 
Small device. Typos and formatting crap

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-04 21:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 16:07 [PATCH 0/4] Fix the x86 defconfig build with GCC 17 Vineet Gupta
2026-11-04 16:07 ` [PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1 Vineet Gupta
2026-11-04 16:07 ` [PATCH 2/4] wait: Make ___wait_is_interruptible() " Vineet Gupta
2026-11-04 16:07 ` [PATCH 3/4] iommupt: Make PT_SUPPORTED_FEATURE() " Vineet Gupta
2026-11-04 16:07 ` [PATCH 4/4] drm/i915: Avoid -Wconstant-logical-operand with GCC 17 Vineet Gupta
2026-11-04 16:27 ` [PATCH 0/4] Fix the x86 defconfig build " Borislav Petkov
2026-11-04 18:05   ` Vineet Gupta
2026-11-04 21:18     ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®