-
Notifications
You must be signed in to change notification settings - Fork 190
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
fix(bpf): Access __state from task_struct #1550
fix(bpf): Access __state from task_struct #1550
Conversation
🤖 SeineSailor Here is a concise summary of the pull request changes: Summary: The Key Modifications:
Impact on Codebase:
Observations and Suggestions:
Overall, the pull request appears to be a well-structured and targeted fix to ensure compatibility with older kernel versions. |
bpfassets/libbpf/src/kepler.bpf.c
Outdated
int pid; | ||
unsigned int __state; |
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.
Is it fixed / defined what the size of int
is ?
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.
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.
Also, these fields are BTF relocated - which will perform the necessary checks around int size and signedness at program load time.
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.
Thanks Dave.
Related question ... shouldn't we use unsigned int
or u32
for pid
as well?
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.
Shouldn't we use BPF_CORE_READ() to read the pointers in a safe manner?
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.
@sthaha I'm just using whatever is used in task_struct
in the kernel - see https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h#L977
if you follow the links from pid_t
down to a concrete type you get to https://elixir.bootlin.com/linux/latest/source/include/uapi/asm-generic/posix_types.h#L28
@marceloamaral no you don't need to use BPF_CORE_READ in tp_btf programs.
https://mozillazg.com/2022/06/ebpf-libbpf-btf-powered-enabled-raw-tracepoint-common-questions-en.html#hidthe-difference-between-btf-raw-tracepoint-and-raw-tracepoint
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.
Thanks a lot for clarifications, @dave-tucker 🙏
In older kernels prev_state isn't passed as part of the context of the function. Therefore it's better to access prev_task-->_state directly. The field was renamed from state to __state in Kernel 5.14. Given that we need to support Kernel 5.12+ we include the bpf_core_read.h file such that we can use the bpf_core_field_exists function that allows us to see which field is present in task struct and return the correct value. Signed-off-by: Dave Tucker <[email protected]>
326df18
to
a29280d
Compare
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.
/lgtm
fbe9b3c
into
sustainable-computing-io:main
In older kernels prev_state isn't passed as part of the context of the
function. Therefore it's better to access prev_task-->_state directly.
The field was renamed from state to __state in Kernel 5.14.
Given that we need to support Kernel 5.12+ we include the
bpf_core_read.h file such that we can use the bpf_core_field_exists
function that allows us to see which field is present in task struct
and return the correct value.