fix(libkernel): drop direct mappings when physical backing is released #686

Merged
Pouare514 merged 1 commit from upstream-pr/686 into main 2026-10-06 00:28:22 +00:00
Pouare514 commented 2026-10-05 15:24:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-05T15:24:47Z.


What

ForgetDirectMemory erased the physical pages but left g_directMappings entries pointing at the dead backing, so sceKernelVirtualQuery kept reporting is_direct with a stale physical offset after sceKernelReleaseDirectMemory. Erase (and split, on the phys axis) the affected mapping tracking on release. Mapped views are untouched, so no new faults are introduced.

Found during Deathloop streaming triage: the worker crash site sits in code fed by freshly DoMapDirect'd streaming buffers, and a stale is_direct plus phys offset is a candidate contributor to wrong GPU-side addresses. The fix itself is generic lifecycle bookkeeping, not title-specific.

Tested

  • New CheckReleaseDirectMemoryClearsMappings in core/libs/tests/GuestMemory.cpp: full release and partial (second-page) release, VirtualQuery before/after on both pages.
  • guest_memory passes with the fix; with the fix stashed it aborts (0xc0000409) on the new check, so the test pins the behavior.
  • CI green (linux, windows, report).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4747176007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/686). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-05T15:24:47Z. --- ### What ForgetDirectMemory erased the physical pages but left g_directMappings entries pointing at the dead backing, so sceKernelVirtualQuery kept reporting is_direct with a stale physical offset after sceKernelReleaseDirectMemory. Erase (and split, on the phys axis) the affected mapping tracking on release. Mapped views are untouched, so no new faults are introduced. Found during Deathloop streaming triage: the worker crash site sits in code fed by freshly DoMapDirect'd streaming buffers, and a stale is_direct plus phys offset is a candidate contributor to wrong GPU-side addresses. The fix itself is generic lifecycle bookkeeping, not title-specific. ### Tested - New CheckReleaseDirectMemoryClearsMappings in core/libs/tests/GuestMemory.cpp: full release and partial (second-page) release, VirtualQuery before/after on both pages. - guest_memory passes with the fix; with the fix stashed it aborts (0xc0000409) on the new check, so the test pins the behavior. - CI green (linux, windows, report). ### Checklist - [x] Based on current main; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt - [x] No notes, investigation .md files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!686
No description provided.