-
Notifications
You must be signed in to change notification settings - Fork 15
3i: Refactor vmctx storage and grate call execution path #571
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
base: main
Are you sure you want to change the base?
Conversation
End-to-End Test ReportTest PreviewTest Report Deterministic TestsSummary
Test Results by Category
Non Deterministic TestsSummary
Test Results by Category
Fail TestsSummary
Test Results by Category
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // for functions that require a fixed number of parameters but do not utilize | ||
| // all of them. | ||
| use wasmtime_lind_3i::take_gratefn_wasm; | ||
| // use wasmtime_lind_3i::take_gratefn_wasm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code
| /// Used in the `state` field of `GrateFnEntry` of wasmtime 3i. | ||
| pub const STATE_DEAD: u8 = 2; | ||
| /// The value is expected to be globally unique among all runtimes registered with 3i | ||
| pub const RUNTIME_WASMTIME: u64 = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth using a number other than 1 here for debug purposes. RUNTIME_TYPE_WASMTIME is a bit clearer but possibly could be an enum?
| /// Used by [`lind-common::register_handler`] to fetch the previously staged entry and pass its pointer into 3i. | ||
| /// Performs a read-locked lookup of `(cageid, 0)` in `GRATE_FN_WASM_TABLE` | ||
| /// `get_vmctx` looks up the `VMContext` associated with a given cage and thread. | ||
| /// It returns a copy of the stored `VmCtxWrapper`, or `None` if no entry exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a bit unclear about the terminology here and am not sure whats going on, can we try rewriting this in as plain language as possible? This part is probably important that we all understand/get right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like from my understanding when we were talking about ctx pooling last week we wanted separate deep copies of the ctx's. This seems to say the opposite? Or is this a separate issue?
| false, /* this is not the main thread */ | ||
| ); | ||
|
|
||
| // The main challenge in enabling dynamic syscall interposition between grates and 3i lies in Rust’s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i feel like we reiterate in the comments about the "lifetime challenge a lot" not sure we need to be so verbose about this
| if ctx.is_null() { | ||
| return threei_const::GRATE_ERR; | ||
| } | ||
| let threadid = 1; //always 1. Only fork requires threadid passing, and fork is handled specially |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems weird, or at least the comment seems misdirecting?
rennergade
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few questions here.
In lind-wasm, execution needs to re-enter Wasmtime from outside the current instance or call stack. Two common cases are:
Both cases require an explicit way to recover the correct Wasmtime runtime state (store + instance) for an arbitrary
(cage_id, thread_id)pair. Relying on an implicit “current instance” is not sufficient.Implementation
This PR moves a low-level runtime-state lookup mechanism based on Wasmtime’s
VMContextpointer from 3i to wasmtime:VMContextpointer is extracted and stored in a global table keyed by(cage_id, thread_id).The table stores raw pointers rather than typed handles.
VMContext storage refactoring and execution semantics
This PR resolves #538. Wasmtime stores a single
VMContextpointer per(cage_id, thread_id). When a grate call is executed, theVMContextpointer is retrieved and copied using Rust’sCopysemantics. The copied wrapper is used for the duration of the call and then immediately dropped.Conceptually, this behaves like a single-element context pool with immediate acquire-and-release, but without introducing additional storage or bookkeeping.
Wasmtime instantiation extensions
To minimize divergence from upstream Wasmtime code:
new_started_implremains unchanged.new_started_impl_with_lindis used for cage creation and performs lind-specific memory initialization.new_started_impl_with_lind_thread, is introduced for thread creation. Threads do not require cage-level memory initialization, but they do require returning an InstanceId so the VMContext can be registered.3i runtime-agnostic grate dispatch
This PR clarifies the execution boundary between 3i and runtimes:
_call_grate_funcresolves the runtime and delegates execution entirely to the runtime-provided trampoline.In the current implementation, the Wasmtime runtime registers
grate_callback_trampoline(inwasmtime/run.rs), which:VMContextfor the target grate,3i itself remains runtime-agnostic and does not execute grate code directly.
Test
New tests for multiple register_handler calls.