Commit Graph

331 Commits

Author SHA1 Message Date
vad
211bb0da9e maps: Add integration test for BloomFilter 2026-02-16 18:19:28 +00:00
vad
8962fc79c1 aya-ebpf: Use i32 as a type for eBPF helper return codes
The helpers always return a signed 64-bit r0 value, but the JIT that
translates eBPF into native instructions differs by architecture. On
x86_64 the generated code writes the helper result into a 64-bit
register, so the CPU sign-extends negative errnos automatically. On
aarch64 the JIT frequently uses 32-bit operations (w0) when copying the
helper return and only zero-extends into the upper half of x0.

That results in broken errno codes on aarch64. For example, when a map
operation returns `-ENOENT`, which is supposed to be -2, the i64
representation yields something like `0x0000_0000_FFFF_FFFE`
(4294967294) instead of -2. In short: the ARM64 JIT doesn’t preserve the
sign in the upper half of the 64-bit register, and the error code has to
be cast to a 32-bit integer to make the sign visible.

This makes it awkward for users, because that behavior prevents simply
comparing helper error codes with constants like `libc::ENOENT` without
manual casts.

Given that the maximum error code limit `MAX_ERRNO` in the kernel is
4095, which fits in a 32-bit integer, coerce the error codes to be `i32`
and make all helpers return `Result<T, i32>`.
2026-02-16 18:19:28 +00:00
dependabot[bot]
baa7ddb381 build(deps): bump the cargo-crates group with 2 updates
Updates the requirements on [libbpf-rs](https://github.com/libbpf/libbpf-rs) and [rand](https://github.com/rust-random/rand) to permit the latest version.

Updates `libbpf-rs` to 0.26.0
- [Release notes](https://github.com/libbpf/libbpf-rs/releases)
- [Commits](https://github.com/libbpf/libbpf-rs/compare/v0.25.0...v0.26.0)

Updates `rand` to 0.10.0
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/rand_core-0.9.1...0.10.0)

---
updated-dependencies:
- dependency-name: libbpf-rs
  dependency-version: 0.26.0
  dependency-type: direct:production
  dependency-group: cargo-crates
- dependency-name: rand
  dependency-version: 0.10.0
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
2026-02-09 16:09:10 -05:00
Tamir Duberstein
2f8759cc62 Dial the lints to 100 2026-01-29 10:02:48 -05:00
root
5cfe609872 integration-test: add btf_maps libbpf compatibility tests
Add integration tests to verify that btf_maps generated with the
generalized btf_map_def macro are compatible with libbpf's bpf_map_def.

Also add CI infrastructure for macOS cross-compilation to Linux musl,
including stub headers and autoconf cache variables for libbpf-sys
vendored dependencies.
2026-01-27 14:49:22 +00:00
Tamir Duberstein
e746618143 enable unused_qualifications lint 2026-01-23 11:03:26 -05:00
Lukas Hoehl
d022b8dce4 set value_size to 0 if loading ringbuffer (#1443)
Override ring buffer value_size to 0 to allow slightly malformed 
programs to load. This is the same approach taken by Cillium.

Signed-off-by: Lukas Hoehl <lukas.hoehl@stackit.cloud>
2026-01-16 19:07:39 -05:00
Tamir Duberstein
3eb9cacef4 aya-ebpf: add BTF ring buffer
Co-developed-by: Lukas Hoehl <lukas.hoehl@stackit.cloud>
2026-01-13 05:43:45 -05:00
Sven Cowart
7cbd816a77 doc(aya): document tcx link pinning for atomic program replacement
Add documentation and integration test for SchedClassifier link pinning,
which enables zero-downtime program updates in production environments.

- Add link pinning example to SchedClassifier::attach_with_options()
  showing atomic replacement workflow for TCX mode (kernel >= 6.6).
- Add pin_tcx_link() integration test verifying link persistence
  across program unload and atomic replacement capability.
2026-01-06 20:18:26 -05:00
Tamir Duberstein
a9945b0957 xtask: implement unit tests in VM
This is quite useful when developing on macOS.
2025-12-31 05:01:43 -05:00
swananan
eb99da3cbb uprobe: bundle attach location+cookie via UProbeAttachPoint
This follows the #1417 review discussion: by bundling location
+ cookie into a UProbeAttachPoint we get a more idiomatic Into<_>
entry point, keep the one-to-one relationship enforced by the type
system, and make it easier to extend attach with multi-location
support without introducing parallel arrays or a brand new API.
2025-12-23 18:22:42 +01:00
Tamir Duberstein
5bf66d6127 integration-test: appease clippy
Before this change:
```
warning: manual saturating arithmetic
   --> test/integration-test/src/tests/ring_buf.rs:235:9
    |
235 | /         data.len()
236 | |             .checked_sub(RING_BUF_MAX_ENTRIES - 1)
237 | |             .unwrap_or_default(),
    | |________________________________^ help: consider using `saturating_sub`: `data.len().saturating_sub(RING_BUF_MAX_ENTRIES - 1)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
    = note: `-W clippy::manual-saturating-arithmetic` implied by `-W clippy::all`
    = help: to override `-W clippy::all` add `#[allow(clippy::manual_saturating_arithmetic)]`

warning: manual saturating arithmetic
   --> test/integration-test/src/tests/ring_buf.rs:244:20
    |
244 |     let min_seen = max_seen.checked_sub(max_dropped).unwrap_or_default();
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `max_seen.saturating_sub(max_dropped)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic

warning: manual saturating arithmetic
   --> test/integration-test/src/tests/ring_buf.rs:245:24
    |
245 |     let min_rejected = max_rejected.checked_sub(dropped).unwrap_or_default();
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `max_rejected.saturating_sub(dropped)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic

warning: `integration-test` (lib test) generated 3 warnings (run `cargo clippy --fix --lib -p integration-test --tests` to apply 3 suggestions)
```
2025-12-16 10:05:38 +01:00
Tamir Duberstein
28ae4b9826 test: properly spell "dependency" 2025-12-10 12:03:13 -05:00
Tamir Duberstein
d238b2ea6f Release crates
- aya v0.13.2
- aya-build v0.1.3
- aya-ebpf v0.1.2
- aya-ebpf-bindings v0.1.2
- aya-ebpf-cty v0.2.3
- aya-ebpf-macros v0.1.2
- aya-log v0.2.2
- aya-log-common v0.1.16
- aya-log-ebpf v0.1.2
- aya-log-ebpf-macros v0.1.1
- aya-log-parser v0.1.14
- aya-obj v0.2.2

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
2025-11-17 14:51:14 -05:00
Tamir Duberstein
72810f095f aya: ProbeKind is Entry/Return
We already have separate types for KProbe and UProbe.
2025-11-12 11:28:03 -05:00
Friday Ortiz
ab38afe95d perf_event: support hardware breakpoints
Implement `PerfEventConfig::Breakpoint`, allowing users to attach
hardware breakpoints. Generate `HW_BREAKPOINT_*` and `struct
bpf_perf_event_data` in support of this feature and update the type of
`PerfEventContext` accordingly.

Add a test exercising R, W, RW, and X breakpoints. Note that R
breakpoints are unsupported on x86, and this is asserted in the test.

Extend the VM integration test harness and supporting infrastructure
(e.g. `download_kernel_images.sh`) to download kernel debug packages and
mount `System.map` in initramfs. This is needed (at least) on the aarch
6.1 Debian kernel which was not compiled with `CONFIG_KALLSYMS_ALL=y`
for some reason, and the locations of globals are not available in
kallsyms. To attach breakpoints to these symbols in the test pipeline,
we need to read them from System.map and apply the KASLR offset to get
their real address. The `System.map` file is not provided in the kernel
package by default, so we need to extract it from the corresponding
debug package. The KASLR offset is computed using `gunzip` which appears
in kallsyms on all Debian kernels tested.

Co-authored-by: Tamir Duberstein <tamird@gmail.com>
2025-11-10 16:33:54 -05:00
JPaja
d8f5497884 feat: add Ebpf::maps_disjoint_mut
Implemented using `HashMap::get_disjoint_mut` introduced in Rust 1.86.0.
2025-11-10 14:12:04 -05:00
Tamir Duberstein
112ab47fcd Add clippy coverage for doctests 2025-11-09 18:26:39 -05:00
Tamir Duberstein
866cbe4837 all: bump MSRV to 1.87.0
Use newly stabilized `is_multiple_of`.
2025-11-09 12:23:04 -05:00
Tim W
17573e0e47 aya-build: plumb features of ebpf crates
This allows callers to select features of the ebpf crate.
2025-11-03 18:43:45 -05:00
Tamir Duberstein
17c7c7951c lints: enable clippy::as_underscore 2025-10-26 11:36:51 -04:00
Tamir Duberstein
d9704be77d aya-build: remove cargo_metadata from public API 2025-10-26 09:50:52 -04:00
Tamir Duberstein
05250da20b aya-ebpf: reduce repetition and excessive traits
The traits `FromBtfArgument`, `FromRawTracepointArgs`, `FromPtRegs` are
all fancy ways of saying `Argument` - so replace these traits with it.

This also removes the use of `bpf_probe_read` which was introduced in
05c1586202 because I can't reproduce the
need for it.
2025-10-25 15:01:52 -04:00
Tamir Duberstein
9e577f60b5 integration-test: remove netns-rs
This crate uses a very old version of `nix` which is preventing us from
adding support for loongarch64.

Make panic-in-panic more uniform while I'm here.
2025-10-24 13:09:13 -04:00
Andrew Werner
03e8487177 aya: rename set_ methods on EbpfLoader
This loader is more of a builder, so these `set_` methods didn't
quite fit. See [this discussion][1] for the motivation.

[1]: https://reviewable.io/reviews/aya-rs/aya/1318#gh-2384180366
2025-10-22 00:05:20 -04:00
Andrew Werner
17171647f7 aya/maps/ring_buf: fix producer position initialization
The RingBuf caches the last value it read of the producer so it doesn't
need to constantly contend on the actual producer cache line if lots of
messages have yet to be consumed. It was bogus to initialize this cache
at 0. This patch initializes it properly and adds testing.

Fixes: #1309
2025-10-21 08:30:20 -04:00
Tamir Duberstein
0144c0eb22 integration-test: defer cleanup to ensure unpin 2025-10-17 22:16:28 -04:00
Tamir Duberstein
907920a629 Skip cpumap_chain when attachment fails 2025-10-17 22:16:28 -04:00
Tamir Duberstein
54bd3ac202 Skip lsm_cgroup when loading fails
squash into proper check
2025-10-17 22:16:28 -04:00
Tamir Duberstein
2e5f5efbf1 aya: make ProgramInfo a proper enum
This allows us to distinguish between LSM and LSM_CGROUP programs and do
the proper capability check in is_program_supported.
2025-10-17 22:16:28 -04:00
Tamir Duberstein
3d0b53111f integration-test: remove skips 2025-10-17 22:16:28 -04:00
Tamir Duberstein
b2fd9493a8 integration-test: handle !bpf_perf_link 2025-10-17 15:28:21 -04:00
Tamir Duberstein
0ec60c4f23 Skip bpf_strncmp on kernel < 5.17 2025-10-17 15:28:21 -04:00
Tamir Duberstein
4c22a99cb0 Skip af_xdp when AF_XDP is unsupported 2025-10-17 15:28:21 -04:00
Tamir Duberstein
e5306901a0 Skip test_uprobe_cookie on kernel < 5.15 2025-10-16 13:28:11 -04:00
Tamir Duberstein
08cf90881f integration-test: extract run_pin_program_lifecycle_test 2025-10-16 06:20:45 -04:00
Tamir Duberstein
fe43f776c3 integration-test: extract from_pin 2025-10-16 06:20:45 -04:00
Tamir Duberstein
0840faf6b1 integration-test: extract pin paths 2025-10-16 06:20:44 -04:00
Tamir Duberstein
0f1c975632 integration-test: extract run_unload_program_test 2025-10-16 06:20:44 -04:00
Tamir Duberstein
a6458804fc integration-test: extract types 2025-10-16 06:20:44 -04:00
Tamir Duberstein
a2f4951cce integration-test: remove errant semicolons 2025-10-16 06:20:44 -04:00
Tamir Duberstein
89d746ad1b integration-test: extract attach fns 2025-10-16 06:20:44 -04:00
Tamir Duberstein
48300b6498 integration-test: extract program names 2025-10-16 06:20:43 -04:00
Tamir Duberstein
4041fe9293 integration-test: move memmove out of pin tests 2025-10-16 06:20:43 -04:00
Christian A. Jacobsen
a98b638fa9 feat(log): add support for logging raw pointer types
* Requires the usage of `:p` display hint.
* Will, like stdlib, log with `0x` prefix.
2025-10-16 05:22:10 -04:00
Altug Bozkurt
fc5387c806 lsm: cgroup attachment type support 2025-10-09 06:23:19 -07:00
Tamir Duberstein
66ed37c8a9 integration-test: add LSM 2025-10-08 08:59:04 -07:00
Tamir Duberstein
8e75214815 feature_probe: properly check for LSM support
Turns out this is not supported in aarch64 until 6.4.
2025-10-08 08:59:04 -07:00
Tamir Duberstein
9ba87c661b xtask: copy kernel config into the initramfs image
When preparing the VM initramfs detect the `config-*` file that ships alongside
the vmlinuz/modules in each kernel archive and install it under `/boot` (both
as `/boot/config` and `/boot/config-<version>`). This makes the running
kernel’s configuration available inside the guest for the integration tests.
2025-10-08 08:59:04 -07:00
Tamir Duberstein
ffa65efb36 integration-ebpf: avoid mentioning the size 2025-10-08 08:57:31 -07:00