Commit 326941b2 authored by Longxuan Yu's avatar Longxuan Yu Committed by Jens Axboe
Browse files

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: a26a35e9 ("io_uring: make poll refs more robust")
Cc: stable@vger.kernel.org
Reported-by: default avatarYifan Wu <yifanwucs@gmail.com>
Reported-by: default avatarJuefei Pu <tomapufckgml@gmail.com>
Co-developed-by: default avatarYuan Tan <yuantan098@gmail.com>
Signed-off-by: default avatarYuan Tan <yuantan098@gmail.com>
Suggested-by: default avatarXin Liu <bird@lzu.edu.cn>
Tested-by: default avatarZhengchuan Liang <zcliangcn@gmail.com>
Signed-off-by: default avatarLongxuan Yu <ylong030@ucr.edu>
Signed-off-by: default avatarRen Wei <n05ec@lzu.edu.cn>
Reviewed-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://patch.msgid.link/3a3508b08bcd7f1bc3beff848ae6e1d73d355043.1775965597.git.ylong030@ucr.edu


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 5bdb4078
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ static bool io_poll_get_ownership_slowpath(struct io_kiocb *req)
 */
static inline bool io_poll_get_ownership(struct io_kiocb *req)
{
	if (unlikely(atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
	if (unlikely((unsigned int)atomic_read(&req->poll_refs) >= IO_POLL_REF_BIAS))
		return io_poll_get_ownership_slowpath(req);
	return !(atomic_fetch_inc(&req->poll_refs) & IO_POLL_REF_MASK);
}