fix(libkernel): retire an EV_ONESHOT note through its delete callback and follow Windows $Deleted paths #7049
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7049"
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 blawesom on 2026-10-17T08:19:31Z.
What
Carries the additive pieces of #6510 (as offered there after its feature was superseded by #5847), revised per the review of
b64fd7377:deleteEventFuncinvocation when anEV_ONESHOTnote retires inCollectTriggered\$Extend$Deleted`exactly instead of any path containing$Deleted`kqueue_registersetskn_sfflagsunconditionally for filters withoutf_touch, matchingmain's unconditionalSetVnodeNotesdocs/dev/debt/libkernel.mdTested
Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): full suite passes except the knownmainregression (agc_driver_tessellationsegfault, #4727); conventions pass. New tests:VnodeOneshotWatchStops: a vnodeEV_ONESHOTfires once, the note is gone, and on Linux the retired watch's inotify descriptor count returns to its pre-watch level (with a bounded wait for the watch thread to exit) — the leak the review describedPeriodicTimerFiresTwice: a plain periodic timer fires twice (uncovered onmainbefore)TimerDisableEnableRearm: a disabled periodic timer'sEV_ENABLEreports the expiries missed while disabled in one step and keeps the note's phase, and anEV_ADD | EV_ENABLEre-add still throwsRecycleBinDeleteWatchedFile(Windows-gated): a watched file renamed under\$Extend$Deleted`reportsNOTE_DELETE`The requested timer test is in the branch now (
TimerDisableEnableRearm):EV_DISABLEfollowed byEV_ENABLEwithdata == 0on a periodic timer reports the expiries missed while disabled in one step and keeps the note's phase, as FreeBSD 11'sfilt_timerexpirecounts a disabled note and keeps itsp_nexttime. The next-wait abort described in the earlier round no longer reproduces: it was observed on the pre-rebase head, beforemain's equeue wait refactor (5cbc46029b). One guard change came out of writing it: a timer modify that setsfflagswas silently ignored, wherekqueue_registercopies it onto the note — it now refuses with the other re-adds, waiting for the measured rules.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)main)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T08:27:14Z.
Review of b64fd7377: the EV_ONESHOT detach is correct (it matches FreeBSD
kqueue_scan, and it's safe under the lock). Three things block merge:kqueue_register(kern_event.c:1345-1357), every change to an existing knote reaches the "user may change some filter values" block, and filters withoutf_touch(vnode included) getkn->kn_sfflags = kev->fflagsunconditionally. So on FreeBSD,EV_ENABLE/EV_DISABLEwithfflags == 0clears the vnode interest. Main matches that today (SetVnodeNotes(event, change.fflags)is unconditional). Please drop the guard, or point to console/libkernel evidence that the PS5 differs.RunHostWatchthread);data == 0: no firing while disabled, and the period is kept after EV_ENABLE;$Deletedpath (RenameAndDeleteWatchedFileis#ifndef _WIN32).conventionscheck fails on the PR template (What/Tested/Checklist are missing), so linux and windows were skipped. Please fill in the template.Minor:
path.find(L"$Deleted")matches any path containing that text. With POSIX delete semantics the file moves under\$Extend\$Deleted\, so matchL"\\$Extend\\$Deleted\\".data == 0as "keep the period" is a sane choice, but FreeBSD stores the 0. Please add a line todocs/dev/debt/libkernel.md.When this lands, #6510 should be closed as superseded, since this carries its parts.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T14:18:35Z.
Addressed the review in
b3e3e8118: the vnode guard is dropped, the $Deleted match is the exact recycle-bin path, the requested vnode-oneshot/periodic/recycle-bin tests are in (with the inotify release check), the debt line for the timer period is added, and the template is filled. One finding did not make it in — the timer EV_DISABLE/EV_ENABLE cycle aborts on the next wait after a single re-fire, so the relaxed guard needs the timer state to re-arm on enable before that test can land; details in the Tested section of the PR body.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T08:17:37Z.
Re-anchored onto current
main(53b717de6) —mainhad moved past the branch, so the needs-rebase label was fair. The one conflict was the kqueue test runner:main's newLowWaterMarks()call kept alongside this PR's test calls. Full suite green apart from the knownmainregression (agc_driver_tessellation, Mesa #5444); conventions pass; the kqueue tests including the review-requested ones all pass on the re-anchored head.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T20:45:52Z.
Review: COMMENTED
Static review plus a small arm64 repro on macOS (Apple M2 Max, macOS 27.2, Apple clang 21), head
53b717de6. Two problems in the new tests incore/libs/tests/GuestKqueue.cpp.1.
RecycleBinDeleteWatchedFilenever runs on any platform. Inmain()its call is nested inside the non-Windows block:The function itself is defined only under
#ifdef _WIN32(line 760), so the\$Extend\$Deleted\change inFileEvent.cpp(IsDeleted/SnapshotHints) has no test that actually runs, even though the PR body lists it under Tested. Moving the#ifdef _WIN32 ... #endifblock after the closing#endiffixes it.2. The leak check in
VnodeOneshotWatchStopspasses vacuously on macOS.InotifyWatchCount(lines 705-716) iterates/proc/self/fdunder#ifndef _WIN32. macOS has no/proc, sodirectory_iteratorsets the error code and the count is always 0. That makesRequire(InotifyWatchCount() == watchesBefore)(line 743) true regardless of the fix. The macOS host watch is a::kqueue()per note (FileEvent.cpp:446), closed whenStopVnodestops the watch thread, so the same leak is possible there.Repro: the PR's
InotifyWatchCountcopied as is, plus 3 deliberately leakedkqueue()descriptors:Suggestion: gate the current helper on
__linux__. On__APPLE__, countPROX_FDTYPE_KQUEUEentries fromproc_pidinfo(getpid(), PROC_PIDLISTFDS, ...)(<libproc.h>), which detected the leaked descriptors above. Alternatively, skip the leak assertion where the count is not meaningful, so the test does not claim coverage it does not have.(The branch also currently conflicts with
main.)AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T12:55:08Z.
Review: CHANGES_REQUESTED
The production change looks right: the
deleteEventFunccall mirrors the existing one inCollectOncePerWait, and the exact\$Extend\$Deleted\match addresses the earlier review. The branch needs the following before it can merge (it also conflicts withmainincore/libs/tests/GuestKqueue.cppanddocs/dev/debt/libkernel.md):core/libs/tests/GuestKqueue.cpp(main(), ~line 967):RecycleBinDeleteWatchedFile()is called inside#ifndef _WIN32, so its#ifdef _WIN32is never true and the$Deletedchange has no test that runs. Move the#ifdef _WIN32block after the closing#endif(as reported by @jotitadev).InotifyWatchCount(~line 706) reads/proc/self/fd; on macOS that directory does not exist, the count is always 0 and the leak assertion passes without checking anything. Gate it on__linux__and skip the assertion elsewhere (or count kqueue descriptors viaproc_pidinfo).DisableAndEnable,Dispatch,ForceOneshotandStressTest(~165 lines) that the description does not mention and that belong to the superseded #6510 feature already covered byDisableAndDispatchonmain. Drop them, or move them to their own PR with their own justification.StressTestdepends on 4 threads and 1–2 ms sleeps and asserts strict arrival order, which is a flake risk on the CI runners.DisableAndEnable();call and the double blank line beforeStressTest.Please rebase on current
main(keepmain'sLowWaterMarks()/DisableAndDispatch()calls) and re-runguest_kqueue. Happy to re-review once these are addressed.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-21T17:12:23Z.
Rebased onto current
main(d34da5d69) and addressed the review in895ca7c6:RecycleBinDeleteWatchedFile()now runs on Windows: its call moved after the closing#endifof the#ifndef _WIN32block, so the\$Extend\$Deleted\path is exercisedInotifyWatchCountand both leak assertions gate on__linux__; on macOS and Windows the leak check is skipped instead of passing vacuously (macOS has no/proc)DisableAndEnable,Dispatch,ForceOneshotandStressTestare dropped with theirmain()calls (superseded #6510 feature;StressTestasserted strict arrival order across 4 threads with 1–2 ms sleeps — CI flake risk), and the two includes only they needed are goneStandardInput,WatchKqueue, edge-triggered calls) alongside this PR's test callsEVFILT_TIMERline)Tested: Linux (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):guest_kqueuepasses on the rebased head;tools/check_conventions.py --base origin/mainpasses. The Windows-gatedRecycleBinDeleteWatchedFilestill needs a Windows run to confirm it executes there.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-22T06:26:05Z.
@adriadam10 — re-requesting your review, as you offered:
Addressed per your review; head is now
3ecd18feaf(rebased, same content as072d780c66).main(d6eafa54d0);main'sLowWaterMarks()andDisableAndDispatch()are kept.RecycleBinDeleteWatchedFile()now runs on Windows: its#ifdef _WIN32block sits after the closing#endifof the non-Windows block, so the$Extend$Deletedpath is exercised.InotifyWatchCountand both leak assertions gate on__linux__; elsewhere the count is not asserted. I took your "skip the assertion where the count is not meaningful" option rather thanproc_pidinfokqueue counting on macOS — happy to switch if you would rather have real coverage there.DisableAndEnable,Dispatch,ForceOneshotandStressTestare dropped together with theirmain()calls, so the indentation and blank-line cosmetics went with them.guest_kqueuere-run on the rebased head: Passed (4.2 s) — Linux (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja, Release,BUILD_TESTING=ON, Ryzen 7 9800X3D).tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.pyreports only the shareddocs/dev/debt/libkernel.mdline and the same-file PRs already known open (#7088, #7653), none of which this builds on.