Commit Graph

105 Commits

Author SHA1 Message Date
vad
0bf462d221 maps: Take &self in all methods of 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
Jamie Hill-Daniel
294e0c1941 ebpf: Add helper for safe loading of globals 2026-02-13 11:13:57 -08:00
Gustavo Noronha Silva
dd9bb520d2 tracepoint: use read_kernel() for read_at()
For most architectures just bpf_probe_read() works, but for those that
have overlapping memory address spaces, like UML, we must use the
specific helper.
2026-02-09 17:34:32 +11:00
Tamir Duberstein
2f8759cc62 Dial the lints to 100 2026-01-29 10:02:48 -05:00
vad
998ad08ba0 maps: Do not anonymize BTF maps
See https://github.com/llvm/llvm-project/pull/164851. This fixup is
not needed.
2026-01-28 05:58:54 +00:00
root
930fa7b8af aya-ebpf: generalize btf_map_def macro type parameters
Modify the btf_map_def! macro to generate flat #[repr(C)] structs
instead of UnsafeCell wrappers. This produces BTF that both aya
and libbpf can parse.

Support type parameters with optional defaults and const generics with
configurable types. Allow trailing commas and improve formatting.

Also remove UnsafeCell traversal code from aya-obj loader since
it is no longer needed with flat struct layout.
2026-01-27 14:49:22 +00:00
Tamir Duberstein
e746618143 enable unused_qualifications lint 2026-01-23 11:03:26 -05:00
Tamir Duberstein
394668806b aya-ebpf: define hash maps via macro 2026-01-21 09:05:51 -05:00
Tamir Duberstein
f35f7a3610 aya, aya-ebpf: reduce duplication 2026-01-21 09:05:51 -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
Donghyun Shin
1d10f8751d aya-ebpf: fix redirect_sk_lookup receiver type
The `redirect_sk_lookup` method for SockMap and SockHash
previously required exclusive references.

The documentation for `bpf_map_lookup_elem` makes no
mention of a requirement for exclusive references.

Therefore, `redirect_sk_lookup` has been changed to
receive shared references to SockMap and SockHash.
2026-01-12 10:43:04 -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
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
Tamir Duberstein
112ab47fcd Add clippy coverage for doctests 2025-11-09 18:26:39 -05:00
Tamir Duberstein
03fea9e304 aya-ebpf: reduce duplication 2025-10-26 15:51:12 -04:00
Tamir Duberstein
17c7c7951c lints: enable clippy::as_underscore 2025-10-26 11:36:51 -04:00
Tamir Duberstein
778b447e3b lints: enable unsafe_op_in_unsafe_fn 2025-10-26 11:36:50 -04:00
Tamir Duberstein
f610453ec2 ebpf: extract CARGO_CFG_BPF_TARGET_ARCH logic 2025-10-26 07:24:46 -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
Godones
4b4b9f83bd enable bpf_target_arch = loongarch64
Signed-off-by: Godones <chenlinfeng25@outlook.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
2025-10-24 20:01:06 -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
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
Michal R
98e8c78376 aya-ebpf: Make use of Borrow and BorrowMut in map methods
Let callers pass either owned objects or references. We do that already
in the user-space methods.
2025-10-07 16:36:50 +01:00
Tamir Duberstein
de42b80c74 aya,ebpf: add BPF_MAP_TYPE_SK_STORAGE
This map type requires BTF, and we can finally do it!
2025-10-05 17:32:21 -04:00
Tamir Duberstein
0013ff4e9e ebpf: use null pointers at runtime
The values here do not matter, this is just to get type information.
2025-10-05 07:47:16 -04:00
Tamir Duberstein
275c5b6bbc ebpf: use ptr::from_ref
This is consistent with other such conversions.
2025-10-05 07:47:16 -04:00
Tamir Duberstein
fe99fa1d2e ebpf: run clippy with target=bpf
This build warnings from integration tests and makes `aya-ebpf`'s build
script stricter.
2025-10-03 13:44:36 -04:00
Tamir Duberstein
5f5305c2a8 lint all crates; enable strict pointer lints 2025-09-29 05:19:23 -04:00
Michal R
0b2a544ddd aya-ebpf: Add BTF array definition
Before this change, Aya supported only legacy BPF map definitions, which
are instances of the `bpf_map_def` struct and end up in the `maps` ELF
section.

This change introduces a BTF map definition for arrays, with custom
structs indicating the metadata of the map, which end up in the `.maps`
section.

Co-authored-by: Tamir Duberstein <tamird@gmail.com>
2025-09-18 10:49:59 +00:00
Michal R
d5e4e9270a aya-ebpf: Remove irrelevant FIXME comment
eBPF verifier in recent kernels should be smart enough to track map
map types and catch invalid pointer casts. Rust type system makes sure
that the `get` method can return only the same type the map was created
with. Therefore, safe usage of Aya map types shouldn't cause element
type mismatches.

Manual alignment checks (`pointer::is_aligned` or manual pointer
arithmetic operations) cause the following verifier error:

```
bitwise operator &= on pointer prohibited
```

And it extremely unlikely `bpf_map_lookup_elem` ever returns a
misaligned pointer.
2025-09-18 10:49:59 +00:00
Michal R
3569c9afc3 aya-ebpf: Take c_void instead of bpf_map_def in map helpers
`bpf_map_def` is a legacy map definition. To be able to introduce BTF
map definitions, make the `lookup` and `remove` helpers work with
`c_void` and let the callers cast the map types to it.
2025-09-18 10:49:59 +00:00
Tamir Duberstein
353b83383d aya-log-ebpf: zero copy! 2025-09-09 06:28:43 -04:00
Tamir Duberstein
3f60168d4b ring_buf: add RingBufBytes for raw byte slices 2025-09-08 21:44:14 -04:00
Tamir Duberstein
f537dc6684 ring_buf: destructure, avoid as casts 2025-09-08 18:59:44 -04:00
Xiaobo Liu
53ec616411 ebpf: add peak() method to Queue and Stack
Add integration tests covering push,pop,peek for both types.

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
2025-09-05 21:50:04 -04:00
Addison Crump
f6606473af aya-log: properly hint log level to verifier
The log level implementation in b36cbc3eb8
was incomplete as the verifier could reject programs which exceeded
their instruction limits within logging statements. This commit
addresses this issue by making the log level static variable immutable
(s.t. the compiler puts it in a read-only section) and adds an
additional test which the verifier will reject as an infinite loop iff
it is unable to detect that the static variable would otherwise allow
the logging.
2025-09-05 11:23:09 -04:00
Tamir Duberstein
b36cbc3eb8 implement load-time log level mask 2025-09-04 21:08:34 -04:00
Tamir Duberstein
9be2d723ce aya-log: Replace AsyncPerfEventArray with RingBuf
This doesn't get us to zero copy because the reserve/submit APIs do not
support DSTs for reasons I don't remember.

Now that it is unused in userspace, move `LOG_BUF_CAPACITY` to
`aya-log-ebpf` by making its type `LogValueLength` which obviates the
need for `log_value_length_sufficient`.
2025-07-07 09:33:52 -04:00
Tamir Duberstein
8fb19264da aya-log-ebpf: tidy up macro_support
Move top level items into and remove unused items from `macro_support`.
2025-07-07 09:33:33 -04:00
tamird
bd0424ca61 aya-obj, aya-ebpf-bindings: regenerate
libbpf commit: 20ea95b4505c477af3b6ff6ce9d19cee868ddc5d
2025-06-09 15:24:17 -04:00
Tamir Duberstein
ccf6c4707f aya-ebpf: disable generic_const_exprs
This has recently regressed on nightly.

See https://github.com/rust-lang/rust/issues/141492.
2025-05-24 16:34:05 -04:00
Tamir Duberstein
4f654865e9 aya-ebpf: add a dedicated generic_const_exprs cfg 2025-05-24 16:34:05 -04:00
Tamir Duberstein
6004fcdb0f aya-ebpf: put mem{set,move,cpy} behind cfg(target_arch = "bpf")
Address some lints while I'm here.
2025-04-21 10:12:42 -04:00
Dave Tucker
9eecbe9d0e Merge pull request #1224 from dave-tucker/unused_trait_names
chore(*): set clippy unused_trait_names = warn
2025-03-20 19:31:36 +00:00
Tamir Duberstein
77b1c6194c Add support for Flow Dissector programs
Closes #216.

Co-authored-by: Zenna Allwein <zrallwein@gmail.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
2025-03-20 13:54:10 -04:00
Dave Tucker
f6c5cb2ad2 chore(*): set clippy unused_trait_names = warn
We have previously tried to import traits anonymously where possible but
enforcing this manually was hard.

Since Rust 1.83 clippy can now enforce this for us.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
2025-03-20 15:16:11 +00:00
Tamir Duberstein
49a828ec56 taplo: reorder-keys
Group non-workspace keys before workspace ones for readability.
2025-03-17 11:38:09 -04:00
Tamir Duberstein
a43e40ae1d introduce workspace lints, warn on unused crates
In practice this will forbid unused dependencies because we run clippy
with `--deny warnings`.

Workspace lints is a nice place to ratchet up lints through the codebase
all at once and consistently.
2025-03-06 14:46:03 -05:00
Tamir Duberstein
6252b4c972 aya-obj,aya-ebpf-*: hook up loongarch64
This causes rustfmt to format those files.

Squish some other conditional compilation to get rustfmt sorting.
2025-03-04 15:59:00 -05:00