lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87msg26fxt.fsf@kernel.org>
Date: Tue, 07 Jan 2025 12:31:32 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Gary Guo" <gary@...yguo.net>
Cc: "Miguel Ojeda" <ojeda@...nel.org>,  "Alex Gaynor"
 <alex.gaynor@...il.com>,  "Boqun Feng" <boqun.feng@...il.com>,
  =?utf-8?Q?Bj=C3=B6rn?= Roy
 Baron <bjorn3_gh@...tonmail.com>,  "Benno Lossin"
 <benno.lossin@...ton.me>,  "Alice Ryhl" <aliceryhl@...gle.com>,  "Trevor
 Gross" <tmgross@...ch.edu>,  "Nathan Chancellor" <nathan@...nel.org>,
  "Nick Desaulniers" <ndesaulniers@...gle.com>,  "Bill Wendling"
 <morbo@...gle.com>,  "Justin Stitt" <justinstitt@...gle.com>,  "Masahiro
 Yamada" <masahiroy@...nel.org>,  "Nicolas Schier" <nicolas@...sle.eu>,
  "Andrew Morton" <akpm@...ux-foundation.org>,  "Dirk Behme"
 <dirk.behme@...bosch.com>,  "Tamir Duberstein" <tamird@...il.com>,
  "Christian Brauner" <brauner@...nel.org>,  "Martin Rodriguez Reboredo"
 <yakoyoku@...il.com>,  "Paul Moore" <paul@...l-moore.com>,  "Wedson
 Almeida Filho" <wedsonaf@...il.com>,  "Steven Rostedt (Google)"
 <rostedt@...dmis.org>,  "Matt Gilbride" <mattgilbride@...gle.com>,
  "Danilo Krummrich" <dakr@...nel.org>,  "Eder Zulian"
 <ezulian@...hat.com>,  "Filipe Xavier" <felipe_life@...e.com>,
  <rust-for-linux@...r.kernel.org>,  <llvm@...ts.linux.dev>,  "Kees Cook"
 <kees@...nel.org>,  "Daniel Xu" <dxu@...uu.xyz>,
  <linux-kbuild@...r.kernel.org>,  <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 2/3] kbuild: rust: provide an option to inline C
 helpers into Rust

"Gary Guo" <gary@...yguo.net> writes:

> A new Kconfig option, `RUST_INLINE_HELPERS` is added to allow C helpers
> (which was created to allow Rust to call into inline/macro C functions
> without having to re-implement the logic in Rust) to be inlined into
> Rust crates without performing a global LTO.
>
> If the option is enabled, the following is performed:
> * For helpers, instead of compiling them to object file to be linked
>   into vmlinux, we compile them to LLVM IR.
> * The LLVM IR is patched to add `linkonce_odr` linkage. This linkage
>   means that the function is inlineable (effect of `_odr`), and the
>   symbols generated will have weak linkage if emitted into object file
>   (important since as later described, we might have multiple copies of
>   the same symbol) and it will may be discarded if it is not invoked or
>   all invocations are inlined.
> * The LLVM IR is compiled to bitcode (This is step is not necessary, but
>   is a performance optimisation to prevent LLVM from always have to
>   reparse the same IR).
> * When a Rust crate is compiled, instead of generating object file, we
>   ask LLVM bitcode to be generated.
> * llvm-link is invoked to combine the helper bitcode with the crate
>   bitcode. This step is similar to LTO, but this is much faster since it
>   only needs to inline the helpers.
> * clang is invoked to turn the combined bitcode into object file.
>
> Some caveats with the option:
> * clang and Rust doesn't have the exact target string. Manual inspection
>   shows that they should be compatible, but since they are not exactly
>   the same LLVM seems to prefer not inlining them. This is bypassed with
>   `--ignore-tti-inline-compatible`.
> * LLVM doesn't want to inline functions combined with
>   `-fno-delete-null-pointer-checks` with code compiled without. So we
>   remove this command when compiling helpers. I think this should be
>   okay since this is one of the hardening features and we shouldn't have
>   null pointer dereferences in these helpers.
>
> The checks can also be bypassed with force inlining (`__always_inline`)
> but the behaviour is the same with extra options.
>
> Co-developed-by: Boqun Feng <boqun.feng@...il.com>
> Signed-off-by: Boqun Feng <boqun.feng@...il.com>
> Signed-off-by: Gary Guo <gary@...yguo.net>


Reviewed-by: Andreas Hindborg <a.hindborg@...nel.org>
Tested-by: Andreas Hindborg <a.hindborg@...nel.org>

Tested with downstream rnull tree, works as expected.

Best regards,
Andreas Hindborg



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ