Skip to content

fix(libkernel_sys): record EINVAL in the aiocb for oversized and unsigned-signal aio requests - #16191

Closed
MarcZX10 wants to merge 4 commits into
boykopovar:mainfrom
MarcZX10:fix-aio-error-after-rejected-request
Closed

MarcZX10 wants to merge 4 commits into
boykopovar:mainfrom
MarcZX10:fix-aio-error-after-rejected-request

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

What

Queue() in core/libs/prx/libkernel_sys/Aio.cpp rejects two requests with Fail(GuestEinval), which sets errno but does not store the error in the guest aiocb. The request is never queued, but status stays -1 and error stays 0 (set on entry), so a following aio_error() reports the rejected request as completed without error. The other rejection paths in the same function go through the local fail() helper, which records the error in the aiocb.

Affected checks:

  • nbytes > INT_MAX: fix e3cebfb6a2, test dd23eece9d
  • SIGEV_SIGNAL / SIGEV_THREAD_ID with signo outside 1..SignalMax: fix 2ce12e4318, test 8c10407b0e

The fix only changes the two return statements to fail(GuestEinval). The call still returns -1 with EINVAL; the aiocb now carries the same EINVAL that aio_error() reports.

The existing validation test asserted huge.error == 0 for the oversized request, which pinned the defect; it now expects EINVAL.

Overlap and interaction: open PR #14403 adds a copy-in line directly above the nbytes check in Queue(). It does not change the lines this PR changes, but the hunks are adjacent. Merging this branch with #14403 produces a textual conflict in core/libs/prx/libkernel_sys/Aio.cpp (checked with git merge-tree). This PR does not depend on #14403 and is based on upstream/main. #15115 touches aio_suspend and is not affected.

Tested

Linux host (kernel 6.1), throwaway archive build with the CPU startup gate patched.

  • Ran guest_kernel_sys_aio (guest_kernel_sys_aio_tests) on the fixed head 8c10407b0e: build exit 0, 1/1 passed.
  • Negative control, run: with both fixes removed in the archived copy (not committed), the rebuilt test failed at check failed at line 91 (the nbytes case), as expected.
  • Negative control not run: the signo-only control (only the signo fix removed). The signo case is therefore not individually shown to fail without its fix.
  • python3 tools/check_conventions.py --base upstream/main: passed. git diff --check upstream/main: clean.
  • tools/pr_precheck.py (no-build): conventions and ABI audit passed; build-dependent C++ tests reported not run by that tool, which the build above covers.
  • No export changed, so the public-headers audit was not run.

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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions github-actions Bot added prx needs rebase Conflicts with main, rebase needed labels Nov 5, 2026
…is too large

Queue() rejected a request whose nbytes exceeds INT_MAX with Fail(), which
sets errno but never stores the error in the guest aiocb. The request
keeps the status -1 and error 0 set at entry, so a following aio_error()
reported the rejected request as completed without error.

Use the local fail() helper, which records the error in the aiocb as the
other rejection paths in Queue() already do.
…s rejected

The validation test pinned the aiocb error to 0 for a request with
nbytes above INT_MAX. Expect EINVAL there, as the other rejected
requests do, and check that aio_error() reports the same error.
…st without a valid signo

Queue() rejected a SIGEV_SIGNAL or SIGEV_THREAD_ID request whose signo is
outside 1..SignalMax with Fail(), which sets errno but never stores the
error in the guest aiocb. The request kept status -1 and error 0, so a
following aio_error() reported it as completed without error.

Use the local fail() helper, as the other rejection paths in Queue() do.
…ith signo 0

Expect EINVAL in the aiocb and from aio_error() when the signal
notification has no valid signo, matching the other rejected requests.
@MarcZX10
MarcZX10 force-pushed the fix-aio-error-after-rejected-request branch from 8c10407 to 4b9daae Compare November 7, 2026 15:43
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 4b9daae4af, merged onto main 4ab649f4d8 (03be84038a, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_kernel_sys_aio passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@oneandonlydean oneandonlydean self-assigned this Nov 8, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @MarcZX10,

Reviewed at 4b9daae. I think main's mix of Fail and fail is deliberate. It follows the FreeBSD 11 aio_aqueue() (stable/11 sys/kern/vfs_aio.c :1483-1509) line by line:

  • copyin failure: store_error(ujob, error), then return
  • aio_nbytes > IOSIZE_MAX: returns EINVAL without store_error
  • bad sigev_notify: store_error(ujob, EINVAL)
  • bad sigev_signo for SIGEV_SIGNAL / SIGEV_THREAD_ID: returns EINVAL without store_error

That is exactly what Queue() does on main (Aio.cpp:171-176), and the old huge.error == 0 assertion pinned that behaviour on purpose. Newer FreeBSD routes both checks through err2:/err1:, which does store_error, so that matches this PR. But the PS5 kernel is based on FreeBSD 11.

Could you point to a PS5-side source (a trace from real hardware, or a disassembly) showing that these two rejections write EINVAL into the aiocb? Without one, I'd keep main's behaviour and close this.

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read 4b9daae4af against main.

Correctness. The two Fail(GuestEinval) returns in Queue (core/libs/prx/libkernel_sys/Aio.cpp) are not an oversight: they reproduce FreeBSD 11.4 aio_aqueue_job (sys/kern/vfs_aio.c), which stores status = -1 and error = 0 on entry, then calls ops->store_error(ujob, ...) for the queue limit, the copy-in failure and a bad sigev_notify, but returns EINVAL without store_error for aio_nbytes > IOSIZE_MAX and for an invalid sigev_signo. FreeBSD's kern_aio_error then takes the "failure of aio_aqueue" path (fetch_status == -1) and returns the stored error, which is 0 for those two cases. So main's aio_error result of 0 for the oversized and bad-signal requests is the reference behaviour, and the huge.error == 0 assertion was pinning it on purpose, next to the notify.error == Einval assertion for the case where FreeBSD does store it. Switching both to fail makes AnyPS5 diverge from FreeBSD with no PS5 measurement given.

Test. The updated assertions fail on main (it leaves error at 0), so they exercise the change, but they encode the non-FreeBSD result. Unless there is console evidence that the PS5 kernel stores EINVAL here, this should stay as it is on main; if there is, cite it and add a libkernel_sys.md entry recording the departure from FreeBSD.

Not run here; this is from reading the code.

AI-assisted: yes.

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 4b9daae4af, merged onto main 94d70921fa (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: guest_kernel_sys_aio.
  • All of them pass in 3 of 3 runs.
  • Negative control: with this PR's code reverted to main (files it adds removed) and rebuilt, guest_kernel_sys_aio fails in 2 of 2 runs, so the tests detect the change.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 18190 core/libs/prx/libkernel_sys/Aio.cpp

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 4b9daae4af, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#16207, #17573, #18945, #20978, #21054, #22002, #22003, #22042, #22078, #22822, #24354, #24484, #12860, #18915, #19999, #22160, #22890, #22891, #23488, #23751, #24051, #24578, #14506, #19462, #22206, #22291, #22627, #24048, #24424). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_kernel_sys_aio (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6526 tests) on the RTX 3080 has 15 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #12860 (guest_user_service_account_name_limits, guest_user_service_age_level_guest_bounds, guest_user_service_initial_user_bounds, guest_user_service_kratos), #22891 (nkwebkit_securityorigin), #18915 (public_headers); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_apr_read_longeof, guest_filesystem, guest_kernel_rename, guest_windows_directory_link_types, tools_patch_advisor_json, tools_suggest_patches. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@MarcZX10

Copy link
Copy Markdown
Contributor Author

@gabichuuuuu @MarcZX10

No code change pushed on this PR yet. This is a decision for the author, because the review's objection depends on how PS5 behaves, not on the code alone.

What I checked:

  • Head 4b9daae4af (branch fix-aio-error-after-rejected-request) changes only the two return Fail(GuestEinval) lines in Queue() in core/libs/prx/libkernel_sys/Aio.cpp to return fail(GuestEinval), and updates the test assertion for the oversized request from huge.error == 0 to EINVAL.
  • I did not verify the FreeBSD 11.4 aio_aqueue_job / kern_aio_error behaviour described in the review. I have no FreeBSD source here. That claim is the reviewer's reading and is still unchecked.

Options:

  1. Keep the PR as is. Argument: the PR body says the aiocb should carry the EINVAL that aio_error() reports, which is the direction the rest of Queue() already takes. Needed: evidence that the PS5 kernel reports 0 here would contradict this.
  2. Revert the two fail(...) changes and the test change, so main behaviour stays. Argument: matches the FreeBSD reading in the review, which the PR does not cite.
  3. Keep the change and cite evidence (console or FreeBSD source for the exact lines) that the PS5 kernel stores EINVAL here. If it does, add a libkernel_sys debt fragment under docs/dev/debt/changes/ noting any departure from FreeBSD.

@MarcZX10 please pick one (or say which evidence you have). I will apply it on the fork branch, run check_conventions.py, and push fast-forward once you choose.

Not verified by me: the test run (the PR reports one local run, which I did not reproduce) and the FreeBSD comparison.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

I am closing this for now. Recording EINVAL in the aiocb needs console evidence, or a libkernel_sys.md entry that cites it, and none has come in since 7 Nov. If you can measure it on the console, please reopen it with that and we will look again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants