From f0544426d2c2c9ca49fe68325e5ccd133dd52ac7 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Fri, 10 Apr 2020 14:26:04 -0700 Subject: [PATCH] Enable the `uffd` feature by default, but filter on OS Notably, this should get us building and running uffd in Linux CI. It turns out to be a tremendous pain to enable a feature flag for just one crate within a workspace. The situation is [being addressed][1], but in the meantime I believe the best route forward is to just have uffd on by default for Linux. [1]: https://github.com/rust-lang/cargo/issues/5364 --- lucet-runtime/Cargo.toml | 2 +- lucet-runtime/lucet-runtime-internals/Cargo.toml | 4 +++- lucet-runtime/lucet-runtime-internals/src/region.rs | 2 +- lucet-runtime/src/c_api.rs | 4 ++-- lucet-runtime/src/lib.rs | 11 +++++++++-- lucet-runtime/tests/entrypoint.rs | 2 +- lucet-runtime/tests/globals.rs | 2 +- lucet-runtime/tests/guest_fault.rs | 2 +- lucet-runtime/tests/host.rs | 2 +- lucet-runtime/tests/memory.rs | 2 +- lucet-runtime/tests/stack.rs | 2 +- lucet-runtime/tests/start.rs | 2 +- lucet-runtime/tests/strcmp.rs | 2 +- lucet-runtime/tests/timeout.rs | 2 +- 14 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lucet-runtime/Cargo.toml b/lucet-runtime/Cargo.toml index fb1d88996..174a64b60 100644 --- a/lucet-runtime/Cargo.toml +++ b/lucet-runtime/Cargo.toml @@ -49,7 +49,7 @@ assets = [ ] [features] -default-features = [] +default = ["uffd"] uffd = ["lucet-runtime-internals/uffd"] [package.metadata.docs.rs] diff --git a/lucet-runtime/lucet-runtime-internals/Cargo.toml b/lucet-runtime/lucet-runtime-internals/Cargo.toml index 174e1e995..39f284d3e 100644 --- a/lucet-runtime/lucet-runtime-internals/Cargo.toml +++ b/lucet-runtime/lucet-runtime-internals/Cargo.toml @@ -27,6 +27,8 @@ num-traits = "0.2" raw-cpuid = "6.0.0" thiserror = "1.0.4" tracing = "0.1.12" + +[target.'cfg(target_os = "linux")'.dependencies] userfaultfd = { version = "0.1.0", optional = true } # This is only a dependency to ensure that other crates don't pick a newer version as a transitive @@ -43,7 +45,7 @@ byteorder = "1.2" cc = "1.0" [features] -default-features = [] +default = ["uffd"] uffd = ["userfaultfd"] [package.metadata.docs.rs] diff --git a/lucet-runtime/lucet-runtime-internals/src/region.rs b/lucet-runtime/lucet-runtime-internals/src/region.rs index 5b1f48ede..26bc20054 100644 --- a/lucet-runtime/lucet-runtime-internals/src/region.rs +++ b/lucet-runtime/lucet-runtime-internals/src/region.rs @@ -1,6 +1,6 @@ pub mod mmap; -#[cfg(feature = "uffd")] +#[cfg(all(target_os = "linux", feature = "uffd"))] pub mod uffd; use crate::alloc::{Alloc, Limits, Slot}; diff --git a/lucet-runtime/src/c_api.rs b/lucet-runtime/src/c_api.rs index c62b8502f..9eb277770 100644 --- a/lucet-runtime/src/c_api.rs +++ b/lucet-runtime/src/c_api.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "uffd")] +#[cfg(all(target_os = "linux", feature = "uffd"))] use crate::UffdRegion; use crate::{DlModule, Instance, Limits, MmapRegion, Module, Region}; use libc::{c_char, c_int, c_void}; @@ -103,7 +103,7 @@ pub unsafe extern "C" fn lucet_uffd_region_create( region_out: *mut *mut lucet_region, ) -> lucet_error { cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { assert_nonnull!(region_out); let limits = limits .as_ref() diff --git a/lucet-runtime/src/lib.rs b/lucet-runtime/src/lib.rs index 6c30b83e2..ca1e0abf1 100644 --- a/lucet-runtime/src/lib.rs +++ b/lucet-runtime/src/lib.rs @@ -386,7 +386,14 @@ //! `Instance`, reducing startup time. Instance stack pages can also be lazily initialized, reducing //! the memory footprint of instances that only use a small portion of their available stack space. //! -//! To use `UffdRegion`, enable the `uffd` Cargo feature, which is off by default. +//! `UffdRegion` is enabled by default on Linux platforms, but can be disabled by disabling default +//! features for this crate and `lucet-runtime-internals`: +//! +//! ```toml +//! [dependencies] +//! lucet-runtime = { version = "0.6.1", default-features = false } +//! lucet-runtime-internals = { version = "0.6.1", default-features = false } +//! ``` #![deny(bare_trait_objects)] @@ -410,7 +417,7 @@ pub use lucet_runtime_internals::instance::{ pub use lucet_runtime_internals::lucet_hostcalls; pub use lucet_runtime_internals::module::{DlModule, Module}; pub use lucet_runtime_internals::region::mmap::MmapRegion; -#[cfg(feature = "uffd")] +#[cfg(all(target_os = "linux", feature = "uffd"))] pub use lucet_runtime_internals::region::uffd::UffdRegion; pub use lucet_runtime_internals::region::{InstanceBuilder, Region, RegionCreate}; pub use lucet_runtime_internals::val::{UntypedRetVal, Val}; diff --git a/lucet-runtime/tests/entrypoint.rs b/lucet-runtime/tests/entrypoint.rs index 8bcc32819..a3ecfb89a 100644 --- a/lucet-runtime/tests/entrypoint.rs +++ b/lucet-runtime/tests/entrypoint.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::entrypoint_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { entrypoint_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/globals.rs b/lucet-runtime/tests/globals.rs index 90c34cb5a..4927a5c45 100644 --- a/lucet-runtime/tests/globals.rs +++ b/lucet-runtime/tests/globals.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::globals_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { globals_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/guest_fault.rs b/lucet-runtime/tests/guest_fault.rs index 74df066ac..019730be2 100644 --- a/lucet-runtime/tests/guest_fault.rs +++ b/lucet-runtime/tests/guest_fault.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::guest_fault_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { guest_fault_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/host.rs b/lucet-runtime/tests/host.rs index 4874a8a24..5404c2c15 100644 --- a/lucet-runtime/tests/host.rs +++ b/lucet-runtime/tests/host.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::host_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { host_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/memory.rs b/lucet-runtime/tests/memory.rs index cc48db9ef..f6488f06b 100644 --- a/lucet-runtime/tests/memory.rs +++ b/lucet-runtime/tests/memory.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::memory_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { memory_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/stack.rs b/lucet-runtime/tests/stack.rs index abf2c9dce..bc8e33e85 100644 --- a/lucet-runtime/tests/stack.rs +++ b/lucet-runtime/tests/stack.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::stack_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { stack_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/start.rs b/lucet-runtime/tests/start.rs index c9def4f89..09923054f 100644 --- a/lucet-runtime/tests/start.rs +++ b/lucet-runtime/tests/start.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::start_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { start_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/strcmp.rs b/lucet-runtime/tests/strcmp.rs index afebc4d26..badd163c1 100644 --- a/lucet-runtime/tests/strcmp.rs +++ b/lucet-runtime/tests/strcmp.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::strcmp_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { strcmp_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion diff --git a/lucet-runtime/tests/timeout.rs b/lucet-runtime/tests/timeout.rs index 7c1872ef7..8a9492b42 100644 --- a/lucet-runtime/tests/timeout.rs +++ b/lucet-runtime/tests/timeout.rs @@ -1,7 +1,7 @@ use lucet_runtime_tests::timeout_tests; cfg_if::cfg_if! { - if #[cfg(feature = "uffd")] { + if #[cfg(all(target_os = "linux", feature = "uffd"))] { timeout_tests!( mmap => lucet_runtime::MmapRegion, uffd => lucet_runtime::UffdRegion