Skip to content

Commit 326941b

Browse files
fengsxyaxboe
authored andcommitted
io_uring/poll: fix signed comparison in io_poll_get_ownership()
io_poll_get_ownership() uses a signed comparison to check whether poll_refs has reached the threshold for the slowpath: if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS)) atomic_read() returns int (signed). When IO_POLL_CANCEL_FLAG (BIT(31)) is set in poll_refs, the value becomes negative in signed arithmetic, so the >= 128 comparison always evaluates to false and the slowpath is never taken. Fix this by casting the atomic_read() result to unsigned int before the comparison, so that the cancel flag is treated as a large positive value and correctly triggers the slowpath. Fixes: a26a35e ("io_uring: make poll refs more robust") Cc: [email protected] Reported-by: Yifan Wu <[email protected]> Reported-by: Juefei Pu <[email protected]> Co-developed-by: Yuan Tan <[email protected]> Signed-off-by: Yuan Tan <[email protected]> Suggested-by: Xin Liu <[email protected]> Tested-by: Zhengchuan Liang <[email protected]> Signed-off-by: Longxuan Yu <[email protected]> Signed-off-by: Ren Wei <[email protected]> Reviewed-by: Pavel Begunkov <[email protected]> Link: https://patch.msgid.link/3a3508b08bcd7f1bc3beff848ae6e1d73d355043.1775965597.git.ylong030@ucr.edu Signed-off-by: Jens Axboe <[email protected]>
1 parent 5bdb407 commit 326941b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

io_uring/poll.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static bool io_poll_get_ownership_slowpath(struct io_kiocb *req)
9393
*/
9494
static inline bool io_poll_get_ownership(struct io_kiocb *req)
9595
{
96-
if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
96+
if (unlikely((unsigned int)atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
9797
return io_poll_get_ownership_slowpath(req);
9898
return !(atomic_fetch_inc(&req->poll_refs) & IO_POLL_REF_MASK);
9999
}

0 commit comments

Comments
 (0)