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

feat: fvm-wasm-instrument stack limiter and gas #494

Merged
merged 31 commits into from
May 4, 2022

Conversation

magik6k
Copy link
Contributor

@magik6k magik6k commented Apr 14, 2022

No description provided.

@Stebalien
Copy link
Member

This looks like the correct approach, but do we need to do any pre-validation first?

@magik6k magik6k force-pushed the feat/wasm-instrumentation branch 3 times, most recently from 3cab1fa to 0e5d64c Compare April 20, 2022 12:05
@magik6k
Copy link
Contributor Author

magik6k commented Apr 20, 2022

Depends on filecoin-project/fvm-wasm-instrument#3

@magik6k magik6k changed the title WIP feat: fvm-wasm-instrument stack limiter WIP feat: fvm-wasm-instrument stack limiter and gas Apr 21, 2022
@magik6k magik6k force-pushed the feat/wasm-instrumentation branch 3 times, most recently from 28d64ed to 7ca7a63 Compare April 24, 2022 14:03
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/syscalls/bind.rs Outdated Show resolved Hide resolved
@magik6k magik6k force-pushed the feat/wasm-instrumentation branch 4 times, most recently from 2528ed8 to 7774b8e Compare April 25, 2022 12:08
@magik6k magik6k marked this pull request as ready for review April 25, 2022 12:12
@magik6k magik6k changed the title WIP feat: fvm-wasm-instrument stack limiter and gas feat: fvm-wasm-instrument stack limiter and gas Apr 25, 2022
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review

fvm/src/call_manager/default.rs Outdated Show resolved Hide resolved
fvm/src/call_manager/default.rs Outdated Show resolved Hide resolved
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/gas/price_list.rs Outdated Show resolved Hide resolved
fvm/src/machine/engine.rs Outdated Show resolved Hide resolved
fvm/src/machine/engine.rs Outdated Show resolved Hide resolved
fvm/src/syscalls/bind.rs Outdated Show resolved Hide resolved
fvm/src/syscalls/bind.rs Outdated Show resolved Hide resolved
fvm/src/call_manager/default.rs Outdated Show resolved Hide resolved
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/gas/price_list.rs Outdated Show resolved Hide resolved
fvm/src/kernel/mod.rs Outdated Show resolved Hide resolved
fvm/src/machine/engine.rs Show resolved Hide resolved
fvm/src/machine/engine.rs Outdated Show resolved Hide resolved
@magik6k magik6k force-pushed the feat/wasm-instrumentation branch 2 times, most recently from c5b660b to 5c108f3 Compare April 28, 2022 11:25
@magik6k
Copy link
Contributor Author

magik6k commented Apr 28, 2022

Related ffi PR: filecoin-project/filecoin-ffi#273

@magik6k magik6k force-pushed the feat/wasm-instrumentation branch 2 times, most recently from b28b727 to 1e06f7b Compare April 29, 2022 15:03
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits, but the logic LGTM.

fvm/src/call_manager/default.rs Outdated Show resolved Hide resolved
fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
fvm/src/gas/price_list.rs Outdated Show resolved Hide resolved
fvm/src/lib.rs Outdated Show resolved Hide resolved
@@ -55,23 +104,20 @@ pub fn default_wasmtime_config() -> wasmtime::Config {
// > not enabled by default.
c.cranelift_nan_canonicalization(true);

// c.cranelift_opt_level(Speed); ?
// Set to something much higher than the instrumented limiter.
c.max_wasm_stack(64 << 20).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: make sure this doesn't force us to allocate 64MiB per container.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a backstop? Why do we need it? I guess because it can't be disabled entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the default is 512k

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell wasm execution uses the native stack - when this is set to a high value the out_of_stack test will fail with:

thread 'out_of_stack' has overflowed its stack
fatal runtime error: stack overflow

Given that, I don't think we're allocating here

fvm/src/machine/engine.rs Outdated Show resolved Hide resolved
fvm/src/machine/engine.rs Outdated Show resolved Hide resolved
Comment on lines +160 to +162
let out = syscall(ctx $(, $t)*).into();

let result = match out {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can re-combine these lines now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We'll split them again if we merge #465.)

Comment on lines 158 to 175
let (mut memory, mut data) = memory_and_data(&mut caller)?;
let ctx = Context{kernel: &mut data.kernel, memory: &mut memory};
let result = match syscall(ctx $(, $t)*).into()? {
Ok(_) => {
let out = syscall(ctx $(, $t)*).into();

let result = match out {
Ok(Ok(_)) => {
log::trace!("syscall {}::{}: ok", module, name);
data.last_error = None;
0
Ok(0)
},
Err(err) => {
Ok(Err(err)) => {
let code = err.1;
log::trace!("syscall {}::{}: fail ({})", module, name, code as u32);
data.last_error = Some(backtrace::Cause::new(module, name, err));
code as u32
Ok(code as u32)
},
Err(e) => Err(e.into()),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider wrapping all of this in a closure (and immediately calling it) to make trapping errors a bit easier.

(NetworkVersion::V14, actors_v6::BUNDLE_CAR),
(NetworkVersion::V15, actors_v7::BUNDLE_CAR),
(NetworkVersion::V16, actors_v7::BUNDLE_CAR), // todo bad hack
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is because we still don't have a release for v8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the integration test runner needs a bundle to load, even if we don't use any actor code. Ideally we could run integration tests without actor bundles - that would also make those tests run much faster.

fvm/src/gas/mod.rs Outdated Show resolved Hide resolved
@magik6k magik6k force-pushed the feat/wasm-instrumentation branch from 95d1f37 to ea08252 Compare May 4, 2022 19:38
@Stebalien Stebalien enabled auto-merge (squash) May 4, 2022 19:54
@Stebalien Stebalien merged commit f4a7473 into master May 4, 2022
@Stebalien Stebalien deleted the feat/wasm-instrumentation branch May 4, 2022 19:58
@raulk raulk mentioned this pull request May 5, 2022
48 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants