From: Menglong Dong <menglong.dong@linux.dev>
To: Menglong Dong <menglong8.dong@gmail.com>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: ast@kernel.org, andrii@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: Re: [PATCH bpf-next v10 11/12] selftests/bpf: add testcases for fsession cookie
Date: Thu, 22 Jan 2026 10:18:58 +0800 [thread overview]
Message-ID: <2814828.mvXUDI8C0e@7940hx> (raw)
In-Reply-To: <CAEf4BzYbzSf_jXwFxni0viHRHhYQ=k=Ggq79S=FRNmxQGdcS1w@mail.gmail.com>
On 2026/1/22 08:07 Andrii Nakryiko <andrii.nakryiko@gmail.com> write:
> On Thu, Jan 15, 2026 at 3:24 AM Menglong Dong <menglong8.dong@gmail.com> wrote:
> >
> > 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 <dongml2@chinatelecom.cn>
> > ---
> > v3:
> > - restructure the testcase by combine the testcases for session cookie and
> > get_func_ip into one patch
> > ---
> > .../selftests/bpf/progs/fsession_test.c | 53 +++++++++++++++++++
> > 1 file changed, 53 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/progs/fsession_test.c b/tools/testing/selftests/bpf/progs/fsession_test.c
> > index f504984d42f2..4e55ca67db46 100644
> > --- a/tools/testing/selftests/bpf/progs/fsession_test.c
> > +++ b/tools/testing/selftests/bpf/progs/fsession_test.c
> > @@ -108,3 +108,56 @@ int BPF_PROG(test6, int a)
> > test6_entry_result = (const void *) addr == &bpf_fentry_test1;
> > return 0;
> > }
> > +
> > +__u64 test7_entry_ok = 0;
> > +__u64 test7_exit_ok = 0;
> > +SEC("fsession/bpf_fentry_test1")
> > +int BPF_PROG(test7, int a)
> > +{
> > + __u64 *cookie = bpf_session_cookie(ctx);
> > +
> > + if (!bpf_session_is_return(ctx)) {
> > + *cookie = 0xAAAABBBBCCCCDDDDull;
> > + test7_entry_ok = *cookie == 0xAAAABBBBCCCCDDDDull;
>
> you are trying to double-check that writing into *cookie preserves the
> written value, is that right? Do we need volatile read here to ensure
> that compiler doesn't optimize this?
Yeah, you are right. READ_ONCE and WRITE_ONCE should be used
here. I'll use them next version.
Thanks!
Menglong Dong
>
> > + return 0;
> > + }
> > +
> > + test7_exit_ok = *cookie == 0xAAAABBBBCCCCDDDDull;
> > + return 0;
> > +}
> > +
> > +__u64 test8_entry_ok = 0;
> > +__u64 test8_exit_ok = 0;
> > +
> > +SEC("fsession/bpf_fentry_test1")
> > +int BPF_PROG(test8, int a)
> > +{
> > + __u64 *cookie = bpf_session_cookie(ctx);
> > +
> > + if (!bpf_session_is_return(ctx)) {
> > + *cookie = 0x1111222233334444ull;
> > + test8_entry_ok = *cookie == 0x1111222233334444ull;
> > + return 0;
> > + }
> > +
> > + test8_exit_ok = *cookie == 0x1111222233334444ull;
> > + return 0;
> > +}
> > +
> > +__u64 test9_entry_result = 0;
> > +__u64 test9_exit_result = 0;
> > +
> > +SEC("fsession/bpf_fentry_test1")
> > +int BPF_PROG(test9, int a, int ret)
> > +{
> > + __u64 *cookie = bpf_session_cookie(ctx);
> > +
> > + if (!bpf_session_is_return(ctx)) {
> > + test9_entry_result = a == 1 && ret == 0;
> > + *cookie = 0x123456ULL;
> > + return 0;
> > + }
> > +
> > + test9_exit_result = a == 1 && ret == 2 && *cookie == 0x123456ULL;
> > + return 0;
> > +}
> > --
> > 2.52.0
> >
>
next prev parent reply other threads:[~2026-01-22 2:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 11:22 [PATCH bpf-next v10 00/12] bpf: fsession support Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 01/12] bpf: add " Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 02/12] bpf: use the least significant byte for the nr_args in trampoline Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 03/12] bpf: change prototype of bpf_session_{cookie,is_return} Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 04/12] bpf: support fsession for bpf_session_is_return Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 05/12] bpf: support fsession for bpf_session_cookie Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 06/12] bpf,x86: introduce emit_store_stack_imm64() for trampoline Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 07/12] bpf,x86: add fsession support for x86_64 Menglong Dong
2026-01-22 0:06 ` Andrii Nakryiko
2026-01-22 0:22 ` Andrii Nakryiko
2026-01-22 2:41 ` Menglong Dong
2026-01-22 16:57 ` Andrii Nakryiko
2026-01-15 11:22 ` [PATCH bpf-next v10 08/12] libbpf: add fsession support Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 09/12] bpftool: " Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 10/12] selftests/bpf: add testcases for fsession Menglong Dong
2026-01-15 11:22 ` [PATCH bpf-next v10 11/12] selftests/bpf: add testcases for fsession cookie Menglong Dong
2026-01-22 0:07 ` Andrii Nakryiko
2026-01-22 2:18 ` Menglong Dong [this message]
2026-01-15 11:22 ` [PATCH bpf-next v10 12/12] selftests/bpf: test fsession mixed with fentry and fexit Menglong Dong
2026-01-22 0:09 ` [PATCH bpf-next v10 00/12] bpf: fsession support Andrii Nakryiko
2026-01-22 2:49 ` Menglong Dong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2814828.mvXUDI8C0e@7940hx \
--to=menglong.dong@linux.dev \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=hpa@zytor.com \
--cc=jiang.biao@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=menglong8.dong@gmail.com \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox