Skip to content

Commit c80bdb1

Browse files
committed
io_uring: pass in struct io_big_cqe to io_alloc_ocqe()
Rather than pass extra1/extra2 separately, just pass in the (now) named io_big_cqe struct instead. The callers that don't use/support CQE32 will now just pass a single NULL, rather than two seperate mystery zero values. Move the clearing of the big_cqe elements into io_alloc_ocqe() as well, so it can get moved out of the generic code. Reviewed-by: Caleb Sander Mateos <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 072d37b commit c80bdb1

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

include/linux/io_uring_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ struct io_kiocb {
710710
const struct cred *creds;
711711
struct io_wq_work work;
712712

713-
struct {
713+
struct io_big_cqe {
714714
u64 extra1;
715715
u64 extra2;
716716
} big_cqe;

io_uring/io_uring.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ static bool io_cqring_add_overflow(struct io_ring_ctx *ctx,
724724
}
725725

726726
static struct io_overflow_cqe *io_alloc_ocqe(struct io_ring_ctx *ctx,
727-
struct io_cqe *cqe, u64 extra1,
728-
u64 extra2, gfp_t gfp)
727+
struct io_cqe *cqe,
728+
struct io_big_cqe *big_cqe, gfp_t gfp)
729729
{
730730
struct io_overflow_cqe *ocqe;
731731
size_t ocq_size = sizeof(struct io_overflow_cqe);
@@ -734,17 +734,19 @@ static struct io_overflow_cqe *io_alloc_ocqe(struct io_ring_ctx *ctx,
734734
if (is_cqe32)
735735
ocq_size += sizeof(struct io_uring_cqe);
736736

737-
ocqe = kmalloc(ocq_size, gfp | __GFP_ACCOUNT);
737+
ocqe = kzalloc(ocq_size, gfp | __GFP_ACCOUNT);
738738
trace_io_uring_cqe_overflow(ctx, cqe->user_data, cqe->res, cqe->flags, ocqe);
739739
if (ocqe) {
740740
ocqe->cqe.user_data = cqe->user_data;
741741
ocqe->cqe.res = cqe->res;
742742
ocqe->cqe.flags = cqe->flags;
743-
if (is_cqe32) {
744-
ocqe->cqe.big_cqe[0] = extra1;
745-
ocqe->cqe.big_cqe[1] = extra2;
743+
if (is_cqe32 && big_cqe) {
744+
ocqe->cqe.big_cqe[0] = big_cqe->extra1;
745+
ocqe->cqe.big_cqe[1] = big_cqe->extra2;
746746
}
747747
}
748+
if (big_cqe)
749+
big_cqe->extra1 = big_cqe->extra2 = 0;
748750
return ocqe;
749751
}
750752

@@ -821,7 +823,7 @@ bool io_post_aux_cqe(struct io_ring_ctx *ctx, u64 user_data, s32 res, u32 cflags
821823
struct io_overflow_cqe *ocqe;
822824
struct io_cqe cqe = io_init_cqe(user_data, res, cflags);
823825

824-
ocqe = io_alloc_ocqe(ctx, &cqe, 0, 0, GFP_ATOMIC);
826+
ocqe = io_alloc_ocqe(ctx, &cqe, NULL, GFP_ATOMIC);
825827
filled = io_cqring_add_overflow(ctx, ocqe);
826828
}
827829
io_cq_unlock_post(ctx);
@@ -841,7 +843,7 @@ void io_add_aux_cqe(struct io_ring_ctx *ctx, u64 user_data, s32 res, u32 cflags)
841843
struct io_overflow_cqe *ocqe;
842844
struct io_cqe cqe = io_init_cqe(user_data, res, cflags);
843845

844-
ocqe = io_alloc_ocqe(ctx, &cqe, 0, 0, GFP_KERNEL);
846+
ocqe = io_alloc_ocqe(ctx, &cqe, NULL, GFP_KERNEL);
845847
spin_lock(&ctx->completion_lock);
846848
io_cqring_add_overflow(ctx, ocqe);
847849
spin_unlock(&ctx->completion_lock);
@@ -1451,17 +1453,14 @@ void __io_submit_flush_completions(struct io_ring_ctx *ctx)
14511453
gfp_t gfp = ctx->lockless_cq ? GFP_KERNEL : GFP_ATOMIC;
14521454
struct io_overflow_cqe *ocqe;
14531455

1454-
ocqe = io_alloc_ocqe(ctx, &req->cqe, req->big_cqe.extra1,
1455-
req->big_cqe.extra2, gfp);
1456+
ocqe = io_alloc_ocqe(ctx, &req->cqe, &req->big_cqe, gfp);
14561457
if (ctx->lockless_cq) {
14571458
spin_lock(&ctx->completion_lock);
14581459
io_cqring_add_overflow(ctx, ocqe);
14591460
spin_unlock(&ctx->completion_lock);
14601461
} else {
14611462
io_cqring_add_overflow(ctx, ocqe);
14621463
}
1463-
1464-
memset(&req->big_cqe, 0, sizeof(req->big_cqe));
14651464
}
14661465
}
14671466
__io_cq_unlock_post(ctx);

0 commit comments

Comments
 (0)