Commit Graph

1442 Commits (ede3e91014075de01af02da624cad99861da2dad)
 

Author SHA1 Message Date
Tamir Duberstein b54a106584
log: update comments
These were missed when the code was updated.
1 year ago
Tamir Duberstein 45df2519b6
Merge pull request #736 from aya-rs/logging-better
Remove pointless DefaultLogger
1 year ago
Tamir Duberstein ecf0dd9739
Merge pull request #735 from aya-rs/log-option-not-result
aya-log: s/Result<usize, ()>/Option<NonZeroUsize>/
1 year ago
Tamir Duberstein ca3f70b16a
aya-log: s/Result<usize, ()>/Option<NonZeroUsize>/
`Option<NonZeroUsize>` is guaranteed to have the same size as `usize`,
which is not guarnateed for `Result`. This is a minor optimization, but
also results in simpler code.
1 year ago
Tamir Duberstein 00d265c51b
Remove pointless DefaultLogger
This avoids an atomic load on every log.
1 year ago
Tamir Duberstein 412a0875b4
Merge pull request #733 from tamird/kernel-test
integration-test: Implement running on VMs
1 year ago
Tamir Duberstein 82a77bc83d
integration-test: Implement running on VMs
Implements running integration tests on multiple VMs with arbitrary
kernel images using `cargo xtask integration-test vm ...`.

This changes our coverage from 6.2 to 6.1 and 6.4.
1 year ago
Tamir Duberstein b6a6a81f95
integration-test: deflake log test
Wait for at least one log and increase the wait time 10x.
1 year ago
Tamir Duberstein d3513e7010
Merge pull request #734 from aya-rs/reduce-slicing
aya-obj: s/types.types[i]/*t/ where possible
1 year ago
Tamir Duberstein dfb6020a1d
aya-obj: s/types.types[i]/*t/ where possible
We already have a mutable reference in scope, use it where possible.
1 year ago
Tamir Duberstein 84d5791d4e
Merge pull request #729 from aya-rs/logs-inline-always
log: annotate logging functions inlining
1 year ago
Dave Tucker 2a55fc7bd3
Merge pull request #725 from dave-tucker/enum64
aya, aya-obj: Implement ENUM64 fixups
1 year ago
Dave Tucker e38e2566e3 aya, aya-obj: Implement ENUM64 fixups
This commit adds:

- A probe to see if the ENUM64 feature is supported
- Fixups for the use of signed enums, or enum64 types
  on systems where enum64 is not supported

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 3cfd886dc5
log: annotate logging functions inlining
Some of these functions fail to compile when not inlined, so we should
be explicit.

Before deciding on this approach I tried various ways of making all
these functions #[inline(never)] to save instructions but I ran into
blockers:
- These functions currently return Result, which is a structure. This is
  not permitted in BPF.
- I tried inventing a newtype that is a #[repr(transparent)] wrapper of
  u16, and having these functions return that; however it seems that
  even if the object code is legal, the verifier will reject such
  functions because the BTF (if present, and it was in my local
  experiments) would indicate that the return is a structure.
- I tried having these functions return a plain u16 where 0 means error,
  but the verifier still rejected the BTF because the receiver (even if
  made into &self) is considered a structure, and forbidden.

We can eventually overcome these problems by "lying" in our BTF once
support for it matures in the bpf-linker repo (e.g. Option<NonZeroU16>
should be perfectly legal as it is guaranteed to be word-sized), but we
aren't there yet, and this is the safest thing we can do for now.
1 year ago
Tamir Duberstein fe047d79a3
aya-log-common: Simplify
- Remove `TagLenValue`; this type has a single method, which is now a
  function.
- Remove generics from `TagLenValue::write` (now `write`). The tag is
  always `u8`, and the value is always a sequence of bytes.
- Replace slicing operations which can panic with calls to `get` which
  explicit check bounds.
1 year ago
Dave Tucker e21001226f
Merge pull request #731 from dave-tucker/noclone-btf
aya-obj: Mutate BTF in-place without clone
1 year ago
Tamir Duberstein cb42d028d0
Merge pull request #727 from tamird/build-everywhere
integration-test: avoid reliance on kernel headers
1 year ago
Tamir Duberstein 54c90ec72c
integration-test: De-duplicate BTF relocation test 1 year ago
Tamir Duberstein 71bc3ea0b5
integration-test: avoid reliance on kernel headers
This should allow us to build on any system.
1 year ago
Tamir Duberstein b46fb616be
integration-test: fix BTF relocation test
The struct_flavors test previously expected the same thing with and
without relocations. It now expects different values.

Also rename an enum variant "u64" to "S64". This was a typo. Turns out
that U32 is a type that exists in kernel headers, so all enum values are
suffixed with "_VAL".

Remove stdlib.h and the call to exit(). This alone makes the test fail
with a poisoned relocation. Bringing over the map definition makes the
test work again.
1 year ago
Tamir Duberstein 0904cd089e
integration-test: DRY clang setup 1 year ago
Tamir Duberstein dc9f72adf0
test,xtask: Simplify ExitStatus handling 1 year ago
Dave Tucker 098d4364bd aya-obj: Mutate BTF in-place without clone
The BTF we're working on is Cow anyway so modifying in-place is fine.
All we need to do is store some information before we start our
mutable iteration to avoid concurrently borrowing types both mutably and
immutably.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 72afd877b5
integration-test: clang-format C files 1 year ago
Tamir Duberstein bcbb7e08fa
Cargo.toml: Remove default-features settings
These are all set to false at the root.
1 year ago
Tamir Duberstein 761e4ddbe3
Merge pull request #726 from aya-rs/btf-iter-alloc
btf: avoid multiple vector allocations
1 year ago
Tamir Duberstein 826e0e5050
btf: use Self instead of restating the type 1 year ago
Tamir Duberstein 2a054d76ae
btf: avoid multiple vector allocations
Rather than creating an empty vector and iteratively appending - which
might induce intermediate allocations - create an ExactSizeIterator and
collect it into a vector, which should produce exactly one allocation.
1 year ago
Dave Tucker 1979da92a7
Merge pull request #721 from dave-tucker/fix-funcinfo
aya: Fix (func|line)_info multiple progs in section
1 year ago
Dave Tucker 79ea64ca7f aya: Fix (func|line)_info multiple progs in section
This commit fixes the (func|line)_info when we have multiple programs in
the same section. The integration test reloc.bpf.c serves as our test
case here. This required filtering down the (func|line)_info to only
that in scope of the current symbol + then adjusting the offets to
appease the kernel.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein bd5442a1de
Merge pull request #709 from nrxus/fd-link-owned-fd
aya: Use OwnedFd in FdLink. (#709)
1 year ago
Andrés Medina 8ebf0ac327
aya: Use OwnedFd in FdLink. 1 year ago
Dave Tucker e9153792f1
Merge pull request #720 from dave-tucker/programsection-noname
aya-obj: Remove name from ProgramSection
1 year ago
Addison Crump d8709de9f2
Extract trait SymbolResolver 1 year ago
ajwerner ef6308b640
Merge pull request #718 from ajwerner/better-code
uprobe: refactor target resolution
1 year ago
Dave Tucker cca9b8f1a7 aya-obj: Remove name from ProgramSection
The name here is never used as we get the program name from the symbol
table instead.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Andrew Werner 81fb4e5568 uprobe: refactor target resolution
This attempts to do fewer lossy conversions and to avoid some
allocations.
1 year ago
ajwerner de8604d011
Merge pull request #717 from ajwerner/no-libc-in-integration-tests
uprobe,integration-test: do not exercise dylib resolution in integration tests
1 year ago
Dave Tucker 77e9603976
Merge pull request #711 from dave-tucker/sleepable
Tidy up aya-bpf-macros (again)
1 year ago
Andrew Werner 79c9489a4f integration-test: attach uprobes to self
For unclear reasons, two of the integration tests related to uprobes
were resolving a symbol in libc. The integration-test binary can be
built statically, in which case it would not load or reference libc.
Statically linking the integration tests and running them in a VM
without a userland is a convenient mechanism to exercise the tests
against different kernel versions.

The fact that the statically linked integration-test binary does not
load libc is not the only reason these tests failed in such an
environment. In fact, the logic to look in the process's memory
maps was not running (because no pid was being passed).

Separate logic to determine which object file to use when attempting
to resolve a symbol for attaching a uprobe changes its behavior based
on whether that target is an absolute path. If the target is not an
absolute path, the code searches through the LdSoCache. This cache does
not always exist in linux systems; when an attach call is made with a
relative path target and there is no /etc/ld.so.cache file, the attach
call will fail. This commit does not change that behavior, it merely
sidesteps it.
1 year ago
Andrew Werner dcc6b84a88 programs/uprobe: extract library path resolving
The function is extracted so that a test could be written. This test is
valid on linux-gnu targets, and it doesn't need any special privileges.
This is in anticipation of removing the code that uses this functionality
(seemingly incidentally) from integration tests.
1 year ago
Tamir Duberstein 368ddf10c4
Merge pull request #712 from aya-rs/loaded-links
integration-test: remove bpftool dependency
1 year ago
Tamir Duberstein 30faa5f68f Add links iterator
This is not yet exposed in documentation, but is complete enough for use
in tests, removing the dependency on bpftool.

Updates #645.
1 year ago
Tamir Duberstein b1bf61ca61
Merge pull request #716 from aya-rs/prealloc-vec
aya: preallocate the vector
1 year ago
Dave Tucker 71737f5576 aya: Set BPF_F_SLEEPABLE for sleepable programs
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 89ef97e848
aya: preallocate the vector
This code badly needs tests :(
1 year ago
Dave Tucker 677e7bda4a aya-obj: Propagate sleepable into ProgramSection
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker 7eebdcbdeb aya-bpf-macros: Cleanup and remove required_args
This commit cleans up the recently refactored aya-bpf-macros
to be a little easier to maintain:

Cosmetic changes:

1. The flow of the parse function is the same in each file
2. Useless if !attrs.is_empty() guards were removed
3. The compile error when cgroup_sock programs have an invalid
   attach_type was in the wrong location

Functional changes:

1. Remove pop_required_arg. All args are optional and making them
   required was a mistake on my part. We may revisit this later.
2. Rename pop_arg to pop_string_arg
3. Implement pop_bool_arg to allow for single idents to be mixed with
   our key/value pair syntax in macro attributes. This is used for
   `sleepable` and `frags` in XDP programs.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 7bb9b7f5a5
programs: plug file descriptor leak
This leaked a file descriptor if bpf_prog_get_info_by_fd failed.
1 year ago
Tamir Duberstein b1404e9a73
sys: push error construction up 1 year ago