diff --git a/block/blk-crypto-profile.c b/block/blk-crypto-profile.c index fe550725c777..7cdef1bee6f7 100644 --- a/block/blk-crypto-profile.c +++ b/block/blk-crypto-profile.c @@ -79,7 +79,18 @@ int blk_crypto_profile_init(struct blk_crypto_profile *profile, unsigned int slot_hashtable_size; memset(profile, 0, sizeof(*profile)); + + /* + * profile->lock of an underlying device can nest inside profile->lock + * of a device-mapper device, so use a dynamic lock class to avoid + * false-positive lockdep reports. + */ +#ifdef CONFIG_LOCKDEP + lockdep_register_key(&profile->lockdep_key); + __init_rwsem(&profile->lock, "&profile->lock", &profile->lockdep_key); +#else init_rwsem(&profile->lock); +#endif if (num_slots == 0) return 0; @@ -89,7 +100,7 @@ int blk_crypto_profile_init(struct blk_crypto_profile *profile, profile->slots = kvcalloc(num_slots, sizeof(profile->slots[0]), GFP_KERNEL); if (!profile->slots) - return -ENOMEM; + goto err_destroy; profile->num_slots = num_slots; @@ -443,6 +454,9 @@ void blk_crypto_profile_destroy(struct blk_crypto_profile *profile) { if (!profile) return; +#ifdef CONFIG_LOCKDEP + lockdep_unregister_key(&profile->lockdep_key); +#endif kvfree(profile->slot_hashtable); kvfree_sensitive(profile->slots, sizeof(profile->slots[0]) * profile->num_slots); diff --git a/include/linux/blk-crypto-profile.h b/include/linux/blk-crypto-profile.h index 8b30d04ef008..794f608a8994 100644 --- a/include/linux/blk-crypto-profile.h +++ b/include/linux/blk-crypto-profile.h @@ -131,6 +131,9 @@ struct blk_crypto_profile { * keyslots while ensuring that they can't be changed concurrently. */ struct rw_semaphore lock; +#ifdef CONFIG_LOCKDEP + struct lock_class_key lockdep_key; +#endif /* List of idle slots, with least recently used slot at front */ wait_queue_head_t idle_slots_wait_queue;