From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512230; b=4uT8BcNedtBi07UEQNvzor0nhUwWc5q58ToxjBTry6SHUR6e2XAO9gPwY7GRoF2EnHf4 cc7ntTdfj91rR32zKrATqR6qin3ZAVRnWtPZjvofcdPP3kzfCllbbtP8wxys41KRvQXZH OKv666CzJZsiCoyNfNy8ZBEaexumyX/zkRpx4hmLoOcTfxwOEqnhBSoEGX4lrbMh47Pys jy7n3fqTUMY9HW5niOpnNQTfcVbQUDiSHUqgnXv9Oe5Q8Q4mA2UK+kqMQayUooccIoghZ p1tU9kM9Q+9cez+B5NgSTOGtQXXQ0Mvs0p9oIhnY7UjfmvWgyrzRZyopKSXnJ0DRAeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512230; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=AN+EiFZOKWA+gQwHk/+UmkKzN6kvSd+1Gx1lk9c7dHY=; b=Nwc+8gZmyIVkAOQoHsMM568pVgeruHzZWExblkpbkShWa2EnMZZ8gCBJI0qw0qOo9UIT q6bYKUtXy2+S58dEXDbKAFK1BR5dFApCdFkUq1oXGtxh86tA6Pg1EfQ+XJ0w3pz6bXpjC HDaUnRaopE/6eVOzU7bL2HvcRxZ1eD5JShSSQMAz4mTDtKMnry7TnHSqouoVwVMVkvEHn Rtvq+Wzb01Mvauv7lqIRuPZUawV18UpZFq3VYjuQhhJHAHrnpVSn2oEG/YS9cbvVMnYtI 1sSsehR/S8guaPX3XLaz5z5PJbiF859xOut5nVaXJiTD912Q8pgQ06VQL3Ajgno7kyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=RoQvJxVG; arc=none smtp.remote-ip=209.85.161.47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA8C0606A322 for ; Sat, 5 Dec 2026 23:10:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA8C0606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=RoQvJxVG Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-70b875f6f1fso1622753eaf.2 for ; Sat, 05 Dec 2026 15:10:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512229; x=1797117029; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AN+EiFZOKWA+gQwHk/+UmkKzN6kvSd+1Gx1lk9c7dHY=; b=RoQvJxVGQX+yiapUyPjc8F5GWT6cQg2Kx2ZYg5Y6JkyY99afwe5vY9xkLBg9VdvTcy p/ATzdfmD050NxRYQgPiBQxIpvMbDf04SOAq83p2+AZPI4uXn65qov+1OqdzpH+ZnvId 8gmtIyp706jW/Eag+Qh9aeJCRlwL60+5B+RUyEd1/4QB3/he5EXayM8qpI2G6xr1Hc1W vfXkAqxfo/vNGOisMA6V0IYSCbyhmb2t5wfvN3yiWCMcAYVsrYk440vkpsaWQtMxo6m2 WTggji14+Jv6hHSO8oJl8im4ZL821KbXvDYLlRtLtvr8Dy/Q58nSHd48y7XfbqrCfltG 809A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512229; x=1797117029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AN+EiFZOKWA+gQwHk/+UmkKzN6kvSd+1Gx1lk9c7dHY=; b=cbFvbsyOYwU/W6jmY4JVI+vHz1rWn12Ypri8MNqgWoT5N8+iHHkOAC8K2y8oD2FHAG R4S5dCfcd53YOLu5qaGS8wTbujyZbi637srzf9fhxGevgEZ9uqPSoEPIuNIZf8OG46XG mclXsClPdyFiY+TQb34gHKSJCMxd/tbEXYUqYs8R2Zc0dW0Vy7JXHF6A1KCD0icjLF2/ XoPfZidYGq1gT316y2ZdTOZEdXlgudt/DkcD5Vi1bBanEbFTSZa0ut3cVdrejME5Gs5b vEm7XSj2gjiaJu9VUWwZQKIIokR4rVp3zNaa3jxEgQPdXrjjw5DTJ8zhySNPcyOqDxvL 3LEQ== X-Gm-Message-State: APuU4Z+Atia7P2IP1A7ZB72KeQFpj3Vw99ao5xjo5vy2Fl9i1K+R7TJH +hguTk90hYQb38CTtX1MlL+B5kvEF1pyhV+b0Vbb4cwAOTVOXM7yKzgjKbOlGPt27VzaPwVag0o NJN8kxGg= X-Gm-Gg: AZFdTZfjKGQ+BG8MvkNH9/1XEI8THGzuBSJCGVxo6o41dbgkFWO6TSx7kHD38uq6UW7 MqVAFYzDz2fiVmncEj/TOxacHFALqwYwxZofMf+0sohNO+mlupqaAxMhOcQGO7fQD7rqCVtMxbT Hq8tJfaBxAVfIy9+HsrLV5z3C3FtZ8XkptAy+HEc13nUwj6N80BHTmnNKaJ6QLgEtNktMseRdiy YfitpCd/Pfe7LEHa3uPUPHiK5PwDns4u4Pt2RaMEVn2N+TXgXSpV0WLQmAPKHjr4D7xodkwNNYe 9bWcDKFJLPVAZL6y16imvObmyhSWC2Q5G8hiz5WfA/TKXd5y4Aymkqw9xZWaiuBzA2bxA+UnGi8 TTj9TEiPpPXKRc771Efuo4+8sD4Vy3CvKuIxi0qLsykQVPPCUPManO7kWG4MXS0V6dEM4fMupgR l5kjJaEbsY9qgow0WqRpf8ESsg1HWeuZmSggfpL3/8+WUWISK/elNlX5YF4KVVQaEIOwtXq5XDv DKNIbNvvrwK4MsQFyTpgmXXAcHKOUAabWjLL3kzcdZgfxUYpBoSbfF+iEn7scP8rHpBIquQl6W2 UERt6ShxgU8h4cGCUnJFNHxJUK7A3kEs8Wotli2QuXbt5px+4zWuJnl4S7AG0YXiUclkUmrhHv1 WA340rTYqHhzsIkoQt+3TcQ9TvaD1ukTNw9Dn X-Received: by 2002:a05:6820:1c84:b0:71a:f5b7:e0ce with SMTP id 006d021491bc7-71bf203a970mr5392809eaf.24.1796512228787; Sat, 05 Dec 2026 15:10:28 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f8313082sm6309624a34.16.2026.12.05.15.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:10:27 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.1.y 7/9] io_uring/timeout: flush timeouts outside of the timeout lock Date: Sat, 5 Dec 2026 23:10:10 +0000 Message-ID: <20261205231012.3977993-8-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231012.3977993-1-axboe@kernel.dk> References: <20261205231012.3977993-1-axboe@kernel.dk> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit a9c83a0ab66a5b02e914daed502fb8d3a8d3d619 upstream. syzbot reports that a recent fix causes nesting issues between the (now) raw timeoutlock and the eventfd locking: ============================= [ BUG: Invalid wait context ] 6.13.0-rc4-00080-g9828a4c0901f #29 Not tainted ----------------------------- kworker/u32:0/68094 is trying to lock: ffff000014d7a520 (&ctx->wqh#2){..-.}-{3:3}, at: eventfd_signal_mask+0x64/0x180 other info that might help us debug this: context-{5:5} 6 locks held by kworker/u32:0/68094: #0: ffff0000c1d98148 ((wq_completion)iou_exit){+.+.}-{0:0}, at: process_one_work+0x4e8/0xfc0 #1: ffff80008d927c78 ((work_completion)(&ctx->exit_work)){+.+.}-{0:0}, at: process_one_work+0x53c/0xfc0 #2: ffff0000c59bc3d8 (&ctx->completion_lock){+.+.}-{3:3}, at: io_kill_timeouts+0x40/0x180 #3: ffff0000c59bc358 (&ctx->timeout_lock){-.-.}-{2:2}, at: io_kill_timeouts+0x48/0x180 #4: ffff800085127aa0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x8/0x38 #5: ffff800085127aa0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x8/0x38 stack backtrace: CPU: 7 UID: 0 PID: 68094 Comm: kworker/u32:0 Not tainted 6.13.0-rc4-00080-g9828a4c0901f #29 Hardware name: linux,dummy-virt (DT) Workqueue: iou_exit io_ring_exit_work Call trace: show_stack+0x1c/0x30 (C) __dump_stack+0x24/0x30 dump_stack_lvl+0x60/0x80 dump_stack+0x14/0x20 __lock_acquire+0x19f8/0x60c8 lock_acquire+0x1a4/0x540 _raw_spin_lock_irqsave+0x90/0xd0 eventfd_signal_mask+0x64/0x180 io_eventfd_signal+0x64/0x108 io_req_local_work_add+0x294/0x430 __io_req_task_work_add+0x1c0/0x270 io_kill_timeout+0x1f0/0x288 io_kill_timeouts+0xd4/0x180 io_uring_try_cancel_requests+0x2e8/0x388 io_ring_exit_work+0x150/0x550 process_one_work+0x5e8/0xfc0 worker_thread+0x7ec/0xc80 kthread+0x24c/0x300 ret_from_fork+0x10/0x20 because after the preempt-rt fix for the timeout lock nesting inside the io-wq lock, we now have the eventfd spinlock nesting inside the raw timeout spinlock. Rather than play whack-a-mole with other nesting on the timeout lock, split the deletion and killing of timeouts so queueing the task_work for the timeout cancelations can get done outside of the timeout lock. Reported-by: syzbot+b1fc199a40b65d601b65@syzkaller.appspotmail.com Fixes: 020b40f35624 ("io_uring: make ctx->timeout_lock a raw spinlock") Signed-off-by: Jens Axboe [axboe: 6.1 passes the task rather than the tctx to io_kill_timeouts() and io_match_task(), takes the completion lock there with io_cq_lock(), and calls io_flush_timeouts() with the completion lock held] --- io_uring/timeout.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/io_uring/timeout.c b/io_uring/timeout.c index 4c523dce3746..885139d7542b 100644 --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -49,7 +49,27 @@ static inline void io_put_req(struct io_kiocb *req) } } -static bool io_kill_timeout(struct io_kiocb *req, int status) +static __cold bool io_flush_killed_timeouts(struct list_head *list, int err) +{ + if (list_empty(list)) + return false; + + while (!list_empty(list)) { + struct io_timeout *timeout; + struct io_kiocb *req; + + timeout = list_first_entry(list, struct io_timeout, list); + list_del_init(&timeout->list); + req = cmd_to_io_kiocb(timeout); + if (err) + req_set_fail(req); + io_req_queue_tw_complete(req, err); + } + + return true; +} + +static void io_kill_timeout(struct io_kiocb *req, struct list_head *list) __must_hold(&req->ctx->completion_lock) __must_hold(&req->ctx->timeout_lock) { @@ -58,22 +78,18 @@ static bool io_kill_timeout(struct io_kiocb *req, int status) if (hrtimer_try_to_cancel(&io->timer) != -1) { struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout); - if (status) - req_set_fail(req); atomic_set(&req->ctx->cq_timeouts, atomic_read(&req->ctx->cq_timeouts) + 1); - list_del_init(&timeout->list); - io_req_queue_tw_complete(req, status); - return true; + list_move_tail(&timeout->list, list); } - return false; } __cold void io_flush_timeouts(struct io_ring_ctx *ctx) __must_hold(&ctx->completion_lock) { - u32 seq; struct io_timeout *timeout, *tmp; + LIST_HEAD(list); + u32 seq; raw_spin_lock_irq(&ctx->timeout_lock); seq = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts); @@ -105,10 +121,11 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx) if (events_got < events_needed) break; - io_kill_timeout(req, 0); + io_kill_timeout(req, &list); } ctx->cq_last_tm_flush = seq; raw_spin_unlock_irq(&ctx->timeout_lock); + io_flush_killed_timeouts(&list, 0); } static void io_req_tw_fail_links(struct io_kiocb *link, bool *locked) @@ -659,18 +676,18 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk, bool cancel_all) { struct io_timeout *timeout, *tmp; - int canceled = 0; + LIST_HEAD(list); io_cq_lock(ctx); raw_spin_lock_irq(&ctx->timeout_lock); list_for_each_entry_safe(timeout, tmp, &ctx->timeout_list, list) { struct io_kiocb *req = cmd_to_io_kiocb(timeout); - if (io_match_task(req, tsk, cancel_all) && - io_kill_timeout(req, -ECANCELED)) - canceled++; + if (io_match_task(req, tsk, cancel_all)) + io_kill_timeout(req, &list); } raw_spin_unlock_irq(&ctx->timeout_lock); io_cq_unlock_post(ctx); - return canceled != 0; + + return io_flush_killed_timeouts(&list, -ECANCELED); } -- 2.55.0