Subject: Re: [PATCH bpf-next v3 16/17] bpf: Realign skb metadata for TC progs using data_meta

From: Jakub Sitnicki <[email-masked]>
Date: Thu, 08 Jan 2026 20:54:54 +0100

On Wed, Jan 07, 2026 at 02:01 PM -08, Alexei Starovoitov wrote:
> On Wed, Jan 7, 2026 at 6:28 AM Jakub Sitnicki <[email-masked]> wrote:
>>
>>
>> +static void bpf_skb_meta_realign(struct sk_buff *skb)
>> +{
>> +       u8 *meta_end = skb_metadata_end(skb);
>> +       u8 meta_len = skb_metadata_len(skb);
>> +       u8 *meta;
>> +       int gap;
>> +
>> +       gap = skb_mac_header(skb) - meta_end;
>> +       if (!meta_len || !gap)
>> +               return;
>> +
>> +       if (WARN_ONCE(gap < 0, "skb metadata end past mac header")) {
>> +               skb_metadata_clear(skb);
>> +               return;
>> +       }
>> +
>> +       meta = meta_end - meta_len;
>> +       memmove(meta + gap, meta, meta_len);
>> +       skb_shinfo(skb)->meta_end += gap;
>> +
>> +       bpf_compute_data_pointers(skb);
>> +}
>> +
>>  static int tc_cls_act_prologue(struct bpf_insn *insn_buf, u32 pkt_access_flags,
>>                                const struct bpf_prog *prog)
>>  {
>> -       return bpf_unclone_prologue(insn_buf, pkt_access_flags, prog,
>> -                                   TC_ACT_SHOT);
>> +       struct bpf_insn *insn = insn_buf;
>> +       int cnt;
>> +
>> +       if (pkt_access_flags & PA_F_DATA_META_LOAD) {
>> +               /* Realign skb metadata for access through data_meta pointer.
>> +                *
>> +                * r6 = r1; // r6 will be "u64 *ctx"
>> +                * r0 = bpf_skb_meta_realign(r1); // r0 is undefined
>> +                * r1 = r6;
>> +                */
>> +               BUILD_BUG_ON(!__same_type(&bpf_skb_meta_realign,
>> +                                         (void (*)(struct sk_buff *))NULL));
>> +               *insn++ = BPF_MOV64_REG(BPF_REG_6, BPF_REG_1);
>> +               *insn++ = BPF_EMIT_CALL(bpf_skb_meta_realign);
>
> Not quite. drop this BUILD_BUG_ON(), since it's pointless and misleading.

Will do.

> bpf_skb_meta_realign() has to be the one done with BPF_CALL_1(...).
> Otherwise above will work only on x86.
> In this case on arm64 too, but it's by accident.
> BPF_CALL* has to do ABI conversion from BPF to native.
>
> For kfuncs that's what JITs do via btf_func_model machinery.

Oh, 32-bit ARM has different register mapping. TIL. Thanks.