From nobody Tue Apr 7 12:37:59 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32F8A27B32B; Wed, 25 Feb 2026 14:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772030272; cv=none; b=tR5BcSSUFiuTt7r2exnOCgFQxAaw7U4yGD2Lgy2+xb7zIk9kF0gkGWBOTqKQfbkUwZ9W4cEfByg4Zg4BCFc7k4RsjtmfO0IiEo/mG+cH2zvX9tE2yfnsFBK13r5HHpC53ccrr7JeShtEokJ6P5EIWEqZ+XMRC7Chjt9wzct5dTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772030272; c=relaxed/simple; bh=D1Ptlw/ViwBvNhgCWWvUbciImZ+P4Eu19FKO9uHhpkg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=UsZMxKPLtEfgEnI4pYPNLwfhUmUa1Yh9uWXDahCgC2rxBEOLhqv2SewkgfUztaKrk3aN4V/shvooX9L+vMUOc4FtsVPFGStvDOVu+k7vnb4Qo75q1WgUAXGwshz9HQaTIQwRZvwqKfoTGnyyTOySqK+6JtUSm5gMLG8iNN3/7ZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ixtPdtsr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=D6XX7rYa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ixtPdtsr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="D6XX7rYa" Date: Wed, 25 Feb 2026 14:37:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1772030269; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jt3mW+sirSxqztKnZBaYiOp7d7WpjpUpz1jaM5lR/Ho=; b=ixtPdtsrIVYxf+YoX4sp7Ui49FR+W+ecpGbBM8agi69SuvRkFkgzdJ0qED0a0KJprRhbvV BAVK5IdStncuJXNmzhTAB9iu2CMsiLkZlFuNK6kAVz/fooy1wa/vMc53280muMQlzbSVuN LBSvL63GfOBIrd8ushZm68H49XgYOu9MJphrSEMZx40b31CemW4j1wLjt9Z3w83btqZygn 1vs17QfgLeMZ/YGYw6qW2mRfNgpsV1LrZHAGtQ2nVDN05/8qI6twsThzqdbgwzUw0Jf6SG pQZuWsU+aVMj//0rozzHxpoJPuJWQtFJ6yYlkeV0bC6FxgLBsLpssHTAY+XX5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1772030269; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jt3mW+sirSxqztKnZBaYiOp7d7WpjpUpz1jaM5lR/Ho=; b=D6XX7rYaOMrGmEzc37koHt5ClIV0OGOTxxu/aIL/Lp9n7IAgUpaqU7opeH5xfSDRy4V2qh KmYVlUYGQGnKzKBw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf: Fix __perf_event_overflow() vs perf_remove_from_context() race Cc: Simond Hu , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260224122909.GV1395416@noisy.programming.kicks-ass.net> References: <20260224122909.GV1395416@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177203026760.1647592.6609514601681232494.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the perf/urgent branch of tip: Commit-ID: c9bc1753b3cc41d0e01fbca7f035258b5f4db0ae Gitweb: https://git.kernel.org/tip/c9bc1753b3cc41d0e01fbca7f035258b5= f4db0ae Author: Peter Zijlstra AuthorDate: Tue, 24 Feb 2026 13:29:09 +01:00 Committer: Peter Zijlstra CommitterDate: Wed, 25 Feb 2026 15:02:34 +01:00 perf: Fix __perf_event_overflow() vs perf_remove_from_context() race Make sure that __perf_event_overflow() runs with IRQs disabled for all possible callchains. Specifically the software events can end up running it with only preemption disabled. This opens up a race vs perf_event_exit_event() and friends that will go and free various things the overflow path expects to be present, like the BPF program. Fixes: 592903cdcbf6 ("perf_counter: add an event_list") Reported-by: Simond Hu Signed-off-by: Peter Zijlstra (Intel) Tested-by: Simond Hu Link: https://patch.msgid.link/20260224122909.GV1395416@noisy.programming.k= icks-ass.net --- kernel/events/core.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 22a0f40..1f5699b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10777,6 +10777,13 @@ int perf_event_overflow(struct perf_event *event, struct perf_sample_data *data, struct pt_regs *regs) { + /* + * Entry point from hardware PMI, interrupts should be disabled here. + * This serializes us against perf_event_remove_from_context() in + * things like perf_event_release_kernel(). + */ + lockdep_assert_irqs_disabled(); + return __perf_event_overflow(event, 1, data, regs); } =20 @@ -10853,6 +10860,19 @@ static void perf_swevent_event(struct perf_event *= event, u64 nr, { struct hw_perf_event *hwc =3D &event->hw; =20 + /* + * This is: + * - software preempt + * - tracepoint preempt + * - tp_target_task irq (ctx->lock) + * - uprobes preempt/irq + * - kprobes preempt/irq + * - hw_breakpoint irq + * + * Any of these are sufficient to hold off RCU and thus ensure @event + * exists. + */ + lockdep_assert_preemption_disabled(); local64_add(nr, &event->count); =20 if (!regs) @@ -10861,6 +10881,16 @@ static void perf_swevent_event(struct perf_event *= event, u64 nr, if (!is_sampling_event(event)) return; =20 + /* + * Serialize against event_function_call() IPIs like normal overflow + * event handling. Specifically, must not allow + * perf_event_release_kernel() -> perf_remove_from_context() to make + * progress and 'release' the event from under us. + */ + guard(irqsave)(); + if (event->state !=3D PERF_EVENT_STATE_ACTIVE) + return; + if ((event->attr.sample_type & PERF_SAMPLE_PERIOD) && !event->attr.freq) { data->period =3D nr; return perf_swevent_overflow(event, 1, data, regs); @@ -11359,6 +11389,11 @@ void perf_tp_event(u16 event_type, u64 count, void= *record, int entry_size, struct perf_sample_data data; struct perf_event *event; =20 + /* + * Per being a tracepoint, this runs with preemption disabled. + */ + lockdep_assert_preemption_disabled(); + struct perf_raw_record raw =3D { .frag =3D { .size =3D entry_size, @@ -11691,6 +11726,11 @@ void perf_bp_event(struct perf_event *bp, void *da= ta) struct perf_sample_data sample; struct pt_regs *regs =3D data; =20 + /* + * Exception context, will have interrupts disabled. + */ + lockdep_assert_irqs_disabled(); + perf_sample_data_init(&sample, bp->attr.bp_addr, 0); =20 if (!bp->hw.state && !perf_exclude_event(bp, regs)) @@ -12155,7 +12195,7 @@ static enum hrtimer_restart perf_swevent_hrtimer(st= ruct hrtimer *hrtimer) =20 if (regs && !perf_exclude_event(event, regs)) { if (!(event->attr.exclude_idle && is_idle_task(current))) - if (__perf_event_overflow(event, 1, &data, regs)) + if (perf_event_overflow(event, &data, regs)) ret =3D HRTIMER_NORESTART; } =20