hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/release-management/issues/IB4E8P CVE: NA
--------------------------------
The task will be used later for dumping request in blk-io-hierarchy.
Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/blk-flush.c | 2 ++ block/blk-mq.c | 3 +++ block/blk-mq.h | 25 +++++++++++++++++++++++++ include/linux/blk-mq.h | 4 ++++ 4 files changed, 34 insertions(+)
diff --git a/block/blk-flush.c b/block/blk-flush.c index ff462409db1c..4f64194f2eb6 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -238,6 +238,7 @@ static enum rq_end_io_ret flush_end_io(struct request *flush_rq, * avoiding use-after-free. */ WRITE_ONCE(flush_rq->state, MQ_RQ_IDLE); + blk_mq_put_alloc_task(flush_rq); if (fq->rq_status != BLK_STS_OK) { error = fq->rq_status; fq->rq_status = BLK_STS_OK; @@ -341,6 +342,7 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq, flush_rq->rq_flags |= RQF_FLUSH_SEQ; flush_rq->end_io = flush_end_io; blk_rq_init_bi_alloc_time(flush_rq, first_rq); + blk_mq_get_alloc_task(flush_rq, first_rq->bio); /* * Order WRITE ->end_io and WRITE rq->ref, and its pair is the one * implied in refcount_inc_not_zero() called from diff --git a/block/blk-mq.c b/block/blk-mq.c index b375e1ec6c09..56d6d59f9735 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -388,6 +388,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->end_io_data = NULL;
blk_rq_init_bi_alloc_time(rq, NULL); + blk_mq_get_alloc_task(rq, data->bio);
blk_crypto_rq_set_defaults(rq); INIT_LIST_HEAD(&rq->queuelist); @@ -710,6 +711,7 @@ static void __blk_mq_free_request(struct request *rq) struct blk_mq_hw_ctx *hctx = rq->mq_hctx; const int sched_tag = rq->internal_tag;
+ blk_mq_put_alloc_task(rq); blk_crypto_free_request(rq); blk_pm_mark_last_busy(rq); rq->mq_hctx = NULL; @@ -2921,6 +2923,7 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, .q = q, .nr_tags = 1, .cmd_flags = bio->bi_opf, + .bio = bio, }; struct request *rq;
diff --git a/block/blk-mq.h b/block/blk-mq.h index 8b9aac701035..29ee2c3fe00b 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -158,6 +158,8 @@ struct blk_mq_alloc_data { /* input & output parameter */ struct blk_mq_ctx *ctx; struct blk_mq_hw_ctx *hctx; + + KABI_EXTEND(struct bio *bio) };
struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, @@ -445,4 +447,27 @@ do { \ #define blk_mq_run_dispatch_ops(q, dispatch_ops) \ __blk_mq_run_dispatch_ops(q, true, dispatch_ops) \
+#ifdef CONFIG_BLK_BIO_ALLOC_TASK +static inline void blk_mq_get_alloc_task(struct request *rq, struct bio *bio) +{ + rq->pid = bio ? get_pid(bio->pid) : get_pid(task_pid(current)); +} + +static inline void blk_mq_put_alloc_task(struct request *rq) +{ + if (rq->pid) { + put_pid(rq->pid); + rq->pid = NULL; + } +} +#else +static inline void blk_mq_get_alloc_task(struct request *rq, struct bio *bio) +{ +} + +static inline void blk_mq_put_alloc_task(struct request *rq) +{ +} +#endif + #endif diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 9e8a860f74f4..b301ebe67eb4 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -195,7 +195,11 @@ struct request { #else KABI_RESERVE(1) #endif +#ifdef CONFIG_BLK_BIO_ALLOC_TASK + KABI_USE(2, struct pid *pid) +#else KABI_RESERVE(2) +#endif KABI_RESERVE(3) KABI_RESERVE(4) KABI_RESERVE(5)