Skip to contentSkip to conversation

Help testing llvm patch to generate verifier friendly code

DISCUSSION Yonghong Song 3 participants 4 messages Sep 23, 2020 BPF

lore
Share & tools
lore
#0 lore raw

Hi,

I have spent some time to add additional logic in llvm BPF backend in order to generate verifier friendly code.

The first patch is:
https://reviews.llvm.org/D87153
which moves CORE relocation builtin handling from in late IR optimization (after inlining and major optimizations)
to in early IR optimization (before inlining and any optimizations). The reason is to prevent harmful CSEs.

But this change may change how compiler do optimizations. The patch can pass bpf selftests in latest bpf-next. Andrii helped it can also pass bcc/libbpf-tools.

If your code uses COREs, esp. having a lot of subroutines and/or loops, it would be good to give a try with new patch to see whether there are any issues or not. In my case, for one of our internal applications with lots of subroutines and loops, inlining all subroutines and unrolling all loops will cause register spills which cannot be handled by the verifier, while existing llvm won't have issue.

FYI, I have two more patches (still need tuning) in pipeline:
https://reviews.llvm.org/D85570 to serialize code across control flows
https://reviews.llvm.org/D87428 to avoid repeated condition evaluation

Thanks,

Yonghong

#1 lore raw
Quoted 17 lines · Yonghong Song

Hi,

I have spent some time to add additional logic in llvm BPF backend in order to generate verifier friendly code.

The first patch is:

   https://reviews.llvm.org/D87153

which moves CORE relocation builtin handling from in late IR optimization (after inlining and major optimizations)
to in early IR optimization (before inlining and any optimizations). The reason is to prevent harmful CSEs.

But this change may change how compiler do optimizations. The patch can pass bpf selftests in latest bpf-next. Andrii helped it can also pass bcc/libbpf-tools.

Quoted 7 lines

If your code uses COREs, esp. having a lot of subroutines and/or loops, it would be good to give a try with new patch to see whether there are any issues or not. In my case, for one of our internal applications with lots of subroutines and loops, inlining all subroutines and unrolling all loops will cause register spills which cannot be handled by the verifier, while existing llvm won't have issue.

Hi Yonghong,

We currently don't use CORE (outside of bcc, etc.), so there isn't much I can test I guess? Please let me know if there is something I can do for your follow up patches.

Best
Lorenz

Signature · 4 lines
Lorenz Bauer  |  Systems Engineer
6th Floor, County Hall/The Riverside Building, SE1 7PB, UK

www.cloudflare.com
#2 lore raw
Quoted 27 lines · Lorenz Bauer
Quoted 17 lines · Yonghong Song

Hi,

I have spent some time to add additional logic in llvm BPF backend in order to generate verifier friendly code.

The first patch is:

   https://reviews.llvm.org/D87153

which moves CORE relocation builtin handling from in late IR optimization (after inlining and major optimizations)
to in early IR optimization (before inlining and any optimizations). The reason is to prevent harmful CSEs.

But this change may change how compiler do optimizations. The patch can pass bpf selftests in latest bpf-next. Andrii helped it can also pass bcc/libbpf-tools.

Quoted 7 lines

If your code uses COREs, esp. having a lot of subroutines and/or loops, it would be good to give a try with new patch to see whether there are any issues or not. In my case, for one of our internal applications with lots of subroutines and loops, inlining all subroutines and unrolling all loops will cause register spills which cannot be handled by the verifier, while existing llvm won't have issue.

Quoted 6 lines

Hi Yonghong,

We currently don't use CORE (outside of bcc, etc.), so there isn't much I can test I guess? Please let me know if there is something I can do for your follow up patches.

It would still be good if you could test all three Clang/LLVM patches Yonghong referenced. The latter two are not CO-RE-specific. Thanks!

And pedantic nit: BCC doesn't use CO-RE, it just does runtime compilation using local kernel headers with exact memory layout of kernel structs.

Quoted 8 lines

Best
Lorenz

--
Lorenz Bauer | Systems Engineer
6th Floor, County Hall/The Riverside Building, SE1 7PB, UK

www.cloudflare.com

#3 lore raw
Quoted 30 lines · Andrii Nakryiko
Quoted 29 lines · Lorenz Bauer
Quoted 17 lines · Yonghong Song

Hi,

I have spent some time to add additional logic in llvm BPF backend in order to generate verifier friendly code.

The first patch is:

    https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D87153&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=-_pOOUYXONnvN0eDqgPfyjzi3pU0ZJV-eT7LViel2u0&s=1lUhNqSXg_nXYENMizJLX-GtAxNqKETBdD50CC4wB-U&e=

which moves CORE relocation builtin handling from in late IR optimization (after inlining and major optimizations)
to in early IR optimization (before inlining and any optimizations). The reason is to prevent harmful CSEs.

But this change may change how compiler do optimizations. The patch can pass bpf selftests in latest bpf-next. Andrii helped it can also pass bcc/libbpf-tools.

Quoted 7 lines

If your code uses COREs, esp. having a lot of subroutines and/or loops, it would be good to give a try with new patch to see whether there are any issues or not. In my case, for one of our internal applications with lots of subroutines and loops, inlining all subroutines and unrolling all loops will cause register spills which cannot be handled by the verifier, while existing llvm won't have issue.

Hi Yonghong,

Quoted 7 lines
Quoted 4 lines

We currently don't use CORE (outside of bcc, etc.), so there isn't much I can test I guess? Please let me know if there is something I can do for your follow up patches.

It would still be good if you could test all three Clang/LLVM patches Yonghong referenced. The latter two are not CO-RE-specific. Thanks!

Right, the first patch (I described here) in 3-patch series

    Patch 1: https://reviews.llvm.org/D87153

is related to CORE and will be a noop for program without CORE.

The second and the third patches:

    Patch 2: https://reviews.llvm.org/D85570
    Patch 3: https://reviews.llvm.org/D87428

is not related to CORE and intends to solve some verifier failures related to value range. Please see commit message for the above two patches.

Agree that it would be still be good to test all of them, esp, if you have asm/source workaround, it will be curious to see how many those can be removed.

Thanks!

Quoted 13 lines

And pedantic nit: BCC doesn't use CO-RE, it just does runtime compilation using local kernel headers with exact memory layout of kernel structs.

Quoted 8 lines

Best
Lorenz

--
Lorenz Bauer | Systems Engineer
6th Floor, County Hall/The Riverside Building, SE1 7PB, UK

https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cloudflare.com&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=-_pOOUYXONnvN0eDqgPfyjzi3pU0ZJV-eT7LViel2u0&s=5gNN1mRte8LrjgHn6sz7v6goGzL2lWt4-EaghCAagq0&e=