From: Bart Van Assche <bvanassche@acm.org>
To: device-mapper development <dm-devel@redhat.com>
Cc: linux-scsi <linux-scsi@vger.kernel.org>,
Alasdair G Kergon <agk@redhat.com>, Jens Axboe <axboe@kernel.dk>,
Mike Snitzer <snitzer@redhat.com>, Tejun Heo <tj@kernel.org>,
James Bottomley <JBottomley@parallels.com>
Subject: [PATCH 1/2] block: Avoid invoking blk_run_queue() recursively
Date: Fri, 22 Feb 2013 11:46:14 +0100 [thread overview]
Message-ID: <51274C76.8080007@acm.org> (raw)
In-Reply-To: <51274C2F.6070500@acm.org>
Some block drivers, e.g. dm and SCSI, need to trigger a queue
run from inside functions that may be invoked by their request_fn()
implementation. Make sure that invoking blk_run_queue() instead
of blk_run_queue_async() from such functions does not trigger
recursion. Making blk_run_queue() skip queue processing when
invoked recursively is safe because the only two affected
request_fn() implementations (dm and SCSI) guarantee that the
request queue will be reexamined sooner or later before returning
from their request_fn() implementation.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Tejun Heo <tj@kernel.org>
Cc: James Bottomley <JBottomley@parallels.com>
Cc: Alasdair G Kergon <agk@redhat.com>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: <stable@vger.kernel.org>
---
block/blk-core.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index c973249..cf26e3a 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -304,19 +304,24 @@ EXPORT_SYMBOL(blk_sync_queue);
* This variant runs the queue whether or not the queue has been
* stopped. Must be called with the queue lock held and interrupts
* disabled. See also @blk_run_queue.
+ *
+ * Note:
+ * Request handling functions are allowed to invoke __blk_run_queue() or
+ * blk_run_queue() directly or indirectly. This will not result in a
+ * recursive call of the request handler. However, such request handling
+ * functions must, before they return, either reexamine the request queue
+ * or invoke blk_delay_queue() to avoid that queue processing stops.
+ *
+ * Some request handler implementations, e.g. scsi_request_fn() and
+ * dm_request_fn(), unlock the queue lock internally. Returning immediately
+ * if q->request_fn_active > 0 avoids that for the same queue multiple
+ * threads execute the request handling function concurrently.
*/
inline void __blk_run_queue_uncond(struct request_queue *q)
{
- if (unlikely(blk_queue_dead(q)))
+ if (unlikely(blk_queue_dead(q) || q->request_fn_active))
return;
- /*
- * Some request_fn implementations, e.g. scsi_request_fn(), unlock
- * the queue lock internally. As a result multiple threads may be
- * running such a request function concurrently. Keep track of the
- * number of active request_fn invocations such that blk_drain_queue()
- * can wait until all these request_fn calls have finished.
- */
q->request_fn_active++;
q->request_fn(q);
q->request_fn_active--;
--
1.7.10.4
next prev parent reply other threads:[~2013-02-22 10:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-22 10:45 [PATCH 0/2] dm: Avoid use-after-free of a mapped device Bart Van Assche
2013-02-22 10:46 ` Bart Van Assche [this message]
2013-02-22 18:14 ` [PATCH 1/2] block: Avoid invoking blk_run_queue() recursively Tejun Heo
2013-02-22 18:57 ` Bart Van Assche
2013-02-22 19:01 ` Jens Axboe
2013-02-23 12:34 ` Bart Van Assche
2013-02-22 10:47 ` [PATCH 2/2] dm: Avoid use-after-free of a mapped device Bart Van Assche
2013-02-22 11:08 ` Mike Snitzer
2013-02-22 11:22 ` Bart Van Assche
2013-02-22 11:28 ` Mike Snitzer
2013-02-25 9:49 ` Jun'ichi Nomura
2013-02-25 15:09 ` Bart Van Assche
2013-02-26 0:30 ` Jun'ichi Nomura
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=51274C76.8080007@acm.org \
--to=bvanassche@acm.org \
--cc=JBottomley@parallels.com \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@redhat.com \
--cc=linux-scsi@vger.kernel.org \
--cc=snitzer@redhat.com \
--cc=tj@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.