[PATCH v2] rust: uaccess: mark UserSliceReader methods inline

Antonio Hickey posted 1 patch 9 months, 1 week ago
There is a newer version of this series
rust/kernel/uaccess.rs | 2 ++
1 file changed, 2 insertions(+)
[PATCH v2] rust: uaccess: mark UserSliceReader methods inline
Posted by Antonio Hickey 9 months, 1 week ago
When you build the kernel using the llvm-19.1.4-rust-1.83.0-x86_64
toolchain provided by kernel.org with ARCH=x86_64, the following symbols
are generated:

$nm vmlinux | grep ' _R'.*UserSliceReader | rustfilt
ffffffff817c3320 T <kernel::uaccess::UserSliceReader>::read_slice
ffffffff817c32b0 T <kernel::uaccess::UserSliceReader>::read_raw

However, these Rust symbols are trivial wrappers around the functions
copy_from_user, _copy_from_user respectively. It doesn't
make sense to go through a trivial wrapper for these functions, so mark
them inline.

After applying this patch, the above command will produce no output.

Link: https://github.com/Rust-for-Linux/linux/issues/1145
Suggested-by: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: Antonio Hickey <contact@antoniohickey.com>
---
 rust/kernel/uaccess.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index 719b0a48ff55..3d8a08aeed89 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -218,6 +218,7 @@ pub fn is_empty(&self) -> bool {
     /// # Guarantees
     ///
     /// After a successful call to this method, all bytes in `out` are initialized.
+    #[inline]
     pub fn read_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> Result {
         let len = out.len();
         let out_ptr = out.as_mut_ptr().cast::<c_void>();
@@ -239,6 +240,7 @@ pub fn read_raw(&mut self, out: &mut [MaybeUninit<u8>]) -> Result {
     ///
     /// Fails with [`EFAULT`] if the read happens on a bad address, or if the read goes out of
     /// bounds of this [`UserSliceReader`]. This call may modify `out` even if it returns an error.
+    #[inline]
     pub fn read_slice(&mut self, out: &mut [u8]) -> Result {
         // SAFETY: The types are compatible and `read_raw` doesn't write uninitialized bytes to
         // `out`.
-- 
2.48.1
Re: [PATCH v2] rust: uaccess: mark UserSliceReader methods inline
Posted by Miguel Ojeda 9 months, 1 week ago
On Wed, Mar 12, 2025 at 12:44 AM Antonio Hickey
<contact@antoniohickey.com> wrote:
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1145
> Suggested-by: https://github.com/Rust-for-Linux/linux/issues/1145

The Suggested-by tag is meant to explain who suggested it, rather than
duplicate the link -- please see:

    https://docs.kernel.org/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes

(I typically also put the Link after the tag, if the link is meant to
show the original suggestion, just like the documentation requests for
the Reported-by/Closes pair)

In any case, there is no need to re-send a v3 just for this, you can
wait to see if there is any feedback.

Thanks for the patch!

Cheers,
Miguel
Re: [PATCH v2] rust: uaccess: mark UserSliceReader methods inline
Posted by Antonio Hickey 9 months, 1 week ago
On Wed, Mar 12, 2025 at 02:56:26AM +0100, Miguel Ojeda wrote:
> The Suggested-by tag is meant to explain who suggested it, rather than
> duplicate the link -- please see:
> 
>     https://docs.kernel.org/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes
> 
> (I typically also put the Link after the tag, if the link is meant to
> show the original suggestion, just like the documentation requests for
> the Reported-by/Closes pair)
> 
> In any case, there is no need to re-send a v3 just for this, you can
> wait to see if there is any feedback.

Ahh ok yea the Suggested-by tag makes a lot more sense now haha had a feeling duplicating
the link wasn't right, but was more hesitant to mark someone in specific as suggested by.

Will make note of this for my future patches.

Thanks,
Antonio