RFC rust: sync: create lock class using `#[track_caller]`
Get series with b4
b4 am [email protected] change-id 20260702-rust_lockdep-6220af6a6ba9Versions newest first
- v1 RFC Latest2 patches 10 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | rust: sync: introduce a way to create lock class from callerrust/ rust/ rust/ +1 more | +46 | 2 replies | |
| 2/2 | lockdep: delegate Rust lock class printing to Rust codekernel/ kernel/ rust/ +3 more | +49 | 1 reply |
Reviews trailers per patch
All 2 patches have a Reviewed-by or Acked-by.
| Patch | Lyude Paul |
|---|---|
| 1/2 | R-b |
| 2/2 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH RFC 0/2] rust: sync: create lock class using `#[track_caller]`
Currently we're adding more and more macros so that lock classes can be created. The only purpose served by these macros are to create names and static lock classes so they can be tracked by lockdep.
I've come up with an approach that uses Location::caller and Rust's #[track_caller] feature for this purpose instead. Location::caller() will return a &'static Location<'static> that lives in .rodata. As only addresses matter for static objects, the address of the Location themselves could be used for lock classes. The Location is of 2 * usize + 8 bytes, so they could host 2 lock class keys, so DelayedWork which needs two lock classes can also use this mechanism.
The Location::caller could also be used to provide the name; currently, optional_name just uses file_name:line_number as the name, and this information is available in Location. However, Location encodes them using file name as a C string plus two u32's for line and column number, so it cannot provide a single name. I came up with an alternative method, which is to use a special string, which lockdep can recognize and delegate back to Rust to print it.
---
Gary Guo (2):
rust: sync: introduce a way to create lock class from caller
lockdep: delegate Rust lock class printing to Rust code
kernel/locking/lockdep.c | 7 ++++- kernel/locking/lockdep_internals.h | 3 ++ rust/kernel/sync.rs | 61 +++++++++++++++++++++++++++++++++++--- rust/kernel/sync/lock.rs | 21 +++++++++++-- rust/kernel/sync/lock/mutex.rs | 11 ++++--- rust/kernel/sync/lock/spinlock.rs | 11 ++++--- 6 files changed, 95 insertions(+), 19 deletions(-)
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260702-rust_lockdep-6220af6a6ba9
Best regards,
Signature · 1 line
Gary Guo <[email protected]>