Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring: always do atomic put from iowq

io_uring always switches requests to atomic refcounting for iowq
execution before there is any parallilism by setting REQ_F_REFCOUNT,
and the flag is not cleared until the request completes. That should be
fine as long as the compiler doesn't make up a non existing value for
the flags, however KCSAN still complains when the request owner changes
oter flag bits:

BUG: KCSAN: data-race in io_req_task_cancel / io_wq_free_work
...
read to 0xffff888117207448 of 8 bytes by task 3871 on cpu 0:
req_ref_put_and_test io_uring/refs.h:22 [inline]

Skip REQ_F_REFCOUNT checks for iowq, we know it's set.

Reported-by: syzbot+903a2ad71fb3f1e47cf5@syzkaller.appspotmail.com
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/d880bc27fb8c3209b54641be4ff6ac02b0e5789a.1743679736.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
39051364 57ed58c1

+8 -1
+1 -1
io_uring/io_uring.c
··· 1796 1796 struct io_kiocb *req = container_of(work, struct io_kiocb, work); 1797 1797 struct io_kiocb *nxt = NULL; 1798 1798 1799 - if (req_ref_put_and_test(req)) { 1799 + if (req_ref_put_and_test_atomic(req)) { 1800 1800 if (req->flags & IO_REQ_LINK_FLAGS) 1801 1801 nxt = io_req_find_next(req); 1802 1802 io_free_req(req);
+7
io_uring/refs.h
··· 17 17 return atomic_inc_not_zero(&req->refs); 18 18 } 19 19 20 + static inline bool req_ref_put_and_test_atomic(struct io_kiocb *req) 21 + { 22 + WARN_ON_ONCE(!(data_race(req->flags) & REQ_F_REFCOUNT)); 23 + WARN_ON_ONCE(req_ref_zero_or_close_to_overflow(req)); 24 + return atomic_dec_and_test(&req->refs); 25 + } 26 + 20 27 static inline bool req_ref_put_and_test(struct io_kiocb *req) 21 28 { 22 29 if (likely(!(req->flags & REQ_F_REFCOUNT)))