From: Jakub Sitnicki <jakub@cloudflare.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Amery Hung <ameryhung@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Martin KaFai Lau <martin.lau@kernel.org>,
bpf <bpf@vger.kernel.org>,
Network Development <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Simon Horman <horms@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
kernel-team <kernel-team@cloudflare.com>
Subject: Re: [PATCH bpf-next v2 15/16] bpf: Realign skb metadata for TC progs using data_meta
Date: Tue, 06 Jan 2026 18:36:17 +0100 [thread overview]
Message-ID: <877btu8wz2.fsf@cloudflare.com> (raw)
In-Reply-To: <CAADnVQJ=kmVAZsgkG9P2nEBTUG3E4PrDG=Yz8tfeFysH4ZBqVw@mail.gmail.com> (Alexei Starovoitov's message of "Mon, 5 Jan 2026 18:04:28 -0800")
On Mon, Jan 05, 2026 at 06:04 PM -08, Alexei Starovoitov wrote:
> On Mon, Jan 5, 2026 at 3:19 PM Amery Hung <ameryhung@gmail.com> wrote:
>>
>> >
>> > >
>> > > I guess we can mark such emitted call in insn_aux_data as finalized
>> > > and get_func_proto() isn't needed.
>> >
>> > It is a good idea.
>> >
>>
>> Hmm, insn_aux_data has to be marked in gen_{pro,epi}logue since this
>> is the only place we know whether the call needs fixup or not. However
>> insn_aux_data is not available yet in gen_{pro,epi}logue because we
>> haven't resized insn_aux_data.
>>
>> Can we do some hack based on the fact that calls emitted by
>> BPF_EMIT_CALL() are finalized while calls emitted by BPF_RAW_INSN()
>> most likely are not?
>> Let BPF_EMIT_CALL() mark the call insn as finalized temporarily (e.g.,
>> .off = 1). Then, when do_misc_fixups() encounters it just reset off to
>> 0 and don't call get_func_proto().
>
> marking inside insn via off=1 or whatever is an option,
> but once we remove BPF_CALL_KFUNC from gen_prologue we can
> delete add_kfunc_in_insns() altogether and replace it with
> a similar loop that does
> if (bpf_helper_call()) mark insn_aux_data.
>
> That would be a nice benefit, since add_kfunc_call() from there
> was always a bit odd, since we're adding kfuncs early before the main
> verifier pass and after, because of gen_prologue.
Thanks for all the pointers.
I understood we're looking for something like this:
---8<---
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index b32ddf0f0ab3..9ccd56c04a45 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -561,6 +561,7 @@ struct bpf_insn_aux_data {
bool non_sleepable; /* helper/kfunc may be called from non-sleepable context */
bool is_iter_next; /* bpf_iter_<type>_next() kfunc call */
bool call_with_percpu_alloc_ptr; /* {this,per}_cpu_ptr() with prog percpu alloc */
+ bool finalized_call; /* call holds function offset relative to __bpf_base_call */
u8 alu_state; /* used in combination with alu_limit */
/* true if STX or LDX instruction is a part of a spill/fill
* pattern for a bpf_fastcall call.
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1ca5c5e895ee..cc737d103cdd 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -21806,6 +21806,14 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
env->prog = new_prog;
delta += cnt - 1;
+ /* gen_prologue emits function calls with target address
+ * relative to __bpf_call_base. Skip patch_call_imm fixup.
+ */
+ for (i = 0; i < cnt - 1; i++) {
+ if (bpf_helper_call(&env->prog->insnsi[i]))
+ env->insn_aux_data[i].finalized_call = true;
+ }
+
ret = add_kfunc_in_insns(env, insn_buf, cnt - 1);
if (ret < 0)
return ret;
@@ -23412,6 +23420,9 @@ static int do_misc_fixups(struct bpf_verifier_env *env)
goto next_insn;
}
patch_call_imm:
+ if (env->insn_aux_data[i + delta].finalized_call)
+ goto next_insn;
+
fn = env->ops->get_func_proto(insn->imm, env->prog);
/* all functions that have prototype and verifier allowed
* programs to call them, must be real in-kernel functions
@@ -23423,6 +23434,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env)
return -EFAULT;
}
insn->imm = fn->func - __bpf_call_base;
+ env->insn_aux_data[i + delta].finalized_call = true;
next_insn:
if (subprogs[cur_subprog + 1].start == i + delta + 1) {
subprogs[cur_subprog].stack_depth += stack_depth_extra;
diff --git a/net/core/filter.c b/net/core/filter.c
index 7f5bc6a505e1..53993c2c492d 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -9082,8 +9082,7 @@ static int bpf_unclone_prologue(struct bpf_insn *insn_buf, u32 pkt_access_flags,
/* ret = bpf_skb_pull_data(skb, 0); */
*insn++ = BPF_MOV64_REG(BPF_REG_6, BPF_REG_1);
*insn++ = BPF_ALU64_REG(BPF_XOR, BPF_REG_2, BPF_REG_2);
- *insn++ = BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
- BPF_FUNC_skb_pull_data);
+ *insn++ = BPF_EMIT_CALL(bpf_skb_pull_data);
/* if (!ret)
* goto restore;
* return TC_ACT_SHOT;
@@ -9135,11 +9134,8 @@ static int bpf_gen_ld_abs(const struct bpf_insn *orig,
return insn - insn_buf;
}
-__bpf_kfunc_start_defs();
-
-__bpf_kfunc void bpf_skb_meta_realign(struct __sk_buff *skb_)
+static void bpf_skb_meta_realign(struct sk_buff *skb)
{
- struct sk_buff *skb = (typeof(skb))skb_;
u8 *meta_end = skb_metadata_end(skb);
u8 meta_len = skb_metadata_len(skb);
u8 *meta;
@@ -9161,14 +9157,6 @@ __bpf_kfunc void bpf_skb_meta_realign(struct __sk_buff *skb_)
bpf_compute_data_pointers(skb);
}
-__bpf_kfunc_end_defs();
-
-BTF_KFUNCS_START(tc_cls_act_hidden_ids)
-BTF_ID_FLAGS(func, bpf_skb_meta_realign)
-BTF_KFUNCS_END(tc_cls_act_hidden_ids)
-
-BTF_ID_LIST_SINGLE(bpf_skb_meta_realign_ids, func, bpf_skb_meta_realign)
-
static int tc_cls_act_prologue(struct bpf_insn *insn_buf, u32 pkt_access_flags,
const struct bpf_prog *prog)
{
@@ -9182,8 +9170,10 @@ static int tc_cls_act_prologue(struct bpf_insn *insn_buf, u32 pkt_access_flags,
* r0 = bpf_skb_meta_realign(r1); // r0 is undefined
* r1 = r6;
*/
+ BUILD_BUG_ON(!__same_type(&bpf_skb_meta_realign,
+ (void (*)(struct sk_buff *skb))NULL));
*insn++ = BPF_MOV64_REG(BPF_REG_6, BPF_REG_1);
- *insn++ = BPF_CALL_KFUNC(0, bpf_skb_meta_realign_ids[0]);
+ *insn++ = BPF_EMIT_CALL(bpf_skb_meta_realign);
*insn++ = BPF_MOV64_REG(BPF_REG_1, BPF_REG_6);
}
cnt = bpf_unclone_prologue(insn, pkt_access_flags, prog, TC_ACT_SHOT);
next prev parent reply other threads:[~2026-01-06 17:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-05 12:14 [PATCH bpf-next v2 00/16] Decouple skb metadata tracking from MAC header offset Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 01/16] bnxt_en: Call skb_metadata_set when skb->data points at metadata end Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 02/16] i40e: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 03/16] igb: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 04/16] igc: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 05/16] ixgbe: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 06/16] net/mlx5e: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 07/16] veth: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 08/16] xsk: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 09/16] xdp: " Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 10/16] net: Track skb metadata end separately from MAC offset Jakub Sitnicki
2026-01-05 12:14 ` [PATCH bpf-next v2 11/16] bpf, verifier: Remove side effects from may_access_direct_pkt_data Jakub Sitnicki
2026-01-05 18:23 ` Eduard Zingerman
2026-01-05 12:14 ` [PATCH bpf-next v2 12/16] bpf, verifier: Turn seen_direct_write flag into a bitmap Jakub Sitnicki
2026-01-05 18:48 ` Eduard Zingerman
2026-01-05 12:14 ` [PATCH bpf-next v2 13/16] bpf, verifier: Propagate packet access flags to gen_prologue Jakub Sitnicki
2026-01-05 18:49 ` Eduard Zingerman
2026-01-05 12:14 ` [PATCH bpf-next v2 14/16] bpf, verifier: Track when data_meta pointer is loaded Jakub Sitnicki
2026-01-05 18:48 ` Eduard Zingerman
2026-01-05 12:14 ` [PATCH bpf-next v2 15/16] bpf: Realign skb metadata for TC progs using data_meta Jakub Sitnicki
2026-01-05 19:14 ` Alexei Starovoitov
2026-01-05 19:20 ` Jakub Sitnicki
2026-01-05 19:42 ` Amery Hung
2026-01-05 20:02 ` Alexei Starovoitov
2026-01-05 20:54 ` Martin KaFai Lau
2026-01-05 21:47 ` Alexei Starovoitov
2026-01-05 22:25 ` Martin KaFai Lau
2026-01-05 23:19 ` Amery Hung
2026-01-06 2:04 ` Alexei Starovoitov
2026-01-06 17:36 ` Jakub Sitnicki [this message]
2026-01-06 17:46 ` Amery Hung
2026-01-06 18:40 ` Alexei Starovoitov
2026-01-06 19:12 ` Jakub Sitnicki
2026-01-06 19:42 ` Amery Hung
2026-01-05 12:14 ` [PATCH bpf-next v2 16/16] selftests/bpf: Test skb metadata access after L2 decapsulation Jakub Sitnicki
2026-01-10 21:07 ` [PATCH bpf-next v2 00/16] Decouple skb metadata tracking from MAC header offset Jakub Sitnicki
2026-01-14 11:52 ` Jakub Sitnicki
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=877btu8wz2.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=song@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