Commit ab67983f authored by Yu Kuai's avatar Yu Kuai
Browse files

block: support to recored bio allocation task in request

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: default avatarYu Kuai <yukuai3@huawei.com>
parent cb07babf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+3 −0
Original line number Diff line number Diff line
@@ -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;

+25 −0
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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)