Skip to content

Commit 079afb0

Browse files
committed
io_uring/futex: mark wait requests as inflight
Inflight marking is used so that do_exit() -> io_uring_files_cancel() will find requests with files that reference an io_uring instance, so they can get appropriately canceled before the files go away. However, it's also called before the mm goes away. Mark futex/futexv wait requests as being inflight, so that io_uring_files_cancel() will prune them. This ensures that the mm stays alive, which is important as an exiting mm will also free the futex private hash buckets. An io_uring futex request with FUTEX2_PRIVATE set relies on those being alive until the request has completed. A recent commit added these futex private hashes, which get killed when the mm goes away. Fixes: 80367ad ("futex: Add basic infrastructure for local task local hash") Link: https://lore.kernel.org/io-uring/38053.1749045482@localhost/ Reported-by: Robert Morris <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 6a8118a commit 079afb0

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

io_uring/futex.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ int io_futex_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
145145
!futex_validate_input(iof->futex_flags, iof->futex_mask))
146146
return -EINVAL;
147147

148+
/* Mark as inflight, so file exit cancelation will find it */
149+
io_req_track_inflight(req);
148150
return 0;
149151
}
150152

@@ -190,6 +192,8 @@ int io_futexv_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
190192
return ret;
191193
}
192194

195+
/* Mark as inflight, so file exit cancelation will find it */
196+
io_req_track_inflight(req);
193197
iof->futexv_owned = 0;
194198
iof->futexv_unqueued = 0;
195199
req->flags |= REQ_F_ASYNC_DATA;

io_uring/io_uring.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ static void io_clean_op(struct io_kiocb *req)
408408
req->flags &= ~IO_REQ_CLEAN_FLAGS;
409409
}
410410

411-
static inline void io_req_track_inflight(struct io_kiocb *req)
411+
/*
412+
* Mark the request as inflight, so that file cancelation will find it.
413+
* Can be used if the file is an io_uring instance, or if the request itself
414+
* relies on ->mm being alive for the duration of the request.
415+
*/
416+
inline void io_req_track_inflight(struct io_kiocb *req)
412417
{
413418
if (!(req->flags & REQ_F_INFLIGHT)) {
414419
req->flags |= REQ_F_INFLIGHT;

io_uring/io_uring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void io_add_aux_cqe(struct io_ring_ctx *ctx, u64 user_data, s32 res, u32 cflags)
8383
bool io_req_post_cqe(struct io_kiocb *req, s32 res, u32 cflags);
8484
void __io_commit_cqring_flush(struct io_ring_ctx *ctx);
8585

86+
void io_req_track_inflight(struct io_kiocb *req);
8687
struct file *io_file_get_normal(struct io_kiocb *req, int fd);
8788
struct file *io_file_get_fixed(struct io_kiocb *req, int fd,
8889
unsigned issue_flags);

0 commit comments

Comments
 (0)