feat(libkernel): always fire a socket read knote with NOTE_LOWAT below 1 #14832
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14832"
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 kallmek3nny on 2026-11-01T19:15:33Z.
What
A socket
EVFILT_READknote withNOTE_LOWATand a mark below 1 threwNotImplemented_nid_no_patch. It now follows FreeBSD 11.4.filt_soreadsetskn_data = sbavail(&so->so_rcv) - so->so_rcv.sb_ctland, withNOTE_LOWAT, returnskn_data >= kn_sdata.sbavailreturns au_int(sockbuf.h), so the difference is unsigned andkn_data, anintptr_t(event.h), is never negative. A mark of 0 or below is therefore always met:keventcall, withdataset to the queued bytes: 0 on an empty socket, withoutEV_EOF.EV_CLEARknote is reported once when it is added and again after new data arrives, becausekqueue_scandequeues anEV_CLEARknote after reporting it.EV_ADDon an existing knote replaces the mark, askqueue_registercopieskev->dataintokn_sdatafor descriptor filters and then callsf_event. A drained socket re-added with -1 is reported (data0); re-added with 1 it is not.soo_kqfiltergives itfilt_solisten, which has noNOTE_LOWAThandling.EVFILT_WRITEmark below 1 still throws.filt_sowritecomparessbspace, which can be negative, and returns 0 on an unconnected socket whose protocol requires a connection, so a write mark below 1 is not always met.The kevent measurements entry in
docs/dev/debt/libkernel.md(payload processes on a PS5, firmware 12.70) recorded the level-triggered stream-socket case as still throwing here: a mark of 0 on an empty Unix-domain stream socket gave a read event at once (data0), and so did re-adding that knote with -1 once the socket was drained. This PR implements that behaviour and removes the clause from that entry (line 172). In the kevent entry (line 167), "Marks below 1 ... throw" now says a read mark below 1 is always met except on a listening socket, and a write mark below 1 throws. TheEV_CLEARand listening-socket cases are not measured on a PS5.Code:
DescriptorLowWaterinEqueue/src/Kqueue.cppthrows for a mark below 1 only onEVFILT_WRITE. The newLowWaterAlwaysMetsetsKernelEqueueEvent::lowWaterAlwaysMetwhen a knote is added and whenEV_ADDchanges an existing one. The level-triggered poll inEqueue/Equeue.cppandPollEdgeinKqueue.cppreport a socket that the host does not report as readable when that flag is set and the socket is not listening, withdata0 and no EOF.Tests in
core/libs/tests/GuestKqueue.cpp:LowWaterMarks: a mark of 0 on a stream socket with 4 queued bytes (data4); a mark of 8 there (no event). On an idle stream socketpair: a mark of 0 (event,data0, noEV_EOF), then 3 bytes sent (data3), then a re-add with -1 after draining (data0) and with 1 (no event).EdgeTriggeredSocketRead: anEV_CLEARknote with a mark of 0 gives one event withdata0 and none on the next call, then one withdata2 after 2 bytes are sent, then none.Overlap: no open PR implements a read mark below 1. Open-PR searches for
NOTE_LOWAT,low water,lowatandfilt_soreadreturn #7088, #7121, #9843 and #10645, and all four keep the throw or don't touch it.tools/pr_overlap.pyreports #12741 (macOS edge watches) on debt line 167. #12741 rewrites that entry and keeps the "Marks below 1 ... throw" text, and it changesEdgeWatch.cpp, not the code here. #12741 was opened first, so the proposed order is #12741 first (Depends on: #12741, proposed to its author in a comment here). After #12741 merges, this branch is rebased ontomainand keeps both edits to that line.RejectEdgeWriteMarknext toDescriptorLowWaterand inAddDescriptorKnoteandModifyKnote, and adds a write-side test inGuestKqueue.cpp. It is write-side only and changes none of the lines this PR changes, but itsKqueue.cpphunks are next to ours and it also rewrites the same kevent debt entry, so the second to merge will likely need a rebase.sceKernelAddReadEvent/sceKernelAddWriteEventpath inEqueue.cpp(lines 876-896 onmain) and debt line 192 for sizes above 1. It does not touch the kevent read-mark-below-1 throw.main. I searched each of their diffs for added or removed lines namingNOTE_LOWAT, low water,lowWater,below 1orfilt_soread; for #5021, wheregh pr difffailed, I searched its per-file patches from the GitHub API. Only #7088 and #9843 match, as above. #7088 makes regular files ignoreNOTE_LOWATand keeps "marks below 1 ... throw" in its rewrite of the debt entry. #7121, #9293, #9297 and #9302 shareEqueue.hpp,Equeue.cpp,Kqueue.cpporGuestKqueue.cppbut change none of the code lines this PR changes and no low-water text.Tested
Windows 11 Home 10.0.26300.9711, Git Bash, WinLibs gcc/g++, Ninja, Release. No title or homebrew; only the guest kqueue and public header tests were run.
e450145140, before the branch was cut:git submodule update --init --recursive --jobs 8,cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_TESTING=ON -DPython3_EXECUTABLE=C:/Python314/python.exe,cmake --build build --parallel 4: exit 0.f2d874c1fd), after the last edit:cmake --build build --target guest_kqueue_tests --parallel 4rebuilt 11 libkernel objects, among themEqueue.cppandKqueue.cpp, andGuestKqueue.cpp, and relinkedlibkernel.prxandguest_kqueue_tests.exe: exit 0.ctest --test-dir build -R '^guest_kqueue$' --no-tests=error --output-on-failure --timeout 120: 1/1 passed (5.55 s).f0a712175f:ctest --test-dir build -R '^guest_kqueue|public_headers' --no-tests=error --output-on-failure --timeout 120: 67/67 passed (public_headers,public_headers_compile_0to_63,guest_kqueue,guest_kqueue_cleared_race).python tools/check_conventions.py --base origin/main: exit 0, 0 errors and 2debt-lengthwarnings fordocs/dev/debt/libkernel.md. Line 167 is 3622 characters (3537 onmain) and line 172 is 4159 characters (4336 onmain); both were already over 1000 characters onmain.python tools/pr_overlap.py --branch feat/libkernel-kevent-lowat-below-one: exit 2. It probed 2023 open PRs and fails closed when it cannot compare every one. The manual comparison is under What.b15b896411, which removes theThrowsassertion for anEVFILT_WRITEmark of 0 fromLowWaterMarks(the write path still throws inKqueue.cpp, and no test pins it):cmake --build build --target guest_kqueue_tests --parallel 4: exit 0.ctest --test-dir build -R '^guest_kqueue' --output-on-failure: 2/2 passed (guest_kqueue,guest_kqueue_cleared_race).tools/check_conventions.py: exit 0, 0 errors and the same 2debt-lengthwarnings.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T19:31:32Z.
Review: COMMENTED
Reviewed — no blocking findings
The low-water update matches the reviewed source and reported PS5 stream-socket behavior; I found no source blocker, and approval is withheld while the label check remains pending.
What I ran
Reviewed head
f0a712175fbd7448827b6be896a521d4e36b5040against basef2d874c1fdccf781c0fa5d86619bb5dd8894b958. The stack preview is clean against currentmain(e0caf1360035286bd22b9f2a3030e97b880ffb28). Environment: Linux x86_64, Debian 12, Python 3.11.2, Git 2.39.5. No build or C++ tests were run locally.Results
mainCaptured command output
Negative control
Not run locally. The PR reports the suite on Windows after the change, but no removed-fix variant was run as a negative control in this review.
Findings
Blocking
None found in the five changed files. The read-side flag is limited to open read sockets with
NOTE_LOWATbelow 1; edge-triggered modifications rearm the watcher, and listening sockets remain on their separate readiness path. The new tests cover level-triggered andEV_CLEARcases.Non-blocking
The PR reports a Windows 11 build and focused tests passing, including the added edge-triggered case; I did not rerun them. The
labelscheck was pending, so this review does not approve the change yet.Sources
8c639945Not verified
No local C++ build or runtime test was run. The Windows results and PS5 measurements were read from the PR description, not independently reproduced. Hosted Linux and specialized jobs were skipped, and the label check was still pending.
To get this to a good state
No source change is requested. Once the label check completes, I will refresh the exact head and required checks before deciding whether approval is appropriate.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T19:41:50Z.
Review: APPROVED
Re-checked — hosted checks passed, approved
The exact head is unchanged, the pending labels check has passed, and the hosted Windows build and tests passed; my earlier full review found no blocking source issue.
What I ran
Rechecked head
f0a712175fbd7448827b6be896a521d4e36b5040against basef2d874c1fdccf781c0fa5d86619bb5dd8894b958using GitHub’s live PR and check state. Environment: Debian 12 x86_64; no local build or compiler run.Results
Captured hosted-check output
Findings
Blocking
None found in the previously reviewed source.
Non-blocking
The source review and author-reported tests were not repeated in this CI-only follow-up.
Sources
Not verified
No local build, C++ tests, Linux/macOS test, console run or GPU behavior was performed in this follow-up. Linux and specialized hosted jobs were skipped.
To get this to a good state
No further action is needed for the reviewed head. If it changes, I will review the new head and its checks.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T19:44:33Z.
Review: CHANGES_REQUESTED
Re-checked — same head, changes requested
I found two review blockers that were missed in my earlier approval: the new test pins an intentionally unimplemented write case, and the reported debt-file overlap with open PR #12741 has no declared landing order.
What I ran
Re-checked head
f0a712175fbd7448827b6be896a521d4e36b5040against basef2d874c1fdccf781c0fa5d86619bb5dd8894b958; the head is unchanged. Linux x86_64; source, PR discussion and live overlap reports inspected. No build or tests were run for this corrective review.Results
Findings
Blocking
GuestKqueue.cppasserts thatEVFILT_WRITEwithNOTE_LOWATzero throws, whileKqueue.cppdeliberately leaves that behavior unimplemented throughNotImplemented_nid_no_patch. This test would make a later implementation fail despite correct progress. Please remove this assertion or implement and test the write-side behavior in scope.docs/dev/debt/libkernel.mdparagraph changed here. This PR's description acknowledges the shared line but saysDepends on: none; repository contribution rules require agreeing the order with the other author and declaring that order. Please coordinate with #12741 and update the dependency/landing-order declaration accordingly.Non-blocking
None.
Sources
Not verified
No build, test run, or console behavior was checked in this corrective pass. The earlier review's test evidence was supplied by the author, not run by me.
To get this to a good state
Remove the assertion for the intentionally unimplemented write path, and coordinate the shared debt-line landing order with #12741; I will re-check the changed head and rerun the applicable no-build checks.