| 9b90864b | 19-Dec-2024 |
Danilo Krummrich <[email protected]> |
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 <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Co-developed-by: Gary Guo <[email protected]> Signed-off-by: Gary Guo <[email protected]> Co-developed-by: Fabien Parent <[email protected]> Signed-off-by: Fabien Parent <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Tested-by: Dirk Behme <[email protected]> Tested-by: Fabien Parent <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| ea7e1828 | 19-Dec-2024 |
Danilo Krummrich <[email protected]> |
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 <[email protected]> Signed-off-by: Wedson Almeida Filho <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Tested-by: Dirk Behme <[email protected]> Tested-by: Fabien Parent <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| a790265c | 19-Dec-2024 |
Danilo Krummrich <[email protected]> |
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 <[email protected]> Tested-by: Dirk Behme <[email protected]> Tested-by: Fabien Parent <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| fbd7a5a0 | 25-Nov-2024 |
Lyude Paul <[email protected]> |
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 <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| daa03fe5 | 19-Nov-2024 |
Lyude Paul <[email protected]> |
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 <[email protected]> Reviewed-by: Filipe Xavier <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| 15abc880 | 19-Nov-2024 |
Lyude Paul <[email protected]> |
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 <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://patchwork.freedesktop.org/series/131522/ [1] Signed-off-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
show more ...
|
| 0c5928de | 23-Oct-2024 |
Yutaro Ohno <[email protected]> |
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 <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Acked-by: Andreas Hindborg <[email protected]> Link: https://lore.kernel.org/r/ZxkcU5yTFCagg_lX@ohnotp Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 21e08aa5 | 11-Nov-2024 |
Guangbo Cui <[email protected]> |
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 <[email protected]> Suggested-by: Boqun Feng <[email protected]> Link: https://github.com/Rust-for-Linux/linux/issues/1126 Signed-off-by: Guangbo Cui <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 2dde1c8b | 07-Nov-2024 |
Tamir Duberstein <[email protected]> |
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 <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 3f4223c0 | 16-Oct-2024 |
Dirk Behme <[email protected]> |
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 <[email protected]> Signed-off-by: Dirk Behme <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded slightly. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| 9b98be76 | 13-Sep-2024 |
Gary Guo <[email protected]> |
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 <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ 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 <[email protected]>
show more ...
|
| 1bae8729 | 13-Sep-2024 |
Gary Guo <[email protected]> |
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 <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ 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 <[email protected]>
show more ...
|
| 88441d5c | 10-Dec-2024 |
Alice Ryhl <[email protected]> |
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 <[email protected]> Reviewed-by: Lee Jones <[email protected]> Tested-by: Lee Jones <[email protected]> Reviewed-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|