From nobody Mon Feb 9 11:47:18 2026 Received: from mail-yw1-f196.google.com (mail-yw1-f196.google.com [209.85.128.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0CAE155C87 for ; Sun, 4 Jan 2026 12:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767529820; cv=none; b=J5qHBQSRGo3p1Z47jvwYCStt3hnbZIx2Dqhr4OFyNpJ7Wr1302dvfySCMOJnusiU0UliG6Lmfdtegvly0EpnE/pnpd9QeIP1tHdnlVTJDCXLZ13VKzkm2VHWB45DHD7G2Lgjl8Cmu34XnX+WmYVluyuiZy1DlL5wWrXU0QcroUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767529820; c=relaxed/simple; bh=30IrruSBttNJv11mnhPPFrDbo5C5jVGpYPadqyOEUcg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=afyCBaWHEKodn9dOTnYvNv88UtzNtqbixo1P+igSwupHEwWLe0Kvx3aMCKDCzfyY4ZUeWk29+mP1811c8HNvnlFQyTxc6Nb2OE3Pvx52QctD3dxou7he/QXh1lbI7zNCcdp8h8/2HrvqDtMNVY3uMVI/cGbqMS/mHqqZ2FSZqrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bxyI1OfM; arc=none smtp.client-ip=209.85.128.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bxyI1OfM" Received: by mail-yw1-f196.google.com with SMTP id 00721157ae682-78fc0f33998so86385967b3.0 for ; Sun, 04 Jan 2026 04:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767529818; x=1768134618; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i4Bxr4OZff+AEQ0Kvht+WX5RF8ZeS18xbuX/dUJTalk=; b=bxyI1OfMRLesF6qlo60Jj8Gu8mJ6w8FhRMqlL/MS0XcJGmr8kxBII9nUgkDuRsclOK UALToxRGu+KuuKHkL1WxfRxYuEHT8Pse23BqLmV7o3WvNwnESnjzcZEvcVBJdkciHduF SYPa0xUUJvNI49loWwNVq7P+feX659v7Rf6JbsfvwJkXzL9ydn/qJLN5QyoifVilkdIA xxdcEMt5bh2O7GNZVWQ+CZogQL3o7kdgOH6iNn+w/IRoVhDiMVcO6g1bsX3+STIhR6zd peDF7MLmkUuK2e+y3oxj1mF2bWb60vx43oZB9jTFNA4kGiGE4JRfQIo5S8HCvAdZpeFp LRIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767529818; x=1768134618; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i4Bxr4OZff+AEQ0Kvht+WX5RF8ZeS18xbuX/dUJTalk=; b=VyyhUbElZ+1ABmOTh/wUvdYYisgxLLZiFXDRK9w/hS0I988cZDJFNo02yyPK8ZkFXs VNFFG/D1VU420//Ol74942arTR/f05FrAs+Turk5c19HU0N8BL5GwXfwIL3QiqChqH7R Mu/K+2T1BwDyCk7zCgHastX/hGVxBVC2+Edz6IfnpPChT9/z1Bc/hpqekemBOzLtc9fl 1NCRAU5ieDZi3Nx/DJQ0D3mXQCpMNXEhdjPDqu0oD5B5T4q9uyeZMNwLChnDh/3SARFh Mg4zoR9o2KdvcM3ddITec1M3N75fdDyKRX29dXHSPiPbighUe5/NbgnuCgCm/MDHL1V0 VjbQ== X-Forwarded-Encrypted: i=1; AJvYcCUBksiNbgZcpEsi9339ENC9fy8ReTMq1LEj416Joh7XS+tLCHcUBIxWtv2Q2z68X3VBru2XboK06sxFeaI=@vger.kernel.org X-Gm-Message-State: AOJu0YycQ+ZTS7rmgM7oTT8WpB+wiUdiEMeJdWHbQIGl/3LdH59N8ges e4ptoucShQvtqkTXTXg+wUeRe/dhstKTi8FAvr/a9dajPq5kC+4La1X6 X-Gm-Gg: AY/fxX4RuWxlHMpzKCQ1f/cghY0+137px8UtoUWt779Na/McDXP89oGnKZ9Ox9/xaeQ bKSBtJ2CsmPpJ07KmTJM8RRmxUq1AtzLE+jcJTOUrpAlb2i24Uu0c5KjU2NfpWlUBXRQaiKoovh KM0Ua89/VEu/gEEugpiAcpLIl9PY5VxdfYbeDDUVuECrJ8X3AQv+tuopu65f0HY3SO5MWz0DvXT f3xeN1vnW4wXnBy0A3Om4PskfCVBBbXyHmUw7Ih9sDB5X6BSBuImDG0vr+G8acqcoYdtYN+EI7t g15htX9Rorva+D8sZRZVIsVZaX2grXaGXW+70rTx+brGNsU5NGScTjFGl08h8cT1PKeunTVA24N qq/DSXC00VFfRkMczCU/cnFGu4WdcW4a15jGbIyA4Eb3y44uJ5y8s5/DtIgY0m4FlyDjlapgtEj O+T+DgjLs= X-Google-Smtp-Source: AGHT+IEttVPCWCvk8Pr0apQez8fgF7tG1sqIw2qS7xEH+hRKidNyasenyD8alWTfRCkhKagcAfR5Cg== X-Received: by 2002:a05:690c:2703:b0:789:61ca:88f6 with SMTP id 00721157ae682-78fb3f02ce1mr844762997b3.4.1767529817694; Sun, 04 Jan 2026 04:30:17 -0800 (PST) Received: from 7940hx ([23.94.188.235]) by smtp.gmail.com with ESMTPSA id 00721157ae682-78fb4378372sm175449427b3.12.2026.01.04.04.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jan 2026 04:30:17 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@kernel.org, andrii@kernel.org Cc: daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, dsahern@kernel.org, tglx@linutronix.de, mingo@redhat.com, jiang.biao@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v6 08/10] selftests/bpf: add testcases for fsession Date: Sun, 4 Jan 2026 20:28:12 +0800 Message-ID: <20260104122814.183732-9-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260104122814.183732-1-dongml2@chinatelecom.cn> References: <20260104122814.183732-1-dongml2@chinatelecom.cn> 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" Add testcases for BPF_TRACE_FSESSION. The function arguments and return value are tested both in the entry and exit. And the kfunc bpf_fsession_is_ret() is also tested. As the layout of the stack changed for fsession, so we also test bpf_get_func_ip() for it. Signed-off-by: Menglong Dong --- .../selftests/bpf/prog_tests/fsession_test.c | 90 ++++++++++++++ .../selftests/bpf/progs/fsession_test.c | 110 ++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/fsession_test.c create mode 100644 tools/testing/selftests/bpf/progs/fsession_test.c diff --git a/tools/testing/selftests/bpf/prog_tests/fsession_test.c b/tools= /testing/selftests/bpf/prog_tests/fsession_test.c new file mode 100644 index 000000000000..83f3953a1ff6 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/fsession_test.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 ChinaTelecom */ +#include +#include "fsession_test.skel.h" + +static int check_result(struct fsession_test *skel) +{ + LIBBPF_OPTS(bpf_test_run_opts, topts); + int err, prog_fd; + + /* Trigger test function calls */ + prog_fd =3D bpf_program__fd(skel->progs.test1); + err =3D bpf_prog_test_run_opts(prog_fd, &topts); + if (!ASSERT_OK(err, "test_run_opts err")) + return err; + if (!ASSERT_OK(topts.retval, "test_run_opts retval")) + return topts.retval; + + for (int i =3D 0; i < sizeof(*skel->bss) / sizeof(__u64); i++) { + if (!ASSERT_EQ(((__u64 *)skel->bss)[i], 1, "test_result")) + return -EINVAL; + } + + return 0; +} + +static void test_fsession_basic(void) +{ + struct fsession_test *skel =3D NULL; + int err; + + skel =3D fsession_test__open_and_load(); + if (!ASSERT_OK_PTR(skel, "fsession_test__open_and_load")) + goto cleanup; + + err =3D fsession_test__attach(skel); + if (!ASSERT_OK(err, "fsession_attach")) + goto cleanup; + + check_result(skel); +cleanup: + fsession_test__destroy(skel); +} + +static void test_fsession_reattach(void) +{ + struct fsession_test *skel =3D NULL; + int err; + + skel =3D fsession_test__open_and_load(); + if (!ASSERT_OK_PTR(skel, "fsession_test__open_and_load")) + goto cleanup; + + /* First attach */ + err =3D fsession_test__attach(skel); + if (!ASSERT_OK(err, "fsession_first_attach")) + goto cleanup; + + if (check_result(skel)) + goto cleanup; + + /* Detach */ + fsession_test__detach(skel); + + /* Reset counters */ + memset(skel->bss, 0, sizeof(*skel->bss)); + + /* Second attach */ + err =3D fsession_test__attach(skel); + if (!ASSERT_OK(err, "fsession_second_attach")) + goto cleanup; + + if (check_result(skel)) + goto cleanup; + +cleanup: + fsession_test__destroy(skel); +} + +void test_fsession_test(void) +{ +#if !defined(__x86_64__) + test__skip(); + return; +#endif + if (test__start_subtest("fsession_basic")) + test_fsession_basic(); + if (test__start_subtest("fsession_reattach")) + test_fsession_reattach(); +} diff --git a/tools/testing/selftests/bpf/progs/fsession_test.c b/tools/test= ing/selftests/bpf/progs/fsession_test.c new file mode 100644 index 000000000000..b180e339c17f --- /dev/null +++ b/tools/testing/selftests/bpf/progs/fsession_test.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 ChinaTelecom */ +#include +#include +#include + +char _license[] SEC("license") =3D "GPL"; + +__u64 test1_entry_result =3D 0; +__u64 test1_exit_result =3D 0; + +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test1, int a, int ret) +{ + bool is_exit =3D bpf_fsession_is_return(ctx); + + if (!is_exit) { + test1_entry_result =3D a =3D=3D 1 && ret =3D=3D 0; + return 0; + } + + test1_exit_result =3D a =3D=3D 1 && ret =3D=3D 2; + return 0; +} + +__u64 test2_entry_result =3D 0; +__u64 test2_exit_result =3D 0; + +SEC("fsession/bpf_fentry_test3") +int BPF_PROG(test2, char a, int b, __u64 c, int ret) +{ + bool is_exit =3D bpf_fsession_is_return(ctx); + + if (!is_exit) { + test2_entry_result =3D a =3D=3D 4 && b =3D=3D 5 && c =3D=3D 6 && ret =3D= =3D 0; + return 0; + } + + test2_exit_result =3D a =3D=3D 4 && b =3D=3D 5 && c =3D=3D 6 && ret =3D= =3D 15; + return 0; +} + +__u64 test3_entry_result =3D 0; +__u64 test3_exit_result =3D 0; + +SEC("fsession/bpf_fentry_test4") +int BPF_PROG(test3, void *a, char b, int c, __u64 d, int ret) +{ + bool is_exit =3D bpf_fsession_is_return(ctx); + + if (!is_exit) { + test3_entry_result =3D a =3D=3D (void *)7 && b =3D=3D 8 && c =3D=3D 9 &&= d =3D=3D 10 && ret =3D=3D 0; + return 0; + } + + test3_exit_result =3D a =3D=3D (void *)7 && b =3D=3D 8 && c =3D=3D 9 && d= =3D=3D 10 && ret =3D=3D 34; + return 0; +} + +__u64 test4_entry_result =3D 0; +__u64 test4_exit_result =3D 0; + +SEC("fsession/bpf_fentry_test5") +int BPF_PROG(test4, __u64 a, void *b, short c, int d, __u64 e, int ret) +{ + bool is_exit =3D bpf_fsession_is_return(ctx); + + if (!is_exit) { + test4_entry_result =3D a =3D=3D 11 && b =3D=3D (void *)12 && c =3D=3D 13= && d =3D=3D 14 && + e =3D=3D 15 && ret =3D=3D 0; + return 0; + } + + test4_exit_result =3D a =3D=3D 11 && b =3D=3D (void *)12 && c =3D=3D 13 &= & d =3D=3D 14 && + e =3D=3D 15 && ret =3D=3D 65; + return 0; +} + +__u64 test5_entry_result =3D 0; +__u64 test5_exit_result =3D 0; + +SEC("fsession/bpf_fentry_test7") +int BPF_PROG(test5, struct bpf_fentry_test_t *arg, int ret) +{ + bool is_exit =3D bpf_fsession_is_return(ctx); + + if (!is_exit) { + if (!arg) + test5_entry_result =3D ret =3D=3D 0; + return 0; + } + + if (!arg) + test5_exit_result =3D 1; + return 0; +} + +__u64 test6_entry_result =3D 0; +__u64 test6_exit_result =3D 0; +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test6, int a) +{ + __u64 addr =3D bpf_get_func_ip(ctx); + + if (bpf_fsession_is_return(ctx)) + test6_exit_result =3D (const void *) addr =3D=3D &bpf_fentry_test1; + else + test6_entry_result =3D (const void *) addr =3D=3D &bpf_fentry_test1; + return 0; +} --=20 2.52.0