io_uring/fdinfo: handle mixed sized CQEs
authorJens Axboe <axboe@kernel.dk>
Thu, 7 Aug 2025 20:09:57 +0000 (14:09 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 8 Aug 2025 15:24:49 +0000 (09:24 -0600)
Ensure that the CQ ring iteration handles differently sized CQEs, not
just a fixed 16b or 32b size per ring. These CQEs aren't possible just
yet, but prepare the fdinfo CQ ring dumping for handling them.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/fdinfo.c

index 9798d6fb4ec73bf174dd887e0eca561faaada2b1..5c733983876905cdb7527ac3266bdde0cfc94edc 100644 (file)
@@ -65,15 +65,12 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
        unsigned int sq_tail = READ_ONCE(r->sq.tail);
        unsigned int cq_head = READ_ONCE(r->cq.head);
        unsigned int cq_tail = READ_ONCE(r->cq.tail);
-       unsigned int cq_shift = 0;
        unsigned int sq_shift = 0;
-       unsigned int sq_entries, cq_entries;
+       unsigned int sq_entries;
        int sq_pid = -1, sq_cpu = -1;
        u64 sq_total_time = 0, sq_work_time = 0;
        unsigned int i;
 
-       if (ctx->flags & IORING_SETUP_CQE32)
-               cq_shift = 1;
        if (ctx->flags & IORING_SETUP_SQE128)
                sq_shift = 1;
 
@@ -125,18 +122,23 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
                seq_printf(m, "\n");
        }
        seq_printf(m, "CQEs:\t%u\n", cq_tail - cq_head);
-       cq_entries = min(cq_tail - cq_head, ctx->cq_entries);
-       for (i = 0; i < cq_entries; i++) {
-               unsigned int entry = i + cq_head;
-               struct io_uring_cqe *cqe = &r->cqes[(entry & cq_mask) << cq_shift];
+       while (cq_head < cq_tail) {
+               struct io_uring_cqe *cqe;
+               bool cqe32 = false;
 
+               cqe = &r->cqes[(cq_head & cq_mask)];
+               if (cqe->flags & IORING_CQE_F_32 || ctx->flags & IORING_SETUP_CQE32)
+                       cqe32 = true;
                seq_printf(m, "%5u: user_data:%llu, res:%d, flag:%x",
-                          entry & cq_mask, cqe->user_data, cqe->res,
+                          cq_head & cq_mask, cqe->user_data, cqe->res,
                           cqe->flags);
-               if (cq_shift)
+               if (cqe32)
                        seq_printf(m, ", extra1:%llu, extra2:%llu\n",
                                        cqe->big_cqe[0], cqe->big_cqe[1]);
                seq_printf(m, "\n");
+               cq_head++;
+               if (cqe32)
+                       cq_head++;
        }
 
        if (ctx->flags & IORING_SETUP_SQPOLL) {