Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Ali Nasrollahi <a.nasrolahi01@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev,  kees@kernel.org, nathan@kernel.org
Subject: Re: [PATCH] x86/cfi: mark cfi_debug as __maybe_unused
Date: Thu, 19 Nov 2026 09:35:30 +0330	[thread overview]
Message-ID: <av6OwOx3psCYzS4L@zephyr> (raw)
In-Reply-To: <20261117183505.GL1813469@noisy.programming.kicks-ass.net>

On 26/11/17 07:35PM, Peter Zijlstra wrote:
> On Mon, Nov 16, 2026 at 09:00:27PM +0330, Ali Nasrollahi wrote:
> >     When CONFIG_FINEIBT is disabled, cfi_debug is never read, but
> >     alternative_instructions() still resets it after calling
> >     __apply_fineibt(). Clang 23 diagnoses this as -Wunused-but-set-global
> >     with W=1, causing a build failure when CONFIG_WERROR=y. Mark cfi_debug
> >     as __maybe_unused to account for configurations without FineIBT.
> > 
> > Signed-off-by: Ali Nasrollahi <A.Nasrolahi01@gmail.com>
> 
> Does something like so also work?
> 
> ---
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index efbc11f8c336..9bfc36566e17 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -1195,9 +1195,9 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { }
>  #endif
>  
>  enum cfi_mode cfi_mode __ro_after_init = __CFI_DEFAULT;
> -static bool cfi_debug __ro_after_init;
>  
>  #ifdef CONFIG_FINEIBT_BHI
> +static bool cfi_debug __ro_after_init;
>  bool cfi_bhi __ro_after_init = false;
>  #endif
>  
> @@ -1894,6 +1894,7 @@ static void __init_or_module __apply_fineibt(s32 *start_retpoline, s32 *end_retp
>  		break;
>  	}
>  
> +	cfi_debug = false;
>  err:
>  	pr_err("Something went horribly wrong trying to rewrite the CFI implementation.\n");
>  }
> @@ -2281,7 +2282,6 @@ void __init alternative_instructions(void)
>  
>  	__apply_fineibt(__retpoline_sites, __retpoline_sites_end,
>  			__cfi_sites, __cfi_sites_end, true);
> -	cfi_debug = false;
>  
>  	/*
>  	 * Rewrite the retpolines, must be done before alternatives since

Thank you for your review.

Regarding this:

>  #ifdef CONFIG_FINEIBT_BHI
> +static bool cfi_debug __ro_after_init;
>  bool cfi_bhi __ro_after_init = false;
>  #endif

FINEIBT can be enabled while FINEIBT_BHI is disabled, for example when
rust is enabled. In that case, the declaration is compiled out while
the uses remain, which naturally caused my build to fail with an
undeclared cfi_debug. Maybe you meant to put it under under
CONFIG_FINEIBT instead?

Additionally, I kept my original patch limited to the warning fix
because I wasn't sure about the effects of changing the reset. With your
change the CFI_OFF, CFI_KCFI and CFI_FINEIBT cases return before
reaching the new assignment. Wouldn't this change the behviour? or
perhaps that is expected.

Cheers,
    -- Ali

  reply	other threads:[~2026-11-19  6:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:30 [PATCH] x86/cfi: mark cfi_debug as __maybe_unused Ali Nasrollahi
2026-11-17 18:35 ` Peter Zijlstra
2026-11-19  6:05   ` Ali Nasrollahi [this message]
2026-11-19  9:10     ` Peter Zijlstra

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=av6OwOx3psCYzS4L@zephyr \
    --to=a.nasrolahi01@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /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