On Tue, May 26, 2026 at 10:58 PM +02, Jiri Olsa wrote:
> Adding tests for forked/cloned optimized uprobes and make
> sure the child can properly execute optimized probe for
> both fork (dups mm) and clone with CLONE_VM.
>
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> .../selftests/bpf/prog_tests/uprobe_syscall.c | 88 +++++++++++++++++++
> 1 file changed, 88 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
> b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
> index efff0c515184..033d32b4cc27 100644
> --- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
> +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
> @@ -4,6 +4,8 @@
>
> #ifdef __x86_64__
>
> +#define _GNU_SOURCE
> +#include <sched.h>
> #include <unistd.h>
> #include <asm/ptrace.h>
> #include <linux/compiler.h>
> @@ -936,6 +938,88 @@ static void test_uprobe_error(void)
> ASSERT_EQ(errno, EPROTO, "errno");
> }
>
> +__attribute__((aligned(16)))
> +__nocf_check __weak __naked void uprobe_fork_test(void)
> +{
> + asm volatile (
> + ".byte 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00,
> 0x00\n" /* nop10 */
> + "ret\n"
> + );
> +}
> +
> +static int child_func(void *arg)
Nit: Could annotate with noreturn:
#include <stdnoreturn.h>
/* ... */
static noreturn int child_func(void *arg)
> +{
> + struct uprobe_syscall_executed *skel = arg;
> +
> + /* Make sure the child's probe is still there and optimized.. */
> + if (memcmp(uprobe_fork_test, lea_rsp, sizeof(lea_rsp)))
> + _exit(1);
> +
> + skel->bss->pid = getpid();
> +
> + /* .. and it executes properly. */
> + uprobe_fork_test();
> +
> + if (skel->bss->executed != 3)
> + _exit(2);
> +
> + _exit(0);
> +}
[...]
Reviewed-by: Jakub Sitnicki <[email protected]>