fix(libkernel): fail fsync, fstatfs, fchflags, futimes and flock on a ksem id as FreeBSD 11.4 does #24488

Merged
brajankw merged 2 commits from upstream-pr/24488 into main 2026-11-27 11:05:12 +00:00
brajankw commented 2026-11-20 17:28:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-20T17:28:53Z.


What

These calls reached the host null device behind a ksem id: fstatfs returned host data, fchflags threw, and futimes tried to set the null device's times. FreeBSD 11.4 takes the vnode for fsync, fdatasync, fstatfs, fchflags and futimes through getvnode, which fails with EINVAL for a file that is not a vnode, and sys_flock fails with EOPNOTSUPP for one, before it checks the operation.

  • These now answer as they already do for a kqueue, except futimes, which #24483 fixes for a kqueue.
  • futimes still copies its times in first, as kern_futimes runs getutimes before getvnode, so EFAULT keeps its place.
  • IsKsemDescriptor, which this uses, is replaced by DuplicateKsemDescriptor in open #22191. The two merge without a textual conflict, but whichever lands second needs a rebase that keeps a ksem predicate, or the build breaks. I will rebase this as soon as #22191 lands.
  • Tests: VnodeCalls in GuestKernelSysKsem.cpp, including flock with operation 0.
  • Debt: no fragment.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head ad4b485923, on #24487's head f78c18f92a, which has since merged, so main now contains it and this PR shows only its own commit. The runs after the first two bullets are from earlier heads.

  • At ad4b485923: ctest -R '^guest_(kernel_sys_ksem|kqueue|kqueue_cleared_race)$': 3/3 passed.
  • At 7aba775579, merged with my eight other updated branches onto main bd9a6c00a6: ctest over the 23 tests these branches touch (guest_kernel_ioctl_fionread, guest_kernel_ioctl_device_type, guest_kernel_fcntl*, guest_kernel_app_archive_*, guest_kernel_sys_ksem, guest_kqueue, guest_equeue_events, guest_socket_events, guest_system_configuration, guest_socket_pair, guest_recvmsg_memory, guest_kernel_sys_cpuset, np_uds_events, guest_np_uds_* and guest_np_trophy_*): all pass.
  • Negative control: with only the test change, on main 84e16538d4, guest_kernel_sys_ksem fails at the new fstatfs check.
  • On 85bc501067, ctest over guest_kernel_sys_ksem, guest_kqueue, guest_kernel_sys, guest_filesystem, guest_file_vector, guest_kernel_sys_aio, guest_equeue_events, guest_kernel_fcntl, guest_kernel_ioctl_fionread and guest_kernel_ioctl_device_type: all 10 pass.
  • Full ctest (6393 tests, -j 12) on this branch and my other eleven branches of this round, merged onto main 84e16538d4: 6378 passed. The 15 failures also fail on main in this environment:
    • nine need a .git directory, network access or a passwd entry for the user: conventions_git_errors, test_script_registration, web_library_assets, title_run, title_run_identity, guest_kernel_sys_login, guest_net_ctl, guest_getlogin and guest_getlogin_no_session;
    • five agc_driver GPU cases fail the same way on main: prepared_shaders with its indirect, uncached and debug forms, and storage_file_write;
    • agc_driver_image_table_packed_guards is unstable on main as well (2 of 10 runs passed on its own on main 3f4693be43).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch fix/libkernel-ksem-vnode-calls: #22191 adds a call in the same place of GuestKernelSysKsem.cpp's main (line 300), so whichever lands second needs a rebase; could not compare #6936, #7121, #7447, #9293, #9297, #9302, #12682, #12688, #12700, #12965 and #15037, which conflict with main; none of them touches these checks.
  • Not tested on Windows or macOS. No title.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5417568305 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24488). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-20T17:28:53Z. --- ### What These calls reached the host null device behind a ksem id: `fstatfs` returned host data, `fchflags` threw, and `futimes` tried to set the null device's times. FreeBSD 11.4 takes the vnode for `fsync`, `fdatasync`, `fstatfs`, `fchflags` and `futimes` through [`getvnode`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L3850-L3877), which fails with `EINVAL` for a file that is not a vnode, and [`sys_flock`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_descrip.c#L2889-L2903) fails with `EOPNOTSUPP` for one, before it checks the operation. - These now answer as they already do for a kqueue, except `futimes`, which #24483 fixes for a kqueue. - `futimes` still copies its times in first, as `kern_futimes` runs `getutimes` before `getvnode`, so `EFAULT` keeps its place. - `IsKsemDescriptor`, which this uses, is replaced by `DuplicateKsemDescriptor` in open #22191. The two merge without a textual conflict, but whichever lands second needs a rebase that keeps a ksem predicate, or the build breaks. I will rebase this as soon as #22191 lands. - Tests: `VnodeCalls` in `GuestKernelSysKsem.cpp`, including `flock` with operation 0. - Debt: no fragment. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release). Head `ad4b485923`, on #24487's head `f78c18f92a`, which has since merged, so `main` now contains it and this PR shows only its own commit. The runs after the first two bullets are from earlier heads. - At `ad4b485923`: `ctest -R '^guest_(kernel_sys_ksem|kqueue|kqueue_cleared_race)$'`: 3/3 passed. - At `7aba775579`, merged with my eight other updated branches onto `main` `bd9a6c00a6`: `ctest` over the 23 tests these branches touch (`guest_kernel_ioctl_fionread`, `guest_kernel_ioctl_device_type`, `guest_kernel_fcntl*`, `guest_kernel_app_archive_*`, `guest_kernel_sys_ksem`, `guest_kqueue`, `guest_equeue_events`, `guest_socket_events`, `guest_system_configuration`, `guest_socket_pair`, `guest_recvmsg_memory`, `guest_kernel_sys_cpuset`, `np_uds_events`, `guest_np_uds_*` and `guest_np_trophy_*`): all pass. - Negative control: with only the test change, on `main` `84e16538d4`, `guest_kernel_sys_ksem` fails at the new `fstatfs` check. - On `85bc501067`, `ctest` over `guest_kernel_sys_ksem`, `guest_kqueue`, `guest_kernel_sys`, `guest_filesystem`, `guest_file_vector`, `guest_kernel_sys_aio`, `guest_equeue_events`, `guest_kernel_fcntl`, `guest_kernel_ioctl_fionread` and `guest_kernel_ioctl_device_type`: all 10 pass. - Full `ctest` (6393 tests, `-j 12`) on this branch and my other eleven branches of this round, merged onto `main` `84e16538d4`: 6378 passed. The 15 failures also fail on `main` in this environment: - nine need a `.git` directory, network access or a passwd entry for the user: `conventions_git_errors`, `test_script_registration`, `web_library_assets`, `title_run`, `title_run_identity`, `guest_kernel_sys_login`, `guest_net_ctl`, `guest_getlogin` and `guest_getlogin_no_session`; - five `agc_driver` GPU cases fail the same way on `main`: `prepared_shaders` with its `indirect`, `uncached` and `debug` forms, and `storage_file_write`; - `agc_driver_image_table_packed_guards` is unstable on `main` as well (2 of 10 runs passed on its own on `main` `3f4693be43`). - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch fix/libkernel-ksem-vnode-calls`: #22191 adds a call in the same place of `GuestKernelSysKsem.cpp`'s `main` (line 300), so whichever lands second needs a rebase; could not compare #6936, #7121, #7447, #9293, #9297, #9302, #12682, #12688, #12700, #12965 and #15037, which conflict with `main`; none of them touches these checks. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-20 17:55:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T17:55:57Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 85bc501067:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_sys_ksem_tests, guest_kqueue_tests built cleanly.
  • CTest (guest_kernel_sys_ksem, guest_kqueue, guest_kqueue_cleared_race):
    1/3 Test #5877: guest_kqueue .....................   Passed    5.75 sec
    2/3 Test #1036: guest_kernel_sys_ksem ............   Passed    5.39 sec
    3/3 Test #5878: guest_kqueue_cleared_race ........   Passed   23.96 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #5877: guest_kqueue .....................Subprocess aborted***Exception:   0.74 sec
    2/3 Test #1036: guest_kernel_sys_ksem ............***Failed    5.38 sec
    3/3 Test #5878: guest_kqueue_cleared_race ........***Timeout  30.12 sec
    0% tests passed, 3 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified sceKernelRead, sceKernelWrite, sceKernelLseek, sceKernelReadv, and sceKernelWritev reject ksem descriptors with SCE_KERNEL_ERROR_EOPNOTSUPP (or 0 when bytes/iov is empty for read) and SCE_KERNEL_ERROR_ESPIPE as FreeBSD 11.4 does
    • Verified sceKernelFsync, sceKernelFdatasync, _fstatfs_nid_postfix, fchflags_nid_postfix, and sceKernelFutimes fail with EINVAL on ksem descriptors matching getvnode behaviour in FreeBSD 11.4
    • Verified flock_nid_postfix fails with EOPNOTSUPP on ksem descriptors before evaluating operation arguments, matching sys_flock behaviour in FreeBSD 11.4
    • Verified TransferArgumentError and PositionedArgumentError in Stdio.cpp properly handle null buffers and positioned transfers for ksem descriptors
    • Verified unit test coverage in GuestKernelSysKsem.cpp (Transfers and VnodeCalls) and GuestKqueue.cpp thoroughly covers all modified entrypoints and error codes

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5997138532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24488#pullrequestreview-5997138532). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T17:55:57Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `85bc501067`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_sys_ksem_tests`, `guest_kqueue_tests` built cleanly. - **CTest** (`guest_kernel_sys_ksem`, `guest_kqueue`, `guest_kqueue_cleared_race`): ``` 1/3 Test #5877: guest_kqueue ..................... Passed 5.75 sec 2/3 Test #1036: guest_kernel_sys_ksem ............ Passed 5.39 sec 3/3 Test #5878: guest_kqueue_cleared_race ........ Passed 23.96 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #5877: guest_kqueue .....................Subprocess aborted***Exception: 0.74 sec 2/3 Test #1036: guest_kernel_sys_ksem ............***Failed 5.38 sec 3/3 Test #5878: guest_kqueue_cleared_race ........***Timeout 30.12 sec 0% tests passed, 3 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - Verified sceKernelRead, sceKernelWrite, sceKernelLseek, sceKernelReadv, and sceKernelWritev reject ksem descriptors with SCE_KERNEL_ERROR_EOPNOTSUPP (or 0 when bytes/iov is empty for read) and SCE_KERNEL_ERROR_ESPIPE as FreeBSD 11.4 does - Verified sceKernelFsync, sceKernelFdatasync, _fstatfs_nid_postfix, fchflags_nid_postfix, and sceKernelFutimes fail with EINVAL on ksem descriptors matching getvnode behaviour in FreeBSD 11.4 - Verified flock_nid_postfix fails with EOPNOTSUPP on ksem descriptors before evaluating operation arguments, matching sys_flock behaviour in FreeBSD 11.4 - Verified TransferArgumentError and PositionedArgumentError in Stdio.cpp properly handle null buffers and positioned transfers for ksem descriptors - Verified unit test coverage in GuestKernelSysKsem.cpp (Transfers and VnodeCalls) and GuestKqueue.cpp thoroughly covers all modified entrypoints and error codes Looks Good To Me
MarcZX10 commented 2026-11-21 05:39:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:39:12Z.

Review: APPROVED


Reviewed — looks good

Nothing in the changed code blocks merging; the targeted review found no verified defects.

What I ran

Reviewed head 85bc5010674a842c1db7ae8f3cb6c1428fbf3ff5 using the prepared diff and pinned reader. No commands or tests were run by me; test results in the PR description are author-reported.

Read core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp, core/libs/tests/GuestKernelSysKsem.cpp, core/libs/tests/GuestKqueue.cpp (changed files; included in the review folder), and the targeted context in core/libs/prx/libkernel/Semaphore/include/Ksem.hpp and core/libs/prx/libkernel/Semaphore/src/Ksem.cpp.

Results

Check Result Note
Changed-code review passed No verified defect found
Author-reported targeted tests not run Ten named CTest cases reported passing
Windows and macOS checks not run Not tested per PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run tests, build the change, or verify behavior on Windows, macOS, or a console. The author reports Linux Debian 13/GCC 14.2 Release testing and a passing set of ten targeted CTest cases. All changed files were included and read; files.json exclusions were not provided in the prepared materials, so excluded-file status is not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003209430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24488#pullrequestreview-6003209430). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T05:39:12Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the changed code blocks merging; the targeted review found no verified defects. ## What I ran Reviewed head `85bc5010674a842c1db7ae8f3cb6c1428fbf3ff5` using the prepared diff and pinned reader. No commands or tests were run by me; test results in the PR description are author-reported. Read `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp`, `core/libs/tests/GuestKernelSysKsem.cpp`, `core/libs/tests/GuestKqueue.cpp` (changed files; included in the review folder), and the targeted context in `core/libs/prx/libkernel/Semaphore/include/Ksem.hpp` and `core/libs/prx/libkernel/Semaphore/src/Ksem.cpp`. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | No verified defect found | | Author-reported targeted tests | not run | Ten named CTest cases reported passing | | Windows and macOS checks | not run | Not tested per PR description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run tests, build the change, or verify behavior on Windows, macOS, or a console. The author reports Linux Debian 13/GCC 14.2 Release testing and a passing set of ten targeted CTest cases. All changed files were included and read; `files.json` exclusions were not provided in the prepared materials, so excluded-file status is not verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 09:27:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T09:27:58Z.

Review: COMMENTED


Reviewed — no blocking findings

The changed code consistently routes ksem descriptors through the intended error paths; I did not independently run the reported checks.

What I ran

Reviewed head 7aba775579e5bcbc3976ddafbdf7bef221368900 using the pinned reader. No tests or other commands were run.

Results

Check Result Note
Changed code review passed All three changed files were inspected
Tests not run Results in the description are author-reported

Negative control

Not run independently; the description reports a negative control on an earlier main revision.

Findings

Blocking

None.

Non-blocking

None.

Sources

  • core/libs/prx/libkernel/File/src/Open.cpp and core/libs/prx/libkernel/File/src/Stdio.cpp at head 7aba775579e5bcbc3976ddafbdf7bef221368900.
  • core/libs/tests/GuestKernelSysKsem.cpp at head 7aba775579e5bcbc3976ddafbdf7bef221368900.

Not verified

No checks were run independently. The description reports test results, but they were not confirmed in this review. All changed files listed in the manifest were included and inspected; no changed files were excluded.

To get this to a good state

Nothing is required. Optional: confirm the reported checks on the current head in CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6054946395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24488#pullrequestreview-6054946395). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T09:27:58Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed code consistently routes ksem descriptors through the intended error paths; I did not independently run the reported checks. ## What I ran Reviewed head `7aba775579e5bcbc3976ddafbdf7bef221368900` using the pinned reader. No tests or other commands were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files were inspected | | Tests | not run | Results in the description are author-reported | ## Negative control Not run independently; the description reports a negative control on an earlier main revision. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - `core/libs/prx/libkernel/File/src/Open.cpp` and `core/libs/prx/libkernel/File/src/Stdio.cpp` at head `7aba775579e5bcbc3976ddafbdf7bef221368900`. - `core/libs/tests/GuestKernelSysKsem.cpp` at head `7aba775579e5bcbc3976ddafbdf7bef221368900`. ## Not verified No checks were run independently. The description reports test results, but they were not confirmed in this review. All changed files listed in the manifest were included and inspected; no changed files were excluded. ## To get this to a good state Nothing is required. Optional: confirm the reported checks on the current head in CI.
MarcZX10 commented 2026-11-25 11:37:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T11:37:38Z.

Review: APPROVED


Reviewed — looks good

The reviewed changes add ksem-specific descriptor errors and regression coverage; no verified blocking defect was found in the inspected code.

What I ran

  • Reviewed head ad4b4859235f4d57376fac71b9ba581cb204c5d2 using the prepared diff and repo_read.py.
  • No commands or tests were run by me. The author reports selected tests and a negative control in description.md; these were not independently verified.
  • Read all changed lines in Open.cpp, Stdio.cpp, and GuestKernelSysKsem.cpp, plus the ksem descriptor predicate implementation.

Results

Check Result Note
Changed-line review passed All changed lines inspected
Tests run by reviewer not run Author-reported runs not independently checked
Negative control not run Author reports it failed as expected

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Test runs described by the author, including the negative control.
  • Behavior on Windows, macOS, and physical console hardware.
  • Files excluded by the prepared packet under files.json; that document was unavailable through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6056902728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24488#pullrequestreview-6056902728). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T11:37:38Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed changes add ksem-specific descriptor errors and regression coverage; no verified blocking defect was found in the inspected code. ## What I ran - Reviewed head `ad4b4859235f4d57376fac71b9ba581cb204c5d2` using the prepared diff and `repo_read.py`. - No commands or tests were run by me. The author reports selected tests and a negative control in `description.md`; these were not independently verified. - Read all changed lines in `Open.cpp`, `Stdio.cpp`, and `GuestKernelSysKsem.cpp`, plus the ksem descriptor predicate implementation. ## Results | Check | Result | Note | |---|---|---| | Changed-line review | passed | All changed lines inspected | | Tests run by reviewer | not run | Author-reported runs not independently checked | | Negative control | not run | Author reports it failed as expected | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Test runs described by the author, including the negative control. - Behavior on Windows, macOS, and physical console hardware. - Files excluded by the prepared packet under `files.json`; that document was unavailable through the reader. ## To get this to a good state Nothing is required.
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!24488
No description provided.