b75a99e1 | 28-Apr-2025 |
Danilo Krummrich <dakr@kernel.org> |
samples: rust: pci: take advantage of Devres::access()
For the I/O operations executed from the probe() method, take advantage of Devres::access(), avoiding the atomic check and RCU read lock requir
samples: rust: pci: take advantage of Devres::access()
For the I/O operations executed from the probe() method, take advantage of Devres::access(), avoiding the atomic check and RCU read lock required otherwise entirely.
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Acked-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Link: https://lore.kernel.org/r/20250428140137.468709-4-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
0c848b3a | 11-Apr-2025 |
Alexandre Courbot <acourbot@nvidia.com> |
samples: rust: convert PCI rust sample driver to use try_access_with()
This method limits the scope of the revocable guard and is considered safer to use for most cases, so let's showcase it here.
samples: rust: convert PCI rust sample driver to use try_access_with()
This method limits the scope of the revocable guard and is considered safer to use for most cases, so let's showcase it here.
Reviewed-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Acked-by: Miguel Ojeda <ojeda@kernel.org> Link: https://lore.kernel.org/r/20250411-try_with-v4-2-f470ac79e2e2@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
show more ...
|
4d320e30 | 14-Mar-2025 |
Danilo Krummrich <dakr@kernel.org> |
rust: platform: fix unrestricted &mut platform::Device
As by now, platform::Device is implemented as:
#[derive(Clone)] pub struct Device(ARef<device::Device>);
This may be convenient, but has th
rust: platform: fix unrestricted &mut platform::Device
As by now, platform::Device is implemented as:
#[derive(Clone)] pub struct Device(ARef<device::Device>);
This may be convenient, but has the implication that drivers can call device methods that require a mutable reference concurrently at any point of time.
Instead define platform::Device as
pub struct Device<Ctx: DeviceContext = Normal>( Opaque<bindings::platform_dev>, PhantomData<Ctx>, );
and manually implement the AlwaysRefCounted trait.
With this we can implement methods that should only be called from bus callbacks (such as probe()) for platform::Device<Core>. Consequently, we make this type accessible in bus callbacks only.
Arbitrary references taken by the driver are still of type ARef<platform::Device> and hence don't provide access to methods that are reserved for bus callbacks.
Fixes: 683a63befc73 ("rust: platform: add basic platform device / driver abstractions") Reviewed-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Acked-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20250314160932.100165-5-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
95cb0cb5 | 27-Feb-2025 |
Lyude Paul <lyude@redhat.com> |
rust/faux: Add missing parent argument to Registration::new()
A little late in the review of the faux device interface, we added the ability to specify a parent device when creating new faux devices
rust/faux: Add missing parent argument to Registration::new()
A little late in the review of the faux device interface, we added the ability to specify a parent device when creating new faux devices - but this never got ported over to the rust bindings. So, let's add the missing argument now so we don't have to convert other users later down the line.
Signed-off-by: Lyude Paul <lyude@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250227193522.198344-1-lyude@redhat.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
47cb6bf7 | 03-Dec-2024 |
Xiangfei Ding <dingxiangfei2009@gmail.com> |
rust: use derive(CoercePointee) on rustc >= 1.84.0
The `kernel` crate relies on both `coerce_unsized` and `dispatch_from_dyn` unstable features.
Alice Ryhl has proposed [1] the introduction of the
rust: use derive(CoercePointee) on rustc >= 1.84.0
The `kernel` crate relies on both `coerce_unsized` and `dispatch_from_dyn` unstable features.
Alice Ryhl has proposed [1] the introduction of the unstable macro `SmartPointer` to reduce such dependence, along with a RFC patch [2]. Since Rust 1.81.0 this macro, later renamed to `CoercePointee` in Rust 1.84.0 [3], has been fully implemented with the naming discussion resolved.
This feature is now on track to stabilization in the language. In order to do so, we shall start using this macro in the `kernel` crate to prove the functionality and utility of the macro as the justification of its stabilization.
This patch makes this switch in such a way that the crate remains backward compatible with older Rust compiler versions, via the new Kconfig option `RUSTC_HAS_COERCE_POINTEE`.
A minimal demonstration example is added to the `samples/rust/rust_print_main.rs` module.
Link: https://rust-lang.github.io/rfcs/3621-derive-smart-pointer.html [1] Link: https://lore.kernel.org/all/20240823-derive-smart-pointer-v1-1-53769cd37239@google.com/ [2] Link: https://github.com/rust-lang/rust/pull/131284 [3] Signed-off-by: Xiangfei Ding <dingxiangfei2009@gmail.com> Reviewed-by: Fiona Behrens <me@kloenk.dev> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20241203205050.679106-2-dingxiangfei2009@gmail.com [ Fixed version to 1.84. Renamed option to `RUSTC_HAS_COERCE_POINTEE` to match `CC_HAS_*` ones. Moved up new config option, closer to the `CC_HAS_*` ones. Simplified Kconfig line. Fixed typos and slightly reworded example and commit. Added Link to PR. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
8d9b095b | 13-Dec-2024 |
Lee Jones <lee@kernel.org> |
samples: rust_misc_device: Provide an example C program to exercise functionality
Here is the expected output (manually spliced together):
USERSPACE: Opening /dev/rust-misc-device for reading and w
samples: rust_misc_device: Provide an example C program to exercise functionality
Here is the expected output (manually spliced together):
USERSPACE: Opening /dev/rust-misc-device for reading and writing KERNEL: rust_misc_device: Opening Rust Misc Device Sample USERSPACE: Calling Hello KERNEL: rust_misc_device: IOCTLing Rust Misc Device Sample KERNEL: rust_misc_device: -> Hello from the Rust Misc Device USERSPACE: Fetching initial value KERNEL: rust_misc_device: IOCTLing Rust Misc Device Sample KERNEL: rust_misc_device: -> Copying data to userspace (value: 0) USERSPACE: Submitting new value (1) KERNEL: rust_misc_device: IOCTLing Rust Misc Device Sample KERNEL: rust_misc_device: -> Copying data from userspace (value: 1) USERSPACE: Fetching new value KERNEL: rust_misc_device: IOCTLing Rust Misc Device Sample KERNEL: rust_misc_device: -> Copying data to userspace (value: 1) USERSPACE: Attempting to call in to an non-existent IOCTL KERNEL: rust_misc_device: IOCTLing Rust Misc Device Sample KERNEL: rust_misc_device: -> IOCTL not recognised: 20992 USERSPACE: ioctl: Succeeded to fail - this was expected: Inappropriate ioctl for device USERSPACE: Closing /dev/rust-misc-device KERNEL: rust_misc_device: Exiting the Rust Misc Device Sample USERSPACE: Success
Signed-off-by: Lee Jones <lee@kernel.org> Link: https://lore.kernel.org/r/20241213134715.601415-6-lee@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|
42523ceb | 13-Dec-2024 |
Lee Jones <lee@kernel.org> |
samples: rust_misc_device: Demonstrate additional get/set value functionality
Expand the complexity of the sample driver by providing the ability to get and set an integer. The value is protected b
samples: rust_misc_device: Demonstrate additional get/set value functionality
Expand the complexity of the sample driver by providing the ability to get and set an integer. The value is protected by a mutex.
Signed-off-by: Lee Jones <lee@kernel.org> Link: https://lore.kernel.org/r/20241213134715.601415-4-lee@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
show more ...
|