Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions block/blk-ioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
if (task->io_context)
kmem_cache_free(iocontext_cachep, ioc);
else
task->io_context = ioc;
/* Pairs with READ_ONCE() in __get_task_ioprio() */
smp_store_release(&task->io_context, ioc);
}
task->io_context->ioprio = ioprio;
WRITE_ONCE(task->io_context->ioprio, ioprio);
out:
task_unlock(task);
return 0;
Expand Down
11 changes: 9 additions & 2 deletions include/linux/ioprio.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,24 @@ static inline int task_nice_ioclass(struct task_struct *task)
*/
static inline int __get_task_ioprio(struct task_struct *p)
{
struct io_context *ioc = p->io_context;
struct io_context *ioc;
int prio;

/*
* Only the current task itself drops its io_context, in
* exit_io_context(), so a non-NULL ioc is always valid. However,
* another task may change ->io_context or ioc->ioprio, so make sure
* to get the latest value with READ_ONCE().
*/
ioc = READ_ONCE(p->io_context);
if (!ioc)
return IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
task_nice_ioprio(p));

if (p != current)
lockdep_assert_held(&p->alloc_lock);

prio = ioc->ioprio;
prio = READ_ONCE(ioc->ioprio);
if (IOPRIO_PRIO_CLASS(prio) == IOPRIO_CLASS_NONE)
prio = IOPRIO_PRIO_VALUE(task_nice_ioclass(p),
task_nice_ioprio(p));
Expand Down
Loading