Skip to content

Commit b24c5d7

Browse files
isilenceaxboe
authored andcommitted
io_uring: simplify big_cqe handling
Don't keep big_cqe bits of req in a union with hash_node, find a separate space for it. It's bit safer, but also if we keep it always initialised, we can get rid of ugly REQ_F_CQE32_INIT handling. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/447aa1b2968978c99e655ba88db536e903df0fe9.1692916914.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 31d3ba9 commit b24c5d7

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

include/linux/io_uring_types.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ enum {
409409
REQ_F_SINGLE_POLL_BIT,
410410
REQ_F_DOUBLE_POLL_BIT,
411411
REQ_F_PARTIAL_IO_BIT,
412-
REQ_F_CQE32_INIT_BIT,
413412
REQ_F_APOLL_MULTISHOT_BIT,
414413
REQ_F_CLEAR_POLLIN_BIT,
415414
REQ_F_HASH_LOCKED_BIT,
@@ -479,8 +478,6 @@ enum {
479478
REQ_F_PARTIAL_IO = BIT(REQ_F_PARTIAL_IO_BIT),
480479
/* fast poll multishot mode */
481480
REQ_F_APOLL_MULTISHOT = BIT(REQ_F_APOLL_MULTISHOT_BIT),
482-
/* ->extra1 and ->extra2 are initialised */
483-
REQ_F_CQE32_INIT = BIT(REQ_F_CQE32_INIT_BIT),
484481
/* recvmsg special flag, clear EPOLLIN */
485482
REQ_F_CLEAR_POLLIN = BIT(REQ_F_CLEAR_POLLIN_BIT),
486483
/* hashed into ->cancel_hash_locked, protected by ->uring_lock */
@@ -579,13 +576,7 @@ struct io_kiocb {
579576
struct io_task_work io_task_work;
580577
unsigned nr_tw;
581578
/* for polled requests, i.e. IORING_OP_POLL_ADD and async armed poll */
582-
union {
583-
struct hlist_node hash_node;
584-
struct {
585-
u64 extra1;
586-
u64 extra2;
587-
};
588-
};
579+
struct hlist_node hash_node;
589580
/* internal polling, see IORING_FEAT_FAST_POLL */
590581
struct async_poll *apoll;
591582
/* opcode allocated if it needs to store data for async defer */
@@ -595,6 +586,11 @@ struct io_kiocb {
595586
/* custom credentials, valid IFF REQ_F_CREDS is set */
596587
const struct cred *creds;
597588
struct io_wq_work work;
589+
590+
struct {
591+
u64 extra1;
592+
u64 extra2;
593+
} big_cqe;
598594
};
599595

600596
struct io_overflow_cqe {

io_uring/io_uring.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,13 +807,10 @@ static bool io_cqring_event_overflow(struct io_ring_ctx *ctx, u64 user_data,
807807

808808
void io_req_cqe_overflow(struct io_kiocb *req)
809809
{
810-
if (!(req->flags & REQ_F_CQE32_INIT)) {
811-
req->extra1 = 0;
812-
req->extra2 = 0;
813-
}
814810
io_cqring_event_overflow(req->ctx, req->cqe.user_data,
815811
req->cqe.res, req->cqe.flags,
816-
req->extra1, req->extra2);
812+
req->big_cqe.extra1, req->big_cqe.extra2);
813+
memset(&req->big_cqe, 0, sizeof(req->big_cqe));
817814
}
818815

819816
/*
@@ -1057,6 +1054,7 @@ static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
10571054
req->async_data = NULL;
10581055
/* not necessary, but safer to zero */
10591056
memset(&req->cqe, 0, sizeof(req->cqe));
1057+
memset(&req->big_cqe, 0, sizeof(req->big_cqe));
10601058
}
10611059

10621060
static void io_flush_cached_locked_reqs(struct io_ring_ctx *ctx,

io_uring/io_uring.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,12 @@ static inline bool io_fill_cqe_req(struct io_ring_ctx *ctx, struct io_kiocb *req
148148
if (trace_io_uring_complete_enabled())
149149
trace_io_uring_complete(req->ctx, req, req->cqe.user_data,
150150
req->cqe.res, req->cqe.flags,
151-
(req->flags & REQ_F_CQE32_INIT) ? req->extra1 : 0,
152-
(req->flags & REQ_F_CQE32_INIT) ? req->extra2 : 0);
151+
req->big_cqe.extra1, req->big_cqe.extra2);
153152

154153
memcpy(cqe, &req->cqe, sizeof(*cqe));
155-
156154
if (ctx->flags & IORING_SETUP_CQE32) {
157-
u64 extra1 = 0, extra2 = 0;
158-
159-
if (req->flags & REQ_F_CQE32_INIT) {
160-
extra1 = req->extra1;
161-
extra2 = req->extra2;
162-
}
163-
164-
WRITE_ONCE(cqe->big_cqe[0], extra1);
165-
WRITE_ONCE(cqe->big_cqe[1], extra2);
155+
memcpy(cqe->big_cqe, &req->big_cqe, sizeof(*cqe));
156+
memset(&req->big_cqe, 0, sizeof(req->big_cqe));
166157
}
167158
return true;
168159
}

io_uring/uring_cmd.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_do_in_task_lazy);
4343
static inline void io_req_set_cqe32_extra(struct io_kiocb *req,
4444
u64 extra1, u64 extra2)
4545
{
46-
req->extra1 = extra1;
47-
req->extra2 = extra2;
48-
req->flags |= REQ_F_CQE32_INIT;
46+
req->big_cqe.extra1 = extra1;
47+
req->big_cqe.extra2 = extra2;
4948
}
5049

5150
/*

0 commit comments

Comments
 (0)