From nobody Sat Feb 7 04:47:31 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5316931E11F; Tue, 2 Sep 2025 14:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756823802; cv=none; b=ZTqW/INqrJE28zPAUQGXj4ZTYI5i7Y54ElrkpHy4/TxXFxNODGMFHioX2r5bh0ggZ2FDfQo4FpkPA6Gc3P3pYSeWDrwn18ObOYx7udeCP+Oc+0rwqYFCDimac8SiiwhXkC7kXrfNA9FvYPtE4EL0PYhwSMULtXf/EsarBR1LMOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756823802; c=relaxed/simple; bh=jOrI1/r9cXIWWIBL1iahAvqnnE3/HtGeDR9yXqysb2U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fhbvH2gSDi7eatJ2eXcdyCsdS58+bPRBFVKgcFLStAK+WySqtDxw2s6Gk+NAzV3ypAUQwYM80dDeyhw9lYIXxFQGiE7OTiWaz0rkCb4I15O5pxI8aSRcb6mk1mCQKsz7Q0m1lADDYdWJCeivW2OHqu1fZ+HC9hP8MAoDgvquAYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t2QYEvUk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t2QYEvUk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7D7AC4CEF6; Tue, 2 Sep 2025 14:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756823801; bh=jOrI1/r9cXIWWIBL1iahAvqnnE3/HtGeDR9yXqysb2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t2QYEvUkKHXFGrZgaFJ5Y/lV7+xo/IzLJoEXKH+zFjw4X0+9P2QUJ2iC7KT3T62P6 uVNzwA6GklARr6xTRoUVF+u0MPIOg5tGIY31GFRKtqFnnjI6EBFjUNeq0ifqWuu6Ct xNpw5o/DtxjJGd8OYFWZaKWXgBiIIro5WSnNwF9bxQ6HsKDEYjTPqhFrjcz8+7fZAr +xqvBmsHjcnH/1eXjlVUMO4DQrtT57NzKCmKa4AyDcsOHycvs42HEahkSZTvADAiUp xLSAMAd0l7I2j+9uT0bWZbnXH7O1VzSSBr2/H8ilEvjnABe+hxvbzs/25erndtT5H0 2xRcnAbvAYztA== From: Jiri Olsa To: Oleg Nesterov , Masami Hiramatsu , Peter Zijlstra , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org, Song Liu , Yonghong Song , John Fastabend , Hao Luo , Steven Rostedt , Ingo Molnar Subject: [PATCH perf/core 08/11] selftests/bpf: Add uprobe multi context registers changes test Date: Tue, 2 Sep 2025 16:35:01 +0200 Message-ID: <20250902143504.1224726-9-jolsa@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250902143504.1224726-1-jolsa@kernel.org> References: <20250902143504.1224726-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adding test to check we can change common register values through uprobe program. It's x86_64 specific test. Signed-off-by: Jiri Olsa --- .../selftests/bpf/prog_tests/bpf_cookie.c | 1 + .../bpf/prog_tests/uprobe_multi_test.c | 107 ++++++++++++++++++ .../selftests/bpf/progs/uprobe_multi.c | 24 ++++ 3 files changed, 132 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/te= sting/selftests/bpf/prog_tests/bpf_cookie.c index 4a0670c056ba..2425fd26d1ea 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/t= ools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c index 2ee17ef1dae2..012652b07399 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include "uprobe_multi.skel.h" #include "uprobe_multi_bench.skel.h" @@ -1340,6 +1341,111 @@ static void test_bench_attach_usdt(void) printf("%s: detached in %7.3lfs\n", __func__, detach_delta); } =20 +#ifdef __x86_64__ +__naked __maybe_unused unsigned long uprobe_regs_change_trigger(void) +{ + asm volatile ( + "ret\n" + ); +} + +static __naked void uprobe_regs_change(struct pt_regs *before, struct pt_r= egs *after) +{ + asm volatile ( + "movq %r11, 48(%rdi)\n" + "movq %r10, 56(%rdi)\n" + "movq %r9, 64(%rdi)\n" + "movq %r8, 72(%rdi)\n" + "movq %rax, 80(%rdi)\n" + "movq %rcx, 88(%rdi)\n" + "movq %rdx, 96(%rdi)\n" + "movq %rsi, 104(%rdi)\n" + "movq %rdi, 112(%rdi)\n" + + /* save 2nd argument */ + "pushq %rsi\n" + "call uprobe_regs_change_trigger\n" + + /* save return value and load 2nd argument pointer to rax */ + "pushq %rax\n" + "movq 8(%rsp), %rax\n" + + "movq %r11, 48(%rax)\n" + "movq %r10, 56(%rax)\n" + "movq %r9, 64(%rax)\n" + "movq %r8, 72(%rax)\n" + "movq %rcx, 88(%rax)\n" + "movq %rdx, 96(%rax)\n" + "movq %rsi, 104(%rax)\n" + "movq %rdi, 112(%rax)\n" + + /* restore return value and 2nd argument */ + "pop %rax\n" + "pop %rsi\n" + + "movq %rax, 80(%rsi)\n" + "ret\n" + ); +} + +static void unique_regs_common(void) +{ + struct pt_regs before =3D {}, after =3D {}, expected =3D { + .rax =3D 0xc0ffe, + .rcx =3D 0xbad, + .rdx =3D 0xdead, + .r8 =3D 0x8, + .r9 =3D 0x9, + .r10 =3D 0x10, + .r11 =3D 0x11, + .rdi =3D 0x12, + .rsi =3D 0x13, + }; + LIBBPF_OPTS(bpf_uprobe_multi_opts, opts, + .unique =3D true, + ); + struct uprobe_multi *skel; + + skel =3D uprobe_multi__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open")) + return; + + skel->bss->pid =3D getpid(); + skel->bss->regs =3D expected; + + skel->links.uprobe_change_regs =3D bpf_program__attach_uprobe_multi( + skel->progs.uprobe_change_regs, + -1, "/proc/self/exe", + "uprobe_regs_change_trigger", + &opts); + if (!ASSERT_OK_PTR(skel->links.uprobe_change_regs, "bpf_program__attach_u= probe_multi")) + goto cleanup; + + uprobe_regs_change(&before, &after); + + ASSERT_EQ(after.rax, expected.rax, "ax"); + ASSERT_EQ(after.rcx, expected.rcx, "cx"); + ASSERT_EQ(after.rdx, expected.rdx, "dx"); + ASSERT_EQ(after.r8, expected.r8, "r8"); + ASSERT_EQ(after.r9, expected.r9, "r9"); + ASSERT_EQ(after.r10, expected.r10, "r10"); + ASSERT_EQ(after.r11, expected.r11, "r11"); + ASSERT_EQ(after.rdi, expected.rdi, "rdi"); + ASSERT_EQ(after.rsi, expected.rsi, "rsi"); + +cleanup: + uprobe_multi__destroy(skel); +} + +static void test_unique(void) +{ + if (test__start_subtest("unique_regs_common")) + unique_regs_common(); +} +#else +static void test_unique(void) { } +#endif + void test_uprobe_multi_test(void) { if (test__start_subtest("skel_api")) @@ -1372,5 +1478,6 @@ void test_uprobe_multi_test(void) test_session_cookie_skel_api(); if (test__start_subtest("session_cookie_recursive")) test_session_recursive_skel_api(); + test_unique(); RUN_TESTS(uprobe_multi_verifier); } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi.c b/tools/testi= ng/selftests/bpf/progs/uprobe_multi.c index 44190efcdba2..f26f8b840985 100644 --- a/tools/testing/selftests/bpf/progs/uprobe_multi.c +++ b/tools/testing/selftests/bpf/progs/uprobe_multi.c @@ -141,3 +141,27 @@ int usdt_extra(struct pt_regs *ctx) /* we need this one just to mix PID-filtered and global USDT probes */ return 0; } + +#if defined(__TARGET_ARCH_x86) +struct pt_regs regs; + +SEC("uprobe.unique") +int BPF_UPROBE(uprobe_change_regs) +{ + pid_t cur_pid =3D bpf_get_current_pid_tgid() >> 32; + + if (cur_pid !=3D pid) + return 0; + + ctx->ax =3D regs.ax; + ctx->cx =3D regs.cx; + ctx->dx =3D regs.dx; + ctx->r8 =3D regs.r8; + ctx->r9 =3D regs.r9; + ctx->r10 =3D regs.r10; + ctx->r11 =3D regs.r11; + ctx->di =3D regs.di; + ctx->si =3D regs.si; + return 0; +} +#endif --=20 2.51.0