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=1796380632; b=WE7bwGJV1aYYefqPKezpiM15Qj08+4TonCGiCWaCje+Z4eiz2IdHYSxXVYVg9p1YtA7+ CbQQd4PBJywXORglqd999x8ooHCUwwT3BgAGz9978yRY5RGDH+8O42R1rUag0o7Fo9IjA Mz+UCYIcZ/AvQnZtgcnau7OlQglbQWN2bqG0gjmNn2iM00puBJXBSClZIXEu41BO8fDLf PzYpDzcuP97PYy8kvZyFgc1lQ3AgIU8+rukpbVHH+p2tmUMUb2kZiTnUgoYGw+/NA6z6A JlY7PJUwOSjTA8PR+s8wqgfLY06G9yBnen2lddEXqMUEQzpGbcY8TObi1/2SvKUdomA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380632; 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=7h7UPyKnlEcj2HWUiQxGuj3b/Os37HRLb7rSLjd3I+4=; b=PTqne+pOGrvCNNJ3P+oipJinBIIh2ibdbrKhzSu6OSuLQWPFVlaxGUBNsLDpWt8PeJVL iDbf2mW34RkCLkA93Lt6xxzHROcutPP/hJpl1uGdmuxwWvbMWpNYESeWO6vIy4NoBH1Rr H52beK9BX589m97BWtwiBwLKd1GwVGaiFVy4szz6q/ABcyK31rnwcSPwHi/ubi/z1IzxI YOuQ1etjHRpvD+hiEhjxp2HBmfKDbg1GMQQb4h42GayaoiaDvPhjedzc1nYNNbG7HqrM5 5UKbUVPP43/W0RAwg8YiPwgo14n5xJcd/Gi+SAvdjwoaKziOpOmJw3JyzX+VHTPOv6A== 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=hjlqtvAX; 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 2AE88606A686; Fri, 4 Dec 2026 10:37:12 +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=hjlqtvAX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 562C21F00897; Fri, 4 Dec 2026 10:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380631; bh=7h7UPyKnlEcj2HWUiQxGuj3b/Os37HRLb7rSLjd3I+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hjlqtvAXDXSdUU6CBWYMlcAa+2KrK51IiXobfSeeo8D57Rts0VaT6xMPlGAnev7/w bjwQ2WJFeH0UCq+vmhoRXEyDHMaPIO9dHBWQ2yniNOL1KAGc0RvItZffuwgS8/b1Am thuJFD58QwD8qtA3Q3e067PYpmJKJxE2+zhVegQA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tengda Wu , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 7.3 316/742] perf: Fix sigtrap vs fast-switch Date: Fri, 4 Dec 2026 19:03:00 +0900 Message-ID: <20261204100643.424147613@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra [ Upstream commit 34dc983cc1628dea5054baa8687477cbb8683e28 ] perf_sigtrap() contains: WARN_ON_ONCE(event->ctx->task != current) The warning assumes that an event's ctx->task always matches the task that ends up running the pending task_work. That assumption can be broken by the context fast-swap path. The failure sequence is: 1. A -> B switch, perf_event_context_sched_out() takes the fast path and does WRITE_ONCE(ctx->task, next) / WRITE_ONCE(next_ctx->task, task). An NMI then hits while the context is swapped, and __perf_event_overflow() queues pending task_work on the *current* task (A), even though the event now belongs to B's swapped-in context view. 2. B -> A switch. Because A now has pending task_work, nr_no_switch_fast is non-zero, so the slow path is taken and ctx->task is *not* swapped back. 3. A returns to user mode, task_work runs perf_pending_task() -> perf_sigtrap(), and event->ctx->task no longer equals current, tripping the WARN_ON_ONCE(). Therefore; the task_work_add() should in fact use event->ctx->task, rather than current. They are always the same, except in this narrow window between perf_event_task_sched_out() and switch_to(). Fixes: c5d93d23a260 ("perf: Enqueue SIGTRAP always via task_work.") Reported-by: Tengda Wu Tested-by: Tengda Wu Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/20261125161342.GP2669272%40noisy.programming.kicks-ass.net Signed-off-by: Sasha Levin --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 3b8aea12a2fc5..48fee445fb414 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10957,7 +10957,7 @@ static int __perf_event_overflow(struct perf_event *event, * claim the pending_work before task_work_add() recurses. */ if (cmpxchg_local(&event->pending_work, 0, 1) == 0) { - if (!task_work_add(current, &event->pending_task, notify_mode)) { + if (!task_work_add(event->ctx->task, &event->pending_task, notify_mode)) { event->pending_work = pending_id; local_inc(&event->ctx->nr_no_switch_fast); WARN_ON_ONCE(!atomic_long_inc_not_zero(&event->refcount)); -- 2.53.0