-
Notifications
You must be signed in to change notification settings - Fork 298
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
Add support for stack argument #659
Conversation
❌ Deploy Preview for aya-rs-docs failed.Built without sensitive environment variables
|
can you paste the whole compiler output? it looks like you might have two different aya_bpf versions in your project |
Oh, yes. I see. |
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.
Add support for stack argument.
@alessandrod |
@tamird @vadorovsky |
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.
Please add a test.
let addr: __u64 = ctx.rsp + 8 * (n + 1) as __u64; | ||
bpf_probe_read(addr as *const T) | ||
.map(|v| &v as *const _) | ||
.ok() |
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.
Instead of .ok() can we just return the Result?
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.
I just follow from_argument
. It seems that .ok()
is more readable.
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's discarding information.
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's discarding information.
I'm confused. I know bpf_probe_read
returns Result
, and if from_stack_argument
returns Option
, Err
info may be lost.
But the existing from_argument
just return Option
. Should it be better to return Result
to save information or return Option
to adapt the style ?
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.
I'm not sure why the existing functions return Option
. In my opinion they should also return Result
. Perhaps @alessandrod knows something about the return value that I don't.
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.
Yeah, bpf_probe_read returns only 0 or -EFAULT, so it's not really discarding anything.
But I'll say that this from_argument
stuff is very involved - in the existing code I mean, not just in the PR, and needs to be reworked. Sadly I forgot how I'd rework it it's been a while :P
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.
if bpf_probe_read
only returns one of two values, should we wrap it and do the Result -> Option conversion there instead of everywhere it's used?
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 I'm inclined to say no.
My idea is we want to offer different levels of abstractions:
- Generated bindings that give you the original (unsafe) helpers API. This is useful when you want to call things for which we don't provide safe or higher level APIs yet.
- Safe wrappers for the generated helpers. These are still low level, but safe. We don't control these APIs, we just wrap them, and they're unstable so they might change.
bpf_probe_read
might start returning something else at some point (unlikely for the bpf_probe_read case specifically but possible for a more complex helper). Additionally, say I want to write an ebpf program without using any high level bits ofaya-ebpf
, I should be able to do so, and I should be able to build my abstractions on top of these foundational helpers. - We have our own API.
ProbeContext::arg
is an example. It internally uses bpf_probe_read, but that's an implementation detail. If bpf_probe_read starts returning something else, it's conceivable that we won't care at this level and we'll still return None; or if we do decide to return the inner error, we can deprecated the API and have::argument
or something, but we won't be as weird as having to deprecatebpf_probe_read
which technically we don't control we're just wrapping.
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.
Yeah, I wasn't suggesting changing the behavior of bpf_probe_read
, but as it stands we have a lot of .ok()
calls that I think we could centralize.
Any advice about the test? |
You can write a test that uses a |
@liyan-ah, this pull request is now in conflict and requires a rebase. |
moved to #773. |
Hi, I'm new in rust and eBPF. Here I want to add
sarg
support inaya
, and my code is in this PR. The code builds okay in my environment. But when I use it inuprobe
, and try to print message withaya-log-ebpf
, the following error comes:bpf
code:when I build:
Any one with any ideas? Much thanks.