On 2025-04-30 20:27:14 [-0700], Alexei Starovoitov wrote: > From: Alexei Starovoitov <ast@xxxxxxxxxx> > > lockdep_is_held() macro assumes that "struct lockdep_map dep_map;" > is a top level field of any lock that participates in LOCKDEP. > Make it so for local_trylock_t. > > Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> > --- > include/linux/local_lock_internal.h | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h > index bf2bf40d7b18..29df45f95843 100644 > --- a/include/linux/local_lock_internal.h > +++ b/include/linux/local_lock_internal.h > @@ -17,7 +17,10 @@ typedef struct { > > /* local_trylock() and local_trylock_irqsave() only work with local_trylock_t */ > typedef struct { > - local_lock_t llock; > +#ifdef CONFIG_DEBUG_LOCK_ALLOC > + struct lockdep_map dep_map; > + struct task_struct *owner; > +#endif > u8 acquired; > } local_trylock_t; So this trick should make it work. I am not sure it is worth it. It would avoid the cast down the road… diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -17,10 +17,17 @@ typedef struct { /* local_trylock() and local_trylock_irqsave() only work with local_trylock_t */ typedef struct { + union { + local_lock_t llock; #ifdef CONFIG_DEBUG_LOCK_ALLOC - struct lockdep_map dep_map; - struct task_struct *owner; +# define LOCK_PAD_SIZE (offsetof(local_lock_t, dep_map)) + struct { + u8 __padding[LOCK_PAD_SIZE]; + struct lockdep_map dep_map; + }; +#undef LOCK_PAD_SIZE #endif + }; u8 acquired; } local_trylock_t; @@ -34,7 +41,7 @@ typedef struct { .owner = NULL, # define LOCAL_TRYLOCK_DEBUG_INIT(lockname) \ - LOCAL_LOCK_DEBUG_INIT(lockname) + .llock = { LOCAL_LOCK_DEBUG_INIT(llock.lockname) } static inline void local_lock_acquire(local_lock_t *l) { Sebastian