linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kstack_erase: Add -mgeneral-regs-only to silence Clang warnings
@ 2025-07-26 21:26 Kees Cook
  2025-07-27 15:51 ` Nathan Chancellor
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2025-07-26 21:26 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Kees Cook, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Ingo Molnar, Andrew Morton, Mike Rapoport (Microsoft),
	Pratyush Yadav, Jonathan Cameron, Coiby Xu, Josh Poimboeuf,
	Alexander Graf, linux-kernel, llvm, linux-hardening

Once CONFIG_KSTACK_ERASE is enabled with Clang on i386, the build warns:

  kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]

Add -mgeneral-regs-only for the kstack_erase handler, to make Clang feel
better (it is effectively a no-op flag for the kernel). No binary
changes encountered.

Build & boot tested with Clang 21 on x86_64, and i386.
Build tested with GCC 14.2.0 on x86_64, i386, arm64, and arm.

Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/all/20250726004313.GA3650901@ax162
Signed-off-by: Kees Cook <kees@kernel.org>
---
 kernel/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/Makefile b/kernel/Makefile
index e4f01f1d4d0c..0ee9afd8b7cf 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -140,6 +140,7 @@ obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o
 obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
 
 CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
+CFLAGS_kstack_erase.o += $(call cc-option,-mgeneral-regs-only)
 obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
 KASAN_SANITIZE_kstack_erase.o := n
 KCSAN_SANITIZE_kstack_erase.o := n
-- 
2.34.1


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

* Re: [PATCH] kstack_erase: Add -mgeneral-regs-only to silence Clang warnings
  2025-07-26 21:26 [PATCH] kstack_erase: Add -mgeneral-regs-only to silence Clang warnings Kees Cook
@ 2025-07-27 15:51 ` Nathan Chancellor
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Chancellor @ 2025-07-27 15:51 UTC (permalink / raw)
  To: Kees Cook
  Cc: Nick Desaulniers, Bill Wendling, Justin Stitt, Ingo Molnar,
	Andrew Morton, Mike Rapoport (Microsoft), Pratyush Yadav,
	Jonathan Cameron, Coiby Xu, Josh Poimboeuf, Alexander Graf,
	linux-kernel, llvm, linux-hardening

On Sat, Jul 26, 2025 at 02:26:19PM -0700, Kees Cook wrote:
> Once CONFIG_KSTACK_ERASE is enabled with Clang on i386, the build warns:
> 
>   kernel/kstack_erase.c:168:2: warning: function with attribute 'no_caller_saved_registers' should only call a function with attribute 'no_caller_saved_registers' or be compiled with '-mgeneral-regs-only' [-Wexcessive-regsave]
> 
> Add -mgeneral-regs-only for the kstack_erase handler, to make Clang feel
> better (it is effectively a no-op flag for the kernel). No binary
> changes encountered.
> 
> Build & boot tested with Clang 21 on x86_64, and i386.
> Build tested with GCC 14.2.0 on x86_64, i386, arm64, and arm.
> 
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Closes: https://lore.kernel.org/all/20250726004313.GA3650901@ax162
> Signed-off-by: Kees Cook <kees@kernel.org>

Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  kernel/Makefile | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/Makefile b/kernel/Makefile
> index e4f01f1d4d0c..0ee9afd8b7cf 100644
> --- a/kernel/Makefile
> +++ b/kernel/Makefile
> @@ -140,6 +140,7 @@ obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o
>  obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o
>  
>  CFLAGS_kstack_erase.o += $(DISABLE_KSTACK_ERASE)
> +CFLAGS_kstack_erase.o += $(call cc-option,-mgeneral-regs-only)
>  obj-$(CONFIG_KSTACK_ERASE) += kstack_erase.o
>  KASAN_SANITIZE_kstack_erase.o := n
>  KCSAN_SANITIZE_kstack_erase.o := n
> -- 
> 2.34.1
> 

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

end of thread, other threads:[~2025-07-27 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-26 21:26 [PATCH] kstack_erase: Add -mgeneral-regs-only to silence Clang warnings Kees Cook
2025-07-27 15:51 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).