Skip to content

kernel: Preserve TLS key in kernel_reset() after force-rewind#12

Open
JoyciAkira wants to merge 1 commit intookuoku:masterfrom
JoyciAkira:fix/kernel-reset-preserve-tls
Open

kernel: Preserve TLS key in kernel_reset() after force-rewind#12
JoyciAkira wants to merge 1 commit intookuoku:masterfrom
JoyciAkira:fix/kernel-reset-preserve-tls

Conversation

@JoyciAkira
Copy link
Copy Markdown

@JoyciAkira JoyciAkira commented Apr 2, 2026

Summary

Fix critical bug where kernel_reset() was destroying the TLS key created by syscalls_init() during Asyncify force-rewind, causing all subsequent syscalls to fail with ENOMEM (-12).

Problem

After Asyncify force-rewind, the kernel becomes unusable:

  • tls_get() returns NULL
  • new_host_task() fails
  • All syscalls return -12 (ENOMEM)

Root Cause

  1. Force-rewind calls init()syscalls_init()tls_alloc() (Key Prepare website #1)
  2. kernel_reset() frees Key Prepare website #1 and allocates Key Syscall porting is incomplete #2
  3. Kernel threads created with Key Prepare website #1 now have invalid TLS
  4. tls_get() returns NULL, breaking all syscalls

Solution

  • Preserve existing task_key instead of freeing it
  • Only allocate new key as fallback if none exists
  • Don't recreate idle_host_task_loop if already exists
  • Update host0 and set TLS on existing key

Testing

Tested with Zeronode project (https://github.com/zeronode/zeronode):

  • CERT_300_2_STRICT certification gate
  • Boot succeeds with nominal mount after force-rewind
  • No regression in normal boot path

Impact

  • Fixes ENOMEM bug blocking LKL-WASM Asyncify support
  • Benefits all projects using LKL-WASM with Asyncify
  • No regression in normal boot path

Code Changes

  • arch/lkl/kernel/syscalls.c: Modified kernel_reset() function
    • Commented out tls_free(task_key) call
    • Added conditional TLS initialization
    • Added conditional idle_host_task_loop creation

References

  • Technical analysis: Zeronode docs/issues/300.2-enomem-tls-root-cause.md
  • Related issue: Asyncify force-rewind ENOMEM failure

Co-authored-by: Daniele Corrao danicorrao87@gmail.com
Signed-off-by: Daniele Corrao danicorrao87@gmail.com

Update lkl-wasm submodule to include fix for kernel_reset() preserving
TLS key after Asyncify force-rewind.

Fixes ENOMEM (-12) errors on all syscalls after force-rewind.

Signed-off-by: Daniele Corrao <danielecorrao@users.noreply.github.com>

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
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.

1 participant