testing-6.12
16 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
12dfc1d9cb |
UPSTREAM: rust: miscdevice: add mmap support
Add the ability to write a file_operations->mmap hook in Rust when using the miscdevice abstraction. The `vma` argument to the `mmap` hook uses the `VmaNew` type from the previous commit; this type provides the correct set of operations for a file_operations->mmap hook. Link: https://lkml.kernel.org/r/20250408-vma-v16-7-d8b446e885d9@google.com Signed-off-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Gary Guo <gary@garyguo.net> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Balbir Singh <balbirs@nvidia.com> Cc: Benno Lossin <benno.lossin@proton.me> Cc: Björn Roy Baron <bjorn3_gh@protonmail.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Jann Horn <jannh@google.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Trevor Gross <tmgross@umich.edu> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Bug: 429146594 (cherry picked from commit f8c78198816f04619da6eebfc5b67741bff56325) Change-Id: Ib8965aa5d000da6a97650eb04be61df3c21bd85a Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
2ef6dbc73e |
BACKPORT: 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 <chrisi.schrefl@gmail.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250227-miscdevice-fops-change-v1-1-c9e9b75d67eb@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Bug: 429146594 [ aliceryhl: also adjust llseek and similar to new style ] (cherry picked from commit 74fc34937d72d04e89e4f75ea66147cdc9b785f5) Change-Id: Ie87c5015d483a4c5a27ab17ae8a836a8956d1092 Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
6de3ace5b5 |
Revert "FROMLIST: rust: miscdevice: add mmap support"
This reverts commit
|
||
|
|
3744083cdb |
ANDROID: rust: miscdevice: fix formatting
An import was removed from these imports during an LTS merge, which
means that rustfmt now prefers a different formatting of these imports.
Fixes:
|
||
|
|
b3fb80bdc6 |
Merge 6.12.19 into android16-6.12
GKI (arm64) relevant 48 out of 271 changes, affecting 92 files +576/-223 |
||
|
|
5e60c48050 |
ANDROID: ashmem_rust: add toggle for ASHMEM_UNPIN
Add basic functionality for toggling the behavior of the ashmem driver's unpin call. Add a miscdevice that can be used to turn the shrinker on and off. Bug: 370906207 Change-Id: Ic0d1c596b7411dd338ad5c49b3d1ae9e50482c2d Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
977fca6555 |
ANDROID: rust: miscdevice: add llseek/read_iter
Support for these methods has not been sent upstream. Bug: 370906207 Change-Id: Ibdcfbaf36a6b05a82ed57be5b897e723f6e7201a Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
88a4dfa30b |
FROMLIST: rust: miscdevice: add mmap support
Add the ability to write a file_operations->mmap hook in Rust when using the miscdevice abstraction. The `vma` argument to the `mmap` hook uses the `VmAreaNew` type from the previous commit; this type provides the correct set of operations for a file_operations->mmap hook. Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> (for mm bits) Change-Id: I00a0769625bd9e6cbb2dc9613cda8ae371a3ac3b Signed-off-by: Alice Ryhl <aliceryhl@google.com> Bug: 370906207 Link: https://lore.kernel.org/all/20250115-vma-v12-7-375099ae017a@google.com/ Change-Id: I5f4441b60673fdc08190eaf566099dcb88905bb9 Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
78fb59f626 |
FROMGIT: 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 <sfr@canb.auug.org.au> Link: https://lore.kernel.org/r/20250110162828.38614c1b@canb.auug.org.au Link: https://lore.kernel.org/all/20241123222849.350287-2-ojeda@kernel.org/ [1] Signed-off-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20250110101459.536726-1-aliceryhl@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Bug: 370906207 (cherry picked from commit bf2aa7df2687a24ebb52cec4a24443121ac3126d git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-next) Change-Id: If85e78328a94588dd26349215066d955eebaddb0 Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
1799540eeb |
FROMGIT: 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> Bug: 370906207 (cherry picked from commit 5bcc8bfe841b29f7d62f4bb7738bb085ecc51aad git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-next) Change-Id: I8a8621b6865e91d295c624a939f0dd7dab5bdb2c Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
86f90323ec |
FROMGIT: 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> Bug: 370906207 (cherry picked from commit 284ae0be4dcafff0a154c1e69e7430c144a7ddc2 git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-next) Change-Id: I80c53485d97982a7e92a5d9de0e59c468a791daa Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
148b927a08 |
FROMGIT: 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> Bug: 370906207 (cherry picked from commit 88441d5c6d17211bcbd5b429205b09c25598f756 git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-next) Change-Id: I287b4c2d5533c297a40198d1ef2c89b71ba4eef8 Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
ac0aa4cf88 |
FROMGIT: 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 <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-1-b2a79b666dc5@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Bug: 370906207 (cherry picked from commit 0d8a7c7bf47aa1002e0df792cb1d0652bc824cba git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-next) Change-Id: Ie1b13c6dfaf6865fd27cd47b7b1ff53afe900fce Signed-off-by: Alice Ryhl <aliceryhl@google.com> |
||
|
|
e836d2367c |
UPSTREAM: 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 <ojeda@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Closes: https://lore.kernel.org/rust-for-linux/CANiq72kOs6vPDUzZttQNqePFHphCQ30iVmZ5MO7eCJfPG==Vzg@mail.gmail.com/
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20241022-miscdevice-unsafe-warn-fix-v1-1-a78fde1740d6@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 370906207
(cherry picked from commit bd5ee6bcc51b617d28e54069fef818751763962b)
Change-Id: I391069ccc830a24a862daa18e9dc7625c2073aec
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
|
||
|
|
6a5e0ee38e |
UPSTREAM: 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 <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20241015-miscdevice-cint-cast-v1-1-fcf4b75700ac@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 370906207
(cherry picked from commit ccb22ca2805226bbcacdff0fc4b047d947f7948e)
Change-Id: I6fe89fe2dc16fc598d2d9137f691f362dde7bf4f
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
|
||
|
|
401178c45f |
UPSTREAM: 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 <aliceryhl@google.com> Link: https://lore.kernel.org/rust-for-linux/20240328195457.225001-1-wedsonaf@gmail.com/ Link: https://lore.kernel.org/r/20241001-b4-miscdevice-v2-2-330d760041fa@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Bug: 370906207 Change-Id: I556c00141d3ad749aac8001f493e927c4a31e304 (cherry picked from commit f893691e742688ae21ad597c5bba13bef54706cd) Signed-off-by: Alice Ryhl <aliceryhl@google.com> |