feat(libkernel_sys): write the AMM commands and wait for their completion #10799
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10799"
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 EagleBearerYS on 2026-10-25T01:44:25Z.
What
Implements 13 of libkernel_sys's AMPR command exports on the libSceAmpr encoders:
The AMM range and protection checks and the records they build move from libSceAmpr into the APR command buffer header that libSceAmpr and libkernel already share. Each kernel writer records exactly what its libSceAmpr command buffer sibling appends, with the same errors.
dstonly reports the size, as for sceKernelWriteModifyMtypeProtectCommand.typewith bits above 32 is cut to the record's 32-bit field, as sceKernelWriteModifyMtypeProtectCommand does and as the siblings' 32-bittypeimplies. The console's handling isn't measured; the debt entry says so, andguest_kernel_syspins the behaviour (fe9d31edae).a666c83d20). The id each submission is given was stored for the wait after the queue's submit lock was released, so two concurrent submitters could store out of order, and a wait for the later id failed with ESRCH. The wait now compares the id with the AMM queue'ssubmittedcount, which_submitraises under the queue mutex before it returns. This also changesmain's sceAmprAmmWaitCommandBufferCompletion, which uses the same check.The five APR writers (WriteAddress, WriteCounter, WaitOnAddress, WaitOnCounter, EventQueueOnCompletion) stay NotImplemented: no source gives their kernel signatures.
Tested
guest_kernel_syspasses 10 of 10 on Linux and on Windows, 0 skipped. The libc and libkernel suites pass: Linux 143 and 206 tests run, Windows 170 and 222, 0 failed. Main's implementation doesn't build against the new test, because main declares the writers without parameters.fe9d31edae, the widetypecases (run):guest_kernel_sysand the AMPR tests (guest_ampr_markers,guest_amm_placement,guest_ampr_threads,guest_ampr_cpp_errorand^guest_apr_read_) pass 10 runs in a row. Linux: 10 run, 10 pass, 0 skip, 0 fail. Windows: 12 run, 12 pass, 0 skip, 0 fail. The new cases check thattype0x1_0000_0003 records the same bytes as the libSceAmpr sibling given 3, for the map and map direct writers, with and without the GPU mask id, and for the mtype-protect writer. They pin behaviour the previous head already had. The libc and libkernel suites pass on both (143 and 206 tests on Linux, 170 and 222 on Windows), run withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners. Main's implementation doesn't build against the test.a666c83d20, the completion wait (run), red/green against fe9d31edae's implementation:guest_kernel_sysgains a case where four threads submit 4,000 empty AMM buffers each while another thread waits on the newest id any of them has published, through sceKernelWaitCommandBufferCompletion and sceAmprAmmWaitCommandBufferCompletion, and every wait must succeed.guest_kernel_sysand the AMPR tests pass 10 runs in a row: 10 run, 10 pass, 0 skip, 0 fail.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.guest_kernel_syscompares every writer with its libSceAmpr sibling on valid and invalid arguments, with and without a destination and a size output. It also submits a map written by sceKernelWriteMapCommand, waits for it with sceKernelWaitCommandBufferCompletion, and uses the mapped page.No title tested.
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)getfsstat), #11032 (kenv) and #11034 (swapon), adjacent lines indocs/dev/debt/libkernel_sys.mdandcore/libs/tests/GuestKernelSys.cpp, and with #11216 (kldload) and #11231 (kldsym), neighbouring lines: this PR first, then those rebase onto itRelated: #9632 (libkernel_sys, separate rows).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T01:55:40Z.
Review: CHANGES_REQUESTED
I reviewed this against current
main(941ace5) and the exact PR headafd5c4a20e3a0e6bd89021279b67bc43e59f9323. The encoding reuse and writer parity tests are thorough, but the new wait export has a concrete hang case in the shared implementation.\n\nAmmSubmitted_nid_no_patch(id)accepts every nonzero ID up tolastSubmit, then_waitSubmittedwaits untilqueue.completed >= id || id > queue.submitted. If a prior submission was queued and a later ID was submitted through the regular (non-AMM) queue, that later ID can be <=lastSubmitbut > the AMM queue’ssubmitted;sceKernelWaitCommandBufferCompletionthen waits forever because neither predicate can become true. IDs are queue-local in_submit(each_queue(amm)tracks its own submitted/completed counters), whilelastSubmitis only a scalar shared AMM marker. Please make the wait validate against the AMM queue’s own submitted range and ensure unknown IDs return without blocking; add a regression test that interleaves an AMM ID with a regular APR submission.\n\nI also noticed the new writers intentionally ignoregpuMaskId, matching the existing AMM encoder signatures, but I found no debt entry explaining that unsupported mask behavior. Please document whether the mask is intentionally ignored in this single-device emulator or preserve unsupported values until the behavior is evidenced.\n\ngit diff --checkpasses; I did not run the product suite locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T02:42:12Z.
Review: COMMENTED
Reviewed exact head
afd5c4a20e3a0e6bd89021279b67bc43e59f9323. The shared command encoders preserve the existing libSceAmpr writer records and the new tests compare record bytes, size-query behavior, error paths and a submitted map/wait round trip. Current-main conventions andgit diff --checkpass in the PR worktree. The PR reports focused Linux/Windows guest test runs; the current hosted upstream run has policy checks green and product jobs skipped, and I did not rerun the integrated build locally. I left one question about the 64-bittypeinput being narrowed to a 32-bit command field; please resolve that before I approve.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T04:11:28Z.
Review: CHANGES_REQUESTED
Correction to my earlier review: I rechecked the completion wait invariant. lastSubmit is updated only from AMM submissions, so the interleaved regular-APR ID scenario I described cannot by itself make a valid AMM ID wait forever; I withdraw that finding. The current head does address my earlier 64-bit type question in the body/debt and adds tests pinning the truncation behavior, though that remains an author-stated assumption rather than console evidence. I found a separate concurrency bug in the completion marker: AmmSubmit_nid_no_patch calls _submit, then stores its returned ID into lastSubmit after _submit has released the AMM queue submit lock. Two concurrent AMM submissions can therefore complete those steps out of order: id 1 returns and pauses, id 2 returns and stores 2, then id 1 stores 1. A later wait for the already-submitted id 2 is rejected as ESRCH. Please publish the AMM high-water mark monotonically (or update it while submissions are serialized) and add a concurrent regression that proves a later completed submission remains waitable after an earlier submitter publishes late. The exact current diff otherwise contains focused byte-parity and map/wait tests; I did not run product tests locally, and hosted product jobs are skipped.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T05:32:42Z.
Review: APPROVED
Reviewed the exact head
a666c83d20against current maine7e3e9c. The former publication race is removed: AMM waits validate the ID against queue.submitted while holding queue.mutex, the same counter lock used to allocate IDs in _submit, then wait on completion. This prevents an earlier submitter from overwriting a later ID, and rejects IDs not yet issued without blocking. The new concurrent regression drives four AMM submitters and a waiter through both wait exports; the author reports focused Linux and Windows runs, and the prior-head red/green evidence is documented in the PR. I independently ran the current conventions checker on this exact head; it passes. GitHub conventions, labels, eligibility, and report checks pass; hosted product build/test jobs are skipped, so I did not treat them as independent product validation. The PR branch is behind current main, so it still needs a rebase before merge.