From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512227; b=kkEHVsQE4TuN0lEEnZLxpIYQxlySUL3e2UfTJ4Ka5HW525IURHuf3etfxeUxBvJVmlG5 dDCskIfBFG8RCvmmKpBbeAeO7XI4JMa25X431Nya8F0uLE7izkqYg43U2oPzfjzpDDlyY 3u0f33bzmnfoU18hEY93uearIIHJQN1b7AkxOF9aPBIgoeEY5R49r3G5ccn/sosfEI015 83X/hj5qIDpgBELPjLSh/Eqv1DNOnNvcTcp4tMdJauuBCl06aFWgryh+/84/gnfErn9t1 56MVJBK2bXHk/tPd5ikRMIhhz0ARMe9W7ys48tW4BM7zaCYeZNOXNUMct6cBGFNeWcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512227; 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=tv6iS7+obNtltjDgJzv2tVEeAw++UZjIXyE5uYaNXxQ=; b=C9B9rgz6ojhy5+9cWSkl2ZM0wqLdni6xYq0We6LNv7rePFthaUjQfqg91LnAhCdtIE5E 7b5n8+KRkUPmD7GMXYfTsM8vfguOrCSs8i5aSnHoHuEANhwnPF1ySLv4eoByM6FjsS5nU g1JyNvex7wf/uoYSEXQrTWU76ek9QwjmJgvHCHx0oUzFZj2M4HjJOqS3bQV1pbkxmHUXY 0b86LY69eqLvHGWQABRf3bzL90b+NO7/VeDStfuTw9fao/ISbBE5qlSd3dF1YhBRbOTFp EPtLLk3EOSgLE7tyznGyW8MxQN7atE6O38pDd/GjZev9tTD06fopNc8oxxiP+/Wt1cQ== 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=wtskGcO2; arc=none smtp.remote-ip=209.85.161.44 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (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 5FB6A606A322 for ; Sat, 5 Dec 2026 23:10:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5FB6A606A322 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=wtskGcO2 Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-702fd86d674so1647495eaf.2 for ; Sat, 05 Dec 2026 15:10:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512226; x=1797117026; 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=tv6iS7+obNtltjDgJzv2tVEeAw++UZjIXyE5uYaNXxQ=; b=wtskGcO29+9MW77IpJoKTRo+Xuvl605Gmq8ArLnBiQ8oXvfCJyE3NBmeKEpVBTUSXP aWvQul/Fh5Xj9w3xkH6CFkJGdzIM9EhM87xlxi5GfmyaxgDrybmPYmwvbNhpEmsdYwjQ NvXZBmC1IxjJtRhrbB4ImRPA6JvwCMiuI1cQON7h6EtJK2E/SjgIYH8HME++HD8Hms2q wUD8uMwagDnTeqc1ZzRbDh8Wv2FxCA0vHXlkDx6q/630+WHbaA7zFID0MOeRoOhc+dRJ k6lNJNVReqtfNDJsDRXafZxMt4S7CzMzTCLvRF2pBp0e5sXVxkqbUgVsYT4+2DHJBX3x 6Lbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512226; x=1797117026; 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=tv6iS7+obNtltjDgJzv2tVEeAw++UZjIXyE5uYaNXxQ=; b=tWlLL0VnDjv62wvy1u9YGVpVtigrzIjDxCcdEFDI47/poYHL+P7ll5P27slh2S8sfA WAEPeqfOqjF3ouFWYlUzc+Ab8rp3gwWnyInBiWJgNZIqFOOPV7rY6CxC2ZNQw/zxhnQM r0LhWrIKiGrGcsSqUIhgf6BpPWGDx1UE+hRv4/IXrbGr0pIib/8e/kVpIqhAuOx+sSGQ NSvaxhp8/bG2IZlLHRRSvzNgH55JXHKUuBF/PnPjEgy4iljS6eez/0xdWkbxQaxvdLG8 sj1B4f2mzvFokk78zK/cqM4w8LPLcrbpRNEM1M+dlC8rO8X7R5Lh/um1QLSl9SXeU2wC ZseQ== X-Gm-Message-State: APuU4Z/nKdp3XlL40nDP0vhspjNkxlIL+MrP5u8+AkdPBdKVoIId+tzp GKQMkJi16OvgouDYlHivMxB9VQqS9blDvr4Vlv/T5DW8a900g73MNtz2I4bAXQf7qd8= X-Gm-Gg: AZFdTZf1nOSaw+kz9C9XRl1yoXoKV/pj10kOr5KxS3r2FuhgCBThYSJe9A6R01Lm//C yC0pYjxGWV7QllwRf9stDS4LgGHU2W8/DdPjDpxPCe2nim8Ve9fPH/mPZQaEf2GmFkeiKgmL54p AxFNaIBkRykjj5MDfnvcoAV6DhvnqD+Y0AQB7pQbtGvBz2HAFPEh8JgZB9Z7uZHsOIwkcAPxBVd aN7qpeqyn6nGbfRMA7Wx26wGkk1WfBHF08geGVhCzqGle9dzwg+/b6/zEI8bMDVMe2k04sZptpf W84mffjIeL732X73byRXH2WEyD758Ut5kgptGPAqBCvSGBwOqNV/Nu+t6QtPsMPEtPUIOc6MfCx eOwnwnLlsMWWx4RUibkzlau6en25Uuh1NhKCDhRc/VkJPwVFHv5nztIfSSoFDA+etrboUGdEjmt dl5BZw0pcgvJ+8ew3em68OM2UcNl/yM5tmZdelbm9ZNQfs3abi5th2h9gyG5kJVifMCsNKInvQn 4EiGiB8v/BYgbN+LSu2DTI2lJxMjaOWak0kvs+I8mVbX9WtN2RjgwSQsVCn3mXvyEkB6AfjQ9EP VHIcom0Rp6OFlWps2PnAPx4BsTixjgecsUr8/UAft3QnYhx11ij95N2Kn8F04wq1GO74/xxNHtw fz8TF3U2sJ2Qn/0b14+AEYv1zzoTUVNJffRcn X-Received: by 2002:a05:6820:221a:b0:713:da3b:8b2d with SMTP id 006d021491bc7-71bf2070113mr5228491eaf.29.1796512226300; Sat, 05 Dec 2026 15:10:26 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f8313082sm6309624a34.16.2026.12.05.15.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:10:25 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.1.y 6/9] io_uring: make ctx->timeout_lock a raw spinlock Date: Sat, 5 Dec 2026 23:10:09 +0000 Message-ID: <20261205231012.3977993-7-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: io-uring@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 020b40f3562495f3c703a283ece145ffec19e82d upstream. Chase reports that their tester complaints about a locking context mismatch: ============================= [ BUG: Invalid wait context ] 6.13.0-rc1-gf137f14b7ccb-dirty #9 Not tainted ----------------------------- syz.1.25198/182604 is trying to lock: ffff88805e66a358 (&ctx->timeout_lock){-.-.}-{3:3}, at: spin_lock_irq include/linux/spinlock.h:376 [inline] ffff88805e66a358 (&ctx->timeout_lock){-.-.}-{3:3}, at: io_match_task_safe io_uring/io_uring.c:218 [inline] ffff88805e66a358 (&ctx->timeout_lock){-.-.}-{3:3}, at: io_match_task_safe+0x187/0x250 io_uring/io_uring.c:204 other info that might help us debug this: context-{5:5} 1 lock held by syz.1.25198/182604: #0: ffff88802b7d48c0 (&acct->lock){+.+.}-{2:2}, at: io_acct_cancel_pending_work+0x2d/0x6b0 io_uring/io-wq.c:1049 stack backtrace: CPU: 0 UID: 0 PID: 182604 Comm: syz.1.25198 Not tainted 6.13.0-rc1-gf137f14b7ccb-dirty #9 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x82/0xd0 lib/dump_stack.c:120 print_lock_invalid_wait_context kernel/locking/lockdep.c:4826 [inline] check_wait_context kernel/locking/lockdep.c:4898 [inline] __lock_acquire+0x883/0x3c80 kernel/locking/lockdep.c:5176 lock_acquire.part.0+0x11b/0x370 kernel/locking/lockdep.c:5849 __raw_spin_lock_irq include/linux/spinlock_api_smp.h:119 [inline] _raw_spin_lock_irq+0x36/0x50 kernel/locking/spinlock.c:170 spin_lock_irq include/linux/spinlock.h:376 [inline] io_match_task_safe io_uring/io_uring.c:218 [inline] io_match_task_safe+0x187/0x250 io_uring/io_uring.c:204 io_acct_cancel_pending_work+0xb8/0x6b0 io_uring/io-wq.c:1052 io_wq_cancel_pending_work io_uring/io-wq.c:1074 [inline] io_wq_cancel_cb+0xb0/0x390 io_uring/io-wq.c:1112 io_uring_try_cancel_requests+0x15e/0xd70 io_uring/io_uring.c:3062 io_uring_cancel_generic+0x6ec/0x8c0 io_uring/io_uring.c:3140 io_uring_files_cancel include/linux/io_uring.h:20 [inline] do_exit+0x494/0x27a0 kernel/exit.c:894 do_group_exit+0xb3/0x250 kernel/exit.c:1087 get_signal+0x1d77/0x1ef0 kernel/signal.c:3017 arch_do_signal_or_restart+0x79/0x5b0 arch/x86/kernel/signal.c:337 exit_to_user_mode_loop kernel/entry/common.c:111 [inline] exit_to_user_mode_prepare include/linux/entry-common.h:329 [inline] __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline] syscall_exit_to_user_mode+0x150/0x2a0 kernel/entry/common.c:218 do_syscall_64+0xd8/0x250 arch/x86/entry/common.c:89 entry_SYSCALL_64_after_hwframe+0x77/0x7f which is because io_uring has ctx->timeout_lock nesting inside the io-wq acct lock, the latter of which is used from inside the scheduler and hence is a raw spinlock, while the former is a "normal" spinlock and can hence be sleeping on PREEMPT_RT. Change ctx->timeout_lock to be a raw spinlock to solve this nesting dependency on PREEMPT_RT=y. Reported-by: chase xd Signed-off-by: Jens Axboe [axboe: 6.1 has no multishot timeouts, so there is no rearm in io_timeout_complete() to convert, and it has two more timeout_lock sections from later fixes, the cq_timeouts update in io_timeout_cancel() and the __io_wq_cancel_seen() check in io_timeout(). Convert those as well] --- include/linux/io_uring_types.h | 2 +- io_uring/io_uring.c | 10 ++++----- io_uring/timeout.c | 38 +++++++++++++++++----------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 8bee77acb384..f86ef0d78ed4 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -308,7 +308,7 @@ struct io_ring_ctx { /* timeouts */ struct { - spinlock_t timeout_lock; + raw_spinlock_t timeout_lock; atomic_t cq_timeouts; struct list_head timeout_list; struct list_head ltimeout_list; diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index dc2cac09cbe6..3ccc108cf835 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -198,9 +198,9 @@ bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task, struct io_ring_ctx *ctx = head->ctx; /* protect against races with linked timeouts */ - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); matched = io_match_linked(head); - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); } else { matched = io_match_linked(head); } @@ -303,7 +303,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p) mutex_init(&ctx->uring_lock); init_waitqueue_head(&ctx->cq_wait); spin_lock_init(&ctx->completion_lock); - spin_lock_init(&ctx->timeout_lock); + raw_spin_lock_init(&ctx->timeout_lock); INIT_WQ_LIST(&ctx->iopoll_list); INIT_LIST_HEAD(&ctx->io_buffers_pages); INIT_LIST_HEAD(&ctx->io_buffers_comp); @@ -408,10 +408,10 @@ static void io_prep_async_link(struct io_kiocb *req) if (req->flags & REQ_F_LINK_TIMEOUT) { struct io_ring_ctx *ctx = req->ctx; - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); io_for_each_link(cur, req) io_prep_async_work(cur); - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); } else { io_for_each_link(cur, req) io_prep_async_work(cur); diff --git a/io_uring/timeout.c b/io_uring/timeout.c index d793edae44a8..4c523dce3746 100644 --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -75,7 +75,7 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx) u32 seq; struct io_timeout *timeout, *tmp; - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); seq = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts); /* @@ -108,7 +108,7 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx) io_kill_timeout(req, 0); } ctx->cq_last_tm_flush = seq; - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); } static void io_req_tw_fail_links(struct io_kiocb *link, bool *locked) @@ -174,9 +174,9 @@ void io_disarm_next(struct io_kiocb *req) } else if (req->flags & REQ_F_LINK_TIMEOUT) { struct io_ring_ctx *ctx = req->ctx; - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); link = io_disarm_linked_timeout(req); - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); if (link) io_req_queue_tw_complete(link, -ECANCELED); } @@ -212,11 +212,11 @@ static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer) struct io_ring_ctx *ctx = req->ctx; unsigned long flags; - spin_lock_irqsave(&ctx->timeout_lock, flags); + raw_spin_lock_irqsave(&ctx->timeout_lock, flags); list_del_init(&timeout->list); atomic_set(&req->ctx->cq_timeouts, atomic_read(&req->ctx->cq_timeouts) + 1); - spin_unlock_irqrestore(&ctx->timeout_lock, flags); + raw_spin_unlock_irqrestore(&ctx->timeout_lock, flags); if (!(data->flags & IORING_TIMEOUT_ETIME_SUCCESS)) req_set_fail(req); @@ -265,12 +265,12 @@ int io_timeout_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd) { struct io_kiocb *req; - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); req = io_timeout_extract(ctx, cd); if (!IS_ERR(req)) atomic_set(&ctx->cq_timeouts, atomic_read(&ctx->cq_timeouts) + 1); - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); if (IS_ERR(req)) return PTR_ERR(req); @@ -312,7 +312,7 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) struct io_ring_ctx *ctx = req->ctx; unsigned long flags; - spin_lock_irqsave(&ctx->timeout_lock, flags); + raw_spin_lock_irqsave(&ctx->timeout_lock, flags); prev = timeout->head; timeout->head = NULL; @@ -327,7 +327,7 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) } list_del(&timeout->list); timeout->prev = prev; - spin_unlock_irqrestore(&ctx->timeout_lock, flags); + raw_spin_unlock_irqrestore(&ctx->timeout_lock, flags); req->io_task_work.func = io_req_task_link_timeout; io_req_task_work_add(req); @@ -456,12 +456,12 @@ int io_timeout_remove(struct io_kiocb *req, unsigned int issue_flags) } else { enum hrtimer_mode mode = io_translate_timeout_mode(tr->flags); - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); if (tr->ltimeout) ret = io_linked_timeout_update(ctx, tr->addr, &tr->ts, mode); else ret = io_timeout_update(ctx, tr->addr, &tr->ts, mode); - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); } if (ret < 0) @@ -549,11 +549,11 @@ int io_timeout(struct io_kiocb *req, unsigned int issue_flags) struct list_head *entry; u32 tail, base, off = timeout->off; - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); /* the list is searched under ->timeout_lock, see io_wq_cancel_seen() */ if (__io_wq_cancel_seen(req, issue_flags)) { - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); io_req_task_queue_fail(req, -ECANCELED); return IOU_ISSUE_SKIP_COMPLETE; } @@ -609,7 +609,7 @@ int io_timeout(struct io_kiocb *req, unsigned int issue_flags) list_add(&timeout->list, entry); data->timer.function = io_timeout_fn; hrtimer_start(&data->timer, timespec64_to_ktime(data->ts), data->mode); - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); return IOU_ISSUE_SKIP_COMPLETE; } @@ -618,7 +618,7 @@ void io_queue_linked_timeout(struct io_kiocb *req) struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout); struct io_ring_ctx *ctx = req->ctx; - spin_lock_irq(&ctx->timeout_lock); + raw_spin_lock_irq(&ctx->timeout_lock); /* * If the back reference is NULL, then our linked request finished * before we got a chance to setup the timer @@ -631,7 +631,7 @@ void io_queue_linked_timeout(struct io_kiocb *req) data->mode); list_add_tail(&timeout->list, &ctx->ltimeout_list); } - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); /* drop submission reference */ io_put_req(req); } @@ -662,7 +662,7 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk, int canceled = 0; io_cq_lock(ctx); - spin_lock_irq(&ctx->timeout_lock); + 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); @@ -670,7 +670,7 @@ __cold bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk, io_kill_timeout(req, -ECANCELED)) canceled++; } - spin_unlock_irq(&ctx->timeout_lock); + raw_spin_unlock_irq(&ctx->timeout_lock); io_cq_unlock_post(ctx); return canceled != 0; } -- 2.55.0