feat(libkernel): support EVFILT_WRITE on the write end of a pipe #7075
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7075"
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 AlexOfTheForest on 2026-10-17T10:25:07Z.
What
keventthrewNotImplementedforEVFILT_WRITEon any descriptor that is not a socket. On the write end of a pipe it now follows FreeBSD 11'sfilt_pipewriteandpipe_kqfilter:datais the free space in the host pipe buffer:F_GETPIPE_SZminusFIONREADon Linux, the write quota on Windows.EV_EOFwithdata0.EPIPE.Two commits:
feat(libkernel): report the write end of a pipe to equeue descriptor polls:GuestSockets::Readyonly knew the read end of a pipe, andWaitAnyasked the host forPOLLINon every descriptor that is not a socket, so a write interest on a pipe could never fire or wake a wait. AddsPipeWriteState;Readyreports the write end when it is writable or at EOF, andWaitAnyasks forPOLLOUTon it.feat(libkernel): support EVFILT_WRITE on the write end of a pipe: thekeventside, the libkernel debt entries, and aPipeWritecase inguest_kqueue. The test covers: free space before and after a write, no event while the pipe is full (filled withO_NONBLOCKwrites untilEAGAIN), a blocking wait woken when another thread drains the pipe,EV_EOFwithdata0 after the read end closes, andEPIPEwhen the event is added after that.Not changed:
EVFILT_WRITEon the read end still throws, because FreeBSD's pipe ends are bidirectional and host pipes are one-way.EV_CLEARandNOTE_LOWATon a pipe still throw. On macOSEVFILT_WRITEon a pipe throws, because the host has no call for a pipe's capacity. Readiness on Linux follows the host'sPOLLOUTrather than FreeBSD's 512 free bytes, so a guest is never told to write into a pipe that would block. This is documented in the debt file.Tested
Linux x86_64:
guest_kqueue,guest_equeue_events,guest_poll,guest_selectandguest_select_waitall passed 5 of 5 runs. With theWaitAnychange reverted,guest_kqueuefails: the wait runs out its 5 s limit instead of waking when the pipe drains.tools/check_conventions.py --base upstream/mainpasses; the progress report is unchanged. The Windows path (NtQueryInformationFilewrite quota, the same checkpollalready uses) is written but not run. On macOS this case still throws, and the test keeps checking that it throws there.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 github-actions[bot] on 2026-10-17T10:31:30Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/Socket/src/Udp.cppL379docs/dev/debt/libkernel.mdL117, L189docs/dev/debt/libkernel.mdL117-118docs/dev/debt/libkernel.mdL117docs/dev/debt/libkernel.mdL116-117Some 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.
docs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Equeue/src/Kqueue.cppcore/libs/tests/GuestKqueue.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T10:12:57Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One docs-debt conflict, unioned.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; the kqueue tests pass; full suite green apart from the knownmainregression (agc_driver_tessellationsegfault — Mesa, #5444), not this PR.To pick it up:
Head is
d7023cce2.Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-18T12:04:13Z.
@blawesom thanks for the rebase. I redid it on my side so the commits stay under my identity as committer too, using your docs resolution as the reference. The branch is now rebased on current main; guest_kqueue, guest_socket_events, guest_equeue_events, guest_poll and guest_select pass 3/3 on Linux.
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-18T21:30:23Z.
The new
PipeWriteinGuestKqueue.cpptakesstartafter it creates the reader thread that acts after 50 ms, then requireswaited >= 40 ms. Under parallel load the main thread can be preempted between creating that thread and reading the clock, sowaitedcomes out under 40 ms althoughkeventdid wait for the read.PipeReadin the same file has this order and aborts that way on Windows: on our RX 6700 XT PC, 9 of 120 runs under load. A timing probe caught 4 such aborts, and in each the main thread tookstart39 to 68 ms after creating the writer, withkeventreturning 0.3 to 1.4 ms after the write. #7670 movesstartbefore the thread there and inguest_socket_events. Takingstartbefore creating the reader here keeps the new check from flaking the same way.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:51:47Z.
Review: CHANGES_REQUESTED
The full Build's Windows job fails
guest_kqueueon the current head (run 39295565110,mainis green there):PipeWriteincore/libs/tests/GuestKqueue.cpp(thefcntl_nid_postfix(pipe[1], SetStatusFlags, NonBlocking)line) throws on Windows:fcntl: cannot change the mode of pipe descriptor 5, error=231(SetNamedPipeHandleStateon the write end,DescriptorControl.cpp:169). The test never reaches thekeventcode.O_NONBLOCKon the write end (or makefcntlsupport it there), or limit the full-pipe/drain part of the test to Linux and keep the free-space,EV_EOFandEPIPEchecks on both. If the write-end path ofPipeWriteState(NtQueryInformationFilewrite quota) cannot be exercised on Windows, say so in the debt entry.The rest of the libkernel scope passes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T15:16:41Z.
Rebased onto current
mainand added one commit of ours for the Windows failure ofguest_kqueue(fcntlcannot setO_NONBLOCKon a pipe write end there, error=231):PipeWrite: the full-pipe and drain part now runs off Windows only; on Windows the test reads back what it wrote and still checks the free space,EV_EOFandEPIPE.startis taken before the reader thread is created, as @thuanquang pointed out.Checked the diff against FreeBSD 11's
filt_pipewrite/pipe_kqfilter;guest_kqueueand the libkernel scope pass; merged.