Skip to content

Commit 518a178

Browse files
authored
Merge pull request #284 from arnaldo2792/io_uring-fix
Prevent io_uring calls from hanging
2 parents 4e4744a + 2139d84 commit 518a178

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
From 1863335f591d6a708fb5321fe10504174fddc9ee Mon Sep 17 00:00:00 2001
2+
From: Pavel Begunkov <asml.silence@gmail.com>
3+
Date: Wed, 10 Apr 2024 02:26:54 +0100
4+
Subject: [PATCH] io_uring: always lock __io_cqring_overflow_flush
5+
6+
Commit 8d09a88ef9d3cb7d21d45c39b7b7c31298d23998 upstream.
7+
8+
Conditional locking is never great, in case of
9+
__io_cqring_overflow_flush(), which is a slow path, it's not justified.
10+
Don't handle IOPOLL separately, always grab uring_lock for overflow
11+
flushing.
12+
13+
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
14+
Link: https://lore.kernel.org/r/162947df299aa12693ac4b305dacedab32ec7976.1712708261.git.asml.silence@gmail.com
15+
Signed-off-by: Jens Axboe <axboe@kernel.dk>
16+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17+
---
18+
io_uring/io_uring.c | 11 ++++++-----
19+
1 file changed, 6 insertions(+), 5 deletions(-)
20+
21+
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
22+
index f902b161f02c..92c1aa8f3501 100644
23+
--- a/io_uring/io_uring.c
24+
+++ b/io_uring/io_uring.c
25+
@@ -593,6 +593,8 @@ static bool __io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)
26+
bool all_flushed;
27+
size_t cqe_size = sizeof(struct io_uring_cqe);
28+
29+
+ lockdep_assert_held(&ctx->uring_lock);
30+
+
31+
if (!force && __io_cqring_events(ctx) == ctx->cq_entries)
32+
return false;
33+
34+
@@ -647,12 +649,9 @@ static bool io_cqring_overflow_flush(struct io_ring_ctx *ctx)
35+
bool ret = true;
36+
37+
if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {
38+
- /* iopoll syncs against uring_lock, not completion_lock */
39+
- if (ctx->flags & IORING_SETUP_IOPOLL)
40+
- mutex_lock(&ctx->uring_lock);
41+
+ mutex_lock(&ctx->uring_lock);
42+
ret = __io_cqring_overflow_flush(ctx, false);
43+
- if (ctx->flags & IORING_SETUP_IOPOLL)
44+
- mutex_unlock(&ctx->uring_lock);
45+
+ mutex_unlock(&ctx->uring_lock);
46+
}
47+
48+
return ret;
49+
@@ -1405,6 +1404,8 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min)
50+
int ret = 0;
51+
unsigned long check_cq;
52+
53+
+ lockdep_assert_held(&ctx->uring_lock);
54+
+
55+
if (!io_allowed_run_tw(ctx))
56+
return -EEXIST;
57+
58+
--
59+
2.47.0
60+

packages/kernel-6.1/kernel-6.1.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Patch1004: 1004-af_unix-increase-default-max_dgram_qlen-to-512.patch
4242
# Drop AL revert of upstream patch to minimize delta. The necessary dependency
4343
# options for nvidia are instead included through DRM_SIMPLE
4444
Patch1005: 1005-Revert-Revert-drm-fb_helper-improve-CONFIG_FB-depend.patch
45+
# Prevent applications using io_uring from hanging
46+
Patch1100: 1100-io_uring-always-lock-__io_cqring_overflow_flush.patch
4547

4648
BuildRequires: bc
4749
BuildRequires: elfutils-devel

0 commit comments

Comments
 (0)