Re: [PATCH 2/7] scripts: modpost: increase buf_printf's buffer size
From: Alexandre Courbot
Date: Tue May 19 2026 - 23:52:55 EST
On Wed May 20, 2026 at 11:44 AM JST, Alexandre Courbot wrote:
> Hi Gary,
>
> On Fri May 1, 2026 at 10:02 PM JST, Gary Guo wrote:
>> On Thu Apr 30, 2026 at 3:55 PM BST, Alexandre Courbot wrote:
>>> Rust tends to produce long symbol names; when trying to export symbols
>>> from nova-core for nova-drm to link to, the 500 bytes of the internal
>>> buffer used for symbol name formatting are not enough, making modpost
>>> fail.
>>>
>>> Fix this by increasing the size of the buffer used to format the symbols
>>> to 1024 bytes. It is a stack buffer, but modpost is a user-space program
>>> so that shouldn't be a problem.
>>
>> I think we should make sure all constants related to symbol names match.
>> KSYM_NAME_LEN is 512 so this should just be that.
>
> Do you mean we should use `KSYM_NAME_LEN` for the size of `tmp`? The
> formatted strings can be longer than the symbol name alone (see the
> example below which wraps it into `KSYMTAB_FUNC()`), so this should
> probably be `KSYM_NAME_LEN + something` if we align to it.
>
>>
>> The only case that I've been hit with very long symbol names so far is doc tests.
>> Can you provide an example of the case where you're hit with very long symbol
>> names in Nova? In many cases they're just functions that are supposed to be
>> inlined but isn't.
>
> Here is an example string that doesn't make it, it doesn't seem related
> to doctests but also doesn't occur on all configs:
>
> ERROR: modpost: buf_printf output was truncated for string
> KSYMTAB_FUNC(_RINvXs5_NtNtCs1EKtwoKEMO2_6kernel5alloc4kboxINtB6_3BoxINtNtNtCs1peUGmbrgHn_4core3mem12maybe_uninit11MaybeUninitINtNtBa_9auxiliary16RegistrationDataNtNtCs6wA3Ay79aUn_9nova_core6driver7AuxDataEENtNtB8_9allocator7KmallocEINtCsfxcgfq7FLKi_8pin_init12InPlaceWriteB1L_E14write_pin_initNtNtBa_5error5ErrorINtNtB3x_10___internal11InitClosureNCINvYIBH_B1L_B34_EINtNtBa_4init11InPlaceInitB1L_E8pin_initB4t_IB4N_NCINvMsd_B1O_INtB1O_12RegistrationINtNtNtBa_5types6for_lt15UnsafeForLtImplDG_INtB72_:
> 608 bytes needed, 500 available
So if I add the inlines in the diff thereafter, these errors are gone,
without even increasing `SZ`.
The module also appears to be smaller:
$ size /tmp/nova_core_base.o /tmp/nova_core_inline.o
text data bss dec hex filename
103856 736 288 104880 199b0 /tmp/nova_core_base.o
102718 736 288 103742 1953e /tmp/nova_core_inline.o
Here is the diff. I can try to fine-tune the places we inline, but they
all look sensible to me.
diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
index 2f8c16473c2c..592fffc72e52 100644
--- a/rust/kernel/alloc/kbox.rs
+++ b/rust/kernel/alloc/kbox.rs
@@ -433,6 +433,7 @@ impl<T, A> InPlaceWrite<T> for Box<MaybeUninit<T>, A>
{
type Initialized = Box<T, A>;
+ #[inline(always)]
fn write_init<E>(mut self, init: impl Init<T, E>) -> Result<Self::Initialized, E> {
let slot = self.as_mut_ptr();
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
@@ -442,6 +443,7 @@ fn write_init<E>(mut self, init: impl Init<T, E>) -> Result<Self::Initialized, E
Ok(unsafe { Box::assume_init(self) })
}
+ #[inline(always)]
fn write_pin_init<E>(mut self, init: impl PinInit<T, E>) -> Result<Pin<Self::Initialized>, E> {
let slot = self.as_mut_ptr();
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 7a0d4559d7b5..36d4bf1959fb 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -151,6 +151,7 @@ fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::Pinne
/// type.
///
/// If `T: !Unpin` it will not be able to move afterwards.
+ #[inline(always)]
fn pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> error::Result<Self::PinnedSelf>
where
Error: From<E>,
diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index 18d6c0d62ce0..973f15165606 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -712,6 +712,7 @@ fn try_init<E>(init: impl Init<T, E>, flags: Flags) -> Result<Self, E>
impl<T> InPlaceWrite<T> for UniqueArc<MaybeUninit<T>> {
type Initialized = UniqueArc<T>;
+ #[inline(always)]
fn write_init<E>(mut self, init: impl Init<T, E>) -> Result<Self::Initialized, E> {
let slot = self.as_mut_ptr();
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
@@ -721,6 +722,7 @@ fn write_init<E>(mut self, init: impl Init<T, E>) -> Result<Self::Initialized, E
Ok(unsafe { self.assume_init() })
}
+ #[inline(always)]
fn write_pin_init<E>(mut self, init: impl PinInit<T, E>) -> Result<Pin<Self::Initialized>, E> {
let slot = self.as_mut_ptr();
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index ac316fd7b538..381a06ee0d59 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -367,6 +367,7 @@ pub const fn zeroed() -> Self {
/// This function is safe, because the `T` inside of an `Opaque` is allowed to be
/// uninitialized. Additionally, access to the inner `T` requires `unsafe`, so the caller needs
/// to verify at that point that the inner value is valid.
+ #[inline(always)]
pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit<Self> {
// SAFETY: We contain a `MaybeUninit`, so it is OK for the `init_func` to not fully
// initialize the `T`.
@@ -386,6 +387,7 @@ pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit<Self> {
/// This function is safe, because the `T` inside of an `Opaque` is allowed to be
/// uninitialized. Additionally, access to the inner `T` requires `unsafe`, so the caller needs
/// to verify at that point that the inner value is valid.
+ #[inline(always)]
pub fn try_ffi_init<E>(
init_func: impl FnOnce(*mut T) -> Result<(), E>,
) -> impl PinInit<Self, E> {
@@ -417,6 +419,7 @@ pub const fn cast_from(this: *const T) -> *const Self {
impl<T> Wrapper<T> for Opaque<T> {
/// Create an opaque pin-initializer from the given pin-initializer.
+ #[inline(always)]
fn pin_init<E>(slot: impl PinInit<T, E>) -> impl PinInit<Self, E> {
Self::try_ffi_init(|ptr: *mut T| {
// SAFETY:
diff --git a/rust/pin-init/internal/src/pin_data.rs b/rust/pin-init/internal/src/pin_data.rs
index 7d871236b49c..945254740f61 100644
--- a/rust/pin-init/internal/src/pin_data.rs
+++ b/rust/pin-init/internal/src/pin_data.rs
@@ -395,6 +395,7 @@ fn handle_field(
/// to deallocate.
#pin_safety
#(#attrs)*
+ #[inline(always)]
#vis unsafe fn #ident<E>(
self,
slot: *mut #ty,
@@ -409,6 +410,7 @@ fn handle_field(
///
#[doc = #slot_safety]
#(#attrs)*
+ #[inline(always)]
#vis unsafe fn #project_ident<'__slot>(
self,
slot: &'__slot mut #ty,