[PATCH v3 0/6] Rust: support `CPU_MITIGATIONS` and enable `objtool`

Miguel Ojeda posted 6 patches 1 month, 2 weeks ago
arch/x86/Makefile               |  7 ++++-
rust/Makefile                   | 22 +++++++++------
rust/macros/module.rs           | 12 +++++++++
scripts/Makefile.build          |  9 +++++--
scripts/generate_rust_target.rs | 15 +++++++++++
tools/objtool/check.c           | 48 ++++++++++++++++++++++++++++++++-
tools/objtool/noreturns.h       |  2 ++
7 files changed, 103 insertions(+), 12 deletions(-)
[PATCH v3 0/6] Rust: support `CPU_MITIGATIONS` and enable `objtool`
Posted by Miguel Ojeda 1 month, 2 weeks ago
Hi,

This is just v2 with the helper function suggested by Peter.

I dropped Benno's and Alice's Tested-bys from the modified patch, just
in case, but the logic should be equivalent.

Cheers,
Miguel

v3:
  - Added `is_rust_noreturn()` helper function (Peter).
  - Reworded a couple bits.

v2: https://lore.kernel.org/rust-for-linux/20240724161501.1319115-1-ojeda@kernel.org/
v1: https://lore.kernel.org/rust-for-linux/20231023174449.251550-1-ojeda@kernel.org/

Miguel Ojeda (6):
  rust: module: add static pointer to `{init,cleanup}_module()`
  x86/rust: support MITIGATION_RETPOLINE
  x86/rust: support MITIGATION_RETHUNK
  x86/rust: support MITIGATION_SLS
  objtool/rust: list `noreturn` Rust functions
  objtool/kbuild/rust: enable objtool for Rust

 arch/x86/Makefile               |  7 ++++-
 rust/Makefile                   | 22 +++++++++------
 rust/macros/module.rs           | 12 +++++++++
 scripts/Makefile.build          |  9 +++++--
 scripts/generate_rust_target.rs | 15 +++++++++++
 tools/objtool/check.c           | 48 ++++++++++++++++++++++++++++++++-
 tools/objtool/noreturns.h       |  2 ++
 7 files changed, 103 insertions(+), 12 deletions(-)


base-commit: b1263411112305acf2af728728591465becb45b0
--
2.45.2
Re: [PATCH v3 0/6] Rust: support `CPU_MITIGATIONS` and enable `objtool`
Posted by Miguel Ojeda 2 weeks, 6 days ago
On Thu, Jul 25, 2024 at 8:35 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> Miguel Ojeda (6):
>   rust: module: add static pointer to `{init,cleanup}_module()`
>   x86/rust: support MITIGATION_RETPOLINE
>   x86/rust: support MITIGATION_RETHUNK
>   x86/rust: support MITIGATION_SLS
>   objtool/rust: list `noreturn` Rust functions
>   objtool/kbuild/rust: enable objtool for Rust
>
>  arch/x86/Makefile               |  7 ++++-
>  rust/Makefile                   | 22 +++++++++------
>  rust/macros/module.rs           | 12 +++++++++
>  scripts/Makefile.build          |  9 +++++--
>  scripts/generate_rust_target.rs | 15 +++++++++++
>  tools/objtool/check.c           | 48 ++++++++++++++++++++++++++++++++-
>  tools/objtool/noreturns.h       |  2 ++
>  7 files changed, 103 insertions(+), 12 deletions(-)

Applied to `rust-next` -- thanks everyone!

In the `noreturn` patch:

    [ Kees agrees this should be automated and Peter says:

        So it would be fairly simple to make objtool consume a magic section
        emitted by the compiler.. I think we've asked the compiler folks
        for that at some point even, but I don't have clear recollections.

      We will ask upstream Rust about it. And if they agree, then perhaps
      we can get Clang/GCC to implement something similar too -- for this
      sort of thing we can take advantage of the shorter cycles of `rustc`
      as well as their unstable features concept to experiment.

      Gary proposed using DWARF (though it would need to be available), and
      wrote a proof of concept script using the `object` and `gimli` crates:
      https://gist.github.com/nbdd0121/449692570622c2f46a29ad9f47c3379a

        - Miguel ]

    [ Added `len_mismatch_fail` symbol for new `kernel` crate code merged
      since then as well as 3 more `core::panicking` symbols that appear
      in `RUST_DEBUG_ASSERTIONS=y` builds.  - Miguel ]

Cheers,
Miguel
Re: [PATCH v3 0/6] Rust: support `CPU_MITIGATIONS` and enable `objtool`
Posted by Benno Lossin 1 month, 2 weeks ago
On 25.07.24 20:33, Miguel Ojeda wrote:
> Hi,
> 
> This is just v2 with the helper function suggested by Peter.
> 
> I dropped Benno's and Alice's Tested-bys from the modified patch, just
> in case, but the logic should be equivalent.

I re-ran my tests and the results are the same as with v1.

Tested-by: Benno Lossin <benno.lossin@proton.me>

---
Cheers,
Benno

> Cheers,
> Miguel
> 
> v3:
>   - Added `is_rust_noreturn()` helper function (Peter).
>   - Reworded a couple bits.
> 
> v2: https://lore.kernel.org/rust-for-linux/20240724161501.1319115-1-ojeda@kernel.org/
> v1: https://lore.kernel.org/rust-for-linux/20231023174449.251550-1-ojeda@kernel.org/
> 
> Miguel Ojeda (6):
>   rust: module: add static pointer to `{init,cleanup}_module()`
>   x86/rust: support MITIGATION_RETPOLINE
>   x86/rust: support MITIGATION_RETHUNK
>   x86/rust: support MITIGATION_SLS
>   objtool/rust: list `noreturn` Rust functions
>   objtool/kbuild/rust: enable objtool for Rust
> 
>  arch/x86/Makefile               |  7 ++++-
>  rust/Makefile                   | 22 +++++++++------
>  rust/macros/module.rs           | 12 +++++++++
>  scripts/Makefile.build          |  9 +++++--
>  scripts/generate_rust_target.rs | 15 +++++++++++
>  tools/objtool/check.c           | 48 ++++++++++++++++++++++++++++++++-
>  tools/objtool/noreturns.h       |  2 ++
>  7 files changed, 103 insertions(+), 12 deletions(-)
> 
> 
> base-commit: b1263411112305acf2af728728591465becb45b0
> --
> 2.45.2