diff options
author | Roland Dreier <roland@purestorage.com> | 2012-11-22 05:00:11 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-11-23 08:32:55 -0500 |
commit | 893d290f1d7496db97c9471bc352ad4a11dc8a25 (patch) | |
tree | c6d5444d06949edfd5d13fa0beed0992dd2ae469 /block/blk-exec.c | |
parent | 836413e8c78ecbc55aa31f3cb600f8ee1aa355a2 (diff) |
block: Don't access request after it might be freed
After we've done __elv_add_request() and __blk_run_queue() in
blk_execute_rq_nowait(), the request might finish and be freed
immediately. Therefore checking if the type is REQ_TYPE_PM_RESUME
isn't safe afterwards, because if it isn't, rq might be gone.
Instead, check beforehand and stash the result in a temporary.
This fixes crashes in blk_execute_rq_nowait() I get occasionally when
running with lots of memory debugging options enabled -- I think this
race is usually harmless because the window for rq to be reallocated
is so small.
Signed-off-by: Roland Dreier <roland@purestorage.com>
Cc: stable@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-exec.c')
-rw-r--r-- | block/blk-exec.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/block/blk-exec.c b/block/blk-exec.c index 8b6dc5bd4dd0..f71eac35c1b9 100644 --- a/block/blk-exec.c +++ b/block/blk-exec.c | |||
@@ -52,11 +52,17 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk, | |||
52 | rq_end_io_fn *done) | 52 | rq_end_io_fn *done) |
53 | { | 53 | { |
54 | int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK; | 54 | int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK; |
55 | bool is_pm_resume; | ||
55 | 56 | ||
56 | WARN_ON(irqs_disabled()); | 57 | WARN_ON(irqs_disabled()); |
57 | 58 | ||
58 | rq->rq_disk = bd_disk; | 59 | rq->rq_disk = bd_disk; |
59 | rq->end_io = done; | 60 | rq->end_io = done; |
61 | /* | ||
62 | * need to check this before __blk_run_queue(), because rq can | ||
63 | * be freed before that returns. | ||
64 | */ | ||
65 | is_pm_resume = rq->cmd_type == REQ_TYPE_PM_RESUME; | ||
60 | 66 | ||
61 | spin_lock_irq(q->queue_lock); | 67 | spin_lock_irq(q->queue_lock); |
62 | 68 | ||
@@ -71,7 +77,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk, | |||
71 | __elv_add_request(q, rq, where); | 77 | __elv_add_request(q, rq, where); |
72 | __blk_run_queue(q); | 78 | __blk_run_queue(q); |
73 | /* the queue is stopped so it won't be run */ | 79 | /* the queue is stopped so it won't be run */ |
74 | if (rq->cmd_type == REQ_TYPE_PM_RESUME) | 80 | if (is_pm_resume) |
75 | q->request_fn(q); | 81 | q->request_fn(q); |
76 | spin_unlock_irq(q->queue_lock); | 82 | spin_unlock_irq(q->queue_lock); |
77 | } | 83 | } |