Skip to contentSkip to conversation

blk-mq: Fix queue usage on failed request allocation

PATCH In review Keith Busch 5 participants 5 messages Aug 14, 2017 – Aug 15, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-mq: Fix queue usage on failed request allocation

blk_mq_get_request() does not release the callers queue usage counter when allocation fails. The caller still needs to account for its own queue usage when it is unable to allocate a request.

Fixes 1ad43c0078b7 ("blk-mq: don't leak preempt counter/q_usage_counter when allocating rq failed")
---
 block/blk-mq.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/blk-mq.c +2 -3
index 535cbdf..4603b11 100644
@@ -360,12 +360,12 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
 		return ERR_PTR(ret);
 
 	rq = blk_mq_get_request(q, NULL, op, &alloc_data);
+	blk_queue_exit(q);
 
 	if (!rq)
 		return ERR_PTR(-EWOULDBLOCK);
 
 	blk_mq_put_ctx(alloc_data.ctx);
-	blk_queue_exit(q);
 
 	rq->__data_len = 0;
 	rq->__sector = (sector_t) -1;
@@ -411,12 +411,11 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
 
 	rq = blk_mq_get_request(q, NULL, op, &alloc_data);
+	blk_queue_exit(q);
 
 	if (!rq)
 		return ERR_PTR(-EWOULDBLOCK);
 
-	blk_queue_exit(q);
-
 	return rq;
 }
 EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);
Signature · 1 line
2.5.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Keith Busch

blk_mq_get_request() does not release the callers queue usage counter when allocation fails. The caller still needs to account for its own queue usage when it is unable to allocate a request.

Fixes 1ad43c0078b7 ("blk-mq: don't leak preempt counter/q_usage_counter when allocating rq failed")
Signature · 1 line
Ming
Tested-by on v1 1/1
#3 lore raw
In reply to Keith Busch
Quoted 9 lines · Keith Busch

blk_mq_get_request() does not release the callers queue usage counter when allocation fails. The caller still needs to account for its own queue usage when it is unable to allocate a request.

Fixes 1ad43c0078b7 ("blk-mq: don't leak preempt counter/q_usage_counter when allocating rq failed")

---

tested with 4.13-rc5+ using the following commands in a loop:

1. modprobe nvme
2. sleep 10
3. modprobe -r nvme

Looks good,

maintainer
#4 lore raw
In reply to Keith Busch
Quoted 3 lines · Keith Busch

blk_mq_get_request() does not release the callers queue usage counter when allocation fails. The caller still needs to account for its own queue usage when it is unable to allocate a request.

Thanks Keith, applied.

Signature · 1 line
Jens Axboe