Issue in blk_mq_alloc_request_hctx()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi guys,

I find that a call to blk_mq_alloc_request_hctx() sometimes has rq->bio set when returned, when I didn't think it should. I notice that we explicitly zero this field (and data len and sector) in blk_mq_alloc_request().

This trips up scsi_setup_scsi_cmd() for me, which checks these fields.

This is what I thought needs changing:

---8<----

From 396d0b64b73cc6fb5193189d9da2c6107dbeff83 Mon Sep 17 00:00:00 2001
From: John Garry <john.garry@xxxxxxxxxx>
Date: Fri, 21 Oct 2022 11:56:11 +0100
Subject: [PATCH] blk-mq: Properly init rq and fix queue enter/exit in
 blk_mq_alloc_request_hctx()


diff --git a/block/blk-mq.c b/block/blk-mq.c
index f33ea455dd72..cce5cda3c442 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -611,6 +611,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 		.nr_tags	= 1,
 	};
 	u64 alloc_time_ns = 0;
+	struct request *rq;
 	unsigned int cpu;
 	unsigned int tag;
 	int ret;
@@ -660,8 +661,15 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	tag = blk_mq_get_tag(&data);
 	if (tag == BLK_MQ_NO_TAG)
 		goto out_queue_exit;
-	return blk_mq_rq_ctx_init(&data, blk_mq_tags_from_data(&data), tag,
+	rq = blk_mq_rq_ctx_init(&data, blk_mq_tags_from_data(&data), tag,
 					alloc_time_ns);
+	if (!rq)
+		goto out_queue_exit;
+
+	rq->__data_len = 0;
+	rq->__sector = (sector_t) -1;
+	rq->bio = rq->biotail = NULL;
+	return rq;


--->8---


What that, now my code under dev looks ok. Is that change correct? Seems strange to be missed..

Cheers,
John



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux