[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250911213157.GA1039411@joelbox2>
Date: Thu, 11 Sep 2025 17:31:57 -0400
From: Joel Fernandes <joelagnelf@...dia.com>
To: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: John Hubbard <jhubbard@...dia.com>,
Alexandre Courbot <acourbot@...dia.com>,
Timur Tabi <ttabi@...dia.com>, Alistair Popple <apopple@...dia.com>,
Miguel Ojeda <ojeda@...nel.org>
Subject: Printing with overflow checks can cause modpost errors
Hello,
Recently some of have been running into modpost errors more frequently. Ahead
of Kangrejos, I am trying to study them, the one I looked at today is truly
weird, below are more details.
I narrowed it down to the print statement and specifically the FFI call to
printk bindings. This was first reported by Timur Tabi on CC.
With CONFIG_RUST_OVERFLOW_CHECKS=y and CONFIG_RUST_BUILD_ASSERT_ALLOW=y, the
following patch when applied to nova-core will fail to build with following
errors. The question is why does the overflow checking fail since the
arithmetic is valid, and why only during printing (and say not during the
call to write32).
MODPOST Module.symvers
ERROR: modpost: "rust_build_error" [drivers/gpu/nova-core/nova_core.ko] undefined!
make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1
make[1]: *** [/home/joelaf/repo/linux-nova-rm-call/Makefile:1961: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Any comments or thoughts?
---8<-----------------------
From: Joel Fernandes <joelagnelf@...dia.com>
Subject: [PATCH] Reproduce modpost error due to print
Signed-off-by: Joel Fernandes <joelagnelf@...dia.com>
---
drivers/gpu/nova-core/nova_core.rs | 1 +
drivers/gpu/nova-core/test_modpost.rs | 60 +++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
create mode 100644 drivers/gpu/nova-core/test_modpost.rs
diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
index 4dbc7e5daae3..9ed48ddf6df9 100644
--- a/drivers/gpu/nova-core/nova_core.rs
+++ b/drivers/gpu/nova-core/nova_core.rs
@@ -15,6 +15,7 @@
mod sbuffer;
mod util;
mod vbios;
+mod test_modpost;
pub(crate) const MODULE_NAME: &kernel::str::CStr = <LocalModule as kernel::ModuleMetadata>::NAME;
diff --git a/drivers/gpu/nova-core/test_modpost.rs b/drivers/gpu/nova-core/test_modpost.rs
new file mode 100644
index 000000000000..eab82b6176a8
--- /dev/null
+++ b/drivers/gpu/nova-core/test_modpost.rs
@@ -0,0 +1,60 @@
+use kernel::prelude::*;
+use kernel::io::Io;
+use core::ops::Deref;
+use crate::driver::Bar0;
+use crate::falcon::{FalconEngine};
+use crate::falcon::gsp::Gsp;
+
+macro_rules! test_reg_array {
+ ($name:ident @ $base:ty [ $offset:literal [ $size:expr ] ]) => {
+ pub(crate) struct $name(u32);
+
+ impl $name {
+ pub(crate) const OFFSET: usize = $offset;
+ pub(crate) const SIZE: usize = $size;
+ pub(crate) const STRIDE: usize = 4;
+
+ #[inline(always)]
+ pub(crate) fn write_with_printk<const SIZE: usize, T, B>(
+ self,
+ io: &T,
+ _base: &B,
+ idx: usize
+ ) where
+ T: Deref<Target = Io<SIZE>>,
+ B: kernel::io::register::RegisterBase<$base>,
+ {
+ // This assert has no effect on the issue and can be commented
+ // to still reproduce the error.
+ build_assert!(idx < Self::SIZE);
+
+ let offset = <B as kernel::io::register::RegisterBase<$base>>::BASE +
+ Self::OFFSET + (idx * Self::STRIDE);
+
+ // PRINTK BLOCK -- entire block can be replaced with pr_err("{}", offset)
+ // and it would still show the same error.
+ let args = core::format_args!("{}", offset);
+ unsafe {
+ kernel::bindings::_printk( // ---> Causes the MODPOST error
+ kernel::print::format_strings::ERR.as_ptr(),
+ crate::__LOG_PREFIX.as_ptr(),
+ core::ptr::from_ref(&args).cast::<kernel::ffi::c_void>(),
+ );
+ }
+ // END PRINTK BLOCK
+
+ io.write32(self.0, offset);
+ }
+
+ }
+ };
+}
+
+test_reg_array!(TestFbifTranscfg @ crate::falcon::PFalconBase [ 0x00000600 [ 8 ] ]);
+
+#[no_mangle]
+pub(crate) extern "C" fn test_single(bar: &Bar0) {
+ TestFbifTranscfg(0x00000001).write_with_printk(bar, &Gsp::ID, 0);
+}
+
+
--
2.34.1
Powered by blists - more mailing lists