forked from torvalds/linux
-
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
Closed
walking-machine
wants to merge
12
commits into
master
from
generic-metadata-sample-module-btf-syscall
Closed
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c8c5144
uapi: add metadata flag to xdp flags
mswiatko 92adc5d
net: include xdp generic metadata definition
mswiatko aef5c23
ice: use xdp generic metadata
mswiatko f40e089
btf: ice: implement finding BTF type id
mswiatko b063494
samples: bpf: add simple sample with CORE
walking-machine 20f3208
[TEMP] bpf: use xdp_meta_generic in kernel
walking-machine 5520689
samples: bpf: Improve user experience in xdp_meta sample
walking-machine 8c1d5da
bpf: samples: Print out hash and RX VID
walking-machine 4b40b4a
bpf: samples: Patch module BTF id into bpf insns
walking-machine 7ac5e22
bpf: samples: Read BTF ID with libbpf in hints sample
walking-machine 0a0b30e
libbpf: Acquire vmlinux BTF ID from libbpf
walking-machine f03ca7d
libbpf: Pass BTF ID in struct bpf_core_cand
walking-machine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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))) | ||
|
||
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)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of version 2 of the GNU General Public | ||
* License as published by the Free Software Foundation. | ||
*/ | ||
#include "vmlinux.h" | ||
|
||
#include <bpf/bpf_tracing.h> | ||
#include <bpf/bpf_core_read.h> | ||
#include <bpf/bpf_helpers.h> | ||
|
||
SEC("xdp") | ||
int xdp_meta_prog(struct xdp_md *ctx) | ||
{ | ||
struct xdp_meta_generic *data_meta = | ||
(void *)(long)ctx->data_meta; | ||
void *data_end = (void *)(long)ctx->data_end; | ||
void *data = (void *)(long)ctx->data; | ||
struct ethhdr *eth = data; | ||
u64 nh_off; | ||
u32 btf_id_libbpf; | ||
u32 btf_id_meta; | ||
u16 rxcvid; | ||
u32 hash; | ||
long *value; | ||
|
||
nh_off = sizeof(*eth); | ||
if (data + nh_off > data_end) | ||
return XDP_DROP; | ||
|
||
|
||
if (data_meta + 1 > data) | ||
return XDP_DROP; | ||
|
||
btf_id_libbpf = bpf_core_type_id_kernel(struct xdp_meta_generic); | ||
bpf_probe_read_kernel(&btf_id_meta, sizeof(btf_id_meta), (void*)data - 4); | ||
|
||
bpf_printk("id from libbpf %d, id from hints metadata %d\n", | ||
btf_id_libbpf, btf_id_meta); | ||
|
||
if (btf_id_libbpf == btf_id_meta) | ||
bpf_printk("Received meta is generic\n"); | ||
else | ||
bpf_printk("Received meta type is unknown\n"); | ||
|
||
|
||
hash = BPF_CORE_READ(data_meta, hash); | ||
rxcvid = BPF_CORE_READ(data_meta, rxcvid); | ||
bpf_printk("Metadata. Hash: 0x%x, VID: %d\n", hash, rxcvid); | ||
|
||
return XDP_PASS; | ||
} | ||
|
||
char LICENSE[] SEC("license") = "GPL"; |
Oops, something went wrong.
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.
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.
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.