Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp343185lqb; Tue, 4 Jun 2024 13:07:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNhXrzlMLqAUxRpR7hra08GeNcG46p1zhWO6S/4pIEa357vObp4QY+PwCaUU3PeAZOAhlFzWXyIVeO1HA8vWcaRSx2nGVfSNi/ztKJIw== X-Google-Smtp-Source: AGHT+IHqGDv8wQ+Wex9cvSV5espEpa292IzfrBP1UKXojc1vKdxVtcF6eAvKy47nHN1BcVsXupvX X-Received: by 2002:a17:903:22c6:b0:1f6:3414:6a90 with SMTP id d9443c01a7336-1f6a590a93dmr7141725ad.13.1717531644395; Tue, 04 Jun 2024 13:07:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717531644; cv=pass; d=google.com; s=arc-20160816; b=oOYbXdD+ri6wJb0b8dzbfKSxcR9x05Ru+8RXTwVMbMc2lbZNGVXLOIrsyBWuGt1kea LJjeGz4FjrSBXW13O+/eILyk4lZK3exIGdz6QT3/3QFjaies+Hrgk+zKqgf5ox8b6PoS KSswgz2ExtBN7YyUnPu7Vturclpl/RfZ69tT+HqrQN8wa41wiqN7OVKPpGHMYbEq9KB4 tH6Ki6rfLpTgLdiDOTp7P6gksbatFKSIU3bOLfXmAeNmVsA4yT1ebO9hZnV5NY7mpuQQ YQQ0tQdeFfclDIryCHIjabdE/9vUA0VPADTeFG8MY7v9/nyVdipnR5Uvcb0xToEw4XOa MiCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HZJDDCyezLLG/QMlTUPVdh9VuMEZnx239OCi/im+P98=; fh=u3to46i6vVc15/oqkgIGXd5IRsv1JvYq+fe7qFLhiF8=; b=PWBImNGTI0HX4MjKQ6KPkfV3uMdiEUeReZGI/XAPwCZv3dsc5ZNMiS+/BHI3DzfaH4 6svTxPM6hM0gIOQMnDnnmsnhY6JcvimoRJLA0dOMp9VjaaCsX49iGLJODtM9HHfd7h92 oUbnBZEzOn7a3I9HIvKU8sorpIY5cbIRJb2b5LArfsF5GVreb3XvJC7hnsniNAaA6TtY bM4UeudQacNauK2BdszSTNPGAEEip5FccS2SLkAN4YlcifCN5WCyZdmVwu1oFllz8CLj 0gpCk+b4dga7XTcUha9uVxLnm7uXXfdSDfqBiQ8ndjVI3CxFvA7LkBd7b9oaV6ukVWfa aFnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="szzlgn//"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f69587fde8si19523885ad.228.2024.06.04.13.07.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 13:07:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="szzlgn//"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BFB9928345D for ; Tue, 4 Jun 2024 20:06:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B44614D293; Tue, 4 Jun 2024 20:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="szzlgn//" 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 21E7414B061; Tue, 4 Jun 2024 20:04:35 +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=1717531476; cv=none; b=kY02hPtxJml6LlbqsSxG7aK5o6g/rg7YniFRqNlg8HH0QneLD9NoF2Xh8QB2GZMwXCJXQDByk+qd4XPU9NbD1gbpKDD1WOHS/dkjpTVorNm7TNdaDewf86qt6Mb/FYOqNtUfViWdssgxT8OnxGYNcKOT2utQ/nE8ucozgkRku+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717531476; c=relaxed/simple; bh=TMgn7zTEGzLC10FmODgIHZC1q/TA7cHJbeHkzDcrUJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MoH/Fve0KqJGfJXLXrDuBy0tUBCZvSfKYQNt6cqOzkxWLO+ytW7lUgrNVnx8NRxYtWWe2m1R+obglCbdffppq6ZmCXdqK1SH+oETCPZhyOjRjBXgJb7VO67wgyNwYwd9h7YyPFuY3/0wYbBzlYq7HUQMIugvEMMi05C0xk8i11k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=szzlgn//; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EA1BC2BBFC; Tue, 4 Jun 2024 20:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717531475; bh=TMgn7zTEGzLC10FmODgIHZC1q/TA7cHJbeHkzDcrUJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=szzlgn//rhriiVwGMiESgp+pG34SMvZuLTTEd5+ZaU29XJbvqzIQfMtQJqJiPC8sG kqEa8C0w4mcHqyMpeGnJH5JHkLch2S9p+Ms4lavBg2MRvp7sp59qQyW+pAwo5G1vyA auD/2RQAJfbEpUSlwmw5saLZ7v/H9W4uKX5poF2luHUwxzswQ3bYmH2MmePdGxUrpc q4ywXjUuWBmHayDnO0tdTM+iIvHznUnHdXQkoFqRKpeFG39f5ooEk0ujQhHebvEGtV jkUHrYvaVld2NXxwqm6Wu3gI66X9hzE/cRzKpJHijPL9xM4zK2349CS6MuyD0Ip61h JFZeaJxfBiWCA== From: Jiri Olsa To: Oleg Nesterov , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [RFC bpf-next 10/10] selftests/bpf: Add uprobe session recursive test Date: Tue, 4 Jun 2024 22:02:21 +0200 Message-ID: <20240604200221.377848-11-jolsa@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240604200221.377848-1-jolsa@kernel.org> References: <20240604200221.377848-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: 8bit Adding uprobe session test that verifies the cookie value is stored properly when single uprobe-ed function is executed recursively. Signed-off-by: Jiri Olsa --- .../bpf/prog_tests/uprobe_multi_test.c | 57 +++++++++++++++++++ .../progs/uprobe_multi_session_recursive.c | 44 ++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c index 34671253e130..cdd7c327e16d 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c @@ -7,6 +7,7 @@ #include "uprobe_multi_usdt.skel.h" #include "uprobe_multi_session.skel.h" #include "uprobe_multi_session_cookie.skel.h" +#include "uprobe_multi_session_recursive.skel.h" #include "bpf/libbpf_internal.h" #include "testing_helpers.h" @@ -27,6 +28,12 @@ noinline void uprobe_multi_func_3(void) asm volatile (""); } +noinline void uprobe_session_recursive(int i) +{ + if (i) + uprobe_session_recursive(i - 1); +} + struct child { int go[2]; int pid; @@ -587,6 +594,54 @@ static void test_session_cookie_skel_api(void) uprobe_multi_session_cookie__destroy(skel); } +static void test_session_recursive_skel_api(void) +{ + struct uprobe_multi_session_recursive *skel = NULL; + int i, err; + + skel = uprobe_multi_session_recursive__open_and_load(); + if (!ASSERT_OK_PTR(skel, "uprobe_multi_session_recursive__open_and_load")) + goto cleanup; + + skel->bss->pid = getpid(); + + err = uprobe_multi_session_recursive__attach(skel); + if (!ASSERT_OK(err, "uprobe_multi_session_recursive__attach")) + goto cleanup; + + for (i = 0; i < ARRAY_SIZE(skel->bss->test_uprobe_cookie_entry); i++) + skel->bss->test_uprobe_cookie_entry[i] = i + 1; + + uprobe_session_recursive(5); + + /* + * entry uprobe: + * uprobe_session_recursive(5) { *cookie = 1, return 0 + * uprobe_session_recursive(4) { *cookie = 2, return 1 + * uprobe_session_recursive(3) { *cookie = 3, return 0 + * uprobe_session_recursive(2) { *cookie = 4, return 1 + * uprobe_session_recursive(1) { *cookie = 5, return 0 + * uprobe_session_recursive(0) { *cookie = 6, return 1 + * return uprobe: + * } i = 0 not executed + * } i = 1 test_uprobe_cookie_return[0] = 5 + * } i = 2 not executed + * } i = 3 test_uprobe_cookie_return[1] = 3 + * } i = 4 not executed + * } i = 5 test_uprobe_cookie_return[2] = 1 + */ + + ASSERT_EQ(skel->bss->idx_entry, 6, "idx_entry"); + ASSERT_EQ(skel->bss->idx_return, 3, "idx_return"); + + ASSERT_EQ(skel->bss->test_uprobe_cookie_return[0], 5, "test_uprobe_cookie_return[0]"); + ASSERT_EQ(skel->bss->test_uprobe_cookie_return[1], 3, "test_uprobe_cookie_return[1]"); + ASSERT_EQ(skel->bss->test_uprobe_cookie_return[2], 1, "test_uprobe_cookie_return[2]"); + +cleanup: + uprobe_multi_session_recursive__destroy(skel); +} + static void test_bench_attach_uprobe(void) { long attach_start_ns = 0, attach_end_ns = 0; @@ -681,4 +736,6 @@ void test_uprobe_multi_test(void) test_session_error_multiple_instances(); if (test__start_subtest("session_cookie")) test_session_cookie_skel_api(); + if (test__start_subtest("session_cookie_recursive")) + test_session_recursive_skel_api(); } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c new file mode 100644 index 000000000000..7babc180c28f --- /dev/null +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "bpf_kfuncs.h" +#include "bpf_misc.h" + +char _license[] SEC("license") = "GPL"; + +int pid = 0; + +int idx_entry = 0; +int idx_return = 0; + +__u64 test_uprobe_cookie_entry[6]; +__u64 test_uprobe_cookie_return[3]; + +static int check_cookie(void) +{ + long *cookie = bpf_session_cookie(); + + if (bpf_session_is_return()) { + if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return)) + return 1; + test_uprobe_cookie_return[idx_return++] = *cookie; + return 0; + } + + if (idx_entry >= ARRAY_SIZE(test_uprobe_cookie_entry)) + return 1; + *cookie = test_uprobe_cookie_entry[idx_entry]; + return idx_entry++ % 2; +} + + +SEC("uprobe.session//proc/self/exe:uprobe_session_recursive") +int uprobe_recursive(struct pt_regs *ctx) +{ + if (bpf_get_current_pid_tgid() >> 32 != pid) + return 1; + + return check_cookie(); +} -- 2.45.1