From nobody Mon Feb 9 11:29:33 2026 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) (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 05FCF3451AE for ; Sat, 10 Jan 2026 14:13:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768054398; cv=none; b=amH9UxbSTB3TSOAdQk5Gv9/2Ap5Kvbftx4qUIS9/z2x2++MLWk3j6D9u80D6X/kNfq+1kDujh1QWRLpoFNH53VJr2Ar4SvF14pEheRZ841IqputJswbr1A6vLg+8nYErbAHEdchR10Fx0NlxwnLLbNVbD20vVNEsuzsAmSD8sps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768054398; c=relaxed/simple; bh=gXCuEnHLqfXsAH6FAwsjxm9SB5MyEaZI5cp68UEcCxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qYgjeDHwg+fByWutEjB5FDcMR5zorYqxiVjAqsmYWgGl28XaYHoFxH9CAUAgfoFvgJgheIXPEh1D90cLfwv+FAoc1+uQzjmtWwCmT/irDCS9DMqg8gX+8z1Z508vBFDm9B8pRd102EIKm/8yaluy09gbcYnL3x0bzxDkWuJKhD8= 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=AyQt6RlD; arc=none smtp.client-ip=209.85.216.68 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="AyQt6RlD" Received: by mail-pj1-f68.google.com with SMTP id 98e67ed59e1d1-34c3259da34so3152880a91.2 for ; Sat, 10 Jan 2026 06:13:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768054396; x=1768659196; 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=V0oqk3QUBfKZsQ1aXSAR/rKLECXiTolyzvGw8W9Eifk=; b=AyQt6RlDNs+uqwnxX/5qWaa96aotiR0MVIzcR6pJrglwwoPdJ53Wd2DU48qUBwOXOA EDsAGialjUClSuMU6DTdbioJpRLpXwNdUQyXnz6vNgq+hZcpXDqtjIdb6cBqCxyoEJrI AhVsMXQHJZ0786My6nm7p2n1YHIObRAY+ucfshyEyNegi+zDoqivm6cY4Z5xUxWNbJ7+ dcYmnnvgZJSW3HWR3gSivLXFzL9OkIcs5tvxOuq5vSsOn4BuPbGjLAWIQBsMDX/vbNTW OkA/ft5D0xWn2IwLs+QuddxyZCNUwh/1jC32GiwMrqDl2dD9ugG1ag2lDAiiozzU/4dc dtmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768054396; x=1768659196; 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=V0oqk3QUBfKZsQ1aXSAR/rKLECXiTolyzvGw8W9Eifk=; b=IllLGhERfQu8uH3Ce5wkxQRU+phnNYM4d493zCT0YNWuoyy3kNuT9ase24gQLja8xf 9QLL2/wTUshj/dfBan5NRvRy2zppU7ULJbgJOrVFWzv5vawtJG0CsWTIULX9m4bBRkoY dBaBxA/f8mpe3X8gN9lHsAlW1ChGQXdO+Fb0KVSAArhxb29iR2SbDa2TcWWK+YDinh8q 2oW5v7iS7BhxiUkmtVaXMhwh8FK0OhxwSGoFq+rjX9HJrWJbazFCHpGhfXM33/Qb1bMm tm6dxuLiuS4SiwEi1AbEnXIHNZd6+rEsHukdwHlmkhFbZeQq6syn3m5KvS8f+e9aCNkZ xzRA== X-Forwarded-Encrypted: i=1; AJvYcCUmql8DOXEoxkHTl3VshTrOkjzF3S2Jshe+Fy57XocmhTDxtpIG5sMDECEQ5S5tBq97xx4SD/VLUkSCyGg=@vger.kernel.org X-Gm-Message-State: AOJu0YzuP8AQ9W4CPLAX0xasyrsH3fe3NfzDvM0Fu1Y+kyutraAUJ8Ah +55C9/exVjzjlgMO+ncbxFiv+od/Fbaw4IQy+IvP0Mb8U81Jj0tyJiSG X-Gm-Gg: AY/fxX7SOo9ZgawAJHKxy0n2QoBiXSTSOZlcVR1p/ZKVs31zh6vTl8hWzBModqSh3rn uUBbHD/Qa+wsOh++hCD/Pw4bRdXmF3tElI9jK1WZyvnZNAdytST5W2dJajtWw7KQN27rwBRbqgG P+ydgR1QoL9TEZ+NBuy8jMyaFkGw0+EEaU8csgXupci9XGPbKYniJTGY5lmWFUsjHmU3dEuuR8J jN2rNYssqQSe1b/peT850CjGn5cNrV7N43/aSSBKnPStTt1mQGgT3UM20dW2hTBkhMvBN6QyBul RqyCHofZMo2MQcX/AHuxGAmFN147B57QkCLqDcj2S0CsaBlaIPSKvw9FuTHavZ1e7bzsTJ6km/y zHe8K/y7d+HpfjA+vSv1M78hPXp45sQ+fvtlkkTostoUQ5SZKRaG2LkCob/OkRYqWm+Zoedld9S MJmW0U8KwwWn9Lh3ABxw== X-Google-Smtp-Source: AGHT+IEm7VhbnMXmVox9xOg+CjqsU7K85YOVbAC/1coBNdKuVTJAf+ZFE4/LT/Ud++6Q8KkUOQoKvg== X-Received: by 2002:a17:90b:57c4:b0:34c:a211:e52a with SMTP id 98e67ed59e1d1-34f68cae46emr11853633a91.27.1768054396410; Sat, 10 Jan 2026 06:13:16 -0800 (PST) Received: from 7950hx ([160.187.0.149]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81f42658f03sm1481079b3a.20.2026.01.10.06.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 06:13:16 -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 v9 10/11] selftests/bpf: add testcases for fsession cookie Date: Sat, 10 Jan 2026 22:11:14 +0800 Message-ID: <20260110141115.537055-11-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260110141115.537055-1-dongml2@chinatelecom.cn> References: <20260110141115.537055-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 f504984d42f2..85e89f7219a7 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_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) +{ + __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; +} + +SEC("fsession/bpf_fentry_test1") +int BPF_PROG(test10, int a, int ret) +{ + __u64 *cookie =3D bpf_session_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_session_cookie(ctx); + + *cookie =3D 0; + return 0; +} --=20 2.52.0