mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Ming Lei <tom.leiming@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH] block: fix mq request allocation
Date: Mon, 02 Dec 2013 10:20:08 -0500	[thread overview]
Message-ID: <x49ob4z700n.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <1385890077-30873-1-git-send-email-tom.leiming@gmail.com> (Ming Lei's message of "Sun, 1 Dec 2013 17:27:57 +0800")

Ming Lei <tom.leiming@gmail.com> writes:

> blk_mq_alloc_request_pinned() may return NULL request in case of
> !__GFP_WAIT, so cause its callers to derefence NULL pointer for
> releasing current context.
>
> This patch introduces two flags to address the issue.

Hi, Ming,


Good catch, but your patch seems overly complicated.  How about
something like the following (compile-tested only), instead?  Note that
I did not touch blk_make_request, as the put_ctx there seems to
correlate to a get_ctx earlier in the function (not a leaked reference
from __blk_mq_alloc_request).

-Jeff

p.s. Jens, every time I see GFP_ATOMIC|__GFP_WAIT, my head explodes.  Just sayin'.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>


diff --git a/block/blk-mq.c b/block/blk-mq.c
index cdc629c..70fd6f9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -202,10 +202,12 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
 		if (rq) {
 			blk_mq_rq_ctx_init(q, ctx, rq, rw);
 			break;
-		} else if (!(gfp & __GFP_WAIT))
-			break;
+		}
 
 		blk_mq_put_ctx(ctx);
+		if (!(gfp & __GFP_WAIT))
+			break;
+
 		__blk_mq_run_hw_queue(hctx);
 		blk_mq_wait_for_tags(hctx->tags);
 	} while (1);
@@ -222,7 +224,8 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
 		return NULL;
 
 	rq = blk_mq_alloc_request_pinned(q, rw, gfp, reserved);
-	blk_mq_put_ctx(rq->mq_ctx);
+	if (rq)
+		blk_mq_put_ctx(rq->mq_ctx);
 	return rq;
 }
 
@@ -235,7 +238,8 @@ struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw,
 		return NULL;
 
 	rq = blk_mq_alloc_request_pinned(q, rw, gfp, true);
-	blk_mq_put_ctx(rq->mq_ctx);
+	if (rq)
+		blk_mq_put_ctx(rq->mq_ctx);
 	return rq;
 }
 EXPORT_SYMBOL(blk_mq_alloc_reserved_request);

  reply	other threads:[~2013-12-02 15:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-01  9:27 Ming Lei
2013-12-02 15:20 ` Jeff Moyer [this message]
2013-12-02 16:49   ` Jens Axboe
2013-12-02 19:14     ` Jeff Moyer
2013-12-03  1:33   ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x49ob4z700n.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®