-
Notifications
You must be signed in to change notification settings - Fork 2
[Draft] Patching in BTF ID + unifying vmlinux and module BTFs acquisition #14
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
Changes from all commits
c8c5144
92adc5d
aef5c23
f40e089
b063494
20f3208
5520689
8c1d5da
4b40b4a
7ac5e22
0a0b30e
2573502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -873,6 +873,7 @@ enum bpf_cmd { | |
| BPF_ITER_CREATE, | ||
| BPF_LINK_DETACH, | ||
| BPF_PROG_BIND_MAP, | ||
| BPF_BTF_VMLINUX_INFO, | ||
| }; | ||
|
|
||
| enum bpf_map_type { | ||
|
|
@@ -1396,6 +1397,11 @@ union bpf_attr { | |
| __aligned_u64 info; | ||
| } info; | ||
|
|
||
| struct { /* anonymous struct used by BPF_BTF_VMLINUX_INFO */ | ||
| __u32 info_len; | ||
| __aligned_u64 info; | ||
| } info_vmlinux; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check (using pahole) if this structure has a padding between u32 and u64. If so, it may be better to explicitly enumerate it.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, BTW, I have forgot to mention this particular problem with current version, I mean that the actual syscall does not use this structure, because internal function requires "info" structure and I kinda postponed the refactoring (hoping a little bit maybe it would not be necessary). But I'll check the padding when structure actually gets into an object file. By enumerating you mean putting additional u32 blank space?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, |
||
|
|
||
| struct { /* anonymous struct used by BPF_PROG_QUERY command */ | ||
| __u32 target_fd; /* container object to query */ | ||
| __u32 attach_type; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6152,6 +6152,43 @@ struct module *btf_try_get_module(const struct btf *btf) | |
| return res; | ||
| } | ||
|
|
||
| struct btf *btf_get_from_module(const struct module *module) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't get exposed anywhere. static? |
||
| { | ||
| struct btf *res = NULL; | ||
| #ifdef CONFIG_DEBUG_INFO_BTF_MODULES | ||
| struct btf_module *btf_mod, *tmp; | ||
|
|
||
| mutex_lock(&btf_module_mutex); | ||
| list_for_each_entry_safe(btf_mod, tmp, &btf_modules, list) { | ||
| if (btf_mod->module != module) | ||
| continue; | ||
|
|
||
| res = btf_mod->btf; | ||
|
|
||
| break; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No empty line needed here. |
||
| } | ||
| mutex_unlock(&btf_module_mutex); | ||
| #endif | ||
|
|
||
| return res; | ||
| } | ||
|
|
||
| s32 btf_get_type_id(const struct module *mod, char *name, u32 kind) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'name' can (and should) be const as well. |
||
| { | ||
| struct btf *btf; | ||
|
|
||
| if (mod) | ||
| btf = btf_get_from_module(mod); | ||
| else | ||
| btf = bpf_get_btf_vmlinux(); | ||
|
|
||
| if (!btf) | ||
| return 0; | ||
|
|
||
| return btf_find_by_name_kind(btf, name, kind); | ||
| } | ||
| EXPORT_SYMBOL_GPL(btf_get_type_id); | ||
|
|
||
| BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags) | ||
| { | ||
| struct btf *btf; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ tprogs-y += xdp_redirect_map_multi | |
| tprogs-y += xdp_redirect_map | ||
| tprogs-y += xdp_redirect | ||
| tprogs-y += xdp_monitor | ||
| tprogs-y += xdp_meta | ||
|
|
||
| # Libbpf dependencies | ||
| LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a | ||
|
|
@@ -118,6 +119,7 @@ xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o $(XDP_SAMPLE) | |
| xdp_redirect_map-objs := xdp_redirect_map_user.o $(XDP_SAMPLE) | ||
| xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE) | ||
| xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE) | ||
| xdp_meta-objs := xdp_meta_user.o | ||
|
|
||
| # Tell kbuild to always build the programs | ||
| always-y := $(tprogs-y) | ||
|
|
@@ -314,6 +316,7 @@ $(obj)/xdp_redirect_map_multi_user.o: $(obj)/xdp_redirect_map_multi.skel.h | |
| $(obj)/xdp_redirect_map_user.o: $(obj)/xdp_redirect_map.skel.h | ||
| $(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h | ||
| $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h | ||
| $(obj)/xdp_meta_user.o: $(obj)/xdp_meta.skel.h | ||
|
|
||
| $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h | ||
| $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h | ||
|
|
@@ -371,17 +374,18 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/x | |
| -c $(filter %.bpf.c,$^) -o $@ | ||
|
|
||
| LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect_map_multi.skel.h \ | ||
| xdp_redirect_map.skel.h xdp_redirect.skel.h xdp_monitor.skel.h | ||
| xdp_redirect_map.skel.h xdp_redirect.skel.h xdp_monitor.skel.h \ | ||
| xdp_meta.skel.h | ||
| clean-files += $(LINKED_SKELS) | ||
|
|
||
| xdp_redirect_cpu.skel.h-deps := xdp_redirect_cpu.bpf.o xdp_sample.bpf.o | ||
| xdp_redirect_map_multi.skel.h-deps := xdp_redirect_map_multi.bpf.o xdp_sample.bpf.o | ||
| xdp_redirect_map.skel.h-deps := xdp_redirect_map.bpf.o xdp_sample.bpf.o | ||
| xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o | ||
| xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o | ||
| xdp_meta.skel.h-deps := xdp_meta.bpf.o | ||
|
|
||
| LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps))) | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: please avoid unwanted/unrelated changes to sneak into the commits in the future. It's okay to have them in drafts / WIPs, but a good habit anyway. |
||
| BPF_SRCS_LINKED := $(notdir $(wildcard $(src)/*.bpf.c)) | ||
| BPF_OBJS_LINKED := $(patsubst %.bpf.c,$(obj)/%.bpf.o, $(BPF_SRCS_LINKED)) | ||
| BPF_SKELS_LINKED := $(addprefix $(obj)/,$(LINKED_SKELS)) | ||
|
|
||
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.
BPF_BTF_GET_VMLINUX_INFOas we discussed previously?