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=1796385836; b=n60VI+zaCH/hkLi0116KVXoJyR71US3h/P7jF5F2YbBYwWW3nOE1K4TqUJW1pbW+Abzf sgsooVSSyiW+D//VW1vGPRY26dGVAZwrX+GG+IhrBcIPjIO/MJHey/rCB++yAtEnGXCzO Ydd8cqoMYcKEZctWeJQU0NtAThIyUBMFtd0qalSArPhprD+TG5w6+uCG87yerZuFIJVnl xjMA9UyBFNxdPpR27Num5YScNbXpubX/roZ38idLwKlsV2k2QTZ/wvK8eLOQirkCZywlD /7f7tVtYv7P2OZO0lARB4l/SAh4abzRj+ISixJsw4W9gDziAAWfmGr+DTb7NeLvob+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385836; 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=JJCqxDbiQQ5cHJK/kYey0aykUt3fZcJs1qCsLNbfPrc=; b=e5SQzh/EUwZbxC1Z1Bg2oY4Rb0KQs+dkxr00Dfb4Jpdfh4DhlFskunTs9k/CowZdawwR nOrZbzCjgxZRyOSUDMzBuk+duDRyfBPjWkY0dVTS6JKdT8V4XhfVYdq2QItj4U6o+Clb7 S9q+bvtkPAIZ2NiebJyMusS2gG9vk8k8qtr/x8YC6vEF57RvvrQUNGahOY8L0TSjsX65e u3v2IxVkLzzGHEgHUQlJID5cgnkmmypZlyJdU4wmxrzdDD/NG29NIsykanBWuyYFiS1OP qHpGSylm3hpAHKqRFlTc1NP/7TnJX7G50JBnHNTa151Th/i7mqjHpD4FNKKpytFg4zg== 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=mZvnYRYQ; 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 5F1D2606A32D; Fri, 4 Dec 2026 12:03:56 +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=mZvnYRYQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id C982D1F000C2; Fri, 4 Dec 2026 12:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385836; bh=JJCqxDbiQQ5cHJK/kYey0aykUt3fZcJs1qCsLNbfPrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mZvnYRYQpeIGUimPZL/FHnljUGXcXvW52Y9m6NMDzrv/+Vb/ZyhRIYNMdwjVRhk4M c0+tm3LRUg/NFOP2laMLqroagvHNxWH5JVc1K7BIUaYk75mjef6EXu3S/Nsj0v+jCU SgCvdewGhn/z1bGoa7x4IjMM+IY9LrCpWoSZ62Kc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Namhyung Kim , Kyle Huey , Ingo Molnar , Song Liu , Jiri Olsa , Andrii Nakryiko , Luo Gengkun , Sasha Levin Subject: [PATCH 6.6 0711/1167] perf/bpf: Call BPF handler directly, not through overflow machinery Date: Fri, 4 Dec 2026 19:02:18 +0900 Message-ID: <20261204100720.586605404@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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: Kyle Huey [ Upstream commit f11f10bfa1ca23b32020b2073aa13131a27978fe ] To ultimately allow BPF programs attached to perf events to completely suppress all of the effects of a perf event overflow (rather than just the sample output, as they do today), call bpf_overflow_handler() from __perf_event_overflow() directly rather than modifying struct perf_event's overflow_handler. Return the BPF program's return value from bpf_overflow_handler() so that __perf_event_overflow() knows how to proceed. Remove the now unnecessary orig_overflow_handler from struct perf_event. This patch is solely a refactoring and results in no behavior change. Suggested-by: Namhyung Kim Signed-off-by: Kyle Huey Signed-off-by: Ingo Molnar Acked-by: Song Liu Acked-by: Jiri Olsa Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/r/20240412015019.7060-5-khuey@kylehuey.com Signed-off-by: Luo Gengkun Signed-off-by: Sasha Levin --- include/linux/perf_event.h | 6 +----- kernel/events/core.c | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index b504d7eec86fd..f3bf97c4877bf 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -809,7 +809,6 @@ struct perf_event { u64 (*clock)(void); perf_overflow_handler_t overflow_handler; void *overflow_handler_context; - perf_overflow_handler_t orig_overflow_handler; struct bpf_prog *prog; u64 bpf_cookie; @@ -1352,10 +1351,7 @@ __is_default_overflow_handler(perf_overflow_handler_t overflow_handler) #ifdef CONFIG_BPF_SYSCALL static inline bool uses_default_overflow_handler(struct perf_event *event) { - if (likely(is_default_overflow_handler(event))) - return true; - - return __is_default_overflow_handler(event->orig_overflow_handler); + return is_default_overflow_handler(event); } #else #define uses_default_overflow_handler(event) \ diff --git a/kernel/events/core.c b/kernel/events/core.c index 047c0eaf18464..dcc4d4f07912f 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9605,9 +9605,9 @@ static inline bool sample_is_allowed(struct perf_event *event, struct pt_regs *r } #ifdef CONFIG_BPF_SYSCALL -static void bpf_overflow_handler(struct perf_event *event, - struct perf_sample_data *data, - struct pt_regs *regs) +static int bpf_overflow_handler(struct perf_event *event, + struct perf_sample_data *data, + struct pt_regs *regs) { struct bpf_perf_event_data_kern ctx = { .data = data, @@ -9628,10 +9628,8 @@ static void bpf_overflow_handler(struct perf_event *event, rcu_read_unlock(); out: __this_cpu_dec(bpf_prog_active); - if (!ret) - return; - event->orig_overflow_handler(event, data, regs); + return ret; } static int perf_event_set_bpf_handler(struct perf_event *event, @@ -9667,8 +9665,6 @@ static int perf_event_set_bpf_handler(struct perf_event *event, event->prog = prog; event->bpf_cookie = bpf_cookie; - event->orig_overflow_handler = READ_ONCE(event->overflow_handler); - WRITE_ONCE(event->overflow_handler, bpf_overflow_handler); return 0; } @@ -9679,15 +9675,15 @@ static void perf_event_free_bpf_handler(struct perf_event *event) if (!prog) return; - WRITE_ONCE(event->overflow_handler, event->orig_overflow_handler); event->prog = NULL; bpf_prog_put(prog); } #else -static void bpf_overflow_handler(struct perf_event *event, - struct perf_sample_data *data, - struct pt_regs *regs) +static int bpf_overflow_handler(struct perf_event *event, + struct perf_sample_data *data, + struct pt_regs *regs) { + return 1; } static int perf_event_set_bpf_handler(struct perf_event *event, @@ -9771,7 +9767,8 @@ static int __perf_event_overflow(struct perf_event *event, irq_work_queue(&event->pending_irq); } - READ_ONCE(event->overflow_handler)(event, data, regs); + if (!(event->prog && !bpf_overflow_handler(event, data, regs))) + READ_ONCE(event->overflow_handler)(event, data, regs); if (*perf_event_fasync(event) && event->pending_kill) { event->pending_wakeup = 1; @@ -12126,13 +12123,11 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, overflow_handler = parent_event->overflow_handler; context = parent_event->overflow_handler_context; #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_EVENT_TRACING) - if (overflow_handler == bpf_overflow_handler) { + if (parent_event->prog) { struct bpf_prog *prog = parent_event->prog; bpf_prog_inc(prog); event->prog = prog; - event->orig_overflow_handler = - parent_event->orig_overflow_handler; } #endif } -- 2.53.0