|
Revision tags: v6.15, v6.15-rc7, v6.15-rc6, v6.15-rc5, v6.15-rc4, v6.15-rc3, v6.15-rc2, v6.15-rc1, v6.14, v6.14-rc7, v6.14-rc6, v6.14-rc5 |
|
| #
74fc3493 |
| 27-Feb-2025 |
Alice Ryhl <[email protected]> |
rust: miscdevice: change how f_ops vtable is constructed
I was helping someone with writing a new Rust abstraction, and we were using the miscdevice abstraction as an example. While doing this, it b
rust: miscdevice: change how f_ops vtable is constructed
I was helping someone with writing a new Rust abstraction, and we were using the miscdevice abstraction as an example. While doing this, it became clear to me that the way I implemented the f_ops vtable is confusing to new Rust users, and that the approach used by the block abstractions is less confusing.
Thus, update the miscdevice abstractions to use the same approach as rust/kernel/block/mq/operations.rs.
Sorry about the large diff. This changes the indentation of a large amount of code.
Reviewed-by: Christian Schrefl <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
|
Revision tags: v6.14-rc4, v6.14-rc3, v6.14-rc2, v6.14-rc1, v6.13, v6.13-rc7, v6.13-rc6, v6.13-rc5, v6.13-rc4, v6.13-rc3, v6.13-rc2, v6.13-rc1 |
|
| #
14686571 |
| 20-Nov-2024 |
Tamir Duberstein <[email protected]> |
rust: kernel: change `ForeignOwnable` pointer to mut
It is slightly more convenient to operate on mut pointers, and this also properly conveys the desired ownership semantics of the trait.
Reviewed
rust: kernel: change `ForeignOwnable` pointer to mut
It is slightly more convenient to operate on mut pointers, and this also properly conveys the desired ownership semantics of the trait.
Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Signed-off-by: Tamir Duberstein <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded title slightly. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| #
bf2aa7df |
| 10-Jan-2025 |
Alice Ryhl <[email protected]> |
miscdevice: rust: use build_error! macro instead of function
The function called build_error is an implementation detail of the macro of the same name. Thus, update miscdevice to use the macro rathe
miscdevice: rust: use build_error! macro instead of function
The function called build_error is an implementation detail of the macro of the same name. Thus, update miscdevice to use the macro rather than the function. See [1] for more information on this.
These use the macro with the kernel:: prefix as it has not yet been added to the prelude.
Reported-by: Stephen Rothwell <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/all/[email protected]/ [1] Signed-off-by: Alice Ryhl <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| #
4401565f |
| 23-Nov-2024 |
Miguel Ojeda <[email protected]> |
rust: add `build_error!` to the prelude
The sibling `build_assert!` is already in the prelude, it makes sense that a "core"/"language" facility like this is part of the prelude and users should not
rust: add `build_error!` to the prelude
The sibling `build_assert!` is already in the prelude, it makes sense that a "core"/"language" facility like this is part of the prelude and users should not be defining their own one (thus there should be no risk of future name collisions and we would want to be aware of them anyway).
Thus add `build_error!` into the prelude.
Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Applied the change to the new miscdevice cases. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| #
15f2f931 |
| 23-Nov-2024 |
Miguel Ojeda <[email protected]> |
rust: use the `build_error!` macro, not the hidden function
Code and some examples were using the function, rather than the macro. The macro is what is documented.
Thus move users to the macro.
Re
rust: use the `build_error!` macro, not the hidden function
Code and some examples were using the function, rather than the macro. The macro is what is documented.
Thus move users to the macro.
Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Applied the change to the new miscdevice cases. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
|
Revision tags: v6.12, v6.12-rc7, v6.12-rc6, v6.12-rc5, v6.12-rc4, v6.12-rc3, v6.12-rc2, v6.12-rc1, v6.11 |
|
| #
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 ...
|
| #
27c7518e |
| 15-Dec-2024 |
Miguel Ojeda <[email protected]> |
rust: finish using custom FFI integer types
In the last kernel cycle we migrated most of the `core::ffi` cases in commit d072acda4862 ("rust: use custom FFI integer types"):
Currently FFI integ
rust: finish using custom FFI integer types
In the last kernel cycle we migrated most of the `core::ffi` cases in commit d072acda4862 ("rust: use custom FFI integer types"):
Currently FFI integer types are defined in libcore. This commit creates the `ffi` crate and asks bindgen to use that crate for FFI integer types instead of `core::ffi`.
This commit is preparatory and no type changes are made in this commit yet.
Finish now the few remaining/new cases so that we perform the actual remapping in the next commit as planned.
Acked-by: Jocelyn Falempe <[email protected]> # drm Link: https://lore.kernel.org/rust-for-linux/CANiq72m_rg42SvZK=bF2f0yEoBLVA33UBhiAsv8THhVu=G2dPA@mail.gmail.com/ Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Miguel Ojeda <[email protected]>
show more ...
|
| #
5bcc8bfe |
| 03-Dec-2024 |
Alice Ryhl <[email protected]> |
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| #
284ae0be |
| 10-Dec-2024 |
Lee Jones <[email protected]> |
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 <[email protected]> Signed-off-by: Alice Ryhl <[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 ...
|
| #
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 ...
|
| #
0d8a7c7b |
| 10-Dec-2024 |
Alice Ryhl <[email protected]> |
rust: miscdevice: access file in fops
This allows fops to access information about the underlying struct file for the miscdevice. For example, the Binder driver needs to inspect the O_NONBLOCK flag
rust: miscdevice: access file in fops
This allows fops to access information about the underlying struct file for the miscdevice. For example, the Binder driver needs to inspect the O_NONBLOCK flag inside the fops->ioctl() hook.
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 ...
|
| #
bd5ee6bc |
| 22-Oct-2024 |
Alice Ryhl <[email protected]> |
rust: miscdevice: add missing safety comments
This fixes the following four warnings:
warning: unsafe block missing a safety comment --> /home/aliceryhl/rust-for-linux/rust/kernel/miscdevice.r
rust: miscdevice: add missing safety comments
This fixes the following four warnings:
warning: unsafe block missing a safety comment --> /home/aliceryhl/rust-for-linux/rust/kernel/miscdevice.rs:168:15 | 168 | ..unsafe { MaybeUninit::zeroed().assume_init() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider adding a safety comment on the preceding line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks = note: requested on the command line with `-W clippy::undocumented-unsafe-blocks`
warning: unsafe function's docs are missing a `# Safety` section --> /home/aliceryhl/rust-for-linux/rust/kernel/miscdevice.rs:175:1 | 175 | / unsafe extern "C" fn fops_open<T: MiscDevice>( 176 | | inode: *mut bindings::inode, 177 | | file: *mut bindings::file, 178 | | ) -> c_int { | |__________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc = note: `-W clippy::missing-safety-doc` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::missing_safety_doc)]`
warning: unsafe function's docs are missing a `# Safety` section --> /home/aliceryhl/rust-for-linux/rust/kernel/miscdevice.rs:196:1 | 196 | / unsafe extern "C" fn fops_release<T: MiscDevice>( 197 | | _inode: *mut bindings::inode, 198 | | file: *mut bindings::file, 199 | | ) -> c_int { | |__________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
warning: unsafe function's docs are missing a `# Safety` section --> /home/aliceryhl/rust-for-linux/rust/kernel/miscdevice.rs:210:1 | 210 | / unsafe extern "C" fn fops_ioctl<T: MiscDevice>( 211 | | file: *mut bindings::file, 212 | | cmd: c_uint, 213 | | arg: c_ulong, 214 | | ) -> c_long { | |___________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
Note that these warnings are currently not enabled in the build, but rust-next contains a commit that will enable them, so we should fix them.
Reported-by: Miguel Ojeda <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Closes: https://lore.kernel.org/rust-for-linux/CANiq72kOs6vPDUzZttQNqePFHphCQ30iVmZ5MO7eCJfPG==Vzg@mail.gmail.com/ Acked-by: Miguel Ojeda <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| #
ccb22ca2 |
| 15-Oct-2024 |
Alice Ryhl <[email protected]> |
rust: miscdevice: fix warning on c_uint to u32 cast
When building miscdevice with clippy warnings, the following warning is emitted:
warning: casting to the same type is unnecessary (`u32` -> `u32
rust: miscdevice: fix warning on c_uint to u32 cast
When building miscdevice with clippy warnings, the following warning is emitted:
warning: casting to the same type is unnecessary (`u32` -> `u32`) --> /home/aliceryhl/rust-for-linux/rust/kernel/miscdevice.rs:220:28 | 220 | match T::ioctl(device, cmd as u32, arg as usize) { | ^^^^^^^^^^ help: try: `cmd` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `-W clippy::unnecessary-cast` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::unnecessary_cast)]`
Thus, fix it.
Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|
| #
f893691e |
| 01-Oct-2024 |
Alice Ryhl <[email protected]> |
rust: miscdevice: add base miscdevice abstraction
Provide a `MiscDevice` trait that lets you specify the file operations that you wish to provide for your misc device. For now, only three file opera
rust: miscdevice: add base miscdevice abstraction
Provide a `MiscDevice` trait that lets you specify the file operations that you wish to provide for your misc device. For now, only three file operations are provided: open, close, ioctl.
These abstractions only support MISC_DYNAMIC_MINOR. This enforces that new miscdevices should not hard-code a minor number.
When implementing ioctl, the Result type is used. This means that you can choose to return either of: * An integer of type isize. * An errno using the kernel::error::Error type. When returning an isize, the integer is returned verbatim. It's mainly intended for returning positive integers to userspace. However, it is technically possible to return errors via the isize return value too.
To avoid having a dependency on files, this patch does not provide the file operations callbacks a pointer to the file. This means that they cannot check file properties such as O_NONBLOCK (which Binder needs). Support for that can be added as a follow-up.
To avoid having a dependency on vma, this patch does not provide any way to implement mmap (which Binder needs). Support for that can be added as a follow-up.
Rust Binder will use these abstractions to create the /dev/binder file when binderfs is disabled.
Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/rust-for-linux/[email protected]/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
show more ...
|