Skip to content

Commit

Permalink
[PATCH] Fix current_io_context() vs set_task_ioprio() race
Browse files Browse the repository at this point in the history
I know nothing about io scheduler, but I suspect set_task_ioprio() is not safe.

current_io_context() initializes "struct io_context", then sets ->io_context.
set_task_ioprio() running on another cpu may see the changes out of order, so
->set_ioprio(ioc) may use io_context which was not initialized properly.

Signed-off-by: Oleg Nesterov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Oleg Nesterov authored and Jens Axboe committed Aug 21, 2006
1 parent 78bd4d4 commit 9f83e45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions block/ll_rw_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3628,6 +3628,8 @@ struct io_context *current_io_context(gfp_t gfp_flags)
ret->nr_batch_requests = 0; /* because this is 0 */
ret->aic = NULL;
ret->cic_root.rb_node = NULL;
/* make sure set_task_ioprio() sees the settings above */
smp_wmb();
tsk->io_context = ret;
}

Expand Down
3 changes: 3 additions & 0 deletions fs/ioprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ static int set_task_ioprio(struct task_struct *task, int ioprio)
task->ioprio = ioprio;

ioc = task->io_context;
/* see wmb() in current_io_context() */
smp_read_barrier_depends();

if (ioc && ioc->set_ioprio)
ioc->set_ioprio(ioc, ioprio);

Expand Down

0 comments on commit 9f83e45

Please sign in to comment.