fix(libkernel): publish APR address completions with one store #24924
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24924"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by RafaelMendes1407 on 2026-11-21T11:09:34Z.
What
_storeGuestAddressincore/libs/prx/libkernel/Apr/src/Apr.cpppublishes the value of an APR write-address command. It currently writes that value twice:GuestCopyOut_nid_no_patch(a plain copy);std::atomic_ref<uint64_t>::store(value, memory_order_release).A guest thread that polls the completion word can observe write 1, clear the word to reuse the slot, and then have write 2 set it back to the completion value. The next command buffer that reuses that slot then looks complete before its own read has run, and the guest consumes a buffer whose data has not landed yet.
The guest-visible contract is a single release store of the value, so the change publishes it exactly once:
GuestArena::HostWriteopens the guest write window once, asGuestCopyOutdid;GuestWritable_nid_no_patchchecks the 8-byte word;atomic_refrelease store publishes the value.Null, unaligned or unwritable addresses keep the existing error:
APR: the write address … is not writable guest memory. No other APR behaviour changes.Background: I found this while chasing a load-time issue in Demon's Souls (PPSA01341), where the title polls about 3,000 completion words, one of them reused 491 times in a single load. With fast storage, completion is visible almost at once, which makes the clear-then-restore window easy to hit. This PR does not claim to fix that title's issue; it fixes the double publication, which is wrong for any title.
Tested
Linux (CachyOS, kernel 7.3), GCC, Release build.
guest_apr_read_completion_storecase. It submits a one-command buffer (write 1 to an address) 10,000 times while a consumer thread waits for the word, clears it, and acknowledges. After each round, the word must still be 0.APR rewrote a completion after the consumer cleared it.ctest --test-dir build -R guest_apr_read --repeat until-fail:20: all 10 APR read cases pass 20 times each.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchshows #19060 touchingGuestAprRead.cpp, at a different spot: it adds an AMPR case nearmain()and is unrelated. That means a possible trivial merge conflict, but no overlap in function.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T11:18:13Z.
Review: APPROVED
Reviewed — looks good
The APR completion change and its added regression test are consistent with the stated goal; I found no verified blocking defect in the changed code.
What I ran
Reviewed head
d68bc56389ed3c81f17a570102e860e76ed42744. I read the prepared description, commits, diff, manifest, and all three changed files, including every added line. I usedrepo_read.pyto inspect relevant APR, guest-memory, and test code. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build, tests, reported console behavior, and files excluded from the prepared review folder were not independently verified. Files read:
core/libs/prx/libkernel/Apr/src/Apr.cpp,core/libs/prx/libkernel/CMakeLists.txt, andcore/libs/tests/GuestAprRead.cpp.files.jsonwas unavailable; the prepared manifest lists all three changed files as included, and the prepared file list shows no excluded changed files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T11:31:45Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d68bc56389:tools/check_conventions.pypassed.guest_apr_read_testsbuilt cleanly.guest_apr_read_host,guest_apr_read_direct,guest_apr_read_eof,guest_apr_read_errors,guest_apr_read_streams,guest_apr_read_resolve,guest_apr_read_priorities,guest_apr_read_order,guest_apr_read_completion_store,guest_apr_read_queries):core/libs/prx/libkernel/Apr/src/Apr.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T02:36:58Z.
Review: COMMENTED
Architecture findings (1)
Advisory architecture findings (1)
de4f8caf-6d10-4b2d-a6e1-43bc45e5fea6Reviewing files that changed from the base of the PR and between
5ed18b5d5aandb7fc44000d.core/libs/prx/libkernel/Apr/src/Apr.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/tests/GuestAprRead.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T02:46:40Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
b7fc44000d7768214d8e1f4cb15642650ffbecb4from the prepared diff and pinned repository reader. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
core/libs/tests/GuestAprRead.cpp:797extends the case dispatch, while the existing usage error at line 774 does not listcompletion_store. Consider updating it so a typo in the case name reports the newly available option.Not verified
No build, CTest run, negative control, or console run was performed. The author's reported Linux test results were not independently verified. All changed files were read:
core/libs/prx/libkernel/Apr/src/Apr.cpp,core/libs/prx/libkernel/CMakeLists.txt, andcore/libs/tests/GuestAprRead.cpp; all three are listed as reviewed in the manifest. No files were excluded by the prepared manifest.To get this to a good state
Nothing is required. Optional: include
completion_storein the usage error text.