Skip to content

Conversation

cfc4n
Copy link
Member

@cfc4n cfc4n commented Jun 16, 2025

This pull request introduces several updates to the eBPF codebase, including enhancements to kernel compatibility, new helper macros, and improvements to core relocation handling. The changes aim to increase compatibility with newer compilers, improve usability, and add new functionality for eBPF programs.

Kernel Compatibility Enhancements:

  • Updated include paths in the Makefile to include $(KERN_SRC_PATH)/include/linux, ensuring compatibility with additional kernel headers. [1] [2]
  • Replaced vmlinux_510.h with vmlinux_614.h in kern/bpf/arm64/vmlinux.h to align with a newer kernel version.

Core Relocation and Type Handling:

  • Added support for a new BPF_TYPE_MATCHES kind in enum bpf_type_info_kind to check type matches in target kernels.
  • Introduced bpf_core_cast() to simplify pointer casting with kernel-side BTF types, enabling direct member access.
  • Enhanced macros like bpf_core_field_exists and bpf_core_field_size to support both variable and type-based field references. [1] [2]

Compiler Compatibility and Optimization:

  • Improved compatibility with GCC and Clang by refining macros such as SEC() and offsetof() to handle compiler-specific quirks. [1] [2]
  • Added likely() and unlikely() macros for branch prediction optimization.

New Helper Macros and Functions:

  • Introduced BPF_CORE_WRITE_BITFIELD() for writing to bitfields, complementing existing read macros.
  • Added barrier() and barrier_var() macros to enforce memory and variable-specific compiler barriers.

Cleanups and Deprecations:

  • Removed the legacy bpf_map_def structure, which has been replaced by newer mechanisms in the eBPF ecosystem.

refer: iovisor/bcc#5258

@cfc4n cfc4n requested a review from Copilot June 16, 2025 16:00
@cfc4n cfc4n added the enhancement New feature or request label Jun 16, 2025
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 16, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the eBPF codebase by updating kernel compatibility, improving core relocation handling, and adding new helper macros and functions for more robust pointer casting and branch prediction.

  • Kernel Compatibility Enhancements: Updated include paths and replaced the vmlinux header to support newer kernel versions.
  • Core Relocation and Type Handling: Introduced support for a new type-matching mechanism and added bpf_core_cast for direct member accesses.
  • Compiler Compatibility and Optimization: Refined helper macros (e.g., SEC, likely/unlikely) and removed legacy structures to streamline the code.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
variables.mk Added the '-Wno-unknown-attributes' flag to suppress warnings for unknown attributes.
kern/go_argument.h Updated macros to use standardized parameter access for Go function calls and removed legacy macros.
kern/ecapture.h Adjusted include directives to incorporate new core fixes.
kern/core_fixes.bpf.h Introduced new structures and inline functions to handle kernel CO-RE fixes.
kern/bpf/x86/vmlinux.h Updated the reference to point to the newer vmlinux header.
kern/bpf/bpf_helpers.h Revised helper macros including SEC and branch prediction constructs for improved compiler compatibility.
kern/bpf/bpf_core_read.h Added new macros for bitfield writing and type casting, and updated core read logic.
kern/bpf/arm64/vmlinux.h Updated the reference to use the newer vmlinux header.
Makefile Modified kernel include paths to incorporate the linux directory.
Comments suppressed due to low confidence (3)

variables.mk:262

  • [nitpick] Consider adding a comment explaining why the '-Wno-unknown-attributes' flag is added to inform future maintainers of its purpose.
+	-Wno-unknown-attributes \

kern/go_argument.h:33

  • [nitpick] Ensure that the removal of the GO_PARAM9 macro (and similarly, GOROUTINE) is consistent with the expected argument handling across all target architectures.
-#define GO_PARAM9(x) BPF_CORE_READ((x), r11)

kern/bpf/bpf_helpers.h:41

  • [nitpick] Consider adding a brief comment explaining the rationale behind the conditional SEC macro definitions based on the compiler to aid clarity for future maintenance.
#define SEC(name) __attribute__((section(name), used))

Copy link

Failed to generate code suggestions for PR

@cfc4n cfc4n merged commit 9cd91ad into master Jun 17, 2025
6 checks passed
@cfc4n cfc4n deleted the update-vmlinux-ebpf-macro branch June 17, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant