Commit Graph

723 Commits (e16f0482f8aafabd65836570ff55293a0681b145)

Author SHA1 Message Date
Tamir Duberstein e16f0482f8 Revert "ci: remove cross toolchain"
Turns out this was actually being used through magic.

Remove mips since it is a tier 3 target that is only supported on
nightly and dtolnay/rust-toolchain doesn't seem to handle installing
targets without std.

Exclude xtask since it depends on `ring` which doesn't build on all
targets.

Fix compilation on armv7 which had rotted.

This reverts commit d92fc95c39.
2 weeks ago
Tamir Duberstein f0a9f19ddc Bump edition to 2024
Change FromRawTracepointArgs::arg to return T rather than *const T which
seems to have been returning a dangling pointer.

Arguably this is not strictly necessary; edition 2024 seems to be
focused on increased strictness around unsafe code which doesn't unlock
new functionality for our users. That said, this work revealed an
apparent bug (see above) that we wouldn't otherwise catch due to
allow-by-default lints.
2 weeks ago
Tamir Duberstein ea5f7e3015 Reduce the scope of expected warnings
This fixes a few safety comments to avoid the warnings.
2 weeks ago
Tamir Duberstein 4101a5a55d Use #[expect(...)] rather than #[allow(...)]
This is stricter, and revealed a few unused allowances.
2 weeks ago
Tamir Duberstein 27d69c35f0 aya: remove panics on indeterminate kernel version
Cache the current kernel version in a thread-local while I'm here.

Closes https://github.com/aya-rs/aya/issues/1024.
Closes https://github.com/aya-rs/aya/pull/1042.
2 weeks ago
Tamir Duberstein 9eefb48a0a aya: remove some copies
Replace truncation with proper NULL termination at the site of use.
2 weeks ago
Tamir Duberstein 89aa638e05 aya: add TODO to remove once_cell 2 weeks ago
Tamir Duberstein de1e80c1d1 aya: encode perf_event ioctl contract
Enumerate the possible ioctls in an enum and bake in the knowledge that
they all return 0 on success and -1 on error.
2 weeks ago
Tamir Duberstein eee7975ce4 aya: remove redundant TEST_SYSCALL use
This is already done in `syscall`.
2 weeks ago
Tamir Duberstein 055e36e8d9 aya: encode perf_event_open(2) contract
Per man 2 perf_event_open:

> RETURN VALUE
>   On success, perf_event_open() returns the new file descriptor.  On
>   error, -1 is returned and errno is set to indicate the error.

Bake this into our syscalls so we stop using `_` so much which can hide
information loss. Remove the type parameter to SysResult.
2 weeks ago
Tamir Duberstein bdd8ae2d0b *: avoid `_`
This can silently discard information, so we shouldn't do it.
2 weeks ago
Tamir Duberstein f6df60fa70 aya: encode bpf(2) contract
Per man 2 bpf:

> RETURN VALUE
>   For a successful call, the return value depends on the operation:
>
>   BPF_MAP_CREATE
>     The new file descriptor associated with the eBPF map.
>
>   BPF_PROG_LOAD
>     The new file descriptor associated with the eBPF program.
>
>   All other commands
>     Zero.
>
>   On error, -1 is returned, and errno is set to indicate the error.

Bake this into our syscalls so we stop using `_` so much which can hide
information loss.
2 weeks ago
Tamir Duberstein 2d782606fe *: avoid Result::is_{ok,err}
These methods discard information. Discarding information is bad.
2 weeks ago
Tamir Duberstein dab1aa4e29 maps: avoid retagging in tests 2 weeks ago
Tamir Duberstein f51ab80075 perf_buffer: attempt to preserve provenance
In tests, provide write provenance.
2 weeks ago
Tamir Duberstein 888701425b perf_buffer: use MMap from ring_buf 2 weeks ago
Tamir Duberstein ff82c244f7 netlink: avoiding casting pointers to usize 2 weeks ago
Tamir Duberstein e17feca2d6 maps: remove some stale comments 2 weeks ago
Tamir Duberstein 935ba20224 Enable test under miri
nr_cpus() is stubbed since 9e1bcd0ab8.
2 weeks ago
Tamir Duberstein 9a47495227 aya,aya-obj: preserve pointer provenance 2 weeks ago
Tamir Duberstein 122c49fca4 *: appease clippy
While I'm here convert a String to a PathBuf in an error to avoid lossy
conversions.

See https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error.
2 weeks ago
aorhant 9e1bcd0ab8 aya: Fix PerCpuHashMap NotFound
PerCpuHashMap was never returning MapError::KeyNotFound because
bpf_map_lookup_elem_per_cpu was replacing Ok(None) with
Ok(Some(zeroed_value)).

Update bpf_map_lookup_elem_per_cpu to map the Option value.
2 weeks ago
Tamir Duberstein 9198335100 codegen: remove outdated workaround
bindgen can handle these macros now.
1 month ago
Tamir Duberstein 942ea51906 Avoid handwritten assembly 1 month ago
Tamir Duberstein 8ea11ef9e8 Remove duplication
Use `BPF_PROG_TYPE_TRACEPOINT` instead of `BPF_PROG_TYPE_SOCKET_FILTER`
as the former seems to work with more feature detection functions.
1 month ago
Tamir Duberstein b010b0f028 Avoid raw slice construction
The safety requirements of this transmutation are simpler.
1 month ago
Tyrone Wu 665d4f20bb chore: remove aya_obj -> obj alias
When `aya::obj` was migrated to be its own crate `aya-obj`, the `obj`
alias was created to preserve existing imports that relied on
`crate::obj`.

This resulted in 3 ways to import `aya-obj` objects:
- `use aya_obj::*`
- `use obj::*`
- `use crate::obj::*`

The `obj` alias is now removed to avoid confusion, and all `obj` imports
are funneled through `aya_obj`.
1 month ago
Dave Tucker 39cf6c12f2 feat(aya): Return error messages from netlink
This returns error strings from netlink since they are more informative
than the raw os error. For example:

"Device or Resource Busy" vs. "XDP program already attached".

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 month ago
Tamir Duberstein 0429ed2fa2 Appease clippy
```
error: manual implementation of `ok`
   --> aya/src/util.rs:261:28
    |
261 |                   let addr = match u64::from_str_radix(addr, 16) {
    |  ____________________________^
262 | |                     Ok(addr) => Some(addr),
263 | |                     Err(ParseIntError { .. }) => None,
264 | |                 }?;
    | |_________________^ help: replace with: `u64::from_str_radix(addr, 16).ok()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:1705:44
     |
1705 |             section: ProgramSection::KProbe { .. },
     |                                            ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern
note: the lint level is defined here
    --> aya-obj/src/lib.rs:68:9
     |
68   | #![deny(clippy::all, missing_docs)]
     |         ^^^^^^^^^^^
     = note: `#[deny(clippy::unneeded_struct_pattern)]` implied by `#[deny(clippy::all)]`

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:1769:44
     |
1769 |             section: ProgramSection::KProbe { .. },
     |                                            ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:1787:44
     |
1787 |             section: ProgramSection::KProbe { .. },
     |                                            ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:1919:48
     |
1919 |                 section: ProgramSection::KProbe { .. },
     |                                                ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2041:52
     |
2041 |                 section: ProgramSection::TracePoint { .. },
     |                                                    ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2058:52
     |
2058 |                 section: ProgramSection::TracePoint { .. },
     |                                                    ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2081:54
     |
2081 |                 section: ProgramSection::SocketFilter { .. },
     |                                                      ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2151:55
     |
2151 |                 section: ProgramSection::RawTracePoint { .. },
     |                                                       ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2168:55
     |
2168 |                 section: ProgramSection::RawTracePoint { .. },
     |                                                       ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2243:55
     |
2243 |                 section: ProgramSection::BtfTracePoint { .. },
     |                                                       ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2266:59
     |
2266 |                 section: ProgramSection::SkSkbStreamParser { .. },
     |                                                           ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2289:59
     |
2289 |                 section: ProgramSection::SkSkbStreamParser { .. },
     |                                                           ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2410:58
     |
2410 |                 section: ProgramSection::CgroupSkbIngress { .. },
     |                                                          ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2433:58
     |
2433 |                 section: ProgramSection::CgroupSkbIngress { .. },
     |                                                          ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2456:51
     |
2456 |                 section: ProgramSection::CgroupSkb { .. },
     |                                                   ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: struct pattern is not needed for a unit variant
    --> aya-obj/src/obj.rs:2479:51
     |
2479 |                 section: ProgramSection::CgroupSkb { .. },
     |                                                   ^^^^^^^ help: remove the struct pattern
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_struct_pattern

error: manual implementation of `ok`
   --> aya-log-common/src/lib.rs:168:36
    |
168 |       let wire_len: LogValueLength = match value.len().try_into() {
    |  ____________________________________^
169 | |         Ok(wire_len) => Some(wire_len),
170 | |         Err(TryFromIntError { .. }) => None,
171 | |     }?;
    | |_____^ help: replace with: `value.len().try_into().ok()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err

error: manual implementation of `err`
   --> init/src/main.rs:141:30
    |
141 |           .filter_map(|result| match result {
    |  ______________________________^
142 | |             Ok(()) => None,
143 | |             Err(err) => Some(err),
144 | |         })
    | |_________^ help: replace with: `result.err()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err

error: manual implementation of `err`
  --> xtask/src/public_api.rs:80:30
   |
80 |           .filter_map(|result| match result {
   |  ______________________________^
81 | |             Ok(()) => None,
82 | |             Err(err) => Some(err),
83 | |         })
   | |_________^ help: replace with: `result.err()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_err
```
1 month ago
Tamir Duberstein 356cf45914 Use Set (instead of Map) to hold links
This uses hashbrown instead of std because the latter relies on Borrow
which requires a reference; hashbrown's Equivalent is more flexible.
2 months ago
Tamir Duberstein 69144a977e Appease clippy
```
error: called `Iterator::last` on a `DoubleEndedIterator`; this will needlessly iterate the entire iterator
   --> aya/src/programs/uprobe.rs:282:64
    |
282 |             let path = line.split(|b| b.is_ascii_whitespace()).last()?;
    |                                                                ^^^^^^ help: try: `next_back()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_ended_iterator_last
```
2 months ago
Andrew Werner 628b7fb022 aya::programs::uprobe: add support for cookies
Fixes #1132.

Note that this change does not add support in the public API for kprobes
or tracepoints, but it's a trivial matter of plumbing.

Along the way, the Uprobe::attach API is cleaned up to make the
attachment location more coherent. The logic being: if we're going to be
breaking the API anyway, may as well clean it up a bit.

Furthermore, the aya::sys::bpf_link_attach function is cleaned up by
properly modeling the the union in the final field with a rust enum.
2 months ago
Noah Kennedy df053f095b
docs: update docs for load to mention include_bytes_aligned (#1119)
* docs: update docs for load to mention include_bytes_aligned

This macro is required if you are bundling programs statically into your binary, which is not an uncommon thing to do.

This change updates the documentation for the load function to mention this macro and the need for alignment.
3 months ago
Tamir Duberstein 78ee9a4634 Avoid useless conversions
Use native C types to avoid platform-dependent conversions.
3 months ago
Tamir Duberstein 4257643354 Clean up C type imports 3 months ago
Tamir Duberstein 41706d74e4 Narrow clippy allowances 3 months ago
Michal Rostecki 4f0559f2af chore: Fix cippy errors 3 months ago
Tamir Duberstein 119049f2a2 Define `{detach,take_link}` in macro when possible 4 months ago
Michal Rostecki 85c73af1fe doc(aya): Improve the description of `take_link` methods
Don't mix the tenses.
4 months ago
Michal Rostecki bf2164c92f feat(aya): Add iterator program type
BPF iterators[0] are a way to dump kernel data into user-space and an
alternative to `/proc` filesystem.

This change adds support for BPF iterators on the user-space side. It
provides a possibility to retrieve the outputs of BPF iterator programs
both from sync and async Rust code.

[0] https://docs.kernel.org/bpf/bpf_iterators.html
4 months ago
Tamir Duberstein a77db17ec8 cargo fmt 4 months ago
banditopazzo a16755089b Avoid warning with `allow_unsupported_maps`
Remove the warning log altogether; either it's an error or it isn't.
4 months ago
Dave Tucker 2791badd94 Release aya v0.13.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 months ago
Dave Tucker c6a34cade1 Release aya-obj v0.2.1
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 months ago
Dave Tucker ca0c32d107 fix(aya): Fill bss maps with zeros
The loader should fill bss maps with zeros according to the size of the
ELF section.
Failure to do so yields weird verifier messages as follows:

```
cannot access ptr member ops with moff 0 in struct bpf_map with off 0 size 4
```

Reference to this in the cilium/ebpf code is here [1].
I could not find a reference in libbpf.

1: d0c8fc1937/elf_reader.go (L1159-L1165)

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 months ago
Dave Tucker c169b727e6 Release aya-obj v0.2.0, aya v0.13.0, safety bump aya v0.13.0
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
5 months ago
astoycos 5478cac008 feat(aya): Implement TCX
This commit adds the initial support for TCX
bpf links. This is a new, multi-program, attachment
type allows for the caller to specify where
they would like to be attached relative to other
programs at the attachment point using the LinkOrder
type.

Signed-off-by: astoycos <astoycos@redhat.com>
Co-authored-by: Andre Fredette <afredette@redhat.com>
Co-authored-by: Dave Tucker <dave@dtucker.co.uk>
Co-authored-by: Tamir Duberstein <tamird@gmail.com>
5 months ago
Vladimir Petrzhikovskii d05110fd86 perf: cache `nr_cpus` in a thread_local 5 months ago
Tamir Duberstein afd777b705 Clarify `Arc` usage
Absent this it's easy to miss that there's an `Arc` being cloned here.
5 months ago
Tamir Duberstein e992c280cb Replace `Arc` with `&'static` 5 months ago