Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unwinding in userspace #1098

Merged
merged 6 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rustfmt, clippy, miri, rust-src
components: clippy,miri,rustfmt,rust-src

# Installed *after* nightly so it is the default.
- uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

Expand All @@ -43,10 +45,10 @@ jobs:
run: taplo fmt --check

- name: Check formatting
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check

- name: Run clippy
run: cargo hack clippy --all-targets --feature-powerset --workspace -- --deny warnings
run: ./clippy.sh

- run: cargo xtask public-api
if: github.event_name == 'pull_request'
Expand All @@ -62,7 +64,7 @@ jobs:
- name: Run miri
run: |
set -euxo pipefail
cargo hack miri test --all-targets --feature-powerset \
cargo +nightly hack miri test --all-targets --feature-powerset \
--exclude aya-ebpf \
--exclude aya-ebpf-bindings \
--exclude aya-log-ebpf \
Expand All @@ -85,9 +87,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

Expand Down Expand Up @@ -149,11 +149,13 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rust-src

# Installed *after* nightly so it is the default.
- uses: dtolnay/rust-toolchain@stable

- uses: Swatinem/rust-cache@v2

- name: bpf-linker
Expand All @@ -165,18 +167,21 @@ jobs:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
run: |
set -euxo pipefail
cargo hack build --package aya-ebpf --package aya-log-ebpf \
--feature-powerset \
cargo +nightly hack build \
--target ${{ matrix.target }} \
-Z build-std=core
-Z build-std=core \
--package aya-ebpf \
--package aya-log-ebpf \
--feature-powerset

- name: Test
env:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.bpf_target_arch }}
RUST_BACKTRACE: full
run: |
set -euxo pipefail
cargo hack test --doc \
cargo hack test \
--doc \
--package aya-ebpf \
--package aya-log-ebpf \
--feature-powerset
Expand Down Expand Up @@ -236,10 +241,13 @@ jobs:
echo $(brew --prefix)/opt/gnu-tar/libexec/gnubin >> $GITHUB_PATH
echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH

- uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rust-src

# Installed *after* nightly so it is the default.
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl

- uses: Swatinem/rust-cache@v2
Expand Down
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ tokio = { version = "1.24.0", default-features = false }
which = { version = "7.0.0", default-features = false }
xdpilone = { version = "1.0.5", default-features = false }

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

[profile.release.package.integration-ebpf]
debug = 2
codegen-units = 1
12 changes: 12 additions & 0 deletions clippy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

# `-C panic=abort` because "unwinding panics are not supported without std";
# integration-ebpf contains `#[no_std]` binaries.
#
# `-Zpanic_abort_tests` because "building tests with panic=abort is not supported without
# `-Zpanic_abort_tests`"; Cargo does this automatically when panic=abort is set via profile
# but we want to preserve unwinding at runtime - here we are just running clippy so we don't
# care about unwinding behavior.
#
# `+nightly` because "the option `Z` is only accepted on the nightly compiler".
exec cargo +nightly hack clippy "$@" --all-targets --feature-powerset --workspace -- --deny warnings -C panic=abort -Zpanic_abort_tests
32 changes: 0 additions & 32 deletions ebpf/aya-ebpf-cty/.travis.yml

This file was deleted.

7 changes: 0 additions & 7 deletions ebpf/aya-ebpf-cty/ci/install.sh

This file was deleted.

10 changes: 0 additions & 10 deletions ebpf/aya-ebpf-cty/ci/script.sh

This file was deleted.

8 changes: 0 additions & 8 deletions ebpf/aya-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ edition.workspace = true
aya-ebpf-cty = { version = "^0.2.2", path = "../aya-ebpf-cty" }
aya-ebpf-macros = { version = "^0.1.1", path = "../../aya-ebpf-macros" }
aya-ebpf-bindings = { version = "^0.1.1", path = "../aya-ebpf-bindings" }
const-assert = { workspace = true, optional = true }

[build-dependencies]
rustversion = { workspace = true }

[features]
default = []
# TODO(https://github.com/rust-lang/rust/issues/76560): Always utilize the
# logic gated behind this feature. This is not currently possible because the
# underlying `const_generic_exprs` language feature is still incomplete.
const_assert = ["const-assert"]
6 changes: 1 addition & 5 deletions ebpf/aya-ebpf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg",
html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg"
)]
#![cfg_attr(
feature = "const_assert",
allow(incomplete_features),
feature(generic_const_exprs)
)]
#![cfg_attr(unstable, allow(incomplete_features), feature(generic_const_exprs))]
#![cfg_attr(unstable, feature(never_type))]
#![cfg_attr(target_arch = "bpf", feature(asm_experimental_arch))]
#![allow(clippy::missing_safety_doc)]
Expand Down
18 changes: 13 additions & 5 deletions ebpf/aya-ebpf/src/maps/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use core::{
ops::{Deref, DerefMut},
};

#[cfg(feature = "const_assert")]
use const_assert::{Assert, IsTrue};

use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_RINGBUF},
helpers::{
Expand All @@ -17,6 +14,17 @@ use crate::{
maps::PinningType,
};

#[cfg(unstable)]
mod const_assert {
pub struct Assert<const COND: bool> {}

pub trait IsTrue {}

impl IsTrue for Assert<true> {}
}
#[cfg(unstable)]
use const_assert::{Assert, IsTrue};

#[repr(transparent)]
pub struct RingBuf {
def: UnsafeCell<bpf_map_def>,
Expand Down Expand Up @@ -93,7 +101,7 @@ impl RingBuf {
/// Reserve memory in the ring buffer that can fit `T`.
///
/// Returns `None` if the ring buffer is full.
#[cfg(feature = "const_assert")]
#[cfg(unstable)]
pub fn reserve<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>>
where
Assert<{ 8 % mem::align_of::<T>() == 0 }>: IsTrue,
Expand All @@ -109,7 +117,7 @@ impl RingBuf {
/// be equal or smaller than 8. If you use this with a `T` that isn't properly aligned, this
/// function will be compiled to a panic; depending on your panic_handler, this may make
/// the eBPF program fail to load, or it may make it have undefined behavior.
#[cfg(not(feature = "const_assert"))]
#[cfg(not(unstable))]
pub fn reserve<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>> {
assert_eq!(8 % mem::align_of::<T>(), 0);
self.reserve_impl(flags)
Expand Down
12 changes: 0 additions & 12 deletions test/integration-ebpf/.cargo/config.toml

This file was deleted.

2 changes: 0 additions & 2 deletions test/integration-ebpf/rust-toolchain.toml

This file was deleted.

4 changes: 0 additions & 4 deletions test/integration-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ cargo_metadata = { workspace = true }
# script to build this, but we want to teach cargo about the dependecy so that cache invalidation
# works properly.
#
# Note also that https://github.com/rust-lang/cargo/issues/10593 occurs when `target = ...` is added
# to an artifact dependency; it seems possible to work around that by setting `resolver = "1"` in
# Cargo.toml in the workspace root.
#
# Finally note that *any* usage of `artifact = ...` in *any* Cargo.toml in the workspace breaks
# workflows with stable cargo; stable cargo outright refuses to load manifests that use unstable
# features.
Expand Down
26 changes: 14 additions & 12 deletions test/integration-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = PathBuf::from(out_dir);

let endian = env::var_os("CARGO_CFG_TARGET_ENDIAN").unwrap();
let target = if endian == "big" {
"bpfeb"
} else if endian == "little" {
"bpfel"
} else {
panic!("unsupported endian={:?}", endian)
};

const C_BPF: &[(&str, bool)] = &[
("ext.bpf.c", false),
("iter.bpf.c", true),
Expand All @@ -76,6 +67,15 @@ fn main() {
];

if build_integration_bpf {
let endian = env::var_os("CARGO_CFG_TARGET_ENDIAN").unwrap();
let target = if endian == "big" {
"bpfeb"
} else if endian == "little" {
"bpfel"
} else {
panic!("unsupported endian={:?}", endian)
};

let libbpf_dir = manifest_dir
.parent()
.unwrap()
Expand Down Expand Up @@ -191,7 +191,10 @@ fn main() {

let mut cmd = Command::new("cargo");
cmd.args([
"+nightly",
"build",
"--package",
"integration-ebpf",
"-Z",
"build-std=core",
"--bins",
Expand All @@ -203,11 +206,10 @@ fn main() {

cmd.env("CARGO_CFG_BPF_TARGET_ARCH", arch);

// Workaround to make sure that the rust-toolchain.toml is respected.
for key in ["RUSTUP_TOOLCHAIN", "RUSTC"] {
// Workaround to make sure that the correct toolchain is used.
for key in ["RUSTC", "RUSTC_WORKSPACE_WRAPPER"] {
cmd.env_remove(key);
}
cmd.current_dir(integration_ebpf_dir);

// Workaround for https://github.com/rust-lang/cargo/issues/6412 where cargo flocks itself.
let ebpf_target_dir = out_dir.join("integration-ebpf");
Expand Down
4 changes: 2 additions & 2 deletions xtask/public-api/aya-ebpf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl aya_ebpf::maps::ring_buf::RingBuf
pub fn aya_ebpf::maps::ring_buf::RingBuf::output<T: ?core::marker::Sized>(&self, data: &T, flags: u64) -> core::result::Result<(), i64>
pub const fn aya_ebpf::maps::ring_buf::RingBuf::pinned(byte_size: u32, flags: u32) -> Self
pub fn aya_ebpf::maps::ring_buf::RingBuf::query(&self, flags: u64) -> u64
pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where const_assert::Assert<{ _ }>: const_assert::IsTrue
pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where Assert<{ _ }>: IsTrue
pub const fn aya_ebpf::maps::ring_buf::RingBuf::with_byte_size(byte_size: u32, flags: u32) -> Self
impl core::marker::Sync for aya_ebpf::maps::ring_buf::RingBuf
impl !core::marker::Freeze for aya_ebpf::maps::ring_buf::RingBuf
Expand Down Expand Up @@ -1195,7 +1195,7 @@ impl aya_ebpf::maps::ring_buf::RingBuf
pub fn aya_ebpf::maps::ring_buf::RingBuf::output<T: ?core::marker::Sized>(&self, data: &T, flags: u64) -> core::result::Result<(), i64>
pub const fn aya_ebpf::maps::ring_buf::RingBuf::pinned(byte_size: u32, flags: u32) -> Self
pub fn aya_ebpf::maps::ring_buf::RingBuf::query(&self, flags: u64) -> u64
pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where const_assert::Assert<{ _ }>: const_assert::IsTrue
pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where Assert<{ _ }>: IsTrue
pub const fn aya_ebpf::maps::ring_buf::RingBuf::with_byte_size(byte_size: u32, flags: u32) -> Self
impl core::marker::Sync for aya_ebpf::maps::ring_buf::RingBuf
impl !core::marker::Freeze for aya_ebpf::maps::ring_buf::RingBuf
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn build<F>(target: Option<&str>, f: F) -> Result<Vec<(String, PathBuf)>>
where
F: FnOnce(&mut Command) -> &mut Command,
{
// Always use rust-lld and -Zbuild-std in case we're cross-compiling.
// Always use rust-lld in case we're cross-compiling.
let mut cmd = Command::new("cargo");
cmd.args(["build", "--message-format=json"]);
if let Some(target) = target {
Expand Down
Loading