linux/rust/kernel
Danilo Krummrich f301cb978c rust: devres: implement Devres::access()
Implement a direct accessor for the data stored within the Devres for
cases where we can prove that we own a reference to a Device<Bound>
(i.e. a bound device) of the same device that was used to create the
corresponding Devres container.

Usually, when accessing the data stored within a Devres container, it is
not clear whether the data has been revoked already due to the device
being unbound and, hence, we have to try whether the access is possible
and subsequently keep holding the RCU read lock for the duration of the
access.

However, when we can prove that we hold a reference to Device<Bound>
matching the device the Devres container has been created with, we can
guarantee that the device is not unbound for the duration of the
lifetime of the Device<Bound> reference and, hence, it is not possible
for the data within the Devres container to be revoked.

Therefore, in this case, we can bypass the atomic check and the RCU read
lock, which is a great optimization and simplification for drivers.

Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
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-3-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-05-04 17:54:04 +02:00
..
alloc Rust changes for v6.15 2025-03-30 17:03:26 -07:00
block rust: block: refactor to use &raw mut 2025-03-23 20:39:37 +01:00
drm rust: drm: gem: Add GEM object abstraction 2025-04-28 10:08:23 +02:00
fs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
list rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00
net rust: module: introduce authors key 2025-03-10 15:12:17 +01:00
sync Rust changes for v6.15 2025-03-30 17:03:26 -07:00
time Rust hrtimer API for v6.15 2025-03-25 23:41:14 +01:00
.gitignore rust: jump_label: skip formatting generated file 2024-11-20 13:32:42 -05:00
alloc.rs rust: use derive(CoercePointee) on rustc >= 1.84.0 2025-01-13 23:45:30 +01:00
auxiliary.rs rust: auxiliary: add auxiliary registration 2025-04-19 10:54:46 +02:00
block.rs rust: block: introduce kernel::block::mq module 2024-06-14 07:45:04 -06:00
build_assert.rs rust: add build_error! to the prelude 2025-01-10 00:19:09 +01:00
cred.rs cred,rust: mark Credential methods inline 2025-03-04 17:07:49 -05:00
device.rs rust: device: conditionally expect dead_code for parent() 2025-04-29 23:45:54 +02:00
device_id.rs rust: implement IdArray, IdTable and RawDeviceId 2024-12-20 17:19:25 +01:00
devres.rs rust: devres: implement Devres::access() 2025-05-04 17:54:04 +02:00
dma.rs rust: dma: require a bound device 2025-04-17 15:21:54 +02:00
driver.rs rust: make pin-init its own crate 2025-03-16 21:59:19 +01:00
error.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
faux.rs rust/kernel/faux: mark Registration methods inline 2025-03-11 10:42:23 +01:00
firmware.rs rust: firmware: add module_firmware! macro 2025-03-09 19:23:31 +01:00
fs.rs rust: file: add Rust abstraction for struct file 2024-09-30 13:02:28 +02:00
generated_arch_static_branch_asm.rs.S rust: jump_label: skip formatting generated file 2024-11-20 13:32:42 -05:00
init.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
io.rs rust: io: rename io::Io accessors 2025-02-22 15:44:19 +01:00
ioctl.rs rust: start using the #[expect(...)] attribute 2024-10-07 21:39:57 +02:00
jump_label.rs rust: jump_label: skip formatting generated file 2024-11-20 13:32:42 -05:00
kunit.rs rust: kunit: allow to know if we are in a test 2025-03-20 12:27:05 +01:00
lib.rs rust: drm: ioctl: Add DRM ioctl abstraction 2025-04-24 13:50:05 +02:00
list.rs rust: make pin-init its own crate 2025-03-16 21:59:19 +01:00
miscdevice.rs rust: miscdevice: change how f_ops vtable is constructed 2025-03-07 18:20:36 +01:00
net.rs rust: core abstractions for network PHY drivers 2023-12-15 09:35:50 +00:00
of.rs rust: of: add of::DeviceId abstraction 2024-12-20 17:21:04 +01:00
page.rs rust: page: remove unnecessary helper function from doctest 2025-01-13 23:44:55 +01:00
pci.rs rust: pci: impl TryFrom<&Device> for &pci::Device 2025-04-19 10:20:16 +02:00
pid_namespace.rs rust: add PidNamespace 2024-10-08 15:44:36 +02:00
platform.rs rust: platform: impl TryFrom<&Device> for &platform::Device 2025-04-19 10:20:25 +02:00
prelude.rs rust: make pin-init its own crate 2025-03-16 21:59:19 +01:00
print.rs print: use new #[export] macro for rust_fmt_argument 2025-03-09 20:52:46 +01:00
rbtree.rs rust: rbtree: fix comments referring to Box instead of KBox 2025-03-23 19:43:02 +01:00
revocable.rs rust: revocable: implement Revocable::access() 2025-05-04 17:43:45 +02:00
security.rs lsm,rust: reword "destroy" -> "release" in SecurityCtx 2025-03-04 15:44:46 -05:00
seq_file.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
sizes.rs rust: sizes: add commonly used constants 2024-08-30 10:27:34 +01:00
static_assert.rs rust: static_assert: add static_assert! macro 2022-12-04 01:59:16 +01:00
std_vendor.rs rust: std_vendor: update dbg macro from Rust upstream 2024-10-10 00:33:42 +02:00
str.rs rust: str: implement strip_prefix for BStr 2025-03-20 21:44:47 +01:00
sync.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
task.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
time.rs rust: hrtimer: add clocksource selection through ClockId 2025-03-22 12:08:54 +01:00
tracepoint.rs rust: add tracepoint support 2024-11-04 16:21:44 -05:00
transmute.rs rust: kernel: move FromBytes and AsBytes traits to a new transmute module 2024-10-10 00:33:42 +02:00
types.rs rust: types: add Opaque::zeroed 2025-04-19 10:41:28 +02:00
uaccess.rs rust: uaccess: name the correct function 2025-03-23 19:45:03 +01:00
workqueue.rs Locking changes for v6.15: 2025-03-24 20:55:03 -07:00