block: cleanup the lockdep handling in *alloc_disk
authorChristoph Hellwig <hch@lst.de>
Mon, 16 Aug 2021 13:19:05 +0000 (15:19 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 23 Aug 2021 18:54:30 +0000 (12:54 -0600)
Pass the lockdep name to the low-level __blk_alloc_disk helper and
hardcode the name for it given that the number of minors or node_id
are not very useful information.  While this passes a pointless
argument for non-lockdep builds that is not really an issue as
disk allocation is a probe time only slow path.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210816131910.615153-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq.c
block/genhd.c
include/linux/blk-mq.h
include/linux/genhd.h

index d2725f9..4c56e43 100644 (file)
@@ -3133,7 +3133,8 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
 }
 EXPORT_SYMBOL(blk_mq_init_queue);
 
-struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata)
+struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
+               struct lock_class_key *lkclass)
 {
        struct request_queue *q;
        struct gendisk *disk;
@@ -3142,7 +3143,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata)
        if (IS_ERR(q))
                return ERR_CAST(q);
 
-       disk = __alloc_disk_node(0, set->numa_node);
+       disk = __alloc_disk_node(0, set->numa_node, lkclass);
        if (!disk) {
                blk_cleanup_queue(q);
                return ERR_PTR(-ENOMEM);
index 731a460..2ad2b25 100644 (file)
@@ -1254,7 +1254,8 @@ dev_t blk_lookup_devt(const char *name, int partno)
        return devt;
 }
 
-struct gendisk *__alloc_disk_node(int minors, int node_id)
+struct gendisk *__alloc_disk_node(int minors, int node_id,
+               struct lock_class_key *lkclass)
 {
        struct gendisk *disk;
 
@@ -1282,6 +1283,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
        disk_to_dev(disk)->type = &disk_type;
        device_initialize(disk_to_dev(disk));
        inc_diskseq(disk);
+       lockdep_init_map(&disk->lockdep_map, "(bio completion)", lkclass, 0);
 #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
        INIT_LIST_HEAD(&disk->slave_bdevs);
 #endif
@@ -1298,7 +1300,7 @@ out_free_disk:
 }
 EXPORT_SYMBOL(__alloc_disk_node);
 
-struct gendisk *__blk_alloc_disk(int node)
+struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass)
 {
        struct request_queue *q;
        struct gendisk *disk;
@@ -1307,7 +1309,7 @@ struct gendisk *__blk_alloc_disk(int node)
        if (!q)
                return NULL;
 
-       disk = __alloc_disk_node(0, node);
+       disk = __alloc_disk_node(0, node, lkclass);
        if (!disk) {
                blk_cleanup_queue(q);
                return NULL;
index 22215db..13ba186 100644 (file)
@@ -432,18 +432,14 @@ enum {
        ((policy & ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1)) \
                << BLK_MQ_F_ALLOC_POLICY_START_BIT)
 
+struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
+               struct lock_class_key *lkclass);
 #define blk_mq_alloc_disk(set, queuedata)                              \
 ({                                                                     \
        static struct lock_class_key __key;                             \
-       struct gendisk *__disk = __blk_mq_alloc_disk(set, queuedata);   \
                                                                        \
-       if (!IS_ERR(__disk))                                            \
-               lockdep_init_map(&__disk->lockdep_map,                  \
-                       "(bio completion)", &__key, 0);                 \
-       __disk;                                                         \
+       __blk_mq_alloc_disk(set, queuedata, &__key);                    \
 })
-struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set,
-               void *queuedata);
 struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *);
 int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
                struct request_queue *q);
index b47e297..3d2e5ee 100644 (file)
@@ -259,27 +259,21 @@ static inline sector_t get_capacity(struct gendisk *disk)
 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
 void blk_drop_partitions(struct gendisk *disk);
 
-extern struct gendisk *__alloc_disk_node(int minors, int node_id);
+struct gendisk *__alloc_disk_node(int minors, int node_id,
+               struct lock_class_key *lkclass);
 extern void put_disk(struct gendisk *disk);
 
 #define alloc_disk_node(minors, node_id)                               \
 ({                                                                     \
        static struct lock_class_key __key;                             \
-       const char *__name;                                             \
-       struct gendisk *__disk;                                         \
                                                                        \
-       __name = "(gendisk_completion)"#minors"("#node_id")";           \
-                                                                       \
-       __disk = __alloc_disk_node(minors, node_id);                    \
-                                                                       \
-       if (__disk)                                                     \
-               lockdep_init_map(&__disk->lockdep_map, __name, &__key, 0); \
-                                                                       \
-       __disk;                                                         \
+       __alloc_disk_node(minors, node_id, &__key);                     \
 })
 
 #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
 
+struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass);
+
 /**
  * blk_alloc_disk - allocate a gendisk structure
  * @node_id: numa node to allocate on
@@ -291,15 +285,10 @@ extern void put_disk(struct gendisk *disk);
  */
 #define blk_alloc_disk(node_id)                                                \
 ({                                                                     \
-       struct gendisk *__disk = __blk_alloc_disk(node_id);             \
        static struct lock_class_key __key;                             \
                                                                        \
-       if (__disk)                                                     \
-               lockdep_init_map(&__disk->lockdep_map,                  \
-                       "(bio completion)", &__key, 0);                 \
-       __disk;                                                         \
+       __blk_alloc_disk(node_id, &__key);                              \
 })
-struct gendisk *__blk_alloc_disk(int node);
 void blk_cleanup_disk(struct gendisk *disk);
 
 int __register_blkdev(unsigned int major, const char *name,