Skip to content

Conversation

@brianwitte
Copy link
Contributor

Hey, Alan.

Thanks for all the work on bpftune (and your informative talks on BTF 😄 ).

I wanted to begin the process of porting bpftune to support the BPF backend for gcc.

I started with the Makefile(s).

On my fork, you can:

GCC_BPF=bpf-gcc make && sudo make install

It compiles successfully (and throws warnings due to ignoring unkown clang #pragmas).

Then you can run bpftune in legacy mode:

$ sudo bpftune -S     
bpftune: bpftune works in legacy mode
bpftune: bpftune supports per-netns policy (via netns cookie)

Below are the specifications for the machine I am testing on.
I use upstream Debian for my work as much as possible:

$ bpf-gcc --version 
bpf-gcc (14.1.0-1+2) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ bpftool version                       
bpftool v7.4.0
using libbpf v1.4
features:

$ ll /usr/lib64/ | sudo grep libbpf.so                       
lrwxrwxrwx 1 root root   11 Jun  6 13:33 libbpf.so -> libbpf.so.1
lrwxrwxrwx 1 root root   15 Jun  6 13:33 libbpf.so.1 -> libbpf.so.1.4.3
-rwxr-xr-x 1 root root 1.6M Jun  6 13:33 libbpf.so.1.4.3

$ uname -m && lsb_release -d && uname -r
x86_64
No LSB modules are available.
Description:    Debian GNU/Linux trixie/sid
6.7.12-amd64

I was wondering how I could help bpftune support the gcc backend for BPF and get bpftune to work "fully" out of the box with it.

@oracle-contributor-agreement
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jun 6, 2024
@brianwitte
Copy link
Contributor Author

These appear to be what the gcc bpf backend is throwing warnings about:

bpf-gcc -g -O2 -g -fno-stack-protector -Wall -D__TARGET_ARCH_x86 -gbtf -mcpu=v3 -Wno-error=attributes -Wno-error=address-of-packed-member -Wno-compare-distinct-pointer-types -I../include -I/usr/include -I/usr/include/libnl3 -I../include/uapi -c tcp_buffer_tuner.bpf.c \
        -o tcp_buffer_tuner.bpf.o
In file included from ../include/bpftune/bpftune.bpf.h:36,
                 from tcp_buffer_tuner.bpf.c:20:
../include/bpftune/vmlinux_x86_64.h:5: warning: ignoring ‘#pragma clang attribute’ [-Wunknown-pragmas]
    5 | #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
../include/bpftune/vmlinux_x86_64.h:121955: warning: ignoring ‘#pragma clang attribute’ [-Wunknown-pragmas]
121955 | #pragma clang attribute pop
]

Here are the files grepped from project root:

$ rg "#pragma clang"
include/bpftune/bpftune.bpf.h
284:#pragma clang loop unroll(full)

include/bpftune/vmlinux_x86_64.h
5:#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
121955:#pragma clang attribute pop

include/bpftune/vmlinux_aarch64.h
5:#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
135255:#pragma clang attribute pop

Let me know how I can help with this! 😃

@oracle-contributor-agreement
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Jun 7, 2024
Copy link
Member

@alan-maguire alan-maguire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great, thanks Brian! We'll work on resolving the CO-RE related warnings later.

@alan-maguire alan-maguire merged commit 04bab5d into oracle:main Jun 7, 2024
@alan-maguire
Copy link
Member

your efforts are greatly appreciated, thanks Brian! On the subject of the warnings, the push attribute for Compile Once, Run Everywhere (CO-RE) is in the bpftool-generated vmlinux files as you've observed. That attribute is not supported in gcc so there are efforts upstream to support a gcc-friendly vmlinux.h generation. That said, gcc-bpf does support CO-Re so I think we should be able to get BTF relocations to work regardless. I suggest we regenerate our vmlinux.h files once the upstream efforts are complete.

@brianwitte
Copy link
Contributor Author

Ok, got it! Thank you for getting back to the PR so quickly. That was awesome.

I will look into what the upstream situation is and see if I can get clarity on options available for bpftune.

@alan-maguire
Copy link
Member

thanks for working on this! see this thread for more on the bpftool stuff: https://lore.kernel.org/bpf/[email protected]/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants