Skip to content

Commit 2b7c6b9

Browse files
axboegregkh
authored andcommitted
io_uring/futex: only mark private futex waits as inflight
commit 4d327bb upstream. Inflight tracking of futex wait requests exists to ensure that do_exit() -> io_uring_files_cancel() cancels them before the mm goes away, as a private futex wait depends on the mm private futex hash staying alive for the duration of the request. Shared futexes have no such dependency. A FLAGS_SHARED request always resolves to either an inode based key or an mm-shared key, both of which fail futex_key_is_private() and hence always hash into the global futex hash, whose lifetime isn't tied to the mm. Only mark vectored futex waits as inflight if the futex is private. Cc: stable@vger.kernel.org Fixes: 079afb0 ("io_uring/futex: mark wait requests as inflight") Link: https://lore.kernel.org/io-uring/CANGjgdn=R_qyUdE=j9za+vkmqcxacbP-84OHXF4nZ4ho9qRyVg@mail.gmail.com/ Signed-off-by: Jens Axboe <axboe@kernel.dk> [ kept 6.18's `struct futex_vector *futexv` declaration and changed `ifd->futexv[i].w.flags` to `futexv[i].w.flags` since `struct io_futexv_data` is absent, retaining the `iof->futexv_owned = 0;` init ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b61ebb2 commit 2b7c6b9

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

io_uring/futex.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ int io_futex_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
149149

150150
int io_futex_wait_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
151151
{
152+
struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
152153
int ret;
153154

154155
ret = io_futex_prep(req, sqe);
155156
if (unlikely(ret))
156157
return ret;
157158

158-
/* Mark as inflight, so file exit cancelation will find it */
159-
io_req_track_inflight(req);
159+
/* inflight tracking only needed for mm private hash */
160+
if (!(iof->futex_flags & FLAGS_SHARED))
161+
io_req_track_inflight(req);
160162
return 0;
161163
}
162164

@@ -179,6 +181,7 @@ int io_futexv_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
179181
{
180182
struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
181183
struct futex_vector *futexv;
184+
unsigned int i;
182185
int ret;
183186

184187
/* No flags or mask supported for waitv */
@@ -202,8 +205,14 @@ int io_futexv_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
202205
return ret;
203206
}
204207

205-
/* Mark as inflight, so file exit cancelation will find it */
206-
io_req_track_inflight(req);
208+
/* inflight tracking only needed for mm private hash */
209+
for (i = 0; i < iof->futex_nr; i++) {
210+
if (!(futexv[i].w.flags & FLAGS_SHARED)) {
211+
io_req_track_inflight(req);
212+
break;
213+
}
214+
}
215+
207216
iof->futexv_owned = 0;
208217
iof->futexv_unqueued = 0;
209218
req->flags |= REQ_F_ASYNC_DATA;

0 commit comments

Comments
 (0)