On Mon, May 12, 2025 at 10:39:57AM -0700, Caleb Sander Mateos wrote: > On Fri, May 9, 2025 at 8:06 AM Ming Lei <ming.lei@xxxxxxxxxx> wrote: > > > > `ublk_queue` is read only for io buffer register/unregister command. Both > > `ublk_io` and block layer request are read-only for IO buffer register/ > > unregister command. > > > > So the two command can be issued from other task contexts. > > I mentioned this before in > https://lore.kernel.org/linux-block/CADUfDZqZ_9O7vUAYtxrrujWqPBuP05nBhCbzNuNsc9kJTmX2sA@xxxxxxxxxxxxxx/ > > But UBLK_IO_(UN)REGISTER_IO_BUF still reads io->flags. So it would be > a race condition to handle it on a thread other than ubq_daemon, as > ubq_daemon may concurrently modify io->flags. If you do want to > support UBLK_IO_(UN)REGISTER_IO_BUF on other threads, the writes to > io->flags should use WRITE_ONCE() and the reads on other threads > should use READ_ONCE(). With those modifications, it should be safe > because __ublk_check_and_get_req() atomically checks the state of the > request and increments its reference count. UBLK_IO_(UN)REGISTER_IO_BUF just reads the flag, if UBLK_IO_FLAG_OWNED_BY_SRV is cleared, the OP is failed. Otherwise, __ublk_check_and_get_req() covers everything because both 'ublk_io' and 'request' are pre-allocation. The only race is that new recycled request buffer is registered, that is fine, because it can be treated as logic bug. So I think it isn't necessary to use READ_ONCE/WRITE_ONCE, or can you show what the exact issue is? Thanks, Ming