From: Yonghong Song <yonghong.song@linux.dev>
To: "YiFei Zhu" <zhuyifei@google.com>, bpf <bpf@vger.kernel.org>,
"Ömer Sinan Ağacan" <omeragacan@gmail.com>,
yonghong-song <yhs@fb.com>
Subject: Re: LLVM regression in memcpy struct bpf_sock_ops->remote_ip6 to struct in6_addr
Date: Tue, 18 Aug 2026 23:01:56 -0700 [thread overview]
Message-ID: <4f6c72f7-9d21-4240-849d-08e10b0b2055@linux.dev> (raw)
In-Reply-To: <CAA-VZPmzCKF5uhP0OG4mPwEs8WaL-xyjAYW=bE8z7Z_J4-h6cw@mail.gmail.com>
On 7/21/26 4:56 PM, YiFei Zhu wrote:
> In one of our BPF progs, there is a pattern of copying IPv6 addresses
> (which are four u32s) off of struct bpf_sock_ops into a stack variable
> (a larger struct that contains struct in6_addr), then updating a map
> with that stack variable. After a recent LLVM upgrade, that program no
> longer loads.
>
> I wrote a reproducer:
>
> #include <string.h>
> #include <linux/in6.h>
> #include <linux/bpf.h>
> #include <bpf/bpf_helpers.h>
>
> struct in6_addr addr6;
>
> SEC("sockops")
> int test(struct bpf_sock_ops *skops)
> {
> struct in6_addr stack_addr6;
>
> memcpy(&stack_addr6, skops->remote_ip6, sizeof(skops->remote_ip6));
> addr6 = stack_addr6;
> return 0;
> }
>
> This will fail loading at latest LLVM main with error:
>
> -- BEGIN PROG LOAD LOG --
> 0: R1=ctx() R10=fp0
> 0: (7b) *(u64 *)(r10 -8) = r1 ; R1=ctx() R10=fp0 fp-8=ctx()
> 1: (79) r1 = *(u64 *)(r10 -8) ; R1=ctx() R10=fp0 fp-8=ctx()
> 2: (79) r2 = *(u64 *)(r1 +40)
> invalid bpf_context access off=40 size=8
> processed 3 insns (limit 1000000) max_states_per_insn 0 total_states
> 0 peak_states 0 mark_read 0
> -- END PROG LOAD LOG --
Are you using -O0 compile flag? The above code is not optimal.
I tried with llvm23/-O2, cpu v3, and get the following code:
0: w2 = *(u32 *)(r1 + 0x2c)
1: r3 = 0x0 ll
0000000000000008: R_BPF_64_64 addr6
3: *(u32 *)(r3 + 0xc) = w2
4: w2 = *(u32 *)(r1 + 0x28)
5: *(u32 *)(r3 + 0x8) = w2
6: w2 = *(u32 *)(r1 + 0x24)
7: *(u32 *)(r3 + 0x4) = w2
8: w1 = *(u32 *)(r1 + 0x20)
9: *(u32 *)(r3 + 0x0) = w1
10: w0 = 0x0
11: exit
>
> It seems that the program is reading the address from the bpf_sock_ops
> as two u64s instead of four u32s, and the verifier understandably does
> not allow that due to the complexity of rewriting context accesses. I
> bisected the regression to
>
> commit 790f0623411d5d9d5c989f14e87f2fe86f52eaf3
> Author: Ömer Sinan Ağacan <omeragacan@gmail.com>
> Date: Tue Jun 9 16:03:26 2026
>
> [SelectionDAG] Pass dest and src alignments separately to memcpy
> and memmove lowering functions (#201119)
>
> Looking at its PR [1], it seems that commit caused another regression
> for BPF selftests and that has been fixed, but this regression is
> still reproducible on main with that fix applied.
>
> I'm not really familiar enough with LLVM internals to understand
> exactly why it generates the code this way or how to fix the
> regression.
>
> YiFei Zhu
>
> [1] https://github.com/llvm/llvm-project/pull/201119
>
prev parent reply other threads:[~2026-08-19 6:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 23:56 LLVM regression in memcpy struct bpf_sock_ops->remote_ip6 to struct in6_addr YiFei Zhu
2026-08-19 6:01 ` Yonghong Song [this message]
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=4f6c72f7-9d21-4240-849d-08e10b0b2055@linux.dev \
--to=yonghong.song@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=omeragacan@gmail.com \
--cc=yhs@fb.com \
--cc=zhuyifei@google.com \
/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.