fix(libSceUsbd): retain devices during active USB operations #9803
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9803"
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 Dellz36 on 2026-10-22T15:39:43Z.
What
A device query could pass ownership validation and then use a freed host device when another thread released the last guest reference or closed its owning handle. Final USB shutdown could also destroy state while a query, handler or sleeping waiter still used it.
Retain host devices under the state mutex for the complete device-query/open operation, reject final shutdown while those operations are active, preserve initialization ownership after rejected shutdown, and retain event-lock ownership across backend exceptions. Closing a handle with pending transfers now throws before removing its ownership record. Add deterministic threaded lifetime and event regressions.
This is a follow-up to #9339, including its #9338/#9190 stack. The prerequisite commits remain in the branch ancestry; their device/event/descriptor implementations and exports are not claimed as new work here. The authored follow-up is the final commit after the prerequisite merge. This adds no new-export or title-compatibility claim.
General handle-based concurrent-close pinning and automatic transfer cancellation/draining remain unsupported and are documented in debt/libSceUsbd.md.
Official unmodified
tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch fix/usb-operation-lifetimes-20261022reviewed the complete open-PR inventory. Its only remaining warning is base-conflicted #6044: manually reviewed its USB diff; it relocates GuestUsbd.cpp to tests/input and changes test registration/labels, without implementing these lifetime guards. If it merges first, these test paths/registrations need adapting. No agreed maintainer merge order is claimed; #9339 is explicitly a prerequisite.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)Review follow-up — updated integration and retest
Updated by merging upstream/main
fa107a44c71349da4d9e916881d39158a75a783f, including the reviewer-cited8499ea52e571b0edfc1feecfd3f6b9944012b359. New head:be8a8466bfaa18dc0ac1f09eaf91d39344d06ae2. The existing prerequisite ancestry and #9339 dependency remain intact; this uses a normal fast-forward push without rewriting published commits.Focused retest on the resulting head: Linux 21 USB cases × 5 = 105 passes; Windows 21 USB cases × 5 = 105 passes, zero skips. Linux rebuilt actual libraries through the previously disclosed focused harness. Windows used supported GCC15.2 with normal root CMake configuration and actual libc/libkernel/libSceUsbd/test dependencies. The Windows production source was refreshed from the exact updated Git archive; 132 recorded libc/USB/fixture hashes match, and compiled production files no longer include the separate local libc/kernel candidates. The last additional upstream merge only changes graphics files; updated those files and reran the USB build/test commands. Conventions and whitespace pass. This is focused validation, not a full-suite or PS5/title claim.
Merge-order coordination with @TaymKal requested at https://github.com/boykopovar/AnyPS5/pull/6044#issuecomment-6347879073. Proposed #9339 → #9803 → #6044; offered to adapt paths/registrations if #6044 goes first. Author confirmation is pending. No agreement is claimed; the agreed order/dependency will be recorded on the checklist before merge. Existing
Depends on: #9339is unchanged.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:11:34Z.
Review: CHANGES_REQUESTED
The lifetime changes are backed by a strong report: repeated focused Linux and Windows runs, six targeted lifetime cases, and negative controls. I ran
check_conventions.pyagainst currentupstream/mainandgit diff --check; both pass. I did not run the USB runtime suite locally; this checkout has no configured build tree, and the product build jobs are skipped on the PR.Before approval, please address the current integration state:
b7d1d47a5f; currentupstream/mainis8499ea52e571b0edfc1feecfd3f6b9944012b359(8 commits ahead).CONTRIBUTING.mdrequires branches to stay current. The merge tree is currently clean, but please rebase/update and rerun the focused USB test set on the resulting head.I found no additional blocker in the test and implementation evidence summarized in the description.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T10:06:54Z.
Review: APPROVED
Reviewed — looks good
The changed USB lifetime guards and the added regression coverage are consistent with the stated goal; focused checks are reported by the author, but I did not run them.
What I ran
Reviewed head
be8a8466bfaa18dc0ac1f09eaf91d39344d06ae2using the prepared diff andrepo_read.pyfor targeted source ranges. No commands or tests were run. The description reports Linux and Windows focused USB runs; those are author-reported, not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of all changed files was not read. Targeted ranges were read from
core/libs/prx/libSceUsbd/Export.cpp(lines 1–60, 60–185, 185–246, 246–365, 365–425, 425–580, 580–705, and 760–958), andcore/libs/tests/UsbdPacketQueries.cpp(150–270). Other changed files and source ranges were not reviewed. No tests, builds, console behavior, or author-reported test results were independently verified. The review bundle’sfiles.jsonwas not available through the reader, so exclusions could not be confirmed;manifest.jsonlists changed files, but its complete inventory was not inspected.To get this to a good state
Nothing is required.
Pull request closed