Re: [PATCH 3/4] ublk: use READ_ONCE() to read struct ublksrv_ctrl_cmd
From: Ming Lei
Date: Fri Jan 30 2026 - 10:56:44 EST
On Thu, Jan 29, 2026 at 03:46:16PM -0700, Caleb Sander Mateos wrote:
> struct ublksrv_ctrl_cmd is part of the io_uring_sqe, which may lie in
> userspace-mapped memory. It's racy to access its fields with normal
> loads, as userspace may write to them concurrently. Use READ_ONCE() for
> all the ublksrv_ctrl_cmd field accesses to avoid the race.
>
> Fixes: 87213b0d847c ("ublk: allow non-blocking ctrl cmds in IO_URING_F_NONBLOCK issue")
> Signed-off-by: Caleb Sander Mateos <csander@xxxxxxxxxxxxxxx>
> ---
> drivers/block/ublk_drv.c | 77 +++++++++++++++++++---------------------
> 1 file changed, 37 insertions(+), 40 deletions(-)
I'd suggest to define local `struct ublksrv_ctrl_cmd` variable in
ublk_ctrl_uring_cmd() for avoiding READ_ONCE:
- it is slow control cod path
- READ_ONCE is supposed to be used for fast path and be carefully
- it is sync command
Defining one local data can be simpler to avoid the issue, and more
reliable.
Thanks,
Ming