* [PATCH] samples: rust: debugfs: fix excessive stack use
@ 2026-07-16 14:41 Gary Guo
2026-07-16 20:33 ` Alexandre Courbot
0 siblings, 1 reply; 3+ messages in thread
From: Gary Guo @ 2026-07-16 14:41 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Matthew Maurer
Cc: driver-core, rust-for-linux, linux-kernel
From: Gary Guo <gary@garyguo.net>
The current implementation creates a 4K array and move it into the box.
Klint reports that this causes excesssive stack usage:
warning: stack size of `create_file_write` is 4472 bytes, exceeds the 2048-byte limit
--> samples/rust/rust_debugfs_scoped.rs:54:1
|
54 | / fn create_file_write(
55 | | mod_data: &ModuleData,
56 | | reader: &mut kernel::uaccess::UserSliceReader,
57 | | ) -> Result {
| |___________^
|
= note: the stack size is inferred from instruction `sub $0x1178,%rsp` at .text+2205
Use pin-init to create the array in-place instead.
Fixes: f656279afde1 ("samples: rust: debugfs_scoped: add example for blobs")
Signed-off-by: Gary Guo <gary@garyguo.net>
---
samples/rust/rust_debugfs_scoped.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
index 6a575a15a2c2..33a4a0865f5b 100644
--- a/samples/rust/rust_debugfs_scoped.rs
+++ b/samples/rust/rust_debugfs_scoped.rs
@@ -75,7 +75,7 @@ fn create_file_write(
GFP_KERNEL,
)?;
}
- let blob = KBox::pin_init(new_mutex!([0x42; SZ_4K]), GFP_KERNEL)?;
+ let blob = KBox::pin_init(new_mutex!(pin_init::init_array_from_fn(|_| 0x42)), GFP_KERNEL)?;
let scope = KBox::pin_init(
mod_data.device_dir.scope(
base-commit: b8809969e1d7a591e0f49dd464a5d04b3cf02ab1
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] samples: rust: debugfs: fix excessive stack use
2026-07-16 14:41 [PATCH] samples: rust: debugfs: fix excessive stack use Gary Guo
@ 2026-07-16 20:33 ` Alexandre Courbot
2026-07-16 21:09 ` Gary Guo
0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Courbot @ 2026-07-16 20:33 UTC (permalink / raw)
To: Gary Guo
Cc: Gary Guo, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Thu Jul 16, 2026 at 7:41 AM PDT, Gary Guo wrote:
> From: Gary Guo <gary@garyguo.net>
>
> The current implementation creates a 4K array and move it into the box.
> Klint reports that this causes excesssive stack usage:
>
> warning: stack size of `create_file_write` is 4472 bytes, exceeds the 2048-byte limit
> --> samples/rust/rust_debugfs_scoped.rs:54:1
> |
> 54 | / fn create_file_write(
> 55 | | mod_data: &ModuleData,
> 56 | | reader: &mut kernel::uaccess::UserSliceReader,
> 57 | | ) -> Result {
> | |___________^
> |
> = note: the stack size is inferred from instruction `sub $0x1178,%rsp` at .text+2205
>
> Use pin-init to create the array in-place instead.
>
> Fixes: f656279afde1 ("samples: rust: debugfs_scoped: add example for blobs")
> Signed-off-by: Gary Guo <gary@garyguo.net>
> ---
> samples/rust/rust_debugfs_scoped.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
> index 6a575a15a2c2..33a4a0865f5b 100644
> --- a/samples/rust/rust_debugfs_scoped.rs
> +++ b/samples/rust/rust_debugfs_scoped.rs
> @@ -75,7 +75,7 @@ fn create_file_write(
> GFP_KERNEL,
> )?;
> }
> - let blob = KBox::pin_init(new_mutex!([0x42; SZ_4K]), GFP_KERNEL)?;
> + let blob = KBox::pin_init(new_mutex!(pin_init::init_array_from_fn(|_| 0x42)), GFP_KERNEL)?;
Since this is a sample, do we want to specify the size explicitly as it
is arguably more readable in this case?
Regardless,
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] samples: rust: debugfs: fix excessive stack use
2026-07-16 20:33 ` Alexandre Courbot
@ 2026-07-16 21:09 ` Gary Guo
0 siblings, 0 replies; 3+ messages in thread
From: Gary Guo @ 2026-07-16 21:09 UTC (permalink / raw)
To: Alexandre Courbot, Gary Guo
Cc: Gary Guo, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Onur Özkan, Matthew Maurer, driver-core,
rust-for-linux, linux-kernel
On Thu Jul 16, 2026 at 9:33 PM BST, Alexandre Courbot wrote:
> On Thu Jul 16, 2026 at 7:41 AM PDT, Gary Guo wrote:
>> From: Gary Guo <gary@garyguo.net>
>>
>> The current implementation creates a 4K array and move it into the box.
>> Klint reports that this causes excesssive stack usage:
>>
>> warning: stack size of `create_file_write` is 4472 bytes, exceeds the 2048-byte limit
>> --> samples/rust/rust_debugfs_scoped.rs:54:1
>> |
>> 54 | / fn create_file_write(
>> 55 | | mod_data: &ModuleData,
>> 56 | | reader: &mut kernel::uaccess::UserSliceReader,
>> 57 | | ) -> Result {
>> | |___________^
>> |
>> = note: the stack size is inferred from instruction `sub $0x1178,%rsp` at .text+2205
>>
>> Use pin-init to create the array in-place instead.
>>
>> Fixes: f656279afde1 ("samples: rust: debugfs_scoped: add example for blobs")
>> Signed-off-by: Gary Guo <gary@garyguo.net>
>> ---
>> samples/rust/rust_debugfs_scoped.rs | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/samples/rust/rust_debugfs_scoped.rs b/samples/rust/rust_debugfs_scoped.rs
>> index 6a575a15a2c2..33a4a0865f5b 100644
>> --- a/samples/rust/rust_debugfs_scoped.rs
>> +++ b/samples/rust/rust_debugfs_scoped.rs
>> @@ -75,7 +75,7 @@ fn create_file_write(
>> GFP_KERNEL,
>> )?;
>> }
>> - let blob = KBox::pin_init(new_mutex!([0x42; SZ_4K]), GFP_KERNEL)?;
>> + let blob = KBox::pin_init(new_mutex!(pin_init::init_array_from_fn(|_| 0x42)), GFP_KERNEL)?;
>
> Since this is a sample, do we want to specify the size explicitly as it
> is arguably more readable in this case?
It's not easy to specify size with `init_array_from_fn` because you need to
specify additionally Init, T and E, so it'll become
init_array_from_fn::<_, SZ_4K, _, _>
which is ugly.
Best,
Gary
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-16 21:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 14:41 [PATCH] samples: rust: debugfs: fix excessive stack use Gary Guo
2026-07-16 20:33 ` Alexandre Courbot
2026-07-16 21:09 ` Gary Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox