posk-io opened PR #15312 from posk-io:posk/nostd-threads to bytecodealliance:main:
Note: previous PR 1292 was closed because, I assume, the reviewer did not like the detailed PR message there, so here I'm trying to make it shorter and focus more on what we are trying to do with the PR instead of what the PR does.
In short, at Google we are exploring various ways to make hypervisors more secure and flexible, and one of the experiments is running wasm in the Linux kernel. Note that the link in the previous message points to the wasmtime fork behind this PR, as it is used by a Google project.
The wasm object in the kernel uses wasm threads mapped 1:1 to VCPU threads, and they share state via wasm shared memory. But because this is all in the kernel (Ring 0) context, the target is wasm32-unknown-unknown, which is a no-std target. So we need the 'threads' feature with 'no_std'.
For a detailed description of what the PR does, see the commit message or the PR message in PR 1292.
posk-io removed the review request for wasmtime-core-reviewers from PR #15312.
posk-io requested dicej for a review on PR #15312.
posk-io requested wasmtime-core-reviewers for a review on PR #15312.
posk-io removed the review request for wasmtime-default-reviewers from PR #15312.
posk-io requested fitzgen for a review on PR #15312.
posk-io requested wasmtime-default-reviewers for a review on PR #15312.
posk-io edited PR #15312:
Note: previous PR 15292 was closed because, I assume, the reviewer did not like the detailed PR message there, so here I'm trying to make it shorter and focus more on what we are trying to do with the PR instead of what the PR does.
In short, at Google we are exploring various ways to make hypervisors more secure and flexible, and one of the experiments is running wasm in the Linux kernel. Note that the link in the previous message points to the wasmtime fork behind this PR, as it is used by a Google project.
The wasm object in the kernel uses wasm threads mapped 1:1 to VCPU threads, and they share state via wasm shared memory. But because this is all in the kernel (Ring 0) context, the target is wasm32-unknown-unknown, which is a no-std target. So we need the 'threads' feature with 'no_std'.
For a detailed description of what the PR does, see the commit message or the PR message in PR 1292.
posk-io edited PR #15312:
Note: previous PR 15292 was closed because, I assume, the reviewer did not like the detailed PR message there, so here I'm trying to make it shorter and focus more on what we are trying to do with the PR instead of what the PR does.
In short, at Google we are exploring various ways to make hypervisors more secure and flexible, and one of the experiments is running wasm in the Linux kernel. Note that the link in the previous sentence points to the wasmtime fork behind this PR, as it is used by a Google project.
The wasm object in the kernel uses wasm threads mapped 1:1 to VCPU threads, and they share state via wasm shared memory. But because this is all in the kernel (Ring 0) context, the target is wasm32-unknown-unknown, which is a no-std target. So we need the 'threads' feature with 'no_std'.
For a detailed description of what the PR does, see the commit message or the PR message in PR 1292.
cfallin commented on PR #15312:
Thanks for the PR! I just wanted to drop by to address something I saw:
was closed because, I assume, the reviewer did not like the detailed PR message there
Note that this is not just reviewer preference; we have an organization-wide policy that "strongly recommend[s] that contributors write PR descriptions themselves". As you can probably appreciate, many open-source projects including ours have been subjected to an unrelenting and increasing flood of PRs and issues lately, often without the reviewer doing much pre-work to understand our project and its goals and structure or thoughtfully communicate intent or high-level design to us. As part of the open-source contract, we expect everyone to respect maintainers' time and avoid "extractive contributions" and associated patterns (as defined in that doc). In short, we're happy to accept contributions, but don't foist all the filtering work onto us; reading through huge walls of text is part of that work.
(And, I should note, finding and reading the org's policy rather than assuming the worst of a particular reviewer is also part of that work.)
Thanks!
posk-io commented on PR #15312:
As part of the open-source contract, we expect everyone to respect maintainers' time and avoid "extractive contributions" and associated patterns (as defined in that doc). In short, we're happy to accept contributions, but don't foist all the filtering work onto us; reading through huge walls of text is part of that work.
(And, I should note, finding and reading the org's policy rather than assuming the worst of a particular reviewer is also part of that work.)
I fully agree! The irony was that I did read the policy and asked my AI agent to provide additional details, as my own experience with AI-generated PRs is that they often lack in this regard... Anyway, I'm human, I work on VMMs and Linux kernel, and I want to make web assembly more easily usable in this context.
cfallin edited a comment on PR #15312:
Thanks for the PR! I just wanted to drop by to address something I saw:
was closed because, I assume, the reviewer did not like the detailed PR message there
Note that this is not just reviewer preference; we have an organization-wide policy that "strongly recommend[s] that contributors write PR descriptions themselves". As you can probably appreciate, many open-source projects including ours have been subjected to an unrelenting and increasing flood of PRs and issues lately, often without the author doing much pre-work to understand our project and its goals and structure or thoughtfully communicate intent or high-level design to us. As part of the open-source contract, we expect everyone to respect maintainers' time and avoid "extractive contributions" and associated patterns (as defined in that doc). In short, we're happy to accept contributions, but don't foist all the filtering work onto us; reading through huge walls of text is part of that work.
(And, I should note, finding and reading the org's policy rather than assuming the worst of a particular reviewer is also part of that work.)
Thanks!
github-actions[bot] added the label wasmtime:api on PR #15312.
github-actions[bot] added the label wasmtime:docs on PR #15312.
alexcrichton removed the review request for dicej from PR #15312.
alexcrichton removed the review request for fitzgen from PR #15312.
alexcrichton requested alexcrichton for a review on PR #15312.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Could you explain a bit more what this is doing? I'd be surprised if this ever got this far because I'd expect us to have atomic loads/stores elsewhere in the process which require 64-bit or similar (e.g. the implementations of functions below). Either that or 64-bit atomics would be part of what Cranelift would emit and the question of whether 64-bit atomics would be a problem there.
Basically I'd expect that either (a) Wasmtime would either fail to compile first, or (b) Cranelift would fail to compile or fail to actually execute at runtime. Those are all pretty orthogonal from just checking here, so I'm curious to dive a bit more into what this is enforcing.
:speech_balloon: alexcrichton created PR review comment:
Wasmtime's support for no_std and various features so far generally falls within the category of not actually changing the behavior of WebAssembly or the runtime itself but rather instead just changing how things are implemented. To that extent nothing previous in Wasmtime would result in a panic on wasm-standard operations in one configuration mode vs another. This sort of behavioral change has been handled historically in Wasmtime along the lines of disallowing a feature entirely in a build mode if it can't be supported.
Put another way, I do not think that panicking here, nor panicking in
nonblocking_waitbelow, is a sufficient implementation for landing this PR. That means that the wasm threads proposal isn't actually supported on no-std, so I don't think that Wasmtime should advertise support on no-std for the wasm proposal.Can you detail a bit more what led you to this implementation detail? What use do you have for needing to implement and run the wasm threads proposal while not actually supporting threads blocking? Additionally why do not not require support for 64-bit atomics and 32-bit is sufficient for you use case? I'm hoping that by learning more about your motivations we can better chart a course for how best to solve that.
:speech_balloon: alexcrichton created PR review comment:
Oh, well, hm, now I read further and saw the changes to
atomic_wait64below. I'll comment down there, too.
posk-io commented on PR #15312:
@alexcrichton I did not realize (my mistake) that a change like this first needs to go through a "proposal" phase; I was treating it in a typical "if it seems generally useful, send a PR upstream" way. I apologize for the noise. I'll close this PR.
Answers to your questions, in case making wasm threads work in no-std envs is something you would consider exploring:
- shared memory without atomics: it makes sense to me that shared memory (basically, concurrent access to shared data) requires atomics, so the lines that you flagged looked ok when I reviewed them, especially the second case which is purely static (and the first case should also be resolved by the compiler statically, right?); I agree that this is probably already there, as you suggested:
I'd expect that either (a) Wasmtime would either fail to compile first, or (b) Cranelift would fail to compile or fail to actually execute at runtime.
nonblocking: we explore running wasm in the OS kernel (Linux and some other experimental kernels); for example, handle_vcpu_exit in wasm is callled to process VM exits; another BIG potential use case is to rip out eBPF cruft from Linux kernel and replace it with wasm; nonblocking again... basically, it is hard for me to imagine a use case where we would put blocking wasm in the kernel (which is what no-std wasm targets, right?)
why wasm32 and not wasm64? our use case (a kernel module) does not need a lot of memory, so wasm32 is enough in this regard; given that (a) wasm64 is (anecdotally) slower than wasm32, and (b) wasm32-unk-unk is a Tier-2 target in Rust, while wasm64-unk-unk is still a Tier-3 target, wasm32 was the default choice based on these "vibes".
TL;DR: this work is exploratory/experimental, so we did not run any benchmarks or deeper analysis to make more informed decisions. I prepared this PR in hope that unlocking threads for no-std seemed useful enough to justify a relatively small PR.
:cross_mark: posk-io closed without merge PR #15312.
alexcrichton commented on PR #15312:
At this time Wasmtime doesn't have a requirement of a formal proposal phase for a PR, but all PRs are subject to maintainer review. Reviews can often poke on the fundamentals of a PR as I'm doing here, however.
One thing I can also perhaps clarify here though is that there's two aspects here. One is the semantics of actually running WebAssembly guests, and one is how Wasmtime is compiled itself. The no-std nature here has nothing to do with WebAssembly guests and instead has everything to do with how Wasmtime is compiled itself. For example a no-std Wasmtime build might run a guest that was itself compiled with the Rust standard library compiled down to WebAssembly. The distinction I want to make is that the semantics of WebAssembly and guests are fixed regardless of how Wasmtime is itself compiled (no-std vs not).
it is hard for me to imagine a use case where we would put blocking wasm in the kernel (which is what no-std wasm targets, right?)
An example here is that WebAssembly has defined and fixed semantics for
memory.atomic.wait{32,64}and shared memories. No matter how Wasmtime is compiled it needs to uphold those semantics to claim support for the threads proposal. The nature of the guest, whether it's a no-std wasm target or not, only dictates what subset of WebAssembly the guest is using. As a runtime, however, Wasmtime is still tasked with implementing WebAssembly instructions as defined.Wasmtime does not support all wasm proposals in all configurations in an attempt to support wasm in as many places as possible. For example if you disable the
gcCargo feature of Wasmtime you won't be able to allocate wasm GC objects. That's howthreadsworks right now as well, where if the Cargo feature is disabled then the wasm feature is disabled as well. Wasmtime as a runtime has some leeway to implement things, but we generally require opt-ins for non-standard behavior. For example one non-standard behavior you might want is thatmemory.atomic.wait*would trap (not panic) when called. That would cause all guests to terminate if they called that, and whether or not that's useful is up to your embedding. Similarly 64-bit atomics could simply trap at runtime to support hosts that don't have 64-bit atomics, but you'd have to ensure that your guests don't ever use that.why wasm32 and not wasm64?
This is another example of wasm32/wasm64 are a guest toolchain convention, not a runtime concern. Wasmtime implements the
memory64proposal which means it can run either wasm32-compiled or wasm64-compiled guests, but individual wasm instructions, likememory.atomic.wait64, still have defined semantics no matter how the guest is compiled.
Overall it sounds like what you would want is to limit the wasm instructions that a guest can use. It sounds like you ideally want to reject the
threadsproposal entirely if guests themselves aren't spawning threads. If they're being run in parallel then in theory what you'd want is a guest that doesn't use unsupported instructions. What exactly unsupported instructions fall into this category would be up to you and would be a new invention for your embedding. Wasmtime does not have fine-grained support for wasm instructions like that.My point is that the conversation here, in my opinion, is about what functionality Wasmtime needs to support in an embedding such as yours, and what happens in the case that a wasm module is loaded that uses unsupported functionality. The answer is not to simply panic because we consider runtime panics as CVEs. The answer probably isn't as simple as "just trap" because that's nonstandard WebAssembly behavior. That's not to say nothing can be done, however, but instead this is where I was intending to start the conversation and take it from here. It's totally ok if you would prefer to not land this support upstream in the meantime, but I want to be clear about the expectations from our side at least.
posk-io commented on PR #15312:
You are asking questions at a deeper level than I can properly answer at the moment. We are trying different approaches, and learning of wasm capabilities along the way (we know more about operating systems than about wasm, tbh). If our experiments grow into something real/practical, with a clearly defined feature request (or two), I'll open an issue (or two) here.
Thanks a lot for the thoughtful discussion!
cfallin commented on PR #15312:
One potential way of squaring the circle here w.r.t.
memory.atomic.wait{32,64}is to add new expected "embedder API" functions (seewasmtime-platform.h) and call these. Then your kernel-space embedding can implement them however you like. We would certainly recommend you implement semantics per the spec: minimally probably a spinloop (still has futex semantics, just no CPU yield), or actually yield the CPU if you can do that in your kernel thread.What Alex is getting at in part is that much of the value of the Wasm platform is that the spec is invariant once a feature is supported, so guest libraries can build on it without Wasm-platform-specific patches. That avoids silent mis-execution bugs, which can be really really pernicious to debug (imagine buying a CPU that executes one particular synchronization instruction incorrectly, then trying to run a standard software stack on top!).
Last updated: Nov 19 2026 at 20:05 UTC