]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: sync: Add lock::Backend::assert_is_held()
authorLyude Paul <lyude@redhat.com>
Mon, 25 Nov 2024 20:40:58 +0000 (15:40 -0500)
committerBoqun Feng <boqun.feng@gmail.com>
Thu, 19 Dec 2024 22:04:42 +0000 (14:04 -0800)
commitfbd7a5a0359bc770e898d918d84977ea61163aad
tree9436b34aee7d055c6952513b01a7200db0d975c1
parenteb5ccb038284dc0e69822d71aafcbf7b57394aad
rust: sync: Add lock::Backend::assert_is_held()

Since we've exposed Lock::from_raw() and Guard::new() publically, we
want to be able to make sure that we assert that a lock is actually held
when constructing a Guard for it to handle instances of unsafe
Guard::new() calls outside of our lock module.

Hence add a new method assert_is_held() to Backend, which uses lockdep
to check whether or not a lock has been acquired. When lockdep is
disabled, this has no overhead.

[Boqun: Resolve the conflicts with exposing Guard::new(), reword the
 commit log a bit and format "unsafe { <statement>; }" into "unsafe {
 <statement> }" for the consistency. ]

Signed-off-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20241125204139.656801-1-lyude@redhat.com
rust/helpers/mutex.c
rust/helpers/spinlock.c
rust/kernel/sync/lock.rs
rust/kernel/sync/lock/mutex.rs
rust/kernel/sync/lock/spinlock.rs