Stream: git-wasmtime

Topic: wasmtime / PR #14967 Revise MPK support check to allow no...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek opened PR #14967 from V0ldek:v0ldek/amd-mpk to bytecodealliance:main:

While poking around in the pooling allocator I noticed that my machine actually does not use the MPK features, which was weird since I've used them before. Turns out AMD is just rejected by wasmtime for this feature. After looking into it I actually found a more critical issue.

The check for mpk::is_supported explicitly checked for GenuineIntel, and then for the PKU bit on the cpuid message. This is misguided for two reasons:

  1. Zen3 AMD also supports MPKs but wasmtime misses out on using them;
  2. the OSPKE bit also has to be checked to actually be correct.

Number 1. seems to have been done as an attempt to avoid CI crashes. In #7445, #7446 MPK was disabled and then reenabled for Intel only in PR #7513. I believe that was actually a red herring and those crashes were caused by the second point.

PKU only says if the CPU supports MPKs on the hardware level. However, the OS still needs to enable it (CR4.PKE). If it is not enabled, RDPKRU/WRPKRU raise #UD, which kills the process with SIGILL. An example is a VM that runs on a modern CPU as the hardware, but whose hypervisor has PKU disabled. This would actually fault on any vendor, Intel included. You can test it today on the old version by running wasmtime in QEMU with nopku passed (-append "nopku"), it will crash with the pooling allocator when it tries to set up PKs.

In this commit we switch to checking both PKE and OSPKE, removing the vendor check. This is confirmed to work on modern AMD and Intel, and correctly recognises MPK when ran under QEMU:

We now have a test in tests/mpk.rs to ensure the result of the check agrees with actual capabilities the process has.

Additionally, removed a stale test in pkru::tests::check_read, it was ignored since forever and the new mpk test supersedes it.

If you want confirmation on the CPU bits to be read:

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek removed the review request for wasmtime-core-reviewers from PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek requested pchickey for a review on PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek requested wasmtime-core-reviewers for a review on PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek requested fitzgen for a review on PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek requested wasmtime-default-reviewers for a review on PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 17:31):

V0ldek removed the review request for wasmtime-default-reviewers from PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 19:33):

pchickey removed the review request for pchickey from PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 19:33):

:memo: alexcrichton submitted PR review:

Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 19:33):

:speech_balloon: alexcrichton created PR review comment:

Could this be compiled/run on all platforms and non-x86_64 platforms exit with a failure? That'd help test that is_supported returns false on non-linux and non-x86_64 platforms fo example

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 19:33):

:speech_balloon: alexcrichton created PR review comment:

Instead of using #[test], coudl this test be written with harness = false like this test?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 20:30):

:memo: V0ldek submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 20:30):

:speech_balloon: V0ldek created PR review comment:

Maybe just assert that mpk::is_supported is false on non-x86?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 20:40):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 20:40):

:speech_balloon: alexcrichton created PR review comment:

That sounds reasonable yeah, but I think that'd naturally fall out of "the spawned subprocess failed" as opposed to special-casing it, where the special-casing would be the libc::syscall and asm! blocks.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 20:42):

:memo: V0ldek submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 20:42):

:speech_balloon: V0ldek created PR review comment:

Sure, may I ask why? What's the advantage?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 21:39):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 21:39):

:speech_balloon: alexcrichton created PR review comment:

I personally find that more precise than working around the built-in --test runner since it's easier to see fn main and see that it's doing funny business.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 21:41):

fitzgen removed the review request for fitzgen from PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:18):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:23):

:memo: V0ldek submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:23):

:speech_balloon: V0ldek created PR review comment:

Rewrote to not use a harness and used libtest_mimic like in the test you linked.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:35):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:36):

:memo: V0ldek submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:36):

:speech_balloon: V0ldek created PR review comment:

I'll need to work more on this and test how it interacts with different platforms. One finding is that I'm pretty sure we actually don't want to gate is_support behind x86_64 cause on 32-bit you can also use MPKs.

Another one is FreeBSD. They don't have libc pkey_alloc or pkey_free but they do support PKUs, so the is_support flag would actually say yes. Their API is different, so wasmtime would have to have a separate cfg path for FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=pkru&sektion=3.

I have no idea what happens on macOS and no means to test it either.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 23 2026 at 23:42):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 24 2026 at 01:53):

github-actions[bot] added the label wasmtime:api on PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 24 2026 at 14:53):

:memo: V0ldek submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 24 2026 at 14:53):

:speech_balloon: V0ldek created PR review comment:

So ARM also has its own MPK system, but it is different, e.g. they only have 7 usable keys instead of 15. It would also require rewriting the code in vm/mpk/pkru.rs.

At this point I honestly think that the test should just be "do we return false on those platforms", because FreeBSD and Linux on ARM support MPK architecturally, but wasmtime does not hook into that and it'd be a separate PR to allow that. I will try to figure out how hard it'd be for FreeBSD in this PR, but for ARM I have no machine to test it on so I wouldn't tackle that.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 24 2026 at 15:06):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 24 2026 at 15:14):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 24 2026 at 15:19):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 26 2026 at 15:07):

:thumbs_up: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 26 2026 at 15:07):

alexcrichton commented on PR #14967:

Looks like rustfmt needs a run before merging

view this post on Zulip Wasmtime GitHub notifications bot (Oct 27 2026 at 15:18):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 27 2026 at 16:06):

alexcrichton added PR #14967 Revise MPK support check to allow non-Intel CPUs. to the merge queue

view this post on Zulip Wasmtime GitHub notifications bot (Oct 27 2026 at 16:30):

github-merge-queue[bot] removed PR #14967 Revise MPK support check to allow non-Intel CPUs. from the merge queue

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2026 at 20:57):

V0ldek updated PR #14967.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2026 at 21:13):

alexcrichton added PR #14967 Revise MPK support check to allow non-Intel CPUs. to the merge queue

view this post on Zulip Wasmtime GitHub notifications bot (Oct 30 2026 at 21:37):

github-merge-queue[bot] removed PR #14967 Revise MPK support check to allow non-Intel CPUs. from the merge queue


Last updated: Oct 31 2026 at 23:03 UTC