Skip to content

Commit b3659a6

Browse files
isilenceaxboe
authored andcommitted
io_uring: change ->cqe_cached invariant for CQE32
With IORING_SETUP_CQE32 ->cqe_cached doesn't store a real address but rather an implicit offset into cqes. Store the real cqe pointer and increment it accordingly if CQE32. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/1ee1838cba16bed96381a006950b36ba640d998c.1655455613.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e8c328c commit b3659a6

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

io_uring/io_uring.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,8 @@ struct io_uring_cqe *__io_get_cqe(struct io_ring_ctx *ctx)
701701
{
702702
struct io_rings *rings = ctx->rings;
703703
unsigned int off = ctx->cached_cq_tail & (ctx->cq_entries - 1);
704-
unsigned int shift = 0;
705704
unsigned int free, queued, len;
706705

707-
if (ctx->flags & IORING_SETUP_CQE32)
708-
shift = 1;
709706

710707
/* userspace may cheat modifying the tail, be safe and do min */
711708
queued = min(__io_cqring_events(ctx), ctx->cq_entries);
@@ -715,11 +712,19 @@ struct io_uring_cqe *__io_get_cqe(struct io_ring_ctx *ctx)
715712
if (!len)
716713
return NULL;
717714

718-
ctx->cached_cq_tail++;
715+
if (ctx->flags & IORING_SETUP_CQE32) {
716+
off <<= 1;
717+
len <<= 1;
718+
}
719+
719720
ctx->cqe_cached = &rings->cqes[off];
720721
ctx->cqe_sentinel = ctx->cqe_cached + len;
722+
723+
ctx->cached_cq_tail++;
721724
ctx->cqe_cached++;
722-
return &rings->cqes[off << shift];
725+
if (ctx->flags & IORING_SETUP_CQE32)
726+
ctx->cqe_cached++;
727+
return &rings->cqes[off];
723728
}
724729

725730
static bool io_fill_cqe_aux(struct io_ring_ctx *ctx,

io_uring/io_uring.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@ static inline struct io_uring_cqe *io_get_cqe(struct io_ring_ctx *ctx)
2222
if (likely(ctx->cqe_cached < ctx->cqe_sentinel)) {
2323
struct io_uring_cqe *cqe = ctx->cqe_cached;
2424

25-
if (ctx->flags & IORING_SETUP_CQE32) {
26-
unsigned int off = ctx->cqe_cached - ctx->rings->cqes;
27-
28-
cqe += off;
29-
}
30-
3125
ctx->cached_cq_tail++;
3226
ctx->cqe_cached++;
27+
if (ctx->flags & IORING_SETUP_CQE32)
28+
ctx->cqe_cached++;
3329
return cqe;
3430
}
3531

0 commit comments

Comments
 (0)