2006-08-20 11:44:51

by Oleg Nesterov

[permalink] [raw]
Subject: [PATCH] fix? current_io_context() vs set_task_ioprio() race

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]>

--- 2.6.18-rc4/block/ll_rw_blk.c~3_race 2006-07-16 01:53:08.000000000 +0400
+++ 2.6.18-rc4/block/ll_rw_blk.c 2006-08-20 19:30:10.000000000 +0400
@@ -3628,6 +3628,8 @@ struct io_context *current_io_context(gf
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;
}

--- 2.6.18-rc4/fs/ioprio.c~3_race 2006-08-20 19:09:08.000000000 +0400
+++ 2.6.18-rc4/fs/ioprio.c 2006-08-20 19:57:14.000000000 +0400
@@ -44,6 +44,9 @@ static int set_task_ioprio(struct task_s
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);



2006-08-21 06:26:46

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] fix? current_io_context() vs set_task_ioprio() race

On Sun, Aug 20 2006, Oleg Nesterov wrote:
> 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]>
>
> --- 2.6.18-rc4/block/ll_rw_blk.c~3_race 2006-07-16 01:53:08.000000000 +0400
> +++ 2.6.18-rc4/block/ll_rw_blk.c 2006-08-20 19:30:10.000000000 +0400
> @@ -3628,6 +3628,8 @@ struct io_context *current_io_context(gf
> 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;
> }
>
> --- 2.6.18-rc4/fs/ioprio.c~3_race 2006-08-20 19:09:08.000000000 +0400
> +++ 2.6.18-rc4/fs/ioprio.c 2006-08-20 19:57:14.000000000 +0400
> @@ -44,6 +44,9 @@ static int set_task_ioprio(struct task_s
> 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);

Agree, applied.

--
Jens Axboe