Skip to content

Commit ff93bca

Browse files
congwangdavem330
authored andcommitted
ila: make lockdep happy again
Previously, alloc_ila_locks() and bucket_table_alloc() call spin_lock_init() separately, therefore they have two different lock names and lock class keys. However, after commit b893281 ("ila: Call library function alloc_bucket_locks") they both call helper alloc_bucket_spinlocks() which now only has one lock name and lock class key. This causes a few bogus lockdep warnings as reported by syzbot. Fix this by making alloc_bucket_locks() a macro and pass declaration name as lock name and a static lock class key inside the macro. Fixes: b893281 ("ila: Call library function alloc_bucket_locks") Reported-by: <[email protected]> Cc: Tom Herbert <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 32039ea commit ff93bca

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

include/linux/spinlock.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,20 @@ extern int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock,
451451
#define atomic_dec_and_lock_irqsave(atomic, lock, flags) \
452452
__cond_lock(lock, _atomic_dec_and_lock_irqsave(atomic, lock, &(flags)))
453453

454-
int alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask,
455-
size_t max_size, unsigned int cpu_mult,
456-
gfp_t gfp);
454+
int __alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask,
455+
size_t max_size, unsigned int cpu_mult,
456+
gfp_t gfp, const char *name,
457+
struct lock_class_key *key);
458+
459+
#define alloc_bucket_spinlocks(locks, lock_mask, max_size, cpu_mult, gfp) \
460+
({ \
461+
static struct lock_class_key key; \
462+
int ret; \
463+
\
464+
ret = __alloc_bucket_spinlocks(locks, lock_mask, max_size, \
465+
cpu_mult, gfp, #locks, &key); \
466+
ret; \
467+
})
457468

458469
void free_bucket_spinlocks(spinlock_t *locks);
459470

lib/bucket_locks.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* to a power of 2 to be suitable as a hash table.
1212
*/
1313

14-
int alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *locks_mask,
15-
size_t max_size, unsigned int cpu_mult, gfp_t gfp)
14+
int __alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *locks_mask,
15+
size_t max_size, unsigned int cpu_mult, gfp_t gfp,
16+
const char *name, struct lock_class_key *key)
1617
{
1718
spinlock_t *tlocks = NULL;
1819
unsigned int i, size;
@@ -33,16 +34,18 @@ int alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *locks_mask,
3334
tlocks = kvmalloc_array(size, sizeof(spinlock_t), gfp);
3435
if (!tlocks)
3536
return -ENOMEM;
36-
for (i = 0; i < size; i++)
37+
for (i = 0; i < size; i++) {
3738
spin_lock_init(&tlocks[i]);
39+
lockdep_init_map(&tlocks[i].dep_map, name, key, 0);
40+
}
3841
}
3942

4043
*locks = tlocks;
4144
*locks_mask = size - 1;
4245

4346
return 0;
4447
}
45-
EXPORT_SYMBOL(alloc_bucket_spinlocks);
48+
EXPORT_SYMBOL(__alloc_bucket_spinlocks);
4649

4750
void free_bucket_spinlocks(spinlock_t *locks)
4851
{

0 commit comments

Comments
 (0)