51158207 | 19-Dec-2024 |
Wedson Almeida Filho <wedsonaf@gmail.com> |
rust: add rcu abstraction
Add a simple abstraction to guard critical code sections with an rcu read lock.
Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Wedson Almeida Filho <wedsona
rust: add rcu abstraction
Add a simple abstraction to guard critical code sections with an rcu read lock.
Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Co-developed-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Tested-by: Dirk Behme <dirk.behme@de.bosch.com> Tested-by: Fabien Parent <fabien.parent@linaro.org> Link: https://lore.kernel.org/r/20241219170425.12036-5-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
9b90864b | 19-Dec-2024 |
Danilo Krummrich <dakr@kernel.org> |
rust: implement `IdArray`, `IdTable` and `RawDeviceId`
Most subsystems use some kind of ID to match devices and drivers. Hence, we have to provide Rust drivers an abstraction to register an ID table
rust: implement `IdArray`, `IdTable` and `RawDeviceId`
Most subsystems use some kind of ID to match devices and drivers. Hence, we have to provide Rust drivers an abstraction to register an ID table for the driver to match.
Generally, those IDs are subsystem specific and hence need to be implemented by the corresponding subsystem. However, the `IdArray`, `IdTable` and `RawDeviceId` types provide a generalized implementation that makes the life of subsystems easier to do so.
Co-developed-by: Wedson Almeida Filho <wedsonaf@gmail.com> Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Co-developed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Gary Guo <gary@garyguo.net> Co-developed-by: Fabien Parent <fabien.parent@linaro.org> Signed-off-by: Fabien Parent <fabien.parent@linaro.org> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Tested-by: Dirk Behme <dirk.behme@de.bosch.com> Tested-by: Fabien Parent <fabien.parent@linaro.org> Link: https://lore.kernel.org/r/20241219170425.12036-4-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
ea7e1828 | 19-Dec-2024 |
Danilo Krummrich <dakr@kernel.org> |
rust: implement generic driver registration
Implement the generic `Registration` type and the `RegistrationOps` trait.
The `Registration` structure is the common type that represents a driver regis
rust: implement generic driver registration
Implement the generic `Registration` type and the `RegistrationOps` trait.
The `Registration` structure is the common type that represents a driver registration and is typically bound to the lifetime of a module. However, it doesn't implement actual calls to the kernel's driver core to register drivers itself.
Instead the `RegistrationOps` trait is provided to subsystems, which have to implement `RegistrationOps::register` and `RegistrationOps::unregister`. Subsystems have to provide an implementation for both of those methods where the subsystem specific variants to register / unregister a driver have to implemented.
For instance, the PCI subsystem would call __pci_register_driver() from `RegistrationOps::register` and pci_unregister_driver() from `DrvierOps::unregister`.
Co-developed-by: Wedson Almeida Filho <wedsonaf@gmail.com> Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Tested-by: Dirk Behme <dirk.behme@de.bosch.com> Tested-by: Fabien Parent <fabien.parent@linaro.org> Link: https://lore.kernel.org/r/20241219170425.12036-3-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
a790265c | 19-Dec-2024 |
Danilo Krummrich <dakr@kernel.org> |
rust: module: add trait `ModuleMetadata`
In order to access static metadata of a Rust kernel module, add the `ModuleMetadata` trait.
In particular, this trait provides the name of a Rust kernel mod
rust: module: add trait `ModuleMetadata`
In order to access static metadata of a Rust kernel module, add the `ModuleMetadata` trait.
In particular, this trait provides the name of a Rust kernel module as specified by the `module!` macro.
Signed-off-by: Danilo Krummrich <dakr@kernel.org> Tested-by: Dirk Behme <dirk.behme@de.bosch.com> Tested-by: Fabien Parent <fabien.parent@linaro.org> Link: https://lore.kernel.org/r/20241219170425.12036-2-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
fbd7a5a0 | 25-Nov-2024 |
Lyude Paul <lyude@redhat.com> |
rust: sync: Add lock::Backend::assert_is_held()
Since we've exposed Lock::from_raw() and Guard::new() publically, we want to be able to make sure that we assert that a lock is actually held when con
rust: sync: Add lock::Backend::assert_is_held()
Since we've exposed Lock::from_raw() and Guard::new() publically, we want to be able to make sure that we assert that a lock is actually held when constructing a Guard for it to handle instances of unsafe Guard::new() calls outside of our lock module.
Hence add a new method assert_is_held() to Backend, which uses lockdep to check whether or not a lock has been acquired. When lockdep is disabled, this has no overhead.
[Boqun: Resolve the conflicts with exposing Guard::new(), reword the commit log a bit and format "unsafe { <statement>; }" into "unsafe { <statement> }" for the consistency. ]
Signed-off-by: Lyude Paul <lyude@redhat.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20241125204139.656801-1-lyude@redhat.com
show more ...
|
eb5ccb03 | 20-Nov-2024 |
Lyude Paul <lyude@redhat.com> |
rust: sync: Add SpinLockGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from SpinLocks.
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice
rust: sync: Add SpinLockGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from SpinLocks.
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20241120222742.2490495-3-lyude@redhat.com
show more ...
|
37624dde | 20-Nov-2024 |
Lyude Paul <lyude@redhat.com> |
rust: sync: Add MutexGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from Mutexes.
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice Ryhl
rust: sync: Add MutexGuard type alias
A simple helper alias for code that needs to deal with Guard types returned from Mutexes.
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20241120222742.2490495-2-lyude@redhat.com
show more ...
|
daa03fe5 | 20-Nov-2024 |
Lyude Paul <lyude@redhat.com> |
rust: sync: Make Guard::new() public
Since we added a `Lock::from_raw()` function previously, it makes sense to also introduce an interface for creating a `Guard` from a reference to a `Lock` for in
rust: sync: Make Guard::new() public
Since we added a `Lock::from_raw()` function previously, it makes sense to also introduce an interface for creating a `Guard` from a reference to a `Lock` for instances where we've derived the `Lock` from a raw pointer and know that the lock is already acquired, there are such usages in KMS API.
[Boqun: Add backquotes to type names, reformat the commit log, reword a bit on the usage of KMS API]
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Filipe Xavier <felipe_life@live.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20241119231146.2298971-3-lyude@redhat.com
show more ...
|
15abc880 | 20-Nov-2024 |
Lyude Paul <lyude@redhat.com> |
rust: sync: Add Lock::from_raw() for Lock<(), B>
The KMS bindings [1] have a few bindings that require manually acquiring specific locks before calling certain functions. At the moment though, the o
rust: sync: Add Lock::from_raw() for Lock<(), B>
The KMS bindings [1] have a few bindings that require manually acquiring specific locks before calling certain functions. At the moment though, the only way of acquiring these locks in bindings is to simply call the C locking functions directly - since said locks are not initialized on the Rust side of things.
However - if we add `#[repr(C)]` to `Lock<(), B>`, then given `()` is a ZST - `Lock<(), B>` becomes equivalent in data layout to its inner `B::State` type. Since locks in C don't have data explicitly associated with them anyway, we can take advantage of this to add a `Lock::from_raw()` function that can translate a raw pointer to `B::State` into its proper `Lock<(), B>` equivalent. This lets us simply acquire a reference to the lock in question and work with it like it was initialized on the Rust side of things, allowing us to use less unsafe code to implement bindings with lock requirements.
[Boqun: Use "Link:" instead of a URL and format the commit log]
Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://patchwork.freedesktop.org/series/131522/ [1] Signed-off-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20241119231146.2298971-2-lyude@redhat.com
show more ...
|
0c5928de | 23-Oct-2024 |
Yutaro Ohno <yutaro.ono.418@gmail.com> |
rust: block: fix formatting in GenDisk doc
Align bullet points and improve indentation in the `Invariants` section of the `GenDisk` struct documentation for better readability.
[ Yutaro is also wor
rust: block: fix formatting in GenDisk doc
Align bullet points and improve indentation in the `Invariants` section of the `GenDisk` struct documentation for better readability.
[ Yutaro is also working on implementing the lint we suggested to catch this sort of issue in upstream Rust:
https://github.com/rust-lang/rust-clippy/issues/13601 https://github.com/rust-lang/rust-clippy/pull/13711
Thanks a lot! - Miguel ]
Fixes: 3253aba3408a ("rust: block: introduce `kernel::block::mq` module") Signed-off-by: Yutaro Ohno <yutaro.ono.418@gmail.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Acked-by: Andreas Hindborg <a.hindborg@kernel.org> Link: https://lore.kernel.org/r/ZxkcU5yTFCagg_lX@ohnotp Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
517743c4 | 11-Nov-2024 |
Guangbo Cui <2407018371@qq.com> |
rust: alloc: align Debug implementation for Box with Display
Ensure consistency between `Debug` and `Display` for `Box` by updating `Debug` to match the new `Display` style.
Acked-by: Danilo Krummr
rust: alloc: align Debug implementation for Box with Display
Ensure consistency between `Debug` and `Display` for `Box` by updating `Debug` to match the new `Display` style.
Acked-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Guangbo Cui <2407018371@qq.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/tencent_1FC0BC283DA65DD81A8A14EEF25563934E05@qq.com [ Reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
21e08aa5 | 11-Nov-2024 |
Guangbo Cui <2407018371@qq.com> |
rust: alloc: implement Display for Box
Currently `impl Display` is missing for `Box<T, A>`, as a result, things like using `Box<..>` directly as an operand in `pr_info!()` are impossible, which is l
rust: alloc: implement Display for Box
Currently `impl Display` is missing for `Box<T, A>`, as a result, things like using `Box<..>` directly as an operand in `pr_info!()` are impossible, which is less ergonomic compared to `Box` in Rust std.
Therefore add `impl Display` for `Box`.
Acked-by: Danilo Krummrich <dakr@kernel.org> Suggested-by: Boqun Feng <boqun.feng@gmail.com> Link: https://github.com/Rust-for-Linux/linux/issues/1126 Signed-off-by: Guangbo Cui <2407018371@qq.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/tencent_2AD25C6A6898D3A598CBA54BB6AF59BB900A@qq.com [ Reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
2dde1c8b | 07-Nov-2024 |
Tamir Duberstein <tamird@gmail.com> |
rust: sync: document `PhantomData` in `Arc`
Add a comment explaining the relevant semantics of `PhantomData`. This should help future readers who may, as I did, assume that this field is redundant a
rust: sync: document `PhantomData` in `Arc`
Add a comment explaining the relevant semantics of `PhantomData`. This should help future readers who may, as I did, assume that this field is redundant at first glance.
Signed-off-by: Tamir Duberstein <tamird@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20241107-simplify-arc-v2-1-7256e638aac1@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
3f4223c0 | 16-Oct-2024 |
Dirk Behme <dirk.behme@gmail.com> |
rust: workqueue: Enable execution of doctests
Having the Rust doctests enabled these workqueue tests are built but not executed as the final callers of the print_*() functions are missing. Add them.
rust: workqueue: Enable execution of doctests
Having the Rust doctests enabled these workqueue tests are built but not executed as the final callers of the print_*() functions are missing. Add them.
The result is
# rust_doctest_kernel_workqueue_rs_0.location: rust/kernel/workqueue.rs:35 rust_doctests_kernel: The value is: 42 ok 94 rust_doctest_kernel_workqueue_rs_0 # rust_doctest_kernel_workqueue_rs_3.location: rust/kernel/workqueue.rs:78 rust_doctests_kernel: The value is: 24 rust_doctests_kernel: The second value is: 42 ok 97 rust_doctest_kernel_workqueue_rs_3
Without this change the "The value ..." outputs are not there meaning that this test code is not run.
Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Dirk Behme <dirk.behme@gmail.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/cb953202-0dbe-4127-8a8e-6a75258c2116@gmail.com [ Reworded slightly. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
9a02cbc5 | 07-Dec-2024 |
Daniel Sedlak <daniel@sedlak.dev> |
rust: error: modify `from_errno` to use `try_from_errno`
Modify the from_errno function to use try_from_errno to reduce code duplication while still maintaining all existing behavior and error handl
rust: error: modify `from_errno` to use `try_from_errno`
Modify the from_errno function to use try_from_errno to reduce code duplication while still maintaining all existing behavior and error handling and also reduces unsafe code.
Link: https://github.com/Rust-for-Linux/linux/issues/1125 Suggested-by: Miguel Ojeda <ojeda@kernel.org> Co-developed-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com> Signed-off-by: Guilherme Augusto Martins da Silva <guilhermev2huehue@gmail.com> Signed-off-by: Daniel Sedlak <daniel@sedlak.dev> Reviewed-by: Fiona Behrens <me@kloenk.dev> Link: https://lore.kernel.org/r/20241207112445.55502-1-daniel@sedlak.dev Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
9b98be76 | 13-Sep-2024 |
Gary Guo <gary@garyguo.net> |
rust: cleanup unnecessary casts
With `long` mapped to `isize`, `size_t`/`__kernel_size_t` mapped to `usize` and `char` mapped to `u8`, many of the existing casts are no longer necessary.
Signed-off
rust: cleanup unnecessary casts
With `long` mapped to `isize`, `size_t`/`__kernel_size_t` mapped to `usize` and `char` mapped to `u8`, many of the existing casts are no longer necessary.
Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20240913213041.395655-6-gary@garyguo.net [ Moved `uaccess` changes to the previous commit, since they were irrefutable patterns that Rust >= 1.82.0 warns about. Removed a couple casts that now use `c""` literals. Rebased on top of `rust-next`. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
1bae8729 | 13-Sep-2024 |
Gary Guo <gary@garyguo.net> |
rust: map `long` to `isize` and `char` to `u8`
The following FFI types are replaced compared to `core::ffi`:
1. `char` type is now always mapped to `u8`, since kernel uses `-funsigned-char` on t
rust: map `long` to `isize` and `char` to `u8`
The following FFI types are replaced compared to `core::ffi`:
1. `char` type is now always mapped to `u8`, since kernel uses `-funsigned-char` on the C code. `core::ffi` maps it to platform default ABI, which can be either signed or unsigned.
2. `long` is now always mapped to `isize`. It's very common in the kernel to use `long` to represent a pointer-sized integer, and in fact `intptr_t` is a typedef of `long` in the kernel. Enforce this mapping rather than mapping to `i32/i64` depending on platform can save us a lot of unnecessary casts.
Signed-off-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20240913213041.395655-5-gary@garyguo.net [ Moved `uaccess` changes from the next commit, since they were irrefutable patterns that Rust >= 1.82.0 warns about. Reworded slightly and reformatted a few documentation comments. Rebased on top of `rust-next`. Added the removal of two casts to avoid Clippy warnings. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
5bcc8bfe | 03-Dec-2024 |
Alice Ryhl <aliceryhl@google.com> |
rust: miscdevice: add fops->show_fdinfo() hook
File descriptors should generally provide a fops->show_fdinfo() hook for debugging purposes. Thus, add such a hook to the miscdevice abstractions.
Sig
rust: miscdevice: add fops->show_fdinfo() hook
File descriptors should generally provide a fops->show_fdinfo() hook for debugging purposes. Thus, add such a hook to the miscdevice abstractions.
Signed-off-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20241203-miscdevice-showfdinfo-v1-1-7e990732d430@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
284ae0be | 10-Dec-2024 |
Lee Jones <lee@kernel.org> |
rust: miscdevice: Provide accessor to pull out miscdevice::this_device
There are situations where a pointer to a `struct device` will become necessary (e.g. for calling into dev_*() functions). Thi
rust: miscdevice: Provide accessor to pull out miscdevice::this_device
There are situations where a pointer to a `struct device` will become necessary (e.g. for calling into dev_*() functions). This accessor allows callers to pull this out from the `struct miscdevice`.
Signed-off-by: Lee Jones <lee@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Tested-by: Lee Jones <lee@kernel.org> Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20241210-miscdevice-file-param-v3-3-b2a79b666dc5@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
88441d5c | 10-Dec-2024 |
Alice Ryhl <aliceryhl@google.com> |
rust: miscdevice: access the `struct miscdevice` from fops->open()
Providing access to the underlying `struct miscdevice` is useful for various reasons. For example, this allows you access the miscd
rust: miscdevice: access the `struct miscdevice` from fops->open()
Providing access to the underlying `struct miscdevice` is useful for various reasons. For example, this allows you access the miscdevice's internal `struct device` for use with the `dev_*` printing macros.
Note that since the underlying `struct miscdevice` could get freed at any point after the fops->open() call (if misc_deregister is called), only the open call is given access to it. To use `dev_*` printing macros from other fops hooks, take a refcount on `miscdevice->this_device` to keep it alive. See the linked thread for further discussion on the lifetime of `struct miscdevice`.
Link: https://lore.kernel.org/r/2024120951-botanist-exhale-4845@gregkh Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Lee Jones <lee@kernel.org> Tested-by: Lee Jones <lee@kernel.org> Reviewed-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20241210-miscdevice-file-param-v3-2-b2a79b666dc5@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|