]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: introduce alloc_sched_data and free_sched_data elevator methods
authorNilay Shroff <nilay@linux.ibm.com>
Thu, 13 Nov 2025 08:58:20 +0000 (14:28 +0530)
committerJens Axboe <axboe@kernel.dk>
Thu, 13 Nov 2025 16:27:49 +0000 (09:27 -0700)
The recent lockdep splat [1] highlights a potential deadlock risk
involving ->elevator_lock and ->freeze_lock dependencies on -pcpu_alloc_
mutex. The trace shows that the issue occurs when the Kyber scheduler
allocates dynamic memory for its elevator data during initialization.

To address this, introduce two new elevator operation callbacks:
->alloc_sched_data and ->free_sched_data. The subsequent patch would
build upon these newly introduced methods to suppress lockdep splat[1].

[1] https://lore.kernel.org/all/CAGVVp+VNW4M-5DZMNoADp6o2VKFhi7KxWpTDkcnVyjO0=-D5+A@mail.gmail.com/

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq-sched.h
block/elevator.h

index 1f8e58dd4b497a9ebbeb5bc7d1096e5106ff8497..4e1b86e85a8a9754a62aec907df41cc8634c4702 100644 (file)
@@ -38,6 +38,30 @@ void blk_mq_free_sched_res(struct elevator_resources *res,
                struct blk_mq_tag_set *set);
 void blk_mq_free_sched_res_batch(struct xarray *et_table,
                struct blk_mq_tag_set *set);
+/*
+ * blk_mq_alloc_sched_data() - Allocates scheduler specific data
+ * Returns:
+ *         - Pointer to allocated data on success
+ *         - NULL if no allocation needed
+ *         - ERR_PTR(-ENOMEM) in case of failure
+ */
+static inline void *blk_mq_alloc_sched_data(struct request_queue *q,
+               struct elevator_type *e)
+{
+       void *sched_data;
+
+       if (!e || !e->ops.alloc_sched_data)
+               return NULL;
+
+       sched_data = e->ops.alloc_sched_data(q);
+       return (sched_data) ?: ERR_PTR(-ENOMEM);
+}
+
+static inline void blk_mq_free_sched_data(struct elevator_type *e, void *data)
+{
+       if (e && e->ops.free_sched_data)
+               e->ops.free_sched_data(data);
+}
 
 static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
 {
index 621a63597249e75b96a606368b6d4dbad0e9e377..e34043f6da26e3010cf25ad88610b070a3705a81 100644 (file)
@@ -58,6 +58,8 @@ struct elevator_mq_ops {
        int (*init_hctx)(struct blk_mq_hw_ctx *, unsigned int);
        void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
        void (*depth_updated)(struct request_queue *);
+       void *(*alloc_sched_data)(struct request_queue *);
+       void (*free_sched_data)(void *);
 
        bool (*allow_merge)(struct request_queue *, struct request *, struct bio *);
        bool (*bio_merge)(struct request_queue *, struct bio *, unsigned int);