-
Notifications
You must be signed in to change notification settings - Fork 306
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
Remove duplication, avoid handwritten assembly #1165
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. |
cc @Billy99 I believe the last commit fixes a bug on big-endian. PTAL. |
I was incorrect, the FD always goes in the first instruction, so there was no bug here. |
fb807e7
to
f939005
Compare
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.
Overall this is much better than what we had before. Encoding those bpf_insns must have take a while 😓 A few small things to consider but otherwise looks good.
aya/src/sys/bpf.rs
Outdated
|
||
let gpl = b"GPL\0"; | ||
let mov64_imm = (BPF_ALU64 | BPF_MOV | BPF_K).try_into().unwrap(); |
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.
Given we re-use this same program in many places, is there any benefit to making it const
?
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.
Maybe? But the constants are u32 and the field is u8 - without an as
cast there's no way to make it const IIUC.
u.insn_cnt = insns.len() as u32; | ||
u.insns = insns.as_ptr() as u64; | ||
u.prog_type = bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER as u32; | ||
u.prog_type = bpf_prog_type::BPF_PROG_TYPE_TRACEPOINT as u32; |
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 there a motivation to change the program type?
IIRC SOCKET_FILTER is the oldest of the BPF program types so should always be available.
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.
Yes, it's in the commit message.
Use
BPF_PROG_TYPE_TRACEPOINT
instead ofBPF_PROG_TYPE_SOCKET_FILTER
as the former seems to work with more feature detection functions.
is_perf_link_supported
didn't work when this was SOCKET_FILTER
.
aya/src/sys/bpf.rs
Outdated
|
||
let gpl = b"GPL\0"; | ||
u.license = gpl.as_ptr() as u64; | ||
// TODO(tamird): remove when these are generated on the userspace side. |
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.
Since #1166 has merged, please let me know if you need me to press the button on the codegen
workflow. You should be able to trigger it from Github Actions.
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, working on that in #1168 since the constants I wanted weren't all generated.
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.
Done. I was being blind.
u.map_name[..name_len] | ||
.copy_from_slice(unsafe { slice::from_raw_parts(name.as_ptr(), name_len) }); | ||
let name_bytes = name.to_bytes_with_nul(); | ||
let len = cmp::min(name_bytes.len(), u.map_name.len()); |
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.
Does this account for the nul
byte required to terminate the string?
The string has to be 15 chars + 1 nul byte.
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, note I'm using to_bytes_with_nul
.
The safety requirements of this transmutation are simpler.
Use `BPF_PROG_TYPE_TRACEPOINT` instead of `BPF_PROG_TYPE_SOCKET_FILTER` as the former seems to work with more feature detection functions.
See individual commits.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)