[lkml]   [2021]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectRe: [PATCH 05/17] rust: add C helpers
On Sun, Jul 04, 2021 at 10:27PM +0200, wrote:
> From: Miguel Ojeda <>
> This source file contains forwarders to C macros and inlined
> functions.

What is the story with Rust and LTO? Intuitively, I would expect Rust
code to only perform optimally if the kernel is built with LTO
(currently only supported via Clang).

Because if calls to every one of these helpers are real calls, I would
expect performance to be pretty poor. There's probably a reason these
are macros or inlinable functions.

I would almost go so far and suggest that CONFIG_RUST be modified as

--- a/init/Kconfig
+++ b/init/Kconfig
@@ -2028,6 +2028,7 @@ config RUST
depends on HAS_RUST
depends on !COMPILE_TEST
depends on !MODVERSIONS
+ depends on LTO || EXPERT
default n
Enables Rust support in the kernel.
[ I'm sure there are configs that don't yet work with LTO, but could be
useful to enable for debugging or testing purposes, and therefore would
make it conditional on CONFIG_EXPERT as well. ]

> +unsigned long rust_helper_copy_from_user(void *to, const void __user *from, unsigned long n)
> +{
> + return copy_from_user(to, from, n);
> +}
> +

From some local tests, it looks like simply attaching
__attribute__((always_inline)) will do what one would expect when
compiling with Clang LTO (I checked -flto=thin).

If you confirm this also works across C and Rust TUs when enabling LTO,
I would then suggested adding __attribute__((always_inline)) to all
these helpers.

-- Marco

 \ /
  Last update: 2021-07-07 12:20    [W:0.341 / U:0.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site