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

linux-kernel: Enable BTF #127922

Merged
merged 1 commit into from
Aug 25, 2021
Merged

linux-kernel: Enable BTF #127922

merged 1 commit into from
Aug 25, 2021

Conversation

roblabla
Copy link
Contributor

Motivation for this change

BTF is a new, lightweight debug information format tailored specifically
for the needs of eBPF, allowing eBPF programs to be portable across
various kernel versions, configurations and distributions. This is used
by bpftrace and lots of new eBPF-based tooling to avoid a dependency
on LLVM on the host.

BTF debug information is enabled on all major distributions: Fedora 31+,
RHEL 8.2+, Ubuntu 20.10, Debian 11 and ArchLinux all have enabled it.

Enabling BTF debug information requires adding two new dependencies to
the kernel build: Python3 and pahole. Those will be used to generate the
BTF debugging information.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@moni-dz
Copy link
Contributor

moni-dz commented Jun 23, 2021

@ofborg build linux_xanmod

@moni-dz
Copy link
Contributor

moni-dz commented Jun 23, 2021

@ofborg test latestKernel.login kernel-latest

@Atemu
Copy link
Member

Atemu commented Jun 23, 2021

Please target staging, this causes a ton of rebuilds which most users won't directly benefit from any time soon.

@roblabla
Copy link
Contributor Author

How should I do that? Just change the target branch in github's ui?

@lovesegfault
Copy link
Member

How should I do that? Just change the target branch in github's ui?

I'm not sure that works. For me I do:

git fetch --all
git checkout $myBranch
git rebase -i origin/staging
git push --force

You may or may not fiddle with GH's UI as well, not sure.

@Atemu
Copy link
Member

Atemu commented Jun 24, 2021

No, don't do that. That way you'd try to merge staging into master and ping pretty much all codeowners.

Just change the base (or target) branch in the GH UI. You only need to rebase if there's a merge conflict between your branch and staging; after you changed the target branch that is.

@roblabla roblabla changed the base branch from master to staging June 24, 2021 08:58
@roblabla
Copy link
Contributor Author

Done, and no conflicts!

@ofborg ofborg bot requested a review from moni-dz June 24, 2021 09:09
@markpash
Copy link
Contributor

markpash commented Aug 3, 2021

Hi, what else needs to be done for this PR to get approvals and get merged? Having BTF info in the kernel is very useful for software packages that make use of eBPF and for eBPF development.

@lovesegfault
Copy link
Member

If someone resolves the conflict and pings me I will merge this.

BTF is a new, lightweight debug information format tailored specifically
for the needs of eBPF, allowing eBPF programs to be portable across
various kernel versions, configurations and distributions. This is used
by bpftrace and lots of new eBPF-based tooling to avoid a dependency
on LLVM on the host.

BTF debug information is enabled on all major distributions: Fedora 31+,
RHEL 8.2+, Ubuntu 20.10, Debian 11 and ArchLinux all have enabled it.

Enabling BTF debug information requires adding two new dependencies to
the kernel build: Python3 and pahole. Those will be used to generate the
BTF debugging information.
@roblabla
Copy link
Contributor Author

roblabla commented Aug 18, 2021

Well, that shux. It works on my machine, and I tested kernel 5.10 and 5.12 (EDIT: 5.13 since latest staging removed 5.12). To test, I use a flake.nix system that looks like this:

{
    inputs.nixpkgs.url = "github:roblabla/nixpkgs/enable-btf";
    packages.x86_64-linux.kernel = nixpkgs.legacyPackages.x86_64-linux.linuxPackages_5_10.kernel;
    packages.x86_64-linux.configfile = nixpkgs.legacyPackages.x86_64-linux.linuxPackages_5_10.kernel.configfile;
  };
}

and then just run nix build '.#configfile'. The lockfile pins commit 34150f8 now.

@Mic92 Could you provide the full logs so I can figure out what went wrong? Those warnings in the last 10 lines all seem "normal" to me, and not hard errors. The actual problem is probably burried in the logs.

@ofborg ofborg bot requested review from moni-dz and removed request for Chiiruno August 18, 2021 08:59
@Mic92 Mic92 merged commit 2976669 into NixOS:staging Aug 25, 2021
@Mic92
Copy link
Member

Mic92 commented Aug 25, 2021

I think it's only linuxPackages_5_10_hardened.kernel now which is sort of broken anyway.

@lopsided98
Copy link
Contributor

zlib needs to be in nativeBuildInputs, otherwise the kernel fails to cross-compile. zlib appears to only be used for a build system tool, so this makes sense.

@Izorkin
Copy link
Contributor

Izorkin commented Sep 27, 2021

With this PR error build kernel:

  LD [M]  drivers/net/wireless/intersil/hostap/hostap_pci.ko
  LD [M]  drivers/net/wireless/intel/iwlwifi/iwlwifi.ko
  LD [M]  drivers/net/wireless/intersil/orinoco/orinoco.ko
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: drivers/net/wireless/intel/ipw2x00/ipw2100.ko: final close failed: No space left on device
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: drivers/net/wireless/ath/wil6210/wil6210.ko: final close failed: No space left on device
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/ipw2x00/ipw2100.ko] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/ath/wil6210/wil6210.ko] Error 1
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/broadcom/b43legacy/b43legacy.ko] Error 1
/nix/store/qfb4j7w2fjjq953nd9xncz5mymj5n0kb-bash-5.1-p8/bin/bash: line 1: printf: write error: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/cisco/airo_cs.ko] Error 1
make[3]: *** Deleting file 'drivers/net/wireless/cisco/airo_cs.ko'
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/ipw2x00/ipw2200.ko] Error 1
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/cisco/airo.ko] Error 1
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/broadcom/brcm80211/brcmsmac/brcmsmac.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/iwlegacy/iwl3945.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/ipw2x00/libipw.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko] Error 1
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/broadcom/b43/b43.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: drivers/net/wireless/ath/ath9k/ath9k_htc.ko: final close failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/ath/ath9k/ath9k_htc.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intersil/hostap/hostap_cs.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/ath/ath9k/ath9k_hw.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: : drivers/net/wireless/intersil/hostap/hostap.kodrivers/net/wireless/intersil/orinoco/orinoco.ko: final close failed: : final close failed: No space left on deviceNo space left on device

make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intersil/hostap/hostap.ko] Error 1
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intersil/orinoco/orinoco.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/iwlwifi/mvm/iwlmvm.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/iwlwifi/iwlwifi.ko] Error 1
make[2]: *** [../scripts/Makefile.modpost:152: __modpost] Error 2
make[1]: *** [/tmp/nix-build-linux-5.12.19.drv-0/linux-5.12.19/Makefile:1450: modules] Error 2
make: *** [../Makefile:215: __sub-make] Error 2
builder for '/nix/store/rjxmmqq2rmp8g2pm8zw05mjji47c1m3q-linux-5.12.19.drv' failed with exit code 2
note: build failure may have been caused by lack of free disk space
error: build of '/nix/store/rjxmmqq2rmp8g2pm8zw05mjji47c1m3q-linux-5.12.19.drv' failed

@Mic92
Copy link
Member

Mic92 commented Sep 28, 2021

@Izorkin your error looks like you run out of disk-space. Make sure $TMPDIR is not pointing to a tmpfs.

Mic92 added a commit to Mic92/nixpkgs that referenced this pull request Sep 28, 2021
This is untested but according to
NixOS#127922 (comment)

zlib is only used in the host build, which breaks cross-compilation if
not present.
@Mic92 Mic92 mentioned this pull request Sep 28, 2021
12 tasks
@Mic92
Copy link
Member

Mic92 commented Sep 28, 2021

@lopsided98 see #139710

alyssais pushed a commit that referenced this pull request Sep 28, 2021
This is untested but according to
#127922 (comment)

zlib is only used in the host build, which breaks cross-compilation if
not present.
@Izorkin
Copy link
Contributor

Izorkin commented Sep 28, 2021

I checked this variant yesterday - error build.

There is enough free space on /tmp.

df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            16G  4.0K   16G   1% /tmp

Mic92 added a commit to Mic92/nixpkgs that referenced this pull request Sep 28, 2021
This is untested but according to
NixOS#127922 (comment)

zlib is only used in the host build, which breaks cross-compilation if
not present.
@Mic92
Copy link
Member

Mic92 commented Sep 28, 2021

The error message clearly indicates no space left errors though:

make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/iwlegacy/iwl3945.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intel/ipw2x00/libipw.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko] Error 1
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/broadcom/b43/b43.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: drivers/net/wireless/ath/ath9k/ath9k_htc.ko: final close failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/ath/ath9k/ath9k_htc.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device
make[3]: *** [../scripts/Makefile.modfinal:78: drivers/net/wireless/intersil/hostap/hostap_cs.ko] Error 1
/nix/store/fp2h123793bxln4cjxy0mz08sf4nx2m3-binutils-2.35.1/bin/ld: final link failed: No space left on device

Notice that if TMPDIR can also point to /run/user/$UID if you are in a nix-shell, which can be surprising.

@Izorkin
Copy link
Contributor

Izorkin commented Sep 28, 2021

Checked it out. The build uses all 16GB of memory.
Without etnable BTF - 3,5GB.

@Mic92
Copy link
Member

Mic92 commented Sep 28, 2021

Maybe but don't build it on tmpfs than.

@lovesegfault
Copy link
Member

I don't think we should be enabling these by default. People who want it can set options.debug like before.

@roblabla
Copy link
Contributor Author

roblabla commented Sep 28, 2021

Those should definitely be enabled by default, as they enable eBPF CO-RE functionality: https://facebookmicrosites.github.io/bpf/blog/2020/02/19/bpf-portability-and-co-re.html

This is very important for a bunch of bpf-based tools. It's enabled by default on many distribs, like Fedora, Ubuntu and ArchLinux for this reason.

@alyssais
Copy link
Member

This ballooned the size of zfs.ko.xz ten-fold for me, from 881K to 9.4M. Other modules from ZFS are also affected, and the combined size increase means my initramfs no longer fits on my boot partition. But it didn't increase the size of Linux itself at all, so presumably there's some change we can make to the ZFS package to fix this?

I do agree it makes sense for this to be enabled by default.

@roblabla roblabla deleted the enable-btf branch September 29, 2021 09:43
@Mic92
Copy link
Member

Mic92 commented Sep 29, 2021

Kernel without btf:

$ wc -c bzImage
6360032

Kernel with btf

$ wc -c ./result/bzImage
7280640 ./result/bzImage

So it's a 14% increase for the kernel image.

Not sure where the 10x increase for zfs comes from.

@Atemu
Copy link
Member

Atemu commented Oct 11, 2021

#141284

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

Successfully merging this pull request may close these issues.

None yet

10 participants