From nobody Mon Oct 6 05:01:22 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B217B2E3365; Fri, 25 Jul 2025 10:08:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753438118; cv=none; b=qT2+gAo2gxRsxH6h4RxRWSh5ES9okR+i5M/X3kU/oZ7IMqc+b7Vf+kPIis0++jEmQCmKjTkOLXoSQyPlkP7oQUBqMuT7xxy8FapBqmoJcKk9tJP3ZG6GTGkSgT5SHeMSr5dF+2X92wW8zsYr2hb+ujxpVWXUF5RXOJqPfENhcU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753438118; c=relaxed/simple; bh=7cyml8Yx9LrT/GiCd2nhThh6sBVeJwNVx9qws069z5M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XE3nFl3lYYjeba9sRlLy7Q8KNRwleWh3mm5rGnVuNI+hjwECTCZKCERItW7eCTFruKFA4aGLUtQUuXwhkWHTTJcQqV63A37OmJeq9NDuNMoF3Mt5DZxcVkmiis4GEWr+8dTZDVJkkWupTqxzkx6UwPg4GzhlNKJ6tIVfZPimfhA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 31CCF2C1E; Fri, 25 Jul 2025 03:08:29 -0700 (PDT) Received: from e132581.arm.com (e132581.arm.com [10.1.196.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EEFAC3F5A1; Fri, 25 Jul 2025 03:08:31 -0700 (PDT) From: Leo Yan Date: Fri, 25 Jul 2025 11:08:12 +0100 Subject: [PATCH RESEND v3 2/6] bpf: Add bpf_perf_event_aux_pause kfunc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250725-perf_aux_pause_resume_bpf_rebase-v3-2-ae21deb49d1a@arm.com> References: <20250725-perf_aux_pause_resume_bpf_rebase-v3-0-ae21deb49d1a@arm.com> In-Reply-To: <20250725-perf_aux_pause_resume_bpf_rebase-v3-0-ae21deb49d1a@arm.com> To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Ian Rogers , Adrian Hunter , KP Singh , Matt Bobrowski , Song Liu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Yonghong Song , John Fastabend , Stanislav Fomichev , Hao Luo , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , James Clark , Suzuki K Poulose , Mike Leach Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Leo Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753438103; l=2404; i=leo.yan@arm.com; s=20250604; h=from:subject:message-id; bh=7cyml8Yx9LrT/GiCd2nhThh6sBVeJwNVx9qws069z5M=; b=S3seupvm0QeNkZqul2qen6v8J36ZvOvtFO7fQxpdxHey9MkJThqfrynJ8u1fMJvbOiIe3yy3y 7Xy5mVC2zOOAyIY97w/kxSGN1R/cn5VGJAiKEIdi+Ru3IqxHLUu065C X-Developer-Key: i=leo.yan@arm.com; a=ed25519; pk=k4BaDbvkCXzBFA7Nw184KHGP5thju8lKqJYIrOWxDhI= The bpf_perf_event_aux_pause kfunc is introduced for pause and resume the Perf AUX trace used by eBPF programs. An attached tracepoint (e.g., ftrace tracepoint or a dynamic tracepoint using uprobe or kprobe) can invoke bpf_perf_event_aux_pause() to pause or resume AUX trace. This is useful for fine-grained tracing. Signed-off-by: Leo Yan --- kernel/trace/bpf_trace.c | 55 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 55 insertions(+) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 3ae52978cae61a5d60b43c764d3e267bd32e1085..fbed1f9a92cce666e2a61d6bfce= aabfd5efade1c 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -704,6 +704,61 @@ static const struct bpf_func_proto bpf_perf_event_outp= ut_proto =3D { .arg5_type =3D ARG_CONST_SIZE_OR_ZERO, }; =20 +__bpf_kfunc_start_defs(); + +__bpf_kfunc int bpf_perf_event_aux_pause(void *p__map, u64 flags, bool pau= se) +{ + struct bpf_map *map =3D p__map; + struct bpf_array *array =3D container_of(map, struct bpf_array, map); + unsigned int cpu =3D smp_processor_id(); + u64 index =3D flags & BPF_F_INDEX_MASK; + struct bpf_event_entry *ee; + + if (map->map_type !=3D BPF_MAP_TYPE_PERF_EVENT_ARRAY) + return -EINVAL; + + /* Disabling IRQ avoids race condition with perf event flows. */ + guard(irqsave)(); + + if (unlikely(flags & ~(BPF_F_INDEX_MASK))) + return -EINVAL; + + if (index =3D=3D BPF_F_CURRENT_CPU) + index =3D cpu; + + if (unlikely(index >=3D array->map.max_entries)) + return -E2BIG; + + ee =3D READ_ONCE(array->ptrs[index]); + if (!ee) + return -ENOENT; + + if (!has_aux(ee->event)) + return -EINVAL; + + perf_event_aux_pause(ee->event, pause); + return 0; +} + +__bpf_kfunc_end_defs(); + +BTF_KFUNCS_START(perf_event_kfunc_set_ids) +BTF_ID_FLAGS(func, bpf_perf_event_aux_pause, KF_TRUSTED_ARGS) +BTF_KFUNCS_END(perf_event_kfunc_set_ids) + +static const struct btf_kfunc_id_set bpf_perf_event_kfunc_set =3D { + .owner =3D THIS_MODULE, + .set =3D &perf_event_kfunc_set_ids, +}; + +static int __init bpf_perf_event_kfuncs_init(void) +{ + return register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, + &bpf_perf_event_kfunc_set); +} + +late_initcall(bpf_perf_event_kfuncs_init); + static DEFINE_PER_CPU(int, bpf_event_output_nest_level); struct bpf_nested_pt_regs { struct pt_regs regs[3]; --=20 2.34.1