From: Damien Le Moal <dlemoal@kernel.org>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+feeb9b5352b9ff89618a@syzkaller.appspotmail.com
Subject: Re: [PATCH v3] block: annotate lockless task ioprio accesses
Date: Thu, 22 Oct 2026 09:34:01 +0200 [thread overview]
Message-ID: <10bb721f-43bb-4a22-a9c5-6ebacda9b6b4@kernel.org> (raw)
In-Reply-To: <20261020125233.9820-1-ngocthang2710.1999@gmail.com>
On 2026/10/20 14:52, Nguyen Ngoc Thang wrote:
> __get_task_ioprio() reads task->io_context and ioc->ioprio without
> task_lock() when called on current, e.g. from init_sync_kiocb() on every
> write. set_task_ioprio() can update both for another task at any time,
> including the first publication of a new io_context. KCSAN reports it:
>
> BUG: KCSAN: data-race in __kernel_write_iter / set_task_ioprio
> value changed: 0x0000000000000000 -> 0xffff888109813730
>
> A stale or torn value is harmless, a task simply gets the old or new
> priority, but the compiler may tear or refetch the accesses and the
> io_context fields must be visible before the pointer is.
>
> The io_context itself needs no extra protection: only the owning task
> drops it, in exit_io_context(), so it cannot be freed under a lockless
> reader running as current.
>
> Publish the pointer with smp_store_release(), read it with READ_ONCE()
> (address dependency orders the ioprio load), and mark the ioprio
> accesses.
>
> Reported-by: syzbot+feeb9b5352b9ff89618a@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=feeb9b5352b9ff89618a
> Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
The patch title still mentions "annotate", which is really vague. Please change
the title to be more descriptive. E.g. "use READ_ONCE() to access a task ioprio
context".
> diff --git a/block/blk-ioc.c b/block/blk-ioc.c
> index d15918d7fabb..12ddc672f41d 100644
> --- a/block/blk-ioc.c
> +++ b/block/blk-ioc.c
> @@ -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);
This is normally paired with smp_load_acquire(). The generic implementation of
that is simply a READ_ONCE() followed by an __smp_mb(), but some architectures
may have their own implementation. So why is it always correct to pair with
READ_ONCE()? Why not use WRITE_ONCE() here?
> }
> - task->io_context->ioprio = ioprio;
> + WRITE_ONCE(task->io_context->ioprio, ioprio);
> out:
> task_unlock(task);
> return 0;
> diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
--
Damien Le Moal
Western Digital Research
prev parent reply other threads:[~2026-10-22 7:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 7:16 [PATCH] " Nguyen Ngoc Thang
2026-10-19 11:59 ` Damien Le Moal
2026-10-19 12:18 ` Nguyen Ngoc Thang
2026-10-19 12:28 ` Damien Le Moal
2026-10-19 12:58 ` [PATCH v2] " Nguyen Ngoc Thang
2026-10-19 15:47 ` Damien Le Moal
2026-10-20 12:52 ` [PATCH v3] " Nguyen Ngoc Thang
2026-10-22 7:34 ` Damien Le Moal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10bb721f-43bb-4a22-a9c5-6ebacda9b6b4@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ngocthang2710.1999@gmail.com \
--cc=syzbot+feeb9b5352b9ff89618a@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®