Skip to content

Commit

Permalink
cfq-iosched: fix race between exiting queue and exiting task
Browse files Browse the repository at this point in the history
Original patch from Nikanth Karthikesan <knikanth@suse.de>

When a queue exits the queue lock is taken and cfq_exit_queue() would free all
the cic's associated with the queue.

But when a task exits, cfq_exit_io_context() gets cic one by one and then
locks the associated queue to call __cfq_exit_single_io_context. It looks like
between getting a cic from the ioc and locking the queue, the queue might have
exited on another cpu.

Fix this by rechecking the cfq_io_context queue key inside the queue lock
again, and not calling into __cfq_exit_single_io_context() if somebody
beat us to it.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Jens Axboe committed Dec 29, 2008
1 parent 8ae30b8 commit 62c1fe9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion block/cfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,15 @@ static void cfq_exit_single_io_context(struct io_context *ioc,
unsigned long flags;

spin_lock_irqsave(q->queue_lock, flags);
__cfq_exit_single_io_context(cfqd, cic);

/*
* Ensure we get a fresh copy of the ->key to prevent
* race between exiting task and queue
*/
smp_read_barrier_depends();
if (cic->key)
__cfq_exit_single_io_context(cfqd, cic);

spin_unlock_irqrestore(q->queue_lock, flags);
}
}
Expand Down

0 comments on commit 62c1fe9

Please sign in to comment.