-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
mpk: restore PKRU state when a fiber resumes execution #7789
Conversation
This probably needs an |
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
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.
Looks good to me 👍
With a test that fails without this change I think it's good-to-go.
Previously, when a fiber was suspended, other computation could change the PKRU state on the current CPU. This means that the fiber could be resumed with a different PKRU state. This could be bad, resulting in situations in which the fiber can access more memory slots than it should or cannot even access its own memory slots. This change saves the PKRU state prior to a fiber being suspended. When the fiber resumes execution, that PKRU state is restored.
This adds a test that alternately polls two Wasm instances in a loop. Since the instances are async, we can set up epochs to suspend each fiber as we iterate over a loop. Because we alternate between the two instances, it checks that `AsyncCx::block_on` has correctly restored the PKRU bits; otherwise we should see test failures. In the process of writing this test I discovered bytecodealliance#7942, which can be solved separately (it has to do with the interaction between memory images, _not_ used here, and MPK). prtest:full
Not all stores have protection keys and MPK is not always enabled. This change checks for these conditions before context-switching the PKRU bits.
Previously, when a fiber was suspended, other computation could change the PKRU state on the current CPU. This means that the fiber could be resumed with a different PKRU state. This could be bad, resulting in situations in which the fiber can access more memory slots than it should or cannot even access its own memory slots.
This change saves the PKRU state prior to a fiber being suspended. When the fiber resumes execution, that PKRU state is restored.