Commit Graph

89 Commits (1634fa7188e40ed75da53517f1fdb7396c348c34)

Author SHA1 Message Date
tyrone-wu 1634fa7188
aya-obj: add conversion u32 to enum type for prog, link, & attach type
Add conversion from u32 to program type, link type, and attach type.
Additionally, remove duplicate match statement for u32 conversion to
`BPF_MAP_TYPE_BLOOM_FILTER` & `BPF_MAP_TYPE_CGRP_STORAGE`.

New error `InvalidTypeBinding<T>` is created to represent when a
parsed/received value binding to a type is invalid.
This is used in the new conversions added here, and also replaces
`InvalidMapTypeError` in `TryFrom` for `bpf_map_type`.
2 months ago
tyrone-wu cb8e478800
aya,integration-test: improve integration tests for info API
Improves the existing integraiton tests for `loaded_programs()` and
`loaded_maps()` in consideration for older kernels:
  - Opt for `SocketFilter` program in tests since XDP requires v4.8 and
    fragments requires v5.18.
  - For assertion tests, first perform the assertion, if the assertion
    fails, then it checks the host kernel version to see if it is above
    the minimum version requirement. If not, then continue with test,
    otherwise fail.
    For assertions that are skipped, they're logged in stderr which can
    be observed with `-- --nocapture`.

This also fixes the `bpf_prog_get_info_by_fd()` call for kernels below
v4.15. If calling syscall  on kernels below v4.15, it can produce an
`E2BIG` error  because `check_uarg_tail_zero()` expects the entire
struct to all-zero bytes (which is caused from the map info).

Instead, we first attempt the syscall with the map info filled, if it
returns `E2BIG`, then perform syscall again with empty closure.

Also adds doc for which version a kernel feature was introduced for
better  awareness.

The tests have been verified kernel versions:
  - 4.13.0
  - 4.15.0
  - 6.1.0
2 months ago
tyrone-wu a25f501ece
aya: expose run_time_ns and run_cnt fields in ProgramInfo
Added functions to expose `run_time_ns` & `run_cnt` statistics from
ProgramInfo/bpf_prog_info.
3 months ago
tyrone-wu fa6af6a204
aya,aya-obj: add BPF_ENABLE_STATS syscall function
Add bpf syscall function for BPF_ENABLE_STATS to enable stats tracking
for benchmarking purposes.

Additionally, move `#[cfg(test)]` annotation around the `Drop` trait
instead. Having separate functions causes some complications when
needing ownership/moving of the inner value `OwnedFd` when `Drop` is
manually implemented.
3 months ago
Tamir Duberstein 23ece3d794 public-api: regenerate
See https://github.com/rust-lang/rust/pull/126877, I think.
3 months ago
Dave Tucker 9a138870f3 chore(xtask): Bless API changes
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Dave Tucker 3d57d358e4 fix(aya): Fix PerfEventArray resize logic
There was a logic bug in the previously merged patch where we
set the correctly calculated max_entries size with the original.

To fix this and prevent regressions a unit test was added.
This highlighted that the original map definition needs to be
mutated in order for the max_entries change to be properly applied.

As such, this resize logic moved out of aya::sys into aya::maps

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Dave Tucker ef0d1253ef fix(ebpf): Remove PerfEventArray::with_max_entries
This API doesn't make sense as the max_entries needs to be set to the
number of online CPUs by the loader.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
3 months ago
Michal Rostecki 6dab7176f5 chore: Bless public API 4 months ago
dave-tucker 8d7446e011 [codegen] Update libbpf to 686f600bca59e107af4040d0838ca2b02c14ff50
Update libbpf to 686f600bca59e107af4040d0838ca2b02c14ff50

Files changed:
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
M	aya-obj/src/generated/linux_bindings_powerpc64.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
M	aya-obj/src/generated/linux_bindings_s390x.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 months ago
Wouter Dullaert b8a22fa040 feat(aya-ebpf): Add memmove to the public-api 4 months ago
dependabot[bot] d581431d9a
build(deps): update public-api requirement in the cargo-crates group
Updates the requirements on [public-api](https://github.com/Enselic/cargo-public-api) to permit the latest version.

Updates `public-api` to 0.35.1
- [Release notes](https://github.com/Enselic/cargo-public-api/releases)
- [Changelog](https://github.com/Enselic/cargo-public-api/blob/main/rustdoc-json/CHANGELOG.md)
- [Commits](https://github.com/Enselic/cargo-public-api/compare/public-api-v0.35.0...public-api-v0.35.1)

---
updated-dependencies:
- dependency-name: public-api
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
4 months ago
dave-tucker 8b50a6a573 [codegen] Update libbpf to c1a6c770c46c6e78ad6755bf596c23a4e6f6b216
Update libbpf to c1a6c770c46c6e78ad6755bf596c23a4e6f6b216

Files changed:
M	aya-obj/src/generated/linux_bindings_aarch64.rs
M	aya-obj/src/generated/linux_bindings_armv7.rs
A	aya-obj/src/generated/linux_bindings_powerpc64.rs
M	aya-obj/src/generated/linux_bindings_riscv64.rs
A	aya-obj/src/generated/linux_bindings_s390x.rs
M	aya-obj/src/generated/linux_bindings_x86_64.rs
M	ebpf/aya-ebpf-bindings/src/aarch64/bindings.rs
M	ebpf/aya-ebpf-bindings/src/armv7/bindings.rs
A	ebpf/aya-ebpf-bindings/src/powerpc64/bindings.rs
A	ebpf/aya-ebpf-bindings/src/powerpc64/helpers.rs
M	ebpf/aya-ebpf-bindings/src/riscv64/bindings.rs
A	ebpf/aya-ebpf-bindings/src/s390x/bindings.rs
A	ebpf/aya-ebpf-bindings/src/s390x/helpers.rs
M	ebpf/aya-ebpf-bindings/src/x86_64/bindings.rs

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
4 months ago
Tamir Duberstein bfafe9e786 public-api: regenerate
See https://github.com/rust-lang/rust/commit/ec201b86.
5 months ago
Tamir Duberstein 35aa9ac1a5 public-api: regenerate
See https://github.com/Enselic/cargo-public-api/pull/584.

Constant values are no longer considered part of the API.
5 months ago
Alessandro Decina a2c8fcab4e aya: bless API changes
The equivalent crate has a blanket implementation smh. We don't depend
on it directly it's pulled in by the object crate.
6 months ago
Tamir Duberstein a11b61ebfd s/MiriSafeFd/MockableFd/
The need for this type isn't specific to Miri; it is necessary on
toolchains containing https://github.com/rust-lang/rust/pull/124210 - it
just so happens that today this is nightly only, and so is Miri.
6 months ago
Tamir Duberstein 7a7d16885a Avoid crashing under Miri
See https://github.com/rust-lang/rust/pull/124210.
6 months ago
Alessandro Decina 60abea54ce chore(aya-log): bless API 7 months ago
tyrone-wu 1cf3d3c222 public-api: added new api for RetProbeContext 7 months ago
Tamir Duberstein b21f2a1945 Mark aya-tool publish=false
This is for internal use, get it off the API treadmill.
7 months ago
Tamir Duberstein 73751fb878 public-api: regenerate
See https://github.com/rayon-rs/either/pull/101.
7 months ago
Tamir Duberstein 80920ddf3f public-api: regenerate
This is roughly a revert of af1a9b39112a8341ef049c8697bed3350e76f2f1;
see https://github.com/rust-lang/rust/pull/123638.
7 months ago
Kevin Ji df9fe94216 xtask: Bless public-api changes 7 months ago
Tamir Duberstein af1a9b3911 public-api: regenerate
Auto trait bounds have changed in one of:
- https://github.com/rust-lang/rust/pull/123340.
- https://github.com/rust-lang/rust/pull/123375.
7 months ago
Tamir Duberstein 0a32dacd2f Appease clippy
```
  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:198:57
      |
  198 |     pub fn btf(&mut self, btf: Option<&'a Btf>) -> &mut EbpfLoader<'a> {
      |                                                         ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self
  note: the lint level is defined here
     --> aya/src/lib.rs:42:5
      |
  42  |     clippy::use_self,
      |     ^^^^^^^^^^^^^^^^

  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:222:54
      |
  222 |     pub fn allow_unsupported_maps(&mut self) -> &mut EbpfLoader<'a> {
      |                                                      ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:243:69
      |
  243 |     pub fn map_pin_path<P: AsRef<Path>>(&mut self, path: P) -> &mut EbpfLoader<'a> {
      |                                                                     ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:292:15
      |
  292 |     ) -> &mut EbpfLoader<'a> {
      |               ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:313:73
      |
  313 |     pub fn set_max_entries(&mut self, name: &'a str, size: u32) -> &mut EbpfLoader<'a> {
      |                                                                         ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:335:56
      |
  335 |     pub fn extension(&mut self, name: &'a str) -> &mut EbpfLoader<'a> {
      |                                                        ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

  error: unnecessary structure name repetition
     --> aya/src/bpf.rs:353:75
      |
  353 |     pub fn verifier_log_level(&mut self, level: VerifierLogLevel) -> &mut EbpfLoader<'a> {
      |                                                                           ^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self
```

See https://github.com/rust-lang/rust-clippy/pull/12386.
8 months ago
Tamir Duberstein c302f8370d public-api: regenerate
Nightly now exposes `core::marker::Freeze`.

https://github.com/rust-lang/rust/pull/121840
8 months ago
Dave Tucker 715e62dd38 chore(aya): Bless public API
Bless the BpfError type alias

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
8 months ago
Dave Tucker d0c244356f chore: Bless public API changes
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
8 months ago
Gary Guo 542306d295 Add `CgroupDevice::query`
This follows closely the existing `LircMode2::query`.
8 months ago
Alessandro Decina f491f56204 aya: bless API 9 months ago
Alessandro Decina 0f6a734392 aya: perf_event: add inherit argument to attach() 10 months ago
Alessandro Decina 92b1947885 aya: add StackTraceMap::remove() 10 months ago
Tamir Duberstein 057f27dc20 public-api: regenerate
StructuralEq has been removed.

See 0df7810734.
10 months ago
Tamir Duberstein 1edd42aa0a
public-api: regenerate
`Send + Sync` became `Sync + Send` for reasons I don't understand.
10 months ago
Alessandro Decina e1aefa4e87 aya: bless API change 10 months ago
dependabot[bot] b3ec33e763
build(deps): update public-api requirement from 0.32.0 to 0.33.1
Updates the requirements on [public-api](https://github.com/Enselic/cargo-public-api) to permit the latest version.
- [Release notes](https://github.com/Enselic/cargo-public-api/releases)
- [Changelog](https://github.com/Enselic/cargo-public-api/blob/main/rustdoc-json/CHANGELOG.md)
- [Commits](https://github.com/Enselic/cargo-public-api/compare/v0.32.0...v0.32.0)

---
updated-dependencies:
- dependency-name: public-api
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
11 months ago
astoycos b1769678f4 aya/maps: pin for (async)perf_event_array
Implement pinning for perf_event_array and async_perf_event_array.
Additionally make the core MapData.pin method operate on a reference
rather than a mutable reference.

Signed-off-by: astoycos <astoycos@redhat.com>
12 months ago
Andrew Werner c06fcc3eda maps/ringbuf: make RingBuf: Send + Sync
There was no reason for them not to be -- the APIs all require mutable
references and hold onto mutable references, so there cannot be internal
concurrency. The !Send + !Sync came from the MMap, but not for any good
reason.
12 months ago
Adam Preuss 4d24d1cfe8 aya: add MapInfo struct following the same pattern as ProgramInfo
This makes the APIs for loading maps and programs more similar.
12 months ago
Adam Preuss 36420d9297 aya: support loading a map by fd
This adds support to loading maps by fd similarly to the way programs
can be loaded by fd.
12 months ago
Andrés Medina 68ba02002f aya: make KernelVersion::code public 12 months ago
Tamir Duberstein 6e256fad5b public-api: bless with new nightly
See https://github.com/rust-lang/rust/commit/58a80c85b9323e59e1b7e744d6.
1 year ago
dependabot[bot] c89b2d156d
build(deps): update async-io requirement from 1.3 to 2.0
Updates the requirements on [async-io](https://github.com/smol-rs/async-io) to permit the latest version.
- [Release notes](https://github.com/smol-rs/async-io/releases)
- [Changelog](https://github.com/smol-rs/async-io/blob/master/CHANGELOG.md)
- [Commits](https://github.com/smol-rs/async-io/compare/v1.3.0...v1.13.0)

---
updated-dependencies:
- dependency-name: async-io
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
1 year ago
Andrew Werner e2cf734490 aya: Implement RingBuf
This implements the userspace binding for RingBuf.

Instead of streaming the samples as heap buffers, the process_ring
function takes a callback to which we pass the event's byte region,
roughly following [libbpf]'s API design. This avoids a copy and allows
marking the consumer pointer in a timely manner.

[libbpf]: https://github.com/libbpf/libbpf/blob/master/src/ringbuf.c

Additionally, integration tests are added to demonstrate the usage
of the new APIs and to ensure that they work end-to-end.

Co-authored-by: William Findlay <william@williamfindlay.com>
Co-authored-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
1 year ago
Andrew Werner b73c0a46f5
aya: impl From<obj::InvalidMapTypeError> for MapTypeError 1 year ago
Tamir Duberstein 5cdd1baf29
aya: import types from std::ffi rather than libc 1 year ago
astoycos 7b71c7e1cd aya/maps: add pin() api
- Adds new `maps_mut()` API to the BpfManager to allow us to iterate though
and pin all of maps at the same time.

- Adds new pin(Path)/unpin(Path) api to Maps so they
can be generically pinned AFTER load.

- Adds macro for pinning explicit map types in aya.
Convert all explicit map types "inner" field to be
pub crate in order to facilitate this.

Signed-off-by: astoycos <astoycos@redhat.com>
1 year ago
Tuetuopay 0edc13b4d4 bpf: add a shared try_redirect_map function for XDP maps 1 year ago
Tuetuopay 579e3cee22 aya, bpf: misc fixes following review comments 1 year ago