-
Notifications
You must be signed in to change notification settings - Fork 2
[Draft] Append BTF ID to type ID in libbpf CO-RE relocation #13
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
f03ca7d
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 |
|---|---|---|
|
|
@@ -4542,6 +4542,25 @@ static int bpf_prog_bind_map(union bpf_attr *attr) | |
| return ret; | ||
| } | ||
|
|
||
| #define BPF_BTF_VMLINUX_INFO_LAST_FIELD info.info | ||
|
Collaborator
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. Is this needed?
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. Yep, it's used behind the curtains by CHECK_ATTR(): https://elixir.bootlin.com/linux/v5.15-rc7/source/kernel/bpf/syscall.c#L715 That's why I prefer to pass all needed params to macros explicitly :P
Collaborator
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, got it, thanks |
||
|
|
||
| static int bpf_btf_get_vmlinux_info(const union bpf_attr *attr, | ||
| union bpf_attr __user *uattr) | ||
| { | ||
| struct bpf_btf_info __user *uinfo = u64_to_user_ptr(attr->info.info); | ||
| u32 info_len = attr->info.info_len; | ||
| int err; | ||
|
|
||
| if (CHECK_ATTR(BPF_BTF_VMLINUX_INFO)) | ||
| return -EINVAL; | ||
|
|
||
| err = bpf_check_uarg_tail_zero(USER_BPFPTR(uinfo), sizeof(*uinfo), info_len); | ||
| if (err) | ||
| return err; | ||
|
|
||
| return btf_get_info_by_fd(bpf_get_btf_vmlinux(), attr, uattr); | ||
| } | ||
|
|
||
| static int __sys_bpf(int cmd, bpfptr_t uattr, unsigned int size) | ||
| { | ||
| union bpf_attr attr; | ||
|
|
@@ -4678,6 +4697,9 @@ static int __sys_bpf(int cmd, bpfptr_t uattr, unsigned int size) | |
| case BPF_PROG_BIND_MAP: | ||
| err = bpf_prog_bind_map(&attr); | ||
| break; | ||
| case BPF_BTF_VMLINUX_INFO: | ||
| err = bpf_btf_get_vmlinux_info(&attr, uattr.user); | ||
| break; | ||
| default: | ||
| err = -EINVAL; | ||
| break; | ||
|
|
||
| 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. Oops. |
||
| 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.
One thing here. If both vmlinux and our module have the same struct, will this func return different IDs when called with mod and without? That might be unwanted when we will compare type IDs against each other. The flow should probably be going the way that if vmlinux has this structure, then we always return type ID from it, and a type ID from a module only if there's no such type in vmlinux.
Uh oh!
There was an error while loading. Please reload this page.
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.
From what I know of how BTFs work, type duplication between vmlinux and any single module BTF is impossible, it's a problem only if we have 2 module BTFs. But I like the idea of looking into vmlinux first, even if we do have a mod != NULL, this would improve user experience. There is non-zero possibility that btf_find_by_name_kind() already does that (checks base btf, which is vmlinux), I need to check this.
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.
It does exactly that, so functionally this piece of code is OK.