From nobody Mon Feb 9 14:32:41 2026 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.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 146F61CAA79 for ; Sat, 24 Jan 2026 03:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769225600; cv=none; b=tV6SPnhPuoPWcPAo4I6X54ijDcxwg2b6GZYpLcnQi5aA15Y2sGsEPe4AUd0nNYUI0hxCbaAoCjygmWM+vj8xPVs4pUp/eBsNuMOVBjGxu7T0VqG/AKOrVhjj1L5EaDqeqbrZxsx1ecCRgUOFnmnVS+c0cQl0+2yybCFyCYzExXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769225600; c=relaxed/simple; bh=MY0TzEwIF2cncGc4J2MGjes5OtwOQCXp+QMlMZ001rc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MvCyR+tNsVBEjrMJmYt5MKnkNZDTZGmR5fj175Z55qpMjiNsetGnMEeMtO0oEiTbMFfllknnQZXLrHaGTKSjEAAHkd3bXH9fSlkBCk761/yGEFDJSqPVbz0DZ0zl77HImH53HMrDDaJs2y+kYXOrnp+sqoCx1KH7VNzB83CU/Wg= 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=T2Ktq0i2; arc=none smtp.client-ip=209.85.214.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="T2Ktq0i2" Received: by mail-pl1-f195.google.com with SMTP id d9443c01a7336-2a7a23f5915so17898065ad.2 for ; Fri, 23 Jan 2026 19:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769225598; x=1769830398; 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=ePFOCu4by0RV/ygPSJGiVD2r6LAEFSKblHnuNBvqT3M=; b=T2Ktq0i2acqqKiOMV8Kuo2CUC3O7L5j6ASCRSCDI+RxNv7a+BxckrcDGtH69cnUHi/ 2P8/kCWurwddyGxqpSW9FBXIGfc4e5Kpd9S6K7Rk6mOZSbsgAtioDDbirhMqvmc5Ws3D D3AMZ+z58quWI9Jvqtv5HDgoiiYJWkh5kfIVsgcB3O05GTRwjOG5+qrf7jr2+l/4lUEn SS/adGdDzZdYWCsZY01OsVSq2VL1Sy9LUD1DAsand1iuOG1pgGKL8XP69iQqjJuMcO7R 9YJjBRM3R2l5YE8iHu0GV/0zryinbitQMEyl+ojJTPscoUFjErLDffW8r1PUQM8w0N/N GjQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769225598; x=1769830398; 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=ePFOCu4by0RV/ygPSJGiVD2r6LAEFSKblHnuNBvqT3M=; b=vb6rDqlbhnZf0Kf4b0unk7T60og0Jx/4YR6yUIdL+uJRNhd0oyWjX4nDG4rMauNBBk yMfeonNB94QcUOk7+xOUkSdnmQiZzd034ednp9kHOobaefGu/zSzhyJsEDdEgg+P5oqJ Me1WJRy8mNJif7JVOoCdu0rGhNns8Na1Z6Yk7ZOBE+6NP6czrD62dM2MdJfrS2QVkP9i 3ICKMsKlc48kXwkpBFgVhtae7wywxmGZiz9YTa/u/sL9m8mGaOG3IKdiVq8KVAHUxpil +B21DvokGnYbeDd+XOAN4D3D64ppuCwlk8zP5W0HxeA2ApOFmu2snDa5hqLRFDBzsG/k wN2g== X-Forwarded-Encrypted: i=1; AJvYcCXxqiu0msXrmwVjj0YwWELZmtpAVFPmVYfmUUnM2MTezIScO8icmyZk5xLw+UiJ87btO8LACLD3P7KvxNU=@vger.kernel.org X-Gm-Message-State: AOJu0YwQE832nsEweBSHPfAXCYsobEedJFx/UmVy90wqiNKESMgcNljA R5e2JDEUg7OGy9oVLK/fk3aULkt7wnq6S3HU0gAZpOKRMGj6sOCsZsGJ X-Gm-Gg: AZuq6aKB/QutmAdikTM85U+hGtOrl9cl2vu3NEtirXEd9DzEpSiOKFX7r7qZC3qjFf9 oEhQfuySElM0bBz3ohxO4KZ0dqqfTMITpvdO8Zdt+wQxvgCiC1AOfOizpgyYhT2qSs8EA9vqyH8 CldQiOafGJlvnXhnf44TiCy1rLm4+b7RABy7xtFxedypa4YRQpDCyqB1i0aMt/f8eAyYxSVyjUB qZ0ZXUhCdneVDD2TCohREN1tuTbLNRa5P3CwL8KpTWqLoy1ksJ1V3NQXORQzQ2XietqfC/U7RAV HPwe6wgRFnMv16wo4tPpZIsS9hxQKmmwhXVphwSnlyoUV8wzmPbdzHbp2CcRg5xN1GFNheBTHl9 Y898v5wUe8w7Yq3sTdJatkzCi0LsABUO934VlnY5YpPNUJ38wtmWh3SKmMPtObR7Ewbp8Vz/4OK FNpe33gENh X-Received: by 2002:a17:902:db0b:b0:295:20b8:e104 with SMTP id d9443c01a7336-2a80ec7fa5amr32307055ad.58.1769225598537; Fri, 23 Jan 2026 19:33:18 -0800 (PST) Received: from 7950hx ([103.173.155.241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a802dcddb0sm32539805ad.38.2026.01.23.19.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jan 2026 19:33:18 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, 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 v12 12/13] selftests/bpf: add testcases for fsession cookie Date: Sat, 24 Jan 2026 11:31:18 +0800 Message-ID: <20260124033119.28682-13-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260124033119.28682-1-dongml2@chinatelecom.cn> References: <20260124033119.28682-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. bpf_get_func_ip() will influence the layout of the session cookies, so we test the cookie in two case: with and without bpf_get_func_ip(). Signed-off-by: Menglong Dong --- v12: - add the case to test session cookie without bpf_get_func_ip() v11: - add "volatile" to the variable "cookie" 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 | 34 ++++++++++ .../selftests/bpf/progs/fsession_test.c | 66 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/fsession_test.c b/tools= /testing/selftests/bpf/prog_tests/fsession_test.c index 75bb42942b67..0c4b428e1cee 100644 --- a/tools/testing/selftests/bpf/prog_tests/fsession_test.c +++ b/tools/testing/selftests/bpf/prog_tests/fsession_test.c @@ -77,6 +77,38 @@ 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; + + /* + * The test_fsession_basic() will test the session cookie with + * bpf_get_func_ip() case, so we need only check + * the cookie without bpf_get_func_ip() case here + */ + bpf_program__set_autoload(skel->progs.test6, false); + + err =3D fsession_test__load(skel); + if (!ASSERT_OK(err, "fsession_test__load")) + goto cleanup; + + err =3D fsession_test__attach(skel); + if (!ASSERT_OK(err, "fsession_attach")) + goto cleanup; + + skel->bss->test6_entry_result =3D 1; + skel->bss->test6_exit_result =3D 1; + + check_result(skel); +cleanup: + fsession_test__destroy(skel); +} + void test_fsession_test(void) { #if !defined(__x86_64__) @@ -87,4 +119,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 0e1b66b2dddc..211332bdcccb 100644 --- a/tools/testing/selftests/bpf/progs/fsession_test.c +++ b/tools/testing/selftests/bpf/progs/fsession_test.c @@ -95,3 +95,69 @@ int BPF_PROG(test5, struct bpf_fentry_test_t *arg, int r= et) return 0; } =20 +__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_session_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; +} + +__u64 test7_entry_ok =3D 0; +__u64 test7_exit_ok =3D 0; +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test7, int a) +{ + volatile __u64 *cookie =3D bpf_session_cookie(ctx); + + if (!bpf_session_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) +{ + volatile __u64 *cookie =3D bpf_session_cookie(ctx); + + if (!bpf_session_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_session_cookie(ctx); + + if (!bpf_session_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; +} --=20 2.52.0