- Jul 23, 2023
-
-
Fabien Parent authored
Signed-off-by:
Fabien Parent <fabien.parent@linaro.org>
-
Fabien Parent authored
Add some basic debugfs sample module to show how to use the debugfs API. The sample module is showing: * How to create a directory * How to define and register a debugfs file by implementing file::Operations * How to use the attribute macro to expose simple numerical debugfs values. This is the equivalent of the C macro DEFINE_DEBUGFS_ATTRIBUTE{,_SIGNED} Signed-off-by:
Fabien Parent <fabien.parent@linaro.org>
-
Fabien Parent authored
Signed-off-by:
Fabien Parent <fabien.parent@linaro.org>
-
Fabien Parent authored
Port file::Operations and its dependencies from the `rust` branch. This is a trimmed version from what can be found in `rust` since I only need a subset of the functionality. Signed-off-by:
Fabien Parent <fabien.parent@linaro.org>
-
- Jul 18, 2023
-
-
Miguel Ojeda authored
`rustc` outputs by default the temporary files (i.e. the ones saved by `-Csave-temps`, such as `*.rcgu*` files) in the current working directory when `-o` and `--out-dir` are not given (even if `--emit=x=path` is given, i.e. it does not use those for temporaries). Since out-of-tree modules are compiled from the `linux` tree, `rustc` then tries to create them there, which may not be accessible. Thus pass `--out-dir` explicitly, even if it is just for the temporary files. Reported-by:
Raphael Nestler <raphael.nestler@gmail.com> Closes: https://github.com/Rust-for-Linux/linux/issues/1015 Reported-by:
Andrea Righi <andrea.righi@canonical.com> Tested-by:
Raphael Nestler <raphael.nestler@gmail.com> Tested-by:
Andrea Righi <andrea.righi@canonical.com> Cc: stable@vger.kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20230718055235.1050223-1-ojeda@kernel.org
-
Miguel Ojeda authored
Alice has been involved with the Rust for Linux project for almost a year now. She has been primarily working on the Android Binder Driver [1]. In addition, she has been reviewing patches in the mailing list for some months and has submitted improvements to the core Rust support. She is also part of the core maintainer team for the widely used library Tokio [2], an asynchronous Rust runtime. Her expertise with the language will be very useful to have around in the future if Rust grows within the kernel, thus add her to the `RUST` entry as reviewer. Link: https://rust-for-linux.com/android-binder-driver [1] Link: https://tokio.rs [2] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Acked-by:
Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20230718054521.1048785-1-ojeda@kernel.org
-
Miguel Ojeda authored
Andreas has been involved with the Rust for Linux project for more than a year now. He has been primarily working on the Rust NVMe driver [1], presenting it in several places (such as LPC [2][3] and Kangrejos [4]). In addition, he recently submitted the Rust null block driver [5] and has been reviewing patches in the mailing list for some months. Thus add him to the `RUST` entry as reviewer. Link: https://rust-for-linux.com/nvme-driver [1] Link: https://lpc.events/event/16/contributions/1180/attachments/1017/1961/deck.pdf [2] Link: https://www.youtube.com/watch?v=BwywU1MqW38 [3] Link: https://kangrejos.com/A%20Linux%20(PCI)%20NVMe%20Driver%20in%20Rust.pdf [4] Link: https://lore.kernel.org/rust-for-linux/20230503090708.2524310-1-nmi@metaspace.dk/ [5] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Acked-by:
Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20230718054426.1048583-1-ojeda@kernel.org
-
Andrea Righi authored
With commit 2d47c695 ("ubsan: Tighten UBSAN_BOUNDS on GCC") if CONFIG_UBSAN is enabled and gcc supports -fsanitize=bounds-strict, we can trigger the following build error due to bindgen lacking support for this additional build option: BINDGEN rust/bindings/bindings_generated.rs error: unsupported argument 'bounds-strict' to option '-fsanitize=' Fix by adding -fsanitize=bounds-strict to the list of skipped gcc flags for bindgen. Fixes: 2d47c695 ("ubsan: Tighten UBSAN_BOUNDS on GCC") Signed-off-by:
Andrea Righi <andrea.righi@canonical.com> Acked-by:
Kees Cook <keescook@chromium.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230711071914.133946-1-andrea.righi@canonical.com
-
Andrea Righi authored
With commit c1177979 ("btf, scripts: Exclude Rust CUs with pahole") we are now able to use pahole directly to identify Rust compilation units (CUs) and exclude them from generating BTF debugging information (when DEBUG_INFO_BTF is enabled). And if pahole doesn't support the --lang-exclude flag, we can't enable both RUST and DEBUG_INFO_BTF at the same time. So, in any case, the script is_rust_module.sh is just redundant and we can drop it. NOTE: we may also be able to drop the "Rust loadable module" mark inside Rust modules, but it seems safer to keep it for now to make sure we are not breaking any external tool that may potentially rely on it. Signed-off-by:
Andrea Righi <andrea.righi@canonical.com> Acked-by:
Daniel Xu <dxu@dxuuu.xyz> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230704052136.155445-1-andrea.righi@canonical.com
-
Alice Ryhl authored
Previously, the `ForeignOwnable` trait had a method called `borrow_mut` that was intended to provide mutable access to the inner value. However, the method accidentally made it possible to change the address of the object being modified, which usually isn't what we want. (And when we want that, it can be done by calling `from_foreign` and `into_foreign`, like how the old `borrow_mut` was implemented.) In this patch, we introduce an alternate definition of `borrow_mut` that solves the previous problem. Conceptually, given a pointer type `P` that implements `ForeignOwnable`, the `borrow_mut` method gives you the same kind of access as an `&mut P` would, except that it does not let you change the pointer `P` itself. This is analogous to how the existing `borrow` method provides the same kind of access to the inner value as an `&P`. Note that for types like `Arc`, having an `&mut Arc<T>` only gives you immutable access to the inner `T`. This is because mutable references assume exclusive access, but there might be other handles to the same reference counted value, so the access isn't exclusive. The `Arc` type implements this by making `borrow_mut` return the same type as `borrow`. Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230710074642.683831-1-aliceryhl@google.com
-
Alice Ryhl authored
We discovered that the current design of `borrow_mut` is problematic. This patch removes it until a better solution can be found. Specifically, the current design gives you access to a `&mut T`, which lets you change where the `ForeignOwnable` points (e.g., with `core::mem::swap`). No upcoming user of this API intended to make that possible, making all of them unsound. Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230706094615.3080784-1-aliceryhl@google.com
-
Jamie Cunliffe authored
Signed-off-by:
Jamie Cunliffe <Jamie.Cunliffe@arm.com> Link: https://lore.kernel.org/r/20230606145606.1153715-4-Jamie.Cunliffe@arm.com
-
Jamie Cunliffe authored
Enable the PAC ret and BTI options in the Rust build flags to match the options that are used when building C. Signed-off-by:
Jamie Cunliffe <Jamie.Cunliffe@arm.com> Link: https://lore.kernel.org/r/20230606145606.1153715-3-Jamie.Cunliffe@arm.com
-
Jamie Cunliffe authored
This commit provides the build flags for Rust for AArch64. The core Rust support already in the kernel does the rest. When disabling the neon and fp target features to avoid fp & simd registers. The use of fp-armv8 will cause a warning from rustc about an unknown feature that is specified. The target feature is still passed through to LLVM, this behaviour is documented as part of the warning. This will be fixed in a future version of the rustc toolchain. The Rust samples have been tested with this commit. Signed-off-by:
Jamie Cunliffe <Jamie.Cunliffe@arm.com> Link: https://lore.kernel.org/r/20230606145606.1153715-2-Jamie.Cunliffe@arm.com [boqun: resolve the conflicts with kunit test enablement]
-
Gary Guo authored
This macro provides a flexible way to concatenated identifiers together and it allows the resulting identifier to be used to declare new items, which `concat_idents!` does not allow. It also allows identifiers to be transformed before concatenated. The `concat_idents!` example let x_1 = 42; let x_2 = concat_idents!(x, _1); assert!(x_1 == x_2); can be written with `paste!` macro like this: let x_1 = 42; let x_2 = paste!([<x _1>]); assert!(x_1 == x_2); However `paste!` macro is more flexible because it can be used to create a new variable: let x_1 = 42; paste!(let [<x _2>] = [<x _1>];); assert!(x_1 == x_2); While this is not possible with `concat_idents!`. This macro is similar to the `paste!` crate [1], but this is a fresh implementation to avoid vendoring large amount of code directly. Also, I have augmented it to provide a way to specify span of the resulting token, allowing precise control. For example, this code is broken because the variable is declared inside the macro, so Rust macro hygiene rules prevents access from the outside: macro_rules! m { ($id: ident) => { // The resulting token has hygiene of the macro. paste!(let [<$id>] = 1;) } } m!(a); let _ = a; In this versionn of `paste!` macro I added a `span` modifier to allow this: macro_rules! m { ($id: ident) => { // The resulting token has hygiene of `$id`. paste!(let [<$id:span>] = 1;) } } m!(a); let _ = a; Link: http://docs.rs/paste/ [1] Signed-off-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230628171108.1150742-1-gary@garyguo.net
-
Qingsong Chen authored
If the trait has same function name, the `vtable` macro will redefine its `gen_const_name`, e.g.: ```rust #[vtable] pub trait Foo { #[cfg(CONFIG_X)] fn bar(); #[cfg(not(CONFIG_X))] fn bar(x: usize); } ``` Use `HashSet` to avoid this. Signed-off-by:
Qingsong Chen <changxian.cqs@antgroup.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230626074242.3945398-2-changxian.cqs@antgroup.com
-
Miguel Ojeda authored
The KUnit maintainers would like to maintain these files on their side too (thanks!), so add them to their entry. With this in place, `scripts/get_maintainer.pl` prints both sets of maintainers/reviewers (i.e. KUnit and Rust) for those files, which is the behavior we are looking for. Reviewed-by:
David Gow <davidgow@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20230718052752.1045248-8-ojeda@kernel.org
-
Miguel Ojeda authored
Rust has documentation tests: these are typically examples of usage of any item (e.g. function, struct, module...). They are very convenient because they are just written alongside the documentation. For instance: /// Sums two numbers. /// /// ``` /// assert_eq!(mymod::f(10, 20), 30); /// ``` pub fn f(a: i32, b: i32) -> i32 { a + b } In userspace, the tests are collected and run via `rustdoc`. Using the tool as-is would be useful already, since it allows to compile-test most tests (thus enforcing they are kept in sync with the code they document) and run those that do not depend on in-kernel APIs. However, by transforming the tests into a KUnit test suite, they can also be run inside the kernel. Moreover, the tests get to be compiled as other Rust kernel objects instead of targeting userspace. On top of that, the integration with KUnit means the Rust support gets to reuse the existing testing facilities. For instance, the kernel log would look like: KTAP version 1 1..1 KTAP version 1 # Subtest: rust_doctests_kernel 1..59 # rust_doctest_kernel_build_assert_rs_0.location: rust/kernel/build_assert.rs:13 ok 1 rust_doctest_kernel_build_assert_rs_0 # rust_doctest_kernel_build_assert_rs_1.location: rust/kernel/build_assert.rs:56 ok 2 rust_doctest_kernel_build_assert_rs_1 # rust_doctest_kernel_init_rs_0.location: rust/kernel/init.rs:122 ok 3 rust_doctest_kernel_init_rs_0 ... # rust_doctest_kernel_types_rs_2.location: rust/kernel/types.rs:150 ok 59 rust_doctest_kernel_types_rs_2 # rust_doctests_kernel: pass:59 fail:0 skip:0 total:59 # Totals: pass:59 fail:0 skip:0 total:59 ok 1 rust_doctests_kernel Therefore, add support for running Rust documentation tests in KUnit. Some other notes about the current implementation and support follow. The transformation is performed by a couple scripts written as Rust hostprogs. Tests using the `?` operator are also supported as usual, e.g.: /// ``` /// # use kernel::{spawn_work_item, workqueue}; /// spawn_work_item!(workqueue::system(), || pr_info!("x"))?; /// # Ok::<(), Error>(()) /// ``` The tests are also compiled with Clippy under `CLIPPY=1`, just like normal code, thus also benefitting from extra linting. The names of the tests are currently automatically generated. This allows to reduce the burden for documentation writers, while keeping them fairly stable for bisection. This is an improvement over the `rustdoc`-generated names, which include the line number; but ideally we would like to get `rustdoc` to provide the Rust item path and a number (for multiple examples in a single documented Rust item). In order for developers to easily see from which original line a failed doctests came from, a KTAP diagnostic line is printed to the log, containing the location (file and line) of the original test (i.e. instead of the location in the generated Rust file): # rust_doctest_kernel_types_rs_2.location: rust/kernel/types.rs:150 This line follows the syntax for declaring test metadata in the proposed KTAP v2 spec [1], which may be used for the proposed KUnit test attributes API [2]. Thus hopefully this will make migration easier later on (suggested by David [3]). The original line in that test attribute is figured out by providing an anchor (suggested by Boqun [4]). The original file is found by walking the filesystem, checking directory prefixes to reduce the amount of combinations to check, and it is only done once per file. Ambiguities are detected and reported. A notable difference from KUnit C tests is that the Rust tests appear to assert using the usual `assert!` and `assert_eq!` macros from the Rust standard library (`core`). We provide a custom version that forwards the call to KUnit instead. Importantly, these macros do not require passing context, unlike the KUnit C ones (i.e. `struct kunit *`). This makes them easier to use, and readers of the documentation do not need to care about which testing framework is used. In addition, it may allow us to test third-party code more easily in the future. However, a current limitation is that KUnit does not support assertions in other tasks. Thus we presently simply print an error to the kernel log if an assertion actually failed. This should be revisited to properly fail the test, perhaps saving the context somewhere else, or letting KUnit handle it. Link: https://lore.kernel.org/lkml/20230420205734.1288498-1-rmoar@google.com/ [1] Link: https://lore.kernel.org/linux-kselftest/20230707210947.1208717-1-rmoar@google.com/ [2] Link: https://lore.kernel.org/rust-for-linux/CABVgOSkOLO-8v6kdAGpmYnZUb+LKOX0CtYCo-Bge7r_2YTuXDQ@mail.gmail.com/ [3] Link: https://lore.kernel.org/rust-for-linux/ZIps86MbJF%2FiGIzd@boqun-archlinux/ [4] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
David Gow <davidgow@google.com> Link: https://lore.kernel.org/r/20230718052752.1045248-7-ojeda@kernel.org
-
Miguel Ojeda authored
Rust documentation tests are going to be build/run-tested with the KUnit integration added in a future patch, thus update them to make them compilable/testable so that we may start enforcing it. Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
David Gow <davidgow@google.com> Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20230718052752.1045248-6-ojeda@kernel.org
-
Miguel Ojeda authored
Rust documentation tests are going to be build/run-tested with the KUnit integration added in a future patch, thus update them to make them compilable/testable so that we may start enforcing it. Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
David Gow <davidgow@google.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20230718052752.1045248-5-ojeda@kernel.org
-
Miguel Ojeda authored
Rust documentation tests are going to be build/run-tested with the KUnit integration added in a future patch, thus update them to make them compilable/testable so that we may start enforcing it. Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by:
David Gow <davidgow@google.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20230718052752.1045248-4-ojeda@kernel.org
-
Miguel Ojeda authored
Rust documentation tests are going to be build/run-tested with the KUnit integration added in a future patch, thus update them to make them compilable/testable so that we may start enforcing it. Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by:
David Gow <davidgow@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20230718052752.1045248-3-ojeda@kernel.org
-
Miguel Ojeda authored
The header uses `NULL` in both `CONFIG_KUNIT=y` and `=n` cases, but does not include it explicitly. When `CONFIG_KUNIT=y`, the header is already getting included via the other headers, so it is not a problem for users. However, when `CONFIG_KUNIT=n`, it is not, and thus a user could hit a build error when including `kunit/test-bug.h`, like we are doing later in this series [1]. Thus include `linux/stddef.h`, and do so outside the `#if`, since it is used in both cases. Reported-by:
Boqun Feng <boqun.feng@gmail.com> Closes: https://lore.kernel.org/rust-for-linux/ZJ8cNUW3oR2p+gL1@boqun-archlinux/ [1] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
David Gow <davidgow@google.com> Link: https://lore.kernel.org/r/20230718052752.1045248-2-ojeda@kernel.org
-
- Jul 10, 2023
-
-
Aakash Sen Sharma authored
* Rationale: Upgrades bindgen to code-generation for anonymous unions, structs, and enums [7] for LLVM-16 based toolchains. The following upgrade also incorporates `noreturn` support from bindgen allowing us to remove useless `loop` calls which was placed as a workaround. * Truncated build logs on using bindgen `v0.56.0` prior to LLVM-16 toolchain: ``` $ make rustdoc LLVM=1 CLIPPY=1 -j$(nproc) RUSTC L rust/core.o BINDGEN rust/bindings/bindings_generated.rs BINDGEN rust/bindings/bindings_helpers_generated.rs BINDGEN rust/uapi/uapi_generated.rs thread 'main' panicked at '"ftrace_branch_data_union_(anonymous_at__/_/include/linux/compiler_types_h_146_2)" is not a valid Ident', .../proc-macro2-1.0.24/src/fallback.rs:693:9 ... thread 'main' panicked at '"ftrace_branch_data_union_(anonymous_at__/_/include/linux/compiler_types_h_146_2)" is not a valid Ident', .../proc-macro2-1.0.24/src/fallback.rs:693:9 ... ``` * LLVM-16 Changes: API changes [1] were introduced such that libclang would emit names like "(unnamed union at compiler_types.h:146:2)" for unnamed unions, structs, and enums whereas it previously returned an empty string. * Bindgen Changes: Bindgen `v0.56.0` on LLVM-16 based toolchains hence was unable to process the anonymous union in `include/linux/compiler_types` `struct ftrace_branch_data` and caused subsequent panics as the new `libclang` API emitted name was not being handled. The following issue was fixed in Bindgen `v0.62.0` [2]. Bindgen `v0.58.0` changed the flags `--whitelist-*` and `--blacklist-*` to `--allowlist-*` and `--blocklist-*` respectively [3]. Bindgen `v0.61.0` added support for `_Noreturn`, `[[noreturn]]`, `__attribute__((noreturn))` [4], hence the empty `loop`s used to circumvent bindgen returning `!` in place of `()` for noreturn attributes have been removed completely. Bindgen `v0.61.0` also changed default functionality to bind `size_t` to `usize` [5] and added the `--no-size_t-is-usize` [5] flag to not bind `size_t` as `usize`. Bindgen `v0.65.0` removed `--size_t-is-usize` flag [6]. Link: https://github.com/llvm/llvm-project/commit/19e984ef8f49bc3ccced15621989fa9703b2cd5b [1] Link: https://github.com/rust-lang/rust-bindgen/pull/2319 [2] Link: https://github.com/rust-lang/rust-bindgen/pull/1990 [3] Link: https://github.com/rust-lang/rust-bindgen/issues/2094 [4] Link: https://github.com/rust-lang/rust-bindgen/commit/cc78b6fdb6e829e5fb8fa1639f2182cb49333569 [5] Link: https://github.com/rust-lang/rust-bindgen/pull/2408 [6] Closes: https://github.com/Rust-for-Linux/linux/issues/1013 [7] Signed-off-by:
Aakash Sen Sharma <aakashsensharma@gmail.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Tested-by:
Ariel Miculas <amiculas@cisco.com> Link: https://lore.kernel.org/r/20230612194311.24826-1-aakashsensharma@gmail.com [boqun: resolve conflicts because of Rust version bump] Signed-off-by:
Boqun Feng <boqun.feng@gmail.com>
-
Boqun Feng authored
While there are default impls for these methods, using the respective C api's is faster. Currently neither the existing nor these new GlobalAlloc method implementations are actually called. Instead the __rust_* function defined below the GlobalAlloc impl are used. With rustc 1.71 these functions will be gone and all allocation calls will go through the GlobalAlloc implementation. Link: https://github.com/Rust-for-Linux/linux/issues/68 Signed-off-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> [boqun: add size adjustment for alignment requirement] Signed-off-by:
Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20230625232528.89306-1-boqun.feng@gmail.com
-
Miguel Ojeda authored
The `rust_is_available.sh` script runs for everybody compiling the kernel, even if not using Rust. Therefore, it is important to ensure that the script is correct to avoid breaking people's compilation. In addition, the script needs to be able to handle a set of subtle cases, including parsing version strings of different tools. Therefore, maintenance of this script can be greatly eased with a set of tests. Thus add a test suite to cover hopefully most of the setups that the script may encounter in the wild. Extra setups can be easily added later on if missing. The script currently covers all the branches of the shell script, including several ways in which they may be entered. Python is used for this script, since the script under test does not depend on Rust, thus hopefully making it easier for others to use if the need arises. Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-12-ojeda@kernel.org
-
Miguel Ojeda authored
The script already checks for `$RUSTC` and `$BINDGEN` existing and exiting without failure. However, one may still pass an unexpected binary that does not output what the later parsing expects. The script still successfully reports a failure as expected, but the error is confusing. For instance: $ RUSTC=true BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " *** *** Please see Documentation/rust/quick-start.rst for details *** on how to set up the Rust support. *** Thus add an explicit check and a proper message for unexpected output from the called command. Similarly, do so for the `libclang` version parsing, too. Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQYk6s11MASRHW6oxtkqF00EJVqhHOP=5rynWt-QDUsXw@mail.gmail.com/ Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-11-ojeda@kernel.org
-
Miguel Ojeda authored
The script already checks if `$RUSTC` and `$BINDGEN` exists via `command`, but the environment variables may point to a non-executable file, or the programs may fail for some other reason. While the script successfully exits with a failure as it should, the error given can be quite confusing depending on the shell and the behavior of its `command`. For instance, with `dash`: $ RUSTC=./mm BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " Thus detect failure exit codes when calling `$RUSTC` and `$BINDGEN` and print a better message, in a similar way to what we do when extracting the `libclang` version found by `bindgen`. Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQYk6s11MASRHW6oxtkqF00EJVqhHOP=5rynWt-QDUsXw@mail.gmail.com/ Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-10-ojeda@kernel.org
-
Miguel Ojeda authored
In order to match the version string, `sed` is used in a couple cases, and `grep` and `head` in a couple others. Make the script more consistent and easier to understand by using the same method, `sed`, for all of them. This makes the version matching also a bit more strict for the changed cases, since the strings `rustc ` and `bindgen ` will now be required, which should be fine since `rustc` complains if one attempts to call it with another program name, and `bindgen` uses a hardcoded string. In addition, clarify why one of the existing `sed` commands does not provide an address like the others. Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Masahiro Yamada <masahiroy@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-9-ojeda@kernel.org
-
Miguel Ojeda authored
`bindgen`'s output for `libclang`'s version check contains paths, which in turn may contain strings that look like version numbers [1][2]: .../6.1.0-dev/.../rust_is_available_bindgen_libclang.h:2:9: warning: clang version 11.1.0 [-W#pragma-messages], err: false which the script will pick up as the version instead of the latter. It is also the case that versions may appear after the actual version (e.g. distribution's version text), which was the reason behind `head` [3]: .../rust-is-available-bindgen-libclang.h:2:9: warning: clang version 13.0.0 (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false Thus instead ask for a match after the `clang version` string. Reported-by:
Jordan Isaacs <mail@jdisaacs.com> Closes: https://github.com/Rust-for-Linux/linux/issues/942 [1] Reported-by:
Ethan D. Twardy <ethan.twardy@gmail.com> Closes: https://lore.kernel.org/rust-for-linux/20230528131802.6390-2-ethan.twardy@gmail.com/ [2] Reported-by:
Tiago Lam <tiagolam@gmail.com> Closes: https://github.com/Rust-for-Linux/linux/pull/789 [3] Fixes: 78521f33 ("scripts: add `rust_is_available.sh`") Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-By:
Ethan Twardy <ethan.twardy@gmail.com> Tested-By:
Ethan Twardy <ethan.twardy@gmail.com> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-8-ojeda@kernel.org
-
Miguel Ojeda authored
Sometimes [1] users may attempt to setup the Rust support by checking what Kbuild does and they end up finding out about `scripts/rust_is_available.sh`. Inevitably, they run the script directly, but unless they setup the required variables, the result of the script is not meaningful. We could add some defaults to the variables, but that could be confusing for those that may override the defaults (compared to their kernel builds), and `$CC` would not be a simple default in any case. Therefore, instead, explicitly check whether the expected variables are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation about the fact that the script is meant to be called from Kbuild, since that is the most likely cause for the variables not being set. Link: https://lore.kernel.org/oe-kbuild-all/Y6r4mXz5NS0+HVXo@zn.tnic/ [1] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-7-ojeda@kernel.org
-
Miguel Ojeda authored
`scripts/rust_is_available.sh` calls `bindgen` with a special header in order to check whether the `libclang` version in use is suitable. However, the invocation itself may fail if, for instance, `bindgen` cannot locate `libclang`. This is fine for Kconfig (since the script will still fail and therefore disable Rust as it should), but it is pretty confusing for users of the `rustavailable` target given the error will be unrelated: ./scripts/rust_is_available.sh: 21: arithmetic expression: expecting primary: "100000 * + 100 * + " make: *** [Makefile:1816: rustavailable] Error 2 Instead, run the `bindgen` invocation independently in a previous step, saving its output and return code. If it fails, then show the user a proper error message. Otherwise, continue as usual with the saved output. Since the previous patch we show a reference to the docs, and the docs now explain how `bindgen` looks for `libclang`, thus the error message can leverage the documentation, avoiding duplication here (and making users aware of the setup guide in the documentation). Reported-by:
Nick Desaulniers <ndesaulniers@google.com> Link: https://lore.kernel.org/rust-for-linux/CAKwvOdm5JT4wbdQQYuW+RT07rCi6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ Reported-by:
François Valenduc <francoisvalenduc@gmail.com> Closes: https://github.com/Rust-for-Linux/linux/issues/934 Reported-by:
Alexandru Radovici <msg4alex@gmail.com> Closes: https://github.com/Rust-for-Linux/linux/pull/921 Reported-by:
Matthew Leach <dev@mattleach.net> Closes: https://lore.kernel.org/rust-for-linux/20230507084116.1099067-1-dev@mattleach.net/ Fixes: 78521f33 ("scripts: add `rust_is_available.sh`") Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Masahiro Yamada <masahiroy@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-6-ojeda@kernel.org
-
Miguel Ojeda authored
People trying out the Rust support in the kernel may get warnings and errors from `scripts/rust_is_available.sh` from the `rustavailable` target or the build step. Some of those users may be following the Quick Start guide, but others may not (likely those getting warnings from the build step instead of the target). While the messages are fairly clear on what the problem is, it may not be clear how to solve the particular issue, especially for those not aware of the documentation. We could add all sorts of details on the script for each one, but it is better to point users to the documentation instead, where it is easily readable in different formats. It also avoids duplication. Thus add a reference to the documentation whenever the script fails or there is at least a warning. Reviewed-by:
Finn Behrens <fin@nyantec.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Masahiro Yamada <masahiroy@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-5-ojeda@kernel.org
-
Miguel Ojeda authored
Sometimes users need to tweak the finding process of `libclang` for `bindgen` via the `clang-sys`-provided environment variables. Thus add a paragraph to the setting up guide, including a reference to `clang-sys`'s relevant documentation. Link: https://lore.kernel.org/rust-for-linux/CAKwvOdm5JT4wbdQQYuW+RT07rCi6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ Reviewed-by:
Nick Desaulniers <ndesaulniers@google.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-4-ojeda@kernel.org
-
Russell Currey authored
rust_is_available.sh uses cc-version.sh to identify which C compiler is in use, as scripts/Kconfig.include does. cc-version.sh isn't designed to be able to handle multiple arguments in one variable, i.e. "ccache clang". Its invocation in rust_is_available.sh quotes "$CC", which makes $1 == "ccache clang" instead of the intended $1 == ccache & $2 == clang. cc-version.sh could also be changed to handle having "ccache clang" as one argument, but it only has the one consumer upstream, making it simpler to fix the caller here. Signed-off-by:
Russell Currey <ruscur@russell.cc> Fixes: 78521f33 ("scripts: add `rust_is_available.sh`") Link: https://github.com/Rust-for-Linux/linux/pull/873 [ Reworded title prefix and reflow line to 75 columns. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-3-ojeda@kernel.org
-
Masahiro Yamada authored
The -v option is passed when this script is invoked from Makefile, but not when invoked from Kconfig. As you can see in scripts/Kconfig.include, the 'success' macro suppresses stdout and stderr anyway, so this script does not need to be quiet. Signed-off-by:
Masahiro Yamada <masahiroy@kernel.org> Reviewed-by:
Miguel Ojeda <ojeda@kernel.org> Tested-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20230109061436.3146442-1-masahiroy@kernel.org [ Reworded prefix to match the others in the patch series. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-2-ojeda@kernel.org
-
Benno Lossin authored
Adds a `PhantomPinned` field to `Opaque<T>`. This removes the last Rust guarantee: the assumption that the type `T` can be freely moved. This is not the case for many types from the C side (e.g. if they contain a `struct list_head`). This change removes the need to add a `PhantomPinned` field manually to Rust structs that contain C structs which must not be moved. Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230630150216.109789-1-benno.lossin@proton.me
-
Alice Ryhl authored
When combining `UnsafeCell` with `MaybeUninit`, it is idiomatic to use `UnsafeCell` as the outer type. Intuitively, this is because a `MaybeUninit<T>` might not contain a `T`, but we always want the effect of the `UnsafeCell`, even if the inner value is uninitialized. Now, strictly speaking, this doesn't really make a difference. The compiler will always apply the `UnsafeCell` effect even if the inner value is uninitialized. But I think we should follow the convention here. Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230614115328.2825961-1-aliceryhl@google.com
-
Boqun Feng authored
Currently the KernelAllocator simply passes the size of the type Layout to krealloc(), and in theory the alignment requirement from the type Layout may be larger than the guarantee provided by SLAB, which means the allocated object is mis-aligned. Fixes this by adjusting the allocation size to the nearest power of two, which SLAB always guarantees a size-aligned allocation. And because Rust guarantees that original size must be a multiple of alignment and the alignment must be a power of two, then the alignment requirement is satisfied. Suggested-by:
Vlastimil Babka <vbabka@suse.cz> Co-developed-by:
Andreas Hindborg (Samsung) <nmi@metaspace.dk> Signed-off-by:
Andreas Hindborg (Samsung) <nmi@metaspace.dk> Signed-off-by:
Boqun Feng <boqun.feng@gmail.com> Cc: stable@vger.kernel.org # v6.1+ Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230613164258.3831917-1-boqun.feng@gmail.com
-
- Jul 09, 2023
-
-
Linus Torvalds authored
-