Thread (15 messages) 15 messages, 7 authors, 2026-01-30
STALE172d

[RFC PATCH 2/2] kbuild: rust: use klint to provide CONFIG_FRAME_WARN

From: Gary Guo <gary@kernel.org>
Date: 2026-01-27 17:23:59
Also in: linux-kbuild, lkml
Subsystem: kernel build + files below scripts/ (unless maintained elsewhere), the rest · Maintainers: Nathan Chancellor, Nicolas Schier, Linus Torvalds

From: Gary Guo <gary@garyguo.net>

klint is able to analyze frame size and warn on frames that are too big.

With `register_tool(klint)` support, we can simply instruct rust to turn on
`klint::stack_frame_too_large`. This is a no-op if normal rustc (or Clippy)
is invoked, but will perform the check if klint is used.

This is an example of a bug caught using this option:

warning: stack size of `gsp::cmdq::Cmdq::new` is 8216 bytes, exceeds the 2048-byte limit
   --> drivers/gpu/nova-core/gsp/cmdq.rs:453:5
    |
453 |     pub(crate) fn new(dev: &device::Device<device::Bound>) -> Result<Cmdq> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the stack size is inferred from instruction `sub $0x2018,%rsp` at .text+32778

Signed-off-by: Gary Guo <gary@garyguo.net>
---
 scripts/Makefile.warn | 1 +
 1 file changed, 1 insertion(+)
diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn
index 5567da6c7dfe..254a4d53f8f3 100644
--- a/scripts/Makefile.warn
+++ b/scripts/Makefile.warn
@@ -23,6 +23,7 @@ KBUILD_CFLAGS += -Wmissing-prototypes
 
 ifneq ($(CONFIG_FRAME_WARN),0)
 KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
+KBUILD_RUSTFLAGS += -Wklint::stack-frame-too-large
 endif
 
 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
-- 
2.51.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help