public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs
@ 2026-02-03 17:06 Jens Axboe
  2026-02-03 17:54 ` Keith Busch
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2026-02-03 17:06 UTC (permalink / raw)
  To: io-uring; +Cc: 是参差

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: ??? <shicenci@gmail.com>
Link: https://lore.kernel.org/all/PS1PPF7E1D7501FE5631002D242DD89403FAB9BA@PS1PPF7E1D7501F.apcprd02.prod.outlook.com/
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c
index 4f12e98b22c3..80178b69e05a 100644
--- a/io_uring/fdinfo.c
+++ b/io_uring/fdinfo.c
@@ -67,7 +67,7 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
 	unsigned int cq_head = READ_ONCE(r->cq.head);
 	unsigned int cq_tail = READ_ONCE(r->cq.tail);
 	unsigned int sq_shift = 0;
-	unsigned int sq_entries;
+	unsigned int cq_entries, sq_entries;
 	int sq_pid = -1, sq_cpu = -1;
 	u64 sq_total_time = 0, sq_work_time = 0;
 	unsigned int i;
@@ -146,9 +146,11 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
 			}
 		}
 		seq_printf(m, "\n");
+		cond_resched();
 	}
 	seq_printf(m, "CQEs:\t%u\n", cq_tail - cq_head);
-	while (cq_head < cq_tail) {
+	cq_entries = min(cq_tail - cq_head, ctx->cq_entries);
+	for (i = 0; i < cq_entries; i++) {
 		struct io_uring_cqe *cqe;
 		bool cqe32 = false;
 
@@ -163,8 +165,11 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
 					cqe->big_cqe[0], cqe->big_cqe[1]);
 		seq_printf(m, "\n");
 		cq_head++;
-		if (cqe32)
+		if (cqe32) {
 			cq_head++;
+			i++;
+		}
+		cond_resched();
 	}
 
 	if (ctx->flags & IORING_SETUP_SQPOLL) {

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs
  2026-02-03 17:06 [PATCH] io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs Jens Axboe
@ 2026-02-03 17:54 ` Keith Busch
  2026-02-03 17:56   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Busch @ 2026-02-03 17:54 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, 是参差

On Tue, Feb 03, 2026 at 10:06:18AM -0700, Jens Axboe wrote:
> 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

Hey, another cond_resched that lazy preemption would make unnecessary!
Looks good anyway.

Reviewed-by: Keith Busch <kbusch@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs
  2026-02-03 17:54 ` Keith Busch
@ 2026-02-03 17:56   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-02-03 17:56 UTC (permalink / raw)
  To: Keith Busch; +Cc: io-uring, 是参差

On 2/3/26 10:54 AM, Keith Busch wrote:
> On Tue, Feb 03, 2026 at 10:06:18AM -0700, Jens Axboe wrote:
>> 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
> 
> Hey, another cond_resched that lazy preemption would make unnecessary!

Yeah exactly...

> Looks good anyway.
> 
> Reviewed-by: Keith Busch <kbusch@kernel.org>

Thanks!

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-03 17:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 17:06 [PATCH] io_uring/fdinfo: be a bit nicer when looping a lot of SQEs/CQEs Jens Axboe
2026-02-03 17:54 ` Keith Busch
2026-02-03 17:56   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox