Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

allow instance to be reentered while yielding#12153

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dicej wants to merge2 commits intobytecodealliance:main
base:main
Choose a base branch
Loading
fromdicej:fix-12128

Conversation

@dicej
Copy link
Contributor

The spec says we should allow this, so now we do.

Thansk to Alex for the test case!

Fixes#12128

@dicejdicej requested a review froma team as acode ownerDecember 10, 2025 22:36
Copy link
Member

@alexcrichtonalexcrichton left a comment

Choose a reason for hiding this comment

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

Code/test all look fine, but I'm trying to correlate this with the spec as well. I thought I remember that historicallymay_enter was a thing but it's no longer present inCanonicalABI.md. Can you clarify which point in the spec I should be looking at to double-check this? (and probably queue up some sort of rename/refactor to handlemay_enter to align with the spec)

@dicej
Copy link
ContributorAuthor

dicej commentedDec 10, 2025
edited
Loading

Code/test all look fine, but I'm trying to correlate this with the spec as well. I thought I remember that historicallymay_enter was a thing but it's no longer present inCanonicalABI.md. Can you clarify which point in the spec I should be looking at to double-check this? (and probably queue up some sort of rename/refactor to handlemay_enter to align with the spec)

Search fortrap_if_on_the_stack inCanonicalABI.md and the prose that follows. I agree that some renaming and/or refactoring may be due.

@dicej
Copy link
ContributorAuthor

dicej commentedDec 10, 2025
edited
Loading

I'm investigating the test failure;looks like dropping a subtask while it's yielding in an infinite loop will require some extra care. EDIT: the problem is more fundamental than that, and the refactoring Alex suggested above is going to be necessary in order to fix#12128 properly.

@github-actionsgithub-actionsbot added the wasmtime:apiRelated to the API of the `wasmtime` crate itself labelDec 11, 2025
@alexcrichton
Copy link
Member

Joel and I discussed this and the conclusion is that themay_enter handling in Wasmtime is outdated and no longer in sync with the spec after component-model-async refactors. Effectively we need to rebuild the reentrance check from scratch throughout Wasmtime and avoid usingmay_enter for the triple-purpose of: preventing reentrance, requiringpost_return, and lockdown-on-trap. This'll require refactors internally to use a new component-model-async helper but willhave an impact on component adapter performance as well. This all corresponds totrap_if_on_the_stack in the spec (scroll down a bit)

@dicejdicej requested a review froma team as acode ownerDecember 16, 2025 22:04
@dicejdicej requested review fromcfallin and removed request fora teamDecember 16, 2025 22:04
@dicejdicejforce-pushed thefix-12128 branch 2 times, most recently fromc2e3b0a tofbb2cf2CompareDecember 16, 2025 22:39
Now that the component model supports multiple tasks and cooperative threadsrunning concurrently in the same instance, the old model of using a per-instanceflag to track whether a component may be entered no longer works.  Instead ofkeeping track of whether an instance has been entered at all, we must now keeptrack of whether an instance has been entered for each in-progress task.This commit removes `FLAG_MAY_ENTER` from `InstanceFlags`, relying instead on aper-task call stack maintained at runtime.  When the `component-model-async`feature is enabled, we reuse the `GuestTask` stack for this purpose.  When the`component-model-async` feature is disabled, there's just a single stack usedfor the entire store.  Note that these stacks are only updated when crossingcomponent boundaries -- not at every internal call within an instance.Each time we're about to enter a instance from either the host or the guest, wecheck the call stack, and if the instance is already present, we trap.Otherwise, we push a new element onto the stack and later pop it back off oncethe callee returns a value.In addition to trapping on recursive reentrance, we do a couple of additionalchecks for host-to-guest calls, for which we previously relied on`FLAG_MAY_ENTER`:- If _any_ instance owned by the store has previously trapped, we disallow entering that or any other instance owned by the store.- If a post-return call is needed for an instance, we disallow entering it until that call has been made.Note that, for sync-to-sync, guest-to-guest calls, the above process entailssignificantly more overhead than the prior code, which only involved checkingand setting a flag and did not require calling into the host at all.  I intendto follow this PR up with one or more optimizations to reduce that overhead.See the discussion of `trap_if_on_the_stack` inhttps://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.mdfor examples of such optimizations.In addition to the above refactoring, this commit does a couple of relatedthings:- When a host function recursively calls back into guest code, we now chain the old call stack to the new one.  This allows us to catch recursive reentrance which may span multiple top-level instances.- Previously, we did not push a new task on the stack for sync-to-sync, guest-to-guest calls, which meant we missed catching some violations of the sync-task-must-not-block-before-returning rule.  Now that we are pushing a new task in that case, we catch all such violations, which means some of the existing WAST tests needed updating.Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@alexcrichtonalexcrichtonalexcrichton left review comments

@cfallincfallinAwaiting requested review from cfallincfallin is a code owner automatically assigned from bytecodealliance/wasmtime-compiler-reviewers

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

wasmtime:apiRelated to the API of the `wasmtime` crate itself

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

component-model-async: Cannot reenter component during a task's yield?

2 participants

@dicej@alexcrichton

[8]ページ先頭

©2009-2025 Movatter.jp