Skip to content

Commit 26a6167

Browse files
committed
io_uring: read 'count' for IORING_OP_TIMEOUT in prep handler
Add the count field to struct io_timeout, and ensure the prep handler has read it. Timeout also needs an async context always, set it up in the prep handler if we don't have one. Signed-off-by: Jens Axboe <[email protected]>
1 parent e47293f commit 26a6167

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/io_uring.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ struct io_timeout {
330330
struct file *file;
331331
u64 addr;
332332
int flags;
333+
unsigned count;
333334
};
334335

335336
struct io_rw {
@@ -2902,7 +2903,12 @@ static int io_timeout_prep(struct io_kiocb *req, struct io_async_ctx *io,
29022903
if (flags & ~IORING_TIMEOUT_ABS)
29032904
return -EINVAL;
29042905

2905-
data = &io->timeout;
2906+
req->timeout.count = READ_ONCE(sqe->off);
2907+
2908+
if (!io && io_alloc_async_ctx(req))
2909+
return -ENOMEM;
2910+
2911+
data = &req->io->timeout;
29062912
data->req = req;
29072913
req->flags |= REQ_F_TIMEOUT;
29082914

@@ -2920,7 +2926,6 @@ static int io_timeout_prep(struct io_kiocb *req, struct io_async_ctx *io,
29202926

29212927
static int io_timeout(struct io_kiocb *req)
29222928
{
2923-
const struct io_uring_sqe *sqe = req->sqe;
29242929
unsigned count;
29252930
struct io_ring_ctx *ctx = req->ctx;
29262931
struct io_timeout_data *data;
@@ -2942,7 +2947,7 @@ static int io_timeout(struct io_kiocb *req)
29422947
* timeout event to be satisfied. If it isn't set, then this is
29432948
* a pure timeout request, sequence isn't used.
29442949
*/
2945-
count = READ_ONCE(sqe->off);
2950+
count = req->timeout.count;
29462951
if (!count) {
29472952
req->flags |= REQ_F_TIMEOUT_NOSEQ;
29482953
spin_lock_irq(&ctx->completion_lock);

0 commit comments

Comments
 (0)