Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: ipv6: optimize ipv6_addr_copy() #30029

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

julianwiedmann
Copy link
Member

@julianwiedmann julianwiedmann commented Dec 21, 2023

Refresh the optimization from #24341, it's a nice gain for IPv6 already.

@julianwiedmann julianwiedmann added sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/misc This PR makes changes that have no direct user impact. kind/complexity-issue Relates to BPF complexity or program size issues feature/ipv6 Relates to IPv6 protocol support labels Dec 21, 2023
@julianwiedmann
Copy link
Member Author

/ci-verifier

@julianwiedmann julianwiedmann force-pushed the 1.16-bpf-ipv6-addr-copy branch 2 times, most recently from a2fbd16 to 616dafe Compare December 21, 2023 13:58
@julianwiedmann
Copy link
Member Author

/ci-verifier

@julianwiedmann julianwiedmann force-pushed the 1.16-bpf-ipv6-addr-copy branch 2 times, most recently from 4ff0d33 to a240e26 Compare December 21, 2023 14:35
@julianwiedmann
Copy link
Member Author

/ci-verifier

@julianwiedmann julianwiedmann force-pushed the 1.16-bpf-ipv6-addr-copy branch from a240e26 to cc1931c Compare December 21, 2023 14:50
@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann julianwiedmann marked this pull request as ready for review December 21, 2023 16:07
@julianwiedmann julianwiedmann requested a review from a team as a code owner December 21, 2023 16:07
borkmann and others added 2 commits January 8, 2024 13:46
Seen in verifier log where byte-by-byte copy happens:

        [...]
        ; if (nat_46x64) {
        404: (16) if w5 == 0x1 goto pc+2437   ; R5=scalar(umax=4294967295,var_off=(0x0; 0xffffffff))
        ; dst->d1 = src->d1;
        405: (71) r2 = *(u8 *)(r1 +8)         ; R1_w=pkt(off=0,r=40,imm=0) R2_w=scalar(umax=255,var_off=(0x0; 0xff))
        406: (71) r3 = *(u8 *)(r1 +9)         ; R1_w=pkt(off=0,r=40,imm=0) R3_w=scalar(umax=255,var_off=(0x0; 0xff))
        407: (67) r3 <<= 8                    ; R3_w=scalar(umax=65280,var_off=(0x0; 0xff00))
        408: (4f) r3 |= r2                    ; R2_w=scalar(umax=255,var_off=(0x0; 0xff)) R3_w=scalar()
        409: (71) r4 = *(u8 *)(r1 +10)        ; R1_w=pkt(off=0,r=40,imm=0) R4_w=scalar(umax=255,var_off=(0x0; 0xff))
        410: (71) r2 = *(u8 *)(r1 +11)        ; R1_w=pkt(off=0,r=40,imm=0) R2_w=scalar(umax=255,var_off=(0x0; 0xff))
        411: (67) r2 <<= 8                    ; R2_w=scalar(umax=65280,var_off=(0x0; 0xff00))
        412: (4f) r2 |= r4                    ; R2_w=scalar() R4_w=scalar(umax=255,var_off=(0x0; 0xff))
        413: (67) r2 <<= 16                   ; R2_w=scalar(smax=9223372036854710272,umax=18446744073709486080,var_off=(0x0; 0xffffffffffff0000),s32_max=2147418112,u32_max=-65536)
        414: (4f) r2 |= r3                    ; R2_w=scalar() R3_w=scalar()
        415: (71) r3 = *(u8 *)(r1 +13)        ; R1_w=pkt(off=0,r=40,imm=0) R3_w=scalar(umax=255,var_off=(0x0; 0xff))
        416: (64) w3 <<= 8                    ; R3_w=scalar(umax=65280,var_off=(0x0; 0xff00))
        417: (71) r4 = *(u8 *)(r1 +12)        ; R1_w=pkt(off=0,r=40,imm=0) R4_w=scalar(umax=255,var_off=(0x0; 0xff))
        418: (4c) w3 |= w4                    ; R3_w=scalar() R4_w=scalar(umax=255,var_off=(0x0; 0xff))
        419: (71) r4 = *(u8 *)(r1 +15)        ; R1_w=pkt(off=0,r=40,imm=0) R4_w=scalar(umax=255,var_off=(0x0; 0xff))
        420: (64) w4 <<= 8                    ; R4_w=scalar(umax=65280,var_off=(0x0; 0xff00))
        421: (71) r5 = *(u8 *)(r1 +14)        ; R1_w=pkt(off=0,r=40,imm=0) R5_w=scalar(umax=255,var_off=(0x0; 0xff))
        422: (4c) w4 |= w5                    ; R4_w=scalar() R5_w=scalar(umax=255,var_off=(0x0; 0xff))
        423: (64) w4 <<= 16                   ; R4_w=scalar(umax=4294901760,var_off=(0x0; 0xffff0000),s32_max=2147418112)
        424: (4c) w4 |= w3                    ; R3_w=scalar() R4_w=scalar()
        425: (67) r4 <<= 32                   ; R4_w=scalar(smax=9223372032559808512,umax=18446744069414584320,var_off=(0x0; 0xffffffff00000000),s32_min=0,s32_max=0,u32_max=0)
        426: (4f) r4 |= r2                    ; R2_w=scalar() R4_w=scalar()
        ; dst->d1 = src->d1;
        427: (7b) *(u64 *)(r10 -264) = r4     ; R4_w=scalar() R10=fp0 fp-264_w=mmmmmmmm
        ; dst->d2 = src->d2;
        [...]

Signed-off-by: Daniel Borkmann <[email protected]>
[jwi: add ipv6_addr_copy_unaligned() to tolerate some unaligned access]
Signed-off-by: Julian Wiedmann <[email protected]>
Clean up some open-coded copy operations, so that they benefit from the
optimizations in ipv6_addr_copy().

Signed-off-by: Julian Wiedmann <[email protected]>
@julianwiedmann julianwiedmann force-pushed the 1.16-bpf-ipv6-addr-copy branch from cc1931c to 9b81dd9 Compare January 8, 2024 11:46
@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann
Copy link
Member Author

(fresh rebase to pick up the latest complexity test improvements)

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jan 11, 2024
@julianwiedmann julianwiedmann added this pull request to the merge queue Jan 11, 2024
Merged via the queue into cilium:main with commit 1d04719 Jan 11, 2024
62 checks passed
@julianwiedmann julianwiedmann deleted the 1.16-bpf-ipv6-addr-copy branch January 11, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/ipv6 Relates to IPv6 protocol support kind/complexity-issue Relates to BPF complexity or program size issues ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants