Repository navigation
fix(libkernel): handle kevent timer re-adds and the AIO, LIO, SENDFILE and PROCDESC filters as measured on a PS5 - #7653
Conversation
|
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.
Some 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.
|
AI-assisted: yes (Claude Code); results above were run on this machine. |
dd2b999 to
dab63ce
Compare
dab63ce to
3fa43a8
Compare
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, To pick it up: Head is |
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, One observation for reviewers: your To pick it up: Head is |
3fa43a8 to
d208d59
Compare
d208d59 to
1412fb8
Compare
|
Rebase handoff — rebased onto current
Verified on Linux (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja, Release, The earlier observation stands: your To pick it up: Head is |
…E and PROCDESC filters as measured on a PS5 In payload processes on a PS5 (firmware 12.70), re-adding an existing periodic EVFILT_TIMER with EV_ADD, fflags 0 and a positive period kept the armed expiry and the expirations already counted, and applied the new period after that expiry, as FreeBSD 11.0 does. EV_ONESHOT in the re-add left the timer periodic. Here such a re-add threw; it now does the same. Re-adding a one-shot or disabled timer, a re-add with nonzero fflags, a period of 0 or less, a period that overflows the armed expiry or flags other than EV_ONESHOT, and the other changes to an existing timer except EV_DELETE still throw. There, EV_ADD failed with EPERM for EVFILT_AIO, EVFILT_LIO and EVFILT_SENDFILE at every ident and flag set tried, and EV_DELETE and EV_ENABLE of them without EV_ADD failed with ENOENT. EVFILT_PROCDESC failed with EBADF on a descriptor that is not open and with EINVAL on every kind of open descriptor tried, and EV_DELETE of it on a socket failed with ENOENT. These filters threw here; they now answer the same way. EV_ADD of EVFILT_PROCDESC fails with EINVAL on the kinds of descriptor tried and on shared memory, and throws on other kinds and on descriptors 0 to 2 that are not sockets or kqueues; a change without EV_ADD fails with ENOENT, after the descriptor check for EVFILT_PROCDESC. A new kevent measurements debt entry, which the kqueue and kevent entry points to, records these measurements and the answers for NOTE_LOWAT marks and EVFILT_READ on another kqueue, which still throw here. The kqueue and kevent entry also stops listing a NOTE_NSECONDS period above one second with a fraction among the cases that throw, since d71a1c5 made it work.
1412fb8 to
27e3702
Compare
|
Rebased onto current main; the only conflict was the kqueue and kevent debt entry, which main rewrote since. Your edits are reapplied on its current text (the kevent-on-a-kqueue clause is dropped, main supports it now). Timer re-add and AIO/LIO/SENDFILE/PROCDESC changes checked against the console measurements and the debt entries; the new tests fail without the change; guest_kqueue and the libkernel tests pass; merged. |
What
Two
keventpaths that threw now answer the way payload processes on a PS5 (firmware 12.70) got them.Re-adding an existing timer. In the payload process,
EV_ADDon an existing periodicEVFILT_TIMER, withfflags0 and a positive period (milliseconds), kept the armed expiry and the expirations already counted, and applied the new period after that expiry. The debt entry already named the two FreeBSD candidates (11.0 keeps the expiry, 11.4'sfilt_timertouchrestarts the timer); the re-added timers behaved like 11.0's.mainbefore this PREV_ADD | EV_ONESHOTTo keep the counted expirations,
EditEventnow counts the expired periods of a timer before it edits it, asAddEventalready did. Re-adding a one-shot or disabled timer (anEV_DISPATCHtimer that has reported is disabled), a re-add with nonzerofflags(NOTE_MSECONDSincluded), a period of 0 or less, a period too large to add to the armed expiry or flags other thanEV_ONESHOTwere not measured and still throw, and every other change to an existing timer exceptEV_DELETEstill throws.Filters with no attach here. These filters threw
NotImplemented:EV_ADDofEVFILT_AIO,EVFILT_LIOorEVFILT_SENDFILEat idents 0, 5, 999, 2^40 and an open pipe, and at ident 5 also withEV_CLEAR,EV_ONESHOTorEV_DISABLEEPERMEV_ADDofEVFILT_PROCDESCon a descriptor that is not open (999 and a closed one) or an ident aboveINT_MAXEBADFEV_ADDofEVFILT_PROCDESCon Unix-domain stream and datagram sockets, descriptor 0 (a socket), anAF_INETUDP socket, both ends of a pipe, a regular file, a directory, another kqueue and the kqueue itselfEINVALEINVALon these kinds of descriptor (sockets, pipes, regular files, directories, kqueues), since there are no process descriptors here, and on shared memory and JIT shared memory, which are host files here (not measured; FreeBSD 11.0 answersEINVALforshm_openobjects); any other kind, such as/dev/randomand/dev/urandom, throws, and so do descriptors 0 to 2 that are not sockets or kqueuesEV_DELETEandEV_ENABLEof the first three at ident 5,EV_DELETEofEVFILT_PROCDESCon a socketENOENTENOENTfor every other change withoutEV_ADD, after the descriptor check forEVFILT_PROCDESC, as for any other filter without a knote;EV_ENABLEtogether withEV_DISABLEisEINVALbefore that, as for every filterWhen
EV_ADDof one of these filters fails withEPERM, or withEINVALon a descriptor other than the kqueue itself, its error event hasfflags0 and the errno indata, as FreeBSD 11.0'skqueue_registerclearsfflagsanddatabefore the attach andkqueue_keventthen stores the error indata; a descriptor that is not open, the kqueue itself andEV_ENABLEwithEV_DISABLEfail before that and keep theirfflags. That was not measured.EVFILT_PROCon the probe's own process withNOTE_EXIT,EVFILT_SIGNALforSIGUSR1andEVFILT_FSat ident 0 were accepted in the payload process and are not changed here; they still throw.Debt: in
docs/dev/debt/libkernel.md, a newkevent measurementsentry records the measurements above, and thekqueue and kevententry points to it: it now says that nothing here is taken from a console except what that entry lists, and it no longer lists these filters and the timer re-adds that entry describes among the cases that throw. The new entry also records what the payload process got in cases that still throw here, all on Unix-domain socketpairs except the last: aNOTE_LOWATmark of 0 on an empty stream socket (a read event at once,data0, and the same after re-adding that knote with -1), a write mark of 2 on the other end of that socketpair (data8192) and a re-add of that knote with 2^30 (no event), a mark of 5 on a datagram socket (no event after a 1-byte datagram, an event withdata11 after a second, 10-byte one), andEVFILT_READon another kqueue (datais the number of events pending in it: 1, then 2). Thekqueue and kevententry also listed aNOTE_NSECONDSperiod above one second with a fraction among the cases that throw; d71a1c5 made it work, so that clause now says how such a period is used.Overlaps: none of the open PRs changes the timer re-add or these filters, but several touch the same lines:
mainfd423f9 conflicted with it in the include block ofKqueue.cppand in thekqueue and keventdebt line; the resolution keeps itsHostStreams.hppinclude and its sentence about a read event on the host stream on descriptor 0, next to this PR's changes.maineaae7e0 conflicted with it in the debt file, where it changed theJIT shared memoryline right before thekqueue and keventline this PR changes; the resolution keeps itsJIT shared memoryline and this PR'skqueue and keventline, so this PR's change to the debt file is the same as before the rebase.JIT shared memorydebt line. Merged withmaineaae7e0 it conflicts in the debt file and three other files, and merged with this PR instead it conflicts in the same files and no others.ModifyKnoteso that a timer change withoutEV_ADDand withdata0 no longer throws. This PR handles theEV_ADDre-add inRegister, beforeModifyKnote. Its check that another change to an existing timer throws passesdata5, which throws with or without that change. Whichever lands second rewords "every change to an existing timer exceptEV_DELETEand theEV_ADDre-adds that the kevent measurements entry describes" in thekqueue and kevententry and "other changes to an existing timer" in thekevent measurementsentry.main: feat(libkernel): support EVFILT_WRITE on the write end of a pipe #7075, feat(libkernel): report open, read and close notes on watched files #7121 and fix(libkernel): bound equeue pending events #7509 in the debt file, fix(libkernel): retire an EV_ONESHOT note through its delete callback and follow Windows $Deleted paths #7049 inGuestKqueue.cppand the debt file, feat(libkernel): support EV_CLEAR on sockets and pipes in kevent on Linux #7129 inKqueue.cppand the debt file, and feat(libkernel): support kevent read and write events on regular files #7088 inKqueue.cpp,GuestKqueue.cppand the debt file. Merged with this PR instead ofmain, each conflicts in the same files and no others.How the console was measured
resolvelines show that thekeventall three probes call, and thekqueuep72 and p75 call, are the oneslibkernel_sys.sprxexports; p73 did not checkkqueue.EVFILT_PROCDESCon descriptor 0, which the payload manager opened, andEVFILT_FS,EVFILT_AIO,EVFILT_LIOandEVFILT_SENDFILEat ident 0. The cases of one group share a kqueue, and some re-add a knote that an earlier case registered. p72 logs the return value anderrnoof everykeventcall and every returned event.first_at_msis when the first event came, counted from the start of that window: the 400 ms window starts right after the re-add and the 200 ms window right after the 400 ms one.fstattype of descriptor 0 and of one descriptor of each kind it creates (sockfor descriptor 0 and the sockets,fifofor the pipe and for a kqueue,regfor the file,dirfor the directory). It then addsEVFILT_PROCDESCon descriptor 0, one end of a Unix-domain stream and of a datagram socketpair, anAF_INETUDP socket, both pipe ends, a regular file, a directory, a second kqueue, the kqueue itself, a closed descriptor and ident 2^40, and deletes it on the stream socket. It adds the other three filters at idents 0, 5, 999, 2^40 and an open pipe, at ident 5 also withEV_CLEAR,EV_ONESHOTandEV_DISABLE, and deletes and enables them at ident 5. It removes its temporary file at the end, and its UDP socket is never bound or used.EVFILT_PROCwas registered on the probe's own process forNOTE_EXITandEVFILT_SIGNALonSIGUSR1; no signal was sent. No filter below -12 other than -1000 was tried.Console output (excerpt, lines copied unchanged)
The
pNN:prefix names the probe; the rest of each line is copied unchanged.Tested
Build: Windows 11 x86-64, full build with WinLibs MinGW-w64 GCC 15.2.0 (posix-seh, ucrt, r7) and
-DBUILD_TESTING=ON.Tests: after #6542 landed, the branch was rebased onto
maineaae7e0 (the conflict is described under Overlaps). With this branch on thatmain, theguest_*tests pass: 498 of 499, andguest_video_out_wqhd_detection_no_vulkanis skipped on this machine. That is the second of two full runs. The first, right after the build, took 898 s instead of the second run's 69 s; in it seven tests timed out, none of them a kqueue or kevent test, andguest_itimerfailed;guest_itimerpassed in the second run and then 5 runs in a row.guest_kqueuepassed in both full runs and in 3 more runs in a row.Temporary file names:
TemporaryNameinGuestKqueue.cppnow puts the process id in each name. A reviewer saw one Linux copy ofProcdescOnFilesfail to remove its temporary file while 8 copies ran at once; with the process id in the name, copies that run at the same time no longer share a file. Since its timer checks depend on timing,guest_kqueuealso ran as 8 copies at once, three times: the timer and filter checks passed in all 24 copies. Five copies stopped later, in the existing check that watches a deleted file, where Windows refused the watch on$Deleted(FindFirstChangeNotificationerror 5) while the 8 copies ran, with a different file name in each copy.Old code, new test: with
Kqueue.cppandEqueue.cppreverted to thatmainand the new tests kept,guest_kqueueaborts withkevent: changing an existing EVFILT_TIMER not implemented.Console: behaviour measured on a PS5 (firmware 12.70), as described above.
Not tested here: Linux (a reviewer reported a Linux run in the comments), and no title.
Rebased onto main 6696def (the debt entry merged with main's pipe write-end and write low-water mark sentences; no code conflict). Re-tested on Windows 11, WinLibs GCC 15.2.0 r7:
ctest -R "guest_kqueue|guest_kevent|guest_equeue"twice, 2 of 2 pass both times (guest_kqueue,guest_equeue_events); revert check withEqueue.cppandKqueue.cpprestored from the previous commit:guest_kqueueaborts.Checklist
Based on current
main; no other open PR implements the same functionsOne 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 fileNo notes, investigation
.mdfiles 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
Rebase: rebased onto
main1e774a3 after the conflicts reported in the comments. The only conflict was thekqueue and keventdebt line, wheremain(feat(libkernel): accept a kevent read event on descriptor 0 #6343) added the sentence about a read event on the host stream on descriptor 0 and this PR rewrites the same line; the resolution keeps both, next to theHostStreams.hppinclude, which now merges without a conflict. The code and test changes are otherwise the same as before the rebase. Re-tested on the new base: full build with WinLibs GCC 15.2.0 (Windows 11), exit 0;guest_kqueuepassed twice (3.56 s, 3.55 s) andguest_equeue_eventstwice (1.67 s, 0.48 s); withEqueue.cppandKqueue.cpprestored frommainthe test aborts withkevent: changing an existing EVFILT_TIMER not implemented.Depends on: none
Fixes: none
Unblocks: none
GPUs tested: n/a
AI-assisted: yes