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
BPF example with ktrace and CO-RE #24
Merged
netoptimizer
merged 18 commits into
xdp-project:master
from
netoptimizer:ktrace01-CO-RE.public
Jun 24, 2021
Merged
BPF example with ktrace and CO-RE #24
netoptimizer
merged 18 commits into
xdp-project:master
from
netoptimizer:ktrace01-CO-RE.public
Jun 24, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Using bpf_core_type_id_kernel to find kernels BTF_ID for SKB. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Use this --debug to better understand what libbpf does of CO-RE relocation tricks and lookup of BTF-IDs. Example output: [...] libbpf: loading kernel BTF '/sys/kernel/btf/vmlinux': 0 libbpf: map 'ktrace01.data': created successfully, fd=4 libbpf: sec 'kprobe/udp_send_skb': found 4 CO-RE relocations libbpf: prog 'udp_send_skb': relo #0: kind <byte_off> (0), spec is [2] struct pt_regs.di (0:14 @ offset 112) libbpf: CO-RE relocating [0] struct pt_regs: found target candidate [176] struct pt_regs in [vmlinux] libbpf: prog 'udp_send_skb': relo #0: matching candidate #0 [176] struct pt_regs.di (0:14 @ offset 112) libbpf: prog 'udp_send_skb': relo #0: patched insn #0 (LDX/ST/STX) off 112 -> 112 libbpf: prog 'udp_send_skb': relo xdp-project#1: kind <byte_off> (0), spec is [7] struct sk_buff___local.hash (0:1 @ offset 4) libbpf: CO-RE relocating [0] struct sk_buff___local: found target candidate [2965] struct sk_buff in [vmlinux] [...] Notice how the BTF-ID of 'struct sk_buff' is resolved to be 2965. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Going to merge this as I need to reference some of the commits in emails. |
netoptimizer
added a commit
that referenced
this pull request
Aug 25, 2021
Fixes pull request #24 I had forgot to git add headers/vmlinux/vmlinux_arch.h in PR#24 which caused compile failures for ktrace-CO-RE. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
"Learning by doing":
I had to change the Makefile system to handle
SEC("kprobe")
and macroBPF_KPROBE
as compiling with-target bpf
result inPT_REGS_PARM1
not being defined. Asinclude <bpf/bpf_tracing.h>
cannot determine the ARCH from compiler defines.To solve this detect the
ARCH
our makefile system in file lib/common.mk (viauname -m
) and defines the__TARGET_ARCH_$(ARCH)
inBPF_CFLAGS
.This PR also contains some
vmlinux.h
header variants for a number of ARCHs.Choose to splitup
vmlinux_*.h
headers and only include what was needed for this example.We will see how much maintenance this cause, and if this is the case we can consider adding the full
vmlinux.h
later.