From: Bart Van Assche <bvanassche@acm.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Bart Van Assche <bvanassche@acm.org>,
Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.de>,
John Garry <john.garry@huawei.com>
Subject: [PATCH] blk-mq: Fix two racy hctx->tags->rqs[] assignments
Date: Fri, 23 Apr 2021 13:01:09 -0700 [thread overview]
Message-ID: <20210423200109.18430-1-bvanassche@acm.org> (raw)
hctx->tags->rqs[] must be cleared before releasing a request tag because
otherwise clearing that pointer races with the following assignment in
blk_mq_get_driver_tag():
rcu_assign_pointer(hctx->tags->rqs[rq->tag], rq);
Reported-by: Ming Lei <ming.lei@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: John Garry <john.garry@huawei.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
block/blk-mq.c | 2 +-
block/blk-mq.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 06d204796c43..1ffaab7c9b11 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -501,8 +501,8 @@ static void __blk_mq_free_request(struct request *rq)
blk_pm_mark_last_busy(rq);
rq->mq_hctx = NULL;
if (rq->tag != BLK_MQ_NO_TAG) {
- blk_mq_put_tag(hctx->tags, ctx, rq->tag);
rcu_assign_pointer(hctx->tags->rqs[rq->tag], NULL);
+ blk_mq_put_tag(hctx->tags, ctx, rq->tag);
}
if (sched_tag != BLK_MQ_NO_TAG)
blk_mq_put_tag(hctx->sched_tags, ctx, sched_tag);
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 9ccb1818303b..f73cd659eb81 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -225,8 +225,8 @@ static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx)
static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx,
struct request *rq)
{
- blk_mq_put_tag(hctx->tags, rq->mq_ctx, rq->tag);
rcu_assign_pointer(hctx->tags->rqs[rq->tag], NULL);
+ blk_mq_put_tag(hctx->tags, rq->mq_ctx, rq->tag);
rq->tag = BLK_MQ_NO_TAG;
if (rq->rq_flags & RQF_MQ_INFLIGHT) {
next reply other threads:[~2021-04-23 20:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 20:01 Bart Van Assche [this message]
2021-04-24 19:33 ` [PATCH] blk-mq: Fix two racy hctx->tags->rqs[] assignments Jens Axboe
2021-04-25 0:13 ` 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=20210423200109.18430-1-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=john.garry@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.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