From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795035688; b=Y3vwglcEFVrEanVllTXeBj02jpsykkrzbhe1gdL6sXINhV2ji2TupYwq/bciUnA0YXdg Jfun3IWUaXG8nYTvLIsQ1y81UvCNPFlh7GWBYcFjaPIJrPm/XZWib+2j2OpWQByJzoBpl GFqLbAgI5q+WC+cQnsBFgBah+Xt5ZsSixZAogTluc4+oGhsokSyIgySPV6aKWrkJRCJ3H 46ArSDr1wLtkptxJ6+onmlFZnjUCn3SjeBvEiE/+N0qbWUVHjyCkHge4biRttA5+SZQbK WTSNfsMUUOoHufsap3St9GeI+FbCmp76fKMfi/IisgeXFg/7wEicBb8Wa7rBjC+sgeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795035688; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=YP8oTMyxF0ILgDGeWnMJKL3wu3h4LTW/Fye/7OTTQPY=; b=AHIv2KjNWgI61PwKMmhD649pJ1/hD/q5LmvudAMHSluQfNiFMoeNlmoJek1daYppulEU MITM1ARhLJ4peGknaNwF2fL/Pdp7ykBoPGV2OmA9BC6NG8nWMJlLFBqj4lC04x1br1sni wsLV0LOyUY4TjSBhpb+p05QEjd9DFVgMv3vQDKWr90QMM+eq3MWTG5BkoOeurALuK+iE1 RaJvZTjfxwXnh71SB6mpdW/cVVir6i1weaEk3MnW/4LGsljurMHcUImcbGxsDh9THdo6g RiKUAXbBKHqWgJsqtGyhb5h9YlOKIsaHd+pSIlbkbWpsLHC5FpkH98Ruc19cpOU9hqw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="y1NNNAI/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9F3860A2602; Wed, 18 Nov 2026 21:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=y1NNNAI/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 370F81F000C6; Wed, 18 Nov 2026 21:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795035688; bh=YP8oTMyxF0ILgDGeWnMJKL3wu3h4LTW/Fye/7OTTQPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=y1NNNAI/9o+MWEPh1R6uWeLU3ohWXZPzHBAIHru8OttyZ2vU/X4aI6JSie4Gn9e5E /5qEtISZOsk5QtCleLNV2pRKFqUDw/8H03ePXthUzOpDoYshvGAA6dr0LMDIEboMdj lyzPUuv6bIGrTBLOA+mHWFn6+y8r/IE8ql12T9dw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Cheng Yongkang , Jens Axboe Subject: [PATCH 6.6 0752/3318] io_uring/timeout: count cancelled timeouts in cq_timeouts Date: Wed, 18 Nov 2026 15:22:54 +0100 Message-ID: <20261118150341.211747787@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cheng Yongkang Commit 1c8b49851543f41fc8bb18bcd1f15cc93d14b530 upstream. io_timeout_cancel() posts the cancelled timeout's -ECANCELED CQE without advancing ctx->cq_timeouts. io_timeout_fn() and io_kill_timeout() advance it for every timeout CQE they post, and io_flush_timeouts() computes the number of non-timeout completions as seq = cached_cq_tail - cq_timeouts to compare against each off timeout's target_seq. The cancelled timeout's CQE is therefore counted as a regular completion, so every cancellation makes an already armed off timeout fire one completion early. A ring with a keep-alive timeout of off=4 completes it after two NOPs when one off=100 victim is cancelled through IORING_OP_ASYNC_CANCEL, and before any NOP when two victims are cancelled. The cancel CQE should count, but the cancelled timeouts' -ECANCELED CQEs must not: the expected counts are three and two NOPs respectively. Advance cq_timeouts when io_timeout_extract() succeeds, under timeout_lock and before the -ECANCELED completion is queued, matching io_timeout_fn() and io_kill_timeout(). The -ENOENT and -EALREADY paths post no new timeout CQE and keep their accounting. Both the ASYNC_CANCEL and the TIMEOUT_REMOVE path go through io_timeout_cancel(). Fixes: bfe68a221905 ("io_uring: off timeouts based only on completions") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Cheng Yongkang Link: https://patch.msgid.link/179328314078.648427.13761781546953594668@gmail.com Signed-off-by: Jens Axboe [axboe: 6.6 uses a regular spinlock for ->timeout_lock] Signed-off-by: Greg Kroah-Hartman --- io_uring/timeout.c | 3 +++ 1 file changed, 3 insertions(+) --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -306,6 +306,9 @@ int io_timeout_cancel(struct io_ring_ctx 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); if (IS_ERR(req))