Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp342368lqb; Tue, 4 Jun 2024 13:06:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5/+hRO+1i1K3qLHMmbe3QLG7D9e4zpGdqXjqB3q89ISmDt1G2AkgmQQf+3qlOlmSeulksi3GkHXNPrDVeyEztcgTPES+rCedsoTct7Q== X-Google-Smtp-Source: AGHT+IEJrextZEU1KT5jkzYJOrjF/BiZDYlUwvy9xVaVY9yr8EMetZMwcw0KhKkNyWahBo5gcuiP X-Received: by 2002:a17:903:32c9:b0:1f6:62b0:8f8d with SMTP id d9443c01a7336-1f6936b76ecmr58672665ad.5.1717531568415; Tue, 04 Jun 2024 13:06:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717531568; cv=pass; d=google.com; s=arc-20160816; b=vpGxpNbPQjfMTNUIMtZjtX8Zc1hDNvtlYo8lD3o3QmaFl1uW0jmetvU0nS0dGmMUpb JQ+BOQZuv13Vpx9klVyLuAnWwj811JHJTnPUylQL8BnksSR1Lks9NMuLnyaRh2jFgSBg xsS0xwsEMDAPcBrcFrKWwjsAjm2qbgtBHkvNyYIR6CPkhKxMVBQSSgE6WdZqv1AFY3Eo /pUaXGbNIoGSMD1vvQ0RTdNTq5OUFl1FOmJcg23xUhnjalsFbymSiL/Ekxi15/5gDLzw SoPVnW/CSypnrxiUoVAkoconQI+47jgj2Mu8U/a5FsyaQhUOG5Jcl4lq/Zfs8m0Dsodp dzsQ== 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=tzzYRtYQMy8tWMpvpCbqpIidM63+UNEr+hWzu8mi2Oo=; fh=u3to46i6vVc15/oqkgIGXd5IRsv1JvYq+fe7qFLhiF8=; b=unAUFM82Cd4UQVZw9liA28ueC8INZVFHlHZ0wnosK7/8nJ5qW+E7RBVt+R6eiBgJ/2 TD3KTF3mlBNpaWTEhl7B8mFH/m5GQMJ58C65ZhnVorBgFY/FfGZK5VyvuXir32QrmJlV QsOZ7s/MTdkfWbQEQNXmI3OSP85317eIAYEZ3iVob78qWX8P1zwkBlZiAZUSS98l/7gb Y1cyrgB9Ngi4uCTT96O6k1uuXyr3LQgCLduP+crsqzRUvA9TVi4sSjf+ySfU/ym+emNn fegAwmp8kLqP3y096CdFe84qEhEiHwW1/AnHSSP6SXoPoPAeQbcEF/k/Y28aCE8znyV5 z5Tg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A27RG7p0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201325-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f63233eefbsi88424865ad.7.2024.06.04.13.06.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 13:06:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A27RG7p0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201325-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201325-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 14940285727 for ; Tue, 4 Jun 2024 20:06:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4722114D71E; Tue, 4 Jun 2024 20:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A27RG7p0" 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 6215F14B097; Tue, 4 Jun 2024 20:04:24 +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=1717531464; cv=none; b=fMfI+hvjk62mi4Wc+JnL2WJ+RVYJaSUTxrL8O83lqpCyqcbtSPsnoq5vPSzb8eS3tAlehnbivdg/BUX/24vbV4lXP92C0qRAPp/epkPzVXddMbpvPMpcHLFif4TYsf/SKWuq1BcJ9UzVC44Pm//+lEhRu3pW3QalWnWhDCmgv3w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717531464; c=relaxed/simple; bh=hu7KQGmdhNivcXLEk2nPk2e4zfC0G+cAgMVE0tYtsfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rOyK4XD4aAQFg+DkpjPIhQVDgS5hoTL7chLYWXzrVhRvyxhWMebQi+zCfkrRjv5kYYK5TJr56iDWCZqcJyvcYPHQPAV/9pYOdpQsGGssjaJFfzp1VElf0U3Z0Fw4KIacZG6K94JsCtURuaVgacV8UcpF0ztOu1jGLSDyrTeF3H4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A27RG7p0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2463C3277B; Tue, 4 Jun 2024 20:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717531464; bh=hu7KQGmdhNivcXLEk2nPk2e4zfC0G+cAgMVE0tYtsfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A27RG7p0Ut4hS8633QUIShMZWre3yWrMVdDj32CeBfvfHNHTChdE0xeZyeftqNNlS svhEuye941yg/qlaFWkXL7i+gDayzw5dJH4l4qKJPHsHv4GJdAx9Y1Bl97d+pkrALT waFQQ5O0nZQRdSzXRtSDFkJgdpbagwZ6q/URHeSCzys/g5lzeVA/3QmLNRvCI7wHQl /UzBPVqP6PL48UoDYKrU4tPLjnKVIfJEHFu0uSVpJH/ZR9QUe7Xhnt7VyYa1tnZFWD UPid2GcHQG6PfXrAf1Ugay5LwIdhIXOSOamr5kErSz/P/MfFLC+FhrRgCJMNshKRbs R7h8QjVN3X7MQ== 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 09/10] selftests/bpf: Add uprobe session cookie test Date: Tue, 4 Jun 2024 22:02:20 +0200 Message-ID: <20240604200221.377848-10-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 get properly propagated from entry to return program. Signed-off-by: Jiri Olsa --- .../bpf/prog_tests/uprobe_multi_test.c | 31 ++++++++++++ .../bpf/progs/uprobe_multi_session_cookie.c | 50 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.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 4bff681f0d7d..34671253e130 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c @@ -6,6 +6,7 @@ #include "uprobe_multi_bench.skel.h" #include "uprobe_multi_usdt.skel.h" #include "uprobe_multi_session.skel.h" +#include "uprobe_multi_session_cookie.skel.h" #include "bpf/libbpf_internal.h" #include "testing_helpers.h" @@ -558,6 +559,34 @@ static void test_session_error_multiple_instances(void) uprobe_multi_session__destroy(skel_2); } +static void test_session_cookie_skel_api(void) +{ + struct uprobe_multi_session_cookie *skel = NULL; + int err; + + skel = uprobe_multi_session_cookie__open_and_load(); + if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load")) + goto cleanup; + + skel->bss->pid = getpid(); + + err = uprobe_multi_session_cookie__attach(skel); + if (!ASSERT_OK(err, " kprobe_multi_session__attach")) + goto cleanup; + + /* trigger all probes */ + uprobe_multi_func_1(); + uprobe_multi_func_2(); + uprobe_multi_func_3(); + + ASSERT_EQ(skel->bss->test_uprobe_1_result, 1, "test_uprobe_1_result"); + ASSERT_EQ(skel->bss->test_uprobe_2_result, 2, "test_uprobe_2_result"); + ASSERT_EQ(skel->bss->test_uprobe_3_result, 3, "test_uprobe_3_result"); + +cleanup: + uprobe_multi_session_cookie__destroy(skel); +} + static void test_bench_attach_uprobe(void) { long attach_start_ns = 0, attach_end_ns = 0; @@ -650,4 +679,6 @@ void test_uprobe_multi_test(void) test_session_skel_api(); if (test__start_subtest("session_errors")) test_session_error_multiple_instances(); + if (test__start_subtest("session_cookie")) + test_session_cookie_skel_api(); } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c b/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c new file mode 100644 index 000000000000..ea41503fad18 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "bpf_kfuncs.h" + +char _license[] SEC("license") = "GPL"; + +int pid = 0; + +__u64 test_uprobe_1_result = 0; +__u64 test_uprobe_2_result = 0; +__u64 test_uprobe_3_result = 0; + +static int check_cookie(__u64 val, __u64 *result) +{ + long *cookie; + + if (bpf_get_current_pid_tgid() >> 32 != pid) + return 1; + + cookie = bpf_session_cookie(); + + if (bpf_session_is_return()) { + *result = *cookie == val ? val : 0; + } else { + *cookie = val; + } + + return 0; +} + +SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1") +int uprobe_1(struct pt_regs *ctx) +{ + return check_cookie(1, &test_uprobe_1_result); +} + +SEC("uprobe.session//proc/self/exe:uprobe_multi_func_2") +int uprobe_2(struct pt_regs *ctx) +{ + return check_cookie(2, &test_uprobe_2_result); +} + +SEC("uprobe.session//proc/self/exe:uprobe_multi_func_3") +int uprobe_3(struct pt_regs *ctx) +{ + return check_cookie(3, &test_uprobe_3_result); +} -- 2.45.1