| 6fbafe1c | 08-Mar-2025 |
Panagiotis Foliadis <[email protected]> |
rust: task: fix `SAFETY` comment in `Task::wake_up`
The `SAFETY` comment inside the `wake_up` method references erroneously the `signal_pending` C function instead of the `wake_up_process` which is
rust: task: fix `SAFETY` comment in `Task::wake_up`
The `SAFETY` comment inside the `wake_up` method references erroneously the `signal_pending` C function instead of the `wake_up_process` which is actually called.
Fix the comment to reference the correct C function.
Fixes: fe95f58320e6 ("rust: task: adjust safety comments in Task methods") Signed-off-by: Panagiotis Foliadis <[email protected]> Reviewed-by: Charalampos Mitrodimas <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Slightly reworded. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 38559da6 | 09-Mar-2025 |
Guilherme Giacomo Simoes <[email protected]> |
rust: module: introduce `authors` key
In the `module!` macro, the `author` field is currently of type `String`.
Since modules can have multiple authors, this limitation prevents specifying more tha
rust: module: introduce `authors` key
In the `module!` macro, the `author` field is currently of type `String`.
Since modules can have multiple authors, this limitation prevents specifying more than one.
Add an `authors` field as `Option<Vec<String>>` to allow creating modules with multiple authors, and change the documentation and all current users to use it. Eventually, the single `author` field may be removed.
[ The `modinfo` key needs to still be `author`; otherwise, tooling may not work properly, e.g.:
$ modinfo --author samples/rust/rust_print.ko Rust for Linux Contributors
I have also kept the original `author` field (undocumented), so that we can drop it more easily in a kernel cycle or two.
- Miguel ]
Suggested-by: Miguel Ojeda <[email protected]> Link: https://github.com/Rust-for-Linux/linux/issues/244 Reviewed-by: Charalampos Mitrodimas <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Signed-off-by: Guilherme Giacomo Simoes <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Fixed `modinfo` key. Kept `author` field. Reworded message accordingly. Updated my email. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 92d2873b | 03-Mar-2025 |
Alice Ryhl <[email protected]> |
print: use new #[export] macro for rust_fmt_argument
This moves the rust_fmt_argument function over to use the new #[export] macro, which will verify at compile-time that the function signature matc
print: use new #[export] macro for rust_fmt_argument
This moves the rust_fmt_argument function over to use the new #[export] macro, which will verify at compile-time that the function signature matches what is in the header file.
Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Tamir Duberstein <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Acked-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Removed period as requested by Andy. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 44e333fe | 03-Mar-2025 |
Alice Ryhl <[email protected]> |
rust: add #[export] macro
Rust has two different tools for generating function declarations to call across the FFI boundary:
* bindgen. Generates Rust declarations from a C header. * cbindgen. Gene
rust: add #[export] macro
Rust has two different tools for generating function declarations to call across the FFI boundary:
* bindgen. Generates Rust declarations from a C header. * cbindgen. Generates C headers from Rust declarations.
However, we only use bindgen in the kernel. This means that when C code calls a Rust function by name, its signature must be duplicated in both Rust code and a C header, and the signature needs to be kept in sync manually.
Introducing cbindgen as a mandatory dependency to build the kernel would be a rather complex and large change, so we do not consider that at this time. Instead, to eliminate this manual checking, introduce a new macro that verifies at compile time that the two function declarations use the same signature. The idea is to run the C declaration through bindgen, and then have rustc verify that the function pointers have the same type.
The signature must still be written twice, but at least you can no longer get it wrong. If the signatures don't match, you will get errors that look like this:
error[E0308]: `if` and `else` have incompatible types --> <linux>/rust/kernel/print.rs:22:22 | 21 | #[export] | --------- expected because of this 22 | unsafe extern "C" fn rust_fmt_argument( | ^^^^^^^^^^^^^^^^^ expected `u8`, found `i8` | = note: expected fn item `unsafe extern "C" fn(*mut u8, *mut u8, *mut c_void) -> *mut u8 {bindings::rust_fmt_argument}` found fn item `unsafe extern "C" fn(*mut i8, *mut i8, *const c_void) -> *mut i8 {print::rust_fmt_argument}`
It is unfortunate that the error message starts out by saying "`if` and `else` have incompatible types", but I believe the rest of the error message is reasonably clear and not too confusing.
Reviewed-by: Tamir Duberstein <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 901b3290 | 03-Mar-2025 |
Alice Ryhl <[email protected]> |
rust: fix signature of rust_fmt_argument
Without this change, the rest of this series will emit the following error message:
error[E0308]: `if` and `else` have incompatible types --> <linux>/rust
rust: fix signature of rust_fmt_argument
Without this change, the rest of this series will emit the following error message:
error[E0308]: `if` and `else` have incompatible types --> <linux>/rust/kernel/print.rs:22:22 | 21 | #[export] | --------- expected because of this 22 | unsafe extern "C" fn rust_fmt_argument( | ^^^^^^^^^^^^^^^^^ expected `u8`, found `i8` | = note: expected fn item `unsafe extern "C" fn(*mut u8, *mut u8, *mut c_void) -> *mut u8 {bindings::rust_fmt_argument}` found fn item `unsafe extern "C" fn(*mut i8, *mut i8, *const c_void) -> *mut i8 {print::rust_fmt_argument}`
The error may be different depending on the architecture.
To fix this, change the void pointer argument to use a const pointer, and change the imports to use crate::ffi instead of core::ffi for integer types.
Fixes: 787983da7718 ("vsprintf: add new `%pA` format specifier") Reviewed-by: Tamir Duberstein <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Acked-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 1d121a33 | 06-Mar-2025 |
Danilo Krummrich <[email protected]> |
rust: firmware: add `module_firmware!` macro
Analogous to the `module!` macro `module_firmware!` adds additional firmware path strings to the .modinfo section.
In contrast to `module!`, where path
rust: firmware: add `module_firmware!` macro
Analogous to the `module!` macro `module_firmware!` adds additional firmware path strings to the .modinfo section.
In contrast to `module!`, where path strings need to be string literals, path strings can be composed with the `firmware::ModInfoBuilder`.
Some drivers require a lot of firmware files (such as nova-core) and hence benefit from more flexibility composing firmware path strings.
Acked-by: Jarkko Sakkinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
show more ...
|
| 52ae96f5 | 10-Feb-2025 |
Alice Ryhl <[email protected]> |
rust: list: make the cursor point between elements
I've been using the linked list cursor for a few different things, and I find it inconvenient to use because all of the functions have signatures a
rust: list: make the cursor point between elements
I've been using the linked list cursor for a few different things, and I find it inconvenient to use because all of the functions have signatures along the lines of `Self -> Option<Self>`. The root cause of these signatures is that the cursor points *at* an element, rather than *between* two elements.
Thus, change the cursor API to point between two elements. This is inspired by the stdlib linked list (well, really by this guy [1]), which also uses cursors that point between elements.
The `peek_next` method returns a helper that lets you look at and optionally remove the element, as one common use-case of cursors is to iterate a list to look for an element, then remove that element.
For many of the methods, this will reduce how many we need since they now just need a prev/next method, instead of the current state where you may end up needing all of curr/prev/next. Also, if we decide to add a function for splitting a list into two lists at the cursor, then a cursor that points between elements is exactly what makes the most sense.
Another advantage is that this means you can now have a cursor into an empty list.
Link: https://rust-unofficial.github.io/too-many-lists/sixth-cursors-intro.html [1] Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 998c6573 | 10-Feb-2025 |
Alice Ryhl <[email protected]> |
rust: list: extract common code for insertion
To prepare for a new cursor API that has the ability to insert elements into the list, extract the common code needed for this operation into a new `ins
rust: list: extract common code for insertion
To prepare for a new cursor API that has the ability to insert elements into the list, extract the common code needed for this operation into a new `insert_inner` method.
Both `push_back` and `push_front` are updated to use the new function.
Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| f73ca66f | 07-Mar-2025 |
Mitchell Levy <[email protected]> |
rust: lockdep: Use Pin for all LockClassKey usages
Reintroduce dynamically-allocated LockClassKeys such that they are automatically (de)registered. Require that all usages of LockClassKeys ensure th
rust: lockdep: Use Pin for all LockClassKey usages
Reintroduce dynamically-allocated LockClassKeys such that they are automatically (de)registered. Require that all usages of LockClassKeys ensure that they are Pin'd.
Currently, only `'static` LockClassKeys are supported, so Pin is redundant. However, it is intended that dynamically-allocated LockClassKeys will eventually be supported, so using Pin from the outset will make that change simpler.
Closes: https://github.com/Rust-for-Linux/linux/issues/1102 Suggested-by: Benno Lossin <[email protected]> Suggested-by: Boqun Feng <[email protected]> Signed-off-by: Mitchell Levy <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| 70b9c856 | 07-Mar-2025 |
Alice Ryhl <[email protected]> |
rust: sync: condvar: Add wait_interruptible_freezable()
To support waiting for a `CondVar` as a freezable process, add a wait_interruptible_freezable() function.
Binder needs this function in the a
rust: sync: condvar: Add wait_interruptible_freezable()
To support waiting for a `CondVar` as a freezable process, add a wait_interruptible_freezable() function.
Binder needs this function in the appropriate places to freeze a process where some of its threads are blocked on the Binder driver.
[ Boqun: Cleaned up the changelog and documentation. ]
Signed-off-by: Alice Ryhl <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| c2849afa | 07-Mar-2025 |
Boqun Feng <[email protected]> |
rust: sync: lock: Add an example for Guard:: Lock_ref()
To provide examples on usage of `Guard::lock_ref()` along with the unit test, an "assert a lock is held by a guard" example is added.
(Also a
rust: sync: lock: Add an example for Guard:: Lock_ref()
To provide examples on usage of `Guard::lock_ref()` along with the unit test, an "assert a lock is held by a guard" example is added.
(Also apply feedback from Benno.)
Signed-off-by: Boqun Feng <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| 6ad64bf9 | 30-Jan-2025 |
Alice Ryhl <[email protected]> |
rust: task: make Pid type alias public
The Pid type alias represents the integer type used for pids in the kernel. It's the Rust equivalent to pid_t, and there are various methods on Task that use P
rust: task: make Pid type alias public
The Pid type alias represents the integer type used for pids in the kernel. It's the Rust equivalent to pid_t, and there are various methods on Task that use Pid as the return type.
Binder needs to use Pid as the type for function arguments and struct fields in many places. Thus, make the type public so that Binder can access it.
Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Fiona Behrens <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 0ea4c390 | 06-Feb-2025 |
Alban Kurti <[email protected]> |
rust: workqueue: add missing newline to pr_info! examples
The documentation examples in rust/kernel/workqueue.rs use pr_info! calls that lack a trailing newline. To maintain consistency with kernel
rust: workqueue: add missing newline to pr_info! examples
The documentation examples in rust/kernel/workqueue.rs use pr_info! calls that lack a trailing newline. To maintain consistency with kernel logging practices, this patch adds the newline to all affected examples.
Fixes: 15b286d1fd05 ("rust: workqueue: add examples") Reported-by: Miguel Ojeda <[email protected]> Link: https://github.com/Rust-for-Linux/linux/issues/1139 Signed-off-by: Alban Kurti <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Replaced Closes with Link since it fixes part of the issue. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 50c3e77e | 06-Feb-2025 |
Alban Kurti <[email protected]> |
rust: sync: add missing newline in locked_by log example
The pr_info! example in rust/kernel/sync/locked_by.rs was missing a newline. This patch appends the missing newline to ensure that log messag
rust: sync: add missing newline in locked_by log example
The pr_info! example in rust/kernel/sync/locked_by.rs was missing a newline. This patch appends the missing newline to ensure that log messages for locked resources display correctly.
Fixes: 7b1f55e3a984 ("rust: sync: introduce `LockedBy`") Reported-by: Miguel Ojeda <[email protected]> Link: https://github.com/Rust-for-Linux/linux/issues/1139 Signed-off-by: Alban Kurti <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Replaced Closes with Link since it fixes part of the issue. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 6933c106 | 06-Feb-2025 |
Alban Kurti <[email protected]> |
rust: init: add missing newline to pr_info! calls
Several pr_info! calls in rust/kernel/init.rs (both in code examples and macro documentation) were missing a newline, causing logs to run together.
rust: init: add missing newline to pr_info! calls
Several pr_info! calls in rust/kernel/init.rs (both in code examples and macro documentation) were missing a newline, causing logs to run together. This commit updates these calls to include a trailing newline, improving readability and consistency with the C side.
Fixes: 6841d45a3030 ("rust: init: add `stack_pin_init!` macro") Fixes: 7f8977a7fe6d ("rust: init: add `{pin_}chain` functions to `{Pin}Init<T, E>`") Fixes: d0fdc3961270 ("rust: init: add `PinnedDrop` trait and macros") Fixes: 4af84c6a85c6 ("rust: init: update expanded macro explanation") Reported-by: Miguel Ojeda <[email protected]> Link: https://github.com/Rust-for-Linux/linux/issues/1139 Signed-off-by: Alban Kurti <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Replaced Closes with Link since it fixes part of the issue. Added one more Fixes tag (still same set of stable kernels). - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| ff64846b | 13-Feb-2025 |
Tamir Duberstein <[email protected]> |
rust: alloc: satisfy POSIX alignment requirement
ISO C's `aligned_alloc` is partially implementation-defined; on some systems it inherits stricter requirements from POSIX's `posix_memalign`.
This c
rust: alloc: satisfy POSIX alignment requirement
ISO C's `aligned_alloc` is partially implementation-defined; on some systems it inherits stricter requirements from POSIX's `posix_memalign`.
This causes the call added in commit dd09538fb409 ("rust: alloc: implement `Cmalloc` in module allocator_test") to fail on macOS because it doesn't meet the requirements of `posix_memalign`.
Adjust the call to meet the POSIX requirement and add a comment. This fixes failures in `make rusttest` on macOS.
Acked-by: Danilo Krummrich <[email protected]> Cc: [email protected] Fixes: dd09538fb409 ("rust: alloc: implement `Cmalloc` in module allocator_test") Signed-off-by: Tamir Duberstein <[email protected]> Reviewed-by: Gary Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Added Cc: stable. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| df27cef1 | 05-Mar-2025 |
Benno Lossin <[email protected]> |
rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<KBox<T>>`
According to [1], `NonNull<T>` and `#[repr(transparent)]` wrapper types such as our custom `KBox<T>` have the
rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<KBox<T>>`
According to [1], `NonNull<T>` and `#[repr(transparent)]` wrapper types such as our custom `KBox<T>` have the null pointer optimization only if `T: Sized`. Thus remove the `Zeroable` implementation for the unsized case.
Link: https://doc.rust-lang.org/stable/std/option/index.html#representation [1] Reported-by: Alice Ryhl <[email protected]> Closes: https://lore.kernel.org/rust-for-linux/CAH5fLghL+qzrD8KiCF1V3vf2YcC6aWySzkmaE2Zzrnh1gKj-hw@mail.gmail.com/ Cc: [email protected] # v6.12+ (a custom patch will be needed for 6.6.y) Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function") Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Added Closes tag and moved up the Reported-by one. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|