- Dec 21, 2023
-
-
Miguel Ojeda authored
Some of our links use relative paths in order to point to files in the source tree, e.g.: //! C header: [`include/linux/printk.h`](../../../../include/linux/printk.h) /// [`struct mutex`]: ../../../../include/linux/mutex.h These are problematic because they are hard to maintain and do not support `O=` builds. Instead, provide support for `srctree`-relative links, e.g.: //! C header: [`include/linux/printk.h`](srctree/include/linux/printk.h) /// [`struct mutex`]: srctree/include/linux/mutex.h The links are fixed after `rustdoc` generation to be based on the absolute path to the source tree. Essentially, this is the automatic version of Tomonori's fix [1], suggested by Gary [2]. Suggested-by:
Gary Guo <gary@garyguo.net> Reported-by:
FUJITA Tomonori <fujita.tomonori@gmail.com> Closes: https://lore.kernel.org/r/20231026.204058.2167744626131849993.fujita.tomonori@gmail.com [1] Fixes: 48fadf44 ("docs: Move rustdoc output, cross-reference it") Link: https://lore.kernel.org/rust-for-linux/20231026154525.6d14b495@eugeo/ [2] Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20231215235428.243211-1-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Boqun Feng authored
Currently, `CondVar::wait()` is an interruptible wait, and this is different than `wait_event()` in include/linux/wait.h (which is an uninterruptible wait). To avoid confusion between different APIs on the interruptible/uninterruptible, make `CondVar::wait()` an uninterruptible wait same as `wait_event()`, also rename the old `wait()` to `CondVar::wait_interruptible()`. Spotted-by:
Tiago Lam <tiagolam@gmail.com> Signed-off-by:
Boqun Feng <boqun.feng@gmail.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Tiago Lam <tiagolam@gmail.com> Link: https://lore.kernel.org/r/20231214200421.690629-1-boqun.feng@gmail.com Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Miguel Ojeda authored
This is the next upgrade to the Rust toolchain, from 1.73.0 to 1.74.1 (i.e. the latest) [1]. See the upgrade policy [2] and the comments on the first upgrade in commit 3ed03f4d ("rust: upgrade to Rust 1.68.2"). # Unstable features No unstable features (that we use) were stabilized. Therefore, the only unstable features allowed to be used outside the `kernel` crate are still `new_uninit,offset_of`, though other code to be upstreamed may increase the list (e.g. `offset_of` was added recently). Please see [3] for details. # Other improvements Rust 1.74.0 allows to use `#[repr(Rust)]` explicitly [4], which can be useful to be explicit about particular cases that would normally use e.g. the C representation, such as silencing lints like the upcoming additions we requested [5] to the `no_mangle_with_rust_abi` Clippy lint (which in turn triggered the `#[repr(Rust)]` addition). Rust 1.74.0 includes a fix for one of the false negative cases we reported in Clippy's `disallowed_macros` lint [6] that we would like to use in the future. Rust 1.74.1 fixes an ICE that the Apple AGX GPU driver was hitting [7]. # Required changes For this upgrade, no changes were required (i.e. on our side). # `alloc` upgrade and reviewing The vast majority of changes are due to our `alloc` fork being upgraded at once. There are two kinds of changes to be aware of: the ones coming from upstream, which we should follow as closely as possible, and the updates needed in our added fallible APIs to keep them matching the newer infallible APIs coming from upstream. Instead of taking a look at the diff of this patch, an alternative approach is reviewing a diff of the changes between upstream `alloc` and the kernel's. This allows to easily inspect the kernel additions only, especially to check if the fallible methods we already have still match the infallible ones in the new version coming from upstream. Another approach is reviewing the changes introduced in the additions in the kernel fork between the two versions. This is useful to spot potentially unintended changes to our additions. To apply these approaches, one may follow steps similar to the following to generate a pair of patches that show the differences between upstream Rust and the kernel (for the subset of `alloc` we use) before and after applying this patch: # Get the difference with respect to the old version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > old.patch git -C linux restore rust/alloc # Apply this patch. git -C linux am rust-upgrade.patch # Get the difference with respect to the new version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > new.patch git -C linux restore rust/alloc Now one may check the `new.patch` to take a look at the additions (first approach) or at the difference between those two patches (second approach). For the latter, a side-by-side tool is recommended. Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1741-2023-12-07 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: https://github.com/Rust-for-Linux/linux/issues/2 [3] Link: https://github.com/rust-lang/rust/pull/114201 [4] Link: https://github.com/rust-lang/rust-clippy/issues/11219 [5] Link: https://github.com/rust-lang/rust-clippy/issues/11431 [6] Link: https://github.com/rust-lang/rust/issues/117976#issuecomment-1822225691 [7] Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Tested-by:
David Gow <davidgow@google.com> Link: https://lore.kernel.org/r/20231214092958.377061-1-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Dec 15, 2023
-
-
FUJITA Tomonori authored
This is the Rust implementation of drivers/net/phy/ax88796b.c. The features are equivalent. You can choose C or Rust version kernel configuration. Signed-off-by:
FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by:
Trevor Gross <tmgross@umich.edu> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Andrew Lunn <andrew@lunn.ch> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Signed-off-by:
David S. Miller <davem@davemloft.net>
-
FUJITA Tomonori authored
This macro creates an array of kernel's `struct phy_driver` and registers it. This also corresponds to the kernel's `MODULE_DEVICE_TABLE` macro, which embeds the information for module loading into the module binary file. A PHY driver should use this macro. Signed-off-by:
FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Andrew Lunn <andrew@lunn.ch> Reviewed-by:
Trevor Gross <tmgross@umich.edu> Signed-off-by:
David S. Miller <davem@davemloft.net>
-
FUJITA Tomonori authored
This patch adds abstractions to implement network PHY drivers; the driver registration and bindings for some of callback functions in struct phy_driver and many genphy_ functions. This feature is enabled with CONFIG_RUST_PHYLIB_ABSTRACTIONS=y. This patch enables unstable const_maybe_uninit_zeroed feature for kernel crate to enable unsafe code to handle a constant value with uninitialized data. With the feature, the abstractions can initialize a phy_driver structure with zero easily; instead of initializing all the members by hand. It's supposed to be stable in the not so distant future. Link: https://github.com/rust-lang/rust/pull/116218 Signed-off-by:
FUJITA Tomonori <fujita.tomonori@gmail.com> Reviewed-by:
Andrew Lunn <andrew@lunn.ch> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Signed-off-by:
David S. Miller <davem@davemloft.net>
-
- Dec 14, 2023
-
-
Matthew Maurer authored
By default, if Rust is passed `--target=foo` rather than a target.json file, it will infer a default sysroot if that component is installed. As the proposed aarch64 support [1] uses `aarch64-unknown-none` rather than a target.json file, this is needed [2] to prevent rustc from being confused between the custom kernel sysroot and the pre-installed one. [ Miguel: Applied Boqun's extra case (for `rusttest`) and reworded to add links to the arm64 patch series discussion. In addition, fixed the `rustdoc` target too (which requires a conditional since `cmd_rustdoc` is also used for host crates like `macros`). ] Signed-off-by:
Matthew Maurer <mmaurer@google.com> Tested-by:
Boqun Feng <boqun.feng@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/rust-for-linux/20231020155056.3495121-1-Jamie.Cunliffe@arm.com/ [1] Link: https://lore.kernel.org/rust-for-linux/CAGSQo01pOixiPXkW867h4vPUaAjtKtHGKhkV-rpifJvKxAf4Ww@mail.gmail.com/ [2] Link: https://lore.kernel.org/r/20231031201752.1189213-1-mmaurer@google.com Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
Traits marked with `#[vtable]` need to provide default implementations for optional functions. The C side represents these with `NULL` in the vtable, so the default functions are never actually called. We do not want to replicate the default behavior from C in Rust, because that is not maintainable. Therefore we should use `build_error` in those default implementations. The error message for that is provided at `kernel::error::VTABLE_DEFAULT_ERROR`. Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Finn Behrens <me@kloenk.dev> Link: https://lore.kernel.org/r/20231026201855.1497680-1-benno.lossin@proton.me [ Wrapped paragraph to 80 as requested and capitalized sentence. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Trevor Gross authored
Enable combining identifiers with literals in the 'paste!' macro. This allows combining user-specified strings with affixes to create namespaced identifiers. This sample code: macro_rules! m { ($name:lit) => { paste!(struct [<_some_ $name _struct_>] {}) } } m!("foo_bar"); Would previously cause a compilation error. It will now generate: struct _some_foo_bar_struct_ {} Signed-off-by:
Trevor Gross <tmgross@umich.edu> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20231118013959.37384-1-tmgross@umich.edu [ Added `:` before example block. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Gary Guo authored
Currently, for `const`s that bindgen doesn't recognise, we define a helper constant with const <TYPE> BINDINGS_<NAME> = <NAME>; in `bindings_helper.h` and then we put pub const <NAME>: <TYPE> = BINDINGS_<NAME>; in `bindings/lib.rs`. This is fine since we currently only have 3 constants that are defined this way, but is going to be more annoying when more constants are added since every new constant needs to be defined in two places. This patch changes the way we define constant helpers to const <TYPE> RUST_CONST_HELPER_<NAME> = <NAME>; and then use `sed` to postprocess Rust code generated by bindgen to remove the distinct prefix, so users of the `bindings` crate can refer to the name directly. Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20231104145700.2495176-1-gary@garyguo.net [ Reworded for typos. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Dec 13, 2023
-
-
Matthew Maurer authored
Neither bindgen nor Rust know about the preserve-most calling convention, and Clang describes it as unstable. Since we aren't using functions with this calling convention from Rust, blocklist them. These functions are only added to the build when list hardening is enabled, which is likely why others didn't notice this yet. Signed-off-by:
Matthew Maurer <mmaurer@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20231031201945.1412345-1-mmaurer@google.com [ Used Markdown for consistency with the other comments in the file. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Masahiro Yamada authored
<linux/export.h> is the right header to include for using EXPORT_SYMBOL_GPL. <linux/module.h> includes much more bloat. Signed-off-by:
Masahiro Yamada <masahiroy@kernel.org> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20231124142617.713096-1-masahiroy@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Dec 12, 2023
-
-
Asahi Lina authored
Make it possible to use a `CString` with the `pr_*` macros directly. That is, instead of: pr_debug!("trying to open {:?}\n", &*filename); we can now write: pr_debug!("trying to open {:?}\n", filename); Signed-off-by:
Asahi Lina <lina@asahilina.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230714-cstring-debug-v1-1-4e7c3018dd4f@asahilina.net [ Reworded to use Alice's commit message as discussed. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Oct 19, 2023
-
-
Miguel Ojeda authored
The static files placement by `rustdoc` changed in Rust 1.67.0 [1], but the custom code we have to replace the logo in the generated HTML files did not get updated. Thus update it to have the Linux logo again in the output. Hopefully `rustdoc` will eventually support a custom logo from a local file [2], so that we do not need to maintain this hack on our side. Link: https://github.com/rust-lang/rust/pull/101702 [1] Link: https://github.com/rust-lang/rfcs/pull/3226 [2] Fixes: 3ed03f4d ("rust: upgrade to Rust 1.68.2") Cc: stable@vger.kernel.org Tested-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20231018155527.1015059-1-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Oct 15, 2023
-
-
Matthew Maurer authored
While GNU grep supports '\|' when in basic regular expression mode, not all grep implementations do (notably toybox grep, used to build the Android kernel, does not). Switching to grep -Ev enables extended regular expressions which includes support for the '|' operator. Signed-off-by:
Matthew Maurer <mmaurer@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Trevor Gross <tmgross@umich.edu> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Tested-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230928201421.2296518-1-mmaurer@google.com [ Reworded for typo. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Matthew Maurer authored
`awk` is already required by the kernel build, and the `xargs` feature used in current Rust detection is not present in all `xargs` (notably, toybox based xargs, used in the Android kernel build). Signed-off-by:
Matthew Maurer <mmaurer@google.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Tested-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230928205045.2375899-1-mmaurer@google.com Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Miguel Ojeda authored
This is the next upgrade to the Rust toolchain, from 1.72.1 to 1.73.0 (i.e. the latest) [1]. See the upgrade policy [2] and the comments on the first upgrade in commit 3ed03f4d ("rust: upgrade to Rust 1.68.2"). # Unstable features No unstable features (that we use) were stabilized. Therefore, the only unstable feature allowed to be used outside the `kernel` crate is still `new_uninit`, though other code to be upstreamed may increase the list. Please see [3] for details. # Required changes For the upgrade, the following changes are required: - Allow `internal_features` for `feature(compiler_builtins)` since now Rust warns about using internal compiler and standard library features (similar to how it also warns about incomplete ones) [4]. - A cleanup for a documentation link thanks to a new `rustdoc` lint. See previous commits for details. - A need to make an intra-doc link to a macro explicit, due to a change in behavior in `rustdoc`. See previous commits for details. # `alloc` upgrade and reviewing The vast majority of changes are due to our `alloc` fork being upgraded at once. There are two kinds of changes to be aware of: the ones coming from upstream, which we should follow as closely as possible, and the updates needed in our added fallible APIs to keep them matching the newer infallible APIs coming from upstream. Instead of taking a look at the diff of this patch, an alternative approach is reviewing a diff of the changes between upstream `alloc` and the kernel's. This allows to easily inspect the kernel additions only, especially to check if the fallible methods we already have still match the infallible ones in the new version coming from upstream. Another approach is reviewing the changes introduced in the additions in the kernel fork between the two versions. This is useful to spot potentially unintended changes to our additions. To apply these approaches, one may follow steps similar to the following to generate a pair of patches that show the differences between upstream Rust and the kernel (for the subset of `alloc` we use) before and after applying this patch: # Get the difference with respect to the old version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > old.patch git -C linux restore rust/alloc # Apply this patch. git -C linux am rust-upgrade.patch # Get the difference with respect to the new version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > new.patch git -C linux restore rust/alloc Now one may check the `new.patch` to take a look at the additions (first approach) or at the difference between those two patches (second approach). For the latter, a side-by-side tool is recommended. Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1730-2023-10-05 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: https://github.com/Rust-for-Linux/linux/issues/2 [3] Link: https://github.com/rust-lang/compiler-team/issues/596 [4] Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20231005210556.466856-4-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Miguel Ojeda authored
The future `rustdoc` in the Rust 1.73.0 upgrade requires an explicit link for `pr_info!`: error: unresolved link to `pr_info` --> rust/kernel/print.rs:395:63 | 395 | /// Use only when continuing a previous `pr_*!` macro (e.g. [`pr_info!`]). | ^^^^^^^^ no item named `pr_info` in scope | = note: `macro_rules` named `pr_info` exists in this crate, but it is not in scope at this link's location = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings` Thus do so to avoid a broken link while upgrading. Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by:
Finn Behrens <me@kloenk.dev> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20231005210556.466856-3-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Miguel Ojeda authored
Starting with Rust 1.73.0, `rustdoc` detects redundant explicit links with its new lint `redundant_explicit_links` [1]: error: redundant explicit link target --> rust/kernel/task.rs:85:21 | 85 | /// [`current`](crate::current) macro because it is safe. | --------- ^^^^^^^^^^^^^^ explicit target is redundant | | | because label contains path that resolves to same destination | = note: when a link's destination is not specified, the label is used to resolve intra-doc links = note: `-D rustdoc::redundant-explicit-links` implied by `-D warnings` help: remove explicit link target | 85 | /// [`current`] macro because it is safe. In order to avoid the warning in the compiler upgrade commit, make it an intra-doc link as the tool suggests. Link: https://github.com/rust-lang/rust/pull/113167 [1] Reviewed-by:
Finn Behrens <me@kloenk.dev> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Link: https://lore.kernel.org/r/20231005210556.466856-2-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Oct 14, 2023
-
-
Matthew Maurer authored
Currently, rustc defaults to invoking `cc`, even if `HOSTCC` is defined, resulting in build failures in hermetic environments where `cc` does not exist. This includes both hostprogs and proc-macros. Since we are setting the linker to `HOSTCC`, we set the linker flavor to `gcc` explicitly. The linker-flavor selects both which linker to search for if the linker is unset, and which kind of linker flags to pass. Without this flag, `rustc` would attempt to determine which flags to pass based on the name of the binary passed as `HOSTCC`. `gcc` is the name of the linker-flavor used by `rustc` for all C compilers, including both `gcc` and `clang`. Signed-off-by:
Matthew Maurer <mmaurer@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Tested-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Nick Desaulniers <ndesaulniers@google.com> Acked-by:
Miguel Ojeda <ojeda@kernel.org> Signed-off-by:
Masahiro Yamada <masahiroy@kernel.org>
-
- Oct 12, 2023
-
-
Andrea Righi authored
Commit df8fc4e9 ("kbuild: Enable -fstrict-flex-arrays=3") enabled '-fstrict-flex-arrays=3' globally, but bindgen does not recognized this compiler option, triggering the following build error: error: unknown argument: '-fstrict-flex-arrays=3', err: true [ Miguel: Commit df8fc4e9 ("kbuild: Enable -fstrict-flex-arrays=3") did it so only conditionally (i.e. only if the C compiler supports it). This explains what Andrea was seeing: he was compiling with a modern enough GCC, which enables the option, but with an old enough Clang. Andrea confirmed this was the case: he was using Clang 14 with GCC 13; and that Clang 15 worked for him. While it is possible to construct code (see mailing list for an example I came up with) where this could break, it is fairly contrived, and anyway GCC-built kernels with Rust enabled should only be used for experimentation until we get support for `rustc_codegen_gcc` and/or GCC Rust. So let's add this for the time being in case it helps somebody. ] Add '-fstrict-flex-arrays' to the list of cflags that should be ignored by bindgen. Fixes: df8fc4e9 ("kbuild: Enable -fstrict-flex-arrays=3") Signed-off-by:
Andrea Righi <andrea.righi@canonical.com> Tested-by:
Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20230815065346.131387-1-andrea.righi@canonical.com Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Manmohan Shukla authored
This patch fixes a trivial markdown style nit in the `SAFETY` comment. Signed-off-by:
Manmohan Shukla <manmshuk@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Jianguo Bao <roidinev@gmail.com> Reviewed-by:
Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by:
Finn Behrens <me@kloenk.dev> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Fixes: c7e20faa ("rust: error: Add Error::to_ptr()") Link: https://lore.kernel.org/r/20230906204857.85619-1-manmshuk@gmail.com Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Wedson Almeida Filho authored
A mistake was made and the description of `ECHILD` is wrong (it reuses the description of `ENOEXEC`). This fixes it to reflect what's in `errno-base.h`. Signed-off-by:
Wedson Almeida Filho <walmeida@microsoft.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Trevor Gross <tmgross@umich.edu> Reviewed-by:
Finn Behrens <me@kloenk.dev> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Fixes: 266def2a ("rust: error: add codes from `errno-base.h`") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20230930144958.46051-1-wedsonaf@gmail.com [ Use the plural, as noticed by Benno. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Oct 05, 2023
-
-
Gary Guo authored
Clippy triggered a false positive on its `new_ret_no_self` lint when using the `pin_init!` macro. Since Rust 1.67.0, that does not happen anymore, since Clippy learnt to not warn about `-> impl Trait<Self>` [1][2]. The kernel nowadays uses Rust 1.72.1, thus remove the `#[allow]`. Signed-off-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Finn Behrens <me@kloenk.dev> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://github.com/rust-lang/rust-clippy/issues/7344 [1] Link: https://github.com/rust-lang/rust-clippy/pull/9733 [2] Link: https://lore.kernel.org/r/20230923024707.47610-1-gary@garyguo.net [ Reworded slightly and added a couple `Link`s. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Miguel Ojeda authored
This is the third upgrade to the Rust toolchain, from 1.71.1 to 1.72.1 (i.e. the latest) [1]. See the upgrade policy [2] and the comments on the first upgrade in commit 3ed03f4d ("rust: upgrade to Rust 1.68.2"). # Unstable features No unstable features (that we use) were stabilized. Therefore, the only unstable feature allowed to be used outside the `kernel` crate is still `new_uninit`, though other code to be upstreamed may increase the list. Please see [3] for details. # Other improvements Previously, the compiler could incorrectly generate a `.eh_frame` section under `-Cpanic=abort`. We were hitting this bug when debug assertions were enabled (`CONFIG_RUST_DEBUG_ASSERTIONS=y`) [4]: LD .tmp_vmlinux.kallsyms1 ld.lld: error: <internal>:(.eh_frame) is being placed in '.eh_frame' Gary fixed the issue in Rust 1.72.0 [5]. # Required changes For the upgrade, the following changes are required: - A call to `Box::from_raw` in `rust/kernel/sync/arc.rs` now requires an explicit `drop()` call. See previous patch for details. # `alloc` upgrade and reviewing The vast majority of changes are due to our `alloc` fork being upgraded at once. There are two kinds of changes to be aware of: the ones coming from upstream, which we should follow as closely as possible, and the updates needed in our added fallible APIs to keep them matching the newer infallible APIs coming from upstream. Instead of taking a look at the diff of this patch, an alternative approach is reviewing a diff of the changes between upstream `alloc` and the kernel's. This allows to easily inspect the kernel additions only, especially to check if the fallible methods we already have still match the infallible ones in the new version coming from upstream. Another approach is reviewing the changes introduced in the additions in the kernel fork between the two versions. This is useful to spot potentially unintended changes to our additions. To apply these approaches, one may follow steps similar to the following to generate a pair of patches that show the differences between upstream Rust and the kernel (for the subset of `alloc` we use) before and after applying this patch: # Get the difference with respect to the old version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > old.patch git -C linux restore rust/alloc # Apply this patch. git -C linux am rust-upgrade.patch # Get the difference with respect to the new version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > new.patch git -C linux restore rust/alloc Now one may check the `new.patch` to take a look at the additions (first approach) or at the difference between those two patches (second approach). For the latter, a side-by-side tool is recommended. Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1721-2023-09-19 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: https://github.com/Rust-for-Linux/linux/issues/2 [3] Closes: https://github.com/Rust-for-Linux/linux/issues/1012 [4] Link: https://github.com/rust-lang/rust/pull/112403 [5] Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Link: https://lore.kernel.org/r/20230823160244.188033-3-ojeda@kernel.org [ Used 1.72.1 instead of .0 (no changes in `alloc`) and reworded to mention that we hit the `.eh_frame` bug under debug assertions. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Miguel Ojeda authored
`Box::from_raw()` is `#[must_use]`, which means the result cannot go unused. In Rust 1.71.0, this was not detected because the block expression swallows the diagnostic [1]: unsafe { Box::from_raw(self.ptr.as_ptr()) }; It would have been detected, however, if the line had been instead: unsafe { Box::from_raw(self.ptr.as_ptr()); } i.e. the semicolon being inside the `unsafe` block, rather than outside. In Rust 1.72.0, the compiler started warning about this [2], so without this patch we will get: error: unused return value of `alloc::boxed::Box::<T>::from_raw` that must be used --> rust/kernel/sync/arc.rs:302:22 | 302 | unsafe { Box::from_raw(self.ptr.as_ptr()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: call `drop(Box::from_raw(ptr))` if you intend to drop the `Box` = note: `-D unused-must-use` implied by `-D warnings` help: use `let _ = ...` to ignore the resulting value | 302 | unsafe { let _ = Box::from_raw(self.ptr.as_ptr()); }; | +++++++ + Thus add an add an explicit `drop()` as the `#[must_use]`'s annotation suggests (instead of the more general help line). Link: https://github.com/rust-lang/rust/issues/104253 [1] Link: https://github.com/rust-lang/rust/pull/112529 [2] Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by:
Björn Roy Baron <bjorn3_gh@protonmail.com> Link: https://lore.kernel.org/r/20230823160244.188033-2-ojeda@kernel.org Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
- Sep 25, 2023
-
-
Alice Ryhl authored
This adds two examples of how to use the workqueue. The first example shows how to use it when you only have one `work_struct` field, and the second example shows how to use it when you have multiple `work_struct` fields. Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
"Andreas Hindborg (Samsung)" <nmi@metaspace.dk> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
Alice Ryhl authored
This adds a convenience method that lets you spawn a closure for execution on a workqueue. This will be the most convenient way to use workqueues, but it is fallible because it needs to allocate memory. Co-developed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
"Andreas Hindborg (Samsung)" <nmi@metaspace.dk> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
Alice Ryhl authored
This implements the `WorkItemPointer` trait for the pointer types that you are likely to use the workqueue with. The `Arc` type is for reference counted objects, and the `Pin<Box<T>>` type is for objects where the caller has exclusive ownership of the object. Co-developed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
"Andreas Hindborg (Samsung)" <nmi@metaspace.dk> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
Alice Ryhl authored
The main challenge with defining `work_struct` fields is making sure that the function pointer stored in the `work_struct` is appropriate for the work item type it is embedded in. It needs to know the offset of the `work_struct` field being used (even if there are several!) so that it can do a `container_of`, and it needs to know the type of the work item so that it can call into the right user-provided code. All of this needs to happen in a way that provides a safe API to the user, so that users of the workqueue cannot mix up the function pointers. There are three important pieces that are relevant when doing this: * The pointer type. * The work item struct. This is what the pointer points at. * The `work_struct` field. This is a field of the work item struct. This patch introduces a separate trait for each piece. The pointer type is given a `WorkItemPointer` trait, which pointer types need to implement to be usable with the workqueue. This trait will be implemented for `Arc` and `Box` in a later patch in this patchset. Implementing this trait is unsafe because this is where the `container_of` operation happens, but user-code will not need to implement it themselves. The work item struct should then implement the `WorkItem` trait. This trait is where user-code specifies what they want to happen when a work item is executed. It also specifies what the correct pointer type is. Finally, to make the work item struct know the offset of its `work_struct` field, we use a trait called `HasWork<T, ID>`. If a type implements this trait, then the type declares that, at the given offset, there is a field of type `Work<T, ID>`. The trait is marked unsafe because the OFFSET constant must be correct, but we provide an `impl_has_work!` macro that can safely implement `HasWork<T>` on a type. The macro expands to something that only compiles if the specified field really has the type `Work<T>`. It is used like this: ``` struct MyWorkItem { work_field: Work<MyWorkItem, 1>, } impl_has_work! { impl HasWork<MyWorkItem, 1> for MyWorkItem { self.work_field } } ``` Note that since the `Work` type is annotated with an id, you can have several `work_struct` fields by using a different id for each one. Co-developed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
Wedson Almeida Filho authored
We provide these methods because it lets us access these queues from Rust without using unsafe code. These methods return `&'static Queue`. References annotated with the 'static lifetime are used when the referent will stay alive forever. That is ok for these queues because they are global variables and cannot be destroyed. Signed-off-by:
Wedson Almeida Filho <walmeida@microsoft.com> Co-developed-by:
Alice Ryhl <aliceryhl@google.com> Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
"Andreas Hindborg (Samsung)" <nmi@metaspace.dk> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
Alice Ryhl authored
Define basic low-level bindings to a kernel workqueue. The API defined here can only be used unsafely. Later commits will provide safe wrappers. Co-developed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
"Andreas Hindborg (Samsung)" <nmi@metaspace.dk> Reviewed-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
Wedson Almeida Filho authored
These methods can be used to turn an `Arc` into a raw pointer and back, in a way that preserves the metadata for fat pointers. This is done using the unstable ptr_metadata feature [1]. However, it could also be done using the unstable pointer_byte_offsets feature [2], which is likely to have a shorter path to stabilization than ptr_metadata. Link: https://github.com/rust-lang/rust/issues/81513 [1] Link: https://github.com/rust-lang/rust/issues/96283 [2] Signed-off-by:
Wedson Almeida Filho <walmeida@microsoft.com> Co-developed-by:
Alice Ryhl <aliceryhl@google.com> 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> Reviewed-by:
Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by:
Boqun Feng <boqun.feng@gmail.com> Signed-off-by:
Tejun Heo <tj@kernel.org>
-
- Aug 21, 2023
-
-
Benno Lossin authored
The previous patches changed the internals of the macros resulting in the example expanded code being outdated. This patch updates the example and only changes documentation. Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230814084602.25699-14-benno.lossin@proton.me Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
The `{pin_}chain` functions extend an initializer: it not only initializes the value, but also executes a closure taking a reference to the initialized value. This allows to do something with a value directly after initialization. Suggested-by:
Asahi Lina <lina@asahilina.net> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230814084602.25699-13-benno.lossin@proton.me [ Cleaned a few trivial nits. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
Remove the blanket implementation of `PinInit<T, E> for I where I: Init<T, E>`. This blanket implementation prevented custom types that implement `PinInit`. Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230814084602.25699-12-benno.lossin@proton.me Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
`UnsafeCell<T>` and `T` have the same layout so if `T` is `Zeroable` then so should `UnsafeCell<T>` be. This allows using the derive macro for `Zeroable` on types that contain an `UnsafeCell<T>`. Since `Opaque<T>` contains a `MaybeUninit<T>`, all bytes zero is a valid bit pattern for that type. Reviewed-by:
Gary Guo <gary@garyguo.net> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230814084602.25699-11-benno.lossin@proton.me Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
Previously only `ident` and generic types were supported in the `{try_}{pin_}init!` macros. This patch allows arbitrary path fragments, so for example `Foo::Bar` but also very complex paths such as `<Foo as Baz>::Bar::<0, i32>`. Internally this is accomplished by using `path` fragments. Due to some peculiar declarative macro limitations, we have to "forget" certain additional parsing information in the token trees. This is achieved by using the `paste!` proc macro. It does not actually modify the input, since no `[< >]` will be present in the input, so it just strips the information held by declarative macros. For example, if a declarative macro takes `$t:path` as its input, it cannot sensibly propagate this to a macro that takes `$($p:tt)*` as its input, since the `$t` token will only be considered one `tt` token for the second macro. If we first pipe the tokens through `paste!`, then it parses as expected. Suggested-by:
Asahi Lina <lina@asahilina.net> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230814084602.25699-10-benno.lossin@proton.me Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
Add two functions `pin_init_array_from_fn` and `init_array_from_fn` that take a function that generates initializers for `T` from `usize`, the added functions then return an initializer for `[T; N]` where every element is initialized by an element returned from the generator function. Suggested-by:
Asahi Lina <lina@asahilina.net> 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> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230814084602.25699-9-benno.lossin@proton.me [ Cleaned a couple trivial nits. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-
Benno Lossin authored
Add the struct update syntax to the init macros, but only for `..Zeroable::zeroed()`. Adding this at the end of the struct initializer allows one to omit fields from the initializer, these fields will be initialized with 0x00 set to every byte. Only types that implement the `Zeroable` trait can utilize this. Suggested-by:
Asahi Lina <lina@asahilina.net> Reviewed-by:
Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by:
Alice Ryhl <aliceryhl@google.com> Reviewed-by:
Gary Guo <gary@garyguo.net> Signed-off-by:
Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230814084602.25699-8-benno.lossin@proton.me [ Rebased on `rust-next` and cleaned a few trivial nits. ] Signed-off-by:
Miguel Ojeda <ojeda@kernel.org>
-