-
Notifications
You must be signed in to change notification settings - Fork 276
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
feat(aya-ebpf): Implement memmove #971
Conversation
✅ Deploy Preview for aya-rs-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
I'm actually quite surprised that rust compiler-builtins don't optimize this implementation somehow (by loading bigger chunks and reducing iterations). I think in eBPF we could load with |
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.
Thanks a lot for the change! 🙏
Could you write a small integration tests which uses memmove? Scrolling back in Discord, I see that your motivation behind this is being able to do
unsafe { (*ip_hdr).dst_addr.in6_u.u6_addr8 = new_ip };
As it was resulting in a verifier error. I think it would be nice to have a test for that.
It wasn't immediately clear to me where to add tests for this, which is why they're absent. I'll take a stab at writing an integration test. |
I think if you are able to write a small program which triggers the error on your kernel, it's almost certainly going to be a reliable reproduces. Just avoid Happy to help with the integration test. The first step would be adding an https://github.com/aya-rs/aya/tree/main/test/integration-ebpf/src Then including it here as a https://github.com/aya-rs/aya/blob/main/test/integration-ebpf/Cargo.toml And writing a test on the user-space side. I think in your case just loading the program would be totally sufficient, no need to do any other actions. https://github.com/aya-rs/aya/blob/main/test/integration-test/src/tests/load.rs#L285 I would literally just try something like: #[test]
fn memmove() {
let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut SchedClassifier = bpf
.program_mut("test_memmove")
.unwrap()
.try_into()
.unwrap();
prog.load().unwrap();
assert_loaded("test_memmove"); I assumed |
4f23afa
to
437a5a0
Compare
I have added an integration test, and simplified the implementation of I have copy/pasted some struct definitions from |
Awesome, that's exactly what I had in mind. 🙂
What's exactly the error?
I think I would be fine with adding a dependency on the library, it doesn't have any dependencies by default. |
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 lint
job is failing, because of public API changes.
@wdullaer Can you run cargo xtask public-api --bless
and commit the result (preferably as a separate commit)? Also, before doing so, make sure you rebase.
I also have a slight preference towards importing the network-types crate instead of copying the types. I don't think it's going to make the build significantly slower. @alessandrod do you agree?
Otherwise, it looks very good, thanks for working on this! 🙏
437a5a0
to
d0c8eaf
Compare
I checked the assembly of the version with memmove implemented and I can clearly see the function implementation in the assembly. So I'm certain the test exercises the code. I added the network-types crate as a dependency and ran the bless task (this target does not work on macos btw). One final note: |
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.
Amazing stuff, looks good!
I'm fine with keeping *mut u8
(for consistency with the compiler-builtins impl and so).
You'll need to rebase to fix the integration test failures. |
@wdullaer Lint errors look legit. The integration test errors should be gone after a rebase. |
The compiler will emit this function for certain operations, but aya currently does not provide an implementation. This leads to ebpf loading failures as the kernel can't find the symbol when loading the program. The implementation is based on https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/mod.rs#L29-L40 and https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/impls.rs#L128-L135 Only the simplest case has been implemented, none of the word optimizations, since memcpy also doesn't seem to have them.
57ce338
to
ad38382
Compare
ad38382
to
fad75de
Compare
I'm sorry about the lint failures. |
The compiler will emit this function for certain operations, but aya currently does not provide an implementation.
This leads to ebpf loading failures as the kernel can't find the symbol when loading the program.
The implementation is based on https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/mod.rs#L29-L40 and https://github.com/rust-lang/compiler-builtins/blob/master/src/mem/impls.rs#L128-L135 Only the simplest case has been implemented, none of the word optimizations, since memcpy also doesn't seem to have them.