Giter VIP home page Giter VIP logo

ci's Introduction

libbpf Github Actions Builds & Tests Coverity CodeQL OSS-Fuzz Status Read the Docs

This is the official home of the libbpf library.

Please use this Github repository for building and packaging libbpf and when using it in your projects through Git submodule.

Libbpf authoritative source code is developed as part of bpf-next Linux source tree under tools/lib/bpf subdirectory and is periodically synced to Github. As such, all the libbpf changes should be sent to BPF mailing list, please don't open PRs here unless you are changing Github-specific parts of libbpf (e.g., Github-specific Makefile).

Libbpf and general BPF usage questions

Libbpf documentation can be found here. It's an ongoing effort and has ways to go, but please take a look and consider contributing as well.

Please check out libbpf-bootstrap and the companion blog post for the examples of building BPF applications with libbpf. libbpf-tools are also a good source of the real-world libbpf-based tracing tools.

See also "BPF CO-RE reference guide" for the coverage of practical aspects of building BPF CO-RE applications and "BPF CO-RE" for general introduction into BPF portability issues and BPF CO-RE origins.

All general BPF questions, including kernel functionality, libbpf APIs and their application, should be sent to [email protected] mailing list. You can subscribe to it here and search its archive here. Please search the archive before asking new questions. It very well might be that this was already addressed or answered before.

[email protected] is monitored by many more people and they will happily try to help you with whatever issue you have. This repository's PRs and issues should be opened only for dealing with issues pertaining to specific way this libbpf mirror repo is set up and organized.

Building libbpf

libelf is an internal dependency of libbpf and thus it is required to link against and must be installed on the system for applications to work. pkg-config is used by default to find libelf, and the program called can be overridden with PKG_CONFIG.

If using pkg-config at build time is not desired, it can be disabled by setting NO_PKG_CONFIG=1 when calling make.

To build both static libbpf.a and shared libbpf.so:

$ cd src
$ make

To build only static libbpf.a library in directory build/ and install them together with libbpf headers in a staging directory root/:

$ cd src
$ mkdir build root
$ BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=root make install

To build both static libbpf.a and shared libbpf.so against a custom libelf dependency installed in /build/root/ and install them together with libbpf headers in a build directory /build/root/:

$ cd src
$ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install

BPF CO-RE (Compile Once โ€“ Run Everywhere)

Libbpf supports building BPF CO-RE-enabled applications, which, in contrast to BCC, do not require Clang/LLVM runtime being deployed to target servers and doesn't rely on kernel-devel headers being available.

It does rely on kernel to be built with BTF type information, though. Some major Linux distributions come with kernel BTF already built in:

  • Fedora 31+
  • RHEL 8.2+
  • OpenSUSE Tumbleweed (in the next release, as of 2020-06-04)
  • Arch Linux (from kernel 5.7.1.arch1-1)
  • Manjaro (from kernel 5.4 if compiled after 2021-06-18)
  • Ubuntu 20.10
  • Debian 11 (amd64/arm64)

If your kernel doesn't come with BTF built-in, you'll need to build custom kernel. You'll need:

  • pahole 1.16+ tool (part of dwarves package), which performs DWARF to BTF conversion;
  • kernel built with CONFIG_DEBUG_INFO_BTF=y option;
  • you can check if your kernel has BTF built-in by looking for /sys/kernel/btf/vmlinux file:
$ ls -la /sys/kernel/btf/vmlinux
-r--r--r--. 1 root root 3541561 Jun  2 18:16 /sys/kernel/btf/vmlinux

To develop and build BPF programs, you'll need Clang/LLVM 10+. The following distributions have Clang/LLVM 10+ packaged by default:

  • Fedora 32+
  • Ubuntu 20.04+
  • Arch Linux
  • Ubuntu 20.10 (LLVM 11)
  • Debian 11 (LLVM 11)
  • Alpine 3.13+

Otherwise, please make sure to update it on your system.

The following resources are useful to understand what BPF CO-RE is and how to use it:

Distributions

Distributions packaging libbpf from this mirror:

Benefits of packaging from the mirror over packaging from kernel sources:

  • Consistent versioning across distributions.
  • No ties to any specific kernel, transparent handling of older kernels. Libbpf is designed to be kernel-agnostic and work across multitude of kernel versions. It has built-in mechanisms to gracefully handle older kernels, that are missing some of the features, by working around or gracefully degrading functionality. Thus libbpf is not tied to a specific kernel version and can/should be packaged and versioned independently.
  • Continuous integration testing via GitHub Actions.
  • Static code analysis via LGTM and Coverity.

Package dependencies of libbpf, package names may vary across distros:

  • zlib
  • libelf

libbpf distro packaging status

bpf-next to Github sync

All the gory details of syncing can be found in scripts/sync-kernel.sh script. See SYNC.md for instruction.

Some header files in this repo (include/linux/*.h) are reduced versions of their counterpart files at bpf-next's tools/include/linux/*.h to make compilation successful.

License

This work is dual-licensed under BSD 2-clause license and GNU LGPL v2.1 license. You can choose between one of them if you use this work.

SPDX-License-Identifier: BSD-2-Clause OR LGPL-2.1

ci's People

Contributors

anakryiko avatar borkmann avatar chantra avatar d-e-s-o avatar danielocfb avatar eddyz87 avatar insearchoflosttime avatar liu-song-6 avatar mykola-lysenko avatar qmonnet avatar teknoraver avatar thefallentree avatar tsipa avatar yonghong-song avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ci's Issues

run BPF CI on changes to this repository

We may want to make sure to run some Linux kernel CI using this repository when a pull request is submitted and/or a change is pushed to master. I'd guess (but have not checked) that we could probably reuse large swaths of libbpf CI hooks to go about that.

Docs

Please add initial documentation for this repo.

Update rootfs with openssl and keyutils

Logs are showing:

  #250     verif_stats:OK
  #251     verif_twfw:OK
  ./verify_sig_setup.sh: line 41: openssl: command not found
  ./verify_sig_setup.sh: line 58: keyctl: command not found
  ./verify_sig_setup.sh: line 58: keyctl: command not found
  test_verify_pkcs7_sig:PASS:mkdtemp 0 nsec
  test_verify_pkcs7_sig:FAIL:_run_setup_process unexpected error: 127 (errno 126)

LLVM feature detection and bpftool's runtime dependencies

TL;DR: I'm trying to fix feature detection for LLVM in the kernel's tools/build system. If I do, this breaks the CI because bpftool misses the LLVM libraries as runtime dependencies.

Context

In the kernel repository, under tools/build/feature, we can test for a number of "features" that may or may not be supported by the host for building tools. These are used by perf or bpftool, for example. In particular, there is a probe to detect the availability of LLVM libraries. But the detection is broken for LLVM v16+, and new versions of LLVM are always reported as missing. I'm trying to fix that.

The fix is simple. So I've got a patch in preparation for it. But this patch also breaks the BPF CI.

Issue

Here's what happens:

  • With the patch applied and LLVM feature detection fixed, LLVM libraries are correctly reported as available in the CI setup when building bpftool.

  • Bpftool uses the LLVM disassembler for JIT-ed programs by default; given that the libraries are available, it links against them.

  • But the libraries also need to be available at runtime for bpftool to work properly. So when running in the VM image, bpftool invocations fail. In test_progs and test_progs_no_alu32, core_reloc attempts to run bpftool gen min_core_btf and fails with the following message:

    ./bpftool: error while loading shared libraries: libLLVM-17.so.1: cannot open shared object file: No such file or directory
    

The reason we never noticed the issue before is likely that the runtime dependencies are met for the alternative libbfd-based disassembler (binutils is installed in the rootfs), and that the CI has likely been using LLVM 16 or higher since before the switch to the LLVM disassembler by default was merged.

Possible fix

The "easy" fix would be to add the LLVM libraries to the rootfs image (using the same version as used to compile bpftool, not just Debian's llvm-dev). But I'm not sure this is desirable, as it would increase the size and build time for the image. So I'm opening this Issue to get some feedback and see whether this is acceptable, or if someone has a better alternative to suggest.

Note: We don't need the JIT-disassembler at all for the selftests at the moment, so if we could build bpftool without LLVM support for selftests, this should solve the issue. But we don't currently have a clean way to disable LLVM support in bpftool (if the libraries are here, we use them, period). We could possibly hack something by crafting and passing a specific value for $(FEATURE_TESTS), or abusing $(LLVM_CONFIG) to make the LLVM feature detection fail, but both hacks would require a way to pass down arguments to the call to $(MAKE) for building bpftool from selftests' Makefile, which we currently don't have. And it doesn't look super clean. Similarly, building bpftool statically would require passing down the right flags, as well as getting compatible LLVM libraries (the default ones can only be used for linking dynamically - we'd have to build them or download some, like in bpftool's CI).

libbpf dependency of iproute2 is too old

Hi,

I was encountering some relocation issue when test PR on BPF-CI. After some digging the error says:

libbpf: prog 'test_lwt_redirect_in': bad map relo against '.rodata.str1.1' in section '.rodata.str1.1'

It turns out the latest root image libbpf-vmtest-rootfs-2022.10.23-bullseye-amd64.tar.zst has iproute2 with libbpf-0.3, and support for .rodata. was introduced in commit 5bf62459b185 ("libbpf: Support multiple .rodata.* and .data.* BPF maps") from v0.6.0. Unpacking and running the root image locally with same BPF object confirms that upgrading libbpf0 would fix the issue.

Will it be feasible if admins can update the root image to pull libbpf0 from bullseye-backport? It does have slight newer version https://packages.debian.org/bullseye-backports/libbpf0, or better if we can have newer iproute2 and libbpf1 in the root image?

thanks

init script spewing errors when vm starts

The checks seem valid yes, when the vm starts we get this error in the logs (see https://github.com/kernel-patches/bpf/actions/runs/3303109637/jobs/5450787223#step:6:425)

+ [ -x /etc/rcS.d/S10-mount ]
  + /etc/rcS.d/S10-mount
  + /bin/mount proc /proc -t proc
  + /bin/mount -t devtmpfs
  + [[ -z devtmpfs on /dev type devtmpfs (rw,relatime,size=3029136k,nr_inodes=757284,mode=755) ]]
  [[: on: unknown operand
  + /bin/mount sysfs /sys -t sysfs
  + /bin/mount bpffs /sys/fs/bpf -t bpf
  + /bin/mount debugfs /sys/kernel/debug -t debugfs
  + [[ -a /dev/fd ]]
  [[: /dev/fd: unknown operand
  + ln -s /proc/self/fd /dev/fd
  + echo Listing currently mounted file systems
  Listing currently mounted file systems
  + /bin/mount
  /dev/vda on / type ext4 (rw,relatime)

mkrootfs_debian.sh failing to build foreign architecture

Building x-arch rootfs started failing. This is because a change may have happen in bullseye recently that calls a binary as part of debootstrap:

The exact error is:

I: Extracting zlib1g...
W: Failure trying to run: chroot "/home/chantra/devel/libbpf/ci/rootfs/tmp.jwLB9EVVaG" /bin/true
W: See /home/chantra/devel/libbpf/ci/rootfs/tmp.jwLB9EVVaG/debootstrap/debootstrap.log for details

and the actual log line:

chroot: failed to run command '/bin/true': Exec format error

The solution to this is to use the --foreign option of debootstrap and using qemu.

Example: https://askubuntu.com/questions/287789/what-is-debootstrap-second-stage-for

chmod: cannot access '/boot/vmlinuz*' if no kernel is installed in container.

If the container does not have any /boot/vmlinuz* file, preepare-rootfs will fail with:

Disk image: /tmp/root.img
vmlinux_setup - Preparing Linux image
  
  chmod: cannot access '/boot/vmlinuz*': No such file or directory
  libguestfs: error: /usr/bin/supermin exited with error status 1.
  To see full error messages you may need to enable debugging.
  Do:
    export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1
  and run the command again.  For further information, read:
    http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs
  You can also run 'libguestfs-test-tool' and post the *complete* output
  into a bug report or message to the libguestfs mailing list.
  Error: Process completed with exit code 2.

This is due to

sudo chmod +r /boot/vmlinuz* || true

Installing linux-image-generic in the container works.

apt install linux-image-generic

but we should re-assess if this is really needed still.

[prepare-rootfs] improve rootfs selection

Currently, we run tests in a Debian Bullseye rootfs. This works with our current CI runners (Ubuntu focal) but this is very brittle.

  1. in the past, we had some dependency issues.
  2. people may run vmtests from different hosts then Ubuntu focal.

The way we do rootfs selection at the moment is pretty simple: https://github.com/libbpf/ci/blob/1b794627fd7431428a7e5a077010285733eaedf2/prepare-rootfs/run.sh#L223C26-L231

The rootfs have the distro release in their name, so we could possibly filter on this.
The script to generate rootfs uses debootstrap and should work with pretty much any Debian derivative.

We could generate a rootfs for common rootfs we care about, put them all in INDEX and when selecting the rootfs, try to match the hosts' distro, and fallback on a default one otherwise.

This should help with #83, and avoid issues like we had in the past (see comment in that PR).

Because currently libbpf/ci and vmtest in kernel tree differ, we would also need to update
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/tree/tools/testing/selftests/bpf/vmtest.sh?id=c1a3daf7363b48c6c4b86aee2efa2287f695f649#n106 with the change.

Given the current behaviour of that function, we may be able to get away with updating the index file and the test will just pick up whatever is latest alphabetically.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.