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

Implement the pooling instance allocator. #2518

Merged
merged 33 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b58afbf
Refactor module instantiation in the runtime.
peterhuene Nov 26, 2020
c8871ee
Allow instance allocators control over module compilation.
peterhuene Dec 8, 2020
f0d93d1
Refactor runtime `Table` to support static storage.
peterhuene Dec 8, 2020
dd284ac
Store memories and tables on Instance as PrimaryMap.
peterhuene Dec 8, 2020
5beb81d
Change how Instance stores instantiated memories in the runtime.
peterhuene Dec 9, 2020
8457261
Ensure default allocator is used for instance deallocation.
peterhuene Dec 15, 2020
3bb145f
Only treat a memory as static when the minimum is also within bounds.
peterhuene Dec 16, 2020
16ca5e1
Implement allocating fiber stacks for an instance allocator.
peterhuene Feb 4, 2021
e71ccbf
Implement the pooling instance allocator.
peterhuene Dec 9, 2020
a2c4391
Implement user fault handling with `userfaultfd` on Linux.
peterhuene Feb 11, 2021
5b2f878
Allow zero-sized allocations on Windows for `Mmap`.
peterhuene Feb 11, 2021
a82f1a3
Skip the stack tests on Windows.
peterhuene Feb 11, 2021
f5c4d87
Implement on-demand memory initialization for the uffd feature.
peterhuene Feb 17, 2021
9091f13
Refactor `initialize_vmcontext`.
peterhuene Feb 18, 2021
f170d0b
Test the uffd feature on Linux.
peterhuene Feb 18, 2021
f48d1e2
Use slice::fill for filling tables.
peterhuene Feb 18, 2021
f533df0
Update the rustc badge to better reflect the supported version.
peterhuene Feb 18, 2021
89d3b5d
Switch CI back to latest nightly.
peterhuene Feb 18, 2021
a481e11
Add the `uffd` feature to the wasmtime crate docs.
peterhuene Feb 26, 2021
505437e
Code cleanup.
peterhuene Feb 27, 2021
4e83392
Fix bad merge.
peterhuene Mar 1, 2021
5ee2b87
Have `new_with_stack` impls return `io::Result`.
peterhuene Mar 3, 2021
a464465
Code review feedback changes.
peterhuene Mar 4, 2021
ff840b3
More PR feedback changes.
peterhuene Mar 4, 2021
a4084db
More feedback changes.
peterhuene Mar 5, 2021
a719076
More code review changes.
peterhuene Mar 5, 2021
1a04939
Make the storage of `wasmtime_runtime::Table` consistent.
peterhuene Mar 6, 2021
9801c68
Fail module translation for segments with overflowing offset+length.
peterhuene Mar 6, 2021
57dfe99
Run wast tests with both instance allocators.
peterhuene Mar 6, 2021
8e51aef
Extract out finding a passive segment.
peterhuene Mar 6, 2021
7a93132
Code review feedback.
peterhuene Mar 8, 2021
5fa0f8d
Move linear memory faulted guard page tracking into `Memory`.
peterhuene Mar 8, 2021
623290d
Use `anyhow::Error` in instantiation errors.
peterhuene Mar 8, 2021
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
35 changes: 22 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
# Note that we use nightly Rust here to get intra-doc links which are a
# nightly-only feature right now.
# Note that we use nightly Rust for the doc_cfg feature (enabled via `nightlydoc` above)
# This version is an older nightly for the new x64 backend (see below)
- uses: ./.github/actions/install-rust
with:
# TODO (rust-lang/rust#79661): We are seeing an internal compiler error when
# building with the latest (2020-12-06) nightly; pin on a slightly older
# version for now.
toolchain: nightly-2020-11-29
toolchain: nightly-2020-12-26
- run: cargo doc --no-deps --all --exclude wasmtime-cli --exclude test-programs --exclude cranelift-codegen-meta
- run: cargo doc --package cranelift-codegen-meta --document-private-items
- uses: actions/upload-artifact@v1
Expand Down Expand Up @@ -122,6 +119,7 @@ jobs:
- run: cargo check --manifest-path crates/wasmtime/Cargo.toml --features jitdump
- run: cargo check --manifest-path crates/wasmtime/Cargo.toml --features cache
- run: cargo check --manifest-path crates/wasmtime/Cargo.toml --features async
- run: cargo check --manifest-path crates/wasmtime/Cargo.toml --features uffd

# Check some feature combinations of the `wasmtime-c-api` crate
- run: cargo check --manifest-path crates/c-api/Cargo.toml --no-default-features
Expand Down Expand Up @@ -167,7 +165,7 @@ jobs:
# flags to rustc.
- uses: ./.github/actions/install-rust
with:
toolchain: nightly-2020-11-29
toolchain: nightly
- run: cargo install cargo-fuzz --vers "^0.8"
- run: cargo fetch
working-directory: ./fuzz
Expand Down Expand Up @@ -224,7 +222,7 @@ jobs:
rust: beta
- build: nightly
os: ubuntu-latest
rust: nightly-2020-11-29
rust: nightly
- build: macos
os: macos-latest
rust: stable
Expand Down Expand Up @@ -303,6 +301,15 @@ jobs:
env:
RUST_BACKTRACE: 1

# Test uffd functionality on Linux
- run: |
cargo test --features uffd -p wasmtime-runtime instance::allocator::pooling
cargo test --features uffd -p wasmtime-cli pooling_allocator
alexcrichton marked this conversation as resolved.
Show resolved Hide resolved
cargo test --features uffd -p wasmtime-cli wast::Cranelift
if: matrix.os == 'ubuntu-latest'
env:
RUST_BACKTRACE: 1

# Build and test lightbeam. Note that
# Lightbeam tests fail right now, but we don't want to block on that.
- run: cargo build --package lightbeam
Expand All @@ -312,8 +319,10 @@ jobs:
RUST_BACKTRACE: 1

# Perform all tests (debug mode) for `wasmtime` with the experimental x64
# backend. This runs on the nightly channel of Rust (because of issues with
# unifying Cargo features on stable) on Ubuntu.
# backend. This runs on an older nightly of Rust (because of issues with
# unifying Cargo features on stable) on Ubuntu such that it's new enough
# to build Wasmtime, but old enough where the -Z options being used
# haven't been stabilized yet.
test_x64:
name: Test x64 new backend
runs-on: ubuntu-latest
Expand All @@ -323,7 +332,7 @@ jobs:
submodules: true
- uses: ./.github/actions/install-rust
with:
toolchain: nightly-2020-11-29
toolchain: nightly-2020-12-26
- uses: ./.github/actions/define-llvm-env

# Install wasm32 targets in order to build various tests throughout the
Expand All @@ -334,7 +343,7 @@ jobs:
# Run the x64 CI script.
- run: ./ci/run-experimental-x64-ci.sh
env:
CARGO_VERSION: "+nightly-2020-11-29"
CARGO_VERSION: "+nightly-2020-12-26"
RUST_BACKTRACE: 1

# Build and test the wasi-nn module.
Expand All @@ -347,7 +356,7 @@ jobs:
submodules: true
- uses: ./.github/actions/install-rust
with:
toolchain: nightly-2020-11-29
toolchain: nightly
- run: rustup target add wasm32-wasi
- uses: ./.github/actions/install-openvino
- run: ./ci/run-wasi-nn-example.sh
Expand Down
68 changes: 67 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jitdump = ["wasmtime/jitdump"]
vtune = ["wasmtime/vtune"]
wasi-crypto = ["wasmtime-wasi-crypto"]
wasi-nn = ["wasmtime-wasi-nn"]
uffd = ["wasmtime/uffd"]

# Try the experimental, work-in-progress new x86_64 backend. This is not stable
# as of June 2020.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p>
<a href="https://github.com/bytecodealliance/wasmtime/actions?query=workflow%3ACI"><img src="https://github.com/bytecodealliance/wasmtime/workflows/CI/badge.svg" alt="build status" /></a>
<a href="https://bytecodealliance.zulipchat.com/#narrow/stream/217126-wasmtime"><img src="https://img.shields.io/badge/zulip-join_chat-brightgreen.svg" alt="zulip chat" /></a>
<img src="https://img.shields.io/badge/rustc-1.37+-green.svg" alt="min rustc" />
<img src="https://img.shields.io/badge/rustc-stable+-green.svg" alt="supported rustc stable" />
<a href="https://docs.rs/wasmtime"><img src="https://docs.rs/wasmtime/badge.svg" alt="Documentation Status" /></a>
</p>

Expand Down
20 changes: 16 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ fn test_directory(

let testsuite = &extract_name(path);
for entry in dir_entries.iter() {
write_testsuite_tests(out, entry, testsuite, strategy)?;
write_testsuite_tests(out, entry, testsuite, strategy, false)?;
write_testsuite_tests(out, entry, testsuite, strategy, true)?;
}

Ok(dir_entries.len())
Expand Down Expand Up @@ -148,6 +149,7 @@ fn write_testsuite_tests(
path: impl AsRef<Path>,
testsuite: &str,
strategy: &str,
pooling: bool,
) -> anyhow::Result<()> {
let path = path.as_ref();
let testname = extract_name(path);
Expand All @@ -160,14 +162,24 @@ fn write_testsuite_tests(
)?;
} else if ignore(testsuite, &testname, strategy) {
writeln!(out, "#[ignore]")?;
} else if pooling {
// Ignore on aarch64 due to using QEMU for running tests (limited memory)
writeln!(out, r#"#[cfg_attr(target_arch = "aarch64", ignore)]"#)?;
}
writeln!(out, "fn r#{}() {{", &testname)?;

writeln!(
out,
"fn r#{}{}() {{",
&testname,
if pooling { "_pooling" } else { "" }
)?;
writeln!(out, " let _ = env_logger::try_init();")?;
writeln!(
out,
" crate::wast::run_wast(r#\"{}\"#, crate::wast::Strategy::{}).unwrap();",
" crate::wast::run_wast(r#\"{}\"#, crate::wast::Strategy::{}, {}).unwrap();",
path.display(),
strategy
strategy,
pooling
)?;
writeln!(out, "}}")?;
writeln!(out)?;
Expand Down
2 changes: 2 additions & 0 deletions cranelift/wasm/src/module_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub fn translate_module<'data>(

Payload::DataCountSection { count, range } => {
validator.data_count_section(count, &range)?;

// NOTE: the count here is the total segment count, not the passive segment count
environ.reserve_passive_data(count)?;
}

Expand Down
12 changes: 12 additions & 0 deletions cranelift/wasm/src/sections_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ pub fn parse_element_section<'data>(
));
}
};
// Check for offset + len overflow
if offset.checked_add(segments.len()).is_none() {
return Err(wasm_unsupported!(
"element segment offset and length overflows"
));
}
environ.declare_table_elements(
TableIndex::from_u32(table_index),
base,
Expand Down Expand Up @@ -447,6 +453,12 @@ pub fn parse_data_section<'data>(
))
}
};
// Check for offset + len overflow
if offset.checked_add(data.len()).is_none() {
return Err(wasm_unsupported!(
"data segment offset and length overflows"
));
}
environ.declare_data_initialization(
MemoryIndex::from_u32(memory_index),
base,
Expand Down
4 changes: 2 additions & 2 deletions crates/c-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub extern "C" fn wasmtime_config_consume_fuel_set(c: &mut wasm_config_t, enable
}

#[no_mangle]
pub extern "C" fn wasmtime_config_max_wasm_stack_set(c: &mut wasm_config_t, size: usize) {
c.config.max_wasm_stack(size);
pub extern "C" fn wasmtime_config_max_wasm_stack_set(c: &mut wasm_config_t, size: usize) -> bool {
c.config.max_wasm_stack(size).is_ok()
}

#[no_mangle]
Expand Down
1 change: 1 addition & 0 deletions crates/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2018"

[dependencies]
anyhow = "1.0"
region = "2.2.0"
cranelift-codegen = { path = "../../cranelift/codegen", version = "0.71.0", features = ["enable-serde"] }
cranelift-entity = { path = "../../cranelift/entity", version = "0.71.0", features = ["enable-serde"] }
cranelift-wasm = { path = "../../cranelift/wasm", version = "0.71.0", features = ["enable-serde"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod isa {
}

pub mod entity {
pub use cranelift_entity::{packed_option, BoxedSlice, EntityRef, PrimaryMap};
pub use cranelift_entity::{packed_option, BoxedSlice, EntityRef, EntitySet, PrimaryMap};
}

pub mod wasm {
Expand Down
Loading