-
Notifications
You must be signed in to change notification settings - Fork 250
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: Maps live in maps section #248
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! ```cargo | ||
//! [dependencies] | ||
//! aya-bpf = { path = "../../../../bpf/aya-bpf" } | ||
//! ``` | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use aya_bpf::{ | ||
bindings::xdp_action, | ||
macros::{map, xdp}, | ||
programs::XdpContext, | ||
maps::Array, | ||
}; | ||
|
||
#[map] | ||
static mut FOO: Array<u32> = Array::<u32>::with_max_entries(10, 0); | ||
|
||
#[map(name = "BAR")] | ||
static mut BAZ: Array<u32> = Array::<u32>::with_max_entries(10, 0); | ||
|
||
#[xdp] | ||
pub fn pass(ctx: XdpContext) -> u32 { | ||
match unsafe { try_pass(ctx) } { | ||
Ok(ret) => ret, | ||
Err(_) => xdp_action::XDP_ABORTED, | ||
} | ||
} | ||
|
||
unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> { | ||
Ok(xdp_action::XDP_PASS) | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
unsafe { core::hint::unreachable_unchecked() } | ||
} |
Binary file not shown.
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,25 @@ | ||
#!/bin/sh | ||
# SUMMARY: Check that maps are correctly represented in ELF files | ||
# LABELS: | ||
|
||
set -ex | ||
|
||
# Source libraries. Uncomment if needed/defined | ||
#. "${RT_LIB}" | ||
. "${RT_PROJECT_ROOT}/_lib/lib.sh" | ||
|
||
NAME=map_test | ||
|
||
clean_up() { | ||
rm -rf ebpf user ${NAME}.o | ||
} | ||
|
||
trap clean_up EXIT | ||
|
||
# Test code goes here | ||
compile_ebpf ${NAME}.ebpf.rs | ||
|
||
readelf --sections ${NAME}.o | grep -q "maps" | ||
readelf --syms ${NAME}.o | grep -q "BAR" | ||
|
||
exit 0 |
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,36 @@ | ||
#!/bin/sh | ||
# SUMMARY: Tests to check ELF from aya-bpf | ||
# LABELS: | ||
|
||
# Source libraries. Uncomment if needed/defined | ||
# . "${RT_LIB}" | ||
. "${RT_PROJECT_ROOT}/_lib/lib.sh" | ||
|
||
set -e | ||
|
||
group_init() { | ||
# Group initialisation code goes here | ||
return 0 | ||
} | ||
|
||
group_deinit() { | ||
# Group de-initialisation code goes here | ||
return 0 | ||
} | ||
|
||
CMD=$1 | ||
case $CMD in | ||
init) | ||
group_init | ||
res=$? | ||
;; | ||
deinit) | ||
group_deinit | ||
res=$? | ||
;; | ||
*) | ||
res=1 | ||
;; | ||
esac | ||
|
||
exit $res |
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.
libbpf expects maps live in
.maps
section.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 only expects them in
.maps
BTF maps.But that being said, I think we need a way to specify it by using this macro.
I'm not suggesting it's the right PR to do this, it might be add as part of BTF map support.
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.
The legacy one is deprecated.
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.
The legacy,
bpf_map_def
style of map definition is the only style that we support inaya-bpf
right now.Not really. If we supported BTF defs, all maps would use BTF map defs.
I'm not sure if libbpf's deprecation notice means support will be removed from the kernel (I doubt it) or whether it's to give users a push to use BTF.
Anyhow, userspace support for BTF maps is proposed in #140 but still needs work.
Support in
aya-bpf
for BTF maps is sadly not as simple as the BTF generated for Rust programs by LLVM isn't correct.