fix(libkernel): announce sendfile's header and trailer reads #17113

Merged
Meh7an merged 1 commit from upstream-pr/17113 into main 2026-12-04 01:59:44 +00:00
Meh7an commented 2026-11-08 10:23:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Meh7an on 2026-11-08T10:23:40Z.


What

sendfile sends its header and trailer vectors from guest memory with ::send, without GuestArenaPrepareHostRead. write, pwrite, AIO and sendto all make that call, and the AGC driver's hook behind it lands pending GPU writes before the host reads the bytes. So a header or trailer the GPU just wrote could go out with its older contents.

SendIovecs now announces each vector. The file data in between is read into a host buffer and needs no announcement.

send has the same gap. It is left to #12700, which adds the call there, so this PR does not repeat it.

Overlap: #12688, #12700 and #12965 change the SendIovecs signature to Socket&, a one-line textual conflict. None of them announces the vectors. tools/pr_overlap.py could not auto-compare 8 PRs touching Udp.cpp because they conflict with main; I read those diffs for SendIovecs, SendAll and sendfile_nid_postfix.

Tested

Windows 11, no title run. guest_sendfile gains a check that the host-read hook is called with each header and trailer vector: it aborts without this change (0xc0000409) and passes with it. Together with it, the 33 ctests matching guest_sendfile|guest_.*socket|guest_host_read pass.

Built and tested on main 0f147e329f, then rebased onto 990481cdbf. SendIovecs and the test file are unchanged between those commits; the tip itself was not built here because it needs the new 3rdparty/curl submodule. Not tested on Linux or macOS.

Rebased onto main 1f56d72520 (2026-11-29). The only conflict was main's new SendIovecs(Socket&, ...) signature, which the change now uses; the added line is unchanged. On that base the 35 ctests matching ^(guest_sendfile|guest_socket_.*|guest_kernel_socket_.*)$ pass, and guest_sendfile still aborts (0xc0000409) without the added line.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of UDP messages made up of multiple buffers, helping ensure each part is ready before transmission. This also supports more consistent sending of data alongside file contents.
  • Tests
    • Added coverage for sending file contents with headers and trailers to verify that all parts are handled.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5210535050 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17113). Originally posted by [Meh7an](https://github.com/Meh7an) on 2026-11-08T10:23:40Z. --- ### What `sendfile` sends its header and trailer vectors from guest memory with `::send`, without `GuestArenaPrepareHostRead`. `write`, `pwrite`, AIO and `sendto` all make that call, and the AGC driver's hook behind it lands pending GPU writes before the host reads the bytes. So a header or trailer the GPU just wrote could go out with its older contents. `SendIovecs` now announces each vector. The file data in between is read into a host buffer and needs no announcement. `send` has the same gap. It is left to #12700, which adds the call there, so this PR does not repeat it. Overlap: #12688, #12700 and #12965 change the `SendIovecs` signature to `Socket&`, a one-line textual conflict. None of them announces the vectors. `tools/pr_overlap.py` could not auto-compare 8 PRs touching `Udp.cpp` because they conflict with main; I read those diffs for `SendIovecs`, `SendAll` and `sendfile_nid_postfix`. ### Tested Windows 11, no title run. `guest_sendfile` gains a check that the host-read hook is called with each header and trailer vector: it aborts without this change (0xc0000409) and passes with it. Together with it, the 33 ctests matching `guest_sendfile|guest_.*socket|guest_host_read` pass. Built and tested on main 0f147e329f, then rebased onto 990481cdbf. `SendIovecs` and the test file are unchanged between those commits; the tip itself was not built here because it needs the new `3rdparty/curl` submodule. Not tested on Linux or macOS. Rebased onto main 1f56d725203 (2026-11-29). The only conflict was main's new `SendIovecs(Socket&, ...)` signature, which the change now uses; the added line is unchanged. On that base the 35 ctests matching `^(guest_sendfile|guest_socket_.*|guest_kernel_socket_.*)$` pass, and `guest_sendfile` still aborts (0xc0000409) without the added line. ### 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) - [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 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of UDP messages made up of multiple buffers, helping ensure each part is ready before transmission. This also supports more consistent sending of data alongside file contents. * **Tests** * Added coverage for sending file contents with headers and trailers to verify that all parts are handled. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
gabichuuuuu commented 2026-11-08 12:31:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T12:31:59Z.

Review: COMMENTED


Windows run of head 2dbe0dd86d, merged onto main 105c9e4d91 (clean merge). That main already has 3rdparty/curl, so this is a build of the tip itself, which the description says wasn't built.

Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release, full build with BUILD_TESTING=ON.

  • -R 'guest_sendfile|guest_.*socket|guest_host_read': 33 / 33 in each of 3 runs.
  • Negative control, with main's Udp.cpp and this PR's test: guest_sendfile aborts 3 / 3 with 0xc0000409. The other files were left as they were, and the PR's Udp.cpp was put back and rebuilt afterwards.

From reading the code: GuestArenaPrepareHostRead_nid_no_patch returns early for a null base or a zero length, so header and trailer entries like {nullptr, 0} stay safe. Each vector is announced right before its own SendAll, so a vector after a failed send isn't announced. That's fine, since it isn't read either.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5817883078 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17113#pullrequestreview-5817883078). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T12:31:59Z. **Review:** COMMENTED --- Windows run of head `2dbe0dd86d`, merged onto `main` `105c9e4d91` (clean merge). That `main` already has `3rdparty/curl`, so this is a build of the tip itself, which the description says wasn't built. **Setup:** Windows 11, WinLibs GCC 15.2 (`x86_64-ucrt-posix-seh`), Release, full build with `BUILD_TESTING=ON`. - `-R 'guest_sendfile|guest_.*socket|guest_host_read'`: 33 / 33 in each of 3 runs. - **Negative control,** with `main`'s `Udp.cpp` and this PR's test: `guest_sendfile` aborts 3 / 3 with `0xc0000409`. The other files were left as they were, and the PR's `Udp.cpp` was put back and rebuilt afterwards. From reading the code: `GuestArenaPrepareHostRead_nid_no_patch` returns early for a null base or a zero length, so header and trailer entries like `{nullptr, 0}` stay safe. Each vector is announced right before its own `SendAll`, so a vector after a failed send isn't announced. That's fine, since it isn't read either.
MarcZX10 commented 2026-11-21 12:02:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:02:40Z.

Review: COMMENTED


Reviewed — no blocking findings

The change at head 2dbe0dd86df368e67fff4da0355f0a4be404d28e correctly announces each sendfile header and trailer vector before sending it; runtime checks were not run in this review.

What I ran

Read the prepared description, commit list, manifest, diff, and both changed files at the pinned head. Used repo_read.py to inspect SendIovecs, its callers, and the host-read hook implementation. No build or tests were run.

Results

Check Result Note
Changed code inspection passed Both changed files read
Build and tests not run Reader access only
Author-reported checks not run Windows 11 results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports the targeted ctests and negative control passed on Windows 11, but those results were not independently verified. The tip was reportedly not built; Linux and macOS behavior was not tested. Both changed files listed in manifest.json under reviewed were read. No files were excluded by the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005064881 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17113#pullrequestreview-6005064881). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T12:02:40Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change at head `2dbe0dd86df368e67fff4da0355f0a4be404d28e` correctly announces each sendfile header and trailer vector before sending it; runtime checks were not run in this review. ## What I ran Read the prepared description, commit list, manifest, diff, and both changed files at the pinned head. Used `repo_read.py` to inspect `SendIovecs`, its callers, and the host-read hook implementation. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code inspection | passed | Both changed files read | | Build and tests | not run | Reader access only | | Author-reported checks | not run | Windows 11 results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports the targeted ctests and negative control passed on Windows 11, but those results were not independently verified. The tip was reportedly not built; Linux and macOS behavior was not tested. Both changed files listed in `manifest.json` under reviewed were read. No files were excluded by the manifest. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-29 09:30:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T09:30:05Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the diff announces each sendfile header and trailer vector immediately before sending it, and the added test checks that all three vectors reach the host-read hook.

What I ran

Reviewed head 9183c6a0e8d2a4efc4a733c62e44949e07d48514. I read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, core/libs/prx/libkernel/Socket/src/Udp.cpp (lines 3330–3500), core/libs/tests/GuestSendfile.cpp (lines 1–100), and core/libs/prx/libc/src/GuestArena.cpp (lines 1035–1070). Both changed files listed in the manifest were read. files.json was unavailable. No commands or tests were run; the test results in the description are author-reported.

Results

Check Result Note
Changed code review passed Both changed files inspected
Tests not run Reported results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported Windows 11 ctest results, behavior on Linux and macOS, and execution on a physical console were not independently verified. No repository files were excluded according to the manifest; files.json was unavailable.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6102279322 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17113#pullrequestreview-6102279322). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-29T09:30:05Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the diff announces each sendfile header and trailer vector immediately before sending it, and the added test checks that all three vectors reach the host-read hook. ## What I ran Reviewed head `9183c6a0e8d2a4efc4a733c62e44949e07d48514`. I read `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, `core/libs/prx/libkernel/Socket/src/Udp.cpp` (lines 3330–3500), `core/libs/tests/GuestSendfile.cpp` (lines 1–100), and `core/libs/prx/libc/src/GuestArena.cpp` (lines 1035–1070). Both changed files listed in the manifest were read. `files.json` was unavailable. No commands or tests were run; the test results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files inspected | | Tests | not run | Reported results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The reported Windows 11 ctest results, behavior on Linux and macOS, and execution on a physical console were not independently verified. No repository files were excluded according to the manifest; `files.json` was unavailable. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 13:09:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:09:08Z.

Review: COMMENTED


Built the changed sources and ran GuestSendfile on Linux against the existing runtime. The fixture passed, including the header and trailer payload and read-announcement checks.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170421940 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17113#pullrequestreview-6170421940). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:09:08Z. **Review:** COMMENTED --- Built the changed sources and ran `GuestSendfile` on Linux against the existing runtime. The fixture passed, including the header and trailer payload and read-announcement checks. AI-assisted: yes.
Plyxen commented 2026-12-03 15:48:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T15:48:15Z.

Review: APPROVED


I read the diff at 9183c6a0e8. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at c1593e4e1dd together with other open PRs (so not an isolated build).

  • guest_sendfile: pass on both.
  • Control (the same tree and tests, with the sources of this PR and of the other CPU PRs in the batch put back to main's): it fails.

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6173210765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17113#pullrequestreview-6173210765). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T15:48:15Z. **Review:** APPROVED --- I read the diff at `9183c6a0e8`. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into `main` at `c1593e4e1dd` together with other open PRs (so not an isolated build). - `guest_sendfile`: pass on both. - Control (the same tree and tests, with the sources of this PR and of the other CPU PRs in the batch put back to `main`'s): it fails. Not checked: a title. AI-assisted: yes (Claude Code)
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!17113
No description provided.