a298232ee6b9a1 ("io_uring: fix link timeout refs") was backported, however the second chunk of it got discarded, which breaks io_uring. It depends on another patch, so backport it first (patch 1/2) and then apply a298232ee6b9a1 again (patch 2/2).
It's a bit messy, the patch will be in the tree twice. Let me know if there is a better way.
Pavel Begunkov (2): io_uring: put link timeout req consistently io_uring: fix link timeout refs
fs/io_uring.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
[ Upstream commit df9727affa058f4f18e388b30247650f8ae13cd8 ]
Don't put linked timeout req in io_async_find_and_cancel() but do it in io_link_timeout_fn(), so we have only one point for that and won't have to do it differently as it's now (put vs put_deferred). Btw, improve a bit io_async_find_and_cancel()'s locking.
Signed-off-by: Pavel Begunkov asml.silence@gmail.com Link: https://lore.kernel.org/r/d75b70957f245275ab7cba83e0ac9c1b86aae78a.161728788... Signed-off-by: Jens Axboe axboe@kernel.dk --- fs/io_uring.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c index 58ac04cca587..930c5d5a2b0b 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -5727,12 +5727,9 @@ static void io_async_find_and_cancel(struct io_ring_ctx *ctx, int ret;
ret = io_async_cancel_one(req->task->io_uring, sqe_addr, ctx); - if (ret != -ENOENT) { - spin_lock_irqsave(&ctx->completion_lock, flags); - goto done; - } - spin_lock_irqsave(&ctx->completion_lock, flags); + if (ret != -ENOENT) + goto done; ret = io_timeout_cancel(ctx, sqe_addr); if (ret != -ENOENT) goto done; @@ -5747,7 +5744,6 @@ static void io_async_find_and_cancel(struct io_ring_ctx *ctx,
if (ret < 0) req_set_fail_links(req); - io_put_req(req); }
static int io_async_cancel_prep(struct io_kiocb *req, @@ -6310,8 +6306,8 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) io_put_req_deferred(req, 1); } else { io_req_complete_post(req, -ETIME, 0); - io_put_req_deferred(req, 1); } + io_put_req_deferred(req, 1); return HRTIMER_NORESTART; }
[ Upstream commit a298232ee6b9a1d5d732aa497ff8be0d45b5bd82 ]
WARNING: CPU: 0 PID: 10242 at lib/refcount.c:28 refcount_warn_saturate+0x15b/0x1a0 lib/refcount.c:28 RIP: 0010:refcount_warn_saturate+0x15b/0x1a0 lib/refcount.c:28 Call Trace: __refcount_sub_and_test include/linux/refcount.h:283 [inline] __refcount_dec_and_test include/linux/refcount.h:315 [inline] refcount_dec_and_test include/linux/refcount.h:333 [inline] io_put_req fs/io_uring.c:2140 [inline] io_queue_linked_timeout fs/io_uring.c:6300 [inline] __io_queue_sqe+0xbef/0xec0 fs/io_uring.c:6354 io_submit_sqe fs/io_uring.c:6534 [inline] io_submit_sqes+0x2bbd/0x7c50 fs/io_uring.c:6660 __do_sys_io_uring_enter fs/io_uring.c:9240 [inline] __se_sys_io_uring_enter+0x256/0x1d60 fs/io_uring.c:9182
io_link_timeout_fn() should put only one reference of the linked timeout request, however in case of racing with the master request's completion first io_req_complete() puts one and then io_put_req_deferred() is called.
Cc: stable@vger.kernel.org # 5.12+ Fixes: 9ae1f8dd372e0 ("io_uring: fix inconsistent lock state") Reported-by: syzbot+a2910119328ce8e7996f@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov asml.silence@gmail.com Link: https://lore.kernel.org/r/ff51018ff29de5ffa76f09273ef48cb24c720368.162041762... Signed-off-by: Jens Axboe axboe@kernel.dk --- fs/io_uring.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c index 930c5d5a2b0b..29a0af50a439 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6307,7 +6307,6 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) } else { io_req_complete_post(req, -ETIME, 0); } - io_put_req_deferred(req, 1); return HRTIMER_NORESTART; }
On Mon, Jul 19, 2021 at 12:54:21AM +0100, Pavel Begunkov wrote:
a298232ee6b9a1 ("io_uring: fix link timeout refs") was backported, however the second chunk of it got discarded, which breaks io_uring. It depends on another patch, so backport it first (patch 1/2) and then apply a298232ee6b9a1 again (patch 2/2).
It's a bit messy, the patch will be in the tree twice. Let me know if there is a better way.
Pavel Begunkov (2): io_uring: put link timeout req consistently io_uring: fix link timeout refs
fs/io_uring.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Not a problem, thanks for these. This is going to be the last 5.12.y release, so it shouldn't be that confusing.
thanks,
greg k-h
On 7/19/21 1:57 PM, Greg KH wrote:
On Mon, Jul 19, 2021 at 12:54:21AM +0100, Pavel Begunkov wrote:
a298232ee6b9a1 ("io_uring: fix link timeout refs") was backported, however the second chunk of it got discarded, which breaks io_uring. It depends on another patch, so backport it first (patch 1/2) and then apply a298232ee6b9a1 again (patch 2/2).
It's a bit messy, the patch will be in the tree twice. Let me know if there is a better way.
Pavel Begunkov (2): io_uring: put link timeout req consistently io_uring: fix link timeout refs
fs/io_uring.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Not a problem, thanks for these. This is going to be the last 5.12.y release, so it shouldn't be that confusing.
Perfect, thanks Greg
linux-stable-mirror@lists.linaro.org