Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Move AsyncContext to field on Instance rather than field on State #644

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benaubin
Copy link
Contributor

@benaubin benaubin commented Feb 26, 2021

Addresses #643. @pchickey

Here's the code diff versus main, prior to the revert of #626: 2a02670...benaubin:custom-run-async-future

@benaubin benaubin changed the title Move AsyncContext to field on Instance rather than field on State WIP: Move AsyncContext to field on Instance rather than field on State Feb 26, 2021
@benaubin benaubin changed the title WIP: Move AsyncContext to field on Instance rather than field on State Move AsyncContext to field on Instance rather than field on State Feb 26, 2021
@benaubin
Copy link
Contributor Author

benaubin commented Feb 26, 2021

Side note: it's kind of ironic that the Arc, which I originally introduced to remove unsafe/potentially unsound code, ended up causing an unsoundness issue.

@benaubin
Copy link
Contributor Author

benaubin commented Feb 27, 2021

Rebased onto main. Squashed all the changes together to make it easier to cherry-pick onto #643.

@kaisa001
Copy link

kaisa001 commented Feb 27, 2021 via email

@benaubin
Copy link
Contributor Author

Translation: image

@pchickey
Copy link
Contributor

pchickey commented Mar 1, 2021

As a quick update - the Lucet folks at Fastly have discussed this and we are keen on removing the asynchronous (signal-based) timeouts feature in favor of synchronous fuel-based timeouts. Our first reason is that making that change will make this code sound: all rust code that is safe ought to be sound, and the way in which this was unsound was surprising to us, the "experts", so how could anyone be confident? The second reason to get rid of asynchronous timeouts is that Wasmtime doesn't have them, and we don't think we want to add them there. Fastly and other Lucet users will need a migration path to Wasmtime and, if that feature can't ever migrate, we should get rid of it.

@benaubin
Copy link
Contributor Author

benaubin commented Mar 1, 2021

@pchickey I agree with that rationale. Should there be a new issue to discuss replacing async signals? This PR sidesteps the signal safety issue entirely by moving the Arc to the instance, rather than State.

As a stopgap, forcing State to derive Copy will prevent any field from implementing Drop, preventing unsound behavior. Of course, that would require adjusting the Yielded state to remove Box

@benaubin
Copy link
Contributor Author

benaubin commented Mar 1, 2021

On removing signals: I don't love gas/instruction counting as the sole criteria for stopping instances, because malicious guests can consume a much larger (orders of magnitude more) amount of CPU time (such as by forcing a large number of cache misses), versus benevolent guests.

Would it be sound to call a user-defined function for on_bound_expired? Then, it would be possible to check metrics like CPU time without having to pay a context switch each time.

Note: no matter what, signals will need to be handled by the instance. Especially SIGFPE/SIGSEGV, which could maybe be caused by a faulty guest, and should (probably) be handled with guest termination.

@benaubin
Copy link
Contributor Author

benaubin commented Mar 1, 2021

Also, in case it helps review, here's the code diff versus the commit on main immediately prior to the revert of #626: 2a02670...benaubin:custom-run-async-future

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants