fix(libkernel): retire stack metadata before releasing mappings #5597

Merged
JJenkx merged 1 commit from upstream-pr/5597 into main 2026-10-14 03:41:02 +00:00
JJenkx commented 2026-10-14 00:43:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-14T00:43:01Z.


What

A joined or retired Linux guest stack is unmapped before its host-page metadata is removed. Another thread can reuse the address between those operations and have its new stack guard rejected with mprotect overlaps host-only guest thread stack pages.

Remove the finished stack's metadata before returning its mapping to the allocator, in both joined-stack cleanup and detached-stack reaping. The native thread has already joined or disappeared from /proc/self/task at these points. Live-stack protection checks are preserved.

Tested

  • Linux x86_64: an unmap-observer regression deterministically fails before the fix because host-only stack metadata still covers a released mapping. Fixing only joined-stack cleanup makes the joined cases pass while detached-stack reaping still fails. Fixing both paths passes the full regression.
  • guest_pthread_stack, guest_kernel_stack_protect and guest_ampr_threads each pass 20 repetitions on the local combined integration: 60 successful runs, no skips. The protection test still rejects changes to live host-only pages.
  • The standalone topic's Thread.cpp and regression match the compiled integration files. The integration also contains independent library and shader changes; standalone full Linux/Windows CI now passes at the recorded topic head. No title compatibility or FPS improvement is claimed.
  • Investigation began after an unrelated registry branch's Linux CI aborted in guest_ampr_threads with the overlap error. The stale-entry ordering is proven by the regression; that CI abort's precise scheduling has not been reproduced.
  • Conventions and whitespace checks pass.

Checklist

  • Based on current main feddf7f4c654; no equivalent open retirement-order fix found
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • No silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none; host thread-stack race
  • GPUs tested: n/a; thread metadata lifecycle
  • AI-assisted: yes

Standalone full Linux and Windows validation passes for topic head d1527840ea3.

Standalone full CI: Linux 1043 passed / 46 skipped; Windows 720 passed / 389 skipped. Skipped cases remain unvalidated.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4851327595 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5597). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-14T00:43:01Z. --- ### What A joined or retired Linux guest stack is unmapped before its host-page metadata is removed. Another thread can reuse the address between those operations and have its new stack guard rejected with `mprotect overlaps host-only guest thread stack pages`. Remove the finished stack's metadata before returning its mapping to the allocator, in both joined-stack cleanup and detached-stack reaping. The native thread has already joined or disappeared from `/proc/self/task` at these points. Live-stack protection checks are preserved. ### Tested - Linux x86_64: an unmap-observer regression deterministically fails before the fix because host-only stack metadata still covers a released mapping. Fixing only joined-stack cleanup makes the joined cases pass while detached-stack reaping still fails. Fixing both paths passes the full regression. - `guest_pthread_stack`, `guest_kernel_stack_protect` and `guest_ampr_threads` each pass 20 repetitions on the local combined integration: 60 successful runs, no skips. The protection test still rejects changes to live host-only pages. - The standalone topic's Thread.cpp and regression match the compiled integration files. The integration also contains independent library and shader changes; standalone full Linux/Windows CI now passes at the recorded topic head. No title compatibility or FPS improvement is claimed. - Investigation began after an unrelated registry branch's Linux CI aborted in `guest_ampr_threads` with the overlap error. The stale-entry ordering is proven by the regression; that CI abort's precise scheduling has not been reproduced. - Conventions and whitespace checks pass. ### Checklist - [x] Based on current main `feddf7f4c654`; no equivalent open retirement-order fix found - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] No silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none; host thread-stack race - [x] GPUs tested: n/a; thread metadata lifecycle - [x] AI-assisted: yes [Standalone full Linux and Windows validation](https://github.com/JJenkx/AnyPS5/actions/runs/38490659862) passes for topic head `d1527840ea3`. Standalone full CI: Linux 1043 passed / 46 skipped; Windows 720 passed / 389 skipped. Skipped cases remain unvalidated.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5597
No description provided.