mirror of
https://github.com/torvalds/linux.git
synced 2026-04-24 17:42:27 -04:00
Both livepatch and BPF trampoline use ftrace. Special attention is needed
when livepatch and fexit program touch the same function at the same
time, because livepatch updates a kernel function and the BPF trampoline
need to call into the right version of the kernel function.
Use samples/livepatch/livepatch-sample.ko for the test.
The test covers two cases:
1) When a fentry program is loaded first. This exercises the
modify_ftrace_direct code path.
2) When a fentry program is loaded first. This exercises the
register_ftrace_direct code path.
Signed-off-by: Song Liu <song@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20251027175023.1521602-4-song@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
31 lines
537 B
C
31 lines
537 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
|
|
|
|
#include <linux/bpf.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
|
|
int fentry_hit;
|
|
int fexit_hit;
|
|
int my_pid;
|
|
|
|
SEC("fentry/cmdline_proc_show")
|
|
int BPF_PROG(fentry_cmdline)
|
|
{
|
|
if (my_pid != (bpf_get_current_pid_tgid() >> 32))
|
|
return 0;
|
|
|
|
fentry_hit = 1;
|
|
return 0;
|
|
}
|
|
|
|
SEC("fexit/cmdline_proc_show")
|
|
int BPF_PROG(fexit_cmdline)
|
|
{
|
|
if (my_pid != (bpf_get_current_pid_tgid() >> 32))
|
|
return 0;
|
|
|
|
fexit_hit = 1;
|
|
return 0;
|
|
}
|