Commit Graph

380 Commits (9518ff8ca66145804f6ddb252f7674ab3b22b6aa)

Author SHA1 Message Date
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>
7 days ago
Tamir Duberstein 0484ab5c57
xtask: use `-cpu host` iff host == guest 7 days ago
JPaja d8f5497884
feat: add `Ebpf::maps_disjoint_mut`
Implemented using `HashMap::get_disjoint_mut` introduced in Rust 1.86.0.
7 days ago
Tamir Duberstein 989a465f0c
xtask: avoid extracting complete archives
Now that we're no longer shelling out to do this, we can avoid most of
the work. Operate directly on the archive, unpacking only what we need.
1 week ago
Tamir Duberstein 2b8cd557aa
xtask: drop build script logging prefix
This code doesn't run under cargo.
1 week ago
Tamir Duberstein 18c7f7ccd6
perf_event: push down type safety
This makes it more difficult to mishandle callers of `perf_event_open`.

Change `wakeup_events = 0` to 1; per `man 2 perf_event_open`:

  Prior to Linux 3.0, setting wakeup_events to 0 resulted in
  no overflow notifications; more recent kernels treat 0 the
  same as 1.
1 week ago
Tamir Duberstein 7e405c216e
perf_event: simplify PerfEventScope 1 week ago
Tamir Duberstein 468b9b73db
xtask: use `-cpu host` on x86
We have started to see errors in CI:

  qemu-system-x86_64: warning: host doesn't support requested feature: CPUID[eax=80000001h].ECX.svm [bit 2]

The internet says this is the remedy.
1 week ago
Tim W 17573e0e47 aya-build: plumb features of ebpf crates
This allows callers to select features of the ebpf crate.
2 weeks ago
Alessandro Decina 3a3c451009 aya: restore must_exist argument to set_global
In
03e8487177
we deprecated set_global but accidentally broke its API by deleting the
must_exist argument.
3 weeks ago
Tamir Duberstein 03fea9e304
aya-ebpf: reduce duplication 3 weeks ago
Tamir Duberstein d9704be77d
aya-build: remove cargo_metadata from public API 3 weeks ago
Tamir Duberstein f610453ec2
ebpf: extract CARGO_CFG_BPF_TARGET_ARCH logic 3 weeks ago
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.
3 weeks ago
Michal R a7cfc694bd xtask: Allow to run VM integration tests without dpkg
Debian packages are just nested archives, where the outer one is ar
and the inner one is lzma2 tarball. Use Rust crates to unpack them.

Co-authored-by: Tamir Duberstein <tamird@gmail.com>
4 weeks ago
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
4 weeks ago
Andrew Werner 5802dc7a23 aya: allow specifying a pin path for a named map
This commit extends the EbpfLoader with set_map_pin_path that allows the
caller to associate a named map with a pin path.

One note is that this path is an absolute path, not relative to
`map_pin_path`, and it forces the map to be loaded from that path.
4 weeks ago
Andrew Werner 1c924bb421 aya: rename map_pin_path to default_map_pin_path
This is the path in which pinned maps are created or resolved. It
isn't actually the path for any specific map itself. This rename
makes way for a method `set_map_pin_path` that actually specifies
the pin path for a specific map.
4 weeks ago
Tamir Duberstein 0144c0eb22
integration-test: defer cleanup to ensure unpin 1 month ago
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.
1 month ago
Tamir Duberstein 8e9404ecd4
aya-obj: apply enum64-to-union fixup in reloc
This code is just awful.
1 month ago
Tamir Duberstein 7224efcad8
aya-obj: patch up 0-size datasec
Use OnceCell for ENUM64 while I'm here as well.
1 month ago
Tamir Duberstein 3ade19b869
Promote BTF loading failure to error on BTF relocs 1 month ago
Tyrone Wu 3d7fbaad28 aya: enforce valid perf_event type & config combos
Add guardrails for when setting event type and config for perf_event
programs. The `PerfEventConfig` enum now defines the event `type` and
`config` of interest.

Remove public re-exports, and add idiomatic Rust types for:
- perf_hw_id => HardwareEvent
- perf_sw_ids => SoftwareEvent
- perf_hw_cache_id => HwCacheEvent
- perf_hw_cache_op_id => HwCacheOp
- perf_hw_cache_op_result_id => HwCacheResult

The motivation behind this is mainly for the `type` and `config` fields
of `bpf_link_info.perf_event.event`. The newly added enums are planned
to also be used in the `bpf_link_info` metadata.

Although `Breakpoint`/`PERF_TYPE_BREAKPOINT` variant exists, it is not
fully implemented. It's only usage at the moment is in link info.
1 month ago
Tamir Duberstein 82aec26963
flow_dissector: add missing impl_try_into_fdlink 1 month ago
Tamir Duberstein 0cb52e850a
xtask: tolerate curl failure when possible
Codex sandbox forbids network access.
1 month ago
Tamir Duberstein 667790e103
xtask: avoid `git submodule update` when possible
`git submodule update` fails when running in a codex sandbox:

```
  error: could not lock config file /Users/tamird/src/aya/.git/modules/libbpf/config: Operation not permitted
```

so just avoid it when not necessary.
1 month ago
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.
1 month ago
Altug Bozkurt fc5387c806
lsm: cgroup attachment type support 1 month ago
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.
1 month ago
Tamir Duberstein 5f046899b5
xtask: teach integration-test vm to consume kernel debs directly
Bundle handling of Debian kernel archives into xtask so callers can pipe
the raw `.deb` paths straight into `cargo xtask integration-test vm …`.
The driver now extracts each archive into `<cache>/kernel-archives`,
locates the matching `vmlinuz-*`, `lib/modules/*`, and config files, and
feeds those into the initramfs build without requiring the user to
pre-run dpkg/tar. With this in place we drop
`.github/scripts/find_kernels.py`, simplify AGENTS.md/CI instructions to
use `find test/.tmp -name '*.deb'`, remove the gnu-tar requirement we no
longer need, and add `tar` as a workspace dependency for the extractor.
1 month ago
Tamir Duberstein fab4fc44b2
xtask: reduce `fs` imports 1 month ago
Tamir Duberstein d16711b2be
xtask: avoid variables named `cmd` and `child` 1 month ago
Tamir Duberstein 71f6176e24
xtask: ensure we actually built depmod 1 month ago
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.
1 month ago
Tamir Duberstein de42b80c74
aya,ebpf: add BPF_MAP_TYPE_SK_STORAGE
This map type requires BTF, and we can finally do it!
1 month ago
Tamir Duberstein 552b69367f
xtask: remove outdated snippet
We handed this to QEMU in e3bfeb9dd6.
1 month ago
Tamir Duberstein bb45904b08
xtask: patch gen_init_cpio.c
Recent changes[0][1] have broken compatibility with macOS; add a patch
to conditionally compile these snippets.

Patch and compile the source unconditionally; caching only the network
portion is good enough and less error prone.

[0] ae18b94099
[1] 97169cd6d9
1 month ago
dependabot[bot] ace02870f2
build(deps): update cargo_metadata requirement in the cargo-crates group
Updates the requirements on [cargo_metadata](https://github.com/oli-obk/cargo_metadata) to permit the latest version.

Updates `cargo_metadata` to 0.22.0
- [Release notes](https://github.com/oli-obk/cargo_metadata/releases)
- [Changelog](https://github.com/oli-obk/cargo_metadata/blob/main/CHANGELOG.md)
- [Commits](https://github.com/oli-obk/cargo_metadata/compare/0.22.0...0.22.0)

---
updated-dependencies:
- dependency-name: cargo_metadata
  dependency-version: 0.22.0
  dependency-type: direct:production
  dependency-group: cargo-crates
...

Signed-off-by: dependabot[bot] <support@github.com>
2 months ago
Tamir Duberstein 5f5305c2a8
lint all crates; enable strict pointer lints 2 months ago
Tamir Duberstein ec3eacc1d8
Increase VM memory
Since 6.1.0-40 we're seeing `Initramfs unpacking failed: write error`.
2 months ago
tamird 32071bdca7 public-api: regenerate 2 months ago
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>
2 months ago
Adam Schreck 263e864cd9 aya: add Map::from_map_data() for pinned map access
Enables creation of Map enum variants directly from MapData instances,
allowing user-space handles to pinned BPF maps without requiring the
original BPF object.

Supports multiple BPF map types.

Motivation:
- Simplifies accessing pinned maps from user space applications.
- Avoids full BPF reloads and potential deadlocks.
- Matches existing ergonomic APIs like LruHashMap::try_from.
- Keeps user code safe and idiomatic.

Closes https://github.com/aya-rs/aya/issues/1305.

Includes test coverage to validate the new API.
2 months ago
Tamir Duberstein 214fe3c367
aya-log-common: seal Argument 2 months ago
Tamir Duberstein 353b83383d
aya-log-ebpf: zero copy! 2 months ago
Tamir Duberstein 3f60168d4b
ring_buf: add RingBufBytes for raw byte slices 2 months ago
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>
2 months ago
Tamir Duberstein b36cbc3eb8
implement load-time log level mask 2 months ago
dependabot[bot] a0b63b8811
build(deps): bump the cargo-crates group with 2 updates (#1333) 3 months ago