feat: enhance BPF core read macros and add new utility functions#797
Merged
Conversation
refer: iovisor/bcc#5258 Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
There was a problem hiding this comment.
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))
|
Failed to generate code suggestions for PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Makefileto include$(KERN_SRC_PATH)/include/linux, ensuring compatibility with additional kernel headers. [1] [2]vmlinux_510.hwithvmlinux_614.hinkern/bpf/arm64/vmlinux.hto align with a newer kernel version.Core Relocation and Type Handling:
BPF_TYPE_MATCHESkind inenum bpf_type_info_kindto check type matches in target kernels.bpf_core_cast()to simplify pointer casting with kernel-side BTF types, enabling direct member access.bpf_core_field_existsandbpf_core_field_sizeto support both variable and type-based field references. [1] [2]Compiler Compatibility and Optimization:
SEC()andoffsetof()to handle compiler-specific quirks. [1] [2]likely()andunlikely()macros for branch prediction optimization.New Helper Macros and Functions:
BPF_CORE_WRITE_BITFIELD()for writing to bitfields, complementing existing read macros.barrier()andbarrier_var()macros to enforce memory and variable-specific compiler barriers.Cleanups and Deprecations:
bpf_map_defstructure, which has been replaced by newer mechanisms in the eBPF ecosystem.refer: iovisor/bcc#5258