From: Menglong Dong <menglong.dong@linux.dev>
To: menglong8.dong@gmail.com, ast@kernel.org, andrii@kernel.org,
bot+bpf-ci@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,
ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org, eddyz87@gmail.com,
yonghong.song@linux.dev, clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v9 05/11] bpf: support fsession for bpf_session_cookie
Date: Sun, 11 Jan 2026 09:54:57 +0800 [thread overview]
Message-ID: <5959432.DvuYhMxLoT@7950hx> (raw)
In-Reply-To: <75ddb4013c7de3c454d564f3052afc81a0906226a17d75aa4301f750e3ef7723@mail.kernel.org>
On 2026/1/10 22:42, bot+bpf-ci@kernel.org wrote:
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index 2640ec2157e1..a416050e0dd2 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -1231,6 +1231,7 @@ enum {
> >
> > #define BPF_TRAMP_M_NR_ARGS 0
> > #define BPF_TRAMP_M_IS_RETURN 8
> > +#define BPF_TRAMP_M_COOKIE 9
>
> [ ... ]
>
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 1b0292a03186..b91fd8af2393 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
>
> [ ... ]
>
> > @@ -22571,6 +22575,22 @@ static int fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> > insn_buf[1] = BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, BPF_TRAMP_M_IS_RETURN);
> > insn_buf[2] = BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1);
> > *cnt = 3;
> > + } else if (desc->func_id == special_kfunc_list[KF_bpf_session_cookie] &&
> > + env->prog->expected_attach_type == BPF_TRACE_FSESSION) {
> > + /* inline bpf_session_cookie() for fsession:
> > + * __u64 *bpf_session_cookie(void *ctx)
> > + * {
> > + * u64 off = (((u64 *)ctx)[-1] >> BPF_TRAMP_M_COOKIE) & 0xFF;
> > + * return &((u64 *)ctx)[-off];
> > + * }
> > + */
> > + insn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8);
> > + insn_buf[1] = BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, BPF_TRAMP_M_COOKIE);
> > + insn_buf[2] = BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xFF);
> > + insn_buf[3] = BPF_ALU64_IMM(BPF_LSH, BPF_REG_0, 3);
> > + insn_buf[4] = BPF_ALU64_REG(BPF_SUB, BPF_REG_0, BPF_REG_1);
> > + insn_buf[5] = BPF_ALU64_IMM(BPF_NEG, BPF_REG_0, 0);
> ^^^^^^^^
>
> This inline code reads the cookie offset from (ctx[-1] >> 9) & 0xFF, but
> does the x86 trampoline actually store the cookie offset at bit position 9?
>
> Looking at arch/x86/net/bpf_jit_comp.c in __arch_prepare_bpf_trampoline(),
> the trampoline stores nr_regs to the nregs_off location:
>
> emit_mov_imm64(&prog, BPF_REG_0, 0, (u32) nr_regs);
> emit_stx(&prog, BPF_DW, BPF_REG_FP, BPF_REG_0, -nregs_off);
>
> This sets ctx[-1] to a small value like 0x0000000000000006, with the high
> bits all zero. When the inline code executes:
>
> off = (ctx[-1] >> 9) & 0xFF --> off = 0
>
> The function then returns &ctx[-0] = ctx itself, which points to the
> function arguments instead of the session cookie.
>
> Is there a missing dependency on a later commit in the series? Commit
> 983968c39241 ("bpf,x86: add fsession support for x86_64") appears to add
> the trampoline code that stores the cookie offset, but it comes after this
> commit in the patch series.
This is intentionally. The whole feature is partly architecture specific.
In this patch, we implement the common part, and in the
983968c39241 ("bpf,x86: add fsession support for x86_64"), we
implement the feature for x86_64.
If the current architecture doesn't implement this feature, the
fsession will not be usable, so this inline code will not be called,
which make sense.
Thanks!
Menglong Dong
>
> > + *cnt = 6;
> > + }
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/20879693280
>
next prev parent reply other threads:[~2026-01-11 1:55 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-10 14:11 [PATCH bpf-next v9 00/11] bpf: fsession support Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 01/11] bpf: add " Menglong Dong
2026-01-14 1:22 ` Andrii Nakryiko
2026-01-14 2:10 ` Menglong Dong
2026-01-14 18:56 ` Andrii Nakryiko
2026-01-15 2:05 ` Menglong Dong
2026-01-15 8:33 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 02/11] bpf: use last 8-bits for the nr_args in trampoline Menglong Dong
2026-01-14 1:22 ` Andrii Nakryiko
2026-01-14 2:19 ` Menglong Dong
2026-01-14 9:52 ` David Laight
2026-01-10 14:11 ` [PATCH bpf-next v9 03/11] bpf: change prototype of bpf_session_{cookie,is_return} Menglong Dong
2026-01-14 1:22 ` Andrii Nakryiko
2026-01-14 2:19 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 04/11] bpf: support fsession for bpf_session_is_return Menglong Dong
2026-01-14 1:22 ` Andrii Nakryiko
2026-01-14 2:25 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 05/11] bpf: support fsession for bpf_session_cookie Menglong Dong
2026-01-10 14:42 ` bot+bpf-ci
2026-01-11 1:54 ` Menglong Dong [this message]
2026-01-14 1:22 ` Andrii Nakryiko
2026-01-14 2:33 ` Alexei Starovoitov
2026-01-14 2:38 ` Menglong Dong
2026-01-14 2:48 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 06/11] bpf,x86: introduce emit_store_stack_imm64() for trampoline Menglong Dong
2026-01-14 1:22 ` Andrii Nakryiko
2026-01-14 2:31 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 07/11] bpf,x86: add fsession support for x86_64 Menglong Dong
2026-01-14 1:25 ` Andrii Nakryiko
2026-01-14 3:27 ` Menglong Dong
2026-01-14 3:35 ` Menglong Dong
2026-01-14 19:05 ` Andrii Nakryiko
2026-01-15 2:12 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 08/11] libbpf: add fsession support Menglong Dong
2026-01-14 1:24 ` Andrii Nakryiko
2026-01-14 3:27 ` Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 09/11] selftests/bpf: add testcases for fsession Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 10/11] selftests/bpf: add testcases for fsession cookie Menglong Dong
2026-01-10 14:11 ` [PATCH bpf-next v9 11/11] selftests/bpf: test fsession mixed with fentry and fexit Menglong Dong
2026-01-14 2:28 ` [PATCH bpf-next v9 00/11] bpf: fsession support Alexei Starovoitov
2026-01-14 2:52 ` 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=5959432.DvuYhMxLoT@7950hx \
--to=menglong.dong@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--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=ihor.solodrai@linux.dev \
--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@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.