lockdep pinning

From: Liam R. Howlett

Date: Thu Feb 26 2026 - 17:03:07 EST


Hello,

I'm trying to detect locking issues in the maple tree, which is severely
complicated by allowing external locks. I have an rcu lock validation
using the get_state_synchronize_rcu() and poll_state_synchronize_rcu()
interface working and would like something like this for write locks.

The issue is that, with external locks, the code that does the unlocking
is outside my scope. Although I can detect a start of an operation and
pin a lock using the existing lockdep_pin_lock() function, I do not know
when the lock is 'done' as it can be used for multiple operations on the
tree.

So I'd either be unpinning too early and be unable to tell if it was
unlocked/relocked, or I'd leave it pinned forever - which will trigger a
warning on release.

What I'm looking for is a way to ensure my code is still in the same
lock context, but not unpin/pin. Maybe something like storing a lock
cookie id in the lock every time it's locked (just overwrite would be
fine), and a way to read that value. Then I can validate the value
against the one I've stored.

AFAICT, I cannot accomplish what I want with the existing lockdep
implementation?

Thanks,
Liam