fix(libkernel): stop cutting regular-file reads and writes at 0x7ffff… #24076
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24076"
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 jpirz on 2026-11-20T05:21:25Z.
What
On Linux one
read,write,pread,pwrite,readv,writev,preadvorpwritevmoves at most0x7ffff000bytes (read(2)), and on macOSreadandwritereject more thanINT_MAXbytes.sceKernelRead,sceKernelWrite,sceKernelPread,sceKernelPwrite, the four vector exports, their POSIX forms and the AIO read and write commands handed each request on a host regular file to one such call, so on Linux any request above0x7ffff000bytes came back short although the file held the data. FreeBSD 11.4 accepts up toSSIZE_MAXper call for a 64-bit process (iosize_max_clamp = 0insys/kern/sys_generic.c), and POSIX allows a short regular-file read only at end of file or after a signal. The Windows vector path already loops.File::TransferInParts(POSIX branch ofStdio.cpp, declared inFile.hpp) sends a transfer of more than0x7ffff000bytes on a regular file to the host in parts of at most 1 GiB withreadv/writev/preadv/pwritev, splitting the iovec array at part boundaries. It stops at a short part and returns the bytes already moved when a later part fails. It returns -2, like the shared-memory helpers, for transfers that one host call serves whole, totals aboveSSIZE_MAX, negative or overflowing offsets and descriptors that are not regular files; those keep their original single host call, so transfers up to0x7ffff000bytes stay atomic as before, and pipes, sockets, terminals and every existing error path are unchanged. Call sites:NativeRead/NativeWrite(Open.cpp),NativePread/NativePwriteand the four vector exports (Stdio.cpp), and the AIONativePread/NativePwrite(Aio.cpp).A new libkernel debt entry records that, for a split transfer, another transfer or seek on the same open file, or a write to the same file, can run between two parts (FreeBSD's
vn_io_faultholds the file offset and a range lock for the whole transfer), and the paths that are still one host call: Windowsread,write,pread,pwrite, theirsceKernelforms and the AIO read and write commands (unchanged; they throw aboveUINT_MAXbytes, and_readrejects more thanINT_MAX), positioned and AIO writes to anO_APPENDfile on macOS (WritevAtEnd), and writes to shared memory objects. None of this was measured on a console.Tested
Ubuntu 24.04 x86-64 container, rebased onto and built at
d50640e264(CMake, Ninja, Release, gcc 13,BUILD_TESTING=ON; targets chosen bytools/select_tests.py, pluslibs).LargeTransfersinguest_file_vector(not on Windows): one 64 MiB file mapped 34 times as a contiguous 0x88000000-byte buffer; a 0x84000000-byte sparse file is read withsceKernelRead,sceKernelPread, an AIO read command,sceKernelReadvandsceKernelPreadv, then 0x88000000 bytes are written withsceKernelWritev, checking counts, the file offset and size, and marks that straddle the 1 GiB part boundaries. The file is truncated to 0 right after the write.d50640e2with the test, library sources reverted):File vector check failed at line 176in 3 of 3 runs, withstraceshowing the hostreadof 0x88000000 bytes returning 0x7ffff000 (2147479552). Earlier, a separate program showed every read form (sceKernelRead,read,sceKernelPread,pread,sceKernelReadv,readv,sceKernelPreadv,preadv, AIO read) and every write form (sceKernelWrite,sceKernelPwrite,sceKernelWritev,sceKernelPwritev, AIO write) returning0x7ffff000for 0x88000000-byte requests.guest_file_vectorpasses in 4 of 4 runs, about 3 s each. In CI the write side is covered throughsceKernelWritevonly; the positioned and single-buffer write forms were checked with the separate program, not in the repository, to keep the test at one 2 GiB write.a445e0f0): a pipe read stays one call (1 MiB returned), a destination unmapped at 1.25 GiB returns 0x50000000, an unmapped first byte returnsEFAULT, a negative AIO offset returnsEINVAL,sceKernelReadofSIZE_MAXreturnsEFAULTandreadofSIZE_MAXEINVAL.tools/select_tests.py, 5540 of 6339,ctest -j3): 5319 pass, 193 are skipped (mostlyagc_driver_*) and 28 fail, none because of this change: 24 socket tests that open IPv6 sockets, which this container lacks (guest_sce_netandguest_socket_listen_backlog_boundsamong them, both failing with the library sources reverted too);agc_driver_image_gather_lodandagc_driver_image_table_packed_guards, which fail on this container's software Vulkan (llvmpipe) with the sources reverted too; andagc_driver_pm4_order_signal, a latency threshold that fails on and off on this loaded machine with and without the change, andagc_driver_runtime_buffer_spans_x3_spans, which timed out in the parallel run and passes alone.iovec wholedeclarations inNativePwriteand the AIONativePwritemoved out of#ifdef __APPLE__and are now compiled on Linux too; Windows code is untouched.tools/pr_overlap.py --branchagainst the open pull requests: no conflicting lines or shared exports. Older pull requests that conflict withmainshareOpen.cpp,Stdio.cpp,Aio.cpp,File.hppor the libkernel debt file; read by hand, none of them splits large regular-file transfers (#12700 and #12965 split blocking pipe reads for cancellation).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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T05:24:03Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
411d08d0ca:tools/check_conventions.pypassed.guest_file_vector_testsbuilt cleanly.guest_file_vector):core/libs/prx/libkernel/Aio/src/Aio.cpp,core/libs/prx/libkernel/File/include/File.hpp,core/libs/prx/libkernel/File/src/Open.cpp,core/libs/prx/libkernel/File/src/Stdio.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:50:18Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent aggregate iovec length overflow before deciding whether to split.
What I ran
Inspected head
411d08d0ca71c707dde8cc3e7345cdee88286327usingrepo_read.pyaccess. No build or tests were run during this review.Results
Findings
Blocking
core/libs/prx/libkernel/File/src/Stdio.cpp:494sumsiov_lenvalues in an unsigned 64-bit accumulator without checking overflow. An iovec total greater thanSSIZE_MAXcan wrap to a value at or below0x7ffff000, causingTransferInPartsto return-2and the caller to make one oversized host call. On Linux this can reproduce the short-transfer behavior this change intends to fix, and wrapped totals could also misdirect the split loop. Reject overflow before accumulating, preserving the existing fallback/error behavior for invalid totals.Non-blocking
None.
Not verified
No build or tests were run. The author reports Ubuntu 24.04 x86-64 test results in the PR description; those results were not independently verified here. macOS, Windows, and console behavior were not run or confirmed. All changed files listed in
manifest.jsonwere read; no changed files were excluded.To get this to a good state
Add checked accumulation for the iovec total so overflow cannot bypass the splitting path; then rerun the build and relevant large-transfer tests on the new head.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T06:58:50Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b1ee66a978:tools/check_conventions.pypassed.guest_file_vector_testsbuilt cleanly.guest_file_vector):core/libs/prx/libkernel/Aio/src/Aio.cpp,core/libs/prx/libkernel/File/include/File.hpp,core/libs/prx/libkernel/File/src/Open.cpp,core/libs/prx/libkernel/File/src/Stdio.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.iov[i].iov_lenintostd::uint64_t totalwithout checked addition allows integer overflow. For example, two iovec buffers with lengths0xFFFFFFFF00000000ULLand0x0000000100001000ULLsum with 64-bit unsigned wrap-around to0x1000ULL(<= 0x7ffff000), causingTransferInPartsto bypass splitting and return -2, incorrectly delegating an aggregate transfer exceeding SSIZE_MAX to a single host call instead of triggering splitting or error fallback. Checked addition (e.g. testingtotal > std::numeric_limits<std::uint64_t>::max() - iov[i].iov_len) is required before accumulating.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:01:38Z.
Review: APPROVED
Reviewed — looks good
The implementation and all six changed files were reviewed at head
b1ee66a978c2e597cb1f68221eab02e744e9602f; no concrete defect was found, but checks were not run in this review.What I ran
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build or tests were run independently. The PR description reports selected tests passing on Ubuntu 24.04 x86-64 and lists unrelated failures in that environment. macOS, Windows, and console behavior were not verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T19:44:10Z.
Review: COMMENTED
Reviewed — no blocking findings
The change at head
107d38ff15c5cedd0883088ae7d873ed101097a2has no verified blocking defects; I could not run its checks, so a formal approval is not justified.What I ran
Read the prepared description, commits, manifest, and diff, then read all six changed files at the pinned head. No commands or tests were run;
repo_read.pywas used to inspect the source.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
I did not run the reported build, tests, or negative control. The description reports the large-transfer test passing in four runs and the selected suite results; these are author-reported, not independently confirmed. The changes list has six files, all included and read; no files were excluded by the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T19:53:02Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
107d38ff15:tools/check_conventions.pypassed.guest_file_vector_testsbuilt cleanly.guest_file_vector):core/libs/prx/libkernel/Aio/src/Aio.cpp,core/libs/prx/libkernel/File/include/File.hpp,core/libs/prx/libkernel/File/src/Open.cpp,core/libs/prx/libkernel/File/src/Stdio.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me