From: "Jörn Engel" <joern@logfs.org>
To: Jens Axboe <axboe@kernel.dk>, oren@purestorage.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Fix race in get_request()
Date: Thu, 7 Aug 2014 20:54:43 -0400 [thread overview]
Message-ID: <20140808005443.GA7895@logfs.org> (raw)
Hello Jens!
I came across the below while investigating some other problem.
Something here doesn't seem right. This looks like an obvious bug and
something roughly along the lines of my patch would fix it. But I
must be in the wrong decade to find such a bug in the block layer.
Is this for real? Or if not, what am I missing?
Jörn
--
If __get_request() returns NULL, get_request will call
prepare_to_wait_exclusive() followed by io_schedule(). Not rechecking
the sleep condition after prepare_to_wait_exclusive() leaves a race
where the condition changes before prepare_to_wait_exclusive(), but
not after and accordingly this thread never gets woken up.
The race must be exceedingly hard to hit, otherwise I cannot explain how
such a classic race could outlive the last millenium.
Signed-off-by: Joern Engel <joern@logfs.org>
---
block/blk-core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/block/blk-core.c b/block/blk-core.c
index 3275353957f0..00aa6c7abe5a 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1068,6 +1068,11 @@ retry:
trace_block_sleeprq(q, bio, rw_flags & 1);
+ rq = __get_request(rl, rw_flags, bio, gfp_mask);
+ if (rq) {
+ finish_wait(&rl->wait[is_sync], &wait);
+ return rq;
+ }
spin_unlock_irq(q->queue_lock);
io_schedule();
--
2.0.0.rc0.1.g7b2ba98
next reply other threads:[~2014-08-08 1:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-08 0:54 Jörn Engel [this message]
2014-08-08 14:24 ` [PATCH] Fix race in get_request() Jens Axboe
2014-08-08 14:28 ` Jens Axboe
2014-08-08 17:43 ` Jörn Engel
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=20140808005443.GA7895@logfs.org \
--to=joern@logfs.org \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=oren@purestorage.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