-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Draft] Append BTF ID to type ID in libbpf CO-RE relocation #13
Changes from 1 commit
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 |
---|---|---|
|
@@ -873,6 +873,7 @@ enum bpf_cmd { | |
BPF_ITER_CREATE, | ||
BPF_LINK_DETACH, | ||
BPF_PROG_BIND_MAP, | ||
BPF_BTF_VMLINUX_INFO, | ||
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. BPF_BTF_GET_VMLINUX_ID? Third word is usually a verb here I'd say. 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. BPF_BTF_GET_VMLINUX_INFO would be better? |
||
}; | ||
|
||
enum bpf_map_type { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,13 +430,28 @@ const struct btf *btf__base_btf(const struct btf *btf) | |
return btf->base_btf; | ||
} | ||
|
||
__u32 btf__obj_id(const struct btf *btf) | ||
static __u32 btf_get_vmlinux_obj_id(void) | ||
{ | ||
struct bpf_btf_info btf_info; | ||
unsigned int len = sizeof(btf_info); | ||
int err = 0; | ||
|
||
memset(&btf_info, 0, sizeof(btf_info)); | ||
err = bpf_get_vmlinux_btf_info(&btf_info, &len); | ||
|
||
if (err) return 0; | ||
return btf_info.id; | ||
} | ||
|
||
__u32 btf_obj_id(const struct btf *btf) | ||
{ | ||
struct bpf_btf_info btf_info; | ||
unsigned int len = sizeof(btf_info); | ||
int err = 0; | ||
int fd = btf__fd(btf); | ||
|
||
if (btf->base_btf == NULL) return btf_get_vmlinux_obj_id(); | ||
|
||
memset(&btf_info, 0, sizeof(btf_info)); | ||
err = bpf_obj_get_info_by_fd(fd, &btf_info, &len); | ||
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. I'm curious if there is a way to get FD for vmlinux to unify both implementations. Loaded kernel is not a file, just a piece of memory, so we can't have a "real" FD here, OTOH we have /proc/kcore, so there probably should be. 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. I've just tested, we can totally get vmlinux fd, so nothing prevents us from initializing it correctly at btf load time. Also now I am kinda more inclined towards adding btf id to libbpf btf struct, it shouldn't be hard to implement. Maybe I'd rather submit that small fix I've mentioned first, just to see what community currently thinks about how fds should be used in libbpf. 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. Yes, sure! I'm glad we're able to get vmlinux fd, seems like new syscall commands won't be needed. 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. We do still need the syscall I've added in this PR, but no other should be necessary 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. Getting vmlinux' FD -> bpf_obj_get_info_by_fd() instead of btf_get_vmlinux_obj_id(), or am I missing something?
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. I guess I need to elaborate on the current situation:
Therefore I would do the following:
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. Changing vmlinux loading process will render btf_get_vmlinux_obj_id() obsolete 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. Sounds fine to me, seems like we should give it a go! |
||
|
||
|
@@ -1390,10 +1405,10 @@ struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf) | |
} | ||
|
||
btf = btf_new(ptr, btf_info.btf_size, base_btf); | ||
btf->fd = btf_fd; | ||
|
||
exit_free: | ||
free(ptr); | ||
btf->fd = btf_fd; | ||
return btf; | ||
} | ||
|
||
|
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 this needed?
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.
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
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.
Oh, got it, thanks