Skip to content

Commit 38cfdd9

Browse files
committed
io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs
Add cond_resched() in those dump loops, just in case a lot of entries are being dumped. And detect invalid CQ ring head/tail entries, to avoid iterating more than what is necessary. Generally not an issue, but can be if things like KASAN or other debugging metrics are enabled. Reported-by: 是参差 <[email protected]> Link: https://lore.kernel.org/all/PS1PPF7E1D7501FE5631002D242DD89403FAB9BA@PS1PPF7E1D7501F.apcprd02.prod.outlook.com/ Reviewed-by: Keith Busch <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b1dfe4e commit 38cfdd9

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

io_uring/fdinfo.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
6767
unsigned int cq_head = READ_ONCE(r->cq.head);
6868
unsigned int cq_tail = READ_ONCE(r->cq.tail);
6969
unsigned int sq_shift = 0;
70-
unsigned int sq_entries;
70+
unsigned int cq_entries, sq_entries;
7171
int sq_pid = -1, sq_cpu = -1;
7272
u64 sq_total_time = 0, sq_work_time = 0;
7373
unsigned int i;
@@ -146,9 +146,11 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
146146
}
147147
}
148148
seq_printf(m, "\n");
149+
cond_resched();
149150
}
150151
seq_printf(m, "CQEs:\t%u\n", cq_tail - cq_head);
151-
while (cq_head < cq_tail) {
152+
cq_entries = min(cq_tail - cq_head, ctx->cq_entries);
153+
for (i = 0; i < cq_entries; i++) {
152154
struct io_uring_cqe *cqe;
153155
bool cqe32 = false;
154156

@@ -163,8 +165,11 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
163165
cqe->big_cqe[0], cqe->big_cqe[1]);
164166
seq_printf(m, "\n");
165167
cq_head++;
166-
if (cqe32)
168+
if (cqe32) {
167169
cq_head++;
170+
i++;
171+
}
172+
cond_resched();
168173
}
169174

170175
if (ctx->flags & IORING_SETUP_SQPOLL) {

0 commit comments

Comments
 (0)