mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-21 16:59:07 +08:00
Compare commits
219 Commits
libbf_0_7
...
v0.8.1_net
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70599f3a1e | ||
|
|
b78c75fcb3 | ||
|
|
f42d136c1c | ||
|
|
812a95fdf7 | ||
|
|
f9f7f2d30a | ||
|
|
25ba007681 | ||
|
|
9bdb296ec6 | ||
|
|
f009af7889 | ||
|
|
62e8af46d2 | ||
|
|
fcd1b668c6 | ||
|
|
0eb12dca7e | ||
|
|
fedeba74b7 | ||
|
|
bf51e3c336 | ||
|
|
d8454ba8ad | ||
|
|
ec3bbc05c0 | ||
|
|
d32e7ea952 | ||
|
|
6abeb4203d | ||
|
|
e28a540c59 | ||
|
|
e8802d6319 | ||
|
|
9476dce6fe | ||
|
|
8ee1202ff4 | ||
|
|
7013b92fef | ||
|
|
20f0330235 | ||
|
|
29869d6ef0 | ||
|
|
72dbaf2ac3 | ||
|
|
bc3673cdd5 | ||
|
|
78909b8caf | ||
|
|
ec718073b0 | ||
|
|
9c73b6d422 | ||
|
|
0c84902331 | ||
|
|
4cb682229d | ||
|
|
0304a3c027 | ||
|
|
a459010926 | ||
|
|
e5ff285a44 | ||
|
|
2d91c46d1a | ||
|
|
d3e41fc1aa | ||
|
|
645500dd7d | ||
|
|
5497411f48 | ||
|
|
74b22b6c8a | ||
|
|
416351822c | ||
|
|
3f9d041e19 | ||
|
|
a945df2439 | ||
|
|
f429a582bf | ||
|
|
25238de149 | ||
|
|
c3f8eecb16 | ||
|
|
25fd7a1cf5 | ||
|
|
0167a88355 | ||
|
|
23e3d8cf31 | ||
|
|
9a976c6b98 | ||
|
|
e93b1010f3 | ||
|
|
76fc1ad6d5 | ||
|
|
33c5f2bec3 | ||
|
|
d4998cbb6c | ||
|
|
eb1d1ad83f | ||
|
|
8aa946389d | ||
|
|
ad0783c430 | ||
|
|
55638904af | ||
|
|
a5d75daa8c | ||
|
|
37218f49fa | ||
|
|
bdbce77631 | ||
|
|
242c116f04 | ||
|
|
4d9cd51e7e | ||
|
|
f035838503 | ||
|
|
7ed5bf8f4c | ||
|
|
1a0f5d1c87 | ||
|
|
c68a2738fd | ||
|
|
97009215cb | ||
|
|
4c39a3e1aa | ||
|
|
cb11988cf4 | ||
|
|
7e8d4234ac | ||
|
|
00f40c01fb | ||
|
|
881eba7ef5 | ||
|
|
4eb6485c08 | ||
|
|
eaf9123419 | ||
|
|
cc904c1a74 | ||
|
|
f3b96c873d | ||
|
|
47595c2f08 | ||
|
|
e4f2e6e865 | ||
|
|
86eb09863c | ||
|
|
d43fc5a42f | ||
|
|
12e932ac0e | ||
|
|
75452cd290 | ||
|
|
ae67bfbae3 | ||
|
|
650adc5118 | ||
|
|
babc92b9f1 | ||
|
|
e335f3fa5f | ||
|
|
7062757357 | ||
|
|
aec48fffee | ||
|
|
c116ae6130 | ||
|
|
99b21d41e3 | ||
|
|
7a443259de | ||
|
|
b3197662ba | ||
|
|
486b1a080b | ||
|
|
ba9850c048 | ||
|
|
5c1d6799df | ||
|
|
1f30788b41 | ||
|
|
a8bc578af9 | ||
|
|
d46f1aaa7c | ||
|
|
1a18c6f051 | ||
|
|
97ab064bc0 | ||
|
|
eee09dc704 | ||
|
|
87dff0a2c7 | ||
|
|
14777c3784 | ||
|
|
3a4e26307d | ||
|
|
ef6f1fdfff | ||
|
|
c3f58eb6cf | ||
|
|
2c3a55bfe7 | ||
|
|
e2d8a820cb | ||
|
|
aaaeea6499 | ||
|
|
f2e994e0b7 | ||
|
|
eb22de1f7d | ||
|
|
0a901dd1cd | ||
|
|
36582ee432 | ||
|
|
e7f46e2cae | ||
|
|
179ca056b0 | ||
|
|
56dff81d46 | ||
|
|
0d4cefc4fc | ||
|
|
5954a6c4aa | ||
|
|
38be0379c9 | ||
|
|
5fa8bb6b42 | ||
|
|
c5b91a333e | ||
|
|
8073e03491 | ||
|
|
eb2b216081 | ||
|
|
bddd106e80 | ||
|
|
e205664ddb | ||
|
|
557499a13e | ||
|
|
ffd4015f3b | ||
|
|
68e7624e9f | ||
|
|
b221db664f | ||
|
|
7bf9ee2dba | ||
|
|
533c7666eb | ||
|
|
dea5ae9fc9 | ||
|
|
8bc3e510fc | ||
|
|
14414c6ea5 | ||
|
|
ea10235072 | ||
|
|
f3cc144922 | ||
|
|
b69f8ee93e | ||
|
|
bbfb018473 | ||
|
|
1ce956ab3a | ||
|
|
5016f30a24 | ||
|
|
075c96c298 | ||
|
|
f044607934 | ||
|
|
4fd682d358 | ||
|
|
3663820dda | ||
|
|
fcb67a3e70 | ||
|
|
73b8386f2e | ||
|
|
462e3f600a | ||
|
|
13fe7fedfa | ||
|
|
b974879969 | ||
|
|
2b674f2b21 | ||
|
|
5810af7446 | ||
|
|
042471d356 | ||
|
|
f7833c0819 | ||
|
|
c562444fb0 | ||
|
|
750c9fb595 | ||
|
|
08cc701fae | ||
|
|
fa323673c5 | ||
|
|
876b933999 | ||
|
|
406386b441 | ||
|
|
1b4b798916 | ||
|
|
f5390e4f07 | ||
|
|
00cd090f81 | ||
|
|
0167a314e7 | ||
|
|
8dcb95d509 | ||
|
|
d112c9ce24 | ||
|
|
4a7fa5b2bc | ||
|
|
ff845b85e8 | ||
|
|
fee7b9400a | ||
|
|
360ed84faa | ||
|
|
3fbed0f1b2 | ||
|
|
67a4b14643 | ||
|
|
7db9ce5fda | ||
|
|
f1b6bc31a5 | ||
|
|
3ef1813702 | ||
|
|
d580bc49d1 | ||
|
|
cc4ef17c78 | ||
|
|
e7084d4363 | ||
|
|
c2ec92f0ee | ||
|
|
05acce9e03 | ||
|
|
2e6e39ef80 | ||
|
|
42f78dd5ac | ||
|
|
50ae8c25d2 | ||
|
|
e85e26492d | ||
|
|
9fb154ee77 | ||
|
|
34d57cc0eb | ||
|
|
a557610d11 | ||
|
|
5ad674a007 | ||
|
|
d647265e4b | ||
|
|
21cd83a1d1 | ||
|
|
6e77ef94f0 | ||
|
|
c84815ee37 | ||
|
|
4282f3cdec | ||
|
|
3591deb9bc | ||
|
|
767badc609 | ||
|
|
8e654d74c4 | ||
|
|
dac1e23c97 | ||
|
|
dc679587eb | ||
|
|
0d834905d8 | ||
|
|
0a43bc8905 | ||
|
|
5d491d5d07 | ||
|
|
9b53decb02 | ||
|
|
426672106e | ||
|
|
c85a8bbe9c | ||
|
|
e7997e49ea | ||
|
|
4c560383a6 | ||
|
|
9c44c8a8e0 | ||
|
|
1c173e5fc8 | ||
|
|
93c570ca4b | ||
|
|
33201b7ebd | ||
|
|
6edaacad4f | ||
|
|
af29a83fe2 | ||
|
|
6387d3900f | ||
|
|
196da61f1d | ||
|
|
db8dc47ce8 | ||
|
|
f7d89c3910 | ||
|
|
0d6262ad0a | ||
|
|
7593fc7a85 | ||
|
|
67f813c8a8 | ||
|
|
2cd2d03f63 |
214813
.github/actions/build-selftests/vmlinux.h
vendored
214813
.github/actions/build-selftests/vmlinux.h
vendored
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,11 @@ sphinx:
|
|||||||
builder: html
|
builder: html
|
||||||
configuration: docs/conf.py
|
configuration: docs/conf.py
|
||||||
|
|
||||||
|
formats:
|
||||||
|
- htmlzip
|
||||||
|
- pdf
|
||||||
|
- epub
|
||||||
|
|
||||||
# Optionally set the version of Python and requirements required to build your docs
|
# Optionally set the version of Python and requirements required to build your docs
|
||||||
python:
|
python:
|
||||||
version: 3.7
|
version: 3.7
|
||||||
|
|||||||
130
.travis.yml
130
.travis.yml
@@ -1,130 +0,0 @@
|
|||||||
sudo: required
|
|
||||||
language: bash
|
|
||||||
dist: focal
|
|
||||||
services:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- PROJECT_NAME='libbpf'
|
|
||||||
- AUTHOR_EMAIL="$(git log -1 --pretty=\"%aE\")"
|
|
||||||
- REPO_ROOT="$TRAVIS_BUILD_DIR"
|
|
||||||
- CI_ROOT="$REPO_ROOT/travis-ci"
|
|
||||||
- VMTEST_ROOT="$CI_ROOT/vmtest"
|
|
||||||
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- qemu-kvm
|
|
||||||
- zstd
|
|
||||||
- binutils-dev
|
|
||||||
- elfutils
|
|
||||||
- libcap-dev
|
|
||||||
- libelf-dev
|
|
||||||
- libdw-dev
|
|
||||||
|
|
||||||
stages:
|
|
||||||
# Run Coverity periodically instead of for each PR for following reasons:
|
|
||||||
# 1) Coverity jobs are heavily rate-limited
|
|
||||||
# 2) Due to security restrictions of encrypted environment variables
|
|
||||||
# in Travis CI, pull requests made from forks can't access encrypted
|
|
||||||
# env variables, making Coverity unusable
|
|
||||||
# See: https://docs.travis-ci.com/user/pull-requests#pull-requests-and-security-restrictions
|
|
||||||
- name: Coverity
|
|
||||||
if: type = cron
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
- stage: Builds & Tests
|
|
||||||
name: Kernel 5.5.0 + selftests
|
|
||||||
language: bash
|
|
||||||
env: KERNEL=5.5.0
|
|
||||||
script: $CI_ROOT/vmtest/run_vmtest.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- name: Kernel LATEST + selftests
|
|
||||||
language: bash
|
|
||||||
env: KERNEL=LATEST
|
|
||||||
script: $CI_ROOT/vmtest/run_vmtest.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- name: Kernel 4.9.0 + selftests
|
|
||||||
language: bash
|
|
||||||
env: KERNEL=4.9.0
|
|
||||||
script: $CI_ROOT/vmtest/run_vmtest.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- name: Debian Build
|
|
||||||
language: bash
|
|
||||||
install: $CI_ROOT/managers/debian.sh SETUP
|
|
||||||
script: $CI_ROOT/managers/debian.sh RUN || travis_terminate 1
|
|
||||||
after_script: $CI_ROOT/managers/debian.sh CLEANUP
|
|
||||||
|
|
||||||
- name: Debian Build (ASan+UBSan)
|
|
||||||
language: bash
|
|
||||||
install: $CI_ROOT/managers/debian.sh SETUP
|
|
||||||
script: $CI_ROOT/managers/debian.sh RUN_ASAN || travis_terminate 1
|
|
||||||
after_script: $CI_ROOT/managers/debian.sh CLEANUP
|
|
||||||
|
|
||||||
- name: Debian Build (clang)
|
|
||||||
language: bash
|
|
||||||
install: $CI_ROOT/managers/debian.sh SETUP
|
|
||||||
script: $CI_ROOT/managers/debian.sh RUN_CLANG || travis_terminate 1
|
|
||||||
after_script: $CI_ROOT/managers/debian.sh CLEANUP
|
|
||||||
|
|
||||||
- name: Debian Build (clang ASan+UBSan)
|
|
||||||
language: bash
|
|
||||||
install: $CI_ROOT/managers/debian.sh SETUP
|
|
||||||
script: $CI_ROOT/managers/debian.sh RUN_CLANG_ASAN || travis_terminate 1
|
|
||||||
after_script: $CI_ROOT/managers/debian.sh CLEANUP
|
|
||||||
|
|
||||||
- name: Debian Build (gcc-10)
|
|
||||||
language: bash
|
|
||||||
install: $CI_ROOT/managers/debian.sh SETUP
|
|
||||||
script: $CI_ROOT/managers/debian.sh RUN_GCC10 || travis_terminate 1
|
|
||||||
after_script: $CI_ROOT/managers/debian.sh CLEANUP
|
|
||||||
|
|
||||||
- name: Debian Build (gcc-10 ASan+UBSan)
|
|
||||||
language: bash
|
|
||||||
install: $CI_ROOT/managers/debian.sh SETUP
|
|
||||||
script: $CI_ROOT/managers/debian.sh RUN_GCC10_ASAN || travis_terminate 1
|
|
||||||
after_script: $CI_ROOT/managers/debian.sh CLEANUP
|
|
||||||
|
|
||||||
- name: Ubuntu Focal Build
|
|
||||||
language: bash
|
|
||||||
script: sudo $CI_ROOT/managers/ubuntu.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- name: Ubuntu Focal Build (arm)
|
|
||||||
arch: arm64
|
|
||||||
language: bash
|
|
||||||
script: sudo $CI_ROOT/managers/ubuntu.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- name: Ubuntu Focal Build (s390x)
|
|
||||||
arch: s390x
|
|
||||||
language: bash
|
|
||||||
script: sudo $CI_ROOT/managers/ubuntu.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- name: Ubuntu Focal Build (ppc64le)
|
|
||||||
arch: ppc64le
|
|
||||||
language: bash
|
|
||||||
script: sudo $CI_ROOT/managers/ubuntu.sh || travis_terminate 1
|
|
||||||
|
|
||||||
- stage: Coverity
|
|
||||||
language: bash
|
|
||||||
env:
|
|
||||||
# Coverity configuration
|
|
||||||
# COVERITY_SCAN_TOKEN=xxx
|
|
||||||
# Encrypted using `travis encrypt --repo libbpf/libbpf COVERITY_SCAN_TOKEN=xxx`
|
|
||||||
- secure: "I9OsMRHbb82IUivDp+I+w/jEQFOJgBDAqYqf1ollqCM1QhocxMcS9bwIAgfPhdXi2hohV7sRrVMZstahY67FAvJLGxNopi4tAPDIAaIFxgO0yDxMhaTMx5xDfMwlIm2FOP/9gB9BQsd6M7CmoQZgXYwBIv7xd1ooxoQrh2rOK1YrRl7UQu3+c3zPTjDfIYZzR3bFttMqZ9/c4U0v8Ry5IFXrel3hCshndHA1TtttJrUSrILlZcmVc1ch7JIy6zCbCU/2lGv0B/7rWXfF8MT7O9jPtFOhJ1DEcd2zhw2n4j9YT3a8OhtnM61LA6ask632mwCOsxpFLTun7AzuR1Cb5mdPHsxhxnCHcXXARa2mJjem0QG1NhwxwJE8sbRDapojexxCvweYlEN40ofwMDSnj/qNt95XIcrk0tiIhGFx0gVNWvAdmZwx+N4mwGPMTAN0AEOFjpgI+ZdB89m+tL/CbEgE1flc8QxUxJhcp5OhH6yR0z9qYOp0nXIbHsIaCiRvt/7LqFRQfheifztWVz4mdQlCdKS9gcOQ09oKicPevKO1L0Ue3cb7Ug7jOpMs+cdh3XokJtUeYEr1NijMHT9+CTAhhO5RToWXIZRon719z3fwoUBNDREATwVFMlVxqSO/pbYgaKminigYbl785S89YYaZ6E5UvaKRHM6KHKMDszs="
|
|
||||||
- COVERITY_SCAN_PROJECT_NAME="libbpf"
|
|
||||||
- COVERITY_SCAN_NOTIFICATION_EMAIL="${AUTHOR_EMAIL}"
|
|
||||||
- COVERITY_SCAN_BRANCH_PATTERN="$TRAVIS_BRANCH"
|
|
||||||
# Note: `make -C src/` as a BUILD_COMMAND will not work here
|
|
||||||
- COVERITY_SCAN_BUILD_COMMAND_PREPEND="cd src/"
|
|
||||||
- COVERITY_SCAN_BUILD_COMMAND="make"
|
|
||||||
install:
|
|
||||||
- sudo echo 'deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse' >>/etc/apt/sources.list
|
|
||||||
- sudo apt-get update
|
|
||||||
- sudo apt-get -y build-dep libelf-dev
|
|
||||||
- sudo apt-get install -y libelf-dev pkg-config
|
|
||||||
script:
|
|
||||||
- scripts/coverity.sh || travis_terminate 1
|
|
||||||
allow_failures:
|
|
||||||
- env: KERNEL=x.x.x
|
|
||||||
@@ -1 +1 @@
|
|||||||
fe68195daf34d5dddacd3f93dd3eafc4beca3a0e
|
d28b25a62a47a8c8aa19bd543863aab6717e68c9
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
dc37dc617fabfb1c3a16d49f5d8cc20e9e3608ca
|
b0d93b44641a83c28014ca38001e85bf6dc8501e
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Usage-Guide:
|
|||||||
SPDX-License-Identifier: BSD-2-Clause
|
SPDX-License-Identifier: BSD-2-Clause
|
||||||
License-Text:
|
License-Text:
|
||||||
|
|
||||||
Copyright (c) <year> <owner> . All rights reserved.
|
Copyright (c) 2015 The Libbpf Authors. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|||||||
58
README.md
58
README.md
@@ -73,34 +73,6 @@ $ cd src
|
|||||||
$ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install
|
$ PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install
|
||||||
```
|
```
|
||||||
|
|
||||||
Distributions
|
|
||||||
=============
|
|
||||||
|
|
||||||
Distributions packaging libbpf from this mirror:
|
|
||||||
- [Fedora](https://src.fedoraproject.org/rpms/libbpf)
|
|
||||||
- [Gentoo](https://packages.gentoo.org/packages/dev-libs/libbpf)
|
|
||||||
- [Debian](https://packages.debian.org/source/sid/libbpf)
|
|
||||||
- [Arch](https://www.archlinux.org/packages/extra/x86_64/libbpf/)
|
|
||||||
- [Ubuntu](https://packages.ubuntu.com/source/impish/libbpf)
|
|
||||||
- [Alpine](https://pkgs.alpinelinux.org/packages?name=libbpf)
|
|
||||||
|
|
||||||
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
|
|
||||||
[TravisCI](https://travis-ci.org/libbpf/libbpf).
|
|
||||||
- Static code analysis via [LGTM](https://lgtm.com/projects/g/libbpf/libbpf)
|
|
||||||
and [Coverity](https://scan.coverity.com/projects/libbpf).
|
|
||||||
|
|
||||||
Package dependencies of libbpf, package names may vary across distros:
|
|
||||||
- zlib
|
|
||||||
- libelf
|
|
||||||
|
|
||||||
BPF CO-RE (Compile Once – Run Everywhere)
|
BPF CO-RE (Compile Once – Run Everywhere)
|
||||||
=========================================
|
=========================================
|
||||||
|
|
||||||
@@ -154,6 +126,36 @@ use it:
|
|||||||
converting some more to both contribute to the BPF community and gain some
|
converting some more to both contribute to the BPF community and gain some
|
||||||
more experience with it.
|
more experience with it.
|
||||||
|
|
||||||
|
Distributions
|
||||||
|
=============
|
||||||
|
|
||||||
|
Distributions packaging libbpf from this mirror:
|
||||||
|
- [Fedora](https://src.fedoraproject.org/rpms/libbpf)
|
||||||
|
- [Gentoo](https://packages.gentoo.org/packages/dev-libs/libbpf)
|
||||||
|
- [Debian](https://packages.debian.org/source/sid/libbpf)
|
||||||
|
- [Arch](https://www.archlinux.org/packages/extra/x86_64/libbpf/)
|
||||||
|
- [Ubuntu](https://packages.ubuntu.com/source/impish/libbpf)
|
||||||
|
- [Alpine](https://pkgs.alpinelinux.org/packages?name=libbpf)
|
||||||
|
|
||||||
|
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](https://github.com/libbpf/libbpf/actions).
|
||||||
|
- Static code analysis via [LGTM](https://lgtm.com/projects/g/libbpf/libbpf)
|
||||||
|
and [Coverity](https://scan.coverity.com/projects/libbpf).
|
||||||
|
|
||||||
|
Package dependencies of libbpf, package names may vary across distros:
|
||||||
|
- zlib
|
||||||
|
- libelf
|
||||||
|
|
||||||
|
[](https://repology.org/project/libbpf/versions)
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ libbpf
|
|||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
|
API Documentation <https://libbpf.readthedocs.io/en/latest/api.html>
|
||||||
libbpf_naming_convention
|
libbpf_naming_convention
|
||||||
libbpf_build
|
libbpf_build
|
||||||
|
|
||||||
This is documentation for libbpf, a userspace library for loading and
|
This is documentation for libbpf, a userspace library for loading and
|
||||||
interacting with bpf programs.
|
interacting with bpf programs.
|
||||||
|
|
||||||
For API documentation see the `versioned API documentation site <https://libbpf.readthedocs.io/en/latest/api.html>`_.
|
|
||||||
|
|
||||||
All general BPF questions, including kernel functionality, libbpf APIs and
|
All general BPF questions, including kernel functionality, libbpf APIs and
|
||||||
their application, should be sent to bpf@vger.kernel.org mailing list.
|
their application, should be sent to bpf@vger.kernel.org mailing list.
|
||||||
You can `subscribe <http://vger.kernel.org/vger-lists.html#bpf>`_ to the
|
You can `subscribe <http://vger.kernel.org/vger-lists.html#bpf>`_ to the
|
||||||
|
|||||||
@@ -997,6 +997,8 @@ enum bpf_attach_type {
|
|||||||
BPF_SK_REUSEPORT_SELECT,
|
BPF_SK_REUSEPORT_SELECT,
|
||||||
BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
|
BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
|
||||||
BPF_PERF_EVENT,
|
BPF_PERF_EVENT,
|
||||||
|
BPF_TRACE_KPROBE_MULTI,
|
||||||
|
BPF_LSM_CGROUP,
|
||||||
__MAX_BPF_ATTACH_TYPE
|
__MAX_BPF_ATTACH_TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1011,6 +1013,8 @@ enum bpf_link_type {
|
|||||||
BPF_LINK_TYPE_NETNS = 5,
|
BPF_LINK_TYPE_NETNS = 5,
|
||||||
BPF_LINK_TYPE_XDP = 6,
|
BPF_LINK_TYPE_XDP = 6,
|
||||||
BPF_LINK_TYPE_PERF_EVENT = 7,
|
BPF_LINK_TYPE_PERF_EVENT = 7,
|
||||||
|
BPF_LINK_TYPE_KPROBE_MULTI = 8,
|
||||||
|
BPF_LINK_TYPE_STRUCT_OPS = 9,
|
||||||
|
|
||||||
MAX_BPF_LINK_TYPE,
|
MAX_BPF_LINK_TYPE,
|
||||||
};
|
};
|
||||||
@@ -1118,6 +1122,11 @@ enum bpf_link_type {
|
|||||||
*/
|
*/
|
||||||
#define BPF_F_XDP_HAS_FRAGS (1U << 5)
|
#define BPF_F_XDP_HAS_FRAGS (1U << 5)
|
||||||
|
|
||||||
|
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
|
||||||
|
* BPF_TRACE_KPROBE_MULTI attach type to create return probe.
|
||||||
|
*/
|
||||||
|
#define BPF_F_KPROBE_MULTI_RETURN (1U << 0)
|
||||||
|
|
||||||
/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
|
/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
|
||||||
* the following extensions:
|
* the following extensions:
|
||||||
*
|
*
|
||||||
@@ -1232,6 +1241,8 @@ enum {
|
|||||||
|
|
||||||
/* If set, run the test on the cpu specified by bpf_attr.test.cpu */
|
/* If set, run the test on the cpu specified by bpf_attr.test.cpu */
|
||||||
#define BPF_F_TEST_RUN_ON_CPU (1U << 0)
|
#define BPF_F_TEST_RUN_ON_CPU (1U << 0)
|
||||||
|
/* If set, XDP frames will be transmitted after processing */
|
||||||
|
#define BPF_F_TEST_XDP_LIVE_FRAMES (1U << 1)
|
||||||
|
|
||||||
/* type for BPF_ENABLE_STATS */
|
/* type for BPF_ENABLE_STATS */
|
||||||
enum bpf_stats_type {
|
enum bpf_stats_type {
|
||||||
@@ -1393,6 +1404,7 @@ union bpf_attr {
|
|||||||
__aligned_u64 ctx_out;
|
__aligned_u64 ctx_out;
|
||||||
__u32 flags;
|
__u32 flags;
|
||||||
__u32 cpu;
|
__u32 cpu;
|
||||||
|
__u32 batch_size;
|
||||||
} test;
|
} test;
|
||||||
|
|
||||||
struct { /* anonymous struct used by BPF_*_GET_*_ID */
|
struct { /* anonymous struct used by BPF_*_GET_*_ID */
|
||||||
@@ -1420,6 +1432,7 @@ union bpf_attr {
|
|||||||
__u32 attach_flags;
|
__u32 attach_flags;
|
||||||
__aligned_u64 prog_ids;
|
__aligned_u64 prog_ids;
|
||||||
__u32 prog_cnt;
|
__u32 prog_cnt;
|
||||||
|
__aligned_u64 prog_attach_flags; /* output: per-program attach_flags */
|
||||||
} query;
|
} query;
|
||||||
|
|
||||||
struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
|
struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
|
||||||
@@ -1472,6 +1485,22 @@ union bpf_attr {
|
|||||||
*/
|
*/
|
||||||
__u64 bpf_cookie;
|
__u64 bpf_cookie;
|
||||||
} perf_event;
|
} perf_event;
|
||||||
|
struct {
|
||||||
|
__u32 flags;
|
||||||
|
__u32 cnt;
|
||||||
|
__aligned_u64 syms;
|
||||||
|
__aligned_u64 addrs;
|
||||||
|
__aligned_u64 cookies;
|
||||||
|
} kprobe_multi;
|
||||||
|
struct {
|
||||||
|
/* this is overlaid with the target_btf_id above. */
|
||||||
|
__u32 target_btf_id;
|
||||||
|
/* black box user-provided value passed through
|
||||||
|
* to BPF program at the execution time and
|
||||||
|
* accessible through bpf_get_attach_cookie() BPF helper
|
||||||
|
*/
|
||||||
|
__u64 cookie;
|
||||||
|
} tracing;
|
||||||
};
|
};
|
||||||
} link_create;
|
} link_create;
|
||||||
|
|
||||||
@@ -2299,8 +2328,8 @@ union bpf_attr {
|
|||||||
* Return
|
* Return
|
||||||
* The return value depends on the result of the test, and can be:
|
* The return value depends on the result of the test, and can be:
|
||||||
*
|
*
|
||||||
* * 0, if current task belongs to the cgroup2.
|
* * 1, if current task belongs to the cgroup2.
|
||||||
* * 1, if current task does not belong to the cgroup2.
|
* * 0, if current task does not belong to the cgroup2.
|
||||||
* * A negative error code, if an error occurred.
|
* * A negative error code, if an error occurred.
|
||||||
*
|
*
|
||||||
* long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
|
* long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
|
||||||
@@ -2992,8 +3021,8 @@ union bpf_attr {
|
|||||||
*
|
*
|
||||||
* # sysctl kernel.perf_event_max_stack=<new value>
|
* # sysctl kernel.perf_event_max_stack=<new value>
|
||||||
* Return
|
* Return
|
||||||
* A non-negative value equal to or less than *size* on success,
|
* The non-negative copied *buf* length equal to or less than
|
||||||
* or a negative error in case of failure.
|
* *size* on success, or a negative error in case of failure.
|
||||||
*
|
*
|
||||||
* long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
|
* long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
|
||||||
* Description
|
* Description
|
||||||
@@ -3570,10 +3599,11 @@ union bpf_attr {
|
|||||||
*
|
*
|
||||||
* *iph* points to the start of the IPv4 or IPv6 header, while
|
* *iph* points to the start of the IPv4 or IPv6 header, while
|
||||||
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
||||||
* **sizeof**\ (**struct ip6hdr**).
|
* **sizeof**\ (**struct ipv6hdr**).
|
||||||
*
|
*
|
||||||
* *th* points to the start of the TCP header, while *th_len*
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
* contains **sizeof**\ (**struct tcphdr**).
|
* contains the length of the TCP header (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
* Return
|
* Return
|
||||||
* 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
|
* 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
|
||||||
* error otherwise.
|
* error otherwise.
|
||||||
@@ -3756,10 +3786,11 @@ union bpf_attr {
|
|||||||
*
|
*
|
||||||
* *iph* points to the start of the IPv4 or IPv6 header, while
|
* *iph* points to the start of the IPv4 or IPv6 header, while
|
||||||
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
||||||
* **sizeof**\ (**struct ip6hdr**).
|
* **sizeof**\ (**struct ipv6hdr**).
|
||||||
*
|
*
|
||||||
* *th* points to the start of the TCP header, while *th_len*
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
* contains the length of the TCP header.
|
* contains the length of the TCP header with options (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
* Return
|
* Return
|
||||||
* On success, lower 32 bits hold the generated SYN cookie in
|
* On success, lower 32 bits hold the generated SYN cookie in
|
||||||
* followed by 16 bits which hold the MSS value for that cookie,
|
* followed by 16 bits which hold the MSS value for that cookie,
|
||||||
@@ -4299,8 +4330,8 @@ union bpf_attr {
|
|||||||
*
|
*
|
||||||
* # sysctl kernel.perf_event_max_stack=<new value>
|
* # sysctl kernel.perf_event_max_stack=<new value>
|
||||||
* Return
|
* Return
|
||||||
* A non-negative value equal to or less than *size* on success,
|
* The non-negative copied *buf* length equal to or less than
|
||||||
* or a negative error in case of failure.
|
* *size* on success, or a negative error in case of failure.
|
||||||
*
|
*
|
||||||
* long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
|
* long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
|
||||||
* Description
|
* Description
|
||||||
@@ -5086,6 +5117,216 @@ union bpf_attr {
|
|||||||
* Return
|
* Return
|
||||||
* 0 on success, or a negative error in case of failure. On error
|
* 0 on success, or a negative error in case of failure. On error
|
||||||
* *dst* buffer is zeroed out.
|
* *dst* buffer is zeroed out.
|
||||||
|
*
|
||||||
|
* long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)
|
||||||
|
* Description
|
||||||
|
* Change the __sk_buff->tstamp_type to *tstamp_type*
|
||||||
|
* and set *tstamp* to the __sk_buff->tstamp together.
|
||||||
|
*
|
||||||
|
* If there is no need to change the __sk_buff->tstamp_type,
|
||||||
|
* the tstamp value can be directly written to __sk_buff->tstamp
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
|
||||||
|
* will be kept during bpf_redirect_*(). A non zero
|
||||||
|
* *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
|
||||||
|
* *tstamp_type*.
|
||||||
|
*
|
||||||
|
* A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
|
||||||
|
* with a zero *tstamp*.
|
||||||
|
*
|
||||||
|
* Only IPv4 and IPv6 skb->protocol are supported.
|
||||||
|
*
|
||||||
|
* This function is most useful when it needs to set a
|
||||||
|
* mono delivery time to __sk_buff->tstamp and then
|
||||||
|
* bpf_redirect_*() to the egress of an iface. For example,
|
||||||
|
* changing the (rcv) timestamp in __sk_buff->tstamp at
|
||||||
|
* ingress to a mono delivery time and then bpf_redirect_*()
|
||||||
|
* to sch_fq@phy-dev.
|
||||||
|
* Return
|
||||||
|
* 0 on success.
|
||||||
|
* **-EINVAL** for invalid input
|
||||||
|
* **-EOPNOTSUPP** for unsupported protocol
|
||||||
|
*
|
||||||
|
* long bpf_ima_file_hash(struct file *file, void *dst, u32 size)
|
||||||
|
* Description
|
||||||
|
* Returns a calculated IMA hash of the *file*.
|
||||||
|
* If the hash is larger than *size*, then only *size*
|
||||||
|
* bytes will be copied to *dst*
|
||||||
|
* Return
|
||||||
|
* The **hash_algo** is returned on success,
|
||||||
|
* **-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if
|
||||||
|
* invalid arguments are passed.
|
||||||
|
*
|
||||||
|
* void *bpf_kptr_xchg(void *map_value, void *ptr)
|
||||||
|
* Description
|
||||||
|
* Exchange kptr at pointer *map_value* with *ptr*, and return the
|
||||||
|
* old value. *ptr* can be NULL, otherwise it must be a referenced
|
||||||
|
* pointer which will be released when this helper is called.
|
||||||
|
* Return
|
||||||
|
* The old value of kptr (which can be NULL). The returned pointer
|
||||||
|
* if not NULL, is a reference which must be released using its
|
||||||
|
* corresponding release function, or moved into a BPF map before
|
||||||
|
* program exit.
|
||||||
|
*
|
||||||
|
* void *bpf_map_lookup_percpu_elem(struct bpf_map *map, const void *key, u32 cpu)
|
||||||
|
* Description
|
||||||
|
* Perform a lookup in *percpu map* for an entry associated to
|
||||||
|
* *key* on *cpu*.
|
||||||
|
* Return
|
||||||
|
* Map value associated to *key* on *cpu*, or **NULL** if no entry
|
||||||
|
* was found or *cpu* is invalid.
|
||||||
|
*
|
||||||
|
* struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk)
|
||||||
|
* Description
|
||||||
|
* Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
|
||||||
|
* Return
|
||||||
|
* *sk* if casting is valid, or **NULL** otherwise.
|
||||||
|
*
|
||||||
|
* long bpf_dynptr_from_mem(void *data, u32 size, u64 flags, struct bpf_dynptr *ptr)
|
||||||
|
* Description
|
||||||
|
* Get a dynptr to local memory *data*.
|
||||||
|
*
|
||||||
|
* *data* must be a ptr to a map value.
|
||||||
|
* The maximum *size* supported is DYNPTR_MAX_SIZE.
|
||||||
|
* *flags* is currently unused.
|
||||||
|
* Return
|
||||||
|
* 0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
|
||||||
|
* -EINVAL if flags is not 0.
|
||||||
|
*
|
||||||
|
* long bpf_ringbuf_reserve_dynptr(void *ringbuf, u32 size, u64 flags, struct bpf_dynptr *ptr)
|
||||||
|
* Description
|
||||||
|
* Reserve *size* bytes of payload in a ring buffer *ringbuf*
|
||||||
|
* through the dynptr interface. *flags* must be 0.
|
||||||
|
*
|
||||||
|
* Please note that a corresponding bpf_ringbuf_submit_dynptr or
|
||||||
|
* bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the
|
||||||
|
* reservation fails. This is enforced by the verifier.
|
||||||
|
* Return
|
||||||
|
* 0 on success, or a negative error in case of failure.
|
||||||
|
*
|
||||||
|
* void bpf_ringbuf_submit_dynptr(struct bpf_dynptr *ptr, u64 flags)
|
||||||
|
* Description
|
||||||
|
* Submit reserved ring buffer sample, pointed to by *data*,
|
||||||
|
* through the dynptr interface. This is a no-op if the dynptr is
|
||||||
|
* invalid/null.
|
||||||
|
*
|
||||||
|
* For more information on *flags*, please see
|
||||||
|
* 'bpf_ringbuf_submit'.
|
||||||
|
* Return
|
||||||
|
* Nothing. Always succeeds.
|
||||||
|
*
|
||||||
|
* void bpf_ringbuf_discard_dynptr(struct bpf_dynptr *ptr, u64 flags)
|
||||||
|
* Description
|
||||||
|
* Discard reserved ring buffer sample through the dynptr
|
||||||
|
* interface. This is a no-op if the dynptr is invalid/null.
|
||||||
|
*
|
||||||
|
* For more information on *flags*, please see
|
||||||
|
* 'bpf_ringbuf_discard'.
|
||||||
|
* Return
|
||||||
|
* Nothing. Always succeeds.
|
||||||
|
*
|
||||||
|
* long bpf_dynptr_read(void *dst, u32 len, struct bpf_dynptr *src, u32 offset)
|
||||||
|
* Description
|
||||||
|
* Read *len* bytes from *src* into *dst*, starting from *offset*
|
||||||
|
* into *src*.
|
||||||
|
* Return
|
||||||
|
* 0 on success, -E2BIG if *offset* + *len* exceeds the length
|
||||||
|
* of *src*'s data, -EINVAL if *src* is an invalid dynptr.
|
||||||
|
*
|
||||||
|
* long bpf_dynptr_write(struct bpf_dynptr *dst, u32 offset, void *src, u32 len)
|
||||||
|
* Description
|
||||||
|
* Write *len* bytes from *src* into *dst*, starting from *offset*
|
||||||
|
* into *dst*.
|
||||||
|
* Return
|
||||||
|
* 0 on success, -E2BIG if *offset* + *len* exceeds the length
|
||||||
|
* of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
|
||||||
|
* is a read-only dynptr.
|
||||||
|
*
|
||||||
|
* void *bpf_dynptr_data(struct bpf_dynptr *ptr, u32 offset, u32 len)
|
||||||
|
* Description
|
||||||
|
* Get a pointer to the underlying dynptr data.
|
||||||
|
*
|
||||||
|
* *len* must be a statically known value. The returned data slice
|
||||||
|
* is invalidated whenever the dynptr is invalidated.
|
||||||
|
* Return
|
||||||
|
* Pointer to the underlying dynptr data, NULL if the dynptr is
|
||||||
|
* read-only, if the dynptr is invalid, or if the offset and length
|
||||||
|
* is out of bounds.
|
||||||
|
*
|
||||||
|
* s64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th, u32 th_len)
|
||||||
|
* Description
|
||||||
|
* Try to issue a SYN cookie for the packet with corresponding
|
||||||
|
* IPv4/TCP headers, *iph* and *th*, without depending on a
|
||||||
|
* listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv4 header.
|
||||||
|
*
|
||||||
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
|
* contains the length of the TCP header (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
|
* Return
|
||||||
|
* On success, lower 32 bits hold the generated SYN cookie in
|
||||||
|
* followed by 16 bits which hold the MSS value for that cookie,
|
||||||
|
* and the top 16 bits are unused.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EINVAL** if *th_len* is invalid.
|
||||||
|
*
|
||||||
|
* s64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th, u32 th_len)
|
||||||
|
* Description
|
||||||
|
* Try to issue a SYN cookie for the packet with corresponding
|
||||||
|
* IPv6/TCP headers, *iph* and *th*, without depending on a
|
||||||
|
* listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv6 header.
|
||||||
|
*
|
||||||
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
|
* contains the length of the TCP header (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
|
* Return
|
||||||
|
* On success, lower 32 bits hold the generated SYN cookie in
|
||||||
|
* followed by 16 bits which hold the MSS value for that cookie,
|
||||||
|
* and the top 16 bits are unused.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EINVAL** if *th_len* is invalid.
|
||||||
|
*
|
||||||
|
* **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
|
||||||
|
*
|
||||||
|
* long bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th)
|
||||||
|
* Description
|
||||||
|
* Check whether *iph* and *th* contain a valid SYN cookie ACK
|
||||||
|
* without depending on a listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv4 header.
|
||||||
|
*
|
||||||
|
* *th* points to the TCP header.
|
||||||
|
* Return
|
||||||
|
* 0 if *iph* and *th* are a valid SYN cookie ACK.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EACCES** if the SYN cookie is not valid.
|
||||||
|
*
|
||||||
|
* long bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th)
|
||||||
|
* Description
|
||||||
|
* Check whether *iph* and *th* contain a valid SYN cookie ACK
|
||||||
|
* without depending on a listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv6 header.
|
||||||
|
*
|
||||||
|
* *th* points to the TCP header.
|
||||||
|
* Return
|
||||||
|
* 0 if *iph* and *th* are a valid SYN cookie ACK.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EACCES** if the SYN cookie is not valid.
|
||||||
|
*
|
||||||
|
* **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
|
||||||
*/
|
*/
|
||||||
#define __BPF_FUNC_MAPPER(FN) \
|
#define __BPF_FUNC_MAPPER(FN) \
|
||||||
FN(unspec), \
|
FN(unspec), \
|
||||||
@@ -5280,6 +5521,22 @@ union bpf_attr {
|
|||||||
FN(xdp_load_bytes), \
|
FN(xdp_load_bytes), \
|
||||||
FN(xdp_store_bytes), \
|
FN(xdp_store_bytes), \
|
||||||
FN(copy_from_user_task), \
|
FN(copy_from_user_task), \
|
||||||
|
FN(skb_set_tstamp), \
|
||||||
|
FN(ima_file_hash), \
|
||||||
|
FN(kptr_xchg), \
|
||||||
|
FN(map_lookup_percpu_elem), \
|
||||||
|
FN(skc_to_mptcp_sock), \
|
||||||
|
FN(dynptr_from_mem), \
|
||||||
|
FN(ringbuf_reserve_dynptr), \
|
||||||
|
FN(ringbuf_submit_dynptr), \
|
||||||
|
FN(ringbuf_discard_dynptr), \
|
||||||
|
FN(dynptr_read), \
|
||||||
|
FN(dynptr_write), \
|
||||||
|
FN(dynptr_data), \
|
||||||
|
FN(tcp_raw_gen_syncookie_ipv4), \
|
||||||
|
FN(tcp_raw_gen_syncookie_ipv6), \
|
||||||
|
FN(tcp_raw_check_syncookie_ipv4), \
|
||||||
|
FN(tcp_raw_check_syncookie_ipv6), \
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
||||||
@@ -5469,6 +5726,15 @@ union { \
|
|||||||
__u64 :64; \
|
__u64 :64; \
|
||||||
} __attribute__((aligned(8)))
|
} __attribute__((aligned(8)))
|
||||||
|
|
||||||
|
enum {
|
||||||
|
BPF_SKB_TSTAMP_UNSPEC,
|
||||||
|
BPF_SKB_TSTAMP_DELIVERY_MONO, /* tstamp has mono delivery time */
|
||||||
|
/* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle,
|
||||||
|
* the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC
|
||||||
|
* and try to deduce it by ingress, egress or skb->sk->sk_clockid.
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
/* user accessible mirror of in-kernel sk_buff.
|
/* user accessible mirror of in-kernel sk_buff.
|
||||||
* new fields can only be added to the end of this structure
|
* new fields can only be added to the end of this structure
|
||||||
*/
|
*/
|
||||||
@@ -5509,7 +5775,8 @@ struct __sk_buff {
|
|||||||
__u32 gso_segs;
|
__u32 gso_segs;
|
||||||
__bpf_md_ptr(struct bpf_sock *, sk);
|
__bpf_md_ptr(struct bpf_sock *, sk);
|
||||||
__u32 gso_size;
|
__u32 gso_size;
|
||||||
__u32 :32; /* Padding, future use. */
|
__u8 tstamp_type;
|
||||||
|
__u32 :24; /* Padding, future use. */
|
||||||
__u64 hwtstamp;
|
__u64 hwtstamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5523,6 +5790,10 @@ struct bpf_tunnel_key {
|
|||||||
__u8 tunnel_ttl;
|
__u8 tunnel_ttl;
|
||||||
__u16 tunnel_ext; /* Padding, future use. */
|
__u16 tunnel_ext; /* Padding, future use. */
|
||||||
__u32 tunnel_label;
|
__u32 tunnel_label;
|
||||||
|
union {
|
||||||
|
__u32 local_ipv4;
|
||||||
|
__u32 local_ipv6[4];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* user accessible mirror of in-kernel xfrm_state.
|
/* user accessible mirror of in-kernel xfrm_state.
|
||||||
@@ -5806,6 +6077,8 @@ struct bpf_prog_info {
|
|||||||
__u64 run_cnt;
|
__u64 run_cnt;
|
||||||
__u64 recursion_misses;
|
__u64 recursion_misses;
|
||||||
__u32 verified_insns;
|
__u32 verified_insns;
|
||||||
|
__u32 attach_btf_obj_id;
|
||||||
|
__u32 attach_btf_id;
|
||||||
} __attribute__((aligned(8)));
|
} __attribute__((aligned(8)));
|
||||||
|
|
||||||
struct bpf_map_info {
|
struct bpf_map_info {
|
||||||
@@ -6417,6 +6690,11 @@ struct bpf_timer {
|
|||||||
__u64 :64;
|
__u64 :64;
|
||||||
} __attribute__((aligned(8)));
|
} __attribute__((aligned(8)));
|
||||||
|
|
||||||
|
struct bpf_dynptr {
|
||||||
|
__u64 :64;
|
||||||
|
__u64 :64;
|
||||||
|
} __attribute__((aligned(8)));
|
||||||
|
|
||||||
struct bpf_sysctl {
|
struct bpf_sysctl {
|
||||||
__u32 write; /* Sysctl is being read (= 0) or written (= 1).
|
__u32 write; /* Sysctl is being read (= 0) or written (= 1).
|
||||||
* Allows 1,2,4-byte read, but no write.
|
* Allows 1,2,4-byte read, but no write.
|
||||||
@@ -6453,7 +6731,8 @@ struct bpf_sk_lookup {
|
|||||||
__u32 protocol; /* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
|
__u32 protocol; /* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
|
||||||
__u32 remote_ip4; /* Network byte order */
|
__u32 remote_ip4; /* Network byte order */
|
||||||
__u32 remote_ip6[4]; /* Network byte order */
|
__u32 remote_ip6[4]; /* Network byte order */
|
||||||
__u32 remote_port; /* Network byte order */
|
__be16 remote_port; /* Network byte order */
|
||||||
|
__u16 :16; /* Zero padding */
|
||||||
__u32 local_ip4; /* Network byte order */
|
__u32 local_ip4; /* Network byte order */
|
||||||
__u32 local_ip6[4]; /* Network byte order */
|
__u32 local_ip6[4]; /* Network byte order */
|
||||||
__u32 local_port; /* Host byte order */
|
__u32 local_port; /* Host byte order */
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ struct btf_type {
|
|||||||
/* "info" bits arrangement
|
/* "info" bits arrangement
|
||||||
* bits 0-15: vlen (e.g. # of struct's members)
|
* bits 0-15: vlen (e.g. # of struct's members)
|
||||||
* bits 16-23: unused
|
* bits 16-23: unused
|
||||||
* bits 24-27: kind (e.g. int, ptr, array...etc)
|
* bits 24-28: kind (e.g. int, ptr, array...etc)
|
||||||
* bits 28-30: unused
|
* bits 29-30: unused
|
||||||
* bit 31: kind_flag, currently used by
|
* bit 31: kind_flag, currently used by
|
||||||
* struct, union and fwd
|
* struct, union, enum, fwd and enum64
|
||||||
*/
|
*/
|
||||||
__u32 info;
|
__u32 info;
|
||||||
/* "size" is used by INT, ENUM, STRUCT, UNION and DATASEC.
|
/* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64.
|
||||||
* "size" tells the size of the type it is describing.
|
* "size" tells the size of the type it is describing.
|
||||||
*
|
*
|
||||||
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
|
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
|
||||||
@@ -63,7 +63,7 @@ enum {
|
|||||||
BTF_KIND_ARRAY = 3, /* Array */
|
BTF_KIND_ARRAY = 3, /* Array */
|
||||||
BTF_KIND_STRUCT = 4, /* Struct */
|
BTF_KIND_STRUCT = 4, /* Struct */
|
||||||
BTF_KIND_UNION = 5, /* Union */
|
BTF_KIND_UNION = 5, /* Union */
|
||||||
BTF_KIND_ENUM = 6, /* Enumeration */
|
BTF_KIND_ENUM = 6, /* Enumeration up to 32-bit values */
|
||||||
BTF_KIND_FWD = 7, /* Forward */
|
BTF_KIND_FWD = 7, /* Forward */
|
||||||
BTF_KIND_TYPEDEF = 8, /* Typedef */
|
BTF_KIND_TYPEDEF = 8, /* Typedef */
|
||||||
BTF_KIND_VOLATILE = 9, /* Volatile */
|
BTF_KIND_VOLATILE = 9, /* Volatile */
|
||||||
@@ -76,6 +76,7 @@ enum {
|
|||||||
BTF_KIND_FLOAT = 16, /* Floating point */
|
BTF_KIND_FLOAT = 16, /* Floating point */
|
||||||
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
|
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
|
||||||
BTF_KIND_TYPE_TAG = 18, /* Type Tag */
|
BTF_KIND_TYPE_TAG = 18, /* Type Tag */
|
||||||
|
BTF_KIND_ENUM64 = 19, /* Enumeration up to 64-bit values */
|
||||||
|
|
||||||
NR_BTF_KINDS,
|
NR_BTF_KINDS,
|
||||||
BTF_KIND_MAX = NR_BTF_KINDS - 1,
|
BTF_KIND_MAX = NR_BTF_KINDS - 1,
|
||||||
@@ -186,4 +187,14 @@ struct btf_decl_tag {
|
|||||||
__s32 component_idx;
|
__s32 component_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* BTF_KIND_ENUM64 is followed by multiple "struct btf_enum64".
|
||||||
|
* The exact number of btf_enum64 is stored in the vlen (of the
|
||||||
|
* info in "struct btf_type").
|
||||||
|
*/
|
||||||
|
struct btf_enum64 {
|
||||||
|
__u32 name_off;
|
||||||
|
__u32 val_lo32;
|
||||||
|
__u32 val_hi32;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* _UAPI__LINUX_BTF_H__ */
|
#endif /* _UAPI__LINUX_BTF_H__ */
|
||||||
|
|||||||
@@ -348,6 +348,8 @@ enum {
|
|||||||
IFLA_PARENT_DEV_NAME,
|
IFLA_PARENT_DEV_NAME,
|
||||||
IFLA_PARENT_DEV_BUS_NAME,
|
IFLA_PARENT_DEV_BUS_NAME,
|
||||||
IFLA_GRO_MAX_SIZE,
|
IFLA_GRO_MAX_SIZE,
|
||||||
|
IFLA_TSO_MAX_SIZE,
|
||||||
|
IFLA_TSO_MAX_SEGS,
|
||||||
|
|
||||||
__IFLA_MAX
|
__IFLA_MAX
|
||||||
};
|
};
|
||||||
@@ -860,6 +862,7 @@ enum {
|
|||||||
IFLA_BOND_PEER_NOTIF_DELAY,
|
IFLA_BOND_PEER_NOTIF_DELAY,
|
||||||
IFLA_BOND_AD_LACP_ACTIVE,
|
IFLA_BOND_AD_LACP_ACTIVE,
|
||||||
IFLA_BOND_MISSED_MAX,
|
IFLA_BOND_MISSED_MAX,
|
||||||
|
IFLA_BOND_NS_IP6_TARGET,
|
||||||
__IFLA_BOND_MAX,
|
__IFLA_BOND_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -251,6 +251,8 @@ enum {
|
|||||||
PERF_BR_SYSRET = 8, /* syscall return */
|
PERF_BR_SYSRET = 8, /* syscall return */
|
||||||
PERF_BR_COND_CALL = 9, /* conditional function call */
|
PERF_BR_COND_CALL = 9, /* conditional function call */
|
||||||
PERF_BR_COND_RET = 10, /* conditional function return */
|
PERF_BR_COND_RET = 10, /* conditional function return */
|
||||||
|
PERF_BR_ERET = 11, /* exception return */
|
||||||
|
PERF_BR_IRQ = 12, /* irq */
|
||||||
PERF_BR_MAX,
|
PERF_BR_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -465,6 +467,8 @@ struct perf_event_attr {
|
|||||||
/*
|
/*
|
||||||
* User provided data if sigtrap=1, passed back to user via
|
* User provided data if sigtrap=1, passed back to user via
|
||||||
* siginfo_t::si_perf_data, e.g. to permit user to identify the event.
|
* siginfo_t::si_perf_data, e.g. to permit user to identify the event.
|
||||||
|
* Note, siginfo_t::si_perf_data is long-sized, and sig_data will be
|
||||||
|
* truncated accordingly on 32 bit architectures.
|
||||||
*/
|
*/
|
||||||
__u64 sig_data;
|
__u64 sig_data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,6 +17,24 @@ mkdir -p "$OUT"
|
|||||||
|
|
||||||
export LIB_FUZZING_ENGINE=${LIB_FUZZING_ENGINE:--fsanitize=fuzzer}
|
export LIB_FUZZING_ENGINE=${LIB_FUZZING_ENGINE:--fsanitize=fuzzer}
|
||||||
|
|
||||||
|
# libelf is compiled with _FORTIFY_SOURCE by default and it
|
||||||
|
# isn't compatible with MSan. It was borrowed
|
||||||
|
# from https://github.com/google/oss-fuzz/pull/7422
|
||||||
|
if [[ "$SANITIZER" == memory ]]; then
|
||||||
|
CFLAGS+=" -U_FORTIFY_SOURCE"
|
||||||
|
CXXFLAGS+=" -U_FORTIFY_SOURCE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# The alignment check is turned off by default on OSS-Fuzz/CFLite so it should be
|
||||||
|
# turned on explicitly there. It was borrowed from
|
||||||
|
# https://github.com/google/oss-fuzz/pull/7092
|
||||||
|
if [[ "$SANITIZER" == undefined ]]; then
|
||||||
|
additional_ubsan_checks=alignment
|
||||||
|
UBSAN_FLAGS="-fsanitize=$additional_ubsan_checks -fno-sanitize-recover=$additional_ubsan_checks"
|
||||||
|
CFLAGS+=" $UBSAN_FLAGS"
|
||||||
|
CXXFLAGS+=" $UBSAN_FLAGS"
|
||||||
|
fi
|
||||||
|
|
||||||
# Ideally libbelf should be built using release tarballs available
|
# Ideally libbelf should be built using release tarballs available
|
||||||
# at https://sourceware.org/elfutils/ftp/. Unfortunately sometimes they
|
# at https://sourceware.org/elfutils/ftp/. Unfortunately sometimes they
|
||||||
# fail to compile (for example, elfutils-0.185 fails to compile with LDFLAGS enabled
|
# fail to compile (for example, elfutils-0.185 fails to compile with LDFLAGS enabled
|
||||||
@@ -26,7 +44,7 @@ rm -rf elfutils
|
|||||||
git clone git://sourceware.org/git/elfutils.git
|
git clone git://sourceware.org/git/elfutils.git
|
||||||
(
|
(
|
||||||
cd elfutils
|
cd elfutils
|
||||||
git checkout 983e86fd89e8bf02f2d27ba5dce5bf078af4ceda
|
git checkout 83251d4091241acddbdcf16f814e3bc6ef3df49a
|
||||||
git log --oneline -1
|
git log --oneline -1
|
||||||
|
|
||||||
# ASan isn't compatible with -Wl,--no-undefined: https://github.com/google/sanitizers/issues/380
|
# ASan isn't compatible with -Wl,--no-undefined: https://github.com/google/sanitizers/issues/380
|
||||||
@@ -36,6 +54,11 @@ find -name Makefile.am | xargs sed -i 's/,--no-undefined//'
|
|||||||
# https://clang.llvm.org/docs/AddressSanitizer.html#usage
|
# https://clang.llvm.org/docs/AddressSanitizer.html#usage
|
||||||
sed -i 's/^\(ZDEFS_LDFLAGS=\).*/\1/' configure.ac
|
sed -i 's/^\(ZDEFS_LDFLAGS=\).*/\1/' configure.ac
|
||||||
|
|
||||||
|
if [[ "$SANITIZER" == undefined ]]; then
|
||||||
|
# That's basicaly what --enable-sanitize-undefined does to turn off unaligned access
|
||||||
|
# elfutils heavily relies on on i386/x86_64 but without changing compiler flags along the way
|
||||||
|
sed -i 's/\(check_undefined_val\)=[0-9]/\1=1/' configure.ac
|
||||||
|
fi
|
||||||
|
|
||||||
autoreconf -i -f
|
autoreconf -i -f
|
||||||
if ! ./configure --enable-maintainer-mode --disable-debuginfod --disable-libdebuginfod \
|
if ! ./configure --enable-maintainer-mode --disable-debuginfod --disable-libdebuginfod \
|
||||||
|
|||||||
42
src/Makefile
42
src/Makefile
@@ -8,10 +8,24 @@ else
|
|||||||
msg = @printf ' %-8s %s%s\n' "$(1)" "$(2)" "$(if $(3), $(3))";
|
msg = @printf ' %-8s %s%s\n' "$(1)" "$(2)" "$(if $(3), $(3))";
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIBBPF_VERSION := $(shell \
|
LIBBPF_MAJOR_VERSION := 1
|
||||||
grep -oE '^LIBBPF_([0-9.]+)' libbpf.map | \
|
LIBBPF_MINOR_VERSION := 0
|
||||||
sort -rV | head -n1 | cut -d'_' -f2)
|
LIBBPF_PATCH_VERSION := 0
|
||||||
LIBBPF_MAJOR_VERSION := $(firstword $(subst ., ,$(LIBBPF_VERSION)))
|
LIBBPF_VERSION := $(LIBBPF_MAJOR_VERSION).$(LIBBPF_MINOR_VERSION).$(LIBBPF_PATCH_VERSION)
|
||||||
|
LIBBPF_MAJMIN_VERSION := $(LIBBPF_MAJOR_VERSION).$(LIBBPF_MINOR_VERSION).0
|
||||||
|
LIBBPF_MAP_VERSION := $(shell grep -oE '^LIBBPF_([0-9.]+)' libbpf.map | sort -rV | head -n1 | cut -d'_' -f2)
|
||||||
|
ifneq ($(LIBBPF_MAJMIN_VERSION), $(LIBBPF_MAP_VERSION))
|
||||||
|
$(error Libbpf release ($(LIBBPF_VERSION)) and map ($(LIBBPF_MAP_VERSION)) versions are out of sync!)
|
||||||
|
endif
|
||||||
|
|
||||||
|
define allow-override
|
||||||
|
$(if $(or $(findstring environment,$(origin $(1))),\
|
||||||
|
$(findstring command line,$(origin $(1)))),,\
|
||||||
|
$(eval $(1) = $(2)))
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(call allow-override,CC,$(CROSS_COMPILE)cc)
|
||||||
|
$(call allow-override,LD,$(CROSS_COMPILE)ld)
|
||||||
|
|
||||||
TOPDIR = ..
|
TOPDIR = ..
|
||||||
|
|
||||||
@@ -21,8 +35,9 @@ ALL_CFLAGS := $(INCLUDES)
|
|||||||
SHARED_CFLAGS += -fPIC -fvisibility=hidden -DSHARED
|
SHARED_CFLAGS += -fPIC -fvisibility=hidden -DSHARED
|
||||||
|
|
||||||
CFLAGS ?= -g -O2 -Werror -Wall -std=gnu89
|
CFLAGS ?= -g -O2 -Werror -Wall -std=gnu89
|
||||||
ALL_CFLAGS += $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
|
ALL_CFLAGS += $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 $(EXTRA_CFLAGS)
|
||||||
ALL_LDFLAGS += $(LDFLAGS)
|
ALL_LDFLAGS += $(LDFLAGS) $(EXTRA_LDFLAGS)
|
||||||
|
|
||||||
ifdef NO_PKG_CONFIG
|
ifdef NO_PKG_CONFIG
|
||||||
ALL_LDFLAGS += -lelf -lz
|
ALL_LDFLAGS += -lelf -lz
|
||||||
else
|
else
|
||||||
@@ -35,9 +50,9 @@ OBJDIR ?= .
|
|||||||
SHARED_OBJDIR := $(OBJDIR)/sharedobjs
|
SHARED_OBJDIR := $(OBJDIR)/sharedobjs
|
||||||
STATIC_OBJDIR := $(OBJDIR)/staticobjs
|
STATIC_OBJDIR := $(OBJDIR)/staticobjs
|
||||||
OBJS := bpf.o btf.o libbpf.o libbpf_errno.o netlink.o \
|
OBJS := bpf.o btf.o libbpf.o libbpf_errno.o netlink.o \
|
||||||
nlattr.o str_error.o libbpf_probes.o bpf_prog_linfo.o xsk.o \
|
nlattr.o str_error.o libbpf_probes.o bpf_prog_linfo.o \
|
||||||
btf_dump.o hashmap.o ringbuf.o strset.o linker.o gen_loader.o \
|
btf_dump.o hashmap.o ringbuf.o strset.o linker.o gen_loader.o \
|
||||||
relo_core.o
|
relo_core.o usdt.o
|
||||||
SHARED_OBJS := $(addprefix $(SHARED_OBJDIR)/,$(OBJS))
|
SHARED_OBJS := $(addprefix $(SHARED_OBJDIR)/,$(OBJS))
|
||||||
STATIC_OBJS := $(addprefix $(STATIC_OBJDIR)/,$(OBJS))
|
STATIC_OBJS := $(addprefix $(STATIC_OBJDIR)/,$(OBJS))
|
||||||
|
|
||||||
@@ -49,9 +64,10 @@ ifndef BUILD_STATIC_ONLY
|
|||||||
VERSION_SCRIPT := libbpf.map
|
VERSION_SCRIPT := libbpf.map
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HEADERS := bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h xsk.h \
|
HEADERS := bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h \
|
||||||
bpf_helpers.h bpf_helper_defs.h bpf_tracing.h \
|
bpf_helpers.h bpf_helper_defs.h bpf_tracing.h \
|
||||||
bpf_endian.h bpf_core_read.h skel_internal.h libbpf_version.h
|
bpf_endian.h bpf_core_read.h skel_internal.h libbpf_version.h \
|
||||||
|
usdt.bpf.h
|
||||||
UAPI_HEADERS := $(addprefix $(TOPDIR)/include/uapi/linux/,\
|
UAPI_HEADERS := $(addprefix $(TOPDIR)/include/uapi/linux/,\
|
||||||
bpf.h bpf_common.h btf.h)
|
bpf.h bpf_common.h btf.h)
|
||||||
|
|
||||||
@@ -99,7 +115,7 @@ $(OBJDIR)/libbpf.so.$(LIBBPF_VERSION): $(SHARED_OBJS)
|
|||||||
-Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
|
-Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
|
||||||
$^ $(ALL_LDFLAGS) -o $@
|
$^ $(ALL_LDFLAGS) -o $@
|
||||||
|
|
||||||
$(OBJDIR)/libbpf.pc:
|
$(OBJDIR)/libbpf.pc: force
|
||||||
$(Q)sed -e "s|@PREFIX@|$(PREFIX)|" \
|
$(Q)sed -e "s|@PREFIX@|$(PREFIX)|" \
|
||||||
-e "s|@LIBDIR@|$(LIBDIR_PC)|" \
|
-e "s|@LIBDIR@|$(LIBDIR_PC)|" \
|
||||||
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
|
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
|
||||||
@@ -152,7 +168,7 @@ clean:
|
|||||||
$(call msg,CLEAN)
|
$(call msg,CLEAN)
|
||||||
$(Q)rm -rf *.o *.a *.so *.so.* *.pc $(SHARED_OBJDIR) $(STATIC_OBJDIR)
|
$(Q)rm -rf *.o *.a *.so *.so.* *.pc $(SHARED_OBJDIR) $(STATIC_OBJDIR)
|
||||||
|
|
||||||
.PHONY: cscope tags
|
.PHONY: cscope tags force
|
||||||
cscope:
|
cscope:
|
||||||
$(call msg,CSCOPE)
|
$(call msg,CSCOPE)
|
||||||
$(Q)ls *.c *.h > cscope.files
|
$(Q)ls *.c *.h > cscope.files
|
||||||
@@ -162,3 +178,5 @@ tags:
|
|||||||
$(call msg,CTAGS)
|
$(call msg,CTAGS)
|
||||||
$(Q)rm -f TAGS tags
|
$(Q)rm -f TAGS tags
|
||||||
$(Q)ls *.c *.h | xargs $(TAGS_PROG) -a
|
$(Q)ls *.c *.h | xargs $(TAGS_PROG) -a
|
||||||
|
|
||||||
|
force:
|
||||||
|
|||||||
369
src/bpf.c
369
src/bpf.c
@@ -29,6 +29,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <linux/bpf.h>
|
#include <linux/bpf.h>
|
||||||
#include <linux/filter.h>
|
#include <linux/filter.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include "bpf.h"
|
#include "bpf.h"
|
||||||
@@ -111,7 +112,7 @@ int probe_memcg_account(void)
|
|||||||
BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
|
BPF_EMIT_CALL(BPF_FUNC_ktime_get_coarse_ns),
|
||||||
BPF_EXIT_INSN(),
|
BPF_EXIT_INSN(),
|
||||||
};
|
};
|
||||||
size_t insn_cnt = sizeof(insns) / sizeof(insns[0]);
|
size_t insn_cnt = ARRAY_SIZE(insns);
|
||||||
union bpf_attr attr;
|
union bpf_attr attr;
|
||||||
int prog_fd;
|
int prog_fd;
|
||||||
|
|
||||||
@@ -146,10 +147,6 @@ int bump_rlimit_memlock(void)
|
|||||||
{
|
{
|
||||||
struct rlimit rlim;
|
struct rlimit rlim;
|
||||||
|
|
||||||
/* this the default in libbpf 1.0, but for now user has to opt-in explicitly */
|
|
||||||
if (!(libbpf_mode & LIBBPF_STRICT_AUTO_RLIMIT_MEMLOCK))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* if kernel supports memcg-based accounting, skip bumping RLIMIT_MEMLOCK */
|
/* if kernel supports memcg-based accounting, skip bumping RLIMIT_MEMLOCK */
|
||||||
if (memlock_bumped || kernel_supports(NULL, FEAT_MEMCG_ACCOUNT))
|
if (memlock_bumped || kernel_supports(NULL, FEAT_MEMCG_ACCOUNT))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -207,86 +204,6 @@ int bpf_map_create(enum bpf_map_type map_type,
|
|||||||
return libbpf_err_errno(fd);
|
return libbpf_err_errno(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, p);
|
|
||||||
|
|
||||||
p.map_flags = create_attr->map_flags;
|
|
||||||
p.numa_node = create_attr->numa_node;
|
|
||||||
p.btf_fd = create_attr->btf_fd;
|
|
||||||
p.btf_key_type_id = create_attr->btf_key_type_id;
|
|
||||||
p.btf_value_type_id = create_attr->btf_value_type_id;
|
|
||||||
p.map_ifindex = create_attr->map_ifindex;
|
|
||||||
if (create_attr->map_type == BPF_MAP_TYPE_STRUCT_OPS)
|
|
||||||
p.btf_vmlinux_value_type_id = create_attr->btf_vmlinux_value_type_id;
|
|
||||||
else
|
|
||||||
p.inner_map_fd = create_attr->inner_map_fd;
|
|
||||||
|
|
||||||
return bpf_map_create(create_attr->map_type, create_attr->name,
|
|
||||||
create_attr->key_size, create_attr->value_size,
|
|
||||||
create_attr->max_entries, &p);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
|
|
||||||
int key_size, int value_size, int max_entries,
|
|
||||||
__u32 map_flags, int node)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, opts);
|
|
||||||
|
|
||||||
opts.map_flags = map_flags;
|
|
||||||
if (node >= 0) {
|
|
||||||
opts.numa_node = node;
|
|
||||||
opts.map_flags |= BPF_F_NUMA_NODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bpf_map_create(map_type, name, key_size, value_size, max_entries, &opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_create_map(enum bpf_map_type map_type, int key_size,
|
|
||||||
int value_size, int max_entries, __u32 map_flags)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = map_flags);
|
|
||||||
|
|
||||||
return bpf_map_create(map_type, NULL, key_size, value_size, max_entries, &opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
|
|
||||||
int key_size, int value_size, int max_entries,
|
|
||||||
__u32 map_flags)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = map_flags);
|
|
||||||
|
|
||||||
return bpf_map_create(map_type, name, key_size, value_size, max_entries, &opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name,
|
|
||||||
int key_size, int inner_map_fd, int max_entries,
|
|
||||||
__u32 map_flags, int node)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, opts);
|
|
||||||
|
|
||||||
opts.inner_map_fd = inner_map_fd;
|
|
||||||
opts.map_flags = map_flags;
|
|
||||||
if (node >= 0) {
|
|
||||||
opts.map_flags |= BPF_F_NUMA_NODE;
|
|
||||||
opts.numa_node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bpf_map_create(map_type, name, key_size, 4, max_entries, &opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name,
|
|
||||||
int key_size, int inner_map_fd, int max_entries,
|
|
||||||
__u32 map_flags)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, opts,
|
|
||||||
.inner_map_fd = inner_map_fd,
|
|
||||||
.map_flags = map_flags,
|
|
||||||
);
|
|
||||||
|
|
||||||
return bpf_map_create(map_type, name, key_size, 4, max_entries, &opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
alloc_zero_tailing_info(const void *orecord, __u32 cnt,
|
alloc_zero_tailing_info(const void *orecord, __u32 cnt,
|
||||||
__u32 actual_rec_size, __u32 expected_rec_size)
|
__u32 actual_rec_size, __u32 expected_rec_size)
|
||||||
@@ -312,11 +229,10 @@ alloc_zero_tailing_info(const void *orecord, __u32 cnt,
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_VERSION(bpf_prog_load_v0_6_0, bpf_prog_load, LIBBPF_0.6.0)
|
int bpf_prog_load(enum bpf_prog_type prog_type,
|
||||||
int bpf_prog_load_v0_6_0(enum bpf_prog_type prog_type,
|
const char *prog_name, const char *license,
|
||||||
const char *prog_name, const char *license,
|
const struct bpf_insn *insns, size_t insn_cnt,
|
||||||
const struct bpf_insn *insns, size_t insn_cnt,
|
const struct bpf_prog_load_opts *opts)
|
||||||
const struct bpf_prog_load_opts *opts)
|
|
||||||
{
|
{
|
||||||
void *finfo = NULL, *linfo = NULL;
|
void *finfo = NULL, *linfo = NULL;
|
||||||
const char *func_info, *line_info;
|
const char *func_info, *line_info;
|
||||||
@@ -463,94 +379,6 @@ done:
|
|||||||
return libbpf_err_errno(fd);
|
return libbpf_err_errno(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((alias("bpf_load_program_xattr2")))
|
|
||||||
int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
|
||||||
char *log_buf, size_t log_buf_sz);
|
|
||||||
|
|
||||||
static int bpf_load_program_xattr2(const struct bpf_load_program_attr *load_attr,
|
|
||||||
char *log_buf, size_t log_buf_sz)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_prog_load_opts, p);
|
|
||||||
|
|
||||||
if (!load_attr || !log_buf != !log_buf_sz)
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
|
|
||||||
p.expected_attach_type = load_attr->expected_attach_type;
|
|
||||||
switch (load_attr->prog_type) {
|
|
||||||
case BPF_PROG_TYPE_STRUCT_OPS:
|
|
||||||
case BPF_PROG_TYPE_LSM:
|
|
||||||
p.attach_btf_id = load_attr->attach_btf_id;
|
|
||||||
break;
|
|
||||||
case BPF_PROG_TYPE_TRACING:
|
|
||||||
case BPF_PROG_TYPE_EXT:
|
|
||||||
p.attach_btf_id = load_attr->attach_btf_id;
|
|
||||||
p.attach_prog_fd = load_attr->attach_prog_fd;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
p.prog_ifindex = load_attr->prog_ifindex;
|
|
||||||
p.kern_version = load_attr->kern_version;
|
|
||||||
}
|
|
||||||
p.log_level = load_attr->log_level;
|
|
||||||
p.log_buf = log_buf;
|
|
||||||
p.log_size = log_buf_sz;
|
|
||||||
p.prog_btf_fd = load_attr->prog_btf_fd;
|
|
||||||
p.func_info_rec_size = load_attr->func_info_rec_size;
|
|
||||||
p.func_info_cnt = load_attr->func_info_cnt;
|
|
||||||
p.func_info = load_attr->func_info;
|
|
||||||
p.line_info_rec_size = load_attr->line_info_rec_size;
|
|
||||||
p.line_info_cnt = load_attr->line_info_cnt;
|
|
||||||
p.line_info = load_attr->line_info;
|
|
||||||
p.prog_flags = load_attr->prog_flags;
|
|
||||||
|
|
||||||
return bpf_prog_load(load_attr->prog_type, load_attr->name, load_attr->license,
|
|
||||||
load_attr->insns, load_attr->insns_cnt, &p);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
|
|
||||||
size_t insns_cnt, const char *license,
|
|
||||||
__u32 kern_version, char *log_buf,
|
|
||||||
size_t log_buf_sz)
|
|
||||||
{
|
|
||||||
struct bpf_load_program_attr load_attr;
|
|
||||||
|
|
||||||
memset(&load_attr, 0, sizeof(struct bpf_load_program_attr));
|
|
||||||
load_attr.prog_type = type;
|
|
||||||
load_attr.expected_attach_type = 0;
|
|
||||||
load_attr.name = NULL;
|
|
||||||
load_attr.insns = insns;
|
|
||||||
load_attr.insns_cnt = insns_cnt;
|
|
||||||
load_attr.license = license;
|
|
||||||
load_attr.kern_version = kern_version;
|
|
||||||
|
|
||||||
return bpf_load_program_xattr2(&load_attr, log_buf, log_buf_sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
|
|
||||||
size_t insns_cnt, __u32 prog_flags, const char *license,
|
|
||||||
__u32 kern_version, char *log_buf, size_t log_buf_sz,
|
|
||||||
int log_level)
|
|
||||||
{
|
|
||||||
union bpf_attr attr;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
bump_rlimit_memlock();
|
|
||||||
|
|
||||||
memset(&attr, 0, sizeof(attr));
|
|
||||||
attr.prog_type = type;
|
|
||||||
attr.insn_cnt = (__u32)insns_cnt;
|
|
||||||
attr.insns = ptr_to_u64(insns);
|
|
||||||
attr.license = ptr_to_u64(license);
|
|
||||||
attr.log_buf = ptr_to_u64(log_buf);
|
|
||||||
attr.log_size = log_buf_sz;
|
|
||||||
attr.log_level = log_level;
|
|
||||||
log_buf[0] = 0;
|
|
||||||
attr.kern_version = kern_version;
|
|
||||||
attr.prog_flags = prog_flags;
|
|
||||||
|
|
||||||
fd = sys_bpf_prog_load(&attr, sizeof(attr), PROG_LOAD_ATTEMPTS);
|
|
||||||
return libbpf_err_errno(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_map_update_elem(int fd, const void *key, const void *value,
|
int bpf_map_update_elem(int fd, const void *key, const void *value,
|
||||||
__u64 flags)
|
__u64 flags)
|
||||||
{
|
{
|
||||||
@@ -638,6 +466,20 @@ int bpf_map_delete_elem(int fd, const void *key)
|
|||||||
return libbpf_err_errno(ret);
|
return libbpf_err_errno(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags)
|
||||||
|
{
|
||||||
|
union bpf_attr attr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
memset(&attr, 0, sizeof(attr));
|
||||||
|
attr.map_fd = fd;
|
||||||
|
attr.key = ptr_to_u64(key);
|
||||||
|
attr.flags = flags;
|
||||||
|
|
||||||
|
ret = sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
|
||||||
|
return libbpf_err_errno(ret);
|
||||||
|
}
|
||||||
|
|
||||||
int bpf_map_get_next_key(int fd, const void *key, void *next_key)
|
int bpf_map_get_next_key(int fd, const void *key, void *next_key)
|
||||||
{
|
{
|
||||||
union bpf_attr attr;
|
union bpf_attr attr;
|
||||||
@@ -816,7 +658,7 @@ int bpf_link_create(int prog_fd, int target_fd,
|
|||||||
{
|
{
|
||||||
__u32 target_btf_id, iter_info_len;
|
__u32 target_btf_id, iter_info_len;
|
||||||
union bpf_attr attr;
|
union bpf_attr attr;
|
||||||
int fd;
|
int fd, err;
|
||||||
|
|
||||||
if (!OPTS_VALID(opts, bpf_link_create_opts))
|
if (!OPTS_VALID(opts, bpf_link_create_opts))
|
||||||
return libbpf_err(-EINVAL);
|
return libbpf_err(-EINVAL);
|
||||||
@@ -853,6 +695,23 @@ int bpf_link_create(int prog_fd, int target_fd,
|
|||||||
if (!OPTS_ZEROED(opts, perf_event))
|
if (!OPTS_ZEROED(opts, perf_event))
|
||||||
return libbpf_err(-EINVAL);
|
return libbpf_err(-EINVAL);
|
||||||
break;
|
break;
|
||||||
|
case BPF_TRACE_KPROBE_MULTI:
|
||||||
|
attr.link_create.kprobe_multi.flags = OPTS_GET(opts, kprobe_multi.flags, 0);
|
||||||
|
attr.link_create.kprobe_multi.cnt = OPTS_GET(opts, kprobe_multi.cnt, 0);
|
||||||
|
attr.link_create.kprobe_multi.syms = ptr_to_u64(OPTS_GET(opts, kprobe_multi.syms, 0));
|
||||||
|
attr.link_create.kprobe_multi.addrs = ptr_to_u64(OPTS_GET(opts, kprobe_multi.addrs, 0));
|
||||||
|
attr.link_create.kprobe_multi.cookies = ptr_to_u64(OPTS_GET(opts, kprobe_multi.cookies, 0));
|
||||||
|
if (!OPTS_ZEROED(opts, kprobe_multi))
|
||||||
|
return libbpf_err(-EINVAL);
|
||||||
|
break;
|
||||||
|
case BPF_TRACE_FENTRY:
|
||||||
|
case BPF_TRACE_FEXIT:
|
||||||
|
case BPF_MODIFY_RETURN:
|
||||||
|
case BPF_LSM_MAC:
|
||||||
|
attr.link_create.tracing.cookie = OPTS_GET(opts, tracing.cookie, 0);
|
||||||
|
if (!OPTS_ZEROED(opts, tracing))
|
||||||
|
return libbpf_err(-EINVAL);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (!OPTS_ZEROED(opts, flags))
|
if (!OPTS_ZEROED(opts, flags))
|
||||||
return libbpf_err(-EINVAL);
|
return libbpf_err(-EINVAL);
|
||||||
@@ -860,7 +719,37 @@ int bpf_link_create(int prog_fd, int target_fd,
|
|||||||
}
|
}
|
||||||
proceed:
|
proceed:
|
||||||
fd = sys_bpf_fd(BPF_LINK_CREATE, &attr, sizeof(attr));
|
fd = sys_bpf_fd(BPF_LINK_CREATE, &attr, sizeof(attr));
|
||||||
return libbpf_err_errno(fd);
|
if (fd >= 0)
|
||||||
|
return fd;
|
||||||
|
/* we'll get EINVAL if LINK_CREATE doesn't support attaching fentry
|
||||||
|
* and other similar programs
|
||||||
|
*/
|
||||||
|
err = -errno;
|
||||||
|
if (err != -EINVAL)
|
||||||
|
return libbpf_err(err);
|
||||||
|
|
||||||
|
/* if user used features not supported by
|
||||||
|
* BPF_RAW_TRACEPOINT_OPEN command, then just give up immediately
|
||||||
|
*/
|
||||||
|
if (attr.link_create.target_fd || attr.link_create.target_btf_id)
|
||||||
|
return libbpf_err(err);
|
||||||
|
if (!OPTS_ZEROED(opts, sz))
|
||||||
|
return libbpf_err(err);
|
||||||
|
|
||||||
|
/* otherwise, for few select kinds of programs that can be
|
||||||
|
* attached using BPF_RAW_TRACEPOINT_OPEN command, try that as
|
||||||
|
* a fallback for older kernels
|
||||||
|
*/
|
||||||
|
switch (attach_type) {
|
||||||
|
case BPF_TRACE_RAW_TP:
|
||||||
|
case BPF_LSM_MAC:
|
||||||
|
case BPF_TRACE_FENTRY:
|
||||||
|
case BPF_TRACE_FEXIT:
|
||||||
|
case BPF_MODIFY_RETURN:
|
||||||
|
return bpf_raw_tracepoint_open(NULL, prog_fd);
|
||||||
|
default:
|
||||||
|
return libbpf_err(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int bpf_link_detach(int link_fd)
|
int bpf_link_detach(int link_fd)
|
||||||
@@ -906,80 +795,48 @@ int bpf_iter_create(int link_fd)
|
|||||||
return libbpf_err_errno(fd);
|
return libbpf_err_errno(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
|
int bpf_prog_query_opts(int target_fd,
|
||||||
__u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt)
|
enum bpf_attach_type type,
|
||||||
|
struct bpf_prog_query_opts *opts)
|
||||||
{
|
{
|
||||||
union bpf_attr attr;
|
union bpf_attr attr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
memset(&attr, 0, sizeof(attr));
|
if (!OPTS_VALID(opts, bpf_prog_query_opts))
|
||||||
attr.query.target_fd = target_fd;
|
|
||||||
attr.query.attach_type = type;
|
|
||||||
attr.query.query_flags = query_flags;
|
|
||||||
attr.query.prog_cnt = *prog_cnt;
|
|
||||||
attr.query.prog_ids = ptr_to_u64(prog_ids);
|
|
||||||
|
|
||||||
ret = sys_bpf(BPF_PROG_QUERY, &attr, sizeof(attr));
|
|
||||||
|
|
||||||
if (attach_flags)
|
|
||||||
*attach_flags = attr.query.attach_flags;
|
|
||||||
*prog_cnt = attr.query.prog_cnt;
|
|
||||||
|
|
||||||
return libbpf_err_errno(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size,
|
|
||||||
void *data_out, __u32 *size_out, __u32 *retval,
|
|
||||||
__u32 *duration)
|
|
||||||
{
|
|
||||||
union bpf_attr attr;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
memset(&attr, 0, sizeof(attr));
|
|
||||||
attr.test.prog_fd = prog_fd;
|
|
||||||
attr.test.data_in = ptr_to_u64(data);
|
|
||||||
attr.test.data_out = ptr_to_u64(data_out);
|
|
||||||
attr.test.data_size_in = size;
|
|
||||||
attr.test.repeat = repeat;
|
|
||||||
|
|
||||||
ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr));
|
|
||||||
|
|
||||||
if (size_out)
|
|
||||||
*size_out = attr.test.data_size_out;
|
|
||||||
if (retval)
|
|
||||||
*retval = attr.test.retval;
|
|
||||||
if (duration)
|
|
||||||
*duration = attr.test.duration;
|
|
||||||
|
|
||||||
return libbpf_err_errno(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr)
|
|
||||||
{
|
|
||||||
union bpf_attr attr;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!test_attr->data_out && test_attr->data_size_out > 0)
|
|
||||||
return libbpf_err(-EINVAL);
|
return libbpf_err(-EINVAL);
|
||||||
|
|
||||||
memset(&attr, 0, sizeof(attr));
|
memset(&attr, 0, sizeof(attr));
|
||||||
attr.test.prog_fd = test_attr->prog_fd;
|
|
||||||
attr.test.data_in = ptr_to_u64(test_attr->data_in);
|
|
||||||
attr.test.data_out = ptr_to_u64(test_attr->data_out);
|
|
||||||
attr.test.data_size_in = test_attr->data_size_in;
|
|
||||||
attr.test.data_size_out = test_attr->data_size_out;
|
|
||||||
attr.test.ctx_in = ptr_to_u64(test_attr->ctx_in);
|
|
||||||
attr.test.ctx_out = ptr_to_u64(test_attr->ctx_out);
|
|
||||||
attr.test.ctx_size_in = test_attr->ctx_size_in;
|
|
||||||
attr.test.ctx_size_out = test_attr->ctx_size_out;
|
|
||||||
attr.test.repeat = test_attr->repeat;
|
|
||||||
|
|
||||||
ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr));
|
attr.query.target_fd = target_fd;
|
||||||
|
attr.query.attach_type = type;
|
||||||
|
attr.query.query_flags = OPTS_GET(opts, query_flags, 0);
|
||||||
|
attr.query.prog_cnt = OPTS_GET(opts, prog_cnt, 0);
|
||||||
|
attr.query.prog_ids = ptr_to_u64(OPTS_GET(opts, prog_ids, NULL));
|
||||||
|
attr.query.prog_attach_flags = ptr_to_u64(OPTS_GET(opts, prog_attach_flags, NULL));
|
||||||
|
|
||||||
test_attr->data_size_out = attr.test.data_size_out;
|
ret = sys_bpf(BPF_PROG_QUERY, &attr, sizeof(attr));
|
||||||
test_attr->ctx_size_out = attr.test.ctx_size_out;
|
|
||||||
test_attr->retval = attr.test.retval;
|
OPTS_SET(opts, attach_flags, attr.query.attach_flags);
|
||||||
test_attr->duration = attr.test.duration;
|
OPTS_SET(opts, prog_cnt, attr.query.prog_cnt);
|
||||||
|
|
||||||
|
return libbpf_err_errno(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
|
||||||
|
__u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt)
|
||||||
|
{
|
||||||
|
LIBBPF_OPTS(bpf_prog_query_opts, opts);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
opts.query_flags = query_flags;
|
||||||
|
opts.prog_ids = prog_ids;
|
||||||
|
opts.prog_cnt = *prog_cnt;
|
||||||
|
|
||||||
|
ret = bpf_prog_query_opts(target_fd, type, &opts);
|
||||||
|
|
||||||
|
if (attach_flags)
|
||||||
|
*attach_flags = opts.attach_flags;
|
||||||
|
*prog_cnt = opts.prog_cnt;
|
||||||
|
|
||||||
return libbpf_err_errno(ret);
|
return libbpf_err_errno(ret);
|
||||||
}
|
}
|
||||||
@@ -994,6 +851,7 @@ int bpf_prog_test_run_opts(int prog_fd, struct bpf_test_run_opts *opts)
|
|||||||
|
|
||||||
memset(&attr, 0, sizeof(attr));
|
memset(&attr, 0, sizeof(attr));
|
||||||
attr.test.prog_fd = prog_fd;
|
attr.test.prog_fd = prog_fd;
|
||||||
|
attr.test.batch_size = OPTS_GET(opts, batch_size, 0);
|
||||||
attr.test.cpu = OPTS_GET(opts, cpu, 0);
|
attr.test.cpu = OPTS_GET(opts, cpu, 0);
|
||||||
attr.test.flags = OPTS_GET(opts, flags, 0);
|
attr.test.flags = OPTS_GET(opts, flags, 0);
|
||||||
attr.test.repeat = OPTS_GET(opts, repeat, 0);
|
attr.test.repeat = OPTS_GET(opts, repeat, 0);
|
||||||
@@ -1179,27 +1037,6 @@ int bpf_btf_load(const void *btf_data, size_t btf_size, const struct bpf_btf_loa
|
|||||||
return libbpf_err_errno(fd);
|
return libbpf_err_errno(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bpf_load_btf(const void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, bool do_log)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_btf_load_opts, opts);
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
retry:
|
|
||||||
if (do_log && log_buf && log_buf_size) {
|
|
||||||
opts.log_buf = log_buf;
|
|
||||||
opts.log_size = log_buf_size;
|
|
||||||
opts.log_level = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = bpf_btf_load(btf, btf_size, &opts);
|
|
||||||
if (fd < 0 && !do_log && log_buf && log_buf_size) {
|
|
||||||
do_log = true;
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
|
|
||||||
return libbpf_err_errno(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len,
|
int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len,
|
||||||
__u32 *prog_id, __u32 *fd_type, __u64 *probe_offset,
|
__u32 *prog_id, __u32 *fd_type, __u64 *probe_offset,
|
||||||
__u64 *probe_addr)
|
__u64 *probe_addr)
|
||||||
|
|||||||
156
src/bpf.h
156
src/bpf.h
@@ -61,48 +61,6 @@ LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,
|
|||||||
__u32 max_entries,
|
__u32 max_entries,
|
||||||
const struct bpf_map_create_opts *opts);
|
const struct bpf_map_create_opts *opts);
|
||||||
|
|
||||||
struct bpf_create_map_attr {
|
|
||||||
const char *name;
|
|
||||||
enum bpf_map_type map_type;
|
|
||||||
__u32 map_flags;
|
|
||||||
__u32 key_size;
|
|
||||||
__u32 value_size;
|
|
||||||
__u32 max_entries;
|
|
||||||
__u32 numa_node;
|
|
||||||
__u32 btf_fd;
|
|
||||||
__u32 btf_key_type_id;
|
|
||||||
__u32 btf_value_type_id;
|
|
||||||
__u32 map_ifindex;
|
|
||||||
union {
|
|
||||||
__u32 inner_map_fd;
|
|
||||||
__u32 btf_vmlinux_value_type_id;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead")
|
|
||||||
LIBBPF_API int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead")
|
|
||||||
LIBBPF_API int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
|
|
||||||
int key_size, int value_size,
|
|
||||||
int max_entries, __u32 map_flags, int node);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead")
|
|
||||||
LIBBPF_API int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
|
|
||||||
int key_size, int value_size,
|
|
||||||
int max_entries, __u32 map_flags);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead")
|
|
||||||
LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size,
|
|
||||||
int value_size, int max_entries, __u32 map_flags);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead")
|
|
||||||
LIBBPF_API int bpf_create_map_in_map_node(enum bpf_map_type map_type,
|
|
||||||
const char *name, int key_size,
|
|
||||||
int inner_map_fd, int max_entries,
|
|
||||||
__u32 map_flags, int node);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead")
|
|
||||||
LIBBPF_API int bpf_create_map_in_map(enum bpf_map_type map_type,
|
|
||||||
const char *name, int key_size,
|
|
||||||
int inner_map_fd, int max_entries,
|
|
||||||
__u32 map_flags);
|
|
||||||
|
|
||||||
struct bpf_prog_load_opts {
|
struct bpf_prog_load_opts {
|
||||||
size_t sz; /* size of this struct for forward/backward compatibility */
|
size_t sz; /* size of this struct for forward/backward compatibility */
|
||||||
|
|
||||||
@@ -145,54 +103,6 @@ LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type,
|
|||||||
const char *prog_name, const char *license,
|
const char *prog_name, const char *license,
|
||||||
const struct bpf_insn *insns, size_t insn_cnt,
|
const struct bpf_insn *insns, size_t insn_cnt,
|
||||||
const struct bpf_prog_load_opts *opts);
|
const struct bpf_prog_load_opts *opts);
|
||||||
/* this "specialization" should go away in libbpf 1.0 */
|
|
||||||
LIBBPF_API int bpf_prog_load_v0_6_0(enum bpf_prog_type prog_type,
|
|
||||||
const char *prog_name, const char *license,
|
|
||||||
const struct bpf_insn *insns, size_t insn_cnt,
|
|
||||||
const struct bpf_prog_load_opts *opts);
|
|
||||||
|
|
||||||
/* This is an elaborate way to not conflict with deprecated bpf_prog_load()
|
|
||||||
* API, defined in libbpf.h. Once we hit libbpf 1.0, all this will be gone.
|
|
||||||
* With this approach, if someone is calling bpf_prog_load() with
|
|
||||||
* 4 arguments, they will use the deprecated API, which keeps backwards
|
|
||||||
* compatibility (both source code and binary). If bpf_prog_load() is called
|
|
||||||
* with 6 arguments, though, it gets redirected to __bpf_prog_load.
|
|
||||||
* So looking forward to libbpf 1.0 when this hack will be gone and
|
|
||||||
* __bpf_prog_load() will be called just bpf_prog_load().
|
|
||||||
*/
|
|
||||||
#ifndef bpf_prog_load
|
|
||||||
#define bpf_prog_load(...) ___libbpf_overload(___bpf_prog_load, __VA_ARGS__)
|
|
||||||
#define ___bpf_prog_load4(file, type, pobj, prog_fd) \
|
|
||||||
bpf_prog_load_deprecated(file, type, pobj, prog_fd)
|
|
||||||
#define ___bpf_prog_load6(prog_type, prog_name, license, insns, insn_cnt, opts) \
|
|
||||||
bpf_prog_load(prog_type, prog_name, license, insns, insn_cnt, opts)
|
|
||||||
#endif /* bpf_prog_load */
|
|
||||||
|
|
||||||
struct bpf_load_program_attr {
|
|
||||||
enum bpf_prog_type prog_type;
|
|
||||||
enum bpf_attach_type expected_attach_type;
|
|
||||||
const char *name;
|
|
||||||
const struct bpf_insn *insns;
|
|
||||||
size_t insns_cnt;
|
|
||||||
const char *license;
|
|
||||||
union {
|
|
||||||
__u32 kern_version;
|
|
||||||
__u32 attach_prog_fd;
|
|
||||||
};
|
|
||||||
union {
|
|
||||||
__u32 prog_ifindex;
|
|
||||||
__u32 attach_btf_id;
|
|
||||||
};
|
|
||||||
__u32 prog_btf_fd;
|
|
||||||
__u32 func_info_rec_size;
|
|
||||||
const void *func_info;
|
|
||||||
__u32 func_info_cnt;
|
|
||||||
__u32 line_info_rec_size;
|
|
||||||
const void *line_info;
|
|
||||||
__u32 line_info_cnt;
|
|
||||||
__u32 log_level;
|
|
||||||
__u32 prog_flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Flags to direct loading requirements */
|
/* Flags to direct loading requirements */
|
||||||
#define MAPS_RELAX_COMPAT 0x01
|
#define MAPS_RELAX_COMPAT 0x01
|
||||||
@@ -200,22 +110,6 @@ struct bpf_load_program_attr {
|
|||||||
/* Recommended log buffer size */
|
/* Recommended log buffer size */
|
||||||
#define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */
|
#define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */
|
||||||
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_load() instead")
|
|
||||||
LIBBPF_API int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
|
|
||||||
char *log_buf, size_t log_buf_sz);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_load() instead")
|
|
||||||
LIBBPF_API int bpf_load_program(enum bpf_prog_type type,
|
|
||||||
const struct bpf_insn *insns, size_t insns_cnt,
|
|
||||||
const char *license, __u32 kern_version,
|
|
||||||
char *log_buf, size_t log_buf_sz);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_load() instead")
|
|
||||||
LIBBPF_API int bpf_verify_program(enum bpf_prog_type type,
|
|
||||||
const struct bpf_insn *insns,
|
|
||||||
size_t insns_cnt, __u32 prog_flags,
|
|
||||||
const char *license, __u32 kern_version,
|
|
||||||
char *log_buf, size_t log_buf_sz,
|
|
||||||
int log_level);
|
|
||||||
|
|
||||||
struct bpf_btf_load_opts {
|
struct bpf_btf_load_opts {
|
||||||
size_t sz; /* size of this struct for forward/backward compatibility */
|
size_t sz; /* size of this struct for forward/backward compatibility */
|
||||||
|
|
||||||
@@ -229,10 +123,6 @@ struct bpf_btf_load_opts {
|
|||||||
LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size,
|
LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size,
|
||||||
const struct bpf_btf_load_opts *opts);
|
const struct bpf_btf_load_opts *opts);
|
||||||
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_btf_load() instead")
|
|
||||||
LIBBPF_API int bpf_load_btf(const void *btf, __u32 btf_size, char *log_buf,
|
|
||||||
__u32 log_buf_size, bool do_log);
|
|
||||||
|
|
||||||
LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,
|
LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,
|
||||||
__u64 flags);
|
__u64 flags);
|
||||||
|
|
||||||
@@ -244,6 +134,7 @@ LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,
|
|||||||
LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key,
|
LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key,
|
||||||
void *value, __u64 flags);
|
void *value, __u64 flags);
|
||||||
LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
|
LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
|
||||||
|
LIBBPF_API int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags);
|
||||||
LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);
|
LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);
|
||||||
LIBBPF_API int bpf_map_freeze(int fd);
|
LIBBPF_API int bpf_map_freeze(int fd);
|
||||||
|
|
||||||
@@ -394,10 +285,6 @@ LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
|
|||||||
LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int attachable_fd,
|
LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int attachable_fd,
|
||||||
enum bpf_attach_type type,
|
enum bpf_attach_type type,
|
||||||
const struct bpf_prog_attach_opts *opts);
|
const struct bpf_prog_attach_opts *opts);
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_prog_attach_opts() instead")
|
|
||||||
LIBBPF_API int bpf_prog_attach_xattr(int prog_fd, int attachable_fd,
|
|
||||||
enum bpf_attach_type type,
|
|
||||||
const struct bpf_prog_attach_opts *opts);
|
|
||||||
LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
|
LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
|
||||||
LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,
|
LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,
|
||||||
enum bpf_attach_type type);
|
enum bpf_attach_type type);
|
||||||
@@ -413,10 +300,20 @@ struct bpf_link_create_opts {
|
|||||||
struct {
|
struct {
|
||||||
__u64 bpf_cookie;
|
__u64 bpf_cookie;
|
||||||
} perf_event;
|
} perf_event;
|
||||||
|
struct {
|
||||||
|
__u32 flags;
|
||||||
|
__u32 cnt;
|
||||||
|
const char **syms;
|
||||||
|
const unsigned long *addrs;
|
||||||
|
const __u64 *cookies;
|
||||||
|
} kprobe_multi;
|
||||||
|
struct {
|
||||||
|
__u64 cookie;
|
||||||
|
} tracing;
|
||||||
};
|
};
|
||||||
size_t :0;
|
size_t :0;
|
||||||
};
|
};
|
||||||
#define bpf_link_create_opts__last_field perf_event
|
#define bpf_link_create_opts__last_field kprobe_multi.cookies
|
||||||
|
|
||||||
LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
|
LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
|
||||||
enum bpf_attach_type attach_type,
|
enum bpf_attach_type attach_type,
|
||||||
@@ -453,17 +350,6 @@ struct bpf_prog_test_run_attr {
|
|||||||
* out: length of cxt_out */
|
* out: length of cxt_out */
|
||||||
};
|
};
|
||||||
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead")
|
|
||||||
LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* bpf_prog_test_run does not check that data_out is large enough. Consider
|
|
||||||
* using bpf_prog_test_run_opts instead.
|
|
||||||
*/
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead")
|
|
||||||
LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data,
|
|
||||||
__u32 size, void *data_out, __u32 *size_out,
|
|
||||||
__u32 *retval, __u32 *duration);
|
|
||||||
LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
|
LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
|
||||||
LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
|
LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
|
||||||
LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);
|
LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);
|
||||||
@@ -473,9 +359,24 @@ LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);
|
|||||||
LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);
|
LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);
|
||||||
LIBBPF_API int bpf_link_get_fd_by_id(__u32 id);
|
LIBBPF_API int bpf_link_get_fd_by_id(__u32 id);
|
||||||
LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);
|
LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);
|
||||||
|
|
||||||
|
struct bpf_prog_query_opts {
|
||||||
|
size_t sz; /* size of this struct for forward/backward compatibility */
|
||||||
|
__u32 query_flags;
|
||||||
|
__u32 attach_flags; /* output argument */
|
||||||
|
__u32 *prog_ids;
|
||||||
|
__u32 prog_cnt; /* input+output argument */
|
||||||
|
__u32 *prog_attach_flags;
|
||||||
|
};
|
||||||
|
#define bpf_prog_query_opts__last_field prog_attach_flags
|
||||||
|
|
||||||
|
LIBBPF_API int bpf_prog_query_opts(int target_fd,
|
||||||
|
enum bpf_attach_type type,
|
||||||
|
struct bpf_prog_query_opts *opts);
|
||||||
LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,
|
LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,
|
||||||
__u32 query_flags, __u32 *attach_flags,
|
__u32 query_flags, __u32 *attach_flags,
|
||||||
__u32 *prog_ids, __u32 *prog_cnt);
|
__u32 *prog_ids, __u32 *prog_cnt);
|
||||||
|
|
||||||
LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);
|
LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);
|
||||||
LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
|
LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
|
||||||
__u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
|
__u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
|
||||||
@@ -512,8 +413,9 @@ struct bpf_test_run_opts {
|
|||||||
__u32 duration; /* out: average per repetition in ns */
|
__u32 duration; /* out: average per repetition in ns */
|
||||||
__u32 flags;
|
__u32 flags;
|
||||||
__u32 cpu;
|
__u32 cpu;
|
||||||
|
__u32 batch_size;
|
||||||
};
|
};
|
||||||
#define bpf_test_run_opts__last_field cpu
|
#define bpf_test_run_opts__last_field batch_size
|
||||||
|
|
||||||
LIBBPF_API int bpf_prog_test_run_opts(int prog_fd,
|
LIBBPF_API int bpf_prog_test_run_opts(int prog_fd,
|
||||||
struct bpf_test_run_opts *opts);
|
struct bpf_test_run_opts *opts);
|
||||||
|
|||||||
@@ -110,21 +110,50 @@ enum bpf_enum_value_kind {
|
|||||||
val; \
|
val; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define ___bpf_field_ref1(field) (field)
|
||||||
|
#define ___bpf_field_ref2(type, field) (((typeof(type) *)0)->field)
|
||||||
|
#define ___bpf_field_ref(args...) \
|
||||||
|
___bpf_apply(___bpf_field_ref, ___bpf_narg(args))(args)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convenience macro to check that field actually exists in target kernel's.
|
* Convenience macro to check that field actually exists in target kernel's.
|
||||||
* Returns:
|
* Returns:
|
||||||
* 1, if matching field is present in target kernel;
|
* 1, if matching field is present in target kernel;
|
||||||
* 0, if no matching field found.
|
* 0, if no matching field found.
|
||||||
|
*
|
||||||
|
* Supports two forms:
|
||||||
|
* - field reference through variable access:
|
||||||
|
* bpf_core_field_exists(p->my_field);
|
||||||
|
* - field reference through type and field names:
|
||||||
|
* bpf_core_field_exists(struct my_type, my_field).
|
||||||
*/
|
*/
|
||||||
#define bpf_core_field_exists(field) \
|
#define bpf_core_field_exists(field...) \
|
||||||
__builtin_preserve_field_info(field, BPF_FIELD_EXISTS)
|
__builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_EXISTS)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convenience macro to get the byte size of a field. Works for integers,
|
* Convenience macro to get the byte size of a field. Works for integers,
|
||||||
* struct/unions, pointers, arrays, and enums.
|
* struct/unions, pointers, arrays, and enums.
|
||||||
|
*
|
||||||
|
* Supports two forms:
|
||||||
|
* - field reference through variable access:
|
||||||
|
* bpf_core_field_size(p->my_field);
|
||||||
|
* - field reference through type and field names:
|
||||||
|
* bpf_core_field_size(struct my_type, my_field).
|
||||||
*/
|
*/
|
||||||
#define bpf_core_field_size(field) \
|
#define bpf_core_field_size(field...) \
|
||||||
__builtin_preserve_field_info(field, BPF_FIELD_BYTE_SIZE)
|
__builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_BYTE_SIZE)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convenience macro to get field's byte offset.
|
||||||
|
*
|
||||||
|
* Supports two forms:
|
||||||
|
* - field reference through variable access:
|
||||||
|
* bpf_core_field_offset(p->my_field);
|
||||||
|
* - field reference through type and field names:
|
||||||
|
* bpf_core_field_offset(struct my_type, my_field).
|
||||||
|
*/
|
||||||
|
#define bpf_core_field_offset(field...) \
|
||||||
|
__builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_BYTE_OFFSET)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convenience macro to get BTF type ID of a specified type, using a local BTF
|
* Convenience macro to get BTF type ID of a specified type, using a local BTF
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ struct inode;
|
|||||||
struct socket;
|
struct socket;
|
||||||
struct file;
|
struct file;
|
||||||
struct bpf_timer;
|
struct bpf_timer;
|
||||||
|
struct mptcp_sock;
|
||||||
|
struct bpf_dynptr;
|
||||||
|
struct iphdr;
|
||||||
|
struct ipv6hdr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* bpf_map_lookup_elem
|
* bpf_map_lookup_elem
|
||||||
@@ -961,8 +965,8 @@ static long (*bpf_probe_write_user)(void *dst, const void *src, __u32 len) = (vo
|
|||||||
* Returns
|
* Returns
|
||||||
* The return value depends on the result of the test, and can be:
|
* The return value depends on the result of the test, and can be:
|
||||||
*
|
*
|
||||||
* * 0, if current task belongs to the cgroup2.
|
* * 1, if current task belongs to the cgroup2.
|
||||||
* * 1, if current task does not belong to the cgroup2.
|
* * 0, if current task does not belong to the cgroup2.
|
||||||
* * A negative error code, if an error occurred.
|
* * A negative error code, if an error occurred.
|
||||||
*/
|
*/
|
||||||
static long (*bpf_current_task_under_cgroup)(void *map, __u32 index) = (void *) 37;
|
static long (*bpf_current_task_under_cgroup)(void *map, __u32 index) = (void *) 37;
|
||||||
@@ -1752,8 +1756,8 @@ static long (*bpf_skb_get_xfrm_state)(struct __sk_buff *skb, __u32 index, struct
|
|||||||
* # sysctl kernel.perf_event_max_stack=<new value>
|
* # sysctl kernel.perf_event_max_stack=<new value>
|
||||||
*
|
*
|
||||||
* Returns
|
* Returns
|
||||||
* A non-negative value equal to or less than *size* on success,
|
* The non-negative copied *buf* length equal to or less than
|
||||||
* or a negative error in case of failure.
|
* *size* on success, or a negative error in case of failure.
|
||||||
*/
|
*/
|
||||||
static long (*bpf_get_stack)(void *ctx, void *buf, __u32 size, __u64 flags) = (void *) 67;
|
static long (*bpf_get_stack)(void *ctx, void *buf, __u32 size, __u64 flags) = (void *) 67;
|
||||||
|
|
||||||
@@ -2461,10 +2465,11 @@ static struct bpf_sock *(*bpf_skc_lookup_tcp)(void *ctx, struct bpf_sock_tuple *
|
|||||||
*
|
*
|
||||||
* *iph* points to the start of the IPv4 or IPv6 header, while
|
* *iph* points to the start of the IPv4 or IPv6 header, while
|
||||||
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
||||||
* **sizeof**\ (**struct ip6hdr**).
|
* **sizeof**\ (**struct ipv6hdr**).
|
||||||
*
|
*
|
||||||
* *th* points to the start of the TCP header, while *th_len*
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
* contains **sizeof**\ (**struct tcphdr**).
|
* contains the length of the TCP header (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
*
|
*
|
||||||
* Returns
|
* Returns
|
||||||
* 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
|
* 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
|
||||||
@@ -2687,10 +2692,11 @@ static long (*bpf_send_signal)(__u32 sig) = (void *) 109;
|
|||||||
*
|
*
|
||||||
* *iph* points to the start of the IPv4 or IPv6 header, while
|
* *iph* points to the start of the IPv4 or IPv6 header, while
|
||||||
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
* *iph_len* contains **sizeof**\ (**struct iphdr**) or
|
||||||
* **sizeof**\ (**struct ip6hdr**).
|
* **sizeof**\ (**struct ipv6hdr**).
|
||||||
*
|
*
|
||||||
* *th* points to the start of the TCP header, while *th_len*
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
* contains the length of the TCP header.
|
* contains the length of the TCP header with options (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
*
|
*
|
||||||
* Returns
|
* Returns
|
||||||
* On success, lower 32 bits hold the generated SYN cookie in
|
* On success, lower 32 bits hold the generated SYN cookie in
|
||||||
@@ -3305,8 +3311,8 @@ static struct udp6_sock *(*bpf_skc_to_udp6_sock)(void *sk) = (void *) 140;
|
|||||||
* # sysctl kernel.perf_event_max_stack=<new value>
|
* # sysctl kernel.perf_event_max_stack=<new value>
|
||||||
*
|
*
|
||||||
* Returns
|
* Returns
|
||||||
* A non-negative value equal to or less than *size* on success,
|
* The non-negative copied *buf* length equal to or less than
|
||||||
* or a negative error in case of failure.
|
* *size* on success, or a negative error in case of failure.
|
||||||
*/
|
*/
|
||||||
static long (*bpf_get_task_stack)(struct task_struct *task, void *buf, __u32 size, __u64 flags) = (void *) 141;
|
static long (*bpf_get_task_stack)(struct task_struct *task, void *buf, __u32 size, __u64 flags) = (void *) 141;
|
||||||
|
|
||||||
@@ -4295,4 +4301,278 @@ static long (*bpf_xdp_store_bytes)(struct xdp_md *xdp_md, __u32 offset, void *bu
|
|||||||
*/
|
*/
|
||||||
static long (*bpf_copy_from_user_task)(void *dst, __u32 size, const void *user_ptr, struct task_struct *tsk, __u64 flags) = (void *) 191;
|
static long (*bpf_copy_from_user_task)(void *dst, __u32 size, const void *user_ptr, struct task_struct *tsk, __u64 flags) = (void *) 191;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_skb_set_tstamp
|
||||||
|
*
|
||||||
|
* Change the __sk_buff->tstamp_type to *tstamp_type*
|
||||||
|
* and set *tstamp* to the __sk_buff->tstamp together.
|
||||||
|
*
|
||||||
|
* If there is no need to change the __sk_buff->tstamp_type,
|
||||||
|
* the tstamp value can be directly written to __sk_buff->tstamp
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
|
||||||
|
* will be kept during bpf_redirect_*(). A non zero
|
||||||
|
* *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
|
||||||
|
* *tstamp_type*.
|
||||||
|
*
|
||||||
|
* A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
|
||||||
|
* with a zero *tstamp*.
|
||||||
|
*
|
||||||
|
* Only IPv4 and IPv6 skb->protocol are supported.
|
||||||
|
*
|
||||||
|
* This function is most useful when it needs to set a
|
||||||
|
* mono delivery time to __sk_buff->tstamp and then
|
||||||
|
* bpf_redirect_*() to the egress of an iface. For example,
|
||||||
|
* changing the (rcv) timestamp in __sk_buff->tstamp at
|
||||||
|
* ingress to a mono delivery time and then bpf_redirect_*()
|
||||||
|
* to sch_fq@phy-dev.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 on success.
|
||||||
|
* **-EINVAL** for invalid input
|
||||||
|
* **-EOPNOTSUPP** for unsupported protocol
|
||||||
|
*/
|
||||||
|
static long (*bpf_skb_set_tstamp)(struct __sk_buff *skb, __u64 tstamp, __u32 tstamp_type) = (void *) 192;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_ima_file_hash
|
||||||
|
*
|
||||||
|
* Returns a calculated IMA hash of the *file*.
|
||||||
|
* If the hash is larger than *size*, then only *size*
|
||||||
|
* bytes will be copied to *dst*
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* The **hash_algo** is returned on success,
|
||||||
|
* **-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if
|
||||||
|
* invalid arguments are passed.
|
||||||
|
*/
|
||||||
|
static long (*bpf_ima_file_hash)(struct file *file, void *dst, __u32 size) = (void *) 193;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_kptr_xchg
|
||||||
|
*
|
||||||
|
* Exchange kptr at pointer *map_value* with *ptr*, and return the
|
||||||
|
* old value. *ptr* can be NULL, otherwise it must be a referenced
|
||||||
|
* pointer which will be released when this helper is called.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* The old value of kptr (which can be NULL). The returned pointer
|
||||||
|
* if not NULL, is a reference which must be released using its
|
||||||
|
* corresponding release function, or moved into a BPF map before
|
||||||
|
* program exit.
|
||||||
|
*/
|
||||||
|
static void *(*bpf_kptr_xchg)(void *map_value, void *ptr) = (void *) 194;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_map_lookup_percpu_elem
|
||||||
|
*
|
||||||
|
* Perform a lookup in *percpu map* for an entry associated to
|
||||||
|
* *key* on *cpu*.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* Map value associated to *key* on *cpu*, or **NULL** if no entry
|
||||||
|
* was found or *cpu* is invalid.
|
||||||
|
*/
|
||||||
|
static void *(*bpf_map_lookup_percpu_elem)(void *map, const void *key, __u32 cpu) = (void *) 195;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_skc_to_mptcp_sock
|
||||||
|
*
|
||||||
|
* Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* *sk* if casting is valid, or **NULL** otherwise.
|
||||||
|
*/
|
||||||
|
static struct mptcp_sock *(*bpf_skc_to_mptcp_sock)(void *sk) = (void *) 196;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_dynptr_from_mem
|
||||||
|
*
|
||||||
|
* Get a dynptr to local memory *data*.
|
||||||
|
*
|
||||||
|
* *data* must be a ptr to a map value.
|
||||||
|
* The maximum *size* supported is DYNPTR_MAX_SIZE.
|
||||||
|
* *flags* is currently unused.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
|
||||||
|
* -EINVAL if flags is not 0.
|
||||||
|
*/
|
||||||
|
static long (*bpf_dynptr_from_mem)(void *data, __u32 size, __u64 flags, struct bpf_dynptr *ptr) = (void *) 197;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_ringbuf_reserve_dynptr
|
||||||
|
*
|
||||||
|
* Reserve *size* bytes of payload in a ring buffer *ringbuf*
|
||||||
|
* through the dynptr interface. *flags* must be 0.
|
||||||
|
*
|
||||||
|
* Please note that a corresponding bpf_ringbuf_submit_dynptr or
|
||||||
|
* bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the
|
||||||
|
* reservation fails. This is enforced by the verifier.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 on success, or a negative error in case of failure.
|
||||||
|
*/
|
||||||
|
static long (*bpf_ringbuf_reserve_dynptr)(void *ringbuf, __u32 size, __u64 flags, struct bpf_dynptr *ptr) = (void *) 198;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_ringbuf_submit_dynptr
|
||||||
|
*
|
||||||
|
* Submit reserved ring buffer sample, pointed to by *data*,
|
||||||
|
* through the dynptr interface. This is a no-op if the dynptr is
|
||||||
|
* invalid/null.
|
||||||
|
*
|
||||||
|
* For more information on *flags*, please see
|
||||||
|
* 'bpf_ringbuf_submit'.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* Nothing. Always succeeds.
|
||||||
|
*/
|
||||||
|
static void (*bpf_ringbuf_submit_dynptr)(struct bpf_dynptr *ptr, __u64 flags) = (void *) 199;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_ringbuf_discard_dynptr
|
||||||
|
*
|
||||||
|
* Discard reserved ring buffer sample through the dynptr
|
||||||
|
* interface. This is a no-op if the dynptr is invalid/null.
|
||||||
|
*
|
||||||
|
* For more information on *flags*, please see
|
||||||
|
* 'bpf_ringbuf_discard'.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* Nothing. Always succeeds.
|
||||||
|
*/
|
||||||
|
static void (*bpf_ringbuf_discard_dynptr)(struct bpf_dynptr *ptr, __u64 flags) = (void *) 200;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_dynptr_read
|
||||||
|
*
|
||||||
|
* Read *len* bytes from *src* into *dst*, starting from *offset*
|
||||||
|
* into *src*.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 on success, -E2BIG if *offset* + *len* exceeds the length
|
||||||
|
* of *src*'s data, -EINVAL if *src* is an invalid dynptr.
|
||||||
|
*/
|
||||||
|
static long (*bpf_dynptr_read)(void *dst, __u32 len, struct bpf_dynptr *src, __u32 offset) = (void *) 201;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_dynptr_write
|
||||||
|
*
|
||||||
|
* Write *len* bytes from *src* into *dst*, starting from *offset*
|
||||||
|
* into *dst*.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 on success, -E2BIG if *offset* + *len* exceeds the length
|
||||||
|
* of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
|
||||||
|
* is a read-only dynptr.
|
||||||
|
*/
|
||||||
|
static long (*bpf_dynptr_write)(struct bpf_dynptr *dst, __u32 offset, void *src, __u32 len) = (void *) 202;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_dynptr_data
|
||||||
|
*
|
||||||
|
* Get a pointer to the underlying dynptr data.
|
||||||
|
*
|
||||||
|
* *len* must be a statically known value. The returned data slice
|
||||||
|
* is invalidated whenever the dynptr is invalidated.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* Pointer to the underlying dynptr data, NULL if the dynptr is
|
||||||
|
* read-only, if the dynptr is invalid, or if the offset and length
|
||||||
|
* is out of bounds.
|
||||||
|
*/
|
||||||
|
static void *(*bpf_dynptr_data)(struct bpf_dynptr *ptr, __u32 offset, __u32 len) = (void *) 203;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_tcp_raw_gen_syncookie_ipv4
|
||||||
|
*
|
||||||
|
* Try to issue a SYN cookie for the packet with corresponding
|
||||||
|
* IPv4/TCP headers, *iph* and *th*, without depending on a
|
||||||
|
* listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv4 header.
|
||||||
|
*
|
||||||
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
|
* contains the length of the TCP header (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* On success, lower 32 bits hold the generated SYN cookie in
|
||||||
|
* followed by 16 bits which hold the MSS value for that cookie,
|
||||||
|
* and the top 16 bits are unused.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EINVAL** if *th_len* is invalid.
|
||||||
|
*/
|
||||||
|
static __s64 (*bpf_tcp_raw_gen_syncookie_ipv4)(struct iphdr *iph, struct tcphdr *th, __u32 th_len) = (void *) 204;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_tcp_raw_gen_syncookie_ipv6
|
||||||
|
*
|
||||||
|
* Try to issue a SYN cookie for the packet with corresponding
|
||||||
|
* IPv6/TCP headers, *iph* and *th*, without depending on a
|
||||||
|
* listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv6 header.
|
||||||
|
*
|
||||||
|
* *th* points to the start of the TCP header, while *th_len*
|
||||||
|
* contains the length of the TCP header (at least
|
||||||
|
* **sizeof**\ (**struct tcphdr**)).
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* On success, lower 32 bits hold the generated SYN cookie in
|
||||||
|
* followed by 16 bits which hold the MSS value for that cookie,
|
||||||
|
* and the top 16 bits are unused.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EINVAL** if *th_len* is invalid.
|
||||||
|
*
|
||||||
|
* **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
|
||||||
|
*/
|
||||||
|
static __s64 (*bpf_tcp_raw_gen_syncookie_ipv6)(struct ipv6hdr *iph, struct tcphdr *th, __u32 th_len) = (void *) 205;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_tcp_raw_check_syncookie_ipv4
|
||||||
|
*
|
||||||
|
* Check whether *iph* and *th* contain a valid SYN cookie ACK
|
||||||
|
* without depending on a listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv4 header.
|
||||||
|
*
|
||||||
|
* *th* points to the TCP header.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 if *iph* and *th* are a valid SYN cookie ACK.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EACCES** if the SYN cookie is not valid.
|
||||||
|
*/
|
||||||
|
static long (*bpf_tcp_raw_check_syncookie_ipv4)(struct iphdr *iph, struct tcphdr *th) = (void *) 206;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bpf_tcp_raw_check_syncookie_ipv6
|
||||||
|
*
|
||||||
|
* Check whether *iph* and *th* contain a valid SYN cookie ACK
|
||||||
|
* without depending on a listening socket.
|
||||||
|
*
|
||||||
|
* *iph* points to the IPv6 header.
|
||||||
|
*
|
||||||
|
* *th* points to the TCP header.
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
* 0 if *iph* and *th* are a valid SYN cookie ACK.
|
||||||
|
*
|
||||||
|
* On failure, the returned value is one of the following:
|
||||||
|
*
|
||||||
|
* **-EACCES** if the SYN cookie is not valid.
|
||||||
|
*
|
||||||
|
* **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
|
||||||
|
*/
|
||||||
|
static long (*bpf_tcp_raw_check_syncookie_ipv6)(struct ipv6hdr *iph, struct tcphdr *th) = (void *) 207;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,30 @@
|
|||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compiler (optimization) barrier.
|
||||||
|
*/
|
||||||
|
#ifndef barrier
|
||||||
|
#define barrier() asm volatile("" ::: "memory")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Variable-specific compiler (optimization) barrier. It's a no-op which makes
|
||||||
|
* compiler believe that there is some black box modification of a given
|
||||||
|
* variable and thus prevents compiler from making extra assumption about its
|
||||||
|
* value and potential simplifications and optimizations on this variable.
|
||||||
|
*
|
||||||
|
* E.g., compiler might often delay or even omit 32-bit to 64-bit casting of
|
||||||
|
* a variable, making some code patterns unverifiable. Putting barrier_var()
|
||||||
|
* in place will ensure that cast is performed before the barrier_var()
|
||||||
|
* invocation, because compiler has to pessimistically assume that embedded
|
||||||
|
* asm section might perform some extra operations on that variable.
|
||||||
|
*
|
||||||
|
* This is a variable-specific variant of more global barrier().
|
||||||
|
*/
|
||||||
|
#ifndef barrier_var
|
||||||
|
#define barrier_var(var) asm volatile("" : "=r"(var) : "0"(var))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper macro to throw a compilation error if __bpf_unreachable() gets
|
* Helper macro to throw a compilation error if __bpf_unreachable() gets
|
||||||
* built into the resulting code. This works given BPF back end does not
|
* built into the resulting code. This works given BPF back end does not
|
||||||
@@ -149,6 +173,8 @@ enum libbpf_tristate {
|
|||||||
|
|
||||||
#define __kconfig __attribute__((section(".kconfig")))
|
#define __kconfig __attribute__((section(".kconfig")))
|
||||||
#define __ksym __attribute__((section(".ksyms")))
|
#define __ksym __attribute__((section(".ksyms")))
|
||||||
|
#define __kptr __attribute__((btf_type_tag("kptr")))
|
||||||
|
#define __kptr_ref __attribute__((btf_type_tag("kptr_ref")))
|
||||||
|
|
||||||
#ifndef ___bpf_concat
|
#ifndef ___bpf_concat
|
||||||
#define ___bpf_concat(a, b) a ## b
|
#define ___bpf_concat(a, b) a ## b
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
#elif defined(__TARGET_ARCH_riscv)
|
#elif defined(__TARGET_ARCH_riscv)
|
||||||
#define bpf_target_riscv
|
#define bpf_target_riscv
|
||||||
#define bpf_target_defined
|
#define bpf_target_defined
|
||||||
|
#elif defined(__TARGET_ARCH_arc)
|
||||||
|
#define bpf_target_arc
|
||||||
|
#define bpf_target_defined
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Fall back to what the compiler says */
|
/* Fall back to what the compiler says */
|
||||||
@@ -54,6 +57,9 @@
|
|||||||
#elif defined(__riscv) && __riscv_xlen == 64
|
#elif defined(__riscv) && __riscv_xlen == 64
|
||||||
#define bpf_target_riscv
|
#define bpf_target_riscv
|
||||||
#define bpf_target_defined
|
#define bpf_target_defined
|
||||||
|
#elif defined(__arc__)
|
||||||
|
#define bpf_target_arc
|
||||||
|
#define bpf_target_defined
|
||||||
#endif /* no compiler target */
|
#endif /* no compiler target */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -233,6 +239,23 @@ struct pt_regs___arm64 {
|
|||||||
/* riscv does not select ARCH_HAS_SYSCALL_WRAPPER. */
|
/* riscv does not select ARCH_HAS_SYSCALL_WRAPPER. */
|
||||||
#define PT_REGS_SYSCALL_REGS(ctx) ctx
|
#define PT_REGS_SYSCALL_REGS(ctx) ctx
|
||||||
|
|
||||||
|
#elif defined(bpf_target_arc)
|
||||||
|
|
||||||
|
/* arc provides struct user_pt_regs instead of struct pt_regs to userspace */
|
||||||
|
#define __PT_REGS_CAST(x) ((const struct user_regs_struct *)(x))
|
||||||
|
#define __PT_PARM1_REG scratch.r0
|
||||||
|
#define __PT_PARM2_REG scratch.r1
|
||||||
|
#define __PT_PARM3_REG scratch.r2
|
||||||
|
#define __PT_PARM4_REG scratch.r3
|
||||||
|
#define __PT_PARM5_REG scratch.r4
|
||||||
|
#define __PT_RET_REG scratch.blink
|
||||||
|
#define __PT_FP_REG __unsupported__
|
||||||
|
#define __PT_RC_REG scratch.r0
|
||||||
|
#define __PT_SP_REG scratch.sp
|
||||||
|
#define __PT_IP_REG scratch.ret
|
||||||
|
/* arc does not select ARCH_HAS_SYSCALL_WRAPPER. */
|
||||||
|
#define PT_REGS_SYSCALL_REGS(ctx) ctx
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(bpf_target_defined)
|
#if defined(bpf_target_defined)
|
||||||
|
|||||||
427
src/btf.c
427
src/btf.c
@@ -130,7 +130,7 @@ static inline __u64 ptr_to_u64(const void *ptr)
|
|||||||
|
|
||||||
/* Ensure given dynamically allocated memory region pointed to by *data* with
|
/* Ensure given dynamically allocated memory region pointed to by *data* with
|
||||||
* capacity of *cap_cnt* elements each taking *elem_sz* bytes has enough
|
* capacity of *cap_cnt* elements each taking *elem_sz* bytes has enough
|
||||||
* memory to accomodate *add_cnt* new elements, assuming *cur_cnt* elements
|
* memory to accommodate *add_cnt* new elements, assuming *cur_cnt* elements
|
||||||
* are already used. At most *max_cnt* elements can be ever allocated.
|
* are already used. At most *max_cnt* elements can be ever allocated.
|
||||||
* If necessary, memory is reallocated and all existing data is copied over,
|
* If necessary, memory is reallocated and all existing data is copied over,
|
||||||
* new pointer to the memory region is stored at *data, new memory region
|
* new pointer to the memory region is stored at *data, new memory region
|
||||||
@@ -305,6 +305,8 @@ static int btf_type_size(const struct btf_type *t)
|
|||||||
return base_size + sizeof(__u32);
|
return base_size + sizeof(__u32);
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
return base_size + vlen * sizeof(struct btf_enum);
|
return base_size + vlen * sizeof(struct btf_enum);
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
|
return base_size + vlen * sizeof(struct btf_enum64);
|
||||||
case BTF_KIND_ARRAY:
|
case BTF_KIND_ARRAY:
|
||||||
return base_size + sizeof(struct btf_array);
|
return base_size + sizeof(struct btf_array);
|
||||||
case BTF_KIND_STRUCT:
|
case BTF_KIND_STRUCT:
|
||||||
@@ -334,6 +336,7 @@ static void btf_bswap_type_base(struct btf_type *t)
|
|||||||
static int btf_bswap_type_rest(struct btf_type *t)
|
static int btf_bswap_type_rest(struct btf_type *t)
|
||||||
{
|
{
|
||||||
struct btf_var_secinfo *v;
|
struct btf_var_secinfo *v;
|
||||||
|
struct btf_enum64 *e64;
|
||||||
struct btf_member *m;
|
struct btf_member *m;
|
||||||
struct btf_array *a;
|
struct btf_array *a;
|
||||||
struct btf_param *p;
|
struct btf_param *p;
|
||||||
@@ -361,6 +364,13 @@ static int btf_bswap_type_rest(struct btf_type *t)
|
|||||||
e->val = bswap_32(e->val);
|
e->val = bswap_32(e->val);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
|
for (i = 0, e64 = btf_enum64(t); i < vlen; i++, e64++) {
|
||||||
|
e64->name_off = bswap_32(e64->name_off);
|
||||||
|
e64->val_lo32 = bswap_32(e64->val_lo32);
|
||||||
|
e64->val_hi32 = bswap_32(e64->val_hi32);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
case BTF_KIND_ARRAY:
|
case BTF_KIND_ARRAY:
|
||||||
a = btf_array(t);
|
a = btf_array(t);
|
||||||
a->type = bswap_32(a->type);
|
a->type = bswap_32(a->type);
|
||||||
@@ -438,11 +448,6 @@ static int btf_parse_type_sec(struct btf *btf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__u32 btf__get_nr_types(const struct btf *btf)
|
|
||||||
{
|
|
||||||
return btf->start_id + btf->nr_types - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
__u32 btf__type_cnt(const struct btf *btf)
|
__u32 btf__type_cnt(const struct btf *btf)
|
||||||
{
|
{
|
||||||
return btf->start_id + btf->nr_types;
|
return btf->start_id + btf->nr_types;
|
||||||
@@ -472,9 +477,22 @@ const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id)
|
|||||||
|
|
||||||
static int determine_ptr_size(const struct btf *btf)
|
static int determine_ptr_size(const struct btf *btf)
|
||||||
{
|
{
|
||||||
|
static const char * const long_aliases[] = {
|
||||||
|
"long",
|
||||||
|
"long int",
|
||||||
|
"int long",
|
||||||
|
"unsigned long",
|
||||||
|
"long unsigned",
|
||||||
|
"unsigned long int",
|
||||||
|
"unsigned int long",
|
||||||
|
"long unsigned int",
|
||||||
|
"long int unsigned",
|
||||||
|
"int unsigned long",
|
||||||
|
"int long unsigned",
|
||||||
|
};
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
const char *name;
|
const char *name;
|
||||||
int i, n;
|
int i, j, n;
|
||||||
|
|
||||||
if (btf->base_btf && btf->base_btf->ptr_sz > 0)
|
if (btf->base_btf && btf->base_btf->ptr_sz > 0)
|
||||||
return btf->base_btf->ptr_sz;
|
return btf->base_btf->ptr_sz;
|
||||||
@@ -485,15 +503,16 @@ static int determine_ptr_size(const struct btf *btf)
|
|||||||
if (!btf_is_int(t))
|
if (!btf_is_int(t))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (t->size != 4 && t->size != 8)
|
||||||
|
continue;
|
||||||
|
|
||||||
name = btf__name_by_offset(btf, t->name_off);
|
name = btf__name_by_offset(btf, t->name_off);
|
||||||
if (!name)
|
if (!name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcmp(name, "long int") == 0 ||
|
for (j = 0; j < ARRAY_SIZE(long_aliases); j++) {
|
||||||
strcmp(name, "long unsigned int") == 0) {
|
if (strcmp(name, long_aliases[j]) == 0)
|
||||||
if (t->size != 4 && t->size != 8)
|
return t->size;
|
||||||
continue;
|
|
||||||
return t->size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,6 +616,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
|
|||||||
case BTF_KIND_STRUCT:
|
case BTF_KIND_STRUCT:
|
||||||
case BTF_KIND_UNION:
|
case BTF_KIND_UNION:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_DATASEC:
|
case BTF_KIND_DATASEC:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
size = t->size;
|
size = t->size;
|
||||||
@@ -644,6 +664,7 @@ int btf__align_of(const struct btf *btf, __u32 id)
|
|||||||
switch (kind) {
|
switch (kind) {
|
||||||
case BTF_KIND_INT:
|
case BTF_KIND_INT:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
return min(btf_ptr_sz(btf), (size_t)t->size);
|
return min(btf_ptr_sz(btf), (size_t)t->size);
|
||||||
case BTF_KIND_PTR:
|
case BTF_KIND_PTR:
|
||||||
@@ -1382,92 +1403,6 @@ struct btf *btf__load_from_kernel_by_id(__u32 id)
|
|||||||
return btf__load_from_kernel_by_id_split(id, NULL);
|
return btf__load_from_kernel_by_id_split(id, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int btf__get_from_id(__u32 id, struct btf **btf)
|
|
||||||
{
|
|
||||||
struct btf *res;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
*btf = NULL;
|
|
||||||
res = btf__load_from_kernel_by_id(id);
|
|
||||||
err = libbpf_get_error(res);
|
|
||||||
|
|
||||||
if (err)
|
|
||||||
return libbpf_err(err);
|
|
||||||
|
|
||||||
*btf = res;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
|
|
||||||
__u32 expected_key_size, __u32 expected_value_size,
|
|
||||||
__u32 *key_type_id, __u32 *value_type_id)
|
|
||||||
{
|
|
||||||
const struct btf_type *container_type;
|
|
||||||
const struct btf_member *key, *value;
|
|
||||||
const size_t max_name = 256;
|
|
||||||
char container_name[max_name];
|
|
||||||
__s64 key_size, value_size;
|
|
||||||
__s32 container_id;
|
|
||||||
|
|
||||||
if (snprintf(container_name, max_name, "____btf_map_%s", map_name) == max_name) {
|
|
||||||
pr_warn("map:%s length of '____btf_map_%s' is too long\n",
|
|
||||||
map_name, map_name);
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
container_id = btf__find_by_name(btf, container_name);
|
|
||||||
if (container_id < 0) {
|
|
||||||
pr_debug("map:%s container_name:%s cannot be found in BTF. Missing BPF_ANNOTATE_KV_PAIR?\n",
|
|
||||||
map_name, container_name);
|
|
||||||
return libbpf_err(container_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
container_type = btf__type_by_id(btf, container_id);
|
|
||||||
if (!container_type) {
|
|
||||||
pr_warn("map:%s cannot find BTF type for container_id:%u\n",
|
|
||||||
map_name, container_id);
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!btf_is_struct(container_type) || btf_vlen(container_type) < 2) {
|
|
||||||
pr_warn("map:%s container_name:%s is an invalid container struct\n",
|
|
||||||
map_name, container_name);
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
key = btf_members(container_type);
|
|
||||||
value = key + 1;
|
|
||||||
|
|
||||||
key_size = btf__resolve_size(btf, key->type);
|
|
||||||
if (key_size < 0) {
|
|
||||||
pr_warn("map:%s invalid BTF key_type_size\n", map_name);
|
|
||||||
return libbpf_err(key_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expected_key_size != key_size) {
|
|
||||||
pr_warn("map:%s btf_key_type_size:%u != map_def_key_size:%u\n",
|
|
||||||
map_name, (__u32)key_size, expected_key_size);
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
value_size = btf__resolve_size(btf, value->type);
|
|
||||||
if (value_size < 0) {
|
|
||||||
pr_warn("map:%s invalid BTF value_type_size\n", map_name);
|
|
||||||
return libbpf_err(value_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expected_value_size != value_size) {
|
|
||||||
pr_warn("map:%s btf_value_type_size:%u != map_def_value_size:%u\n",
|
|
||||||
map_name, (__u32)value_size, expected_value_size);
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
*key_type_id = key->type;
|
|
||||||
*value_type_id = value->type;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void btf_invalidate_raw_data(struct btf *btf)
|
static void btf_invalidate_raw_data(struct btf *btf)
|
||||||
{
|
{
|
||||||
if (btf->raw_data) {
|
if (btf->raw_data) {
|
||||||
@@ -2115,20 +2050,8 @@ int btf__add_field(struct btf *btf, const char *name, int type_id,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static int btf_add_enum_common(struct btf *btf, const char *name, __u32 byte_sz,
|
||||||
* Append new BTF_KIND_ENUM type with:
|
bool is_signed, __u8 kind)
|
||||||
* - *name* - name of the enum, can be NULL or empty for anonymous enums;
|
|
||||||
* - *byte_sz* - size of the enum, in bytes.
|
|
||||||
*
|
|
||||||
* Enum initially has no enum values in it (and corresponds to enum forward
|
|
||||||
* declaration). Enumerator values can be added by btf__add_enum_value()
|
|
||||||
* immediately after btf__add_enum() succeeds.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* - >0, type ID of newly added BTF type;
|
|
||||||
* - <0, on error.
|
|
||||||
*/
|
|
||||||
int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
|
|
||||||
{
|
{
|
||||||
struct btf_type *t;
|
struct btf_type *t;
|
||||||
int sz, name_off = 0;
|
int sz, name_off = 0;
|
||||||
@@ -2153,12 +2076,34 @@ int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
|
|||||||
|
|
||||||
/* start out with vlen=0; it will be adjusted when adding enum values */
|
/* start out with vlen=0; it will be adjusted when adding enum values */
|
||||||
t->name_off = name_off;
|
t->name_off = name_off;
|
||||||
t->info = btf_type_info(BTF_KIND_ENUM, 0, 0);
|
t->info = btf_type_info(kind, 0, is_signed);
|
||||||
t->size = byte_sz;
|
t->size = byte_sz;
|
||||||
|
|
||||||
return btf_commit_type(btf, sz);
|
return btf_commit_type(btf, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append new BTF_KIND_ENUM type with:
|
||||||
|
* - *name* - name of the enum, can be NULL or empty for anonymous enums;
|
||||||
|
* - *byte_sz* - size of the enum, in bytes.
|
||||||
|
*
|
||||||
|
* Enum initially has no enum values in it (and corresponds to enum forward
|
||||||
|
* declaration). Enumerator values can be added by btf__add_enum_value()
|
||||||
|
* immediately after btf__add_enum() succeeds.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* - >0, type ID of newly added BTF type;
|
||||||
|
* - <0, on error.
|
||||||
|
*/
|
||||||
|
int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* set the signedness to be unsigned, it will change to signed
|
||||||
|
* if any later enumerator is negative.
|
||||||
|
*/
|
||||||
|
return btf_add_enum_common(btf, name, byte_sz, false, BTF_KIND_ENUM);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Append new enum value for the current ENUM type with:
|
* Append new enum value for the current ENUM type with:
|
||||||
* - *name* - name of the enumerator value, can't be NULL or empty;
|
* - *name* - name of the enumerator value, can't be NULL or empty;
|
||||||
@@ -2206,6 +2151,82 @@ int btf__add_enum_value(struct btf *btf, const char *name, __s64 value)
|
|||||||
t = btf_last_type(btf);
|
t = btf_last_type(btf);
|
||||||
btf_type_inc_vlen(t);
|
btf_type_inc_vlen(t);
|
||||||
|
|
||||||
|
/* if negative value, set signedness to signed */
|
||||||
|
if (value < 0)
|
||||||
|
t->info = btf_type_info(btf_kind(t), btf_vlen(t), true);
|
||||||
|
|
||||||
|
btf->hdr->type_len += sz;
|
||||||
|
btf->hdr->str_off += sz;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append new BTF_KIND_ENUM64 type with:
|
||||||
|
* - *name* - name of the enum, can be NULL or empty for anonymous enums;
|
||||||
|
* - *byte_sz* - size of the enum, in bytes.
|
||||||
|
* - *is_signed* - whether the enum values are signed or not;
|
||||||
|
*
|
||||||
|
* Enum initially has no enum values in it (and corresponds to enum forward
|
||||||
|
* declaration). Enumerator values can be added by btf__add_enum64_value()
|
||||||
|
* immediately after btf__add_enum64() succeeds.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* - >0, type ID of newly added BTF type;
|
||||||
|
* - <0, on error.
|
||||||
|
*/
|
||||||
|
int btf__add_enum64(struct btf *btf, const char *name, __u32 byte_sz,
|
||||||
|
bool is_signed)
|
||||||
|
{
|
||||||
|
return btf_add_enum_common(btf, name, byte_sz, is_signed,
|
||||||
|
BTF_KIND_ENUM64);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append new enum value for the current ENUM64 type with:
|
||||||
|
* - *name* - name of the enumerator value, can't be NULL or empty;
|
||||||
|
* - *value* - integer value corresponding to enum value *name*;
|
||||||
|
* Returns:
|
||||||
|
* - 0, on success;
|
||||||
|
* - <0, on error.
|
||||||
|
*/
|
||||||
|
int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value)
|
||||||
|
{
|
||||||
|
struct btf_enum64 *v;
|
||||||
|
struct btf_type *t;
|
||||||
|
int sz, name_off;
|
||||||
|
|
||||||
|
/* last type should be BTF_KIND_ENUM64 */
|
||||||
|
if (btf->nr_types == 0)
|
||||||
|
return libbpf_err(-EINVAL);
|
||||||
|
t = btf_last_type(btf);
|
||||||
|
if (!btf_is_enum64(t))
|
||||||
|
return libbpf_err(-EINVAL);
|
||||||
|
|
||||||
|
/* non-empty name */
|
||||||
|
if (!name || !name[0])
|
||||||
|
return libbpf_err(-EINVAL);
|
||||||
|
|
||||||
|
/* decompose and invalidate raw data */
|
||||||
|
if (btf_ensure_modifiable(btf))
|
||||||
|
return libbpf_err(-ENOMEM);
|
||||||
|
|
||||||
|
sz = sizeof(struct btf_enum64);
|
||||||
|
v = btf_add_type_mem(btf, sz);
|
||||||
|
if (!v)
|
||||||
|
return libbpf_err(-ENOMEM);
|
||||||
|
|
||||||
|
name_off = btf__add_str(btf, name);
|
||||||
|
if (name_off < 0)
|
||||||
|
return name_off;
|
||||||
|
|
||||||
|
v->name_off = name_off;
|
||||||
|
v->val_lo32 = (__u32)value;
|
||||||
|
v->val_hi32 = value >> 32;
|
||||||
|
|
||||||
|
/* update parent type's vlen */
|
||||||
|
t = btf_last_type(btf);
|
||||||
|
btf_type_inc_vlen(t);
|
||||||
|
|
||||||
btf->hdr->type_len += sz;
|
btf->hdr->type_len += sz;
|
||||||
btf->hdr->str_off += sz;
|
btf->hdr->str_off += sz;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2626,6 +2647,7 @@ static int btf_ext_setup_info(struct btf_ext *btf_ext,
|
|||||||
const struct btf_ext_info_sec *sinfo;
|
const struct btf_ext_info_sec *sinfo;
|
||||||
struct btf_ext_info *ext_info;
|
struct btf_ext_info *ext_info;
|
||||||
__u32 info_left, record_size;
|
__u32 info_left, record_size;
|
||||||
|
size_t sec_cnt = 0;
|
||||||
/* The start of the info sec (including the __u32 record_size). */
|
/* The start of the info sec (including the __u32 record_size). */
|
||||||
void *info;
|
void *info;
|
||||||
|
|
||||||
@@ -2689,8 +2711,7 @@ static int btf_ext_setup_info(struct btf_ext *btf_ext,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_record_size = sec_hdrlen +
|
total_record_size = sec_hdrlen + (__u64)num_records * record_size;
|
||||||
(__u64)num_records * record_size;
|
|
||||||
if (info_left < total_record_size) {
|
if (info_left < total_record_size) {
|
||||||
pr_debug("%s section has incorrect num_records in .BTF.ext\n",
|
pr_debug("%s section has incorrect num_records in .BTF.ext\n",
|
||||||
ext_sec->desc);
|
ext_sec->desc);
|
||||||
@@ -2699,12 +2720,14 @@ static int btf_ext_setup_info(struct btf_ext *btf_ext,
|
|||||||
|
|
||||||
info_left -= total_record_size;
|
info_left -= total_record_size;
|
||||||
sinfo = (void *)sinfo + total_record_size;
|
sinfo = (void *)sinfo + total_record_size;
|
||||||
|
sec_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ext_info = ext_sec->ext_info;
|
ext_info = ext_sec->ext_info;
|
||||||
ext_info->len = ext_sec->len - sizeof(__u32);
|
ext_info->len = ext_sec->len - sizeof(__u32);
|
||||||
ext_info->rec_size = record_size;
|
ext_info->rec_size = record_size;
|
||||||
ext_info->info = info + sizeof(__u32);
|
ext_info->info = info + sizeof(__u32);
|
||||||
|
ext_info->sec_cnt = sec_cnt;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2788,6 +2811,9 @@ void btf_ext__free(struct btf_ext *btf_ext)
|
|||||||
{
|
{
|
||||||
if (IS_ERR_OR_NULL(btf_ext))
|
if (IS_ERR_OR_NULL(btf_ext))
|
||||||
return;
|
return;
|
||||||
|
free(btf_ext->func_info.sec_idxs);
|
||||||
|
free(btf_ext->line_info.sec_idxs);
|
||||||
|
free(btf_ext->core_relo_info.sec_idxs);
|
||||||
free(btf_ext->data);
|
free(btf_ext->data);
|
||||||
free(btf_ext);
|
free(btf_ext);
|
||||||
}
|
}
|
||||||
@@ -2826,10 +2852,8 @@ struct btf_ext *btf_ext__new(const __u8 *data, __u32 size)
|
|||||||
if (err)
|
if (err)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len)) {
|
if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len))
|
||||||
err = -EINVAL;
|
goto done; /* skip core relos parsing */
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = btf_ext_setup_core_relos(btf_ext);
|
err = btf_ext_setup_core_relos(btf_ext);
|
||||||
if (err)
|
if (err)
|
||||||
@@ -2850,81 +2874,6 @@ const void *btf_ext__get_raw_data(const struct btf_ext *btf_ext, __u32 *size)
|
|||||||
return btf_ext->data;
|
return btf_ext->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int btf_ext_reloc_info(const struct btf *btf,
|
|
||||||
const struct btf_ext_info *ext_info,
|
|
||||||
const char *sec_name, __u32 insns_cnt,
|
|
||||||
void **info, __u32 *cnt)
|
|
||||||
{
|
|
||||||
__u32 sec_hdrlen = sizeof(struct btf_ext_info_sec);
|
|
||||||
__u32 i, record_size, existing_len, records_len;
|
|
||||||
struct btf_ext_info_sec *sinfo;
|
|
||||||
const char *info_sec_name;
|
|
||||||
__u64 remain_len;
|
|
||||||
void *data;
|
|
||||||
|
|
||||||
record_size = ext_info->rec_size;
|
|
||||||
sinfo = ext_info->info;
|
|
||||||
remain_len = ext_info->len;
|
|
||||||
while (remain_len > 0) {
|
|
||||||
records_len = sinfo->num_info * record_size;
|
|
||||||
info_sec_name = btf__name_by_offset(btf, sinfo->sec_name_off);
|
|
||||||
if (strcmp(info_sec_name, sec_name)) {
|
|
||||||
remain_len -= sec_hdrlen + records_len;
|
|
||||||
sinfo = (void *)sinfo + sec_hdrlen + records_len;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
existing_len = (*cnt) * record_size;
|
|
||||||
data = realloc(*info, existing_len + records_len);
|
|
||||||
if (!data)
|
|
||||||
return libbpf_err(-ENOMEM);
|
|
||||||
|
|
||||||
memcpy(data + existing_len, sinfo->data, records_len);
|
|
||||||
/* adjust insn_off only, the rest data will be passed
|
|
||||||
* to the kernel.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < sinfo->num_info; i++) {
|
|
||||||
__u32 *insn_off;
|
|
||||||
|
|
||||||
insn_off = data + existing_len + (i * record_size);
|
|
||||||
*insn_off = *insn_off / sizeof(struct bpf_insn) + insns_cnt;
|
|
||||||
}
|
|
||||||
*info = data;
|
|
||||||
*cnt += sinfo->num_info;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return libbpf_err(-ENOENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
int btf_ext__reloc_func_info(const struct btf *btf,
|
|
||||||
const struct btf_ext *btf_ext,
|
|
||||||
const char *sec_name, __u32 insns_cnt,
|
|
||||||
void **func_info, __u32 *cnt)
|
|
||||||
{
|
|
||||||
return btf_ext_reloc_info(btf, &btf_ext->func_info, sec_name,
|
|
||||||
insns_cnt, func_info, cnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
int btf_ext__reloc_line_info(const struct btf *btf,
|
|
||||||
const struct btf_ext *btf_ext,
|
|
||||||
const char *sec_name, __u32 insns_cnt,
|
|
||||||
void **line_info, __u32 *cnt)
|
|
||||||
{
|
|
||||||
return btf_ext_reloc_info(btf, &btf_ext->line_info, sec_name,
|
|
||||||
insns_cnt, line_info, cnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext)
|
|
||||||
{
|
|
||||||
return btf_ext->func_info.rec_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
__u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext)
|
|
||||||
{
|
|
||||||
return btf_ext->line_info.rec_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct btf_dedup;
|
struct btf_dedup;
|
||||||
|
|
||||||
static struct btf_dedup *btf_dedup_new(struct btf *btf, const struct btf_dedup_opts *opts);
|
static struct btf_dedup *btf_dedup_new(struct btf *btf, const struct btf_dedup_opts *opts);
|
||||||
@@ -3074,9 +3023,7 @@ static int btf_dedup_remap_types(struct btf_dedup *d);
|
|||||||
* deduplicating structs/unions is described in greater details in comments for
|
* deduplicating structs/unions is described in greater details in comments for
|
||||||
* `btf_dedup_is_equiv` function.
|
* `btf_dedup_is_equiv` function.
|
||||||
*/
|
*/
|
||||||
|
int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts)
|
||||||
DEFAULT_VERSION(btf__dedup_v0_6_0, btf__dedup, LIBBPF_0.6.0)
|
|
||||||
int btf__dedup_v0_6_0(struct btf *btf, const struct btf_dedup_opts *opts)
|
|
||||||
{
|
{
|
||||||
struct btf_dedup *d;
|
struct btf_dedup *d;
|
||||||
int err;
|
int err;
|
||||||
@@ -3136,19 +3083,6 @@ done:
|
|||||||
return libbpf_err(err);
|
return libbpf_err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPAT_VERSION(btf__dedup_deprecated, btf__dedup, LIBBPF_0.0.2)
|
|
||||||
int btf__dedup_deprecated(struct btf *btf, struct btf_ext *btf_ext, const void *unused_opts)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(btf_dedup_opts, opts, .btf_ext = btf_ext);
|
|
||||||
|
|
||||||
if (unused_opts) {
|
|
||||||
pr_warn("please use new version of btf__dedup() that supports options\n");
|
|
||||||
return libbpf_err(-ENOTSUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
return btf__dedup(btf, &opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BTF_UNPROCESSED_ID ((__u32)-1)
|
#define BTF_UNPROCESSED_ID ((__u32)-1)
|
||||||
#define BTF_IN_PROGRESS_ID ((__u32)-2)
|
#define BTF_IN_PROGRESS_ID ((__u32)-2)
|
||||||
|
|
||||||
@@ -3467,7 +3401,7 @@ static bool btf_equal_int_tag(struct btf_type *t1, struct btf_type *t2)
|
|||||||
return info1 == info2;
|
return info1 == info2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate type signature hash of ENUM. */
|
/* Calculate type signature hash of ENUM/ENUM64. */
|
||||||
static long btf_hash_enum(struct btf_type *t)
|
static long btf_hash_enum(struct btf_type *t)
|
||||||
{
|
{
|
||||||
long h;
|
long h;
|
||||||
@@ -3501,9 +3435,31 @@ static bool btf_equal_enum(struct btf_type *t1, struct btf_type *t2)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool btf_equal_enum64(struct btf_type *t1, struct btf_type *t2)
|
||||||
|
{
|
||||||
|
const struct btf_enum64 *m1, *m2;
|
||||||
|
__u16 vlen;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!btf_equal_common(t1, t2))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vlen = btf_vlen(t1);
|
||||||
|
m1 = btf_enum64(t1);
|
||||||
|
m2 = btf_enum64(t2);
|
||||||
|
for (i = 0; i < vlen; i++) {
|
||||||
|
if (m1->name_off != m2->name_off || m1->val_lo32 != m2->val_lo32 ||
|
||||||
|
m1->val_hi32 != m2->val_hi32)
|
||||||
|
return false;
|
||||||
|
m1++;
|
||||||
|
m2++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool btf_is_enum_fwd(struct btf_type *t)
|
static inline bool btf_is_enum_fwd(struct btf_type *t)
|
||||||
{
|
{
|
||||||
return btf_is_enum(t) && btf_vlen(t) == 0;
|
return btf_is_any_enum(t) && btf_vlen(t) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2)
|
static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2)
|
||||||
@@ -3516,6 +3472,17 @@ static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2)
|
|||||||
t1->size == t2->size;
|
t1->size == t2->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool btf_compat_enum64(struct btf_type *t1, struct btf_type *t2)
|
||||||
|
{
|
||||||
|
if (!btf_is_enum_fwd(t1) && !btf_is_enum_fwd(t2))
|
||||||
|
return btf_equal_enum64(t1, t2);
|
||||||
|
|
||||||
|
/* ignore vlen when comparing */
|
||||||
|
return t1->name_off == t2->name_off &&
|
||||||
|
(t1->info & ~0xffff) == (t2->info & ~0xffff) &&
|
||||||
|
t1->size == t2->size;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate type signature hash of STRUCT/UNION, ignoring referenced type IDs,
|
* Calculate type signature hash of STRUCT/UNION, ignoring referenced type IDs,
|
||||||
* as referenced type IDs equivalence is established separately during type
|
* as referenced type IDs equivalence is established separately during type
|
||||||
@@ -3728,6 +3695,7 @@ static int btf_dedup_prep(struct btf_dedup *d)
|
|||||||
h = btf_hash_int_decl_tag(t);
|
h = btf_hash_int_decl_tag(t);
|
||||||
break;
|
break;
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
h = btf_hash_enum(t);
|
h = btf_hash_enum(t);
|
||||||
break;
|
break;
|
||||||
case BTF_KIND_STRUCT:
|
case BTF_KIND_STRUCT:
|
||||||
@@ -3817,6 +3785,27 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
|
h = btf_hash_enum(t);
|
||||||
|
for_each_dedup_cand(d, hash_entry, h) {
|
||||||
|
cand_id = (__u32)(long)hash_entry->value;
|
||||||
|
cand = btf_type_by_id(d->btf, cand_id);
|
||||||
|
if (btf_equal_enum64(t, cand)) {
|
||||||
|
new_id = cand_id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (btf_compat_enum64(t, cand)) {
|
||||||
|
if (btf_is_enum_fwd(t)) {
|
||||||
|
/* resolve fwd to full enum */
|
||||||
|
new_id = cand_id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* resolve canonical enum fwd to full enum */
|
||||||
|
d->map[cand_id] = type_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
h = btf_hash_common(t);
|
h = btf_hash_common(t);
|
||||||
@@ -4112,6 +4101,9 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
|
|||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
return btf_compat_enum(cand_type, canon_type);
|
return btf_compat_enum(cand_type, canon_type);
|
||||||
|
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
|
return btf_compat_enum64(cand_type, canon_type);
|
||||||
|
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
return btf_equal_common(cand_type, canon_type);
|
return btf_equal_common(cand_type, canon_type);
|
||||||
@@ -4714,6 +4706,7 @@ int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ct
|
|||||||
case BTF_KIND_INT:
|
case BTF_KIND_INT:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
@@ -4808,6 +4801,16 @@ int btf_type_visit_str_offs(struct btf_type *t, str_off_visit_fn visit, void *ct
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case BTF_KIND_ENUM64: {
|
||||||
|
struct btf_enum64 *m = btf_enum64(t);
|
||||||
|
|
||||||
|
for (i = 0, n = btf_vlen(t); i < n; i++, m++) {
|
||||||
|
err = visit(&m->name_off, ctx);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case BTF_KIND_FUNC_PROTO: {
|
case BTF_KIND_FUNC_PROTO: {
|
||||||
struct btf_param *m = btf_params(t);
|
struct btf_param *m = btf_params(t);
|
||||||
|
|
||||||
|
|||||||
118
src/btf.h
118
src/btf.h
@@ -120,20 +120,12 @@ LIBBPF_API struct btf *libbpf_find_kernel_btf(void);
|
|||||||
|
|
||||||
LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id);
|
LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id);
|
||||||
LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf);
|
LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf);
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 6, "use btf__load_from_kernel_by_id instead")
|
|
||||||
LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
|
|
||||||
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 6, "intended for internal libbpf use only")
|
|
||||||
LIBBPF_API int btf__finalize_data(struct bpf_object *obj, struct btf *btf);
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 6, "use btf__load_into_kernel instead")
|
|
||||||
LIBBPF_API int btf__load(struct btf *btf);
|
|
||||||
LIBBPF_API int btf__load_into_kernel(struct btf *btf);
|
LIBBPF_API int btf__load_into_kernel(struct btf *btf);
|
||||||
LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
|
LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
|
||||||
const char *type_name);
|
const char *type_name);
|
||||||
LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf,
|
LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf,
|
||||||
const char *type_name, __u32 kind);
|
const char *type_name, __u32 kind);
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use btf__type_cnt() instead; note that btf__get_nr_types() == btf__type_cnt() - 1")
|
|
||||||
LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf);
|
|
||||||
LIBBPF_API __u32 btf__type_cnt(const struct btf *btf);
|
LIBBPF_API __u32 btf__type_cnt(const struct btf *btf);
|
||||||
LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf);
|
LIBBPF_API const struct btf *btf__base_btf(const struct btf *btf);
|
||||||
LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
|
LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
|
||||||
@@ -150,29 +142,10 @@ LIBBPF_API void btf__set_fd(struct btf *btf, int fd);
|
|||||||
LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size);
|
LIBBPF_API const void *btf__raw_data(const struct btf *btf, __u32 *size);
|
||||||
LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
|
LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
|
||||||
LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset);
|
LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset);
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "this API is not necessary when BTF-defined maps are used")
|
|
||||||
LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
|
|
||||||
__u32 expected_key_size,
|
|
||||||
__u32 expected_value_size,
|
|
||||||
__u32 *key_type_id, __u32 *value_type_id);
|
|
||||||
|
|
||||||
LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size);
|
LIBBPF_API struct btf_ext *btf_ext__new(const __u8 *data, __u32 size);
|
||||||
LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
|
LIBBPF_API void btf_ext__free(struct btf_ext *btf_ext);
|
||||||
LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size);
|
LIBBPF_API const void *btf_ext__raw_data(const struct btf_ext *btf_ext, __u32 *size);
|
||||||
LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_func_info was never meant as a public API and has wrong assumptions embedded in it; it will be removed in the future libbpf versions")
|
|
||||||
int btf_ext__reloc_func_info(const struct btf *btf,
|
|
||||||
const struct btf_ext *btf_ext,
|
|
||||||
const char *sec_name, __u32 insns_cnt,
|
|
||||||
void **func_info, __u32 *cnt);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_line_info was never meant as a public API and has wrong assumptions embedded in it; it will be removed in the future libbpf versions")
|
|
||||||
int btf_ext__reloc_line_info(const struct btf *btf,
|
|
||||||
const struct btf_ext *btf_ext,
|
|
||||||
const char *sec_name, __u32 insns_cnt,
|
|
||||||
void **line_info, __u32 *cnt);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_func_info is deprecated; write custom func_info parsing to fetch rec_size")
|
|
||||||
__u32 btf_ext__func_info_rec_size(const struct btf_ext *btf_ext);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED("btf_ext__reloc_line_info is deprecated; write custom line_info parsing to fetch rec_size")
|
|
||||||
__u32 btf_ext__line_info_rec_size(const struct btf_ext *btf_ext);
|
|
||||||
|
|
||||||
LIBBPF_API int btf__find_str(struct btf *btf, const char *s);
|
LIBBPF_API int btf__find_str(struct btf *btf, const char *s);
|
||||||
LIBBPF_API int btf__add_str(struct btf *btf, const char *s);
|
LIBBPF_API int btf__add_str(struct btf *btf, const char *s);
|
||||||
@@ -215,6 +188,8 @@ LIBBPF_API int btf__add_field(struct btf *btf, const char *name, int field_type_
|
|||||||
/* enum construction APIs */
|
/* enum construction APIs */
|
||||||
LIBBPF_API int btf__add_enum(struct btf *btf, const char *name, __u32 bytes_sz);
|
LIBBPF_API int btf__add_enum(struct btf *btf, const char *name, __u32 bytes_sz);
|
||||||
LIBBPF_API int btf__add_enum_value(struct btf *btf, const char *name, __s64 value);
|
LIBBPF_API int btf__add_enum_value(struct btf *btf, const char *name, __s64 value);
|
||||||
|
LIBBPF_API int btf__add_enum64(struct btf *btf, const char *name, __u32 bytes_sz, bool is_signed);
|
||||||
|
LIBBPF_API int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value);
|
||||||
|
|
||||||
enum btf_fwd_kind {
|
enum btf_fwd_kind {
|
||||||
BTF_FWD_STRUCT = 0,
|
BTF_FWD_STRUCT = 0,
|
||||||
@@ -257,22 +232,12 @@ struct btf_dedup_opts {
|
|||||||
|
|
||||||
LIBBPF_API int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts);
|
LIBBPF_API int btf__dedup(struct btf *btf, const struct btf_dedup_opts *opts);
|
||||||
|
|
||||||
LIBBPF_API int btf__dedup_v0_6_0(struct btf *btf, const struct btf_dedup_opts *opts);
|
|
||||||
|
|
||||||
LIBBPF_DEPRECATED_SINCE(0, 7, "use btf__dedup() instead")
|
|
||||||
LIBBPF_API int btf__dedup_deprecated(struct btf *btf, struct btf_ext *btf_ext, const void *opts);
|
|
||||||
#define btf__dedup(...) ___libbpf_overload(___btf_dedup, __VA_ARGS__)
|
|
||||||
#define ___btf_dedup3(btf, btf_ext, opts) btf__dedup_deprecated(btf, btf_ext, opts)
|
|
||||||
#define ___btf_dedup2(btf, opts) btf__dedup(btf, opts)
|
|
||||||
|
|
||||||
struct btf_dump;
|
struct btf_dump;
|
||||||
|
|
||||||
struct btf_dump_opts {
|
struct btf_dump_opts {
|
||||||
union {
|
size_t sz;
|
||||||
size_t sz;
|
|
||||||
void *ctx; /* DEPRECATED: will be gone in v1.0 */
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
#define btf_dump_opts__last_field sz
|
||||||
|
|
||||||
typedef void (*btf_dump_printf_fn_t)(void *ctx, const char *fmt, va_list args);
|
typedef void (*btf_dump_printf_fn_t)(void *ctx, const char *fmt, va_list args);
|
||||||
|
|
||||||
@@ -281,51 +246,6 @@ LIBBPF_API struct btf_dump *btf_dump__new(const struct btf *btf,
|
|||||||
void *ctx,
|
void *ctx,
|
||||||
const struct btf_dump_opts *opts);
|
const struct btf_dump_opts *opts);
|
||||||
|
|
||||||
LIBBPF_API struct btf_dump *btf_dump__new_v0_6_0(const struct btf *btf,
|
|
||||||
btf_dump_printf_fn_t printf_fn,
|
|
||||||
void *ctx,
|
|
||||||
const struct btf_dump_opts *opts);
|
|
||||||
|
|
||||||
LIBBPF_API struct btf_dump *btf_dump__new_deprecated(const struct btf *btf,
|
|
||||||
const struct btf_ext *btf_ext,
|
|
||||||
const struct btf_dump_opts *opts,
|
|
||||||
btf_dump_printf_fn_t printf_fn);
|
|
||||||
|
|
||||||
/* Choose either btf_dump__new() or btf_dump__new_deprecated() based on the
|
|
||||||
* type of 4th argument. If it's btf_dump's print callback, use deprecated
|
|
||||||
* API; otherwise, choose the new btf_dump__new(). ___libbpf_override()
|
|
||||||
* doesn't work here because both variants have 4 input arguments.
|
|
||||||
*
|
|
||||||
* (void *) casts are necessary to avoid compilation warnings about type
|
|
||||||
* mismatches, because even though __builtin_choose_expr() only ever evaluates
|
|
||||||
* one side the other side still has to satisfy type constraints (this is
|
|
||||||
* compiler implementation limitation which might be lifted eventually,
|
|
||||||
* according to the documentation). So passing struct btf_ext in place of
|
|
||||||
* btf_dump_printf_fn_t would be generating compilation warning. Casting to
|
|
||||||
* void * avoids this issue.
|
|
||||||
*
|
|
||||||
* Also, two type compatibility checks for a function and function pointer are
|
|
||||||
* required because passing function reference into btf_dump__new() as
|
|
||||||
* btf_dump__new(..., my_callback, ...) and as btf_dump__new(...,
|
|
||||||
* &my_callback, ...) (not explicit ampersand in the latter case) actually
|
|
||||||
* differs as far as __builtin_types_compatible_p() is concerned. Thus two
|
|
||||||
* checks are combined to detect callback argument.
|
|
||||||
*
|
|
||||||
* The rest works just like in case of ___libbpf_override() usage with symbol
|
|
||||||
* versioning.
|
|
||||||
*
|
|
||||||
* C++ compilers don't support __builtin_types_compatible_p(), so at least
|
|
||||||
* don't screw up compilation for them and let C++ users pick btf_dump__new
|
|
||||||
* vs btf_dump__new_deprecated explicitly.
|
|
||||||
*/
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#define btf_dump__new(a1, a2, a3, a4) __builtin_choose_expr( \
|
|
||||||
__builtin_types_compatible_p(typeof(a4), btf_dump_printf_fn_t) || \
|
|
||||||
__builtin_types_compatible_p(typeof(a4), void(void *, const char *, va_list)), \
|
|
||||||
btf_dump__new_deprecated((void *)a1, (void *)a2, (void *)a3, (void *)a4), \
|
|
||||||
btf_dump__new((void *)a1, (void *)a2, (void *)a3, (void *)a4))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LIBBPF_API void btf_dump__free(struct btf_dump *d);
|
LIBBPF_API void btf_dump__free(struct btf_dump *d);
|
||||||
|
|
||||||
LIBBPF_API int btf_dump__dump_type(struct btf_dump *d, __u32 id);
|
LIBBPF_API int btf_dump__dump_type(struct btf_dump *d, __u32 id);
|
||||||
@@ -393,9 +313,10 @@ btf_dump__dump_type_data(struct btf_dump *d, __u32 id,
|
|||||||
#ifndef BTF_KIND_FLOAT
|
#ifndef BTF_KIND_FLOAT
|
||||||
#define BTF_KIND_FLOAT 16 /* Floating point */
|
#define BTF_KIND_FLOAT 16 /* Floating point */
|
||||||
#endif
|
#endif
|
||||||
/* The kernel header switched to enums, so these two were never #defined */
|
/* The kernel header switched to enums, so the following were never #defined */
|
||||||
#define BTF_KIND_DECL_TAG 17 /* Decl Tag */
|
#define BTF_KIND_DECL_TAG 17 /* Decl Tag */
|
||||||
#define BTF_KIND_TYPE_TAG 18 /* Type Tag */
|
#define BTF_KIND_TYPE_TAG 18 /* Type Tag */
|
||||||
|
#define BTF_KIND_ENUM64 19 /* Enum for up-to 64bit values */
|
||||||
|
|
||||||
static inline __u16 btf_kind(const struct btf_type *t)
|
static inline __u16 btf_kind(const struct btf_type *t)
|
||||||
{
|
{
|
||||||
@@ -454,6 +375,11 @@ static inline bool btf_is_enum(const struct btf_type *t)
|
|||||||
return btf_kind(t) == BTF_KIND_ENUM;
|
return btf_kind(t) == BTF_KIND_ENUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool btf_is_enum64(const struct btf_type *t)
|
||||||
|
{
|
||||||
|
return btf_kind(t) == BTF_KIND_ENUM64;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool btf_is_fwd(const struct btf_type *t)
|
static inline bool btf_is_fwd(const struct btf_type *t)
|
||||||
{
|
{
|
||||||
return btf_kind(t) == BTF_KIND_FWD;
|
return btf_kind(t) == BTF_KIND_FWD;
|
||||||
@@ -524,6 +450,18 @@ static inline bool btf_is_type_tag(const struct btf_type *t)
|
|||||||
return btf_kind(t) == BTF_KIND_TYPE_TAG;
|
return btf_kind(t) == BTF_KIND_TYPE_TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool btf_is_any_enum(const struct btf_type *t)
|
||||||
|
{
|
||||||
|
return btf_is_enum(t) || btf_is_enum64(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool btf_kind_core_compat(const struct btf_type *t1,
|
||||||
|
const struct btf_type *t2)
|
||||||
|
{
|
||||||
|
return btf_kind(t1) == btf_kind(t2) ||
|
||||||
|
(btf_is_any_enum(t1) && btf_is_any_enum(t2));
|
||||||
|
}
|
||||||
|
|
||||||
static inline __u8 btf_int_encoding(const struct btf_type *t)
|
static inline __u8 btf_int_encoding(const struct btf_type *t)
|
||||||
{
|
{
|
||||||
return BTF_INT_ENCODING(*(__u32 *)(t + 1));
|
return BTF_INT_ENCODING(*(__u32 *)(t + 1));
|
||||||
@@ -549,6 +487,16 @@ static inline struct btf_enum *btf_enum(const struct btf_type *t)
|
|||||||
return (struct btf_enum *)(t + 1);
|
return (struct btf_enum *)(t + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct btf_enum64 *btf_enum64(const struct btf_type *t)
|
||||||
|
{
|
||||||
|
return (struct btf_enum64 *)(t + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline __u64 btf_enum64_value(const struct btf_enum64 *e)
|
||||||
|
{
|
||||||
|
return ((__u64)e->val_hi32 << 32) | e->val_lo32;
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct btf_member *btf_members(const struct btf_type *t)
|
static inline struct btf_member *btf_members(const struct btf_type *t)
|
||||||
{
|
{
|
||||||
return (struct btf_member *)(t + 1);
|
return (struct btf_member *)(t + 1);
|
||||||
|
|||||||
165
src/btf_dump.c
165
src/btf_dump.c
@@ -144,15 +144,17 @@ static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...)
|
|||||||
static int btf_dump_mark_referenced(struct btf_dump *d);
|
static int btf_dump_mark_referenced(struct btf_dump *d);
|
||||||
static int btf_dump_resize(struct btf_dump *d);
|
static int btf_dump_resize(struct btf_dump *d);
|
||||||
|
|
||||||
DEFAULT_VERSION(btf_dump__new_v0_6_0, btf_dump__new, LIBBPF_0.6.0)
|
struct btf_dump *btf_dump__new(const struct btf *btf,
|
||||||
struct btf_dump *btf_dump__new_v0_6_0(const struct btf *btf,
|
btf_dump_printf_fn_t printf_fn,
|
||||||
btf_dump_printf_fn_t printf_fn,
|
void *ctx,
|
||||||
void *ctx,
|
const struct btf_dump_opts *opts)
|
||||||
const struct btf_dump_opts *opts)
|
|
||||||
{
|
{
|
||||||
struct btf_dump *d;
|
struct btf_dump *d;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (!OPTS_VALID(opts, btf_dump_opts))
|
||||||
|
return libbpf_err_ptr(-EINVAL);
|
||||||
|
|
||||||
if (!printf_fn)
|
if (!printf_fn)
|
||||||
return libbpf_err_ptr(-EINVAL);
|
return libbpf_err_ptr(-EINVAL);
|
||||||
|
|
||||||
@@ -188,17 +190,6 @@ err:
|
|||||||
return libbpf_err_ptr(err);
|
return libbpf_err_ptr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPAT_VERSION(btf_dump__new_deprecated, btf_dump__new, LIBBPF_0.0.4)
|
|
||||||
struct btf_dump *btf_dump__new_deprecated(const struct btf *btf,
|
|
||||||
const struct btf_ext *btf_ext,
|
|
||||||
const struct btf_dump_opts *opts,
|
|
||||||
btf_dump_printf_fn_t printf_fn)
|
|
||||||
{
|
|
||||||
if (!printf_fn)
|
|
||||||
return libbpf_err_ptr(-EINVAL);
|
|
||||||
return btf_dump__new_v0_6_0(btf, printf_fn, opts ? opts->ctx : NULL, opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int btf_dump_resize(struct btf_dump *d)
|
static int btf_dump_resize(struct btf_dump *d)
|
||||||
{
|
{
|
||||||
int err, last_id = btf__type_cnt(d->btf) - 1;
|
int err, last_id = btf__type_cnt(d->btf) - 1;
|
||||||
@@ -318,6 +309,7 @@ static int btf_dump_mark_referenced(struct btf_dump *d)
|
|||||||
switch (btf_kind(t)) {
|
switch (btf_kind(t)) {
|
||||||
case BTF_KIND_INT:
|
case BTF_KIND_INT:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
break;
|
break;
|
||||||
@@ -538,6 +530,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
/*
|
/*
|
||||||
* non-anonymous or non-referenced enums are top-level
|
* non-anonymous or non-referenced enums are top-level
|
||||||
@@ -739,6 +732,7 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id)
|
|||||||
tstate->emit_state = EMITTED;
|
tstate->emit_state = EMITTED;
|
||||||
break;
|
break;
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
if (top_level_def) {
|
if (top_level_def) {
|
||||||
btf_dump_emit_enum_def(d, id, t, 0);
|
btf_dump_emit_enum_def(d, id, t, 0);
|
||||||
btf_dump_printf(d, ";\n\n");
|
btf_dump_printf(d, ";\n\n");
|
||||||
@@ -989,38 +983,81 @@ static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
|
|||||||
btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id));
|
btf_dump_printf(d, "enum %s", btf_dump_type_name(d, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void btf_dump_emit_enum32_val(struct btf_dump *d,
|
||||||
|
const struct btf_type *t,
|
||||||
|
int lvl, __u16 vlen)
|
||||||
|
{
|
||||||
|
const struct btf_enum *v = btf_enum(t);
|
||||||
|
bool is_signed = btf_kflag(t);
|
||||||
|
const char *fmt_str;
|
||||||
|
const char *name;
|
||||||
|
size_t dup_cnt;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < vlen; i++, v++) {
|
||||||
|
name = btf_name_of(d, v->name_off);
|
||||||
|
/* enumerators share namespace with typedef idents */
|
||||||
|
dup_cnt = btf_dump_name_dups(d, d->ident_names, name);
|
||||||
|
if (dup_cnt > 1) {
|
||||||
|
fmt_str = is_signed ? "\n%s%s___%zd = %d," : "\n%s%s___%zd = %u,";
|
||||||
|
btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, dup_cnt, v->val);
|
||||||
|
} else {
|
||||||
|
fmt_str = is_signed ? "\n%s%s = %d," : "\n%s%s = %u,";
|
||||||
|
btf_dump_printf(d, fmt_str, pfx(lvl + 1), name, v->val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btf_dump_emit_enum64_val(struct btf_dump *d,
|
||||||
|
const struct btf_type *t,
|
||||||
|
int lvl, __u16 vlen)
|
||||||
|
{
|
||||||
|
const struct btf_enum64 *v = btf_enum64(t);
|
||||||
|
bool is_signed = btf_kflag(t);
|
||||||
|
const char *fmt_str;
|
||||||
|
const char *name;
|
||||||
|
size_t dup_cnt;
|
||||||
|
__u64 val;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < vlen; i++, v++) {
|
||||||
|
name = btf_name_of(d, v->name_off);
|
||||||
|
dup_cnt = btf_dump_name_dups(d, d->ident_names, name);
|
||||||
|
val = btf_enum64_value(v);
|
||||||
|
if (dup_cnt > 1) {
|
||||||
|
fmt_str = is_signed ? "\n%s%s___%zd = %lldLL,"
|
||||||
|
: "\n%s%s___%zd = %lluULL,";
|
||||||
|
btf_dump_printf(d, fmt_str,
|
||||||
|
pfx(lvl + 1), name, dup_cnt,
|
||||||
|
(unsigned long long)val);
|
||||||
|
} else {
|
||||||
|
fmt_str = is_signed ? "\n%s%s = %lldLL,"
|
||||||
|
: "\n%s%s = %lluULL,";
|
||||||
|
btf_dump_printf(d, fmt_str,
|
||||||
|
pfx(lvl + 1), name,
|
||||||
|
(unsigned long long)val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
|
static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id,
|
||||||
const struct btf_type *t,
|
const struct btf_type *t,
|
||||||
int lvl)
|
int lvl)
|
||||||
{
|
{
|
||||||
const struct btf_enum *v = btf_enum(t);
|
|
||||||
__u16 vlen = btf_vlen(t);
|
__u16 vlen = btf_vlen(t);
|
||||||
const char *name;
|
|
||||||
size_t dup_cnt;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
btf_dump_printf(d, "enum%s%s",
|
btf_dump_printf(d, "enum%s%s",
|
||||||
t->name_off ? " " : "",
|
t->name_off ? " " : "",
|
||||||
btf_dump_type_name(d, id));
|
btf_dump_type_name(d, id));
|
||||||
|
|
||||||
if (vlen) {
|
if (!vlen)
|
||||||
btf_dump_printf(d, " {");
|
return;
|
||||||
for (i = 0; i < vlen; i++, v++) {
|
|
||||||
name = btf_name_of(d, v->name_off);
|
btf_dump_printf(d, " {");
|
||||||
/* enumerators share namespace with typedef idents */
|
if (btf_is_enum(t))
|
||||||
dup_cnt = btf_dump_name_dups(d, d->ident_names, name);
|
btf_dump_emit_enum32_val(d, t, lvl, vlen);
|
||||||
if (dup_cnt > 1) {
|
else
|
||||||
btf_dump_printf(d, "\n%s%s___%zu = %u,",
|
btf_dump_emit_enum64_val(d, t, lvl, vlen);
|
||||||
pfx(lvl + 1), name, dup_cnt,
|
btf_dump_printf(d, "\n%s}", pfx(lvl));
|
||||||
(__u32)v->val);
|
|
||||||
} else {
|
|
||||||
btf_dump_printf(d, "\n%s%s = %u,",
|
|
||||||
pfx(lvl + 1), name,
|
|
||||||
(__u32)v->val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
btf_dump_printf(d, "\n%s}", pfx(lvl));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
|
static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id,
|
||||||
@@ -1178,6 +1215,7 @@ skip_mod:
|
|||||||
break;
|
break;
|
||||||
case BTF_KIND_INT:
|
case BTF_KIND_INT:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
case BTF_KIND_STRUCT:
|
case BTF_KIND_STRUCT:
|
||||||
case BTF_KIND_UNION:
|
case BTF_KIND_UNION:
|
||||||
@@ -1312,6 +1350,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
|
|||||||
btf_dump_emit_struct_fwd(d, id, t);
|
btf_dump_emit_struct_fwd(d, id, t);
|
||||||
break;
|
break;
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
btf_dump_emit_mods(d, decls);
|
btf_dump_emit_mods(d, decls);
|
||||||
/* inline anonymous enum */
|
/* inline anonymous enum */
|
||||||
if (t->name_off == 0 && !d->skip_anon_defs)
|
if (t->name_off == 0 && !d->skip_anon_defs)
|
||||||
@@ -1505,6 +1544,11 @@ static const char *btf_dump_resolve_name(struct btf_dump *d, __u32 id,
|
|||||||
if (s->name_resolved)
|
if (s->name_resolved)
|
||||||
return *cached_name ? *cached_name : orig_name;
|
return *cached_name ? *cached_name : orig_name;
|
||||||
|
|
||||||
|
if (btf_is_fwd(t) || (btf_is_enum(t) && btf_vlen(t) == 0)) {
|
||||||
|
s->name_resolved = 1;
|
||||||
|
return orig_name;
|
||||||
|
}
|
||||||
|
|
||||||
dup_cnt = btf_dump_name_dups(d, name_map, orig_name);
|
dup_cnt = btf_dump_name_dups(d, name_map, orig_name);
|
||||||
if (dup_cnt > 1) {
|
if (dup_cnt > 1) {
|
||||||
const size_t max_len = 256;
|
const size_t max_len = 256;
|
||||||
@@ -1983,7 +2027,8 @@ static int btf_dump_get_enum_value(struct btf_dump *d,
|
|||||||
__u32 id,
|
__u32 id,
|
||||||
__s64 *value)
|
__s64 *value)
|
||||||
{
|
{
|
||||||
/* handle unaligned enum value */
|
bool is_signed = btf_kflag(t);
|
||||||
|
|
||||||
if (!ptr_is_aligned(d->btf, id, data)) {
|
if (!ptr_is_aligned(d->btf, id, data)) {
|
||||||
__u64 val;
|
__u64 val;
|
||||||
int err;
|
int err;
|
||||||
@@ -2000,13 +2045,13 @@ static int btf_dump_get_enum_value(struct btf_dump *d,
|
|||||||
*value = *(__s64 *)data;
|
*value = *(__s64 *)data;
|
||||||
return 0;
|
return 0;
|
||||||
case 4:
|
case 4:
|
||||||
*value = *(__s32 *)data;
|
*value = is_signed ? *(__s32 *)data : *(__u32 *)data;
|
||||||
return 0;
|
return 0;
|
||||||
case 2:
|
case 2:
|
||||||
*value = *(__s16 *)data;
|
*value = is_signed ? *(__s16 *)data : *(__u16 *)data;
|
||||||
return 0;
|
return 0;
|
||||||
case 1:
|
case 1:
|
||||||
*value = *(__s8 *)data;
|
*value = is_signed ? *(__s8 *)data : *(__u8 *)data;
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
pr_warn("unexpected size %d for enum, id:[%u]\n", t->size, id);
|
pr_warn("unexpected size %d for enum, id:[%u]\n", t->size, id);
|
||||||
@@ -2019,7 +2064,7 @@ static int btf_dump_enum_data(struct btf_dump *d,
|
|||||||
__u32 id,
|
__u32 id,
|
||||||
const void *data)
|
const void *data)
|
||||||
{
|
{
|
||||||
const struct btf_enum *e;
|
bool is_signed;
|
||||||
__s64 value;
|
__s64 value;
|
||||||
int i, err;
|
int i, err;
|
||||||
|
|
||||||
@@ -2027,14 +2072,31 @@ static int btf_dump_enum_data(struct btf_dump *d,
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
for (i = 0, e = btf_enum(t); i < btf_vlen(t); i++, e++) {
|
is_signed = btf_kflag(t);
|
||||||
if (value != e->val)
|
if (btf_is_enum(t)) {
|
||||||
continue;
|
const struct btf_enum *e;
|
||||||
btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
btf_dump_type_values(d, "%d", value);
|
for (i = 0, e = btf_enum(t); i < btf_vlen(t); i++, e++) {
|
||||||
|
if (value != e->val)
|
||||||
|
continue;
|
||||||
|
btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
btf_dump_type_values(d, is_signed ? "%d" : "%u", value);
|
||||||
|
} else {
|
||||||
|
const struct btf_enum64 *e;
|
||||||
|
|
||||||
|
for (i = 0, e = btf_enum64(t); i < btf_vlen(t); i++, e++) {
|
||||||
|
if (value != btf_enum64_value(e))
|
||||||
|
continue;
|
||||||
|
btf_dump_type_values(d, "%s", btf_name_of(d, e->name_off));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
btf_dump_type_values(d, is_signed ? "%lldLL" : "%lluULL",
|
||||||
|
(unsigned long long)value);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2094,6 +2156,7 @@ static int btf_dump_type_data_check_overflow(struct btf_dump *d,
|
|||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
case BTF_KIND_PTR:
|
case BTF_KIND_PTR:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
if (data + bits_offset / 8 + size > d->typed_dump->data_end)
|
if (data + bits_offset / 8 + size > d->typed_dump->data_end)
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
break;
|
break;
|
||||||
@@ -2198,6 +2261,7 @@ static int btf_dump_type_data_check_zero(struct btf_dump *d,
|
|||||||
return -ENODATA;
|
return -ENODATA;
|
||||||
}
|
}
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
err = btf_dump_get_enum_value(d, t, data, id, &value);
|
err = btf_dump_get_enum_value(d, t, data, id, &value);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
@@ -2270,6 +2334,7 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
|
|||||||
err = btf_dump_struct_data(d, t, id, data);
|
err = btf_dump_struct_data(d, t, id, data);
|
||||||
break;
|
break;
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
/* handle bitfield and int enum values */
|
/* handle bitfield and int enum values */
|
||||||
if (bit_sz) {
|
if (bit_sz) {
|
||||||
__u64 print_num;
|
__u64 print_num;
|
||||||
|
|||||||
@@ -1043,18 +1043,27 @@ void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *pvalue,
|
|||||||
value = add_data(gen, pvalue, value_size);
|
value = add_data(gen, pvalue, value_size);
|
||||||
key = add_data(gen, &zero, sizeof(zero));
|
key = add_data(gen, &zero, sizeof(zero));
|
||||||
|
|
||||||
/* if (map_desc[map_idx].initial_value)
|
/* if (map_desc[map_idx].initial_value) {
|
||||||
* copy_from_user(value, initial_value, value_size);
|
* if (ctx->flags & BPF_SKEL_KERNEL)
|
||||||
|
* bpf_probe_read_kernel(value, value_size, initial_value);
|
||||||
|
* else
|
||||||
|
* bpf_copy_from_user(value, value_size, initial_value);
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
emit(gen, BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_6,
|
emit(gen, BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_6,
|
||||||
sizeof(struct bpf_loader_ctx) +
|
sizeof(struct bpf_loader_ctx) +
|
||||||
sizeof(struct bpf_map_desc) * map_idx +
|
sizeof(struct bpf_map_desc) * map_idx +
|
||||||
offsetof(struct bpf_map_desc, initial_value)));
|
offsetof(struct bpf_map_desc, initial_value)));
|
||||||
emit(gen, BPF_JMP_IMM(BPF_JEQ, BPF_REG_3, 0, 4));
|
emit(gen, BPF_JMP_IMM(BPF_JEQ, BPF_REG_3, 0, 8));
|
||||||
emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_1, BPF_PSEUDO_MAP_IDX_VALUE,
|
emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_1, BPF_PSEUDO_MAP_IDX_VALUE,
|
||||||
0, 0, 0, value));
|
0, 0, 0, value));
|
||||||
emit(gen, BPF_MOV64_IMM(BPF_REG_2, value_size));
|
emit(gen, BPF_MOV64_IMM(BPF_REG_2, value_size));
|
||||||
|
emit(gen, BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_6,
|
||||||
|
offsetof(struct bpf_loader_ctx, flags)));
|
||||||
|
emit(gen, BPF_JMP_IMM(BPF_JSET, BPF_REG_0, BPF_SKEL_KERNEL, 2));
|
||||||
emit(gen, BPF_EMIT_CALL(BPF_FUNC_copy_from_user));
|
emit(gen, BPF_EMIT_CALL(BPF_FUNC_copy_from_user));
|
||||||
|
emit(gen, BPF_JMP_IMM(BPF_JA, 0, 0, 1));
|
||||||
|
emit(gen, BPF_EMIT_CALL(BPF_FUNC_probe_read_kernel));
|
||||||
|
|
||||||
map_update_attr = add_data(gen, &attr, attr_size);
|
map_update_attr = add_data(gen, &attr, attr_size);
|
||||||
move_blob2blob(gen, attr_field(map_update_attr, map_fd), 4,
|
move_blob2blob(gen, attr_field(map_update_attr, map_fd), 4,
|
||||||
|
|||||||
3737
src/libbpf.c
3737
src/libbpf.c
File diff suppressed because it is too large
Load Diff
933
src/libbpf.h
933
src/libbpf.h
File diff suppressed because it is too large
Load Diff
142
src/libbpf.map
142
src/libbpf.map
@@ -1,29 +1,14 @@
|
|||||||
LIBBPF_0.0.1 {
|
LIBBPF_0.0.1 {
|
||||||
global:
|
global:
|
||||||
bpf_btf_get_fd_by_id;
|
bpf_btf_get_fd_by_id;
|
||||||
bpf_create_map;
|
|
||||||
bpf_create_map_in_map;
|
|
||||||
bpf_create_map_in_map_node;
|
|
||||||
bpf_create_map_name;
|
|
||||||
bpf_create_map_node;
|
|
||||||
bpf_create_map_xattr;
|
|
||||||
bpf_load_btf;
|
|
||||||
bpf_load_program;
|
|
||||||
bpf_load_program_xattr;
|
|
||||||
bpf_map__btf_key_type_id;
|
bpf_map__btf_key_type_id;
|
||||||
bpf_map__btf_value_type_id;
|
bpf_map__btf_value_type_id;
|
||||||
bpf_map__def;
|
|
||||||
bpf_map__fd;
|
bpf_map__fd;
|
||||||
bpf_map__is_offload_neutral;
|
|
||||||
bpf_map__name;
|
bpf_map__name;
|
||||||
bpf_map__next;
|
|
||||||
bpf_map__pin;
|
bpf_map__pin;
|
||||||
bpf_map__prev;
|
|
||||||
bpf_map__priv;
|
|
||||||
bpf_map__reuse_fd;
|
bpf_map__reuse_fd;
|
||||||
bpf_map__set_ifindex;
|
bpf_map__set_ifindex;
|
||||||
bpf_map__set_inner_map_fd;
|
bpf_map__set_inner_map_fd;
|
||||||
bpf_map__set_priv;
|
|
||||||
bpf_map__unpin;
|
bpf_map__unpin;
|
||||||
bpf_map_delete_elem;
|
bpf_map_delete_elem;
|
||||||
bpf_map_get_fd_by_id;
|
bpf_map_get_fd_by_id;
|
||||||
@@ -38,79 +23,37 @@ LIBBPF_0.0.1 {
|
|||||||
bpf_object__btf_fd;
|
bpf_object__btf_fd;
|
||||||
bpf_object__close;
|
bpf_object__close;
|
||||||
bpf_object__find_map_by_name;
|
bpf_object__find_map_by_name;
|
||||||
bpf_object__find_map_by_offset;
|
|
||||||
bpf_object__find_program_by_title;
|
|
||||||
bpf_object__kversion;
|
bpf_object__kversion;
|
||||||
bpf_object__load;
|
bpf_object__load;
|
||||||
bpf_object__name;
|
bpf_object__name;
|
||||||
bpf_object__next;
|
|
||||||
bpf_object__open;
|
bpf_object__open;
|
||||||
bpf_object__open_buffer;
|
|
||||||
bpf_object__open_xattr;
|
|
||||||
bpf_object__pin;
|
bpf_object__pin;
|
||||||
bpf_object__pin_maps;
|
bpf_object__pin_maps;
|
||||||
bpf_object__pin_programs;
|
bpf_object__pin_programs;
|
||||||
bpf_object__priv;
|
|
||||||
bpf_object__set_priv;
|
|
||||||
bpf_object__unload;
|
|
||||||
bpf_object__unpin_maps;
|
bpf_object__unpin_maps;
|
||||||
bpf_object__unpin_programs;
|
bpf_object__unpin_programs;
|
||||||
bpf_perf_event_read_simple;
|
|
||||||
bpf_prog_attach;
|
bpf_prog_attach;
|
||||||
bpf_prog_detach;
|
bpf_prog_detach;
|
||||||
bpf_prog_detach2;
|
bpf_prog_detach2;
|
||||||
bpf_prog_get_fd_by_id;
|
bpf_prog_get_fd_by_id;
|
||||||
bpf_prog_get_next_id;
|
bpf_prog_get_next_id;
|
||||||
bpf_prog_load;
|
|
||||||
bpf_prog_load_xattr;
|
|
||||||
bpf_prog_query;
|
bpf_prog_query;
|
||||||
bpf_prog_test_run;
|
|
||||||
bpf_prog_test_run_xattr;
|
|
||||||
bpf_program__fd;
|
bpf_program__fd;
|
||||||
bpf_program__is_kprobe;
|
|
||||||
bpf_program__is_perf_event;
|
|
||||||
bpf_program__is_raw_tracepoint;
|
|
||||||
bpf_program__is_sched_act;
|
|
||||||
bpf_program__is_sched_cls;
|
|
||||||
bpf_program__is_socket_filter;
|
|
||||||
bpf_program__is_tracepoint;
|
|
||||||
bpf_program__is_xdp;
|
|
||||||
bpf_program__load;
|
|
||||||
bpf_program__next;
|
|
||||||
bpf_program__nth_fd;
|
|
||||||
bpf_program__pin;
|
bpf_program__pin;
|
||||||
bpf_program__pin_instance;
|
|
||||||
bpf_program__prev;
|
|
||||||
bpf_program__priv;
|
|
||||||
bpf_program__set_expected_attach_type;
|
bpf_program__set_expected_attach_type;
|
||||||
bpf_program__set_ifindex;
|
bpf_program__set_ifindex;
|
||||||
bpf_program__set_kprobe;
|
|
||||||
bpf_program__set_perf_event;
|
|
||||||
bpf_program__set_prep;
|
|
||||||
bpf_program__set_priv;
|
|
||||||
bpf_program__set_raw_tracepoint;
|
|
||||||
bpf_program__set_sched_act;
|
|
||||||
bpf_program__set_sched_cls;
|
|
||||||
bpf_program__set_socket_filter;
|
|
||||||
bpf_program__set_tracepoint;
|
|
||||||
bpf_program__set_type;
|
bpf_program__set_type;
|
||||||
bpf_program__set_xdp;
|
|
||||||
bpf_program__title;
|
|
||||||
bpf_program__unload;
|
bpf_program__unload;
|
||||||
bpf_program__unpin;
|
bpf_program__unpin;
|
||||||
bpf_program__unpin_instance;
|
|
||||||
bpf_prog_linfo__free;
|
bpf_prog_linfo__free;
|
||||||
bpf_prog_linfo__new;
|
bpf_prog_linfo__new;
|
||||||
bpf_prog_linfo__lfind_addr_func;
|
bpf_prog_linfo__lfind_addr_func;
|
||||||
bpf_prog_linfo__lfind;
|
bpf_prog_linfo__lfind;
|
||||||
bpf_raw_tracepoint_open;
|
bpf_raw_tracepoint_open;
|
||||||
bpf_set_link_xdp_fd;
|
|
||||||
bpf_task_fd_query;
|
bpf_task_fd_query;
|
||||||
bpf_verify_program;
|
|
||||||
btf__fd;
|
btf__fd;
|
||||||
btf__find_by_name;
|
btf__find_by_name;
|
||||||
btf__free;
|
btf__free;
|
||||||
btf__get_from_id;
|
|
||||||
btf__name_by_offset;
|
btf__name_by_offset;
|
||||||
btf__new;
|
btf__new;
|
||||||
btf__resolve_size;
|
btf__resolve_size;
|
||||||
@@ -127,48 +70,24 @@ LIBBPF_0.0.1 {
|
|||||||
|
|
||||||
LIBBPF_0.0.2 {
|
LIBBPF_0.0.2 {
|
||||||
global:
|
global:
|
||||||
bpf_probe_helper;
|
|
||||||
bpf_probe_map_type;
|
|
||||||
bpf_probe_prog_type;
|
|
||||||
bpf_map__resize;
|
|
||||||
bpf_map_lookup_elem_flags;
|
bpf_map_lookup_elem_flags;
|
||||||
bpf_object__btf;
|
bpf_object__btf;
|
||||||
bpf_object__find_map_fd_by_name;
|
bpf_object__find_map_fd_by_name;
|
||||||
bpf_get_link_xdp_id;
|
|
||||||
btf__dedup;
|
|
||||||
btf__get_map_kv_tids;
|
|
||||||
btf__get_nr_types;
|
|
||||||
btf__get_raw_data;
|
btf__get_raw_data;
|
||||||
btf__load;
|
|
||||||
btf_ext__free;
|
btf_ext__free;
|
||||||
btf_ext__func_info_rec_size;
|
|
||||||
btf_ext__get_raw_data;
|
btf_ext__get_raw_data;
|
||||||
btf_ext__line_info_rec_size;
|
|
||||||
btf_ext__new;
|
btf_ext__new;
|
||||||
btf_ext__reloc_func_info;
|
|
||||||
btf_ext__reloc_line_info;
|
|
||||||
xsk_umem__create;
|
|
||||||
xsk_socket__create;
|
|
||||||
xsk_umem__delete;
|
|
||||||
xsk_socket__delete;
|
|
||||||
xsk_umem__fd;
|
|
||||||
xsk_socket__fd;
|
|
||||||
bpf_program__get_prog_info_linear;
|
|
||||||
bpf_program__bpil_addr_to_offs;
|
|
||||||
bpf_program__bpil_offs_to_addr;
|
|
||||||
} LIBBPF_0.0.1;
|
} LIBBPF_0.0.1;
|
||||||
|
|
||||||
LIBBPF_0.0.3 {
|
LIBBPF_0.0.3 {
|
||||||
global:
|
global:
|
||||||
bpf_map__is_internal;
|
bpf_map__is_internal;
|
||||||
bpf_map_freeze;
|
bpf_map_freeze;
|
||||||
btf__finalize_data;
|
|
||||||
} LIBBPF_0.0.2;
|
} LIBBPF_0.0.2;
|
||||||
|
|
||||||
LIBBPF_0.0.4 {
|
LIBBPF_0.0.4 {
|
||||||
global:
|
global:
|
||||||
bpf_link__destroy;
|
bpf_link__destroy;
|
||||||
bpf_object__load_xattr;
|
|
||||||
bpf_program__attach_kprobe;
|
bpf_program__attach_kprobe;
|
||||||
bpf_program__attach_perf_event;
|
bpf_program__attach_perf_event;
|
||||||
bpf_program__attach_raw_tracepoint;
|
bpf_program__attach_raw_tracepoint;
|
||||||
@@ -176,14 +95,10 @@ LIBBPF_0.0.4 {
|
|||||||
bpf_program__attach_uprobe;
|
bpf_program__attach_uprobe;
|
||||||
btf_dump__dump_type;
|
btf_dump__dump_type;
|
||||||
btf_dump__free;
|
btf_dump__free;
|
||||||
btf_dump__new;
|
|
||||||
btf__parse_elf;
|
btf__parse_elf;
|
||||||
libbpf_num_possible_cpus;
|
libbpf_num_possible_cpus;
|
||||||
perf_buffer__free;
|
perf_buffer__free;
|
||||||
perf_buffer__new;
|
|
||||||
perf_buffer__new_raw;
|
|
||||||
perf_buffer__poll;
|
perf_buffer__poll;
|
||||||
xsk_umem__create;
|
|
||||||
} LIBBPF_0.0.3;
|
} LIBBPF_0.0.3;
|
||||||
|
|
||||||
LIBBPF_0.0.5 {
|
LIBBPF_0.0.5 {
|
||||||
@@ -193,7 +108,6 @@ LIBBPF_0.0.5 {
|
|||||||
|
|
||||||
LIBBPF_0.0.6 {
|
LIBBPF_0.0.6 {
|
||||||
global:
|
global:
|
||||||
bpf_get_link_xdp_info;
|
|
||||||
bpf_map__get_pin_path;
|
bpf_map__get_pin_path;
|
||||||
bpf_map__is_pinned;
|
bpf_map__is_pinned;
|
||||||
bpf_map__set_pin_path;
|
bpf_map__set_pin_path;
|
||||||
@@ -202,9 +116,6 @@ LIBBPF_0.0.6 {
|
|||||||
bpf_program__attach_trace;
|
bpf_program__attach_trace;
|
||||||
bpf_program__get_expected_attach_type;
|
bpf_program__get_expected_attach_type;
|
||||||
bpf_program__get_type;
|
bpf_program__get_type;
|
||||||
bpf_program__is_tracing;
|
|
||||||
bpf_program__set_tracing;
|
|
||||||
bpf_program__size;
|
|
||||||
btf__find_by_name_kind;
|
btf__find_by_name_kind;
|
||||||
libbpf_find_vmlinux_btf_id;
|
libbpf_find_vmlinux_btf_id;
|
||||||
} LIBBPF_0.0.5;
|
} LIBBPF_0.0.5;
|
||||||
@@ -224,14 +135,8 @@ LIBBPF_0.0.7 {
|
|||||||
bpf_object__detach_skeleton;
|
bpf_object__detach_skeleton;
|
||||||
bpf_object__load_skeleton;
|
bpf_object__load_skeleton;
|
||||||
bpf_object__open_skeleton;
|
bpf_object__open_skeleton;
|
||||||
bpf_probe_large_insn_limit;
|
|
||||||
bpf_prog_attach_xattr;
|
|
||||||
bpf_program__attach;
|
bpf_program__attach;
|
||||||
bpf_program__name;
|
bpf_program__name;
|
||||||
bpf_program__is_extension;
|
|
||||||
bpf_program__is_struct_ops;
|
|
||||||
bpf_program__set_extension;
|
|
||||||
bpf_program__set_struct_ops;
|
|
||||||
btf__align_of;
|
btf__align_of;
|
||||||
libbpf_find_kernel_btf;
|
libbpf_find_kernel_btf;
|
||||||
} LIBBPF_0.0.6;
|
} LIBBPF_0.0.6;
|
||||||
@@ -250,10 +155,7 @@ LIBBPF_0.0.8 {
|
|||||||
bpf_prog_attach_opts;
|
bpf_prog_attach_opts;
|
||||||
bpf_program__attach_cgroup;
|
bpf_program__attach_cgroup;
|
||||||
bpf_program__attach_lsm;
|
bpf_program__attach_lsm;
|
||||||
bpf_program__is_lsm;
|
|
||||||
bpf_program__set_attach_target;
|
bpf_program__set_attach_target;
|
||||||
bpf_program__set_lsm;
|
|
||||||
bpf_set_link_xdp_fd_opts;
|
|
||||||
} LIBBPF_0.0.7;
|
} LIBBPF_0.0.7;
|
||||||
|
|
||||||
LIBBPF_0.0.9 {
|
LIBBPF_0.0.9 {
|
||||||
@@ -291,9 +193,7 @@ LIBBPF_0.1.0 {
|
|||||||
bpf_map__value_size;
|
bpf_map__value_size;
|
||||||
bpf_program__attach_xdp;
|
bpf_program__attach_xdp;
|
||||||
bpf_program__autoload;
|
bpf_program__autoload;
|
||||||
bpf_program__is_sk_lookup;
|
|
||||||
bpf_program__set_autoload;
|
bpf_program__set_autoload;
|
||||||
bpf_program__set_sk_lookup;
|
|
||||||
btf__parse;
|
btf__parse;
|
||||||
btf__parse_raw;
|
btf__parse_raw;
|
||||||
btf__pointer_size;
|
btf__pointer_size;
|
||||||
@@ -336,7 +236,6 @@ LIBBPF_0.2.0 {
|
|||||||
perf_buffer__buffer_fd;
|
perf_buffer__buffer_fd;
|
||||||
perf_buffer__epoll_fd;
|
perf_buffer__epoll_fd;
|
||||||
perf_buffer__consume_buffer;
|
perf_buffer__consume_buffer;
|
||||||
xsk_socket__create_shared;
|
|
||||||
} LIBBPF_0.1.0;
|
} LIBBPF_0.1.0;
|
||||||
|
|
||||||
LIBBPF_0.3.0 {
|
LIBBPF_0.3.0 {
|
||||||
@@ -348,8 +247,6 @@ LIBBPF_0.3.0 {
|
|||||||
btf__new_empty_split;
|
btf__new_empty_split;
|
||||||
btf__new_split;
|
btf__new_split;
|
||||||
ring_buffer__epoll_fd;
|
ring_buffer__epoll_fd;
|
||||||
xsk_setup_xdp_prog;
|
|
||||||
xsk_socket__update_xskmap;
|
|
||||||
} LIBBPF_0.2.0;
|
} LIBBPF_0.2.0;
|
||||||
|
|
||||||
LIBBPF_0.4.0 {
|
LIBBPF_0.4.0 {
|
||||||
@@ -397,7 +294,6 @@ LIBBPF_0.6.0 {
|
|||||||
bpf_object__next_program;
|
bpf_object__next_program;
|
||||||
bpf_object__prev_map;
|
bpf_object__prev_map;
|
||||||
bpf_object__prev_program;
|
bpf_object__prev_program;
|
||||||
bpf_prog_load_deprecated;
|
|
||||||
bpf_prog_load;
|
bpf_prog_load;
|
||||||
bpf_program__flags;
|
bpf_program__flags;
|
||||||
bpf_program__insn_cnt;
|
bpf_program__insn_cnt;
|
||||||
@@ -407,18 +303,14 @@ LIBBPF_0.6.0 {
|
|||||||
btf__add_decl_tag;
|
btf__add_decl_tag;
|
||||||
btf__add_type_tag;
|
btf__add_type_tag;
|
||||||
btf__dedup;
|
btf__dedup;
|
||||||
btf__dedup_deprecated;
|
|
||||||
btf__raw_data;
|
btf__raw_data;
|
||||||
btf__type_cnt;
|
btf__type_cnt;
|
||||||
btf_dump__new;
|
btf_dump__new;
|
||||||
btf_dump__new_deprecated;
|
|
||||||
libbpf_major_version;
|
libbpf_major_version;
|
||||||
libbpf_minor_version;
|
libbpf_minor_version;
|
||||||
libbpf_version_string;
|
libbpf_version_string;
|
||||||
perf_buffer__new;
|
perf_buffer__new;
|
||||||
perf_buffer__new_deprecated;
|
|
||||||
perf_buffer__new_raw;
|
perf_buffer__new_raw;
|
||||||
perf_buffer__new_raw_deprecated;
|
|
||||||
} LIBBPF_0.5.0;
|
} LIBBPF_0.5.0;
|
||||||
|
|
||||||
LIBBPF_0.7.0 {
|
LIBBPF_0.7.0 {
|
||||||
@@ -434,8 +326,40 @@ LIBBPF_0.7.0 {
|
|||||||
bpf_xdp_detach;
|
bpf_xdp_detach;
|
||||||
bpf_xdp_query;
|
bpf_xdp_query;
|
||||||
bpf_xdp_query_id;
|
bpf_xdp_query_id;
|
||||||
|
btf_ext__raw_data;
|
||||||
libbpf_probe_bpf_helper;
|
libbpf_probe_bpf_helper;
|
||||||
libbpf_probe_bpf_map_type;
|
libbpf_probe_bpf_map_type;
|
||||||
libbpf_probe_bpf_prog_type;
|
libbpf_probe_bpf_prog_type;
|
||||||
libbpf_set_memlock_rlim_max;
|
libbpf_set_memlock_rlim;
|
||||||
|
} LIBBPF_0.6.0;
|
||||||
|
|
||||||
|
LIBBPF_0.8.0 {
|
||||||
|
global:
|
||||||
|
bpf_map__autocreate;
|
||||||
|
bpf_map__get_next_key;
|
||||||
|
bpf_map__delete_elem;
|
||||||
|
bpf_map__lookup_and_delete_elem;
|
||||||
|
bpf_map__lookup_elem;
|
||||||
|
bpf_map__set_autocreate;
|
||||||
|
bpf_map__update_elem;
|
||||||
|
bpf_map_delete_elem_flags;
|
||||||
|
bpf_object__destroy_subskeleton;
|
||||||
|
bpf_object__open_subskeleton;
|
||||||
|
bpf_program__attach_kprobe_multi_opts;
|
||||||
|
bpf_program__attach_trace_opts;
|
||||||
|
bpf_program__attach_usdt;
|
||||||
|
bpf_program__set_insns;
|
||||||
|
libbpf_register_prog_handler;
|
||||||
|
libbpf_unregister_prog_handler;
|
||||||
|
} LIBBPF_0.7.0;
|
||||||
|
|
||||||
|
LIBBPF_1.0.0 {
|
||||||
|
global:
|
||||||
|
bpf_prog_query_opts;
|
||||||
|
btf__add_enum64;
|
||||||
|
btf__add_enum64_value;
|
||||||
|
libbpf_bpf_attach_type_str;
|
||||||
|
libbpf_bpf_link_type_str;
|
||||||
|
libbpf_bpf_map_type_str;
|
||||||
|
libbpf_bpf_prog_type_str;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,20 +30,10 @@
|
|||||||
/* Add checks for other versions below when planning deprecation of API symbols
|
/* Add checks for other versions below when planning deprecation of API symbols
|
||||||
* with the LIBBPF_DEPRECATED_SINCE macro.
|
* with the LIBBPF_DEPRECATED_SINCE macro.
|
||||||
*/
|
*/
|
||||||
#if __LIBBPF_CURRENT_VERSION_GEQ(0, 6)
|
#if __LIBBPF_CURRENT_VERSION_GEQ(1, 0)
|
||||||
#define __LIBBPF_MARK_DEPRECATED_0_6(X) X
|
#define __LIBBPF_MARK_DEPRECATED_1_0(X) X
|
||||||
#else
|
#else
|
||||||
#define __LIBBPF_MARK_DEPRECATED_0_6(X)
|
#define __LIBBPF_MARK_DEPRECATED_1_0(X)
|
||||||
#endif
|
|
||||||
#if __LIBBPF_CURRENT_VERSION_GEQ(0, 7)
|
|
||||||
#define __LIBBPF_MARK_DEPRECATED_0_7(X) X
|
|
||||||
#else
|
|
||||||
#define __LIBBPF_MARK_DEPRECATED_0_7(X)
|
|
||||||
#endif
|
|
||||||
#if __LIBBPF_CURRENT_VERSION_GEQ(0, 8)
|
|
||||||
#define __LIBBPF_MARK_DEPRECATED_0_8(X) X
|
|
||||||
#else
|
|
||||||
#define __LIBBPF_MARK_DEPRECATED_0_8(X)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This set of internal macros allows to do "function overloading" based on
|
/* This set of internal macros allows to do "function overloading" based on
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "libbpf_legacy.h"
|
|
||||||
#include "relo_core.h"
|
#include "relo_core.h"
|
||||||
|
|
||||||
/* make sure libbpf doesn't use kernel-only integer typedefs */
|
/* make sure libbpf doesn't use kernel-only integer typedefs */
|
||||||
@@ -103,6 +102,17 @@
|
|||||||
#define str_has_pfx(str, pfx) \
|
#define str_has_pfx(str, pfx) \
|
||||||
(strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)
|
(strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)
|
||||||
|
|
||||||
|
/* suffix check */
|
||||||
|
static inline bool str_has_sfx(const char *str, const char *sfx)
|
||||||
|
{
|
||||||
|
size_t str_len = strlen(str);
|
||||||
|
size_t sfx_len = strlen(sfx);
|
||||||
|
|
||||||
|
if (sfx_len <= str_len)
|
||||||
|
return strcmp(str + str_len - sfx_len, sfx);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Symbol versioning is different between static and shared library.
|
/* Symbol versioning is different between static and shared library.
|
||||||
* Properly versioned symbols are needed for shared library, but
|
* Properly versioned symbols are needed for shared library, but
|
||||||
* only the symbol of the new version is needed for static library.
|
* only the symbol of the new version is needed for static library.
|
||||||
@@ -148,6 +158,15 @@ do { \
|
|||||||
#ifndef __has_builtin
|
#ifndef __has_builtin
|
||||||
#define __has_builtin(x) 0
|
#define __has_builtin(x) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct bpf_link {
|
||||||
|
int (*detach)(struct bpf_link *link);
|
||||||
|
void (*dealloc)(struct bpf_link *link);
|
||||||
|
char *pin_path; /* NULL, if not pinned */
|
||||||
|
int fd; /* hook FD, -1 if not applicable */
|
||||||
|
bool disconnected;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Re-implement glibc's reallocarray() for libbpf internal-only use.
|
* Re-implement glibc's reallocarray() for libbpf internal-only use.
|
||||||
* reallocarray(), unfortunately, is not available in all versions of glibc,
|
* reallocarray(), unfortunately, is not available in all versions of glibc,
|
||||||
@@ -329,6 +348,10 @@ enum kern_feature_id {
|
|||||||
FEAT_BTF_TYPE_TAG,
|
FEAT_BTF_TYPE_TAG,
|
||||||
/* memcg-based accounting for BPF maps and progs */
|
/* memcg-based accounting for BPF maps and progs */
|
||||||
FEAT_MEMCG_ACCOUNT,
|
FEAT_MEMCG_ACCOUNT,
|
||||||
|
/* BPF cookie (bpf_get_attach_cookie() BPF helper) support */
|
||||||
|
FEAT_BPF_COOKIE,
|
||||||
|
/* BTF_KIND_ENUM64 support and BTF_KIND_ENUM kflag support */
|
||||||
|
FEAT_BTF_ENUM64,
|
||||||
__FEAT_CNT,
|
__FEAT_CNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -354,6 +377,13 @@ struct btf_ext_info {
|
|||||||
void *info;
|
void *info;
|
||||||
__u32 rec_size;
|
__u32 rec_size;
|
||||||
__u32 len;
|
__u32 len;
|
||||||
|
/* optional (maintained internally by libbpf) mapping between .BTF.ext
|
||||||
|
* section and corresponding ELF section. This is used to join
|
||||||
|
* information like CO-RE relocation records with corresponding BPF
|
||||||
|
* programs defined in ELF sections
|
||||||
|
*/
|
||||||
|
__u32 *sec_idxs;
|
||||||
|
int sec_cnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define for_each_btf_ext_sec(seg, sec) \
|
#define for_each_btf_ext_sec(seg, sec) \
|
||||||
@@ -447,7 +477,10 @@ int btf_ext_visit_str_offs(struct btf_ext *btf_ext, str_off_visit_fn visit, void
|
|||||||
__s32 btf__find_by_name_kind_own(const struct btf *btf, const char *type_name,
|
__s32 btf__find_by_name_kind_own(const struct btf *btf, const char *type_name,
|
||||||
__u32 kind);
|
__u32 kind);
|
||||||
|
|
||||||
extern enum libbpf_strict_mode libbpf_mode;
|
typedef int (*kallsyms_cb_t)(unsigned long long sym_addr, char sym_type,
|
||||||
|
const char *sym_name, void *ctx);
|
||||||
|
|
||||||
|
int libbpf_kallsyms_parse(kallsyms_cb_t cb, void *arg);
|
||||||
|
|
||||||
/* handle direct returned errors */
|
/* handle direct returned errors */
|
||||||
static inline int libbpf_err(int ret)
|
static inline int libbpf_err(int ret)
|
||||||
@@ -462,12 +495,8 @@ static inline int libbpf_err(int ret)
|
|||||||
*/
|
*/
|
||||||
static inline int libbpf_err_errno(int ret)
|
static inline int libbpf_err_errno(int ret)
|
||||||
{
|
{
|
||||||
if (libbpf_mode & LIBBPF_STRICT_DIRECT_ERRS)
|
/* errno is already assumed to be set on error */
|
||||||
/* errno is already assumed to be set on error */
|
return ret < 0 ? -errno : ret;
|
||||||
return ret < 0 ? -errno : ret;
|
|
||||||
|
|
||||||
/* legacy: on error return -1 directly and don't touch errno */
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle error for pointer-returning APIs, err is assumed to be < 0 always */
|
/* handle error for pointer-returning APIs, err is assumed to be < 0 always */
|
||||||
@@ -475,12 +504,7 @@ static inline void *libbpf_err_ptr(int err)
|
|||||||
{
|
{
|
||||||
/* set errno on error, this doesn't break anything */
|
/* set errno on error, this doesn't break anything */
|
||||||
errno = -err;
|
errno = -err;
|
||||||
|
return NULL;
|
||||||
if (libbpf_mode & LIBBPF_STRICT_CLEAN_PTRS)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* legacy: encode err as ptr */
|
|
||||||
return ERR_PTR(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle pointer-returning APIs' error handling */
|
/* handle pointer-returning APIs' error handling */
|
||||||
@@ -490,11 +514,7 @@ static inline void *libbpf_ptr(void *ret)
|
|||||||
if (IS_ERR(ret))
|
if (IS_ERR(ret))
|
||||||
errno = -PTR_ERR(ret);
|
errno = -PTR_ERR(ret);
|
||||||
|
|
||||||
if (libbpf_mode & LIBBPF_STRICT_CLEAN_PTRS)
|
return IS_ERR(ret) ? NULL : ret;
|
||||||
return IS_ERR(ret) ? NULL : ret;
|
|
||||||
|
|
||||||
/* legacy: pass-through original pointer */
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool str_is_empty(const char *s)
|
static inline bool str_is_empty(const char *s)
|
||||||
@@ -529,4 +549,26 @@ static inline int ensure_good_fd(int fd)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The following two functions are exposed to bpftool */
|
||||||
|
int bpf_core_add_cands(struct bpf_core_cand *local_cand,
|
||||||
|
size_t local_essent_len,
|
||||||
|
const struct btf *targ_btf,
|
||||||
|
const char *targ_btf_name,
|
||||||
|
int targ_start_id,
|
||||||
|
struct bpf_core_cand_list *cands);
|
||||||
|
void bpf_core_free_cands(struct bpf_core_cand_list *cands);
|
||||||
|
|
||||||
|
struct usdt_manager *usdt_manager_new(struct bpf_object *obj);
|
||||||
|
void usdt_manager_free(struct usdt_manager *man);
|
||||||
|
struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man,
|
||||||
|
const struct bpf_program *prog,
|
||||||
|
pid_t pid, const char *path,
|
||||||
|
const char *usdt_provider, const char *usdt_name,
|
||||||
|
__u64 usdt_cookie);
|
||||||
|
|
||||||
|
static inline bool is_pow_of_2(size_t x)
|
||||||
|
{
|
||||||
|
return x && (x & (x - 1)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __LIBBPF_LIBBPF_INTERNAL_H */
|
#endif /* __LIBBPF_LIBBPF_INTERNAL_H */
|
||||||
|
|||||||
@@ -20,6 +20,11 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* As of libbpf 1.0 libbpf_set_strict_mode() and enum libbpf_struct_mode have
|
||||||
|
* no effect. But they are left in libbpf_legacy.h so that applications that
|
||||||
|
* prepared for libbpf 1.0 before final release by using
|
||||||
|
* libbpf_set_strict_mode() still work with libbpf 1.0+ without any changes.
|
||||||
|
*/
|
||||||
enum libbpf_strict_mode {
|
enum libbpf_strict_mode {
|
||||||
/* Turn on all supported strict features of libbpf to simulate libbpf
|
/* Turn on all supported strict features of libbpf to simulate libbpf
|
||||||
* v1.0 behavior.
|
* v1.0 behavior.
|
||||||
@@ -54,6 +59,10 @@ enum libbpf_strict_mode {
|
|||||||
*
|
*
|
||||||
* Note, in this mode the program pin path will be based on the
|
* Note, in this mode the program pin path will be based on the
|
||||||
* function name instead of section name.
|
* function name instead of section name.
|
||||||
|
*
|
||||||
|
* Additionally, routines in the .text section are always considered
|
||||||
|
* sub-programs. Legacy behavior allows for a single routine in .text
|
||||||
|
* to be a program.
|
||||||
*/
|
*/
|
||||||
LIBBPF_STRICT_SEC_NAME = 0x04,
|
LIBBPF_STRICT_SEC_NAME = 0x04,
|
||||||
/*
|
/*
|
||||||
@@ -67,8 +76,8 @@ enum libbpf_strict_mode {
|
|||||||
* first BPF program or map creation operation. This is done only if
|
* first BPF program or map creation operation. This is done only if
|
||||||
* kernel is too old to support memcg-based memory accounting for BPF
|
* kernel is too old to support memcg-based memory accounting for BPF
|
||||||
* subsystem. By default, RLIMIT_MEMLOCK limit is set to RLIM_INFINITY,
|
* subsystem. By default, RLIMIT_MEMLOCK limit is set to RLIM_INFINITY,
|
||||||
* but it can be overriden with libbpf_set_memlock_rlim_max() API.
|
* but it can be overriden with libbpf_set_memlock_rlim() API.
|
||||||
* Note that libbpf_set_memlock_rlim_max() needs to be called before
|
* Note that libbpf_set_memlock_rlim() needs to be called before
|
||||||
* the very first bpf_prog_load(), bpf_map_create() or bpf_object__load()
|
* the very first bpf_prog_load(), bpf_map_create() or bpf_object__load()
|
||||||
* operation.
|
* operation.
|
||||||
*/
|
*/
|
||||||
@@ -84,6 +93,25 @@ enum libbpf_strict_mode {
|
|||||||
|
|
||||||
LIBBPF_API int libbpf_set_strict_mode(enum libbpf_strict_mode mode);
|
LIBBPF_API int libbpf_set_strict_mode(enum libbpf_strict_mode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief **libbpf_get_error()** extracts the error code from the passed
|
||||||
|
* pointer
|
||||||
|
* @param ptr pointer returned from libbpf API function
|
||||||
|
* @return error code; or 0 if no error occured
|
||||||
|
*
|
||||||
|
* Note, as of libbpf 1.0 this function is not necessary and not recommended
|
||||||
|
* to be used. Libbpf doesn't return error code embedded into the pointer
|
||||||
|
* itself. Instead, NULL is returned on error and error code is passed through
|
||||||
|
* thread-local errno variable. **libbpf_get_error()** is just returning -errno
|
||||||
|
* value if it receives NULL, which is correct only if errno hasn't been
|
||||||
|
* modified between libbpf API call and corresponding **libbpf_get_error()**
|
||||||
|
* call. Prefer to check return for NULL and use errno directly.
|
||||||
|
*
|
||||||
|
* This API is left in libbpf 1.0 to allow applications that were 1.0-ready
|
||||||
|
* before final libbpf 1.0 without needing to change them.
|
||||||
|
*/
|
||||||
|
LIBBPF_API long libbpf_get_error(const void *ptr);
|
||||||
|
|
||||||
#define DECLARE_LIBBPF_OPTS LIBBPF_OPTS
|
#define DECLARE_LIBBPF_OPTS LIBBPF_OPTS
|
||||||
|
|
||||||
/* "Discouraged" APIs which don't follow consistent libbpf naming patterns.
|
/* "Discouraged" APIs which don't follow consistent libbpf naming patterns.
|
||||||
|
|||||||
@@ -17,47 +17,14 @@
|
|||||||
#include "libbpf.h"
|
#include "libbpf.h"
|
||||||
#include "libbpf_internal.h"
|
#include "libbpf_internal.h"
|
||||||
|
|
||||||
static bool grep(const char *buffer, const char *pattern)
|
|
||||||
{
|
|
||||||
return !!strstr(buffer, pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_vendor_id(int ifindex)
|
|
||||||
{
|
|
||||||
char ifname[IF_NAMESIZE], path[64], buf[8];
|
|
||||||
ssize_t len;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (!if_indextoname(ifindex, ifname))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "/sys/class/net/%s/device/vendor", ifname);
|
|
||||||
|
|
||||||
fd = open(path, O_RDONLY | O_CLOEXEC);
|
|
||||||
if (fd < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
len = read(fd, buf, sizeof(buf));
|
|
||||||
close(fd);
|
|
||||||
if (len < 0)
|
|
||||||
return -1;
|
|
||||||
if (len >= (ssize_t)sizeof(buf))
|
|
||||||
return -1;
|
|
||||||
buf[len] = '\0';
|
|
||||||
|
|
||||||
return strtol(buf, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int probe_prog_load(enum bpf_prog_type prog_type,
|
static int probe_prog_load(enum bpf_prog_type prog_type,
|
||||||
const struct bpf_insn *insns, size_t insns_cnt,
|
const struct bpf_insn *insns, size_t insns_cnt,
|
||||||
char *log_buf, size_t log_buf_sz,
|
char *log_buf, size_t log_buf_sz)
|
||||||
__u32 ifindex)
|
|
||||||
{
|
{
|
||||||
LIBBPF_OPTS(bpf_prog_load_opts, opts,
|
LIBBPF_OPTS(bpf_prog_load_opts, opts,
|
||||||
.log_buf = log_buf,
|
.log_buf = log_buf,
|
||||||
.log_size = log_buf_sz,
|
.log_size = log_buf_sz,
|
||||||
.log_level = log_buf ? 1 : 0,
|
.log_level = log_buf ? 1 : 0,
|
||||||
.prog_ifindex = ifindex,
|
|
||||||
);
|
);
|
||||||
int fd, err, exp_err = 0;
|
int fd, err, exp_err = 0;
|
||||||
const char *exp_msg = NULL;
|
const char *exp_msg = NULL;
|
||||||
@@ -161,31 +128,10 @@ int libbpf_probe_bpf_prog_type(enum bpf_prog_type prog_type, const void *opts)
|
|||||||
if (opts)
|
if (opts)
|
||||||
return libbpf_err(-EINVAL);
|
return libbpf_err(-EINVAL);
|
||||||
|
|
||||||
ret = probe_prog_load(prog_type, insns, insn_cnt, NULL, 0, 0);
|
ret = probe_prog_load(prog_type, insns, insn_cnt, NULL, 0);
|
||||||
return libbpf_err(ret);
|
return libbpf_err(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bpf_probe_prog_type(enum bpf_prog_type prog_type, __u32 ifindex)
|
|
||||||
{
|
|
||||||
struct bpf_insn insns[2] = {
|
|
||||||
BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
||||||
BPF_EXIT_INSN()
|
|
||||||
};
|
|
||||||
|
|
||||||
/* prefer libbpf_probe_bpf_prog_type() unless offload is requested */
|
|
||||||
if (ifindex == 0)
|
|
||||||
return libbpf_probe_bpf_prog_type(prog_type, NULL) == 1;
|
|
||||||
|
|
||||||
if (ifindex && prog_type == BPF_PROG_TYPE_SCHED_CLS)
|
|
||||||
/* nfp returns -EINVAL on exit(0) with TC offload */
|
|
||||||
insns[0].imm = 2;
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
probe_prog_load(prog_type, insns, ARRAY_SIZE(insns), NULL, 0, ifindex);
|
|
||||||
|
|
||||||
return errno != EINVAL && errno != EOPNOTSUPP;
|
|
||||||
}
|
|
||||||
|
|
||||||
int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
|
int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
|
||||||
const char *str_sec, size_t str_len)
|
const char *str_sec, size_t str_len)
|
||||||
{
|
{
|
||||||
@@ -242,15 +188,13 @@ static int load_local_storage_btf(void)
|
|||||||
strs, sizeof(strs));
|
strs, sizeof(strs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int probe_map_create(enum bpf_map_type map_type, __u32 ifindex)
|
static int probe_map_create(enum bpf_map_type map_type)
|
||||||
{
|
{
|
||||||
LIBBPF_OPTS(bpf_map_create_opts, opts);
|
LIBBPF_OPTS(bpf_map_create_opts, opts);
|
||||||
int key_size, value_size, max_entries;
|
int key_size, value_size, max_entries;
|
||||||
__u32 btf_key_type_id = 0, btf_value_type_id = 0;
|
__u32 btf_key_type_id = 0, btf_value_type_id = 0;
|
||||||
int fd = -1, btf_fd = -1, fd_inner = -1, exp_err = 0, err;
|
int fd = -1, btf_fd = -1, fd_inner = -1, exp_err = 0, err;
|
||||||
|
|
||||||
opts.map_ifindex = ifindex;
|
|
||||||
|
|
||||||
key_size = sizeof(__u32);
|
key_size = sizeof(__u32);
|
||||||
value_size = sizeof(__u32);
|
value_size = sizeof(__u32);
|
||||||
max_entries = 1;
|
max_entries = 1;
|
||||||
@@ -326,12 +270,6 @@ static int probe_map_create(enum bpf_map_type map_type, __u32 ifindex)
|
|||||||
|
|
||||||
if (map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS ||
|
if (map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS ||
|
||||||
map_type == BPF_MAP_TYPE_HASH_OF_MAPS) {
|
map_type == BPF_MAP_TYPE_HASH_OF_MAPS) {
|
||||||
/* TODO: probe for device, once libbpf has a function to create
|
|
||||||
* map-in-map for offload
|
|
||||||
*/
|
|
||||||
if (ifindex)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
fd_inner = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,
|
fd_inner = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,
|
||||||
sizeof(__u32), sizeof(__u32), 1, NULL);
|
sizeof(__u32), sizeof(__u32), 1, NULL);
|
||||||
if (fd_inner < 0)
|
if (fd_inner < 0)
|
||||||
@@ -370,15 +308,10 @@ int libbpf_probe_bpf_map_type(enum bpf_map_type map_type, const void *opts)
|
|||||||
if (opts)
|
if (opts)
|
||||||
return libbpf_err(-EINVAL);
|
return libbpf_err(-EINVAL);
|
||||||
|
|
||||||
ret = probe_map_create(map_type, 0);
|
ret = probe_map_create(map_type);
|
||||||
return libbpf_err(ret);
|
return libbpf_err(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex)
|
|
||||||
{
|
|
||||||
return probe_map_create(map_type, ifindex) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int libbpf_probe_bpf_helper(enum bpf_prog_type prog_type, enum bpf_func_id helper_id,
|
int libbpf_probe_bpf_helper(enum bpf_prog_type prog_type, enum bpf_func_id helper_id,
|
||||||
const void *opts)
|
const void *opts)
|
||||||
{
|
{
|
||||||
@@ -407,7 +340,7 @@ int libbpf_probe_bpf_helper(enum bpf_prog_type prog_type, enum bpf_func_id helpe
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
ret = probe_prog_load(prog_type, insns, insn_cnt, buf, sizeof(buf), 0);
|
ret = probe_prog_load(prog_type, insns, insn_cnt, buf, sizeof(buf));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return libbpf_err(ret);
|
return libbpf_err(ret);
|
||||||
|
|
||||||
@@ -427,51 +360,3 @@ int libbpf_probe_bpf_helper(enum bpf_prog_type prog_type, enum bpf_func_id helpe
|
|||||||
return 0;
|
return 0;
|
||||||
return 1; /* assume supported */
|
return 1; /* assume supported */
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bpf_probe_helper(enum bpf_func_id id, enum bpf_prog_type prog_type,
|
|
||||||
__u32 ifindex)
|
|
||||||
{
|
|
||||||
struct bpf_insn insns[2] = {
|
|
||||||
BPF_EMIT_CALL(id),
|
|
||||||
BPF_EXIT_INSN()
|
|
||||||
};
|
|
||||||
char buf[4096] = {};
|
|
||||||
bool res;
|
|
||||||
|
|
||||||
probe_prog_load(prog_type, insns, ARRAY_SIZE(insns), buf, sizeof(buf), ifindex);
|
|
||||||
res = !grep(buf, "invalid func ") && !grep(buf, "unknown func ");
|
|
||||||
|
|
||||||
if (ifindex) {
|
|
||||||
switch (get_vendor_id(ifindex)) {
|
|
||||||
case 0x19ee: /* Netronome specific */
|
|
||||||
res = res && !grep(buf, "not supported by FW") &&
|
|
||||||
!grep(buf, "unsupported function id");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Probe for availability of kernel commit (5.3):
|
|
||||||
*
|
|
||||||
* c04c0d2b968a ("bpf: increase complexity limit and maximum program size")
|
|
||||||
*/
|
|
||||||
bool bpf_probe_large_insn_limit(__u32 ifindex)
|
|
||||||
{
|
|
||||||
struct bpf_insn insns[BPF_MAXINSNS + 1];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < BPF_MAXINSNS; i++)
|
|
||||||
insns[i] = BPF_MOV64_IMM(BPF_REG_0, 1);
|
|
||||||
insns[BPF_MAXINSNS] = BPF_EXIT_INSN();
|
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
probe_prog_load(BPF_PROG_TYPE_SCHED_CLS, insns, ARRAY_SIZE(insns), NULL, 0,
|
|
||||||
ifindex);
|
|
||||||
|
|
||||||
return errno != E2BIG && errno != EINVAL;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#ifndef __LIBBPF_VERSION_H
|
#ifndef __LIBBPF_VERSION_H
|
||||||
#define __LIBBPF_VERSION_H
|
#define __LIBBPF_VERSION_H
|
||||||
|
|
||||||
#define LIBBPF_MAJOR_VERSION 0
|
#define LIBBPF_MAJOR_VERSION 1
|
||||||
#define LIBBPF_MINOR_VERSION 7
|
#define LIBBPF_MINOR_VERSION 0
|
||||||
|
|
||||||
#endif /* __LIBBPF_VERSION_H */
|
#endif /* __LIBBPF_VERSION_H */
|
||||||
|
|||||||
@@ -697,11 +697,6 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_pow_of_2(size_t x)
|
|
||||||
{
|
|
||||||
return x && (x & (x - 1)) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int linker_sanity_check_elf(struct src_obj *obj)
|
static int linker_sanity_check_elf(struct src_obj *obj)
|
||||||
{
|
{
|
||||||
struct src_sec *sec;
|
struct src_sec *sec;
|
||||||
@@ -1340,6 +1335,7 @@ recur:
|
|||||||
case BTF_KIND_STRUCT:
|
case BTF_KIND_STRUCT:
|
||||||
case BTF_KIND_UNION:
|
case BTF_KIND_UNION:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
case BTF_KIND_FUNC:
|
case BTF_KIND_FUNC:
|
||||||
case BTF_KIND_VAR:
|
case BTF_KIND_VAR:
|
||||||
@@ -1362,6 +1358,7 @@ recur:
|
|||||||
case BTF_KIND_INT:
|
case BTF_KIND_INT:
|
||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
case BTF_KIND_ENUM:
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
/* ignore encoding for int and enum values for enum */
|
/* ignore encoding for int and enum values for enum */
|
||||||
if (t1->size != t2->size) {
|
if (t1->size != t2->size) {
|
||||||
pr_warn("global '%s': incompatible %s '%s' size %u and %u\n",
|
pr_warn("global '%s': incompatible %s '%s' size %u and %u\n",
|
||||||
|
|||||||
125
src/netlink.c
125
src/netlink.c
@@ -27,6 +27,14 @@ typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
|
|||||||
typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, libbpf_dump_nlmsg_t,
|
typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, libbpf_dump_nlmsg_t,
|
||||||
void *cookie);
|
void *cookie);
|
||||||
|
|
||||||
|
struct xdp_link_info {
|
||||||
|
__u32 prog_id;
|
||||||
|
__u32 drv_prog_id;
|
||||||
|
__u32 hw_prog_id;
|
||||||
|
__u32 skb_prog_id;
|
||||||
|
__u8 attach_mode;
|
||||||
|
};
|
||||||
|
|
||||||
struct xdp_id_md {
|
struct xdp_id_md {
|
||||||
int ifindex;
|
int ifindex;
|
||||||
__u32 flags;
|
__u32 flags;
|
||||||
@@ -87,29 +95,75 @@ enum {
|
|||||||
NL_DONE,
|
NL_DONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int netlink_recvmsg(int sock, struct msghdr *mhdr, int flags)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
do {
|
||||||
|
len = recvmsg(sock, mhdr, flags);
|
||||||
|
} while (len < 0 && (errno == EINTR || errno == EAGAIN));
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
return -errno;
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int alloc_iov(struct iovec *iov, int len)
|
||||||
|
{
|
||||||
|
void *nbuf;
|
||||||
|
|
||||||
|
nbuf = realloc(iov->iov_base, len);
|
||||||
|
if (!nbuf)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
iov->iov_base = nbuf;
|
||||||
|
iov->iov_len = len;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,
|
static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,
|
||||||
__dump_nlmsg_t _fn, libbpf_dump_nlmsg_t fn,
|
__dump_nlmsg_t _fn, libbpf_dump_nlmsg_t fn,
|
||||||
void *cookie)
|
void *cookie)
|
||||||
{
|
{
|
||||||
|
struct iovec iov = {};
|
||||||
|
struct msghdr mhdr = {
|
||||||
|
.msg_iov = &iov,
|
||||||
|
.msg_iovlen = 1,
|
||||||
|
};
|
||||||
bool multipart = true;
|
bool multipart = true;
|
||||||
struct nlmsgerr *err;
|
struct nlmsgerr *err;
|
||||||
struct nlmsghdr *nh;
|
struct nlmsghdr *nh;
|
||||||
char buf[4096];
|
|
||||||
int len, ret;
|
int len, ret;
|
||||||
|
|
||||||
|
ret = alloc_iov(&iov, 4096);
|
||||||
|
if (ret)
|
||||||
|
goto done;
|
||||||
|
|
||||||
while (multipart) {
|
while (multipart) {
|
||||||
start:
|
start:
|
||||||
multipart = false;
|
multipart = false;
|
||||||
len = recv(sock, buf, sizeof(buf), 0);
|
len = netlink_recvmsg(sock, &mhdr, MSG_PEEK | MSG_TRUNC);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
ret = -errno;
|
ret = len;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > iov.iov_len) {
|
||||||
|
ret = alloc_iov(&iov, len);
|
||||||
|
if (ret)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = netlink_recvmsg(sock, &mhdr, 0);
|
||||||
|
if (len < 0) {
|
||||||
|
ret = len;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);
|
for (nh = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(nh, len);
|
||||||
nh = NLMSG_NEXT(nh, len)) {
|
nh = NLMSG_NEXT(nh, len)) {
|
||||||
if (nh->nlmsg_pid != nl_pid) {
|
if (nh->nlmsg_pid != nl_pid) {
|
||||||
ret = -LIBBPF_ERRNO__WRNGPID;
|
ret = -LIBBPF_ERRNO__WRNGPID;
|
||||||
@@ -130,7 +184,8 @@ start:
|
|||||||
libbpf_nla_dump_errormsg(nh);
|
libbpf_nla_dump_errormsg(nh);
|
||||||
goto done;
|
goto done;
|
||||||
case NLMSG_DONE:
|
case NLMSG_DONE:
|
||||||
return 0;
|
ret = 0;
|
||||||
|
goto done;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -142,15 +197,17 @@ start:
|
|||||||
case NL_NEXT:
|
case NL_NEXT:
|
||||||
goto start;
|
goto start;
|
||||||
case NL_DONE:
|
case NL_DONE:
|
||||||
return 0;
|
ret = 0;
|
||||||
|
goto done;
|
||||||
default:
|
default:
|
||||||
return ret;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
done:
|
done:
|
||||||
|
free(iov.iov_base);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,31 +296,6 @@ int bpf_xdp_detach(int ifindex, __u32 flags, const struct bpf_xdp_attach_opts *o
|
|||||||
return bpf_xdp_attach(ifindex, -1, flags, opts);
|
return bpf_xdp_attach(ifindex, -1, flags, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
int bpf_set_link_xdp_fd_opts(int ifindex, int fd, __u32 flags,
|
|
||||||
const struct bpf_xdp_set_link_opts *opts)
|
|
||||||
{
|
|
||||||
int old_fd = -1, ret;
|
|
||||||
|
|
||||||
if (!OPTS_VALID(opts, bpf_xdp_set_link_opts))
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
|
|
||||||
if (OPTS_HAS(opts, old_fd)) {
|
|
||||||
old_fd = OPTS_GET(opts, old_fd, -1);
|
|
||||||
flags |= XDP_FLAGS_REPLACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = __bpf_set_link_xdp_fd_replace(ifindex, fd, old_fd, flags);
|
|
||||||
return libbpf_err(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = __bpf_set_link_xdp_fd_replace(ifindex, fd, 0, flags);
|
|
||||||
return libbpf_err(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __dump_link_nlmsg(struct nlmsghdr *nlh,
|
static int __dump_link_nlmsg(struct nlmsghdr *nlh,
|
||||||
libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie)
|
libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie)
|
||||||
{
|
{
|
||||||
@@ -364,30 +396,6 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
|
|
||||||
size_t info_size, __u32 flags)
|
|
||||||
{
|
|
||||||
LIBBPF_OPTS(bpf_xdp_query_opts, opts);
|
|
||||||
size_t sz;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
if (!info_size)
|
|
||||||
return libbpf_err(-EINVAL);
|
|
||||||
|
|
||||||
err = bpf_xdp_query(ifindex, flags, &opts);
|
|
||||||
if (err)
|
|
||||||
return libbpf_err(err);
|
|
||||||
|
|
||||||
/* struct xdp_link_info field layout matches struct bpf_xdp_query_opts
|
|
||||||
* layout after sz field
|
|
||||||
*/
|
|
||||||
sz = min(info_size, offsetofend(struct xdp_link_info, attach_mode));
|
|
||||||
memcpy(info, &opts.prog_id, sz);
|
|
||||||
memset((void *)info + sz, 0, info_size - sz);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id)
|
int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id)
|
||||||
{
|
{
|
||||||
LIBBPF_OPTS(bpf_xdp_query_opts, opts);
|
LIBBPF_OPTS(bpf_xdp_query_opts, opts);
|
||||||
@@ -414,11 +422,6 @@ int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int bpf_get_link_xdp_id(int ifindex, __u32 *prog_id, __u32 flags)
|
|
||||||
{
|
|
||||||
return bpf_xdp_query_id(ifindex, flags, prog_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef int (*qdisc_config_t)(struct libbpf_nla_req *req);
|
typedef int (*qdisc_config_t)(struct libbpf_nla_req *req);
|
||||||
|
|
||||||
static int clsact_config(struct libbpf_nla_req *req)
|
static int clsact_config(struct libbpf_nla_req *req)
|
||||||
|
|||||||
372
src/relo_core.c
372
src/relo_core.c
@@ -141,6 +141,86 @@ static bool core_relo_is_enumval_based(enum bpf_core_relo_kind kind)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id,
|
||||||
|
const struct btf *targ_btf, __u32 targ_id, int level)
|
||||||
|
{
|
||||||
|
const struct btf_type *local_type, *targ_type;
|
||||||
|
int depth = 32; /* max recursion depth */
|
||||||
|
|
||||||
|
/* caller made sure that names match (ignoring flavor suffix) */
|
||||||
|
local_type = btf_type_by_id(local_btf, local_id);
|
||||||
|
targ_type = btf_type_by_id(targ_btf, targ_id);
|
||||||
|
if (!btf_kind_core_compat(local_type, targ_type))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
recur:
|
||||||
|
depth--;
|
||||||
|
if (depth < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
local_type = skip_mods_and_typedefs(local_btf, local_id, &local_id);
|
||||||
|
targ_type = skip_mods_and_typedefs(targ_btf, targ_id, &targ_id);
|
||||||
|
if (!local_type || !targ_type)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (!btf_kind_core_compat(local_type, targ_type))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch (btf_kind(local_type)) {
|
||||||
|
case BTF_KIND_UNKN:
|
||||||
|
case BTF_KIND_STRUCT:
|
||||||
|
case BTF_KIND_UNION:
|
||||||
|
case BTF_KIND_ENUM:
|
||||||
|
case BTF_KIND_FWD:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
|
return 1;
|
||||||
|
case BTF_KIND_INT:
|
||||||
|
/* just reject deprecated bitfield-like integers; all other
|
||||||
|
* integers are by default compatible between each other
|
||||||
|
*/
|
||||||
|
return btf_int_offset(local_type) == 0 && btf_int_offset(targ_type) == 0;
|
||||||
|
case BTF_KIND_PTR:
|
||||||
|
local_id = local_type->type;
|
||||||
|
targ_id = targ_type->type;
|
||||||
|
goto recur;
|
||||||
|
case BTF_KIND_ARRAY:
|
||||||
|
local_id = btf_array(local_type)->type;
|
||||||
|
targ_id = btf_array(targ_type)->type;
|
||||||
|
goto recur;
|
||||||
|
case BTF_KIND_FUNC_PROTO: {
|
||||||
|
struct btf_param *local_p = btf_params(local_type);
|
||||||
|
struct btf_param *targ_p = btf_params(targ_type);
|
||||||
|
__u16 local_vlen = btf_vlen(local_type);
|
||||||
|
__u16 targ_vlen = btf_vlen(targ_type);
|
||||||
|
int i, err;
|
||||||
|
|
||||||
|
if (local_vlen != targ_vlen)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < local_vlen; i++, local_p++, targ_p++) {
|
||||||
|
if (level <= 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
skip_mods_and_typedefs(local_btf, local_p->type, &local_id);
|
||||||
|
skip_mods_and_typedefs(targ_btf, targ_p->type, &targ_id);
|
||||||
|
err = __bpf_core_types_are_compat(local_btf, local_id, targ_btf, targ_id,
|
||||||
|
level - 1);
|
||||||
|
if (err <= 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tail recurse for return type check */
|
||||||
|
skip_mods_and_typedefs(local_btf, local_type->type, &local_id);
|
||||||
|
skip_mods_and_typedefs(targ_btf, targ_type->type, &targ_id);
|
||||||
|
goto recur;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
pr_warn("unexpected kind %s relocated, local [%d], target [%d]\n",
|
||||||
|
btf_kind_str(local_type), local_id, targ_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Turn bpf_core_relo into a low- and high-level spec representation,
|
* Turn bpf_core_relo into a low- and high-level spec representation,
|
||||||
* validating correctness along the way, as well as calculating resulting
|
* validating correctness along the way, as well as calculating resulting
|
||||||
@@ -167,7 +247,7 @@ static bool core_relo_is_enumval_based(enum bpf_core_relo_kind kind)
|
|||||||
* just a parsed access string representation): [0, 1, 2, 3].
|
* just a parsed access string representation): [0, 1, 2, 3].
|
||||||
*
|
*
|
||||||
* High-level spec will capture only 3 points:
|
* High-level spec will capture only 3 points:
|
||||||
* - intial zero-index access by pointer (&s->... is the same as &s[0]...);
|
* - initial zero-index access by pointer (&s->... is the same as &s[0]...);
|
||||||
* - field 'a' access (corresponds to '2' in low-level spec);
|
* - field 'a' access (corresponds to '2' in low-level spec);
|
||||||
* - array element #3 access (corresponds to '3' in low-level spec).
|
* - array element #3 access (corresponds to '3' in low-level spec).
|
||||||
*
|
*
|
||||||
@@ -178,29 +258,28 @@ static bool core_relo_is_enumval_based(enum bpf_core_relo_kind kind)
|
|||||||
* Enum value-based relocations (ENUMVAL_EXISTS/ENUMVAL_VALUE) use access
|
* Enum value-based relocations (ENUMVAL_EXISTS/ENUMVAL_VALUE) use access
|
||||||
* string to specify enumerator's value index that need to be relocated.
|
* string to specify enumerator's value index that need to be relocated.
|
||||||
*/
|
*/
|
||||||
static int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
||||||
__u32 type_id,
|
const struct bpf_core_relo *relo,
|
||||||
const char *spec_str,
|
struct bpf_core_spec *spec)
|
||||||
enum bpf_core_relo_kind relo_kind,
|
|
||||||
struct bpf_core_spec *spec)
|
|
||||||
{
|
{
|
||||||
int access_idx, parsed_len, i;
|
int access_idx, parsed_len, i;
|
||||||
struct bpf_core_accessor *acc;
|
struct bpf_core_accessor *acc;
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
const char *name;
|
const char *name, *spec_str;
|
||||||
__u32 id;
|
__u32 id, name_off;
|
||||||
__s64 sz;
|
__s64 sz;
|
||||||
|
|
||||||
|
spec_str = btf__name_by_offset(btf, relo->access_str_off);
|
||||||
if (str_is_empty(spec_str) || *spec_str == ':')
|
if (str_is_empty(spec_str) || *spec_str == ':')
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
memset(spec, 0, sizeof(*spec));
|
memset(spec, 0, sizeof(*spec));
|
||||||
spec->btf = btf;
|
spec->btf = btf;
|
||||||
spec->root_type_id = type_id;
|
spec->root_type_id = relo->type_id;
|
||||||
spec->relo_kind = relo_kind;
|
spec->relo_kind = relo->kind;
|
||||||
|
|
||||||
/* type-based relocations don't have a field access string */
|
/* type-based relocations don't have a field access string */
|
||||||
if (core_relo_is_type_based(relo_kind)) {
|
if (core_relo_is_type_based(relo->kind)) {
|
||||||
if (strcmp(spec_str, "0"))
|
if (strcmp(spec_str, "0"))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -221,7 +300,7 @@ static int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
|||||||
if (spec->raw_len == 0)
|
if (spec->raw_len == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
t = skip_mods_and_typedefs(btf, type_id, &id);
|
t = skip_mods_and_typedefs(btf, relo->type_id, &id);
|
||||||
if (!t)
|
if (!t)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
@@ -231,16 +310,18 @@ static int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
|||||||
acc->idx = access_idx;
|
acc->idx = access_idx;
|
||||||
spec->len++;
|
spec->len++;
|
||||||
|
|
||||||
if (core_relo_is_enumval_based(relo_kind)) {
|
if (core_relo_is_enumval_based(relo->kind)) {
|
||||||
if (!btf_is_enum(t) || spec->raw_len > 1 || access_idx >= btf_vlen(t))
|
if (!btf_is_any_enum(t) || spec->raw_len > 1 || access_idx >= btf_vlen(t))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* record enumerator name in a first accessor */
|
/* record enumerator name in a first accessor */
|
||||||
acc->name = btf__name_by_offset(btf, btf_enum(t)[access_idx].name_off);
|
name_off = btf_is_enum(t) ? btf_enum(t)[access_idx].name_off
|
||||||
|
: btf_enum64(t)[access_idx].name_off;
|
||||||
|
acc->name = btf__name_by_offset(btf, name_off);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!core_relo_is_field_based(relo_kind))
|
if (!core_relo_is_field_based(relo->kind))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
sz = btf__resolve_size(btf, id);
|
sz = btf__resolve_size(btf, id);
|
||||||
@@ -301,7 +382,7 @@ static int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
|||||||
spec->bit_offset += access_idx * sz * 8;
|
spec->bit_offset += access_idx * sz * 8;
|
||||||
} else {
|
} else {
|
||||||
pr_warn("prog '%s': relo for [%u] %s (at idx %d) captures type [%d] of unexpected kind %s\n",
|
pr_warn("prog '%s': relo for [%u] %s (at idx %d) captures type [%d] of unexpected kind %s\n",
|
||||||
prog_name, type_id, spec_str, i, id, btf_kind_str(t));
|
prog_name, relo->type_id, spec_str, i, id, btf_kind_str(t));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,7 +422,7 @@ recur:
|
|||||||
|
|
||||||
if (btf_is_composite(local_type) && btf_is_composite(targ_type))
|
if (btf_is_composite(local_type) && btf_is_composite(targ_type))
|
||||||
return 1;
|
return 1;
|
||||||
if (btf_kind(local_type) != btf_kind(targ_type))
|
if (!btf_kind_core_compat(local_type, targ_type))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
switch (btf_kind(local_type)) {
|
switch (btf_kind(local_type)) {
|
||||||
@@ -349,6 +430,7 @@ recur:
|
|||||||
case BTF_KIND_FLOAT:
|
case BTF_KIND_FLOAT:
|
||||||
return 1;
|
return 1;
|
||||||
case BTF_KIND_FWD:
|
case BTF_KIND_FWD:
|
||||||
|
case BTF_KIND_ENUM64:
|
||||||
case BTF_KIND_ENUM: {
|
case BTF_KIND_ENUM: {
|
||||||
const char *local_name, *targ_name;
|
const char *local_name, *targ_name;
|
||||||
size_t local_len, targ_len;
|
size_t local_len, targ_len;
|
||||||
@@ -478,6 +560,7 @@ static int bpf_core_spec_match(struct bpf_core_spec *local_spec,
|
|||||||
const struct bpf_core_accessor *local_acc;
|
const struct bpf_core_accessor *local_acc;
|
||||||
struct bpf_core_accessor *targ_acc;
|
struct bpf_core_accessor *targ_acc;
|
||||||
int i, sz, matched;
|
int i, sz, matched;
|
||||||
|
__u32 name_off;
|
||||||
|
|
||||||
memset(targ_spec, 0, sizeof(*targ_spec));
|
memset(targ_spec, 0, sizeof(*targ_spec));
|
||||||
targ_spec->btf = targ_btf;
|
targ_spec->btf = targ_btf;
|
||||||
@@ -495,18 +578,22 @@ static int bpf_core_spec_match(struct bpf_core_spec *local_spec,
|
|||||||
|
|
||||||
if (core_relo_is_enumval_based(local_spec->relo_kind)) {
|
if (core_relo_is_enumval_based(local_spec->relo_kind)) {
|
||||||
size_t local_essent_len, targ_essent_len;
|
size_t local_essent_len, targ_essent_len;
|
||||||
const struct btf_enum *e;
|
|
||||||
const char *targ_name;
|
const char *targ_name;
|
||||||
|
|
||||||
/* has to resolve to an enum */
|
/* has to resolve to an enum */
|
||||||
targ_type = skip_mods_and_typedefs(targ_spec->btf, targ_id, &targ_id);
|
targ_type = skip_mods_and_typedefs(targ_spec->btf, targ_id, &targ_id);
|
||||||
if (!btf_is_enum(targ_type))
|
if (!btf_is_any_enum(targ_type))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
local_essent_len = bpf_core_essential_name_len(local_acc->name);
|
local_essent_len = bpf_core_essential_name_len(local_acc->name);
|
||||||
|
|
||||||
for (i = 0, e = btf_enum(targ_type); i < btf_vlen(targ_type); i++, e++) {
|
for (i = 0; i < btf_vlen(targ_type); i++) {
|
||||||
targ_name = btf__name_by_offset(targ_spec->btf, e->name_off);
|
if (btf_is_enum(targ_type))
|
||||||
|
name_off = btf_enum(targ_type)[i].name_off;
|
||||||
|
else
|
||||||
|
name_off = btf_enum64(targ_type)[i].name_off;
|
||||||
|
|
||||||
|
targ_name = btf__name_by_offset(targ_spec->btf, name_off);
|
||||||
targ_essent_len = bpf_core_essential_name_len(targ_name);
|
targ_essent_len = bpf_core_essential_name_len(targ_name);
|
||||||
if (targ_essent_len != local_essent_len)
|
if (targ_essent_len != local_essent_len)
|
||||||
continue;
|
continue;
|
||||||
@@ -584,7 +671,7 @@ static int bpf_core_spec_match(struct bpf_core_spec *local_spec,
|
|||||||
static int bpf_core_calc_field_relo(const char *prog_name,
|
static int bpf_core_calc_field_relo(const char *prog_name,
|
||||||
const struct bpf_core_relo *relo,
|
const struct bpf_core_relo *relo,
|
||||||
const struct bpf_core_spec *spec,
|
const struct bpf_core_spec *spec,
|
||||||
__u32 *val, __u32 *field_sz, __u32 *type_id,
|
__u64 *val, __u32 *field_sz, __u32 *type_id,
|
||||||
bool *validate)
|
bool *validate)
|
||||||
{
|
{
|
||||||
const struct bpf_core_accessor *acc;
|
const struct bpf_core_accessor *acc;
|
||||||
@@ -681,8 +768,7 @@ static int bpf_core_calc_field_relo(const char *prog_name,
|
|||||||
*val = byte_sz;
|
*val = byte_sz;
|
||||||
break;
|
break;
|
||||||
case BPF_CORE_FIELD_SIGNED:
|
case BPF_CORE_FIELD_SIGNED:
|
||||||
/* enums will be assumed unsigned */
|
*val = (btf_is_any_enum(mt) && BTF_INFO_KFLAG(mt->info)) ||
|
||||||
*val = btf_is_enum(mt) ||
|
|
||||||
(btf_int_encoding(mt) & BTF_INT_SIGNED);
|
(btf_int_encoding(mt) & BTF_INT_SIGNED);
|
||||||
if (validate)
|
if (validate)
|
||||||
*validate = true; /* signedness is never ambiguous */
|
*validate = true; /* signedness is never ambiguous */
|
||||||
@@ -709,7 +795,7 @@ static int bpf_core_calc_field_relo(const char *prog_name,
|
|||||||
|
|
||||||
static int bpf_core_calc_type_relo(const struct bpf_core_relo *relo,
|
static int bpf_core_calc_type_relo(const struct bpf_core_relo *relo,
|
||||||
const struct bpf_core_spec *spec,
|
const struct bpf_core_spec *spec,
|
||||||
__u32 *val, bool *validate)
|
__u64 *val, bool *validate)
|
||||||
{
|
{
|
||||||
__s64 sz;
|
__s64 sz;
|
||||||
|
|
||||||
@@ -752,10 +838,9 @@ static int bpf_core_calc_type_relo(const struct bpf_core_relo *relo,
|
|||||||
|
|
||||||
static int bpf_core_calc_enumval_relo(const struct bpf_core_relo *relo,
|
static int bpf_core_calc_enumval_relo(const struct bpf_core_relo *relo,
|
||||||
const struct bpf_core_spec *spec,
|
const struct bpf_core_spec *spec,
|
||||||
__u32 *val)
|
__u64 *val)
|
||||||
{
|
{
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
const struct btf_enum *e;
|
|
||||||
|
|
||||||
switch (relo->kind) {
|
switch (relo->kind) {
|
||||||
case BPF_CORE_ENUMVAL_EXISTS:
|
case BPF_CORE_ENUMVAL_EXISTS:
|
||||||
@@ -765,8 +850,10 @@ static int bpf_core_calc_enumval_relo(const struct bpf_core_relo *relo,
|
|||||||
if (!spec)
|
if (!spec)
|
||||||
return -EUCLEAN; /* request instruction poisoning */
|
return -EUCLEAN; /* request instruction poisoning */
|
||||||
t = btf_type_by_id(spec->btf, spec->spec[0].type_id);
|
t = btf_type_by_id(spec->btf, spec->spec[0].type_id);
|
||||||
e = btf_enum(t) + spec->spec[0].idx;
|
if (btf_is_enum(t))
|
||||||
*val = e->val;
|
*val = btf_enum(t)[spec->spec[0].idx].val;
|
||||||
|
else
|
||||||
|
*val = btf_enum64_value(btf_enum64(t) + spec->spec[0].idx);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
@@ -775,31 +862,6 @@ static int bpf_core_calc_enumval_relo(const struct bpf_core_relo *relo,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bpf_core_relo_res
|
|
||||||
{
|
|
||||||
/* expected value in the instruction, unless validate == false */
|
|
||||||
__u32 orig_val;
|
|
||||||
/* new value that needs to be patched up to */
|
|
||||||
__u32 new_val;
|
|
||||||
/* relocation unsuccessful, poison instruction, but don't fail load */
|
|
||||||
bool poison;
|
|
||||||
/* some relocations can't be validated against orig_val */
|
|
||||||
bool validate;
|
|
||||||
/* for field byte offset relocations or the forms:
|
|
||||||
* *(T *)(rX + <off>) = rY
|
|
||||||
* rX = *(T *)(rY + <off>),
|
|
||||||
* we remember original and resolved field size to adjust direct
|
|
||||||
* memory loads of pointers and integers; this is necessary for 32-bit
|
|
||||||
* host kernel architectures, but also allows to automatically
|
|
||||||
* relocate fields that were resized from, e.g., u32 to u64, etc.
|
|
||||||
*/
|
|
||||||
bool fail_memsz_adjust;
|
|
||||||
__u32 orig_sz;
|
|
||||||
__u32 orig_type_id;
|
|
||||||
__u32 new_sz;
|
|
||||||
__u32 new_type_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Calculate original and target relocation values, given local and target
|
/* Calculate original and target relocation values, given local and target
|
||||||
* specs and relocation kind. These values are calculated for each candidate.
|
* specs and relocation kind. These values are calculated for each candidate.
|
||||||
* If there are multiple candidates, resulting values should all be consistent
|
* If there are multiple candidates, resulting values should all be consistent
|
||||||
@@ -951,11 +1013,11 @@ static int insn_bytes_to_bpf_size(__u32 sz)
|
|||||||
* 5. *(T *)(rX + <off>) = rY, where T is one of {u8, u16, u32, u64};
|
* 5. *(T *)(rX + <off>) = rY, where T is one of {u8, u16, u32, u64};
|
||||||
* 6. *(T *)(rX + <off>) = <imm>, where T is one of {u8, u16, u32, u64}.
|
* 6. *(T *)(rX + <off>) = <imm>, where T is one of {u8, u16, u32, u64}.
|
||||||
*/
|
*/
|
||||||
static int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
|
int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
|
||||||
int insn_idx, const struct bpf_core_relo *relo,
|
int insn_idx, const struct bpf_core_relo *relo,
|
||||||
int relo_idx, const struct bpf_core_relo_res *res)
|
int relo_idx, const struct bpf_core_relo_res *res)
|
||||||
{
|
{
|
||||||
__u32 orig_val, new_val;
|
__u64 orig_val, new_val;
|
||||||
__u8 class;
|
__u8 class;
|
||||||
|
|
||||||
class = BPF_CLASS(insn->code);
|
class = BPF_CLASS(insn->code);
|
||||||
@@ -980,28 +1042,30 @@ poison:
|
|||||||
if (BPF_SRC(insn->code) != BPF_K)
|
if (BPF_SRC(insn->code) != BPF_K)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (res->validate && insn->imm != orig_val) {
|
if (res->validate && insn->imm != orig_val) {
|
||||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, exp %u -> %u\n",
|
pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, exp %llu -> %llu\n",
|
||||||
prog_name, relo_idx,
|
prog_name, relo_idx,
|
||||||
insn_idx, insn->imm, orig_val, new_val);
|
insn_idx, insn->imm, (unsigned long long)orig_val,
|
||||||
|
(unsigned long long)new_val);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
orig_val = insn->imm;
|
orig_val = insn->imm;
|
||||||
insn->imm = new_val;
|
insn->imm = new_val;
|
||||||
pr_debug("prog '%s': relo #%d: patched insn #%d (ALU/ALU64) imm %u -> %u\n",
|
pr_debug("prog '%s': relo #%d: patched insn #%d (ALU/ALU64) imm %llu -> %llu\n",
|
||||||
prog_name, relo_idx, insn_idx,
|
prog_name, relo_idx, insn_idx,
|
||||||
orig_val, new_val);
|
(unsigned long long)orig_val, (unsigned long long)new_val);
|
||||||
break;
|
break;
|
||||||
case BPF_LDX:
|
case BPF_LDX:
|
||||||
case BPF_ST:
|
case BPF_ST:
|
||||||
case BPF_STX:
|
case BPF_STX:
|
||||||
if (res->validate && insn->off != orig_val) {
|
if (res->validate && insn->off != orig_val) {
|
||||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, exp %u -> %u\n",
|
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, exp %llu -> %llu\n",
|
||||||
prog_name, relo_idx, insn_idx, insn->off, orig_val, new_val);
|
prog_name, relo_idx, insn_idx, insn->off, (unsigned long long)orig_val,
|
||||||
|
(unsigned long long)new_val);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (new_val > SHRT_MAX) {
|
if (new_val > SHRT_MAX) {
|
||||||
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) value too big: %u\n",
|
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) value too big: %llu\n",
|
||||||
prog_name, relo_idx, insn_idx, new_val);
|
prog_name, relo_idx, insn_idx, (unsigned long long)new_val);
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
}
|
}
|
||||||
if (res->fail_memsz_adjust) {
|
if (res->fail_memsz_adjust) {
|
||||||
@@ -1013,8 +1077,9 @@ poison:
|
|||||||
|
|
||||||
orig_val = insn->off;
|
orig_val = insn->off;
|
||||||
insn->off = new_val;
|
insn->off = new_val;
|
||||||
pr_debug("prog '%s': relo #%d: patched insn #%d (LDX/ST/STX) off %u -> %u\n",
|
pr_debug("prog '%s': relo #%d: patched insn #%d (LDX/ST/STX) off %llu -> %llu\n",
|
||||||
prog_name, relo_idx, insn_idx, orig_val, new_val);
|
prog_name, relo_idx, insn_idx, (unsigned long long)orig_val,
|
||||||
|
(unsigned long long)new_val);
|
||||||
|
|
||||||
if (res->new_sz != res->orig_sz) {
|
if (res->new_sz != res->orig_sz) {
|
||||||
int insn_bytes_sz, insn_bpf_sz;
|
int insn_bytes_sz, insn_bpf_sz;
|
||||||
@@ -1050,20 +1115,20 @@ poison:
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
imm = insn[0].imm + ((__u64)insn[1].imm << 32);
|
imm = (__u32)insn[0].imm | ((__u64)insn[1].imm << 32);
|
||||||
if (res->validate && imm != orig_val) {
|
if (res->validate && imm != orig_val) {
|
||||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %u -> %u\n",
|
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %llu -> %llu\n",
|
||||||
prog_name, relo_idx,
|
prog_name, relo_idx,
|
||||||
insn_idx, (unsigned long long)imm,
|
insn_idx, (unsigned long long)imm,
|
||||||
orig_val, new_val);
|
(unsigned long long)orig_val, (unsigned long long)new_val);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
insn[0].imm = new_val;
|
insn[0].imm = new_val;
|
||||||
insn[1].imm = 0; /* currently only 32-bit values are supported */
|
insn[1].imm = new_val >> 32;
|
||||||
pr_debug("prog '%s': relo #%d: patched insn #%d (LDIMM64) imm64 %llu -> %u\n",
|
pr_debug("prog '%s': relo #%d: patched insn #%d (LDIMM64) imm64 %llu -> %llu\n",
|
||||||
prog_name, relo_idx, insn_idx,
|
prog_name, relo_idx, insn_idx,
|
||||||
(unsigned long long)imm, new_val);
|
(unsigned long long)imm, (unsigned long long)new_val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -1080,55 +1145,82 @@ poison:
|
|||||||
* [<type-id>] (<type-name>) + <raw-spec> => <offset>@<spec>,
|
* [<type-id>] (<type-name>) + <raw-spec> => <offset>@<spec>,
|
||||||
* where <spec> is a C-syntax view of recorded field access, e.g.: x.a[3].b
|
* where <spec> is a C-syntax view of recorded field access, e.g.: x.a[3].b
|
||||||
*/
|
*/
|
||||||
static void bpf_core_dump_spec(const char *prog_name, int level, const struct bpf_core_spec *spec)
|
int bpf_core_format_spec(char *buf, size_t buf_sz, const struct bpf_core_spec *spec)
|
||||||
{
|
{
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
const struct btf_enum *e;
|
|
||||||
const char *s;
|
const char *s;
|
||||||
__u32 type_id;
|
__u32 type_id;
|
||||||
int i;
|
int i, len = 0;
|
||||||
|
|
||||||
|
#define append_buf(fmt, args...) \
|
||||||
|
({ \
|
||||||
|
int r; \
|
||||||
|
r = snprintf(buf, buf_sz, fmt, ##args); \
|
||||||
|
len += r; \
|
||||||
|
if (r >= buf_sz) \
|
||||||
|
r = buf_sz; \
|
||||||
|
buf += r; \
|
||||||
|
buf_sz -= r; \
|
||||||
|
})
|
||||||
|
|
||||||
type_id = spec->root_type_id;
|
type_id = spec->root_type_id;
|
||||||
t = btf_type_by_id(spec->btf, type_id);
|
t = btf_type_by_id(spec->btf, type_id);
|
||||||
s = btf__name_by_offset(spec->btf, t->name_off);
|
s = btf__name_by_offset(spec->btf, t->name_off);
|
||||||
|
|
||||||
libbpf_print(level, "[%u] %s %s", type_id, btf_kind_str(t), str_is_empty(s) ? "<anon>" : s);
|
append_buf("<%s> [%u] %s %s",
|
||||||
|
core_relo_kind_str(spec->relo_kind),
|
||||||
|
type_id, btf_kind_str(t), str_is_empty(s) ? "<anon>" : s);
|
||||||
|
|
||||||
if (core_relo_is_type_based(spec->relo_kind))
|
if (core_relo_is_type_based(spec->relo_kind))
|
||||||
return;
|
return len;
|
||||||
|
|
||||||
if (core_relo_is_enumval_based(spec->relo_kind)) {
|
if (core_relo_is_enumval_based(spec->relo_kind)) {
|
||||||
t = skip_mods_and_typedefs(spec->btf, type_id, NULL);
|
t = skip_mods_and_typedefs(spec->btf, type_id, NULL);
|
||||||
e = btf_enum(t) + spec->raw_spec[0];
|
if (btf_is_enum(t)) {
|
||||||
s = btf__name_by_offset(spec->btf, e->name_off);
|
const struct btf_enum *e;
|
||||||
|
const char *fmt_str;
|
||||||
|
|
||||||
libbpf_print(level, "::%s = %u", s, e->val);
|
e = btf_enum(t) + spec->raw_spec[0];
|
||||||
return;
|
s = btf__name_by_offset(spec->btf, e->name_off);
|
||||||
|
fmt_str = BTF_INFO_KFLAG(t->info) ? "::%s = %d" : "::%s = %u";
|
||||||
|
append_buf(fmt_str, s, e->val);
|
||||||
|
} else {
|
||||||
|
const struct btf_enum64 *e;
|
||||||
|
const char *fmt_str;
|
||||||
|
|
||||||
|
e = btf_enum64(t) + spec->raw_spec[0];
|
||||||
|
s = btf__name_by_offset(spec->btf, e->name_off);
|
||||||
|
fmt_str = BTF_INFO_KFLAG(t->info) ? "::%s = %lld" : "::%s = %llu";
|
||||||
|
append_buf(fmt_str, s, (unsigned long long)btf_enum64_value(e));
|
||||||
|
}
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core_relo_is_field_based(spec->relo_kind)) {
|
if (core_relo_is_field_based(spec->relo_kind)) {
|
||||||
for (i = 0; i < spec->len; i++) {
|
for (i = 0; i < spec->len; i++) {
|
||||||
if (spec->spec[i].name)
|
if (spec->spec[i].name)
|
||||||
libbpf_print(level, ".%s", spec->spec[i].name);
|
append_buf(".%s", spec->spec[i].name);
|
||||||
else if (i > 0 || spec->spec[i].idx > 0)
|
else if (i > 0 || spec->spec[i].idx > 0)
|
||||||
libbpf_print(level, "[%u]", spec->spec[i].idx);
|
append_buf("[%u]", spec->spec[i].idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
libbpf_print(level, " (");
|
append_buf(" (");
|
||||||
for (i = 0; i < spec->raw_len; i++)
|
for (i = 0; i < spec->raw_len; i++)
|
||||||
libbpf_print(level, "%s%d", i == 0 ? "" : ":", spec->raw_spec[i]);
|
append_buf("%s%d", i == 0 ? "" : ":", spec->raw_spec[i]);
|
||||||
|
|
||||||
if (spec->bit_offset % 8)
|
if (spec->bit_offset % 8)
|
||||||
libbpf_print(level, " @ offset %u.%u)",
|
append_buf(" @ offset %u.%u)", spec->bit_offset / 8, spec->bit_offset % 8);
|
||||||
spec->bit_offset / 8, spec->bit_offset % 8);
|
|
||||||
else
|
else
|
||||||
libbpf_print(level, " @ offset %u)", spec->bit_offset / 8);
|
append_buf(" @ offset %u)", spec->bit_offset / 8);
|
||||||
return;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
#undef append_buf
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CO-RE relocate single instruction.
|
* Calculate CO-RE relocation target result.
|
||||||
*
|
*
|
||||||
* The outline and important points of the algorithm:
|
* The outline and important points of the algorithm:
|
||||||
* 1. For given local type, find corresponding candidate target types.
|
* 1. For given local type, find corresponding candidate target types.
|
||||||
@@ -1159,11 +1251,11 @@ static void bpf_core_dump_spec(const char *prog_name, int level, const struct bp
|
|||||||
* 3. It is supported and expected that there might be multiple flavors
|
* 3. It is supported and expected that there might be multiple flavors
|
||||||
* matching the spec. As long as all the specs resolve to the same set of
|
* matching the spec. As long as all the specs resolve to the same set of
|
||||||
* offsets across all candidates, there is no error. If there is any
|
* offsets across all candidates, there is no error. If there is any
|
||||||
* ambiguity, CO-RE relocation will fail. This is necessary to accomodate
|
* ambiguity, CO-RE relocation will fail. This is necessary to accommodate
|
||||||
* imprefection of BTF deduplication, which can cause slight duplication of
|
* imperfection of BTF deduplication, which can cause slight duplication of
|
||||||
* the same BTF type, if some directly or indirectly referenced (by
|
* the same BTF type, if some directly or indirectly referenced (by
|
||||||
* pointer) type gets resolved to different actual types in different
|
* pointer) type gets resolved to different actual types in different
|
||||||
* object files. If such situation occurs, deduplicated BTF will end up
|
* object files. If such a situation occurs, deduplicated BTF will end up
|
||||||
* with two (or more) structurally identical types, which differ only in
|
* with two (or more) structurally identical types, which differ only in
|
||||||
* types they refer to through pointer. This should be OK in most cases and
|
* types they refer to through pointer. This should be OK in most cases and
|
||||||
* is not an error.
|
* is not an error.
|
||||||
@@ -1177,22 +1269,22 @@ static void bpf_core_dump_spec(const char *prog_name, int level, const struct bp
|
|||||||
* between multiple relocations for the same type ID and is updated as some
|
* between multiple relocations for the same type ID and is updated as some
|
||||||
* of the candidates are pruned due to structural incompatibility.
|
* of the candidates are pruned due to structural incompatibility.
|
||||||
*/
|
*/
|
||||||
int bpf_core_apply_relo_insn(const char *prog_name, struct bpf_insn *insn,
|
int bpf_core_calc_relo_insn(const char *prog_name,
|
||||||
int insn_idx,
|
const struct bpf_core_relo *relo,
|
||||||
const struct bpf_core_relo *relo,
|
int relo_idx,
|
||||||
int relo_idx,
|
const struct btf *local_btf,
|
||||||
const struct btf *local_btf,
|
struct bpf_core_cand_list *cands,
|
||||||
struct bpf_core_cand_list *cands,
|
struct bpf_core_spec *specs_scratch,
|
||||||
struct bpf_core_spec *specs_scratch)
|
struct bpf_core_relo_res *targ_res)
|
||||||
{
|
{
|
||||||
struct bpf_core_spec *local_spec = &specs_scratch[0];
|
struct bpf_core_spec *local_spec = &specs_scratch[0];
|
||||||
struct bpf_core_spec *cand_spec = &specs_scratch[1];
|
struct bpf_core_spec *cand_spec = &specs_scratch[1];
|
||||||
struct bpf_core_spec *targ_spec = &specs_scratch[2];
|
struct bpf_core_spec *targ_spec = &specs_scratch[2];
|
||||||
struct bpf_core_relo_res cand_res, targ_res;
|
struct bpf_core_relo_res cand_res;
|
||||||
const struct btf_type *local_type;
|
const struct btf_type *local_type;
|
||||||
const char *local_name;
|
const char *local_name;
|
||||||
__u32 local_id;
|
__u32 local_id;
|
||||||
const char *spec_str;
|
char spec_buf[256];
|
||||||
int i, j, err;
|
int i, j, err;
|
||||||
|
|
||||||
local_id = relo->type_id;
|
local_id = relo->type_id;
|
||||||
@@ -1201,38 +1293,34 @@ int bpf_core_apply_relo_insn(const char *prog_name, struct bpf_insn *insn,
|
|||||||
if (!local_name)
|
if (!local_name)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
spec_str = btf__name_by_offset(local_btf, relo->access_str_off);
|
err = bpf_core_parse_spec(prog_name, local_btf, relo, local_spec);
|
||||||
if (str_is_empty(spec_str))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
err = bpf_core_parse_spec(prog_name, local_btf, local_id, spec_str,
|
|
||||||
relo->kind, local_spec);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
const char *spec_str;
|
||||||
|
|
||||||
|
spec_str = btf__name_by_offset(local_btf, relo->access_str_off);
|
||||||
pr_warn("prog '%s': relo #%d: parsing [%d] %s %s + %s failed: %d\n",
|
pr_warn("prog '%s': relo #%d: parsing [%d] %s %s + %s failed: %d\n",
|
||||||
prog_name, relo_idx, local_id, btf_kind_str(local_type),
|
prog_name, relo_idx, local_id, btf_kind_str(local_type),
|
||||||
str_is_empty(local_name) ? "<anon>" : local_name,
|
str_is_empty(local_name) ? "<anon>" : local_name,
|
||||||
spec_str, err);
|
spec_str ?: "<?>", err);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_debug("prog '%s': relo #%d: kind <%s> (%d), spec is ", prog_name,
|
bpf_core_format_spec(spec_buf, sizeof(spec_buf), local_spec);
|
||||||
relo_idx, core_relo_kind_str(relo->kind), relo->kind);
|
pr_debug("prog '%s': relo #%d: %s\n", prog_name, relo_idx, spec_buf);
|
||||||
bpf_core_dump_spec(prog_name, LIBBPF_DEBUG, local_spec);
|
|
||||||
libbpf_print(LIBBPF_DEBUG, "\n");
|
|
||||||
|
|
||||||
/* TYPE_ID_LOCAL relo is special and doesn't need candidate search */
|
/* TYPE_ID_LOCAL relo is special and doesn't need candidate search */
|
||||||
if (relo->kind == BPF_CORE_TYPE_ID_LOCAL) {
|
if (relo->kind == BPF_CORE_TYPE_ID_LOCAL) {
|
||||||
/* bpf_insn's imm value could get out of sync during linking */
|
/* bpf_insn's imm value could get out of sync during linking */
|
||||||
memset(&targ_res, 0, sizeof(targ_res));
|
memset(targ_res, 0, sizeof(*targ_res));
|
||||||
targ_res.validate = false;
|
targ_res->validate = false;
|
||||||
targ_res.poison = false;
|
targ_res->poison = false;
|
||||||
targ_res.orig_val = local_spec->root_type_id;
|
targ_res->orig_val = local_spec->root_type_id;
|
||||||
targ_res.new_val = local_spec->root_type_id;
|
targ_res->new_val = local_spec->root_type_id;
|
||||||
goto patch_insn;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* libbpf doesn't support candidate search for anonymous types */
|
/* libbpf doesn't support candidate search for anonymous types */
|
||||||
if (str_is_empty(spec_str)) {
|
if (str_is_empty(local_name)) {
|
||||||
pr_warn("prog '%s': relo #%d: <%s> (%d) relocation doesn't support anonymous types\n",
|
pr_warn("prog '%s': relo #%d: <%s> (%d) relocation doesn't support anonymous types\n",
|
||||||
prog_name, relo_idx, core_relo_kind_str(relo->kind), relo->kind);
|
prog_name, relo_idx, core_relo_kind_str(relo->kind), relo->kind);
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
@@ -1242,17 +1330,15 @@ int bpf_core_apply_relo_insn(const char *prog_name, struct bpf_insn *insn,
|
|||||||
err = bpf_core_spec_match(local_spec, cands->cands[i].btf,
|
err = bpf_core_spec_match(local_spec, cands->cands[i].btf,
|
||||||
cands->cands[i].id, cand_spec);
|
cands->cands[i].id, cand_spec);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
pr_warn("prog '%s': relo #%d: error matching candidate #%d ",
|
bpf_core_format_spec(spec_buf, sizeof(spec_buf), cand_spec);
|
||||||
prog_name, relo_idx, i);
|
pr_warn("prog '%s': relo #%d: error matching candidate #%d %s: %d\n ",
|
||||||
bpf_core_dump_spec(prog_name, LIBBPF_WARN, cand_spec);
|
prog_name, relo_idx, i, spec_buf, err);
|
||||||
libbpf_print(LIBBPF_WARN, ": %d\n", err);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_debug("prog '%s': relo #%d: %s candidate #%d ", prog_name,
|
bpf_core_format_spec(spec_buf, sizeof(spec_buf), cand_spec);
|
||||||
relo_idx, err == 0 ? "non-matching" : "matching", i);
|
pr_debug("prog '%s': relo #%d: %s candidate #%d %s\n", prog_name,
|
||||||
bpf_core_dump_spec(prog_name, LIBBPF_DEBUG, cand_spec);
|
relo_idx, err == 0 ? "non-matching" : "matching", i, spec_buf);
|
||||||
libbpf_print(LIBBPF_DEBUG, "\n");
|
|
||||||
|
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -1262,7 +1348,7 @@ int bpf_core_apply_relo_insn(const char *prog_name, struct bpf_insn *insn,
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (j == 0) {
|
if (j == 0) {
|
||||||
targ_res = cand_res;
|
*targ_res = cand_res;
|
||||||
*targ_spec = *cand_spec;
|
*targ_spec = *cand_spec;
|
||||||
} else if (cand_spec->bit_offset != targ_spec->bit_offset) {
|
} else if (cand_spec->bit_offset != targ_spec->bit_offset) {
|
||||||
/* if there are many field relo candidates, they
|
/* if there are many field relo candidates, they
|
||||||
@@ -1272,15 +1358,18 @@ int bpf_core_apply_relo_insn(const char *prog_name, struct bpf_insn *insn,
|
|||||||
prog_name, relo_idx, cand_spec->bit_offset,
|
prog_name, relo_idx, cand_spec->bit_offset,
|
||||||
targ_spec->bit_offset);
|
targ_spec->bit_offset);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
} else if (cand_res.poison != targ_res.poison || cand_res.new_val != targ_res.new_val) {
|
} else if (cand_res.poison != targ_res->poison ||
|
||||||
|
cand_res.new_val != targ_res->new_val) {
|
||||||
/* all candidates should result in the same relocation
|
/* all candidates should result in the same relocation
|
||||||
* decision and value, otherwise it's dangerous to
|
* decision and value, otherwise it's dangerous to
|
||||||
* proceed due to ambiguity
|
* proceed due to ambiguity
|
||||||
*/
|
*/
|
||||||
pr_warn("prog '%s': relo #%d: relocation decision ambiguity: %s %u != %s %u\n",
|
pr_warn("prog '%s': relo #%d: relocation decision ambiguity: %s %llu != %s %llu\n",
|
||||||
prog_name, relo_idx,
|
prog_name, relo_idx,
|
||||||
cand_res.poison ? "failure" : "success", cand_res.new_val,
|
cand_res.poison ? "failure" : "success",
|
||||||
targ_res.poison ? "failure" : "success", targ_res.new_val);
|
(unsigned long long)cand_res.new_val,
|
||||||
|
targ_res->poison ? "failure" : "success",
|
||||||
|
(unsigned long long)targ_res->new_val);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1314,19 +1403,10 @@ int bpf_core_apply_relo_insn(const char *prog_name, struct bpf_insn *insn,
|
|||||||
prog_name, relo_idx);
|
prog_name, relo_idx);
|
||||||
|
|
||||||
/* calculate single target relo result explicitly */
|
/* calculate single target relo result explicitly */
|
||||||
err = bpf_core_calc_relo(prog_name, relo, relo_idx, local_spec, NULL, &targ_res);
|
err = bpf_core_calc_relo(prog_name, relo, relo_idx, local_spec, NULL, targ_res);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_insn:
|
|
||||||
/* bpf_core_patch_insn() should know how to handle missing targ_spec */
|
|
||||||
err = bpf_core_patch_insn(prog_name, insn, insn_idx, relo, relo_idx, &targ_res);
|
|
||||||
if (err) {
|
|
||||||
pr_warn("prog '%s': relo #%d: failed to patch insn #%u: %d\n",
|
|
||||||
prog_name, relo_idx, relo->insn_off / 8, err);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,14 +44,52 @@ struct bpf_core_spec {
|
|||||||
__u32 bit_offset;
|
__u32 bit_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
int bpf_core_apply_relo_insn(const char *prog_name,
|
struct bpf_core_relo_res {
|
||||||
struct bpf_insn *insn, int insn_idx,
|
/* expected value in the instruction, unless validate == false */
|
||||||
const struct bpf_core_relo *relo, int relo_idx,
|
__u64 orig_val;
|
||||||
const struct btf *local_btf,
|
/* new value that needs to be patched up to */
|
||||||
struct bpf_core_cand_list *cands,
|
__u64 new_val;
|
||||||
struct bpf_core_spec *specs_scratch);
|
/* relocation unsuccessful, poison instruction, but don't fail load */
|
||||||
|
bool poison;
|
||||||
|
/* some relocations can't be validated against orig_val */
|
||||||
|
bool validate;
|
||||||
|
/* for field byte offset relocations or the forms:
|
||||||
|
* *(T *)(rX + <off>) = rY
|
||||||
|
* rX = *(T *)(rY + <off>),
|
||||||
|
* we remember original and resolved field size to adjust direct
|
||||||
|
* memory loads of pointers and integers; this is necessary for 32-bit
|
||||||
|
* host kernel architectures, but also allows to automatically
|
||||||
|
* relocate fields that were resized from, e.g., u32 to u64, etc.
|
||||||
|
*/
|
||||||
|
bool fail_memsz_adjust;
|
||||||
|
__u32 orig_sz;
|
||||||
|
__u32 orig_type_id;
|
||||||
|
__u32 new_sz;
|
||||||
|
__u32 new_type_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id,
|
||||||
|
const struct btf *targ_btf, __u32 targ_id, int level);
|
||||||
int bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id,
|
int bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id,
|
||||||
const struct btf *targ_btf, __u32 targ_id);
|
const struct btf *targ_btf, __u32 targ_id);
|
||||||
|
|
||||||
size_t bpf_core_essential_name_len(const char *name);
|
size_t bpf_core_essential_name_len(const char *name);
|
||||||
|
|
||||||
|
int bpf_core_calc_relo_insn(const char *prog_name,
|
||||||
|
const struct bpf_core_relo *relo, int relo_idx,
|
||||||
|
const struct btf *local_btf,
|
||||||
|
struct bpf_core_cand_list *cands,
|
||||||
|
struct bpf_core_spec *specs_scratch,
|
||||||
|
struct bpf_core_relo_res *targ_res);
|
||||||
|
|
||||||
|
int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
|
||||||
|
int insn_idx, const struct bpf_core_relo *relo,
|
||||||
|
int relo_idx, const struct bpf_core_relo_res *res);
|
||||||
|
|
||||||
|
int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
||||||
|
const struct bpf_core_relo *relo,
|
||||||
|
struct bpf_core_spec *spec);
|
||||||
|
|
||||||
|
int bpf_core_format_spec(char *buf, size_t buf_sz, const struct bpf_core_spec *spec);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,9 +3,19 @@
|
|||||||
#ifndef __SKEL_INTERNAL_H
|
#ifndef __SKEL_INTERNAL_H
|
||||||
#define __SKEL_INTERNAL_H
|
#define __SKEL_INTERNAL_H
|
||||||
|
|
||||||
|
#ifdef __KERNEL__
|
||||||
|
#include <linux/fdtable.h>
|
||||||
|
#include <linux/mm.h>
|
||||||
|
#include <linux/mman.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
#include <linux/bpf.h>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "bpf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef __NR_bpf
|
#ifndef __NR_bpf
|
||||||
# if defined(__mips__) && defined(_ABIO32)
|
# if defined(__mips__) && defined(_ABIO32)
|
||||||
@@ -25,24 +35,23 @@
|
|||||||
* requested during loader program generation.
|
* requested during loader program generation.
|
||||||
*/
|
*/
|
||||||
struct bpf_map_desc {
|
struct bpf_map_desc {
|
||||||
union {
|
/* output of the loader prog */
|
||||||
/* input for the loader prog */
|
int map_fd;
|
||||||
struct {
|
/* input for the loader prog */
|
||||||
__aligned_u64 initial_value;
|
__u32 max_entries;
|
||||||
__u32 max_entries;
|
__aligned_u64 initial_value;
|
||||||
};
|
|
||||||
/* output of the loader prog */
|
|
||||||
struct {
|
|
||||||
int map_fd;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
struct bpf_prog_desc {
|
struct bpf_prog_desc {
|
||||||
int prog_fd;
|
int prog_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
BPF_SKEL_KERNEL = (1ULL << 0),
|
||||||
|
};
|
||||||
|
|
||||||
struct bpf_loader_ctx {
|
struct bpf_loader_ctx {
|
||||||
size_t sz;
|
__u32 sz;
|
||||||
|
__u32 flags;
|
||||||
__u32 log_level;
|
__u32 log_level;
|
||||||
__u32 log_size;
|
__u32 log_size;
|
||||||
__u64 log_buf;
|
__u64 log_buf;
|
||||||
@@ -57,12 +66,144 @@ struct bpf_load_and_run_opts {
|
|||||||
const char *errstr;
|
const char *errstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
long bpf_sys_bpf(__u32 cmd, void *attr, __u32 attr_size);
|
||||||
|
|
||||||
static inline int skel_sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
|
static inline int skel_sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
|
||||||
unsigned int size)
|
unsigned int size)
|
||||||
{
|
{
|
||||||
|
#ifdef __KERNEL__
|
||||||
|
return bpf_sys_bpf(cmd, attr, size);
|
||||||
|
#else
|
||||||
return syscall(__NR_bpf, cmd, attr, size);
|
return syscall(__NR_bpf, cmd, attr, size);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __KERNEL__
|
||||||
|
static inline int close(int fd)
|
||||||
|
{
|
||||||
|
return close_fd(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *skel_alloc(size_t size)
|
||||||
|
{
|
||||||
|
struct bpf_loader_ctx *ctx = kzalloc(size, GFP_KERNEL);
|
||||||
|
|
||||||
|
if (!ctx)
|
||||||
|
return NULL;
|
||||||
|
ctx->flags |= BPF_SKEL_KERNEL;
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void skel_free(const void *p)
|
||||||
|
{
|
||||||
|
kfree(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* skel->bss/rodata maps are populated the following way:
|
||||||
|
*
|
||||||
|
* For kernel use:
|
||||||
|
* skel_prep_map_data() allocates kernel memory that kernel module can directly access.
|
||||||
|
* Generated lskel stores the pointer in skel->rodata and in skel->maps.rodata.initial_value.
|
||||||
|
* The loader program will perform probe_read_kernel() from maps.rodata.initial_value.
|
||||||
|
* skel_finalize_map_data() sets skel->rodata to point to actual value in a bpf map and
|
||||||
|
* does maps.rodata.initial_value = ~0ULL to signal skel_free_map_data() that kvfree
|
||||||
|
* is not nessary.
|
||||||
|
*
|
||||||
|
* For user space:
|
||||||
|
* skel_prep_map_data() mmaps anon memory into skel->rodata that can be accessed directly.
|
||||||
|
* Generated lskel stores the pointer in skel->rodata and in skel->maps.rodata.initial_value.
|
||||||
|
* The loader program will perform copy_from_user() from maps.rodata.initial_value.
|
||||||
|
* skel_finalize_map_data() remaps bpf array map value from the kernel memory into
|
||||||
|
* skel->rodata address.
|
||||||
|
*
|
||||||
|
* The "bpftool gen skeleton -L" command generates lskel.h that is suitable for
|
||||||
|
* both kernel and user space. The generated loader program does
|
||||||
|
* either bpf_probe_read_kernel() or bpf_copy_from_user() from initial_value
|
||||||
|
* depending on bpf_loader_ctx->flags.
|
||||||
|
*/
|
||||||
|
static inline void skel_free_map_data(void *p, __u64 addr, size_t sz)
|
||||||
|
{
|
||||||
|
if (addr != ~0ULL)
|
||||||
|
kvfree(p);
|
||||||
|
/* When addr == ~0ULL the 'p' points to
|
||||||
|
* ((struct bpf_array *)map)->value. See skel_finalize_map_data.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *skel_prep_map_data(const void *val, size_t mmap_sz, size_t val_sz)
|
||||||
|
{
|
||||||
|
void *addr;
|
||||||
|
|
||||||
|
addr = kvmalloc(val_sz, GFP_KERNEL);
|
||||||
|
if (!addr)
|
||||||
|
return NULL;
|
||||||
|
memcpy(addr, val, val_sz);
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *skel_finalize_map_data(__u64 *init_val, size_t mmap_sz, int flags, int fd)
|
||||||
|
{
|
||||||
|
struct bpf_map *map;
|
||||||
|
void *addr = NULL;
|
||||||
|
|
||||||
|
kvfree((void *) (long) *init_val);
|
||||||
|
*init_val = ~0ULL;
|
||||||
|
|
||||||
|
/* At this point bpf_load_and_run() finished without error and
|
||||||
|
* 'fd' is a valid bpf map FD. All sanity checks below should succeed.
|
||||||
|
*/
|
||||||
|
map = bpf_map_get(fd);
|
||||||
|
if (IS_ERR(map))
|
||||||
|
return NULL;
|
||||||
|
if (map->map_type != BPF_MAP_TYPE_ARRAY)
|
||||||
|
goto out;
|
||||||
|
addr = ((struct bpf_array *)map)->value;
|
||||||
|
/* the addr stays valid, since FD is not closed */
|
||||||
|
out:
|
||||||
|
bpf_map_put(map);
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void *skel_alloc(size_t size)
|
||||||
|
{
|
||||||
|
return calloc(1, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void skel_free(void *p)
|
||||||
|
{
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void skel_free_map_data(void *p, __u64 addr, size_t sz)
|
||||||
|
{
|
||||||
|
munmap(p, sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *skel_prep_map_data(const void *val, size_t mmap_sz, size_t val_sz)
|
||||||
|
{
|
||||||
|
void *addr;
|
||||||
|
|
||||||
|
addr = mmap(NULL, mmap_sz, PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||||
|
if (addr == (void *) -1)
|
||||||
|
return NULL;
|
||||||
|
memcpy(addr, val, val_sz);
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *skel_finalize_map_data(__u64 *init_val, size_t mmap_sz, int flags, int fd)
|
||||||
|
{
|
||||||
|
void *addr;
|
||||||
|
|
||||||
|
addr = mmap((void *) (long) *init_val, mmap_sz, flags, MAP_SHARED | MAP_FIXED, fd, 0);
|
||||||
|
if (addr == (void *) -1)
|
||||||
|
return NULL;
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline int skel_closenz(int fd)
|
static inline int skel_closenz(int fd)
|
||||||
{
|
{
|
||||||
if (fd > 0)
|
if (fd > 0)
|
||||||
@@ -136,22 +277,28 @@ static inline int skel_link_create(int prog_fd, int target_fd,
|
|||||||
return skel_sys_bpf(BPF_LINK_CREATE, &attr, attr_sz);
|
return skel_sys_bpf(BPF_LINK_CREATE, &attr, attr_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __KERNEL__
|
||||||
|
#define set_err
|
||||||
|
#else
|
||||||
|
#define set_err err = -errno
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)
|
static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)
|
||||||
{
|
{
|
||||||
int map_fd = -1, prog_fd = -1, key = 0, err;
|
int map_fd = -1, prog_fd = -1, key = 0, err;
|
||||||
union bpf_attr attr;
|
union bpf_attr attr;
|
||||||
|
|
||||||
map_fd = skel_map_create(BPF_MAP_TYPE_ARRAY, "__loader.map", 4, opts->data_sz, 1);
|
err = map_fd = skel_map_create(BPF_MAP_TYPE_ARRAY, "__loader.map", 4, opts->data_sz, 1);
|
||||||
if (map_fd < 0) {
|
if (map_fd < 0) {
|
||||||
opts->errstr = "failed to create loader map";
|
opts->errstr = "failed to create loader map";
|
||||||
err = -errno;
|
set_err;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = skel_map_update_elem(map_fd, &key, opts->data, 0);
|
err = skel_map_update_elem(map_fd, &key, opts->data, 0);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
opts->errstr = "failed to update loader map";
|
opts->errstr = "failed to update loader map";
|
||||||
err = -errno;
|
set_err;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,10 +313,10 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)
|
|||||||
attr.log_size = opts->ctx->log_size;
|
attr.log_size = opts->ctx->log_size;
|
||||||
attr.log_buf = opts->ctx->log_buf;
|
attr.log_buf = opts->ctx->log_buf;
|
||||||
attr.prog_flags = BPF_F_SLEEPABLE;
|
attr.prog_flags = BPF_F_SLEEPABLE;
|
||||||
prog_fd = skel_sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
err = prog_fd = skel_sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
|
||||||
if (prog_fd < 0) {
|
if (prog_fd < 0) {
|
||||||
opts->errstr = "failed to load loader prog";
|
opts->errstr = "failed to load loader prog";
|
||||||
err = -errno;
|
set_err;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,10 +328,12 @@ static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)
|
|||||||
if (err < 0 || (int)attr.test.retval < 0) {
|
if (err < 0 || (int)attr.test.retval < 0) {
|
||||||
opts->errstr = "failed to execute loader prog";
|
opts->errstr = "failed to execute loader prog";
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
err = -errno;
|
set_err;
|
||||||
} else {
|
} else {
|
||||||
err = (int)attr.test.retval;
|
err = (int)attr.test.retval;
|
||||||
|
#ifndef __KERNEL__
|
||||||
errno = -err;
|
errno = -err;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
259
src/usdt.bpf.h
Normal file
259
src/usdt.bpf.h
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
|
||||||
|
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
|
||||||
|
#ifndef __USDT_BPF_H__
|
||||||
|
#define __USDT_BPF_H__
|
||||||
|
|
||||||
|
#include <linux/errno.h>
|
||||||
|
#include <bpf/bpf_helpers.h>
|
||||||
|
#include <bpf/bpf_tracing.h>
|
||||||
|
#include <bpf/bpf_core_read.h>
|
||||||
|
|
||||||
|
/* Below types and maps are internal implementation details of libbpf's USDT
|
||||||
|
* support and are subjects to change. Also, bpf_usdt_xxx() API helpers should
|
||||||
|
* be considered an unstable API as well and might be adjusted based on user
|
||||||
|
* feedback from using libbpf's USDT support in production.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* User can override BPF_USDT_MAX_SPEC_CNT to change default size of internal
|
||||||
|
* map that keeps track of USDT argument specifications. This might be
|
||||||
|
* necessary if there are a lot of USDT attachments.
|
||||||
|
*/
|
||||||
|
#ifndef BPF_USDT_MAX_SPEC_CNT
|
||||||
|
#define BPF_USDT_MAX_SPEC_CNT 256
|
||||||
|
#endif
|
||||||
|
/* User can override BPF_USDT_MAX_IP_CNT to change default size of internal
|
||||||
|
* map that keeps track of IP (memory address) mapping to USDT argument
|
||||||
|
* specification.
|
||||||
|
* Note, if kernel supports BPF cookies, this map is not used and could be
|
||||||
|
* resized all the way to 1 to save a bit of memory.
|
||||||
|
*/
|
||||||
|
#ifndef BPF_USDT_MAX_IP_CNT
|
||||||
|
#define BPF_USDT_MAX_IP_CNT (4 * BPF_USDT_MAX_SPEC_CNT)
|
||||||
|
#endif
|
||||||
|
/* We use BPF CO-RE to detect support for BPF cookie from BPF side. This is
|
||||||
|
* the only dependency on CO-RE, so if it's undesirable, user can override
|
||||||
|
* BPF_USDT_HAS_BPF_COOKIE to specify whether to BPF cookie is supported or not.
|
||||||
|
*/
|
||||||
|
#ifndef BPF_USDT_HAS_BPF_COOKIE
|
||||||
|
#define BPF_USDT_HAS_BPF_COOKIE \
|
||||||
|
bpf_core_enum_value_exists(enum bpf_func_id___usdt, BPF_FUNC_get_attach_cookie___usdt)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum __bpf_usdt_arg_type {
|
||||||
|
BPF_USDT_ARG_CONST,
|
||||||
|
BPF_USDT_ARG_REG,
|
||||||
|
BPF_USDT_ARG_REG_DEREF,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct __bpf_usdt_arg_spec {
|
||||||
|
/* u64 scalar interpreted depending on arg_type, see below */
|
||||||
|
__u64 val_off;
|
||||||
|
/* arg location case, see bpf_udst_arg() for details */
|
||||||
|
enum __bpf_usdt_arg_type arg_type;
|
||||||
|
/* offset of referenced register within struct pt_regs */
|
||||||
|
short reg_off;
|
||||||
|
/* whether arg should be interpreted as signed value */
|
||||||
|
bool arg_signed;
|
||||||
|
/* number of bits that need to be cleared and, optionally,
|
||||||
|
* sign-extended to cast arguments that are 1, 2, or 4 bytes
|
||||||
|
* long into final 8-byte u64/s64 value returned to user
|
||||||
|
*/
|
||||||
|
char arg_bitshift;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* should match USDT_MAX_ARG_CNT in usdt.c exactly */
|
||||||
|
#define BPF_USDT_MAX_ARG_CNT 12
|
||||||
|
struct __bpf_usdt_spec {
|
||||||
|
struct __bpf_usdt_arg_spec args[BPF_USDT_MAX_ARG_CNT];
|
||||||
|
__u64 usdt_cookie;
|
||||||
|
short arg_cnt;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct {
|
||||||
|
__uint(type, BPF_MAP_TYPE_ARRAY);
|
||||||
|
__uint(max_entries, BPF_USDT_MAX_SPEC_CNT);
|
||||||
|
__type(key, int);
|
||||||
|
__type(value, struct __bpf_usdt_spec);
|
||||||
|
} __bpf_usdt_specs SEC(".maps") __weak;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
__uint(type, BPF_MAP_TYPE_HASH);
|
||||||
|
__uint(max_entries, BPF_USDT_MAX_IP_CNT);
|
||||||
|
__type(key, long);
|
||||||
|
__type(value, __u32);
|
||||||
|
} __bpf_usdt_ip_to_spec_id SEC(".maps") __weak;
|
||||||
|
|
||||||
|
/* don't rely on user's BPF code to have latest definition of bpf_func_id */
|
||||||
|
enum bpf_func_id___usdt {
|
||||||
|
BPF_FUNC_get_attach_cookie___usdt = 0xBAD, /* value doesn't matter */
|
||||||
|
};
|
||||||
|
|
||||||
|
static __always_inline
|
||||||
|
int __bpf_usdt_spec_id(struct pt_regs *ctx)
|
||||||
|
{
|
||||||
|
if (!BPF_USDT_HAS_BPF_COOKIE) {
|
||||||
|
long ip = PT_REGS_IP(ctx);
|
||||||
|
int *spec_id_ptr;
|
||||||
|
|
||||||
|
spec_id_ptr = bpf_map_lookup_elem(&__bpf_usdt_ip_to_spec_id, &ip);
|
||||||
|
return spec_id_ptr ? *spec_id_ptr : -ESRCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bpf_get_attach_cookie(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return number of USDT arguments defined for currently traced USDT. */
|
||||||
|
__weak __hidden
|
||||||
|
int bpf_usdt_arg_cnt(struct pt_regs *ctx)
|
||||||
|
{
|
||||||
|
struct __bpf_usdt_spec *spec;
|
||||||
|
int spec_id;
|
||||||
|
|
||||||
|
spec_id = __bpf_usdt_spec_id(ctx);
|
||||||
|
if (spec_id < 0)
|
||||||
|
return -ESRCH;
|
||||||
|
|
||||||
|
spec = bpf_map_lookup_elem(&__bpf_usdt_specs, &spec_id);
|
||||||
|
if (!spec)
|
||||||
|
return -ESRCH;
|
||||||
|
|
||||||
|
return spec->arg_cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fetch USDT argument #*arg_num* (zero-indexed) and put its value into *res.
|
||||||
|
* Returns 0 on success; negative error, otherwise.
|
||||||
|
* On error *res is guaranteed to be set to zero.
|
||||||
|
*/
|
||||||
|
__weak __hidden
|
||||||
|
int bpf_usdt_arg(struct pt_regs *ctx, __u64 arg_num, long *res)
|
||||||
|
{
|
||||||
|
struct __bpf_usdt_spec *spec;
|
||||||
|
struct __bpf_usdt_arg_spec *arg_spec;
|
||||||
|
unsigned long val;
|
||||||
|
int err, spec_id;
|
||||||
|
|
||||||
|
*res = 0;
|
||||||
|
|
||||||
|
spec_id = __bpf_usdt_spec_id(ctx);
|
||||||
|
if (spec_id < 0)
|
||||||
|
return -ESRCH;
|
||||||
|
|
||||||
|
spec = bpf_map_lookup_elem(&__bpf_usdt_specs, &spec_id);
|
||||||
|
if (!spec)
|
||||||
|
return -ESRCH;
|
||||||
|
|
||||||
|
if (arg_num >= BPF_USDT_MAX_ARG_CNT || arg_num >= spec->arg_cnt)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
arg_spec = &spec->args[arg_num];
|
||||||
|
switch (arg_spec->arg_type) {
|
||||||
|
case BPF_USDT_ARG_CONST:
|
||||||
|
/* Arg is just a constant ("-4@$-9" in USDT arg spec).
|
||||||
|
* value is recorded in arg_spec->val_off directly.
|
||||||
|
*/
|
||||||
|
val = arg_spec->val_off;
|
||||||
|
break;
|
||||||
|
case BPF_USDT_ARG_REG:
|
||||||
|
/* Arg is in a register (e.g, "8@%rax" in USDT arg spec),
|
||||||
|
* so we read the contents of that register directly from
|
||||||
|
* struct pt_regs. To keep things simple user-space parts
|
||||||
|
* record offsetof(struct pt_regs, <regname>) in arg_spec->reg_off.
|
||||||
|
*/
|
||||||
|
err = bpf_probe_read_kernel(&val, sizeof(val), (void *)ctx + arg_spec->reg_off);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
break;
|
||||||
|
case BPF_USDT_ARG_REG_DEREF:
|
||||||
|
/* Arg is in memory addressed by register, plus some offset
|
||||||
|
* (e.g., "-4@-1204(%rbp)" in USDT arg spec). Register is
|
||||||
|
* identified like with BPF_USDT_ARG_REG case, and the offset
|
||||||
|
* is in arg_spec->val_off. We first fetch register contents
|
||||||
|
* from pt_regs, then do another user-space probe read to
|
||||||
|
* fetch argument value itself.
|
||||||
|
*/
|
||||||
|
err = bpf_probe_read_kernel(&val, sizeof(val), (void *)ctx + arg_spec->reg_off);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
err = bpf_probe_read_user(&val, sizeof(val), (void *)val + arg_spec->val_off);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||||
|
val >>= arg_spec->arg_bitshift;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* cast arg from 1, 2, or 4 bytes to final 8 byte size clearing
|
||||||
|
* necessary upper arg_bitshift bits, with sign extension if argument
|
||||||
|
* is signed
|
||||||
|
*/
|
||||||
|
val <<= arg_spec->arg_bitshift;
|
||||||
|
if (arg_spec->arg_signed)
|
||||||
|
val = ((long)val) >> arg_spec->arg_bitshift;
|
||||||
|
else
|
||||||
|
val = val >> arg_spec->arg_bitshift;
|
||||||
|
*res = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retrieve user-specified cookie value provided during attach as
|
||||||
|
* bpf_usdt_opts.usdt_cookie. This serves the same purpose as BPF cookie
|
||||||
|
* returned by bpf_get_attach_cookie(). Libbpf's support for USDT is itself
|
||||||
|
* utilizing BPF cookies internally, so user can't use BPF cookie directly
|
||||||
|
* for USDT programs and has to use bpf_usdt_cookie() API instead.
|
||||||
|
*/
|
||||||
|
__weak __hidden
|
||||||
|
long bpf_usdt_cookie(struct pt_regs *ctx)
|
||||||
|
{
|
||||||
|
struct __bpf_usdt_spec *spec;
|
||||||
|
int spec_id;
|
||||||
|
|
||||||
|
spec_id = __bpf_usdt_spec_id(ctx);
|
||||||
|
if (spec_id < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
spec = bpf_map_lookup_elem(&__bpf_usdt_specs, &spec_id);
|
||||||
|
if (!spec)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return spec->usdt_cookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we rely on ___bpf_apply() and ___bpf_narg() macros already defined in bpf_tracing.h */
|
||||||
|
#define ___bpf_usdt_args0() ctx
|
||||||
|
#define ___bpf_usdt_args1(x) ___bpf_usdt_args0(), ({ long _x; bpf_usdt_arg(ctx, 0, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args2(x, args...) ___bpf_usdt_args1(args), ({ long _x; bpf_usdt_arg(ctx, 1, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args3(x, args...) ___bpf_usdt_args2(args), ({ long _x; bpf_usdt_arg(ctx, 2, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args4(x, args...) ___bpf_usdt_args3(args), ({ long _x; bpf_usdt_arg(ctx, 3, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args5(x, args...) ___bpf_usdt_args4(args), ({ long _x; bpf_usdt_arg(ctx, 4, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args6(x, args...) ___bpf_usdt_args5(args), ({ long _x; bpf_usdt_arg(ctx, 5, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args7(x, args...) ___bpf_usdt_args6(args), ({ long _x; bpf_usdt_arg(ctx, 6, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args8(x, args...) ___bpf_usdt_args7(args), ({ long _x; bpf_usdt_arg(ctx, 7, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args9(x, args...) ___bpf_usdt_args8(args), ({ long _x; bpf_usdt_arg(ctx, 8, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args10(x, args...) ___bpf_usdt_args9(args), ({ long _x; bpf_usdt_arg(ctx, 9, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args11(x, args...) ___bpf_usdt_args10(args), ({ long _x; bpf_usdt_arg(ctx, 10, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args12(x, args...) ___bpf_usdt_args11(args), ({ long _x; bpf_usdt_arg(ctx, 11, &_x); (void *)_x; })
|
||||||
|
#define ___bpf_usdt_args(args...) ___bpf_apply(___bpf_usdt_args, ___bpf_narg(args))(args)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BPF_USDT serves the same purpose for USDT handlers as BPF_PROG for
|
||||||
|
* tp_btf/fentry/fexit BPF programs and BPF_KPROBE for kprobes.
|
||||||
|
* Original struct pt_regs * context is preserved as 'ctx' argument.
|
||||||
|
*/
|
||||||
|
#define BPF_USDT(name, args...) \
|
||||||
|
name(struct pt_regs *ctx); \
|
||||||
|
static __attribute__((always_inline)) typeof(name(0)) \
|
||||||
|
____##name(struct pt_regs *ctx, ##args); \
|
||||||
|
typeof(name(0)) name(struct pt_regs *ctx) \
|
||||||
|
{ \
|
||||||
|
_Pragma("GCC diagnostic push") \
|
||||||
|
_Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \
|
||||||
|
return ____##name(___bpf_usdt_args(args)); \
|
||||||
|
_Pragma("GCC diagnostic pop") \
|
||||||
|
} \
|
||||||
|
static __attribute__((always_inline)) typeof(name(0)) \
|
||||||
|
____##name(struct pt_regs *ctx, ##args)
|
||||||
|
|
||||||
|
#endif /* __USDT_BPF_H__ */
|
||||||
1521
src/usdt.c
Normal file
1521
src/usdt.c
Normal file
File diff suppressed because it is too large
Load Diff
336
src/xsk.h
336
src/xsk.h
@@ -1,336 +0,0 @@
|
|||||||
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* AF_XDP user-space access library.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2018 - 2019 Intel Corporation.
|
|
||||||
* Copyright (c) 2019 Facebook
|
|
||||||
*
|
|
||||||
* Author(s): Magnus Karlsson <magnus.karlsson@intel.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LIBBPF_XSK_H
|
|
||||||
#define __LIBBPF_XSK_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <linux/if_xdp.h>
|
|
||||||
|
|
||||||
#include "libbpf.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This whole API has been deprecated and moved to libxdp that can be found at
|
|
||||||
* https://github.com/xdp-project/xdp-tools. The APIs are exactly the same so
|
|
||||||
* it should just be linking with libxdp instead of libbpf for this set of
|
|
||||||
* functionality. If not, please submit a bug report on the aforementioned page.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Load-Acquire Store-Release barriers used by the XDP socket
|
|
||||||
* library. The following macros should *NOT* be considered part of
|
|
||||||
* the xsk.h API, and is subject to change anytime.
|
|
||||||
*
|
|
||||||
* LIBRARY INTERNAL
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define __XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x)
|
|
||||||
#define __XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v)
|
|
||||||
|
|
||||||
#if defined(__i386__) || defined(__x86_64__)
|
|
||||||
# define libbpf_smp_store_release(p, v) \
|
|
||||||
do { \
|
|
||||||
asm volatile("" : : : "memory"); \
|
|
||||||
__XSK_WRITE_ONCE(*p, v); \
|
|
||||||
} while (0)
|
|
||||||
# define libbpf_smp_load_acquire(p) \
|
|
||||||
({ \
|
|
||||||
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
|
|
||||||
asm volatile("" : : : "memory"); \
|
|
||||||
___p1; \
|
|
||||||
})
|
|
||||||
#elif defined(__aarch64__)
|
|
||||||
# define libbpf_smp_store_release(p, v) \
|
|
||||||
asm volatile ("stlr %w1, %0" : "=Q" (*p) : "r" (v) : "memory")
|
|
||||||
# define libbpf_smp_load_acquire(p) \
|
|
||||||
({ \
|
|
||||||
typeof(*p) ___p1; \
|
|
||||||
asm volatile ("ldar %w0, %1" \
|
|
||||||
: "=r" (___p1) : "Q" (*p) : "memory"); \
|
|
||||||
___p1; \
|
|
||||||
})
|
|
||||||
#elif defined(__riscv)
|
|
||||||
# define libbpf_smp_store_release(p, v) \
|
|
||||||
do { \
|
|
||||||
asm volatile ("fence rw,w" : : : "memory"); \
|
|
||||||
__XSK_WRITE_ONCE(*p, v); \
|
|
||||||
} while (0)
|
|
||||||
# define libbpf_smp_load_acquire(p) \
|
|
||||||
({ \
|
|
||||||
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
|
|
||||||
asm volatile ("fence r,rw" : : : "memory"); \
|
|
||||||
___p1; \
|
|
||||||
})
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef libbpf_smp_store_release
|
|
||||||
#define libbpf_smp_store_release(p, v) \
|
|
||||||
do { \
|
|
||||||
__sync_synchronize(); \
|
|
||||||
__XSK_WRITE_ONCE(*p, v); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef libbpf_smp_load_acquire
|
|
||||||
#define libbpf_smp_load_acquire(p) \
|
|
||||||
({ \
|
|
||||||
typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
|
|
||||||
__sync_synchronize(); \
|
|
||||||
___p1; \
|
|
||||||
})
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* LIBRARY INTERNAL -- END */
|
|
||||||
|
|
||||||
/* Do not access these members directly. Use the functions below. */
|
|
||||||
#define DEFINE_XSK_RING(name) \
|
|
||||||
struct name { \
|
|
||||||
__u32 cached_prod; \
|
|
||||||
__u32 cached_cons; \
|
|
||||||
__u32 mask; \
|
|
||||||
__u32 size; \
|
|
||||||
__u32 *producer; \
|
|
||||||
__u32 *consumer; \
|
|
||||||
void *ring; \
|
|
||||||
__u32 *flags; \
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFINE_XSK_RING(xsk_ring_prod);
|
|
||||||
DEFINE_XSK_RING(xsk_ring_cons);
|
|
||||||
|
|
||||||
/* For a detailed explanation on the memory barriers associated with the
|
|
||||||
* ring, please take a look at net/xdp/xsk_queue.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct xsk_umem;
|
|
||||||
struct xsk_socket;
|
|
||||||
|
|
||||||
static inline __u64 *xsk_ring_prod__fill_addr(struct xsk_ring_prod *fill,
|
|
||||||
__u32 idx)
|
|
||||||
{
|
|
||||||
__u64 *addrs = (__u64 *)fill->ring;
|
|
||||||
|
|
||||||
return &addrs[idx & fill->mask];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline const __u64 *
|
|
||||||
xsk_ring_cons__comp_addr(const struct xsk_ring_cons *comp, __u32 idx)
|
|
||||||
{
|
|
||||||
const __u64 *addrs = (const __u64 *)comp->ring;
|
|
||||||
|
|
||||||
return &addrs[idx & comp->mask];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct xdp_desc *xsk_ring_prod__tx_desc(struct xsk_ring_prod *tx,
|
|
||||||
__u32 idx)
|
|
||||||
{
|
|
||||||
struct xdp_desc *descs = (struct xdp_desc *)tx->ring;
|
|
||||||
|
|
||||||
return &descs[idx & tx->mask];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline const struct xdp_desc *
|
|
||||||
xsk_ring_cons__rx_desc(const struct xsk_ring_cons *rx, __u32 idx)
|
|
||||||
{
|
|
||||||
const struct xdp_desc *descs = (const struct xdp_desc *)rx->ring;
|
|
||||||
|
|
||||||
return &descs[idx & rx->mask];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int xsk_ring_prod__needs_wakeup(const struct xsk_ring_prod *r)
|
|
||||||
{
|
|
||||||
return *r->flags & XDP_RING_NEED_WAKEUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb)
|
|
||||||
{
|
|
||||||
__u32 free_entries = r->cached_cons - r->cached_prod;
|
|
||||||
|
|
||||||
if (free_entries >= nb)
|
|
||||||
return free_entries;
|
|
||||||
|
|
||||||
/* Refresh the local tail pointer.
|
|
||||||
* cached_cons is r->size bigger than the real consumer pointer so
|
|
||||||
* that this addition can be avoided in the more frequently
|
|
||||||
* executed code that computs free_entries in the beginning of
|
|
||||||
* this function. Without this optimization it whould have been
|
|
||||||
* free_entries = r->cached_prod - r->cached_cons + r->size.
|
|
||||||
*/
|
|
||||||
r->cached_cons = libbpf_smp_load_acquire(r->consumer);
|
|
||||||
r->cached_cons += r->size;
|
|
||||||
|
|
||||||
return r->cached_cons - r->cached_prod;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u32 xsk_cons_nb_avail(struct xsk_ring_cons *r, __u32 nb)
|
|
||||||
{
|
|
||||||
__u32 entries = r->cached_prod - r->cached_cons;
|
|
||||||
|
|
||||||
if (entries == 0) {
|
|
||||||
r->cached_prod = libbpf_smp_load_acquire(r->producer);
|
|
||||||
entries = r->cached_prod - r->cached_cons;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (entries > nb) ? nb : entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u32 xsk_ring_prod__reserve(struct xsk_ring_prod *prod, __u32 nb, __u32 *idx)
|
|
||||||
{
|
|
||||||
if (xsk_prod_nb_free(prod, nb) < nb)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
*idx = prod->cached_prod;
|
|
||||||
prod->cached_prod += nb;
|
|
||||||
|
|
||||||
return nb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void xsk_ring_prod__submit(struct xsk_ring_prod *prod, __u32 nb)
|
|
||||||
{
|
|
||||||
/* Make sure everything has been written to the ring before indicating
|
|
||||||
* this to the kernel by writing the producer pointer.
|
|
||||||
*/
|
|
||||||
libbpf_smp_store_release(prod->producer, *prod->producer + nb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u32 xsk_ring_cons__peek(struct xsk_ring_cons *cons, __u32 nb, __u32 *idx)
|
|
||||||
{
|
|
||||||
__u32 entries = xsk_cons_nb_avail(cons, nb);
|
|
||||||
|
|
||||||
if (entries > 0) {
|
|
||||||
*idx = cons->cached_cons;
|
|
||||||
cons->cached_cons += entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void xsk_ring_cons__cancel(struct xsk_ring_cons *cons, __u32 nb)
|
|
||||||
{
|
|
||||||
cons->cached_cons -= nb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void xsk_ring_cons__release(struct xsk_ring_cons *cons, __u32 nb)
|
|
||||||
{
|
|
||||||
/* Make sure data has been read before indicating we are done
|
|
||||||
* with the entries by updating the consumer pointer.
|
|
||||||
*/
|
|
||||||
libbpf_smp_store_release(cons->consumer, *cons->consumer + nb);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void *xsk_umem__get_data(void *umem_area, __u64 addr)
|
|
||||||
{
|
|
||||||
return &((char *)umem_area)[addr];
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u64 xsk_umem__extract_addr(__u64 addr)
|
|
||||||
{
|
|
||||||
return addr & XSK_UNALIGNED_BUF_ADDR_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u64 xsk_umem__extract_offset(__u64 addr)
|
|
||||||
{
|
|
||||||
return addr >> XSK_UNALIGNED_BUF_OFFSET_SHIFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline __u64 xsk_umem__add_offset_to_addr(__u64 addr)
|
|
||||||
{
|
|
||||||
return xsk_umem__extract_addr(addr) + xsk_umem__extract_offset(addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_umem__fd(const struct xsk_umem *umem);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_socket__fd(const struct xsk_socket *xsk);
|
|
||||||
|
|
||||||
#define XSK_RING_CONS__DEFAULT_NUM_DESCS 2048
|
|
||||||
#define XSK_RING_PROD__DEFAULT_NUM_DESCS 2048
|
|
||||||
#define XSK_UMEM__DEFAULT_FRAME_SHIFT 12 /* 4096 bytes */
|
|
||||||
#define XSK_UMEM__DEFAULT_FRAME_SIZE (1 << XSK_UMEM__DEFAULT_FRAME_SHIFT)
|
|
||||||
#define XSK_UMEM__DEFAULT_FRAME_HEADROOM 0
|
|
||||||
#define XSK_UMEM__DEFAULT_FLAGS 0
|
|
||||||
|
|
||||||
struct xsk_umem_config {
|
|
||||||
__u32 fill_size;
|
|
||||||
__u32 comp_size;
|
|
||||||
__u32 frame_size;
|
|
||||||
__u32 frame_headroom;
|
|
||||||
__u32 flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_setup_xdp_prog(int ifindex, int *xsks_map_fd);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_socket__update_xskmap(struct xsk_socket *xsk, int xsks_map_fd);
|
|
||||||
|
|
||||||
/* Flags for the libbpf_flags field. */
|
|
||||||
#define XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD (1 << 0)
|
|
||||||
|
|
||||||
struct xsk_socket_config {
|
|
||||||
__u32 rx_size;
|
|
||||||
__u32 tx_size;
|
|
||||||
__u32 libbpf_flags;
|
|
||||||
__u32 xdp_flags;
|
|
||||||
__u16 bind_flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Set config to NULL to get the default configuration. */
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_umem__create(struct xsk_umem **umem,
|
|
||||||
void *umem_area, __u64 size,
|
|
||||||
struct xsk_ring_prod *fill,
|
|
||||||
struct xsk_ring_cons *comp,
|
|
||||||
const struct xsk_umem_config *config);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_umem__create_v0_0_2(struct xsk_umem **umem,
|
|
||||||
void *umem_area, __u64 size,
|
|
||||||
struct xsk_ring_prod *fill,
|
|
||||||
struct xsk_ring_cons *comp,
|
|
||||||
const struct xsk_umem_config *config);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_umem__create_v0_0_4(struct xsk_umem **umem,
|
|
||||||
void *umem_area, __u64 size,
|
|
||||||
struct xsk_ring_prod *fill,
|
|
||||||
struct xsk_ring_cons *comp,
|
|
||||||
const struct xsk_umem_config *config);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_socket__create(struct xsk_socket **xsk,
|
|
||||||
const char *ifname, __u32 queue_id,
|
|
||||||
struct xsk_umem *umem,
|
|
||||||
struct xsk_ring_cons *rx,
|
|
||||||
struct xsk_ring_prod *tx,
|
|
||||||
const struct xsk_socket_config *config);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
|
|
||||||
const char *ifname,
|
|
||||||
__u32 queue_id, struct xsk_umem *umem,
|
|
||||||
struct xsk_ring_cons *rx,
|
|
||||||
struct xsk_ring_prod *tx,
|
|
||||||
struct xsk_ring_prod *fill,
|
|
||||||
struct xsk_ring_cons *comp,
|
|
||||||
const struct xsk_socket_config *config);
|
|
||||||
|
|
||||||
/* Returns 0 for success and -EBUSY if the umem is still in use. */
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
int xsk_umem__delete(struct xsk_umem *umem);
|
|
||||||
LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "AF_XDP support deprecated and moved to libxdp")
|
|
||||||
void xsk_socket__delete(struct xsk_socket *xsk);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __LIBBPF_XSK_H */
|
|
||||||
@@ -7,7 +7,8 @@ ENV_VARS="${ENV_VARS:-}"
|
|||||||
DOCKER_RUN="${DOCKER_RUN:-docker run}"
|
DOCKER_RUN="${DOCKER_RUN:-docker run}"
|
||||||
REPO_ROOT="${REPO_ROOT:-$PWD}"
|
REPO_ROOT="${REPO_ROOT:-$PWD}"
|
||||||
ADDITIONAL_DEPS=(clang pkg-config gcc-10)
|
ADDITIONAL_DEPS=(clang pkg-config gcc-10)
|
||||||
CFLAGS="-g -O2 -Werror -Wall"
|
EXTRA_CFLAGS=""
|
||||||
|
EXTRA_LDFLAGS=""
|
||||||
|
|
||||||
function info() {
|
function info() {
|
||||||
echo -e "\033[33;1m$1\033[0m"
|
echo -e "\033[33;1m$1\033[0m"
|
||||||
@@ -55,17 +56,17 @@ for phase in "${PHASES[@]}"; do
|
|||||||
elif [[ "$phase" = *"GCC10"* ]]; then
|
elif [[ "$phase" = *"GCC10"* ]]; then
|
||||||
ENV_VARS="-e CC=gcc-10 -e CXX=g++-10"
|
ENV_VARS="-e CC=gcc-10 -e CXX=g++-10"
|
||||||
CC="gcc-10"
|
CC="gcc-10"
|
||||||
CFLAGS="${CFLAGS} -Wno-stringop-truncation"
|
|
||||||
else
|
else
|
||||||
CFLAGS="${CFLAGS} -Wno-stringop-truncation"
|
EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-stringop-truncation"
|
||||||
fi
|
fi
|
||||||
if [[ "$phase" = *"ASAN"* ]]; then
|
if [[ "$phase" = *"ASAN"* ]]; then
|
||||||
CFLAGS="${CFLAGS} -fsanitize=address,undefined"
|
EXTRA_CFLAGS="${EXTRA_CFLAGS} -fsanitize=address,undefined"
|
||||||
|
EXTRA_LDFLAGS="${EXTRA_LDFLAGS} -fsanitize=address,undefined"
|
||||||
fi
|
fi
|
||||||
docker_exec mkdir build install
|
docker_exec mkdir build install
|
||||||
docker_exec ${CC} --version
|
docker_exec ${CC} --version
|
||||||
info "build"
|
info "build"
|
||||||
docker_exec make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build
|
docker_exec make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build
|
||||||
info "ldd build/libbpf.so:"
|
info "ldd build/libbpf.so:"
|
||||||
docker_exec ldd build/libbpf.so
|
docker_exec ldd build/libbpf.so
|
||||||
if ! docker_exec ldd build/libbpf.so | grep -q libelf; then
|
if ! docker_exec ldd build/libbpf.so | grep -q libelf; then
|
||||||
@@ -75,7 +76,7 @@ for phase in "${PHASES[@]}"; do
|
|||||||
info "install"
|
info "install"
|
||||||
docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
|
docker_exec make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
|
||||||
info "link binary"
|
info "link binary"
|
||||||
docker_exec bash -c "CFLAGS=\"${CFLAGS}\" ./travis-ci/managers/test_compile.sh"
|
docker_exec bash -c "EXTRA_CFLAGS=\"${EXTRA_CFLAGS}\" EXTRA_LDFLAGS=\"${EXTRA_LDFLAGS}\" ./travis-ci/managers/test_compile.sh"
|
||||||
;;
|
;;
|
||||||
CLEANUP)
|
CLEANUP)
|
||||||
info "Cleanup phase"
|
info "Cleanup phase"
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euox pipefail
|
set -euox pipefail
|
||||||
|
|
||||||
CFLAGS=${CFLAGS:-}
|
EXTRA_CFLAGS=${EXTRA_CFLAGS:-}
|
||||||
|
EXTRA_LDFLAGS=${EXTRA_LDFLAGS:-}
|
||||||
|
|
||||||
cat << EOF > main.c
|
cat << EOF > main.c
|
||||||
#include <bpf/libbpf.h>
|
#include <bpf/libbpf.h>
|
||||||
@@ -11,4 +12,4 @@ int main() {
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
# static linking
|
# static linking
|
||||||
${CC:-cc} ${CFLAGS} -o main -I./install/usr/include main.c ./build/libbpf.a -lelf -lz
|
${CC:-cc} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o main -I./include/uapi -I./install/usr/include main.c ./build/libbpf.a -lelf -lz
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ source "$(dirname $0)/travis_wait.bash"
|
|||||||
|
|
||||||
cd $REPO_ROOT
|
cd $REPO_ROOT
|
||||||
|
|
||||||
CFLAGS="-g -O2 -Werror -Wall -fsanitize=address,undefined -Wno-stringop-truncation"
|
EXTRA_CFLAGS="-Werror -Wall -fsanitize=address,undefined"
|
||||||
|
EXTRA_LDFLAGS="-Werror -Wall -fsanitize=address,undefined"
|
||||||
mkdir build install
|
mkdir build install
|
||||||
cc --version
|
cc --version
|
||||||
make -j$((4*$(nproc))) CFLAGS="${CFLAGS}" -C ./src -B OBJDIR=../build
|
make -j$((4*$(nproc))) EXTRA_CFLAGS="${EXTRA_CFLAGS}" EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" -C ./src -B OBJDIR=../build
|
||||||
ldd build/libbpf.so
|
ldd build/libbpf.so
|
||||||
if ! ldd build/libbpf.so | grep -q libelf; then
|
if ! ldd build/libbpf.so | grep -q libelf; then
|
||||||
echo "FAIL: No reference to libelf.so in libbpf.so!"
|
echo "FAIL: No reference to libelf.so in libbpf.so!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
|
make -j$((4*$(nproc))) -C src OBJDIR=../build DESTDIR=../install install
|
||||||
CFLAGS=${CFLAGS} $(dirname $0)/test_compile.sh
|
EXTRA_CFLAGS=${EXTRA_CFLAGS} EXTRA_LDFLAGS=${EXTRA_LDFLAGS} $(dirname $0)/test_compile.sh
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ packages=(
|
|||||||
# selftests test_progs dependencies.
|
# selftests test_progs dependencies.
|
||||||
binutils
|
binutils
|
||||||
elfutils
|
elfutils
|
||||||
|
ethtool
|
||||||
glibc
|
glibc
|
||||||
iproute2
|
iproute2
|
||||||
# selftests test_verifier dependencies.
|
# selftests test_verifier dependencies.
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
# This script builds a Debian root filesystem image for testing libbpf in a
|
# This script builds a Debian root filesystem image for testing libbpf in a
|
||||||
# virtual machine. Requires debootstrap >= 1.0.95 and zstd.
|
# virtual machine. Requires debootstrap >= 1.0.95 and zstd.
|
||||||
|
|
||||||
|
# Use e.g. ./mkrootfs_debian.sh --arch=s390x to generate a rootfs for a
|
||||||
|
# foreign architecture. Requires configured binfmt_misc, e.g. using
|
||||||
|
# Debian/Ubuntu's qemu-user-binfmt package or
|
||||||
|
# https://github.com/multiarch/qemu-user-static.
|
||||||
|
|
||||||
set -e -u -x -o pipefail
|
set -e -u -x -o pipefail
|
||||||
|
|
||||||
# Check whether we are root now in order to avoid confusing errors later.
|
# Check whether we are root now in order to avoid confusing errors later.
|
||||||
@@ -15,8 +20,20 @@ root=$(mktemp -d -p "$PWD")
|
|||||||
trap 'rm -r "$root"' EXIT
|
trap 'rm -r "$root"' EXIT
|
||||||
|
|
||||||
# Install packages.
|
# Install packages.
|
||||||
packages=binutils,busybox,elfutils,iproute2,libcap2,libelf1,strace,zlib1g
|
packages=(
|
||||||
debootstrap --include="$packages" --variant=minbase bullseye "$root"
|
binutils
|
||||||
|
busybox
|
||||||
|
elfutils
|
||||||
|
ethtool
|
||||||
|
iproute2
|
||||||
|
iptables
|
||||||
|
libcap2
|
||||||
|
libelf1
|
||||||
|
strace
|
||||||
|
zlib1g
|
||||||
|
)
|
||||||
|
packages=$(IFS=, && echo "${packages[*]}")
|
||||||
|
debootstrap --include="$packages" --variant=minbase "$@" bookworm "$root"
|
||||||
|
|
||||||
# Remove the init scripts (tests use their own). Also remove various
|
# Remove the init scripts (tests use their own). Also remove various
|
||||||
# unnecessary files in order to save space.
|
# unnecessary files in order to save space.
|
||||||
@@ -26,11 +43,6 @@ rm -rf \
|
|||||||
"$root"/var/cache/apt/archives/* \
|
"$root"/var/cache/apt/archives/* \
|
||||||
"$root"/var/lib/apt/lists/*
|
"$root"/var/lib/apt/lists/*
|
||||||
|
|
||||||
# Save some more space by removing coreutils - the tests use busybox. Before
|
|
||||||
# doing that, delete the buggy postrm script, which uses the rm command.
|
|
||||||
rm -f "$root/var/lib/dpkg/info/coreutils.postrm"
|
|
||||||
chroot "$root" dpkg --remove --force-remove-essential coreutils
|
|
||||||
|
|
||||||
# Apply common tweaks.
|
# Apply common tweaks.
|
||||||
"$(dirname "$0")"/mkrootfs_tweak.sh "$root"
|
"$(dirname "$0")"/mkrootfs_tweak.sh "$root"
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
# IBM Z self-hosted builder
|
# IBM Z self-hosted builder
|
||||||
|
|
||||||
libbpf CI uses an IBM-provided z15 self-hosted builder. There are no IBM Z
|
libbpf CI uses an IBM-provided z15 self-hosted builder. There are no IBM Z
|
||||||
builds of GitHub Actions runner, and stable qemu-user has problems with .NET
|
builds of GitHub (GH) Actions runner, and stable qemu-user has problems with .NET
|
||||||
apps, so the builder runs the x86_64 runner version with qemu-user built from
|
apps, so the builder runs the x86_64 runner version with qemu-user built from
|
||||||
the master branch.
|
the master branch.
|
||||||
|
|
||||||
|
We are currently supporting runners for the following repositories:
|
||||||
|
* libbpf/libbpf
|
||||||
|
* kernel-patches/bpf
|
||||||
|
* kernel-patches/vmtest
|
||||||
|
|
||||||
|
Below instructions are directly applicable to libbpf, and require minor
|
||||||
|
modifications for kernel-patches repos. Currently, qemu-user-static Docker
|
||||||
|
image is shared between all GitHub runners, but separate actions-runner-\*
|
||||||
|
service / Docker image is created for each runner type.
|
||||||
|
|
||||||
## Configuring the builder.
|
## Configuring the builder.
|
||||||
|
|
||||||
### Install prerequisites.
|
### Install prerequisites.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo dnf install docker # RHEL
|
|
||||||
$ sudo apt install -y docker.io # Ubuntu
|
$ sudo apt install -y docker.io # Ubuntu
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -35,6 +44,10 @@ for details.
|
|||||||
|
|
||||||
### Autostart the x86_64 emulation support.
|
### Autostart the x86_64 emulation support.
|
||||||
|
|
||||||
|
This step is important, you would not be able to build docker container
|
||||||
|
without having this service running. If container build fails, make sure
|
||||||
|
service is running properly.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo systemctl enable --now qemu-user-static
|
$ sudo systemctl enable --now qemu-user-static
|
||||||
```
|
```
|
||||||
@@ -72,3 +85,23 @@ $ sudo systemctl stop actions-runner-libbpf
|
|||||||
$ sudo docker rm -f actions-runner-libbpf
|
$ sudo docker rm -f actions-runner-libbpf
|
||||||
$ sudo docker volume rm actions-runner-libbpf
|
$ sudo docker volume rm actions-runner-libbpf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
In order to check if service is running, use the following command:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo systemctl status <service name>
|
||||||
|
```
|
||||||
|
|
||||||
|
In order to get logs for service:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ journalctl -u <service name>
|
||||||
|
```
|
||||||
|
|
||||||
|
In order to check which containers are currently active:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sudo docker ps
|
||||||
|
```
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ get_stack_raw_tp # spams with kernel warnings until next bpf -> bpf-next merg
|
|||||||
stacktrace_build_id_nmi
|
stacktrace_build_id_nmi
|
||||||
stacktrace_build_id
|
stacktrace_build_id
|
||||||
task_fd_query_rawtp
|
task_fd_query_rawtp
|
||||||
|
varlen
|
||||||
|
|||||||
@@ -25,11 +25,14 @@ ksyms_module_libbpf # JIT does not support calling kernel f
|
|||||||
ksyms_module_lskel # test_ksyms_module_lskel__open_and_load unexpected error: -9 (?)
|
ksyms_module_lskel # test_ksyms_module_lskel__open_and_load unexpected error: -9 (?)
|
||||||
modify_return # modify_return attach failed: -524 (trampoline)
|
modify_return # modify_return attach failed: -524 (trampoline)
|
||||||
module_attach # skel_attach skeleton attach failed: -524 (trampoline)
|
module_attach # skel_attach skeleton attach failed: -524 (trampoline)
|
||||||
|
mptcp
|
||||||
|
kprobe_multi_test # relies on fentry
|
||||||
netcnt # failed to load BPF skeleton 'netcnt_prog': -7 (?)
|
netcnt # failed to load BPF skeleton 'netcnt_prog': -7 (?)
|
||||||
probe_user # check_kprobe_res wrong kprobe res from probe read (?)
|
probe_user # check_kprobe_res wrong kprobe res from probe read (?)
|
||||||
recursion # skel_attach unexpected error: -524 (trampoline)
|
recursion # skel_attach unexpected error: -524 (trampoline)
|
||||||
ringbuf # skel_load skeleton load failed (?)
|
ringbuf # skel_load skeleton load failed (?)
|
||||||
sk_assign # Can't read on server: Invalid argument (?)
|
sk_assign # Can't read on server: Invalid argument (?)
|
||||||
|
sk_lookup # endianness problem
|
||||||
sk_storage_tracing # test_sk_storage_tracing__attach unexpected error: -524 (trampoline)
|
sk_storage_tracing # test_sk_storage_tracing__attach unexpected error: -524 (trampoline)
|
||||||
skc_to_unix_sock # could not attach BPF object unexpected error: -524 (trampoline)
|
skc_to_unix_sock # could not attach BPF object unexpected error: -524 (trampoline)
|
||||||
socket_cookie # prog_attach unexpected error: -524 (trampoline)
|
socket_cookie # prog_attach unexpected error: -524 (trampoline)
|
||||||
@@ -44,6 +47,7 @@ test_lsm # failed to find kernel BTF type ID of
|
|||||||
test_overhead # attach_fentry unexpected error: -524 (trampoline)
|
test_overhead # attach_fentry unexpected error: -524 (trampoline)
|
||||||
test_profiler # unknown func bpf_probe_read_str#45 (overlapping)
|
test_profiler # unknown func bpf_probe_read_str#45 (overlapping)
|
||||||
timer # failed to auto-attach program 'test1': -524 (trampoline)
|
timer # failed to auto-attach program 'test1': -524 (trampoline)
|
||||||
|
timer_crash # trampoline
|
||||||
timer_mim # failed to auto-attach program 'test1': -524 (trampoline)
|
timer_mim # failed to auto-attach program 'test1': -524 (trampoline)
|
||||||
trace_ext # failed to auto-attach program 'test_pkt_md_access_new': -524 (trampoline)
|
trace_ext # failed to auto-attach program 'test_pkt_md_access_new': -524 (trampoline)
|
||||||
trace_printk # trace_printk__load unexpected error: -2 (errno 2) (?)
|
trace_printk # trace_printk__load unexpected error: -2 (errno 2) (?)
|
||||||
@@ -54,3 +58,10 @@ vmlinux # failed to auto-attach program 'handle
|
|||||||
xdp_adjust_tail # case-128 err 0 errno 28 retval 1 size 128 expect-size 3520 (?)
|
xdp_adjust_tail # case-128 err 0 errno 28 retval 1 size 128 expect-size 3520 (?)
|
||||||
xdp_bonding # failed to auto-attach program 'trace_on_entry': -524 (trampoline)
|
xdp_bonding # failed to auto-attach program 'trace_on_entry': -524 (trampoline)
|
||||||
xdp_bpf2bpf # failed to auto-attach program 'trace_on_entry': -524 (trampoline)
|
xdp_bpf2bpf # failed to auto-attach program 'trace_on_entry': -524 (trampoline)
|
||||||
|
map_kptr # failed to open_and_load program: -524 (trampoline)
|
||||||
|
bpf_cookie # failed to open_and_load program: -524 (trampoline)
|
||||||
|
xdp_do_redirect # prog_run_max_size unexpected error: -22 (errno 22)
|
||||||
|
send_signal # intermittently fails to receive signal
|
||||||
|
select_reuseport # intermittently fails on new s390x setup
|
||||||
|
xdp_synproxy # JIT does not support calling kernel function (kfunc)
|
||||||
|
unpriv_bpf_disabled # fentry
|
||||||
|
|||||||
@@ -493,7 +493,7 @@ CONFIG_MODULE_UNLOAD=y
|
|||||||
# CONFIG_MODULE_FORCE_UNLOAD is not set
|
# CONFIG_MODULE_FORCE_UNLOAD is not set
|
||||||
# CONFIG_MODVERSIONS is not set
|
# CONFIG_MODVERSIONS is not set
|
||||||
# CONFIG_MODULE_SRCVERSION_ALL is not set
|
# CONFIG_MODULE_SRCVERSION_ALL is not set
|
||||||
# CONFIG_MODULE_SIG is not set
|
CONFIG_MODULE_SIG=y
|
||||||
CONFIG_MODULE_COMPRESS_NONE=y
|
CONFIG_MODULE_COMPRESS_NONE=y
|
||||||
# CONFIG_MODULE_COMPRESS_GZIP is not set
|
# CONFIG_MODULE_COMPRESS_GZIP is not set
|
||||||
# CONFIG_MODULE_COMPRESS_XZ is not set
|
# CONFIG_MODULE_COMPRESS_XZ is not set
|
||||||
@@ -764,7 +764,8 @@ CONFIG_IPV6_SEG6_BPF=y
|
|||||||
# CONFIG_IPV6_RPL_LWTUNNEL is not set
|
# CONFIG_IPV6_RPL_LWTUNNEL is not set
|
||||||
# CONFIG_IPV6_IOAM6_LWTUNNEL is not set
|
# CONFIG_IPV6_IOAM6_LWTUNNEL is not set
|
||||||
# CONFIG_NETLABEL is not set
|
# CONFIG_NETLABEL is not set
|
||||||
# CONFIG_MPTCP is not set
|
CONFIG_MPTCP=y
|
||||||
|
CONFIG_MPTCP_IPV6=y
|
||||||
# CONFIG_NETWORK_SECMARK is not set
|
# CONFIG_NETWORK_SECMARK is not set
|
||||||
# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
|
# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
|
||||||
CONFIG_NETFILTER=y
|
CONFIG_NETFILTER=y
|
||||||
@@ -784,6 +785,7 @@ CONFIG_NETFILTER_NETLINK=y
|
|||||||
# CONFIG_NETFILTER_NETLINK_OSF is not set
|
# CONFIG_NETFILTER_NETLINK_OSF is not set
|
||||||
CONFIG_NF_CONNTRACK=y
|
CONFIG_NF_CONNTRACK=y
|
||||||
# CONFIG_NF_LOG_SYSLOG is not set
|
# CONFIG_NF_LOG_SYSLOG is not set
|
||||||
|
CONFIG_NETFILTER_SYNPROXY=y
|
||||||
CONFIG_NF_TABLES=y
|
CONFIG_NF_TABLES=y
|
||||||
# CONFIG_NF_TABLES_INET is not set
|
# CONFIG_NF_TABLES_INET is not set
|
||||||
# CONFIG_NF_TABLES_NETDEV is not set
|
# CONFIG_NF_TABLES_NETDEV is not set
|
||||||
@@ -814,6 +816,7 @@ CONFIG_NETFILTER_XT_MARK=y
|
|||||||
#
|
#
|
||||||
# CONFIG_NETFILTER_XT_TARGET_AUDIT is not set
|
# CONFIG_NETFILTER_XT_TARGET_AUDIT is not set
|
||||||
# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
|
# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
|
||||||
|
CONFIG_NETFILTER_XT_TARGET_CT=y
|
||||||
# CONFIG_NETFILTER_XT_TARGET_HMARK is not set
|
# CONFIG_NETFILTER_XT_TARGET_HMARK is not set
|
||||||
# CONFIG_NETFILTER_XT_TARGET_IDLETIMER is not set
|
# CONFIG_NETFILTER_XT_TARGET_IDLETIMER is not set
|
||||||
# CONFIG_NETFILTER_XT_TARGET_LOG is not set
|
# CONFIG_NETFILTER_XT_TARGET_LOG is not set
|
||||||
@@ -858,6 +861,7 @@ CONFIG_NETFILTER_XT_MATCH_BPF=y
|
|||||||
# CONFIG_NETFILTER_XT_MATCH_RECENT is not set
|
# CONFIG_NETFILTER_XT_MATCH_RECENT is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
|
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_SOCKET is not set
|
# CONFIG_NETFILTER_XT_MATCH_SOCKET is not set
|
||||||
|
CONFIG_NETFILTER_XT_MATCH_STATE=y
|
||||||
# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
|
# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_STRING is not set
|
# CONFIG_NETFILTER_XT_MATCH_STRING is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
|
# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
|
||||||
@@ -885,9 +889,10 @@ CONFIG_IP_NF_IPTABLES=y
|
|||||||
# CONFIG_IP_NF_MATCH_ECN is not set
|
# CONFIG_IP_NF_MATCH_ECN is not set
|
||||||
# CONFIG_IP_NF_MATCH_TTL is not set
|
# CONFIG_IP_NF_MATCH_TTL is not set
|
||||||
CONFIG_IP_NF_FILTER=y
|
CONFIG_IP_NF_FILTER=y
|
||||||
|
CONFIG_IP_NF_TARGET_SYNPROXY=y
|
||||||
# CONFIG_IP_NF_TARGET_REJECT is not set
|
# CONFIG_IP_NF_TARGET_REJECT is not set
|
||||||
# CONFIG_IP_NF_MANGLE is not set
|
# CONFIG_IP_NF_MANGLE is not set
|
||||||
# CONFIG_IP_NF_RAW is not set
|
CONFIG_IP_NF_RAW=y
|
||||||
# CONFIG_IP_NF_SECURITY is not set
|
# CONFIG_IP_NF_SECURITY is not set
|
||||||
# CONFIG_IP_NF_ARPTABLES is not set
|
# CONFIG_IP_NF_ARPTABLES is not set
|
||||||
# end of IP: Netfilter Configuration
|
# end of IP: Netfilter Configuration
|
||||||
@@ -2586,6 +2591,7 @@ CONFIG_FUNCTION_TRACER=y
|
|||||||
CONFIG_FUNCTION_GRAPH_TRACER=y
|
CONFIG_FUNCTION_GRAPH_TRACER=y
|
||||||
CONFIG_DYNAMIC_FTRACE=y
|
CONFIG_DYNAMIC_FTRACE=y
|
||||||
CONFIG_DYNAMIC_FTRACE_WITH_REGS=y
|
CONFIG_DYNAMIC_FTRACE_WITH_REGS=y
|
||||||
|
CONFIG_FPROBE=y
|
||||||
CONFIG_FUNCTION_PROFILER=y
|
CONFIG_FUNCTION_PROFILER=y
|
||||||
CONFIG_STACK_TRACER=y
|
CONFIG_STACK_TRACER=y
|
||||||
# CONFIG_IRQSOFF_TRACER is not set
|
# CONFIG_IRQSOFF_TRACER is not set
|
||||||
|
|||||||
@@ -721,7 +721,7 @@ CONFIG_MODULE_UNLOAD=y
|
|||||||
CONFIG_MODVERSIONS=y
|
CONFIG_MODVERSIONS=y
|
||||||
CONFIG_ASM_MODVERSIONS=y
|
CONFIG_ASM_MODVERSIONS=y
|
||||||
CONFIG_MODULE_SRCVERSION_ALL=y
|
CONFIG_MODULE_SRCVERSION_ALL=y
|
||||||
# CONFIG_MODULE_SIG is not set
|
CONFIG_MODULE_SIG=y
|
||||||
# CONFIG_MODULE_COMPRESS is not set
|
# CONFIG_MODULE_COMPRESS is not set
|
||||||
# CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is not set
|
# CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is not set
|
||||||
# CONFIG_UNUSED_SYMBOLS is not set
|
# CONFIG_UNUSED_SYMBOLS is not set
|
||||||
@@ -961,7 +961,8 @@ CONFIG_IPV6_SEG6_LWTUNNEL=y
|
|||||||
CONFIG_IPV6_SEG6_BPF=y
|
CONFIG_IPV6_SEG6_BPF=y
|
||||||
# CONFIG_IPV6_RPL_LWTUNNEL is not set
|
# CONFIG_IPV6_RPL_LWTUNNEL is not set
|
||||||
CONFIG_NETLABEL=y
|
CONFIG_NETLABEL=y
|
||||||
# CONFIG_MPTCP is not set
|
CONFIG_MPTCP=y
|
||||||
|
CONFIG_MPTCP_IPV6=y
|
||||||
CONFIG_NETWORK_SECMARK=y
|
CONFIG_NETWORK_SECMARK=y
|
||||||
CONFIG_NET_PTP_CLASSIFY=y
|
CONFIG_NET_PTP_CLASSIFY=y
|
||||||
# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
|
# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
|
||||||
@@ -979,6 +980,7 @@ CONFIG_NETFILTER_NETLINK_LOG=y
|
|||||||
# CONFIG_NETFILTER_NETLINK_OSF is not set
|
# CONFIG_NETFILTER_NETLINK_OSF is not set
|
||||||
CONFIG_NF_CONNTRACK=y
|
CONFIG_NF_CONNTRACK=y
|
||||||
# CONFIG_NF_LOG_NETDEV is not set
|
# CONFIG_NF_LOG_NETDEV is not set
|
||||||
|
CONFIG_NETFILTER_SYNPROXY=y
|
||||||
# CONFIG_NF_TABLES is not set
|
# CONFIG_NF_TABLES is not set
|
||||||
CONFIG_NETFILTER_XTABLES=y
|
CONFIG_NETFILTER_XTABLES=y
|
||||||
|
|
||||||
@@ -992,6 +994,7 @@ CONFIG_NETFILTER_XTABLES=y
|
|||||||
#
|
#
|
||||||
# CONFIG_NETFILTER_XT_TARGET_AUDIT is not set
|
# CONFIG_NETFILTER_XT_TARGET_AUDIT is not set
|
||||||
# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
|
# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
|
||||||
|
CONFIG_NETFILTER_XT_TARGET_CT=y
|
||||||
# CONFIG_NETFILTER_XT_TARGET_HMARK is not set
|
# CONFIG_NETFILTER_XT_TARGET_HMARK is not set
|
||||||
# CONFIG_NETFILTER_XT_TARGET_IDLETIMER is not set
|
# CONFIG_NETFILTER_XT_TARGET_IDLETIMER is not set
|
||||||
# CONFIG_NETFILTER_XT_TARGET_LOG is not set
|
# CONFIG_NETFILTER_XT_TARGET_LOG is not set
|
||||||
@@ -1037,6 +1040,7 @@ CONFIG_NETFILTER_XT_MATCH_BPF=y
|
|||||||
# CONFIG_NETFILTER_XT_MATCH_RECENT is not set
|
# CONFIG_NETFILTER_XT_MATCH_RECENT is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
|
# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_SOCKET is not set
|
# CONFIG_NETFILTER_XT_MATCH_SOCKET is not set
|
||||||
|
CONFIG_NETFILTER_XT_MATCH_STATE=y
|
||||||
CONFIG_NETFILTER_XT_MATCH_STATISTIC=y
|
CONFIG_NETFILTER_XT_MATCH_STATISTIC=y
|
||||||
# CONFIG_NETFILTER_XT_MATCH_STRING is not set
|
# CONFIG_NETFILTER_XT_MATCH_STRING is not set
|
||||||
# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
|
# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
|
||||||
@@ -1061,9 +1065,10 @@ CONFIG_IP_NF_IPTABLES=y
|
|||||||
# CONFIG_IP_NF_MATCH_AH is not set
|
# CONFIG_IP_NF_MATCH_AH is not set
|
||||||
# CONFIG_IP_NF_MATCH_ECN is not set
|
# CONFIG_IP_NF_MATCH_ECN is not set
|
||||||
# CONFIG_IP_NF_MATCH_TTL is not set
|
# CONFIG_IP_NF_MATCH_TTL is not set
|
||||||
# CONFIG_IP_NF_FILTER is not set
|
CONFIG_IP_NF_FILTER=y
|
||||||
|
CONFIG_IP_NF_TARGET_SYNPROXY=y
|
||||||
# CONFIG_IP_NF_MANGLE is not set
|
# CONFIG_IP_NF_MANGLE is not set
|
||||||
# CONFIG_IP_NF_RAW is not set
|
CONFIG_IP_NF_RAW=y
|
||||||
# CONFIG_IP_NF_SECURITY is not set
|
# CONFIG_IP_NF_SECURITY is not set
|
||||||
# CONFIG_IP_NF_ARPTABLES is not set
|
# CONFIG_IP_NF_ARPTABLES is not set
|
||||||
# end of IP: Netfilter Configuration
|
# end of IP: Netfilter Configuration
|
||||||
@@ -1211,7 +1216,7 @@ CONFIG_MPLS=y
|
|||||||
# CONFIG_NET_NSH is not set
|
# CONFIG_NET_NSH is not set
|
||||||
# CONFIG_HSR is not set
|
# CONFIG_HSR is not set
|
||||||
# CONFIG_NET_SWITCHDEV is not set
|
# CONFIG_NET_SWITCHDEV is not set
|
||||||
# CONFIG_NET_L3_MASTER_DEV is not set
|
CONFIG_NET_L3_MASTER_DEV=y
|
||||||
# CONFIG_QRTR is not set
|
# CONFIG_QRTR is not set
|
||||||
# CONFIG_NET_NCSI is not set
|
# CONFIG_NET_NCSI is not set
|
||||||
CONFIG_RPS=y
|
CONFIG_RPS=y
|
||||||
@@ -1509,6 +1514,7 @@ CONFIG_TUN=y
|
|||||||
CONFIG_VETH=y
|
CONFIG_VETH=y
|
||||||
CONFIG_VIRTIO_NET=y
|
CONFIG_VIRTIO_NET=y
|
||||||
# CONFIG_NLMON is not set
|
# CONFIG_NLMON is not set
|
||||||
|
CONFIG_NET_VRF=y
|
||||||
# CONFIG_ARCNET is not set
|
# CONFIG_ARCNET is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -2793,6 +2799,7 @@ CONFIG_DEBUG_INFO=y
|
|||||||
# CONFIG_DEBUG_INFO_COMPRESSED is not set
|
# CONFIG_DEBUG_INFO_COMPRESSED is not set
|
||||||
# CONFIG_DEBUG_INFO_SPLIT is not set
|
# CONFIG_DEBUG_INFO_SPLIT is not set
|
||||||
# CONFIG_DEBUG_INFO_DWARF4 is not set
|
# CONFIG_DEBUG_INFO_DWARF4 is not set
|
||||||
|
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
|
||||||
CONFIG_DEBUG_INFO_BTF=y
|
CONFIG_DEBUG_INFO_BTF=y
|
||||||
# CONFIG_GDB_SCRIPTS is not set
|
# CONFIG_GDB_SCRIPTS is not set
|
||||||
CONFIG_ENABLE_MUST_CHECK=y
|
CONFIG_ENABLE_MUST_CHECK=y
|
||||||
@@ -2976,6 +2983,7 @@ CONFIG_FUNCTION_GRAPH_TRACER=y
|
|||||||
CONFIG_DYNAMIC_FTRACE=y
|
CONFIG_DYNAMIC_FTRACE=y
|
||||||
CONFIG_DYNAMIC_FTRACE_WITH_REGS=y
|
CONFIG_DYNAMIC_FTRACE_WITH_REGS=y
|
||||||
CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS=y
|
CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS=y
|
||||||
|
CONFIG_FPROBE=y
|
||||||
# CONFIG_FUNCTION_PROFILER is not set
|
# CONFIG_FUNCTION_PROFILER is not set
|
||||||
# CONFIG_STACK_TRACER is not set
|
# CONFIG_STACK_TRACER is not set
|
||||||
# CONFIG_IRQSOFF_TRACER is not set
|
# CONFIG_IRQSOFF_TRACER is not set
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
attach_probe
|
# attach_probe
|
||||||
autoload
|
autoload
|
||||||
bpf_verif_scale
|
bpf_verif_scale
|
||||||
cgroup_attach_autodetach
|
cgroup_attach_autodetach
|
||||||
@@ -10,7 +10,6 @@ core_reloc
|
|||||||
core_retro
|
core_retro
|
||||||
cpu_mask
|
cpu_mask
|
||||||
endian
|
endian
|
||||||
fexit_stress
|
|
||||||
get_branch_snapshot
|
get_branch_snapshot
|
||||||
get_stackid_cannot_attach
|
get_stackid_cannot_attach
|
||||||
global_data
|
global_data
|
||||||
@@ -43,13 +42,13 @@ spinlock
|
|||||||
stacktrace_map
|
stacktrace_map
|
||||||
stacktrace_map_raw_tp
|
stacktrace_map_raw_tp
|
||||||
static_linked
|
static_linked
|
||||||
subprogs
|
|
||||||
task_fd_query_rawtp
|
task_fd_query_rawtp
|
||||||
task_fd_query_tp
|
task_fd_query_tp
|
||||||
tc_bpf
|
tc_bpf
|
||||||
tcp_estats
|
tcp_estats
|
||||||
tcp_rtt
|
tcp_rtt
|
||||||
tp_attach_query
|
tp_attach_query
|
||||||
|
usdt/urand_pid_attach
|
||||||
xdp
|
xdp
|
||||||
xdp_info
|
xdp_info
|
||||||
xdp_noinline
|
xdp_noinline
|
||||||
|
|||||||
Reference in New Issue
Block a user