From 92d75e5e96bbe6e83db051fe06c430035d44248f Mon Sep 17 00:00:00 2001 From: Jeffrey <106184818+c0d33ngr@users.noreply.github.com> Date: Wed, 15 Jan 2025 08:32:55 +0100 Subject: [PATCH 01/34] ci: Update build.yaml to include Ubuntu 24.04 Signed-off-by: Jeffrey Signed-off-by: c0d33ngr --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9059365f..d09a4d9a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, ubuntu-22.04] + os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04] runs-on: ${{ matrix.os }} env: FEATURES: .llvm and .skeletons From 3dba43d8f77bb591c69c583dc36caa9eaed139c1 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 25 Feb 2025 10:07:55 +0000 Subject: [PATCH 02/34] ci: Remove deprecated Ubuntu 20.04 from runners The Ubuntu 20.04-based runners have been deprecated by GitHub at the beginning of this month, and are expected to go fully unsupported by 2025-04-01. Let's remove it from the workflow file. Link: https://github.com/actions/runner-images/issues/11101 Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- .github/workflows/build.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d09a4d9a..534f0c4a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04] + os: [ubuntu-22.04, ubuntu-24.04] runs-on: ${{ matrix.os }} env: FEATURES: .llvm and .skeletons @@ -32,12 +32,6 @@ jobs: with: submodules: true - - name: Use clang-12 and not clang-11 for older Ubuntu - if: matrix.os == 'ubuntu-20.04' - run: | - sudo apt-get remove -y clang-11 llvm-11 - sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 50 - - name: Install dependencies run: | sudo apt-get update From 1242a16fe5869f2dbc3cebc337a007b6c7b82fb0 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 25 Feb 2025 10:53:42 +0000 Subject: [PATCH 03/34] mirror: Add probe for libelf-zstd feature Add the probe to test whether we need to link against the zstd library to use libelf in bpftool. This should ideally have been merged before commit 67f1758bd788 ("bpftool: Link zstd lib required by libelf"), where we have the Makefile use the actual feature, but I forgot to add the probe when synchronising the repository. Elfutils commit a5b07cdf9c49 adds support for ZSTD compression, first shipped with elfutils 0.189. Distros now have it; for example, Ubuntu 22.04 ships version 0.186 (or 0.188 in backports), but Ubuntu 24.04 has 0.189 or 0.190 depending on the arch. Link: https://sourceware.org/git/?p=elfutils.git;a=commit;h=a5b07cdf9c491fb7a4a16598c482c68b718f59b9 Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- src/Makefile.feature | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/Makefile.feature b/src/Makefile.feature index b08e7b90..d16e8a46 100644 --- a/src/Makefile.feature +++ b/src/Makefile.feature @@ -34,9 +34,41 @@ feature-clang-bpf-co-re := \ $(findstring 1,$(call detect,$(CLANG_BPF_CO_RE_PROBE_CMD))) endif # clang-bpf-co-re +### feature-libelf-zstd + +# Define these unconditionally so we can also use the probe for feature-libbfd +LIBELF_ZSTD_PROBE := '$(pound)include \n' +LIBELF_ZSTD_PROBE += 'int main(void) {' +LIBELF_ZSTD_PROBE += ' elf_compress(0, ELFCOMPRESS_ZSTD, 0);' +LIBELF_ZSTD_PROBE += ' return 0;' +LIBELF_ZSTD_PROBE += '}' + +LIBELF_ZSTD_PROBE_CMD = printf '%b\n' $(LIBELF_ZSTD_PROBE) | \ + $(CC) $(CFLAGS) -Wall -Werror -x c - -lelf -lz -lzstd -o - >/dev/null + +define libelf_zstd_build + $(call detect,$(LIBELF_ZSTD_PROBE_CMD)) +endef + +ifneq ($(findstring libelf-zstd,$(FEATURE_TESTS)),) +$(call LOG,Probing: feature-libelf-zstd) +feature-libelf-zstd := $(findstring 1, $(call libelf_zstd_build)) +endif # libelf-zstd + ### feature-libbfd ifneq ($(findstring libbfd,$(FEATURE_TESTS)),) + +# Check whether feature-libbfd probe needs libzstd +ifneq ($(findstring libelf-zstd,$(FEATURE_TESTS)),) + need_libzstd := $(feature-libelf-zstd) +else + need_libzstd := $(findstring 1, $(call libelf_zstd_build)) +endif +ifeq ($(need_libzstd),1) + LIBZSTD_FLAG := -lzstd +endif + LIBBFD_PROBE := '$(pound)include \n' LIBBFD_PROBE += 'int main(void) {' LIBBFD_PROBE += ' bfd_demangle(0, 0, 0);' @@ -51,15 +83,15 @@ endef $(call LOG,Probing: feature-libbfd) feature-libbfd := \ - $(findstring 1,$(call libbfd_build,-lbfd -ldl)) + $(findstring 1,$(call libbfd_build,-lbfd $(LIBZSTD_FLAG) -ldl)) ifneq ($(feature-libbfd),1) $(call LOG,Probing: feature-libbfd-liberty) feature-libbfd-liberty := \ - $(findstring 1,$(call libbfd_build,-lbfd -ldl -liberty)) + $(findstring 1,$(call libbfd_build,-lbfd $(LIBZSTD_FLAG) -ldl -liberty)) ifneq ($(feature-libbfd-liberty),1) $(call LOG,Probing: feature-libbfd-liberty-z) feature-libbfd-liberty-z := \ - $(findstring 1,$(call libbfd_build,-lbfd -ldl -liberty -lz)) + $(findstring 1,$(call libbfd_build,-lbfd $(LIBZSTD_FLAG) -ldl -liberty -lz)) endif endif HAS_LIBBFD := $(findstring 1, \ From 1e210bddf1aa6b7eb1cb4215ea60ef7f81ea1a21 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 25 Feb 2025 11:37:49 +0000 Subject: [PATCH 04/34] mirror: test Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- .github/workflows/build.yaml | 2 ++ src/Makefile | 3 +++ src/Makefile.feature | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 534f0c4a..ca899ca7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,6 +37,8 @@ jobs: sudo apt-get update sudo apt-get install -y \ libbfd-dev libcap-dev libelf-dev libiberty-dev python3-docutils + # Install libsframe1 on Ubuntu 24.04+ + sudo apt install -y libsframe1 || true # clang/LLVM are already installed, but we're missing some aliases. CLANG_VERSION="$(echo '__clang_major__' | clang -E - | tail -n 1)" sudo update-alternatives \ diff --git a/src/Makefile b/src/Makefile index 9305a863..4691840e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -180,6 +180,9 @@ else ifeq ($(feature-disassembler-init-styled), 1) CFLAGS += -DDISASM_INIT_STYLED endif + ifeq ($(feature-libelf-zstd),1) + LIBS += -lsframe + endif endif endif ifeq ($(filter -DHAVE_LLVM_SUPPORT -DHAVE_LIBBFD_SUPPORT,$(CFLAGS)),) diff --git a/src/Makefile.feature b/src/Makefile.feature index d16e8a46..ae7574a8 100644 --- a/src/Makefile.feature +++ b/src/Makefile.feature @@ -66,7 +66,7 @@ else need_libzstd := $(findstring 1, $(call libelf_zstd_build)) endif ifeq ($(need_libzstd),1) - LIBZSTD_FLAG := -lzstd + LIBZSTD_FLAG := -lzstd -lsframe endif LIBBFD_PROBE := '$(pound)include \n' From 7adc69e3709e37af06f12f673a62ea6c30e4cd97 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 25 Feb 2025 17:14:28 +0000 Subject: [PATCH 05/34] ci: Bump Ubuntu image on runners Use Ubuntu 24.04 instead of 22.04 (when we use a single version, not for the build test Matrix where we want to test both), except for the job where we package the release (where we're not really tied to a specific version and can just go with ubuntu-latest). Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- .github/workflows/release.yaml | 6 +++--- .github/workflows/static-build.yaml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 69c00a49..5625e49f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,7 +18,7 @@ env: jobs: build: name: Build static bpftool binary - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: TARGETARCH: ${{ matrix.arch }} FILE_STRING_ARCH_amd64: x86-64 @@ -33,7 +33,7 @@ jobs: if: matrix.arch == 'amd64' run: | sudo apt-get update - sudo apt-get install -y libelf-dev libcap-dev + sudo apt-get install -y libelf-dev libcap-dev libsframe1 - name: Download and extract compiled LLVM release env: @@ -111,7 +111,7 @@ jobs: draft-release: name: Create a draft release - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest needs: build permissions: contents: write diff --git a/.github/workflows/static-build.yaml b/.github/workflows/static-build.yaml index 79411ce9..8b1baf58 100644 --- a/.github/workflows/static-build.yaml +++ b/.github/workflows/static-build.yaml @@ -17,7 +17,7 @@ concurrency: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: LLVM_URL_PREFIX: https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0 LLVM_PATH: clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4 @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y libelf-dev + sudo apt-get install -y libelf-dev libsframe1 - name: Download and extract compiled LLVM release run: | From 88edcb08dc9c4aa7196687468292fbc9ab106012 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Thu, 3 Apr 2025 10:35:40 +0100 Subject: [PATCH 06/34] mirror: Redefine Makefile's quiet $(Q) in Makefile.include for V=1 A follow-up commit will remove the assignation to $(Q) in bpftool's main Makefile, to reflect changes in the kernel repository where the definition of that variable has been moved to tools/scripts/Makefile.include, from where it is shared by various utilities. To preserve the verbose behaviour during the build, when users pass V=1 to the make invocation, we need a definition for the $(Q) "quiet" variable in our own Makefile.include. Let's add it. See Linux commit 293f324ce96d ("tools: Unify top-level quiet infrastructure") Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- src/Makefile.include | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Makefile.include b/src/Makefile.include index cbec8356..60afe887 100644 --- a/src/Makefile.include +++ b/src/Makefile.include @@ -43,6 +43,12 @@ EXTRA_WARNINGS := \ -Wundef \ -Wwrite-strings \ +ifeq ($(V),1) + Q = +else + Q = @ +endif + define descend mkdir -p $(OUTPUT)$(1) && \ $(MAKE) --no-print-directory -C $(1) $(2) From 1289117e6dbfd50be4d1764b2afe942e4a781b0f Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Thu, 3 Apr 2025 09:57:34 +0100 Subject: [PATCH 07/34] sync: Update libbpf submodule Pull latest libbpf from mirror. Libbpf version: 1.6.0 Libbpf commit: 4659eaafa4809150c9d1794455224af37252f6dd Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- libbpf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbpf b/libbpf index 42a6ef63..4659eaaf 160000 --- a/libbpf +++ b/libbpf @@ -1 +1 @@ -Subproject commit 42a6ef63161a8dc4288172b27f3870e50b3606f7 +Subproject commit 4659eaafa4809150c9d1794455224af37252f6dd From d230ded48ab7b759ce210f70883b0b532f540785 Mon Sep 17 00:00:00 2001 From: Charlie Jenkins Date: Thu, 13 Feb 2025 13:06:22 -0800 Subject: [PATCH 08/34] tools: Remove redundant quiet setup Q is exported from Makefile.include so it is not necessary to manually set it. Reviewed-by: Jiri Olsa Signed-off-by: Charlie Jenkins Acked-by: Andrii Nakryiko Acked-by: Quentin Monnet Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexei Starovoitov Cc: Benjamin Tissoires Cc: Daniel Borkmann Cc: Daniel Lezcano Cc: Eduard Zingerman Cc: Hao Luo Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Kosina Cc: John Fastabend Cc: Josh Poimboeuf Cc: KP Singh Cc: Lukasz Luba Cc: Mark Rutland Cc: Martin KaFai Lau Cc: Mykola Lysenko Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Shuah Khan Cc: Song Liu Cc: Stanislav Fomichev Cc: Steven Rostedt (VMware) Cc: Yonghong Song Cc: Zhang Rui Link: https://lore.kernel.org/r/20250213-quiet_tools-v3-2-07de4482a581@rivosinc.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: c0d33ngr --- docs/Makefile | 6 ------ src/Makefile | 6 ------ 2 files changed, 12 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index f402c4a4..2ce271f4 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -5,12 +5,6 @@ INSTALL ?= install RM ?= rm -f RMDIR ?= rmdir --ignore-fail-on-non-empty -ifeq ($(V),1) - Q = -else - Q = @ -endif - prefix ?= /usr/local mandir ?= $(prefix)/man man8dir = $(mandir)/man8 diff --git a/src/Makefile b/src/Makefile index 4691840e..ba6c096f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,12 +5,6 @@ ifeq ($(srctree),) srctree := $(patsubst %/,%,$(dir $(CURDIR))) endif -ifeq ($(V),1) - Q = -else - Q = @ -endif - BPF_DIR = $(srctree)/libbpf/src ifneq ($(OUTPUT),) From a05c2b06ae1a604989d0deb9bf4b2021a33f7ade Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Wed, 5 Mar 2025 23:59:32 +0900 Subject: [PATCH 09/34] treewide: fix typo 'unsigned __init128' -> 'unsigned __int128' "int" was misspelled as "init" the code comments in the bits.h and const.h files. Fix the typo. CC: Andy Shevchenko Signed-off-by: Vincent Mailhol Signed-off-by: Yury Norov Signed-off-by: c0d33ngr --- include/uapi/linux/const.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h index e16be0d3..b8f629ef 100644 --- a/include/uapi/linux/const.h +++ b/include/uapi/linux/const.h @@ -33,7 +33,7 @@ * Missing asm support * * __BIT128() would not work in the asm code, as it shifts an - * 'unsigned __init128' data type as direct representation of + * 'unsigned __int128' data type as direct representation of * 128 bit constants is not supported in the gcc compiler, as * they get silently truncated. * From 07aa817cbd036b36bb7a2404f57dd380a24820f7 Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 20 Feb 2025 15:29:29 +0800 Subject: [PATCH 10/34] bpf: Add networking timestamping support to bpf_get/setsockopt() The new SK_BPF_CB_FLAGS and new SK_BPF_CB_TX_TIMESTAMPING are added to bpf_get/setsockopt. The later patches will implement the BPF networking timestamping. The BPF program will use bpf_setsockopt(SK_BPF_CB_FLAGS, SK_BPF_CB_TX_TIMESTAMPING) to enable the BPF networking timestamping on a socket. Signed-off-by: Jason Xing Signed-off-by: Martin KaFai Lau Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250220072940.99994-2-kerneljasonxing@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index fff6cdb8..8096b5e0 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -6916,6 +6916,12 @@ enum { BPF_SOCK_OPS_ALL_CB_FLAGS = 0x7F, }; +enum { + SK_BPF_CB_TX_TIMESTAMPING = 1<<0, + SK_BPF_CB_MASK = (SK_BPF_CB_TX_TIMESTAMPING - 1) | + SK_BPF_CB_TX_TIMESTAMPING +}; + /* List of known BPF sock_ops operators. * New entries can only be added at the end */ @@ -7094,6 +7100,7 @@ enum { TCP_BPF_SYN_IP = 1006, /* Copy the IP[46] and TCP header */ TCP_BPF_SYN_MAC = 1007, /* Copy the MAC, IP[46], and TCP header */ TCP_BPF_SOCK_OPS_CB_FLAGS = 1008, /* Get or Set TCP sock ops flags */ + SK_BPF_CB_FLAGS = 1009, /* Get or set sock ops flags in socket */ }; enum { From ac5f693c7e2abe41530c5a2c4b3005edf54555f7 Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 20 Feb 2025 15:29:34 +0800 Subject: [PATCH 11/34] bpf: Add BPF_SOCK_OPS_TSTAMP_SCHED_CB callback Support SCM_TSTAMP_SCHED case for bpf timestamping. Add a new sock_ops callback, BPF_SOCK_OPS_TSTAMP_SCHED_CB. This callback will occur at the same timestamping point as the user space's SCM_TSTAMP_SCHED. The BPF program can use it to get the same SCM_TSTAMP_SCHED timestamp without modifying the user-space application. A new SKBTX_BPF flag is added to mark skb_shinfo(skb)->tx_flags, ensuring that the new BPF timestamping and the current user space's SO_TIMESTAMPING do not interfere with each other. Signed-off-by: Jason Xing Signed-off-by: Martin KaFai Lau Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250220072940.99994-7-kerneljasonxing@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 8096b5e0..dd4c64c2 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7034,6 +7034,11 @@ enum { * by the kernel or the * earlier bpf-progs. */ + BPF_SOCK_OPS_TSTAMP_SCHED_CB, /* Called when skb is passing + * through dev layer when + * SK_BPF_CB_TX_TIMESTAMPING + * feature is on. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From ef4ed37f837f17c60f4022bddedb7c58d4c05c8c Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 20 Feb 2025 15:29:35 +0800 Subject: [PATCH 12/34] bpf: Add BPF_SOCK_OPS_TSTAMP_SND_SW_CB callback Support sw SCM_TSTAMP_SND case for bpf timestamping. Add a new sock_ops callback, BPF_SOCK_OPS_TSTAMP_SND_SW_CB. This callback will occur at the same timestamping point as the user space's software SCM_TSTAMP_SND. The BPF program can use it to get the same SCM_TSTAMP_SND timestamp without modifying the user-space application. Based on this patch, BPF program will get the software timestamp when the driver is ready to send the skb. In the sebsequent patch, the hardware timestamp will be supported. Signed-off-by: Jason Xing Signed-off-by: Martin KaFai Lau Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250220072940.99994-8-kerneljasonxing@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index dd4c64c2..d76e5c04 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7039,6 +7039,10 @@ enum { * SK_BPF_CB_TX_TIMESTAMPING * feature is on. */ + BPF_SOCK_OPS_TSTAMP_SND_SW_CB, /* Called when skb is about to send + * to the nic when SK_BPF_CB_TX_TIMESTAMPING + * feature is on. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From 60349e6a16f5cef984c9e683f59fd7c47d2a1148 Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 20 Feb 2025 15:29:36 +0800 Subject: [PATCH 13/34] bpf: Add BPF_SOCK_OPS_TSTAMP_SND_HW_CB callback Support hw SCM_TSTAMP_SND case for bpf timestamping. Add a new sock_ops callback, BPF_SOCK_OPS_TSTAMP_SND_HW_CB. This callback will occur at the same timestamping point as the user space's hardware SCM_TSTAMP_SND. The BPF program can use it to get the same SCM_TSTAMP_SND timestamp without modifying the user-space application. To avoid increasing the code complexity, replace SKBTX_HW_TSTAMP with SKBTX_HW_TSTAMP_NOBPF instead of changing numerous callers from driver side using SKBTX_HW_TSTAMP. The new definition of SKBTX_HW_TSTAMP means the combination tests of socket timestamping and bpf timestamping. After this patch, drivers can work under the bpf timestamping. Considering some drivers don't assign the skb with hardware timestamp, this patch does the assignment and then BPF program can acquire the hwstamp from skb directly. Signed-off-by: Jason Xing Signed-off-by: Martin KaFai Lau Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250220072940.99994-9-kerneljasonxing@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index d76e5c04..37f40511 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7043,6 +7043,10 @@ enum { * to the nic when SK_BPF_CB_TX_TIMESTAMPING * feature is on. */ + BPF_SOCK_OPS_TSTAMP_SND_HW_CB, /* Called in hardware phase when + * SK_BPF_CB_TX_TIMESTAMPING feature + * is on. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From 6fbc2d13fadadc14ac36d409c743388b6c603b47 Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 20 Feb 2025 15:29:37 +0800 Subject: [PATCH 14/34] bpf: Add BPF_SOCK_OPS_TSTAMP_ACK_CB callback Support the ACK case for bpf timestamping. Add a new sock_ops callback, BPF_SOCK_OPS_TSTAMP_ACK_CB. This callback will occur at the same timestamping point as the user space's SCM_TSTAMP_ACK. The BPF program can use it to get the same SCM_TSTAMP_ACK timestamp without modifying the user-space application. This patch extends txstamp_ack to two bits: 1 stands for SO_TIMESTAMPING mode, 2 bpf extension. Signed-off-by: Jason Xing Signed-off-by: Martin KaFai Lau Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250220072940.99994-10-kerneljasonxing@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 37f40511..15ff8719 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7047,6 +7047,11 @@ enum { * SK_BPF_CB_TX_TIMESTAMPING feature * is on. */ + BPF_SOCK_OPS_TSTAMP_ACK_CB, /* Called when all the skbs in the + * same sendmsg call are acked + * when SK_BPF_CB_TX_TIMESTAMPING + * feature is on. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From 2cdbecee76055caaf616f319fbe241d0e4b0ef18 Mon Sep 17 00:00:00 2001 From: Jason Xing Date: Thu, 20 Feb 2025 15:29:38 +0800 Subject: [PATCH 15/34] bpf: Add BPF_SOCK_OPS_TSTAMP_SENDMSG_CB callback This patch introduces a new callback in tcp_tx_timestamp() to correlate tcp_sendmsg timestamp with timestamps from other tx timestamping callbacks (e.g., SND/SW/ACK). Without this patch, BPF program wouldn't know which timestamps belong to which flow because of no socket lock protection. This new callback is inserted in tcp_tx_timestamp() to address this issue because tcp_tx_timestamp() still owns the same socket lock with tcp_sendmsg_locked() in the meanwhile tcp_tx_timestamp() initializes the timestamping related fields for the skb, especially tskey. The tskey is the bridge to do the correlation. For TCP, BPF program hooks the beginning of tcp_sendmsg_locked() and then stores the sendmsg timestamp at the bpf_sk_storage, correlating this timestamp with its tskey that are later used in other sending timestamping callbacks. Signed-off-by: Jason Xing Signed-off-by: Martin KaFai Lau Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20250220072940.99994-11-kerneljasonxing@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 15ff8719..53456370 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7052,6 +7052,11 @@ enum { * when SK_BPF_CB_TX_TIMESTAMPING * feature is on. */ + BPF_SOCK_OPS_TSTAMP_SENDMSG_CB, /* Called when every sendmsg syscall + * is triggered. It's used to correlate + * sendmsg timestamp with corresponding + * tskey. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From 3b009e77def473985df6fe479cc12606b7613141 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Mon, 24 Feb 2025 15:01:16 -0800 Subject: [PATCH 16/34] bpf: Allow pre-ordering for bpf cgroup progs Currently for bpf progs in a cgroup hierarchy, the effective prog array is computed from bottom cgroup to upper cgroups (post-ordering). For example, the following cgroup hierarchy root cgroup: p1, p2 subcgroup: p3, p4 have BPF_F_ALLOW_MULTI for both cgroup levels. The effective cgroup array ordering looks like p3 p4 p1 p2 and at run time, progs will execute based on that order. But in some cases, it is desirable to have root prog executes earlier than children progs (pre-ordering). For example, - prog p1 intends to collect original pkt dest addresses. - prog p3 will modify original pkt dest addresses to a proxy address for security reason. The end result is that prog p1 gets proxy address which is not what it wants. Putting p1 to every child cgroup is not desirable either as it will duplicate itself in many child cgroups. And this is exactly a use case we are encountering in Meta. To fix this issue, let us introduce a flag BPF_F_PREORDER. If the flag is specified at attachment time, the prog has higher priority and the ordering with that flag will be from top to bottom (pre-ordering). For example, in the above example, root cgroup: p1, p2 subcgroup: p3, p4 Let us say p2 and p4 are marked with BPF_F_PREORDER. The final effective array ordering will be p2 p4 p3 p1 Suggested-by: Andrii Nakryiko Acked-by: Andrii Nakryiko Signed-off-by: Yonghong Song Link: https://lore.kernel.org/r/20250224230116.283071-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 53456370..1923ba5e 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1207,6 +1207,7 @@ enum bpf_perf_event_type { #define BPF_F_BEFORE (1U << 3) #define BPF_F_AFTER (1U << 4) #define BPF_F_ID (1U << 5) +#define BPF_F_PREORDER (1U << 6) #define BPF_F_LINK BPF_F_LINK /* 1 << 13 */ /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the From c64dc6ab6f54716051107492ff89d3fa508e3685 Mon Sep 17 00:00:00 2001 From: Peilin Ye Date: Tue, 4 Mar 2025 01:06:13 +0000 Subject: [PATCH 17/34] bpf: Introduce load-acquire and store-release instructions Introduce BPF instructions with load-acquire and store-release semantics, as discussed in [1]. Define 2 new flags: #define BPF_LOAD_ACQ 0x100 #define BPF_STORE_REL 0x110 A "load-acquire" is a BPF_STX | BPF_ATOMIC instruction with the 'imm' field set to BPF_LOAD_ACQ (0x100). Similarly, a "store-release" is a BPF_STX | BPF_ATOMIC instruction with the 'imm' field set to BPF_STORE_REL (0x110). Unlike existing atomic read-modify-write operations that only support BPF_W (32-bit) and BPF_DW (64-bit) size modifiers, load-acquires and store-releases also support BPF_B (8-bit) and BPF_H (16-bit). As an exception, however, 64-bit load-acquires/store-releases are not supported on 32-bit architectures (to fix a build error reported by the kernel test robot). An 8- or 16-bit load-acquire zero-extends the value before writing it to a 32-bit register, just like ARM64 instruction LDARH and friends. Similar to existing atomic read-modify-write operations, misaligned load-acquires/store-releases are not allowed (even if BPF_F_ANY_ALIGNMENT is set). As an example, consider the following 64-bit load-acquire BPF instruction (assuming little-endian): db 10 00 00 00 01 00 00 r0 = load_acquire((u64 *)(r1 + 0x0)) opcode (0xdb): BPF_ATOMIC | BPF_DW | BPF_STX imm (0x00000100): BPF_LOAD_ACQ Similarly, a 16-bit BPF store-release: cb 21 00 00 10 01 00 00 store_release((u16 *)(r1 + 0x0), w2) opcode (0xcb): BPF_ATOMIC | BPF_H | BPF_STX imm (0x00000110): BPF_STORE_REL In arch/{arm64,s390,x86}/net/bpf_jit_comp.c, have bpf_jit_supports_insn(..., /*in_arena=*/true) return false for the new instructions, until the corresponding JIT compiler supports them in arena. [1] https://lore.kernel.org/all/20240729183246.4110549-1-yepeilin@google.com/ Acked-by: Eduard Zingerman Acked-by: Ilya Leoshkevich Cc: kernel test robot Signed-off-by: Peilin Ye Link: https://lore.kernel.org/r/a217f46f0e445fbd573a1a024be5c6bf1d5fe716.1741049567.git.yepeilin@google.com Signed-off-by: Alexei Starovoitov Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 3 +++ src/kernel/bpf/disasm.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 1923ba5e..aafd3091 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -51,6 +51,9 @@ #define BPF_XCHG (0xe0 | BPF_FETCH) /* atomic exchange */ #define BPF_CMPXCHG (0xf0 | BPF_FETCH) /* atomic compare-and-write */ +#define BPF_LOAD_ACQ 0x100 /* load-acquire */ +#define BPF_STORE_REL 0x110 /* store-release */ + enum bpf_cond_pseudo_jmp { BPF_MAY_GOTO = 0, }; diff --git a/src/kernel/bpf/disasm.c b/src/kernel/bpf/disasm.c index 309c4aa1..974d172d 100644 --- a/src/kernel/bpf/disasm.c +++ b/src/kernel/bpf/disasm.c @@ -267,6 +267,18 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, BPF_SIZE(insn->code) == BPF_DW ? "64" : "", bpf_ldst_string[BPF_SIZE(insn->code) >> 3], insn->dst_reg, insn->off, insn->src_reg); + } else if (BPF_MODE(insn->code) == BPF_ATOMIC && + insn->imm == BPF_LOAD_ACQ) { + verbose(cbs->private_data, "(%02x) r%d = load_acquire((%s *)(r%d %+d))\n", + insn->code, insn->dst_reg, + bpf_ldst_string[BPF_SIZE(insn->code) >> 3], + insn->src_reg, insn->off); + } else if (BPF_MODE(insn->code) == BPF_ATOMIC && + insn->imm == BPF_STORE_REL) { + verbose(cbs->private_data, "(%02x) store_release((%s *)(r%d %+d), r%d)\n", + insn->code, + bpf_ldst_string[BPF_SIZE(insn->code) >> 3], + insn->dst_reg, insn->off, insn->src_reg); } else { verbose(cbs->private_data, "BUG_%02x\n", insn->code); } From d46190943517986a2a7af7e9cf4369e7cf3e0058 Mon Sep 17 00:00:00 2001 From: Sewon Nam Date: Tue, 11 Mar 2025 12:12:37 +0900 Subject: [PATCH 18/34] bpf: bpftool: Setting error code in do_loader() We are missing setting error code in do_loader() when bpf_object__open_file() fails. This means the command's exit status code will be successful, even though the operation failed. So make sure to return the correct error code. To maintain consistency with other locations where bpf_object__open_file() is called, return -1. [0] Closes: https://github.com/libbpf/bpftool/issues/156 Reported-by: Dan Carpenter Signed-off-by: Sewon Nam Signed-off-by: Andrii Nakryiko Tested-by: Quentin Monnet Reviewed-by: Quentin Monnet Link: https://lore.kernel.org/bpf/d3b5b4b4-19bb-4619-b4dd-86c958c4a367@stanley.mountain/t/#u Link: https://lore.kernel.org/bpf/20250311031238.14865-1-swnam0729@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: c0d33ngr --- src/prog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/prog.c b/src/prog.c index e71be67f..52ffb74a 100644 --- a/src/prog.c +++ b/src/prog.c @@ -1928,6 +1928,7 @@ static int do_loader(int argc, char **argv) obj = bpf_object__open_file(file, &open_opts); if (!obj) { + err = -1; p_err("failed to open object file"); goto err_close_obj; } From b3aabd10a02730f5872b03e1284a146e9d400711 Mon Sep 17 00:00:00 2001 From: Mykyta Yatsenko Date: Mon, 17 Mar 2025 17:40:36 +0000 Subject: [PATCH 19/34] bpf: BPF token support for BPF_BTF_GET_FD_BY_ID Currently BPF_BTF_GET_FD_BY_ID requires CAP_SYS_ADMIN, which does not allow running it from user namespace. This creates a problem when freplace program running from user namespace needs to query target program BTF. This patch relaxes capable check from CAP_SYS_ADMIN to CAP_BPF and adds support for BPF token that can be passed in attributes to syscall. Signed-off-by: Mykyta Yatsenko Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20250317174039.161275-2-mykyta.yatsenko5@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index aafd3091..28705ae6 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1652,6 +1652,7 @@ union bpf_attr { }; __u32 next_id; __u32 open_flags; + __s32 fd_by_id_token_fd; }; struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */ From 6b435f669fe3f5a33a3f77849430259fca7db265 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Tue, 11 Mar 2025 19:28:08 +0800 Subject: [PATCH 20/34] bpftool: Add -Wformat-signedness flag to detect format errors This commit adds the -Wformat-signedness compiler flag to detect and prevent printf format errors, where signed or unsigned types are mismatched with format specifiers. This helps to catch potential issues at compile-time, ensuring that our code is more robust and reliable. With this flag, the compiler will now warn about incorrect format strings, such as using %d with unsigned types or %u with signed types. Signed-off-by: Jiayuan Chen Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20250311112809.81901-2-jiayuan.chen@linux.dev Signed-off-by: c0d33ngr --- src/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index ba6c096f..e9700829 100644 --- a/src/Makefile +++ b/src/Makefile @@ -63,7 +63,12 @@ prefix ?= /usr/local bash_compdir ?= /usr/share/bash-completion/completions CFLAGS += -O2 -CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers +CFLAGS += -W +CFLAGS += -Wall +CFLAGS += -Wextra +CFLAGS += -Wformat-signedness +CFLAGS += -Wno-unused-parameter +CFLAGS += -Wno-missing-field-initializers CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS)) CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ -I$(or $(OUTPUT),.) \ From c3e7e7cc23cc855ebde8729a1beb5e44bbb1c697 Mon Sep 17 00:00:00 2001 From: Jiayuan Chen Date: Tue, 11 Mar 2025 19:28:09 +0800 Subject: [PATCH 21/34] bpftool: Using the right format specifiers Fixed some formatting specifiers errors, such as using %d for int and %u for unsigned int, as well as other byte-length types. Perform type cast using the type derived from the data type itself, for example, if it's originally an int, it will be cast to unsigned int if forced to unsigned. Signed-off-by: Jiayuan Chen Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20250311112809.81901-3-jiayuan.chen@linux.dev Signed-off-by: c0d33ngr --- src/btf.c | 14 +++++++------- src/btf_dumper.c | 2 +- src/cgroup.c | 2 +- src/common.c | 4 ++-- src/jit_disasm.c | 3 ++- src/kernel/bpf/disasm.c | 4 ++-- src/map_perf_ring.c | 6 +++--- src/net.c | 4 ++-- src/netlink_dumper.c | 6 +++--- src/prog.c | 12 ++++++------ src/tracelog.c | 2 +- src/xlated_dumper.c | 6 +++--- 12 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/btf.c b/src/btf.c index 2636655a..6b14cbfa 100644 --- a/src/btf.c +++ b/src/btf.c @@ -253,7 +253,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id, if (btf_kflag(t)) printf("\n\t'%s' val=%d", name, v->val); else - printf("\n\t'%s' val=%u", name, v->val); + printf("\n\t'%s' val=%u", name, (__u32)v->val); } } if (json_output) @@ -1022,7 +1022,7 @@ static int do_dump(int argc, char **argv) for (i = 0; i < root_type_cnt; i++) { if (root_type_ids[i] == root_id) { err = -EINVAL; - p_err("duplicate root_id %d supplied", root_id); + p_err("duplicate root_id %u supplied", root_id); goto done; } } @@ -1132,7 +1132,7 @@ build_btf_type_table(struct hashmap *tab, enum bpf_obj_type type, break; default: err = -1; - p_err("unexpected object type: %d", type); + p_err("unexpected object type: %u", type); goto err_free; } if (err) { @@ -1155,7 +1155,7 @@ build_btf_type_table(struct hashmap *tab, enum bpf_obj_type type, break; default: err = -1; - p_err("unexpected object type: %d", type); + p_err("unexpected object type: %u", type); goto err_free; } if (fd < 0) { @@ -1188,7 +1188,7 @@ build_btf_type_table(struct hashmap *tab, enum bpf_obj_type type, break; default: err = -1; - p_err("unexpected object type: %d", type); + p_err("unexpected object type: %u", type); goto err_free; } if (!btf_id) @@ -1254,12 +1254,12 @@ show_btf_plain(struct bpf_btf_info *info, int fd, n = 0; hashmap__for_each_key_entry(btf_prog_table, entry, info->id) { - printf("%s%lu", n++ == 0 ? " prog_ids " : ",", entry->value); + printf("%s%lu", n++ == 0 ? " prog_ids " : ",", (unsigned long)entry->value); } n = 0; hashmap__for_each_key_entry(btf_map_table, entry, info->id) { - printf("%s%lu", n++ == 0 ? " map_ids " : ",", entry->value); + printf("%s%lu", n++ == 0 ? " map_ids " : ",", (unsigned long)entry->value); } emit_obj_refs_plain(refs_table, info->id, "\n\tpids "); diff --git a/src/btf_dumper.c b/src/btf_dumper.c index 527fe867..4e896d8a 100644 --- a/src/btf_dumper.c +++ b/src/btf_dumper.c @@ -653,7 +653,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id, case BTF_KIND_ARRAY: array = (struct btf_array *)(t + 1); BTF_PRINT_TYPE(array->type); - BTF_PRINT_ARG("[%d]", array->nelems); + BTF_PRINT_ARG("[%u]", array->nelems); break; case BTF_KIND_PTR: BTF_PRINT_TYPE(t->type); diff --git a/src/cgroup.c b/src/cgroup.c index 9af426d4..93b139bf 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -191,7 +191,7 @@ static int show_bpf_prog(int id, enum bpf_attach_type attach_type, if (attach_btf_name) printf(" %-15s", attach_btf_name); else if (info.attach_btf_id) - printf(" attach_btf_obj_id=%d attach_btf_id=%d", + printf(" attach_btf_obj_id=%u attach_btf_id=%u", info.attach_btf_obj_id, info.attach_btf_id); printf("\n"); } diff --git a/src/common.c b/src/common.c index 0a764426..ecfa790a 100644 --- a/src/common.c +++ b/src/common.c @@ -714,7 +714,7 @@ ifindex_to_arch(__u32 ifindex, __u64 ns_dev, __u64 ns_ino, const char **opt) int vendor_id; if (!ifindex_to_name_ns(ifindex, ns_dev, ns_ino, devname)) { - p_err("Can't get net device name for ifindex %d: %s", ifindex, + p_err("Can't get net device name for ifindex %u: %s", ifindex, strerror(errno)); return NULL; } @@ -739,7 +739,7 @@ ifindex_to_arch(__u32 ifindex, __u64 ns_dev, __u64 ns_ino, const char **opt) /* No NFP support in LLVM, we have no valid triple to return. */ default: p_err("Can't get arch name for device vendor id 0x%04x", - vendor_id); + (unsigned int)vendor_id); return NULL; } } diff --git a/src/jit_disasm.c b/src/jit_disasm.c index c032d2c6..8895b4e1 100644 --- a/src/jit_disasm.c +++ b/src/jit_disasm.c @@ -343,7 +343,8 @@ int disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, { const struct bpf_line_info *linfo = NULL; unsigned int nr_skip = 0; - int count, i, pc = 0; + int count, i; + unsigned int pc = 0; disasm_ctx_t ctx; if (!len) diff --git a/src/kernel/bpf/disasm.c b/src/kernel/bpf/disasm.c index 974d172d..20883c6b 100644 --- a/src/kernel/bpf/disasm.c +++ b/src/kernel/bpf/disasm.c @@ -202,7 +202,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, insn->dst_reg, class == BPF_ALU ? 'w' : 'r', insn->dst_reg); } else if (is_addr_space_cast(insn)) { - verbose(cbs->private_data, "(%02x) r%d = addr_space_cast(r%d, %d, %d)\n", + verbose(cbs->private_data, "(%02x) r%d = addr_space_cast(r%d, %u, %u)\n", insn->code, insn->dst_reg, insn->src_reg, ((u32)insn->imm) >> 16, (u16)insn->imm); } else if (is_mov_percpu_addr(insn)) { @@ -381,7 +381,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, insn->code, class == BPF_JMP32 ? 'w' : 'r', insn->dst_reg, bpf_jmp_string[BPF_OP(insn->code) >> 4], - insn->imm, insn->off); + (u32)insn->imm, insn->off); } } else { verbose(cbs->private_data, "(%02x) %s\n", diff --git a/src/map_perf_ring.c b/src/map_perf_ring.c index 21d7d447..552b4ca4 100644 --- a/src/map_perf_ring.c +++ b/src/map_perf_ring.c @@ -91,15 +91,15 @@ print_bpf_output(void *private_data, int cpu, struct perf_event_header *event) jsonw_end_object(json_wtr); } else { if (e->header.type == PERF_RECORD_SAMPLE) { - printf("== @%lld.%09lld CPU: %d index: %d =====\n", + printf("== @%llu.%09llu CPU: %d index: %d =====\n", e->time / 1000000000ULL, e->time % 1000000000ULL, cpu, idx); fprint_hex(stdout, e->data, e->size, " "); printf("\n"); } else if (e->header.type == PERF_RECORD_LOST) { - printf("lost %lld events\n", lost->lost); + printf("lost %llu events\n", lost->lost); } else { - printf("unknown event type=%d size=%d\n", + printf("unknown event type=%u size=%u\n", e->header.type, e->header.size); } } diff --git a/src/net.c b/src/net.c index d2242d9f..64f958f4 100644 --- a/src/net.c +++ b/src/net.c @@ -476,7 +476,7 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev, for (i = 0; i < optq.count; i++) { NET_START_OBJECT; NET_DUMP_STR("devname", "%s", dev->devname); - NET_DUMP_UINT("ifindex", "(%u)", dev->ifindex); + NET_DUMP_UINT("ifindex", "(%u)", (unsigned int)dev->ifindex); NET_DUMP_STR("kind", " %s", attach_loc_strings[loc]); ret = __show_dev_tc_bpf_name(prog_ids[i], prog_name, sizeof(prog_name)); @@ -831,7 +831,7 @@ static void show_link_netfilter(void) if (err) { if (errno == ENOENT) break; - p_err("can't get next link: %s (id %d)", strerror(errno), id); + p_err("can't get next link: %s (id %u)", strerror(errno), id); break; } diff --git a/src/netlink_dumper.c b/src/netlink_dumper.c index 5f65140b..0a3c7e96 100644 --- a/src/netlink_dumper.c +++ b/src/netlink_dumper.c @@ -45,7 +45,7 @@ static int do_xdp_dump_one(struct nlattr *attr, unsigned int ifindex, NET_START_OBJECT; if (name) NET_DUMP_STR("devname", "%s", name); - NET_DUMP_UINT("ifindex", "(%d)", ifindex); + NET_DUMP_UINT("ifindex", "(%u)", ifindex); if (mode == XDP_ATTACHED_MULTI) { if (json_output) { @@ -74,7 +74,7 @@ int do_xdp_dump(struct ifinfomsg *ifinfo, struct nlattr **tb) if (!tb[IFLA_XDP]) return 0; - return do_xdp_dump_one(tb[IFLA_XDP], ifinfo->ifi_index, + return do_xdp_dump_one(tb[IFLA_XDP], (unsigned int)ifinfo->ifi_index, libbpf_nla_getattr_str(tb[IFLA_IFNAME])); } @@ -168,7 +168,7 @@ int do_filter_dump(struct tcmsg *info, struct nlattr **tb, const char *kind, NET_START_OBJECT; if (devname[0] != '\0') NET_DUMP_STR("devname", "%s", devname); - NET_DUMP_UINT("ifindex", "(%u)", ifindex); + NET_DUMP_UINT("ifindex", "(%u)", (unsigned int)ifindex); NET_DUMP_STR("kind", " %s", kind); ret = do_bpf_filter_dump(tb[TCA_OPTIONS]); NET_END_OBJECT_FINAL; diff --git a/src/prog.c b/src/prog.c index 52ffb74a..f0102953 100644 --- a/src/prog.c +++ b/src/prog.c @@ -521,10 +521,10 @@ static void print_prog_header_plain(struct bpf_prog_info *info, int fd) print_dev_plain(info->ifindex, info->netns_dev, info->netns_ino); printf("%s", info->gpl_compatible ? " gpl" : ""); if (info->run_time_ns) - printf(" run_time_ns %lld run_cnt %lld", + printf(" run_time_ns %llu run_cnt %llu", info->run_time_ns, info->run_cnt); if (info->recursion_misses) - printf(" recursion_misses %lld", info->recursion_misses); + printf(" recursion_misses %llu", info->recursion_misses); printf("\n"); } @@ -569,7 +569,7 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd, bool orphaned) } if (info->btf_id) - printf("\n\tbtf_id %d", info->btf_id); + printf("\n\tbtf_id %u", info->btf_id); emit_obj_refs_plain(refs_table, info->id, "\n\tpids "); @@ -1164,7 +1164,7 @@ static int get_run_data(const char *fname, void **data_ptr, unsigned int *size) } if (nb_read > buf_size - block_size) { if (buf_size == UINT32_MAX) { - p_err("data_in/ctx_in is too long (max: %d)", + p_err("data_in/ctx_in is too long (max: %u)", UINT32_MAX); goto err_free; } @@ -2252,7 +2252,7 @@ static char *profile_target_name(int tgt_fd) t = btf__type_by_id(btf, func_info.type_id); if (!t) { - p_err("btf %d doesn't have type %d", + p_err("btf %u doesn't have type %u", info.btf_id, func_info.type_id); goto out; } @@ -2330,7 +2330,7 @@ static int profile_open_perf_events(struct profiler_bpf *obj) continue; for (cpu = 0; cpu < obj->rodata->num_cpu; cpu++) { if (profile_open_perf_event(m, cpu, map_fd)) { - p_err("failed to create event %s on cpu %d", + p_err("failed to create event %s on cpu %u", metrics[m].name, cpu); return -1; } diff --git a/src/tracelog.c b/src/tracelog.c index bf1f0221..31d806e3 100644 --- a/src/tracelog.c +++ b/src/tracelog.c @@ -78,7 +78,7 @@ static bool get_tracefs_pipe(char *mnt) return false; /* Allow room for NULL terminating byte and pipe file name */ - snprintf(format, sizeof(format), "%%*s %%%zds %%99s %%*s %%*d %%*d\\n", + snprintf(format, sizeof(format), "%%*s %%%zus %%99s %%*s %%*d %%*d\\n", PATH_MAX - strlen(pipe_name) - 1); while (fscanf(fp, format, mnt, type) == 2) if (strcmp(type, fstype) == 0) { diff --git a/src/xlated_dumper.c b/src/xlated_dumper.c index d0094345..5e7cb8b3 100644 --- a/src/xlated_dumper.c +++ b/src/xlated_dumper.c @@ -199,13 +199,13 @@ static const char *print_imm(void *private_data, if (insn->src_reg == BPF_PSEUDO_MAP_FD) snprintf(dd->scratch_buff, sizeof(dd->scratch_buff), - "map[id:%u]", insn->imm); + "map[id:%d]", insn->imm); else if (insn->src_reg == BPF_PSEUDO_MAP_VALUE) snprintf(dd->scratch_buff, sizeof(dd->scratch_buff), - "map[id:%u][0]+%u", insn->imm, (insn + 1)->imm); + "map[id:%d][0]+%d", insn->imm, (insn + 1)->imm); else if (insn->src_reg == BPF_PSEUDO_MAP_IDX_VALUE) snprintf(dd->scratch_buff, sizeof(dd->scratch_buff), - "map[idx:%u]+%u", insn->imm, (insn + 1)->imm); + "map[idx:%d]+%d", insn->imm, (insn + 1)->imm); else if (insn->src_reg == BPF_PSEUDO_FUNC) snprintf(dd->scratch_buff, sizeof(dd->scratch_buff), "subprog[%+d]", insn->imm); From af82703a8d19107e5a080d64f8d1e97dcc5ab8f1 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Thu, 3 Apr 2025 10:04:39 +0100 Subject: [PATCH 22/34] sync: Pull latest bpftool changes from kernel Syncing latest bpftool commits from kernel repository. Baseline bpf-next commit: 239860828f8660e2be487e2fbdae2640cce3fd67 Checkpoint bpf-next commit: 25601e85441dd91cf7973b002f27af4c5b8691ea Baseline bpf commit: 319fc77f8f45a1b3dba15b0cc1a869778fd222f7 Checkpoint bpf commit: 0c2623cef4f49e1ef6a908a389eea86130d11057 Charlie Jenkins (1): tools: Remove redundant quiet setup Jason Xing (6): bpf: Add networking timestamping support to bpf_get/setsockopt() bpf: Add BPF_SOCK_OPS_TSTAMP_SCHED_CB callback bpf: Add BPF_SOCK_OPS_TSTAMP_SND_SW_CB callback bpf: Add BPF_SOCK_OPS_TSTAMP_SND_HW_CB callback bpf: Add BPF_SOCK_OPS_TSTAMP_ACK_CB callback bpf: Add BPF_SOCK_OPS_TSTAMP_SENDMSG_CB callback Jiayuan Chen (2): bpftool: Add -Wformat-signedness flag to detect format errors bpftool: Using the right format specifiers Mykyta Yatsenko (1): bpf: BPF token support for BPF_BTF_GET_FD_BY_ID Peilin Ye (1): bpf: Introduce load-acquire and store-release instructions Sewon Nam (1): bpf: bpftool: Setting error code in do_loader() Vincent Mailhol (1): treewide: fix typo 'unsigned __init128' -> 'unsigned __int128' Yonghong Song (1): bpf: Allow pre-ordering for bpf cgroup progs docs/Makefile | 6 ------ include/uapi/linux/bpf.h | 35 +++++++++++++++++++++++++++++++++++ include/uapi/linux/const.h | 2 +- src/Makefile | 13 ++++++------- src/btf.c | 14 +++++++------- src/btf_dumper.c | 2 +- src/cgroup.c | 2 +- src/common.c | 4 ++-- src/jit_disasm.c | 3 ++- src/kernel/bpf/disasm.c | 16 ++++++++++++++-- src/map_perf_ring.c | 6 +++--- src/net.c | 4 ++-- src/netlink_dumper.c | 6 +++--- src/prog.c | 13 +++++++------ src/tracelog.c | 2 +- src/xlated_dumper.c | 6 +++--- 16 files changed, 88 insertions(+), 46 deletions(-) Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- BPF-CHECKPOINT-COMMIT | 2 +- CHECKPOINT-COMMIT | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BPF-CHECKPOINT-COMMIT b/BPF-CHECKPOINT-COMMIT index ced180be..d259437e 100644 --- a/BPF-CHECKPOINT-COMMIT +++ b/BPF-CHECKPOINT-COMMIT @@ -1 +1 @@ -319fc77f8f45a1b3dba15b0cc1a869778fd222f7 +0c2623cef4f49e1ef6a908a389eea86130d11057 diff --git a/CHECKPOINT-COMMIT b/CHECKPOINT-COMMIT index d15a2987..763cc665 100644 --- a/CHECKPOINT-COMMIT +++ b/CHECKPOINT-COMMIT @@ -1 +1 @@ -239860828f8660e2be487e2fbdae2640cce3fd67 +25601e85441dd91cf7973b002f27af4c5b8691ea From aebfe3064c3f9a4c53775279ab56999e60152e5c Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Thu, 3 Apr 2025 10:28:48 +0100 Subject: [PATCH 23/34] mirror: Update expected diff with kernel sources A recent patch has touched some portions of bpftool's Makefile that differ between kernel's and mirror's sources. Let's update the diff with the expected differences accordingly, to smoothen future sync ups. Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- scripts/sync-kernel-expected-diff.patch | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/scripts/sync-kernel-expected-diff.patch b/scripts/sync-kernel-expected-diff.patch index 9d89815b..9633a615 100644 --- a/scripts/sync-kernel-expected-diff.patch +++ b/scripts/sync-kernel-expected-diff.patch @@ -21,7 +21,7 @@ libbpf --- src/Makefile +++ src/Makefile -@@ -1,10 +1,8 @@ +@@ -1,13 +1,11 @@ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) -include ../../scripts/Makefile.include +include Makefile.include @@ -32,17 +32,12 @@ -srctree := $(patsubst %/,%,$(dir $(srctree))) endif - ifeq ($(V),1) -@@ -13,7 +11,7 @@ - Q = @ - endif - -BPF_DIR = $(srctree)/tools/lib/bpf +BPF_DIR = $(srctree)/libbpf/src ifneq ($(OUTPUT),) _OUTPUT := $(OUTPUT) -@@ -43,16 +41,16 @@ +@@ -37,16 +35,16 @@ $(QUIET_MKDIR)mkdir -p $@ $(LIBBPF): $(wildcard $(BPF_DIR)/*.[ch] $(BPF_DIR)/Makefile) | $(LIBBPF_OUTPUT) @@ -63,7 +58,7 @@ ARCH= CROSS_COMPILE= CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" $@ install_headers $(LIBBPF_BOOTSTRAP_INTERNAL_HDRS): $(LIBBPF_BOOTSTRAP_HDRS_DIR)/%.h: $(BPF_DIR)/%.h | $(LIBBPF_BOOTSTRAP_HDRS_DIR) -@@ -76,9 +74,9 @@ +@@ -75,9 +73,9 @@ CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ -I$(or $(OUTPUT),.) \ -I$(LIBBPF_INCLUDE) \ @@ -89,7 +84,7 @@ endif LIBS = $(LIBBPF) -lelf -lz -@@ -214,7 +208,7 @@ +@@ -225,7 +219,7 @@ $(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF_BOOTSTRAP) $(QUIET_CLANG)$(CLANG) \ -I$(or $(OUTPUT),.) \ @@ -98,7 +93,7 @@ -I$(LIBBPF_BOOTSTRAP_INCLUDE) \ -g -O2 -Wall -fno-stack-protector \ --target=bpf -c $< -o $@ -@@ -232,7 +226,7 @@ +@@ -243,7 +237,7 @@ CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_WITHOUT_SKELETONS) @@ -107,7 +102,7 @@ $(QUIET_CC)$(CC) $(CFLAGS) -c -MMD $< -o $@ $(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF_BOOTSTRAP) -@@ -251,7 +245,7 @@ +@@ -262,7 +256,7 @@ $(call QUIET_CLEAN, feature-detect) $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null @@ -116,7 +111,7 @@ $(call QUIET_CLEAN, bpftool) $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d $(Q)$(RM) -- $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h -@@ -267,7 +261,7 @@ +@@ -278,7 +272,7 @@ install: install-bin $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir) @@ -125,7 +120,7 @@ uninstall: $(call QUIET_UNINST, bpftool) -@@ -275,16 +269,16 @@ +@@ -286,16 +280,16 @@ $(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool doc: From e0b761f3def8afe6bdeefcdbc465508d2862129c Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 20 May 2025 10:13:55 +0100 Subject: [PATCH 24/34] sync: Update libbpf submodule Pull latest libbpf from mirror. Libbpf version: 1.6.0 Libbpf commit: 02bdeb7a2c2e7cb2c9cecb125527a9c5a6bbf139 Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- libbpf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbpf b/libbpf index 4659eaaf..02bdeb7a 160000 --- a/libbpf +++ b/libbpf @@ -1 +1 @@ -Subproject commit 4659eaafa4809150c9d1794455224af37252f6dd +Subproject commit 02bdeb7a2c2e7cb2c9cecb125527a9c5a6bbf139 From 91b345a64cedb1d8777c993287b2091bf5755e86 Mon Sep 17 00:00:00 2001 From: Anton Protopopov Date: Mon, 31 Mar 2025 20:36:17 +0000 Subject: [PATCH 25/34] bpf: Fix a comment describing bpf_attr The map_fd field of the bpf_attr union is used in the BPF_MAP_FREEZE syscall. Explicitly mention this in the comments. Signed-off-by: Anton Protopopov Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20250331203618.1973691-2-a.s.protopopov@gmail.com Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 28705ae6..07ee73cd 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1506,7 +1506,7 @@ union bpf_attr { __s32 map_token_fd; }; - struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ + struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */ __u32 map_fd; __aligned_u64 key; union { From 65158f4a841b6b6fe5bb698e09fe9a359974da97 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Tue, 8 Apr 2025 11:00:04 +0200 Subject: [PATCH 26/34] bpf: Clarify role of BPF_F_RECOMPUTE_CSUM BPF_F_RECOMPUTE_CSUM doesn't update the actual L3 and L4 checksums in the packet, but simply updates skb->csum (according to skb->ip_summed). This patch clarifies that to avoid confusions. Signed-off-by: Paul Chaignon Link: https://lore.kernel.org/r/ff6895d42936f03dbb82334d8bcfd50e00c79086.1744102490.git.paul.chaignon@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 07ee73cd..14ef3db8 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -1995,11 +1995,15 @@ union bpf_attr { * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags) * Description * Store *len* bytes from address *from* into the packet - * associated to *skb*, at *offset*. *flags* are a combination of - * **BPF_F_RECOMPUTE_CSUM** (automatically recompute the - * checksum for the packet after storing the bytes) and - * **BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\ - * **->swhash** and *skb*\ **->l4hash** to 0). + * associated to *skb*, at *offset*. The *flags* are a combination + * of the following values: + * + * **BPF_F_RECOMPUTE_CSUM** + * Automatically update *skb*\ **->csum** after storing the + * bytes. + * **BPF_F_INVALIDATE_HASH** + * Set *skb*\ **->hash**, *skb*\ **->swhash** and *skb*\ + * **->l4hash** to 0. * * A call to this helper is susceptible to change the underlying * packet buffer. Therefore, at load time, all checks on pointers From f87b1b7f941e9e62159624861772e6ec94cf6641 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Tue, 8 Apr 2025 11:00:51 +0200 Subject: [PATCH 27/34] bpf: Clarify the meaning of BPF_F_PSEUDO_HDR In the bpf_l4_csum_replace helper, the BPF_F_PSEUDO_HDR flag should only be set if the modified header field is part of the pseudo-header. If you modify for example the UDP ports and pass BPF_F_PSEUDO_HDR, inet_proto_csum_replace4 will update skb->csum even though it shouldn't (the port and the UDP checksum updates null each other). Signed-off-by: Paul Chaignon Link: https://lore.kernel.org/r/5126ef84ba75425b689482cbc98bffe75e5d8ab0.1744102490.git.paul.chaignon@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 14ef3db8..71d5ac83 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -2055,7 +2055,7 @@ union bpf_attr { * untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and * for updates resulting in a null checksum the value is set to * **CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates - * the checksum is to be computed against a pseudo-header. + * that the modified header field is part of the pseudo-header. * * This helper works in combination with **bpf_csum_diff**\ (), * which does not update the checksum in-place, but offers more From b081076ba4b55cc9df0e7c1e624e2df185c3ca5e Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Wed, 9 Apr 2025 17:11:18 -0700 Subject: [PATCH 28/34] tools headers: Update the uapi/linux/perf_event.h copy with the kernel sources To pick up the changes in: c53e14f1ea4a8f8d perf: Extend per event callchain limit to branch stack Addressing this perf tools build warning: Warning: Kernel ABI header differences: diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h Please see tools/include/uapi/README for further details. Acked-by: Ingo Molnar Tested-by: Venkat Rao Bagalkote Link: https://lore.kernel.org/r/20250410001125.391820-4-namhyung@kernel.org Signed-off-by: Namhyung Kim Signed-off-by: c0d33ngr --- include/uapi/linux/perf_event.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index 0524d541..5fc753c2 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -385,6 +385,8 @@ enum perf_event_read_format { * * @sample_max_stack: Max number of frame pointers in a callchain, * should be < /proc/sys/kernel/perf_event_max_stack + * Max number of entries of branch stack + * should be < hardware limit */ struct perf_event_attr { From 9a01d2e80164232ab2a8051234c0ca6fe178a81b Mon Sep 17 00:00:00 2001 From: YiFei Zhu Date: Mon, 28 Apr 2025 21:15:36 +0000 Subject: [PATCH 29/34] bpftool: Fix regression of "bpftool cgroup tree" EINVAL on older kernels If cgroup_has_attached_progs queries an attach type not supported by the running kernel, due to the kernel being older than the bpftool build, it would encounter an -EINVAL from BPF_PROG_QUERY syscall. Prior to commit 98b303c9bf05 ("bpftool: Query only cgroup-related attach types"), this EINVAL would be ignored by the function, allowing the function to only consider supported attach types. The commit changed so that, instead of querying all attach types, only attach types from the array `cgroup_attach_types` is queried. The assumption is that because these are only cgroup attach types, they should all be supported. Unfortunately this assumption may be false when the kernel is older than the bpftool build, where the attach types queried by bpftool is not yet implemented in the kernel. This would result in errors such as: $ bpftool cgroup tree CgroupPath ID AttachType AttachFlags Name Error: can't query bpf programs attached to /sys/fs/cgroup: Invalid argument This patch restores the logic of ignoring EINVAL from prior to that patch. Fixes: 98b303c9bf05 ("bpftool: Query only cgroup-related attach types") Reported-by: Sagarika Sharma Reported-by: Minh-Anh Nguyen Signed-off-by: YiFei Zhu Signed-off-by: Andrii Nakryiko Acked-by: Quentin Monnet Link: https://lore.kernel.org/bpf/20250428211536.1651456-1-zhuyifei@google.com Signed-off-by: c0d33ngr --- src/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cgroup.c b/src/cgroup.c index 93b139bf..3f1d6be5 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -221,7 +221,7 @@ static int cgroup_has_attached_progs(int cgroup_fd) for (i = 0; i < ARRAY_SIZE(cgroup_attach_types); i++) { int count = count_attached_bpf_progs(cgroup_fd, cgroup_attach_types[i]); - if (count < 0) + if (count < 0 && errno != EINVAL) return -1; if (count > 0) { From 8c79189115fa9a37b2b9a8a43a69bef7f4b9f919 Mon Sep 17 00:00:00 2001 From: Martin KaFai Lau Date: Wed, 7 May 2025 13:32:32 -0700 Subject: [PATCH 30/34] bpftool: Fix cgroup command to only show cgroup bpf programs The netkit program is not a cgroup bpf program and should not be shown in the output of the "bpftool cgroup show" command. However, if the netkit device happens to have ifindex 3, the "bpftool cgroup show" command will output the netkit bpf program as well: > ip -d link show dev nk1 3: nk1@if2: ... link/ether ... netkit mode ... > bpftool net show tc: nk1(3) netkit/peer tw_ns_nk2phy prog_id 469447 > bpftool cgroup show /sys/fs/cgroup/... ID AttachType AttachFlags Name ... ... ... 469447 netkit_peer tw_ns_nk2phy The reason is that the target_fd (which is the cgroup_fd here) and the target_ifindex are in a union in the uapi/linux/bpf.h. The bpftool iterates all values in "enum bpf_attach_type" which includes non cgroup attach types like netkit. The cgroup_fd is usually 3 here, so the bug is triggered when the netkit ifindex just happens to be 3 as well. The bpftool's cgroup.c already has a list of cgroup-only attach type defined in "cgroup_attach_types[]". This patch fixes it by iterating over "cgroup_attach_types[]" instead of "__MAX_BPF_ATTACH_TYPE". Cc: Quentin Monnet Reported-by: Takshak Chahande Signed-off-by: Martin KaFai Lau Acked-by: Daniel Borkmann Reviewed-by: Quentin Monnet Link: https://lore.kernel.org/r/20250507203232.1420762-1-martin.lau@linux.dev Signed-off-by: Alexei Starovoitov Signed-off-by: c0d33ngr --- src/cgroup.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cgroup.c b/src/cgroup.c index 3f1d6be5..944ebe21 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -318,11 +318,11 @@ static int show_bpf_progs(int cgroup_fd, enum bpf_attach_type type, static int do_show(int argc, char **argv) { - enum bpf_attach_type type; int has_attached_progs; const char *path; int cgroup_fd; int ret = -1; + unsigned int i; query_flags = 0; @@ -370,14 +370,14 @@ static int do_show(int argc, char **argv) "AttachFlags", "Name"); btf_vmlinux = libbpf_find_kernel_btf(); - for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++) { + for (i = 0; i < ARRAY_SIZE(cgroup_attach_types); i++) { /* * Not all attach types may be supported, so it's expected, * that some requests will fail. * If we were able to get the show for at least one * attach type, let's return 0. */ - if (show_bpf_progs(cgroup_fd, type, 0) == 0) + if (show_bpf_progs(cgroup_fd, cgroup_attach_types[i], 0) == 0) ret = 0; } @@ -400,9 +400,9 @@ static int do_show(int argc, char **argv) static int do_show_tree_fn(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftw) { - enum bpf_attach_type type; int has_attached_progs; int cgroup_fd; + unsigned int i; if (typeflag != FTW_D) return 0; @@ -434,8 +434,8 @@ static int do_show_tree_fn(const char *fpath, const struct stat *sb, } btf_vmlinux = libbpf_find_kernel_btf(); - for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++) - show_bpf_progs(cgroup_fd, type, ftw->level); + for (i = 0; i < ARRAY_SIZE(cgroup_attach_types); i++) + show_bpf_progs(cgroup_fd, cgroup_attach_types[i], ftw->level); if (errno == EINVAL) /* Last attach type does not support query. From e1625e0acdb8bd7e70ef09210ba2d415963804d8 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Fri, 9 May 2025 17:35:37 +0200 Subject: [PATCH 31/34] bpf: Add support to retrieve ref_ctr_offset for uprobe perf link Adding support to retrieve ref_ctr_offset for uprobe perf link, which got somehow omitted from the initial uprobe link info changes. Signed-off-by: Jiri Olsa Signed-off-by: Andrii Nakryiko Acked-by: Yafang Shao Link: https://lore.kernel.org/bpf/20250509153539.779599-2-jolsa@kernel.org Signed-off-by: c0d33ngr --- include/uapi/linux/bpf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 71d5ac83..16e95398 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -6724,6 +6724,7 @@ struct bpf_link_info { __u32 name_len; __u32 offset; /* offset from file_name */ __u64 cookie; + __u64 ref_ctr_offset; } uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */ struct { __aligned_u64 func_name; /* in/out */ From ed29bec4694a77724b8d2aba5a55710711b60c7f Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Fri, 9 May 2025 17:35:39 +0200 Subject: [PATCH 32/34] bpftool: Display ref_ctr_offset for uprobe link info Adding support to display ref_ctr_offset in link output, like: # bpftool link ... 42: perf_event prog 174 uprobe /proc/self/exe+0x102f13 cookie 3735928559 ref_ctr_offset 0x303a3fa bpf_cookie 3735928559 pids test_progs(1820) # bpftool link -j | jq [ ... { "id": 42, ... "ref_ctr_offset": 50500538, } ] Signed-off-by: Jiri Olsa Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20250509153539.779599-4-jolsa@kernel.org Signed-off-by: c0d33ngr --- src/link.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/link.c b/src/link.c index 52fd2c9f..3535afc8 100644 --- a/src/link.c +++ b/src/link.c @@ -380,6 +380,7 @@ show_perf_event_uprobe_json(struct bpf_link_info *info, json_writer_t *wtr) u64_to_ptr(info->perf_event.uprobe.file_name)); jsonw_uint_field(wtr, "offset", info->perf_event.uprobe.offset); jsonw_uint_field(wtr, "cookie", info->perf_event.uprobe.cookie); + jsonw_uint_field(wtr, "ref_ctr_offset", info->perf_event.uprobe.ref_ctr_offset); } static void @@ -823,6 +824,8 @@ static void show_perf_event_uprobe_plain(struct bpf_link_info *info) printf("%s+%#x ", buf, info->perf_event.uprobe.offset); if (info->perf_event.uprobe.cookie) printf("cookie %llu ", info->perf_event.uprobe.cookie); + if (info->perf_event.uprobe.ref_ctr_offset) + printf("ref_ctr_offset 0x%llx ", info->perf_event.uprobe.ref_ctr_offset); } static void show_perf_event_tracepoint_plain(struct bpf_link_info *info) From dd4ce4e59221d9648b966a1b7e0d2907a626e3be Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 20 May 2025 10:14:43 +0100 Subject: [PATCH 33/34] sync: Pull latest bpftool changes from kernel Syncing latest bpftool commits from kernel repository. Baseline bpf-next commit: 25601e85441dd91cf7973b002f27af4c5b8691ea Checkpoint bpf-next commit: 9325d53fe9adff354b6a93fda5f38c165947da0f Baseline bpf commit: 0c2623cef4f49e1ef6a908a389eea86130d11057 Checkpoint bpf commit: b4432656b36e5cc1d50a1f2dc15357543add530e Anton Protopopov (1): bpf: Fix a comment describing bpf_attr Jiri Olsa (2): bpf: Add support to retrieve ref_ctr_offset for uprobe perf link bpftool: Display ref_ctr_offset for uprobe link info Martin KaFai Lau (1): bpftool: Fix cgroup command to only show cgroup bpf programs Namhyung Kim (1): tools headers: Update the uapi/linux/perf_event.h copy with the kernel sources Paul Chaignon (2): bpf: Clarify role of BPF_F_RECOMPUTE_CSUM bpf: Clarify the meaning of BPF_F_PSEUDO_HDR YiFei Zhu (1): bpftool: Fix regression of "bpftool cgroup tree" EINVAL on older kernels include/uapi/linux/bpf.h | 19 ++++++++++++------- include/uapi/linux/perf_event.h | 2 ++ src/cgroup.c | 14 +++++++------- src/link.c | 3 +++ 4 files changed, 24 insertions(+), 14 deletions(-) Signed-off-by: Quentin Monnet Signed-off-by: c0d33ngr --- BPF-CHECKPOINT-COMMIT | 2 +- CHECKPOINT-COMMIT | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BPF-CHECKPOINT-COMMIT b/BPF-CHECKPOINT-COMMIT index d259437e..b0ce4e8d 100644 --- a/BPF-CHECKPOINT-COMMIT +++ b/BPF-CHECKPOINT-COMMIT @@ -1 +1 @@ -0c2623cef4f49e1ef6a908a389eea86130d11057 +b4432656b36e5cc1d50a1f2dc15357543add530e diff --git a/CHECKPOINT-COMMIT b/CHECKPOINT-COMMIT index 763cc665..4b9069cc 100644 --- a/CHECKPOINT-COMMIT +++ b/CHECKPOINT-COMMIT @@ -1 +1 @@ -25601e85441dd91cf7973b002f27af4c5b8691ea +9325d53fe9adff354b6a93fda5f38c165947da0f From d3e609a3c42c49a163e8a16672e29a43db25ab50 Mon Sep 17 00:00:00 2001 From: Quentin Monnet Date: Tue, 20 May 2025 11:15:18 +0100 Subject: [PATCH 34/34] ci: Dump deprecated Ubuntu 20.04 runner Ubuntu 20.04 runners for GitHub Actions have been retired. Let's remove them from the build matrix, to avoid failures in our CI. We want to add Ubuntu 24.04 instead, but need to finalise https://github.com/libbpf/bpftool/pull/179 for that. Link: https://github.blog/changelog/2025-01-15-github-actions-ubuntu-20-runner-image-brownout-dates-and-other-breaking-changes/ Signed-off-by: Quentin Monnet --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ca899ca7..8a5601df 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-24.04] + os: [ubuntu-22.04] runs-on: ${{ matrix.os }} env: FEATURES: .llvm and .skeletons