-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
support all iters #2630
support all iters #2630
Conversation
d9883c6
to
e28f583
Compare
int main(void) | ||
{ | ||
struct bpf_iter__task iter_task; | ||
struct bpf_iter__task_file iter_task_file; | ||
struct bpf_iter__task_vma iter_task_vma; | ||
|
||
func_1(0, 0, 0); | ||
|
||
bpf_iter_task(); |
Check warning
Code scanning / CodeQL
Expression has no effect
int main(void) | ||
{ | ||
struct bpf_iter__task iter_task; | ||
struct bpf_iter__task_file iter_task_file; | ||
struct bpf_iter__task_vma iter_task_vma; | ||
|
||
func_1(0, 0, 0); | ||
|
||
bpf_iter_task(); | ||
bpf_iter_task_file(); |
Check warning
Code scanning / CodeQL
Expression has no effect
|
||
bpf_iter_task(); | ||
bpf_iter_task_file(); | ||
bpf_iter_task_vma(); |
Check warning
Code scanning / CodeQL
Expression has no effect
917ba89
to
37f4f08
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.
Woah, didn't realize it would be this easy to support all iters. Lgtm overall, just some small nits. Great PR!
OK, it has been removed. In addition, a new commit |
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.
Nice!
Can you update the changelog please? |
According to [1], we can get all iter types supported by the current kernel according to the 'bpf_ter__' prefix [1]: https://www.kernel.org/doc/html/latest/bpf/bpf_iterators.html#how-to-use-bpf-iterators Signed-off-by: Shuyi Cheng <[email protected]>
Run bpftrace -l iter:* the output is as follows: iter:task iter:task_file iter:task_vma But the current kernel does not support 'iter:task_vma'. After applying this patch, run the command again, the output is as follows: iter:bpf_map iter:bpf_map_elem iter:bpf_prog iter:bpf_sk_storage_map iter:ipv6_route iter:netlink iter:sockmap iter:task iter:task_file iter:tcp iter:udp Signed-off-by: Shuyi Cheng <[email protected]>
For each iter, the kernel will have a bpf_iter_$ITER function, so we can get the parameters of iter through bpf_iter_$ITER. Run `bpftrace -l iter:*` and shows: ``` iter:task struct task_struct * task iter:task_file struct task_struct * task int fd struct file * file iter:task_vma struct task_struct * task struct vm_area_struct * vma ``` The output after applying this patch is as follows: ``` iter:bpf_map struct bpf_map * map iter:bpf_map_elem struct bpf_map * map void * key void * value iter:bpf_prog struct bpf_prog * prog iter:bpf_sk_storage_map struct bpf_map * map struct sock * sk void * value iter:ipv6_route struct fib6_info * rt iter:netlink struct netlink_sock * sk iter:sockmap struct bpf_map * map void * key struct sock * sk iter:task struct task_struct * task iter:task_file struct task_struct * task u32 fd struct file * file iter:tcp struct sock_common * sk_common uid_t uid iter:udp struct udp_sock * udp_sk uid_t uid int bucket ``` Signed-off-by: Shuyi Cheng <[email protected]>
Support all iters, this patch mainly modifies the following places: - Delete the hard code, and get the type of iter by concatenating `bpf_iter__` and the function name - Use has_iter to check whether the iter exists - add iter tracing function for tests - clean up older iter related code Signed-off-by: Shuyi Cheng <[email protected]>
When ap.func is empty, the input parameter tokens of the wildcard_match function will be empty, and a panic will occur when tokens[0] is obtained. Therefore, iter should be similar to kfunc, and avoid ap.func being empty during the semantic analysis stage. ``` bpftrace -l kfunc: stdin:1:1-7: ERROR: kfunc should specify a function kfunc: ~~~~~~ bpftrace -l iter: stdin:1:1-6: ERROR: iter should specify a iterator's name iter: ~~~~~ ``` Signed-off-by: Shuyi Cheng <[email protected]>
Signed-off-by: Shuyi Cheng <[email protected]>
Done, thanks. |
This pr mainly improves bpftrace's support for iter
bpftrace -l iter:*
print the iter supported by the current kernelissues: #2620
Checklist
man/adoc/bpftrace.adoc
and if needed indocs/reference_guide.md
CHANGELOG.md