From nobody Mon Feb 9 23:15:07 2026 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (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 EDC01346FB7 for ; Wed, 24 Dec 2025 13:09:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766581796; cv=none; b=sDV5DYpvS2pswG9mMBxaY/OEofOjoB2AP/1/g+p2v+3pxOxHw+N6J0+fiLhT1pnNnNMZBVOSGEh3jQeldS/H4ZGf0q62XeX68SzN0Kbn5KGegDu9xvpkM7Bx/kuo+jwOAzTXLjK4pyBDqW4ND86sCZL+JxgmtPFE80nEsxNp9Zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766581796; c=relaxed/simple; bh=7SDJuFphpW3+olwFXj0xPVEig/npNUEHxEDid1Ga1WY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LtiyQQoPlciwNp0dNwvkPO8x1PF0fONftiU/lyPP6joXq+1uNdhfqyZkJtQQ+MDr/r+ZyEXlOAqnRjIIKiaVUVzyoeLsj5VKAJlUGSfJ3elx+9GZG/yLxlTt8buOvwQ+fg8Cq5cDOCZKTI9b8sUuRQ53nWJAARKwH+q/vkyyfVs= 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=e54ujjhf; arc=none smtp.client-ip=209.85.210.195 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="e54ujjhf" Received: by mail-pf1-f195.google.com with SMTP id d2e1a72fcca58-7ba55660769so4763661b3a.1 for ; Wed, 24 Dec 2025 05:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766581794; x=1767186594; 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=h66nM9SmW+4KvKNcMfrx/eUWGHnc/5Crgy2rlwqjCZQ=; b=e54ujjhfhAfZrgyRuUUB/fnLE+/329MHOKPZK86MWG16vin7+5wg9p1MIkUQblZtxe iC1avUf8lM8HmWD12FBShl07YQm7NJypN/eDozi6B7OtfzPfe5SSEkFW1XSm5zf7n3lW bFNZjTEVWxhWHCwn/NzlTKCNySAyF/V3sF9XiFDAtYjAO+u2cIxrSSmFBqDlxD35J4Ej 4RuCynPLKI6cZpM6JFBnf9P71wuqmcNrc5oJofCB3HJrSEOgCGUvm7ZCvtuKrVRo66nI 5E6gG3TY36wKHDnJztsA6tu6D8M53gkvlAtPSyAjqXgBYWjJu4Sj2TVbwZnHTfRxHvIq eOzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766581794; x=1767186594; 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=h66nM9SmW+4KvKNcMfrx/eUWGHnc/5Crgy2rlwqjCZQ=; b=NWQOdFvHyUnUZ5+9mmLWPyaAlDJMGzWbfi9GybSMnYFQZGWTJYdr6+2GjDSwc+dv3Q jz9pVuc5Wy4Nafkm+gCOoKVXZSe+oH9MXXPyv5b1KETFszTfQ6d6EfQkqJ5sG+IP/J3e KQsw8gn8zVRdEtHnu+R8BdzuFhtbXEodEjMWf4olF0mheFtVVsfNbjQSRl2plHjGwIf0 lTeZBhaODjQ4kUWTKa/fz0g+L7pl0C2Qrk1yfyx5woXSLsKgpIeyGPAMDkDj8PEvBOcO KxJ+XKDbYwaXm3K6T+qk489CUVOPoCJWc+Fzh3Uif+OuEBpZ0s4edj4jorEYwd4cWSCq LcLg== X-Forwarded-Encrypted: i=1; AJvYcCXoooTrnCgZqSpkbxuJfjuZZNlSbkYjMhwI6f/DT72xueCOVnpQFmivWMC1s4EMh9eXlKHIuhaLCHY6mdw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6yy5GI7FS3ywzPTRaRTPAqnbkzwVF5PWbqYi9GqAu2fV95FtE g6YZW935t/hMrLA79nQ6LBwBLAiQBdxV8JvZW+tHaCrxuhietFqXu7OL X-Gm-Gg: AY/fxX6vz25NhasBlyklN9h5k+VEx4VcmRnyMw4zKhP0fCrI6lG3ZISn3V/W6pxlwce m6UMCOOyMM48HwkGykcgpzzLUcHNybNd5P5oa/9PkTemo6GegzTuWwaV9yFEkV4/2CFhOplriU/ NpztrFt1EvhizCkIcIU8fIOe2QVwNtVHBmwjtcnOKrcr+NtMIHjQ/5w3mC8soNg1quK58wYzZJF Rn229a0hyHYItyYMmN6jmn8u++Rt52YUEzGzOchdqtVIMVtjJjZFcYMJGwzvadTQA/vtDCWRG09 jJIsE1C8qTKbkwVEr8uLTaEM5ZHKvLXxKndRDQJh8JHAW4cIjmatAOORIlhfZz8RmoTog3hUlZi dbcwFsOpACH0voOQmBl4O3ZhdJ6c1kfct+vp22wNfWJ3TmD5x0mvCTc8zV9/FlNlhz31eGIeFry BN20wXXFI= X-Google-Smtp-Source: AGHT+IFg2dw1lbCQhvhHSUK/xEBgEMEUo3jTVgV+JCGMWjyZREF95HQ3ZyvRsYpfI/0QHSvjsunkAA== X-Received: by 2002:a05:6a00:1ca7:b0:7e8:4471:8dc with SMTP id d2e1a72fcca58-7ff66e5d527mr14511852b3a.61.1766581794132; Wed, 24 Dec 2025 05:09:54 -0800 (PST) Received: from 7950hx ([160.187.0.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7dfac28fsm16841173b3a.32.2025.12.24.05.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Dec 2025 05:09:53 -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 v5 09/10] selftests/bpf: add testcases for fsession cookie Date: Wed, 24 Dec 2025 21:07:34 +0800 Message-ID: <20251224130735.201422-10-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251224130735.201422-1-dongml2@chinatelecom.cn> References: <20251224130735.201422-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" Test session cookie for fsession. Multiple fsession BPF progs is attached to bpf_fentry_test1() and session cookie is read and write in the testcase. Signed-off-by: Menglong Dong --- v3: - restructure the testcase by combine the testcases for session cookie and get_func_ip into one patch --- .../selftests/bpf/prog_tests/fsession_test.c | 25 +++++++ .../selftests/bpf/progs/fsession_test.c | 72 +++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/fsession_test.c b/tools= /testing/selftests/bpf/prog_tests/fsession_test.c index 83f3953a1ff6..2459f9db1c92 100644 --- a/tools/testing/selftests/bpf/prog_tests/fsession_test.c +++ b/tools/testing/selftests/bpf/prog_tests/fsession_test.c @@ -77,6 +77,29 @@ static void test_fsession_reattach(void) fsession_test__destroy(skel); } =20 +static void test_fsession_cookie(void) +{ + struct fsession_test *skel =3D NULL; + int err; + + skel =3D fsession_test__open(); + if (!ASSERT_OK_PTR(skel, "fsession_test__open")) + goto cleanup; + + err =3D bpf_program__set_autoload(skel->progs.test11, true); + if (!ASSERT_OK(err, "bpf_program__set_autoload")) + goto cleanup; + + err =3D fsession_test__load(skel); + if (!ASSERT_OK(err, "fsession_test__load")) + goto cleanup; + + err =3D fsession_test__attach(skel); + ASSERT_EQ(err, -E2BIG, "fsession_cookie"); +cleanup: + fsession_test__destroy(skel); +} + void test_fsession_test(void) { #if !defined(__x86_64__) @@ -87,4 +110,6 @@ void test_fsession_test(void) test_fsession_basic(); if (test__start_subtest("fsession_reattach")) test_fsession_reattach(); + if (test__start_subtest("fsession_cookie")) + test_fsession_cookie(); } diff --git a/tools/testing/selftests/bpf/progs/fsession_test.c b/tools/test= ing/selftests/bpf/progs/fsession_test.c index b180e339c17f..5630cf3bbd8b 100644 --- a/tools/testing/selftests/bpf/progs/fsession_test.c +++ b/tools/testing/selftests/bpf/progs/fsession_test.c @@ -108,3 +108,75 @@ int BPF_PROG(test6, int a) test6_entry_result =3D (const void *) addr =3D=3D &bpf_fentry_test1; return 0; } + +__u64 test7_entry_ok =3D 0; +__u64 test7_exit_ok =3D 0; +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test7, int a) +{ + __u64 *cookie =3D bpf_fsession_cookie(ctx); + + if (!bpf_fsession_is_return(ctx)) { + *cookie =3D 0xAAAABBBBCCCCDDDDull; + test7_entry_ok =3D *cookie =3D=3D 0xAAAABBBBCCCCDDDDull; + return 0; + } + + test7_exit_ok =3D *cookie =3D=3D 0xAAAABBBBCCCCDDDDull; + return 0; +} + +__u64 test8_entry_ok =3D 0; +__u64 test8_exit_ok =3D 0; + +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test8, int a) +{ + __u64 *cookie =3D bpf_fsession_cookie(ctx); + + if (!bpf_fsession_is_return(ctx)) { + *cookie =3D 0x1111222233334444ull; + test8_entry_ok =3D *cookie =3D=3D 0x1111222233334444ull; + return 0; + } + + test8_exit_ok =3D *cookie =3D=3D 0x1111222233334444ull; + return 0; +} + +__u64 test9_entry_result =3D 0; +__u64 test9_exit_result =3D 0; + +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test9, int a, int ret) +{ + __u64 *cookie =3D bpf_fsession_cookie(ctx); + + if (!bpf_fsession_is_return(ctx)) { + test9_entry_result =3D a =3D=3D 1 && ret =3D=3D 0; + *cookie =3D 0x123456ULL; + return 0; + } + + test9_exit_result =3D a =3D=3D 1 && ret =3D=3D 2 && *cookie =3D=3D 0x1234= 56ULL; + return 0; +} + +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test10, int a, int ret) +{ + __u64 *cookie =3D bpf_fsession_cookie(ctx); + + *cookie =3D 0; + return 0; +} + +/* This is the 5th cookie, so it should fail */ +SEC("?fsession/bpf_fentry_test1") +int BPF_PROG(test11, int a, int ret) +{ + __u64 *cookie =3D bpf_fsession_cookie(ctx); + + *cookie =3D 0; + return 0; +} --=20 2.52.0