mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vineet Gupta <vineet.gupta@linux.dev>
To: "Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "Peter Zijlstra" <peterz@infradead.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Joerg Roedel (AMD)" <joro@8bytes.org>,
	"Will Deacon" <will@kernel.org>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Cc: Vineet Gupta <vineet.gupta@linux.dev>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Xin Li (Intel)" <xin@zytor.com>, Brian Gerst <brgerst@gmail.com>,
	Nikolay Borisov <nik.borisov@suse.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/4] x86/cpufeatures: Make {REQUIRED,DISABLED}_MASK_BIT_SET() return 0 or 1
Date: Wed,  4 Nov 2026 08:07:18 -0800	[thread overview]
Message-ID: <20261104160722.1637541-2-vineet.gupta@linux.dev> (raw)
In-Reply-To: <20261104160722.1637541-1-vineet.gupta@linux.dev>

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


  reply	other threads:[~2026-11-04 16:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-04 16:07 ` [PATCH 2/4] wait: Make ___wait_is_interruptible() return 0 or 1 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

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=20261104160722.1637541-2-vineet.gupta@linux.dev \
    --to=vineet.gupta@linux.dev \
    --cc=airlied@gmail.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=peterz@infradead.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=tglx@kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tursulin@ursulin.net \
    --cc=vincent.guittot@linaro.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=xin@zytor.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

all inboxes | Powered by JetHome®