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(wamr): add wasm-micro-runtime shim implementation #716

Merged
merged 20 commits into from
Nov 16, 2024

Conversation

Mossaka
Copy link
Member

@Mossaka Mossaka commented Nov 3, 2024

Follow up on the work done by #508 and #642. The runtime execution "thread signal env initialized failed" error was resolved by the upstream Wamr SDK and thus I used the latest sdk to re-build the wamr shim.

Now it actually worked!

sudo ctr run  --net-host --rm --runtime=io.containerd.wamr.v1 ghcr.io/containerd/runwasi/wasi-demo-app:latest testwasm /wasi-demo-app.wasm echo "hi"
hi
exiting

TODO

Maciej and others added 8 commits November 3, 2024 22:01
…error

upstream to the official wamr SDK solves this issue

Signed-off-by: jiaxiao zhou <[email protected]>
I believe there are more work to be done to parse the runtimeError
to appropriate exit code.

failures:
    wamr_tests::test_custom_entrypoint
    wamr_tests::test_exit_code
    wamr_tests::test_hello_world_oci
    wamr_tests::test_seccomp
    wamr_tests::test_unreachable

Signed-off-by: jiaxiao zhou <[email protected]>
Comment on lines 89 to 92
.or_else(|err| {
log::error!("Error: {:?}", err);
Err(err)
})
Copy link
Member Author

Choose a reason for hiding this comment

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

we should parse the RuntimeError to appropriate exit code. Any thoughts on this one, @lum1n0us?

Copy link

Choose a reason for hiding this comment

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

Regarding that, I just noticed that WAMR only uses error strings to convey information if something goes wrong during the execution of a Wasm function. So, if it's okay, can we continue to display the error string in the log and use a simple -1 and 0 to indicate failure and success, respectively?

Copy link
Member Author

@Mossaka Mossaka Nov 4, 2024

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

For example, how can I get exit code 42 from running this wasm module?

(module
    ;; Import the required proc_exit WASI function which terminates the program with an exit code.
    ;; The function signature for proc_exit is:
    ;; (exit_code: i32) -> !
    (import "wasi_snapshot_preview1" "proc_exit" (func $proc_exit (param i32)))
    (memory 1)
    (export "memory" (memory 0))
    (func $main (export "_start")
        (call $proc_exit (i32.const 42))
        unreachable
    )
)

Copy link

Choose a reason for hiding this comment

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

We have a fix for this situation. Please have a look.

Copy link
Member Author

Choose a reason for hiding this comment

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

Approved

Copy link

Choose a reason for hiding this comment

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

Merged

@Mossaka
Copy link
Member Author

Mossaka commented Nov 5, 2024

@lum1n0us do you know why the entrypoint_test failed?

thread 'wamr_tests::test_custom_entrypoint' panicked at crates/containerd-shim-wamr/src/tests.rs:58:5:
assertion `left == right` failed
  left: "hello world\n[00:08:01:896 - 7FA1CA910640]: warning: a module with WASI apis should be either a command or a reactor\n"
 right: "hello world\n"

@Mossaka
Copy link
Member Author

Mossaka commented Nov 5, 2024

@lum1n0us
Copy link

lum1n0us commented Nov 5, 2024

Yes, that's because WAMR enforces a strict application ABI check. Every wasm32-wasi .wasm should be classified as either a command or a reactor.

For your case,

  • either patch the case as a command, for example. Add a function like (func $start (export "_start"))
  • or WAMR turns off the WARNING messages by setting a higher log level.

@lum1n0us
Copy link

So, which option?

@Mossaka
Copy link
Member Author

Mossaka commented Nov 13, 2024

I disabled that test for now and I don't think we need to pass it to get this PR merged. Let me fix the linting issue.

if the target is windows, do not import the APIs
changed the compiler_error to panic!

Signed-off-by: jiaxiao zhou <[email protected]>
@Mossaka
Copy link
Member Author

Mossaka commented Nov 13, 2024

@jprendes @andreiltd can you give this PR a review please 🙏

@jprendes jprendes changed the title feat(wamr): add wasm-mico-runtime shim implementation feat(wamr): add wasm-micro-runtime shim implementation Nov 13, 2024
jprendes
jprendes previously approved these changes Nov 13, 2024
Copy link
Collaborator

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

LGTM, left a few comments and suggestions

crates/containerd-shim-wamr/Cargo.toml Show resolved Hide resolved
Comment on lines +15 to +16
unsafe impl Send for WamrEngine {}
unsafe impl Sync for WamrEngine {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Could you add a comment as to why this is safe to do? I guess Runtime is not Send/Sync, should Runtime be made Send/Sync upstream?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe the Runtime should be made Send / Sync upstream

Copy link
Member Author

Choose a reason for hiding this comment

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

@lum1n0us is this the case? Does Wamr Runtime contain any thread-local storage? Does it have any shared internal states?

Comment on lines +27 to +32
impl Clone for WamrEngine {
fn clone(&self) -> Self {
let runtime = Runtime::new().unwrap();
Self { runtime }
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Is this correct? doesn't Runtime hold any state? I don't remember why we require the engine to be Clone :-\

Copy link
Member Author

Choose a reason for hiding this comment

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

We want the Engine to be Clone because we want cheap copies of the Runtime for each container in the pod. This is the case for Wasmtime, WasmEdge and Wasmer. I believe it should be the case for Wamr as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But we don't clone the engine for each container, we clone the process...
In any case, if we create a new runtime with each clone, we might as well use a marker struct for the Engine and create a new runtime inside the run_wasi method.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I agree with you that we clone the entire process so there is no point to clone the engine.

In any case, if we create a new runtime with each clone,

at least for wasmtime, Engine::clone() is a cheap operation: https://docs.wasmtime.dev/api/wasmtime/struct.Engine.html#engines-and-clone

crates/containerd-shim-wamr/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wamr/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wamr/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wamr/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wamr/src/instance.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wamr/src/tests.rs Outdated Show resolved Hide resolved
crates/containerd-shim-wamr/src/tests.rs Outdated Show resolved Hide resolved
Mossaka and others added 3 commits November 13, 2024 22:15
@Mossaka Mossaka merged commit 01ff775 into containerd:main Nov 16, 2024
69 checks passed
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.

3 participants