Re: [PATCH v2] uaccess: decouple INLINE_COPY_FROM_USER and CONFIG_RUST

From: Alice Ryhl

Date: Tue Nov 18 2025 - 05:40:14 EST


On Fri, Oct 24, 2025 at 11:47:53AM -0400, Yury Norov (NVIDIA) wrote:
> Commit 1f9a8286bc0c ("uaccess: always export _copy_[from|to]_user with
> CONFIG_RUST") exports _copy_{from,to}_user() unconditionally, if RUST
> is enabled. This pollutes exported symbols namespace, and spreads RUST
> ifdefery in core files.
>
> It's better to declare a corresponding helper under the rust/helpers,
> similarly to how non-underscored copy_{from,to}_user() is handled.
>
> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> Tested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> Signed-off-by: Yury Norov (NVIDIA) <yury.norov@xxxxxxxxx>

It looks like this is not quite correct. The header file still has this
declaration unconditionally:

extern __must_check unsigned long
_copy_from_user(void *, const void __user *, unsigned long);

extern __must_check unsigned long
_copy_to_user(void __user *, const void *, unsigned long);

this causes:

ERROR: modpost: "_copy_from_user" [samples/rust/rust_misc_device.ko] undefined!
ERROR: modpost: "_copy_to_user" [samples/rust/rust_misc_device.ko] undefined!

This is because when Rust sees both a helper and a non-helper of the
same function, it prefers to call the non-helper version. In this case,
it saw a declaration of the function in the header file, and so it tried
to call that instead of the helper.

To fix this, we need to wrap the above declarations in:

#ifndef INLINE_COPY_FROM_USER

Alice