The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH RFC 0/2] rust: sync: create lock class using `#[track_caller]`
@ 2026-07-03 13:47 Gary Guo
  2026-07-03 13:47 ` [PATCH RFC 1/2] rust: sync: introduce a way to create lock class from caller Gary Guo
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Gary Guo @ 2026-07-03 13:47 UTC (permalink / raw)
  To: Boqun Feng, Alice Ryhl, Lyude Paul, Daniel Almeida,
	Onur Özkan, Miguel Ojeda, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	Tamir Duberstein, Alexandre Courbot, Peter Zijlstra, Ingo Molnar,
	Will Deacon, Waiman Long
  Cc: linux-kernel, rust-for-linux, Gary Guo

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.

Signed-off-by: Gary Guo <gary@garyguo.net>
---
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,
--  
Gary Guo <gary@garyguo.net>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-07-04 17:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 13:47 [PATCH RFC 0/2] rust: sync: create lock class using `#[track_caller]` Gary Guo
2026-07-03 13:47 ` [PATCH RFC 1/2] rust: sync: introduce a way to create lock class from caller Gary Guo
2026-07-03 13:47 ` [PATCH RFC 2/2] lockdep: delegate Rust lock class printing to Rust code Gary Guo
2026-07-03 14:01 ` [PATCH RFC 0/2] rust: sync: create lock class using `#[track_caller]` Peter Zijlstra
2026-07-03 14:24   ` Gary Guo
2026-07-03 22:32     ` Peter Zijlstra
2026-07-04 16:52       ` Gary Guo
2026-07-04 17:10         ` Peter Zijlstra
2026-07-04 17:46           ` Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox