Skip to content
/ linux Public

Commit 886695d

Browse files
axboeSasha Levin
authored andcommitted
io_uring/cancel: add IORING_ASYNC_CANCEL_USERDATA
[ Upstream commit 8165b56 ] Add a flag to explicitly match on user_data in the request for cancelation purposes. This is the default behavior if none of the other match flags are set, but if we ALSO want to match on user_data, then this flag can be set. Signed-off-by: Jens Axboe <axboe@kernel.dk> Stable-dep-of: 22dbb09 ("io_uring/cancel: de-unionize file and user_data in struct io_cancel_data") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ced782c commit 886695d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

include/uapi/linux/io_uring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,13 @@ enum io_uring_op {
276276
* request 'user_data'
277277
* IORING_ASYNC_CANCEL_ANY Match any request
278278
* IORING_ASYNC_CANCEL_FD_FIXED 'fd' passed in is a fixed descriptor
279+
* IORING_ASYNC_CANCEL_USERDATA Match on user_data, default for no other key
279280
*/
280281
#define IORING_ASYNC_CANCEL_ALL (1U << 0)
281282
#define IORING_ASYNC_CANCEL_FD (1U << 1)
282283
#define IORING_ASYNC_CANCEL_ANY (1U << 2)
283284
#define IORING_ASYNC_CANCEL_FD_FIXED (1U << 3)
285+
#define IORING_ASYNC_CANCEL_USERDATA (1U << 4)
284286

285287
/*
286288
* send/sendmsg and recv/recvmsg flags (sqe->ioprio)

io_uring/cancel.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,30 @@ struct io_cancel {
2525
};
2626

2727
#define CANCEL_FLAGS (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_FD | \
28-
IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED)
28+
IORING_ASYNC_CANCEL_ANY | IORING_ASYNC_CANCEL_FD_FIXED | \
29+
IORING_ASYNC_CANCEL_USERDATA)
2930

3031
/*
3132
* Returns true if the request matches the criteria outlined by 'cd'.
3233
*/
3334
bool io_cancel_req_match(struct io_kiocb *req, struct io_cancel_data *cd)
3435
{
36+
bool match_user_data = cd->flags & IORING_ASYNC_CANCEL_USERDATA;
37+
3538
if (req->ctx != cd->ctx)
3639
return false;
37-
if (cd->flags & IORING_ASYNC_CANCEL_ANY) {
40+
41+
if (!(cd->flags & (IORING_ASYNC_CANCEL_FD)))
42+
match_user_data = true;
43+
44+
if (cd->flags & IORING_ASYNC_CANCEL_ANY)
3845
goto check_seq;
39-
} else if (cd->flags & IORING_ASYNC_CANCEL_FD) {
46+
if (cd->flags & IORING_ASYNC_CANCEL_FD) {
4047
if (req->file != cd->file)
4148
return false;
42-
} else {
43-
if (req->cqe.user_data != cd->data)
44-
return false;
4549
}
50+
if (match_user_data && req->cqe.user_data != cd->data)
51+
return false;
4652
if (cd->flags & IORING_ASYNC_CANCEL_ALL) {
4753
check_seq:
4854
if (cd->seq == req->work.cancel_seq)

0 commit comments

Comments
 (0)