-
Notifications
You must be signed in to change notification settings - Fork 2
Fix recursive anon structures in btf. 8000 #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
There was a problem hiding this 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 addresses the recursive handling of anonymous structures in BTF definitions by updating offset calculation routines and cleaning up kprobe structure definitions.
- kprobe_defs.h: Updated the string identifiers to remove the redundant "(anon)" reference.
- btf.c: Introduced a recursive helper function (btf_offsetof_rec) for offset computation and updated related functions accordingly.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
kprobe_defs.h | Edited probe parameter labels to remove "(anon)" from the path. |
btf.c | Refactored offset computation functions to support recursion and adjusted anonymous structure handling. |
Comments suppressed due to low confidence (1)
btf.c:214
- The btf_root_offset2 function no longer checks that the offset is a multiple of 8 and does not perform a division by 8. Please confirm that this change in behavior is intentional and consistent with the expected offset units.
return (off);
9b87f5c
to
33f8b58
Compare
nfritts
approved these changes
Jun 9, 2025
nicholasberlin
approved these changes
Jun 9, 2025
Consider the following structure: ``` struct iov_iter { u8 iter_type; bool copy_mc; bool nofault; bool data_source; bool user_backed; union { size_t iov_offset; int last_offset; }; union { struct iovec __ubuf_iovec; struct { union { /* use iter_iov() to get the current vec */ ----------> const struct iovec *__iov; const struct kvec *kvec; const struct bio_vec *bvec; struct xarray *xarray; void __user *ubuf; }; size_t count; }; }; union { unsigned long nr_segs; loff_t xarray_start; }; }; ``` If we want to get the offsetof(iov_iter, __iov) we need to go through 3 anonymous structures/unions. This change makes it so that when we ask for iov_iter.__iov and we encounter an anonymous structure/union in its members, we recurse into it trying to find ___iov. Fixes tty_probes that rely on iov_iter.__iov, as a bonus it cuts the (anon) hack we had before, now we don't need to specify anything, which implies a btfhub.c regen in the upcoming commits. Spotted, debugged and verified that the fix works by @nicholasberlin, many thanks!!! Co-authored-by: Nicholas Berlin <56366649+nicholasberlin@users.noreply.github.com>
In libbf commit 62e8af46d2c269300f1e9e019ef717b283bd808a, the default error scheme has changed to libbpf_set_strict_mode(), which means no more error codes embeded in pointers. The commit is from 2022, and quark started in 2024, so it never made sense to use IS_ERR_OF_NULL, as it would always be NULL. Makes the code a bit more digestible and cuts an ugly include.
Now that the btf parser is recursive for anonymous structures, we don't need this anymore, see previous commit.
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.
Fix recursive anon structures in btf
Consider the following structure:
If we want to get the offsetof(iov_iter, __iov) we need to go through 3
anonymous structures/unions.
This change makes it so that when we ask for iov_iter.__iov and we encounter an
anonymous structure/union in its members, we recurse into it trying to find
___iov.
Fixes tty_probes that rely on iov_iter.__iov, as a bonus it cuts the (anon) hack
we had before, now we don't need to specify anything, which implies a btfhub.c
regen in the upcoming commits.
Spotted, debugged and verified that the fix works by @nicholasberlin, many
thanks!!!
+++
Adapt libbpf error handling to post 1.0
In libbf commit 62e8af46d2c269300f1e9e019ef717b283bd808a, the default error
scheme has changed to libbpf_set_strict_mode(), which means no more error codes
embeded in pointers. The commit is from 2022, and quark started in 2024, so it
never made sense to use IS_ERR_OF_NULL, as it would always be NULL.
Makes the code a bit more digestible and cuts an ugly include.