8000 wasm: key futexes by mm, not address alone by kilian-ai · Pull Request #57 · tombl/linux · GitHub
[go: up one dir, main page]

Skip to content

wasm: key futexes by mm, not address alone - #57

Open
kilian-ai wants to merge 1 commit into
tombl:wasm-copy-clone-shared-mmfrom
kilian-ai:pr/wasm-futex-key-by-mm
Open

kilian-ai wants to merge 1 commit into
tombl:wasm-copy-clone-shared-mmfrom
kilian-ai:pr/wasm-futex-key-by-mm

Conversation

@kilian-ai
@kilian-ai kilian-ai commented Sep 29, 2026 •
Copy link
Copy Markdown

Stack

Position 10 of 14 in the linux release stack. Below: #75 (wasm-copy-clone-shared-mm). Above: #70.

Order, bottom to top: wasm → #74 → #62 → #71 → #64 → #65 → #66 → #67 → #68 → #75 → #57 → #70 → #73 → #60 → #72. Squash in this order. distro#263 pins #57's head for everything up to #57. #70, #73, #60 and #72 are pinned by their host halves, distro#238, #254, #181 and #246.

Its head lives on kilian-ai's fork, so a GitHub PR can't use it as a base. The same commit is mirrored at tombl/linux wasm-futex-key-by-mm, which is #70's base. Delete the mirror after #57 lands.

On !CONFIG_MMU, get_futex_key() keys private futexes by virtual address alone (key->private.mm = NULL), because a no-MMU system normally has a single address space. wasm has no MMU, but every process gets its own linear memory, and two instances of the same binary have identical layouts. The kernel therefore treats the same address in two processes as one futex:

  • a FUTEX_WAKE in process A can wake a waiter in process B that sits at the same address;
  • B re-checks its own futex word, finds it unchanged and sleeps again;
  • the waiter A meant to wake is never woken.

In practice, two threaded programs running at the same time hang with every thread in S (for example two concurrent multithreaded ffmpeg encodes, or two copies of a condvar ping-pong), while each one passes when run alone.

Change: a new ARCH_NOMMU_PER_MM_ADDRESS_SPACE (in arch/Kconfig, depends on !MMU), selected by WASM, makes get_futex_key() include the mm in the private key, as it does on MMU systems. Threads and CLONE_VM children share an mm, so they still share futexes. Other no-MMU architectures are unaffected.

(FLAGS_SHARED is still compiled to 0 on no-MMU, so "shared" futexes are keyed per mm too. As far as I can tell that is correct here, because separate wasm processes don't share memory that a futex could live in.)

Deterministic repro: one process waits on a static word and a second instance of the same binary wakes its own copy of that word, where nobody waits:

static volatile int word;
/* ./futexkey wait: FUTEX_WAIT_PRIVATE on &word, expected 0, 4 s timeout
   ./futexkey wake: FUTEX_WAKE_PRIVATE on &word, n = 1, print the count */

Run ./futexkey wait & sleep 1; ./futexkey wake. Before this change, the wake reports 1 and the waiter returns 0, woken by the other process. After it, the wake reports 0 and the waiter times out with ETIMEDOUT.

Tested:

  • On a downstream tree based on f06dad0: futexkey 2/2; three concurrent condvar ping-pongs alongside two busy loops, 9/9; two concurrent pthread create/join stress runs, 3/3; two concurrent 4-thread ffmpeg 7.0 encodes, 2/2. All of these hung without the patch.
  • On this branch (f2a512c): make defconfig && make vmlinux.wasm builds; the symbol is =y and kernel/futex/core.o builds without new warnings. I didn't boot this exact tree under @lowland/kernel.

🤖 Generated with Claude Code

kilian-ai added a commit to kilian-ai/linux that referenced this pull request Sep 29, 2026
On !CONFIG_MMU, get_futex_key() keys every futex by its virtual address
only, on the grounds that there is a single address space. wasm has no
MMU but gives every process its own linear memory with an identical
layout, so equal addresses in two processes were the same futex: a
FUTEX_WAKE in one process could be consumed by a waiter in another,
which re-checks its own word and sleeps again, while the intended
waiter never wakes. Two concurrent threaded programs (e.g. two ffmpeg
encodes) hung with every thread asleep.

Add ARCH_NOMMU_PER_MM_ADDRESS_SPACE for no-MMU architectures whose mms
are separate address spaces, select it for wasm, and include the mm in
the private futex key there, as on MMU systems. Threads and CLONE_VM
children share an mm, so they still share futexes.

Same change as f11cdab on wasm-linuxontab-7.1 (tombl#57).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tombl
tombl force-pushed the pr/wasm-futex-key-by-mm branch from 2995b64 to 5e70d83 Compare October 27, 2026 14:35
@tombl
tombl changed the base branch from wasm to wasm-copy-clone-shared-mm October 27, 2026 14:35
On !CONFIG_MMU, get_futex_key() keys every futex by its virtual address
only, on the grounds that there is a single address space. wasm has no
MMU but gives every process its own linear memory with an identical
layout, so equal addresses in two processes were the same futex: a
FUTEX_WAKE in one process could be consumed by a waiter in another,
which re-checks its own word and sleeps again, while the intended
waiter never wakes. Two concurrent threaded programs (e.g. two ffmpeg
encodes) hung with every thread asleep.

Add ARCH_NOMMU_PER_MM_ADDRESS_SPACE for no-MMU architectures whose mms
are separate address spaces, select it for wasm, and include the mm in
the private futex key there, as on MMU systems. Threads and CLONE_VM
children share an mm, so they still share futexes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0