feat(libkernel): accept EVFILT_FS in kevent #14894

Merged
kallmek3nny merged 2 commits from upstream-pr/14894 into main 2026-11-07 03:34:58 +00:00
kallmek3nny commented 2026-11-01 23:21:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kallmek3nny on 2026-11-01T23:21:55Z.


What

kevent threw NotImplemented_nid_no_patch for every EVFILT_FS change. It now accepts EVFILT_FS, as FreeBSD 11.4 does. In vfs_subr.c, filt_fsattach adds EV_CLEAR to the knote and puts it on the global fs_knlist, whatever its ident. filt_fsevent ORs each hint into kn_fflags and reports the knote while kn_fflags is not 0. The only hints come from vfs_event_signal, which vfs_mount.c calls with VQ_MOUNT in vfs_domount_first and with VQ_UNMOUNT in dounmount. Nothing here mounts or unmounts a filesystem (nmount throws), so nothing sends such a hint:

  • EV_ADD stores the knote with EV_CLEAR added and fflags and data 0, as kqueue_register moves kev->fflags and kev->data into kn_sfflags and kn_sdata.
  • The filter never triggers the knote.
  • EV_ENABLE, EV_DISABLE, EV_DELETE and EV_FORCEONESHOT act on it as on other knotes. EV_DELETE or EV_ENABLE with no knote fails with ENOENT.

The kevent measurements entry in docs/dev/debt/libkernel.md (payload processes on a PS5, firmware 12.70) recorded that EVFILT_FS at ident 0 was accepted there and still threw here. This PR rewrites that clause (line 172) to say it is accepted here and to point to the kqueue and kevent entry. That entry (line 167) now lists EVFILT_FS among the filters that do not throw, with the EV_CLEAR that filt_fsattach sets, and says it never fires. Only the acceptance at ident 0 was measured on a PS5; EV_CLEAR and the cleared fflags and data follow FreeBSD 11.4.

Code: Register in Equeue/src/Kqueue.cpp accepts EVFILT_FS (the new constant -9) and adds it with the new AddFsKnote, which stores the knote with EV_CLEAR added and fflags and data cleared in both the stored event and the change.

Tests: FilesystemEvents in core/libs/tests/GuestKqueue.cpp, at ident 0:

  • EV_DELETE and EV_ENABLE with no knote fail with ENOENT.
  • An EV_ADD with EV_RECEIPT, fflags 7, data 9 and a udata returns one receipt with EV_ERROR, data 0 and fflags 0, and no event follows.
  • A second EV_ADD, then EV_DISABLE and EV_ENABLE, return 0 and report no event.
  • EV_FORCEONESHOT with the udata reports one event with EV_RECEIPT, EV_CLEAR and EV_ONESHOT, fflags 0, data 0 and the udata, then none. The knote is gone after that, so EV_DELETE fails with ENOENT.
  • EV_ADD then EV_DELETE return 0, and a second EV_DELETE fails with ENOENT.

Overlap: no open PR implements EVFILT_FS.

  • gh pr list --repo boykopovar/AnyPS5 --state open --search for filt_fsattach, filt_fsevent, VQ_MOUNT and VQ_UNMOUNT returned no PRs. EVFILT_FS returned only my #14854 (below), whose debt rewrite keeps the EVFILT_FS clause as it is on main; my #14886 keeps it too. kevent fs, kqueue fs and kevent filesystem added #14206 (select failing with EBADF when its pipe closes on Windows), kevent filesystem added #7121 (open, read and close notes on watched files), and kqueue mount added #9661 (rename onto or from a Windows directory symbolic link). By title #14206 and #9661 are unrelated; the diff search below found no EVFILT_FS code or text in #7121.
  • tools/pr_overlap.py reports four PRs:
    • #12741 (macOS edge watches) rewrites debt line 167.
    • My #14832 (NOTE_LOWAT below 1) rewrites debt lines 167 and 172 and changes other lines of Kqueue.cpp and GuestKqueue.cpp.
    • Neither adds or removes EVFILT_FS code or text. My #14854 and #14886 are below.
  • My #14854 (EVFILT_PROC with NOTE_EXIT on the calling process) and #14886 (EVFILT_SIGNAL) change the same filter check in Register, and each adds its own add function and Register branch where this PR adds AddFsKnote and its branch. git merge-tree of this branch with #14854's head 575c14f9b4 conflicts in three blocks in Kqueue.cpp, in GuestKqueue.cpp (its ProcessExitOnSelf and this PR's FilesystemEvents go in the same place) and on debt lines 167 and 172. With #14886's head 0211640a74 it conflicts in the same three Kqueue.cpp blocks and on debt lines 167 and 172. Each conflict is two changes to the same lines, and resolving it means keeping both, with every accepted filter in the one filter check. Whichever of these PRs merge later need a rebase of those lines.
  • pr_overlap could not compare 38 PRs that conflict with main. I searched each of their diffs for removed code lines this PR also removes, for the same debt lines or entries, and for added or removed EVFILT_FS text. None shares a removed code line or adds or removes EVFILT_FS text. #7088 (kevent read and write events on regular files) and #9843 (EV_CLEAR EVFILT_WRITE with NOTE_LOWAT above 1 on a Linux TCP socket) also rewrite the kqueue and kevent entry (line 167), so the second to merge will need a rebase there. #7088, #7121 and #9843 also change other lines of Kqueue.cpp and GuestKqueue.cpp.

Tested

Windows 11 Home 10.0.26300.9711, Git Bash, WinLibs gcc/g++, Ninja, Release, in the build tree configured with 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. No title or homebrew; only the guest test below was run.

  • On this branch (base 0580e5c951), after the code, test and debt edits: cmake --build build --target guest_kqueue_tests: exit 0; it rebuilt libkernel.prx and guest_kqueue_tests. ctest --test-dir build -R '^guest_kqueue$' --no-tests=error --output-on-failure --timeout 120: 1/1 passed. The commit 8303e23a41 is that working tree: 3 files, 45 insertions and 3 deletions. No header changed, so public_headers and a full build were not run.
  • On 8303e23a41, python tools/check_conventions.py --base origin/main exited 0 with 0 errors and 2 debt-length warnings for docs/dev/debt/libkernel.md. Line 167 is 3771 characters (3537 on main) and line 172 is 4409 characters (4336 on main); both were already over 1000 characters on main. None of the 3 files changed on origin/main (4ac683fe02) since the merge base.
  • python tools/pr_overlap.py --branch feat/libkernel-kevent-fs: exit 2. It found 1846 open PRs and fails closed when it cannot compare every one. The manual comparison is under What.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One 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 file
  • No notes, investigation .md files 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
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5112605973 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14894). Originally posted by [kallmek3nny](https://github.com/kallmek3nny) on 2026-11-01T23:21:55Z. --- ### What `kevent` threw `NotImplemented_nid_no_patch` for every `EVFILT_FS` change. It now accepts `EVFILT_FS`, as FreeBSD 11.4 does. In [`vfs_subr.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_subr.c), [`filt_fsattach`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_subr.c#L4952-L4958) adds `EV_CLEAR` to the knote and puts it on the global `fs_knlist`, whatever its ident. [`filt_fsevent`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_subr.c#L4968-L4973) ORs each hint into `kn_fflags` and reports the knote while `kn_fflags` is not 0. The only hints come from [`vfs_event_signal`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_subr.c#L4934-L4938), which [`vfs_mount.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_mount.c) calls with `VQ_MOUNT` in `vfs_domount_first` and with `VQ_UNMOUNT` in `dounmount`. Nothing here mounts or unmounts a filesystem (`nmount` throws), so nothing sends such a hint: - `EV_ADD` stores the knote with `EV_CLEAR` added and `fflags` and `data` 0, as `kqueue_register` moves `kev->fflags` and `kev->data` into `kn_sfflags` and `kn_sdata`. - The filter never triggers the knote. - `EV_ENABLE`, `EV_DISABLE`, `EV_DELETE` and `EV_FORCEONESHOT` act on it as on other knotes. `EV_DELETE` or `EV_ENABLE` with no knote fails with `ENOENT`. The kevent measurements entry in `docs/dev/debt/libkernel.md` (payload processes on a PS5, firmware 12.70) recorded that `EVFILT_FS` at ident 0 was accepted there and still threw here. This PR rewrites that clause (line 172) to say it is accepted here and to point to the kqueue and kevent entry. That entry (line 167) now lists `EVFILT_FS` among the filters that do not throw, with the `EV_CLEAR` that `filt_fsattach` sets, and says it never fires. Only the acceptance at ident 0 was measured on a PS5; `EV_CLEAR` and the cleared `fflags` and `data` follow FreeBSD 11.4. Code: `Register` in `Equeue/src/Kqueue.cpp` accepts `EVFILT_FS` (the new constant -9) and adds it with the new `AddFsKnote`, which stores the knote with `EV_CLEAR` added and `fflags` and `data` cleared in both the stored event and the change. Tests: `FilesystemEvents` in `core/libs/tests/GuestKqueue.cpp`, at ident 0: - `EV_DELETE` and `EV_ENABLE` with no knote fail with `ENOENT`. - An `EV_ADD` with `EV_RECEIPT`, `fflags` 7, `data` 9 and a `udata` returns one receipt with `EV_ERROR`, `data` 0 and `fflags` 0, and no event follows. - A second `EV_ADD`, then `EV_DISABLE` and `EV_ENABLE`, return 0 and report no event. - `EV_FORCEONESHOT` with the `udata` reports one event with `EV_RECEIPT`, `EV_CLEAR` and `EV_ONESHOT`, `fflags` 0, `data` 0 and the `udata`, then none. The knote is gone after that, so `EV_DELETE` fails with `ENOENT`. - `EV_ADD` then `EV_DELETE` return 0, and a second `EV_DELETE` fails with `ENOENT`. Overlap: no open PR implements `EVFILT_FS`. - `gh pr list --repo boykopovar/AnyPS5 --state open --search` for `filt_fsattach`, `filt_fsevent`, `VQ_MOUNT` and `VQ_UNMOUNT` returned no PRs. `EVFILT_FS` returned only my #14854 (below), whose debt rewrite keeps the `EVFILT_FS` clause as it is on `main`; my #14886 keeps it too. `kevent fs`, `kqueue fs` and `kevent filesystem` added #14206 (`select` failing with `EBADF` when its pipe closes on Windows), `kevent filesystem` added #7121 (open, read and close notes on watched files), and `kqueue mount` added #9661 (rename onto or from a Windows directory symbolic link). By title #14206 and #9661 are unrelated; the diff search below found no `EVFILT_FS` code or text in #7121. - `tools/pr_overlap.py` reports four PRs: - #12741 (macOS edge watches) rewrites debt line 167. - My #14832 (`NOTE_LOWAT` below 1) rewrites debt lines 167 and 172 and changes other lines of `Kqueue.cpp` and `GuestKqueue.cpp`. - Neither adds or removes `EVFILT_FS` code or text. My #14854 and #14886 are below. - My #14854 (`EVFILT_PROC` with `NOTE_EXIT` on the calling process) and #14886 (`EVFILT_SIGNAL`) change the same filter check in `Register`, and each adds its own add function and `Register` branch where this PR adds `AddFsKnote` and its branch. `git merge-tree` of this branch with #14854's head `575c14f9b4` conflicts in three blocks in `Kqueue.cpp`, in `GuestKqueue.cpp` (its `ProcessExitOnSelf` and this PR's `FilesystemEvents` go in the same place) and on debt lines 167 and 172. With #14886's head `0211640a74` it conflicts in the same three `Kqueue.cpp` blocks and on debt lines 167 and 172. Each conflict is two changes to the same lines, and resolving it means keeping both, with every accepted filter in the one filter check. Whichever of these PRs merge later need a rebase of those lines. - pr_overlap could not compare 38 PRs that conflict with `main`. I searched each of their diffs for removed code lines this PR also removes, for the same debt lines or entries, and for added or removed `EVFILT_FS` text. None shares a removed code line or adds or removes `EVFILT_FS` text. #7088 (kevent read and write events on regular files) and #9843 (`EV_CLEAR` `EVFILT_WRITE` with `NOTE_LOWAT` above 1 on a Linux TCP socket) also rewrite the kqueue and kevent entry (line 167), so the second to merge will need a rebase there. #7088, #7121 and #9843 also change other lines of `Kqueue.cpp` and `GuestKqueue.cpp`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Home 10.0.26300.9711, Git Bash, WinLibs gcc/g++, Ninja, Release, in the build tree configured with `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`. No title or homebrew; only the guest test below was run. - On this branch (base `0580e5c951`), after the code, test and debt edits: `cmake --build build --target guest_kqueue_tests`: exit 0; it rebuilt `libkernel.prx` and `guest_kqueue_tests`. `ctest --test-dir build -R '^guest_kqueue$' --no-tests=error --output-on-failure --timeout 120`: 1/1 passed. The commit `8303e23a41` is that working tree: 3 files, 45 insertions and 3 deletions. No header changed, so `public_headers` and a full build were not run. - On `8303e23a41`, `python tools/check_conventions.py --base origin/main` exited 0 with 0 errors and 2 `debt-length` warnings for `docs/dev/debt/libkernel.md`. Line 167 is 3771 characters (3537 on `main`) and line 172 is 4409 characters (4336 on `main`); both were already over 1000 characters on `main`. None of the 3 files changed on `origin/main` (`4ac683fe02`) since the merge base. - `python tools/pr_overlap.py --branch feat/libkernel-kevent-fs`: exit 2. It found 1846 open PRs and fails closed when it cannot compare every one. The manual comparison is under What. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-01 23:59:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-01T23:59:55Z.

Review: APPROVED


Reviewed at 8303e23a41, merged locally into main 66e1f7f993 (clean merge; GitHub reports it mergeable). Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, Release, Ninja.

Checked against FreeBSD 11.4's source (release/11.4.0, source read, not run, not measured on a console):

  • sys/sys/event.h:42: EVFILT_FS is -9.
  • sys/kern/vfs_subr.c:4952-4958: filt_fsattach sets EV_CLEAR and adds the knote to fs_knlist whatever its ident; filt_fsevent ORs the hint into kn_fflags, so with no hint it never fires.
  • sys/kern/kern_event.c, kqueue_register: for a new knote kev->fflags and kev->data move into kn_sfflags/kn_sdata and are cleared, so the EV_RECEIPT event has fflags 0, as the test expects. For an existing knote EV_FORCEONESHOT (line 1431) sets EV_ONESHOT and activates it without leaving early, and kn->kn_kevent.udata = kev->udata follows, so the forced event carries the change's udata; kn_flags keeps EV_RECEIPT from the first add (line 1396 strips only the action flags).
  • kqueue_scan: an EV_ONESHOT knote is copied out from kn_kevent without calling f_event again and then dropped, so it is reported with fflags and data 0 and a later EV_DELETE fails with ENOENT.

So every assertion in FilesystemEvents() matches 11.4.

What I ran

  • ctest -R '^guest_kqueue$' --repeat until-fail:3: passes, 3 of 3.
  • Negative control: main's Equeue/src/Kqueue.cpp with this PR's test: aborts with kevent: filter -9 not implemented.
  • python tools/check_conventions.py --base upstream/main: no errors; two debt-length warnings on the kqueue and kevent and kevent measurements entries, which are already over the limit on main.

Looks good.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5730891951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14894#pullrequestreview-5730891951). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-01T23:59:55Z. **Review:** APPROVED --- Reviewed at `8303e23a41`, merged locally into `main` `66e1f7f993` (clean merge; GitHub reports it mergeable). Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, Release, Ninja. **Checked against FreeBSD 11.4's source** (`release/11.4.0`, source read, not run, not measured on a console): - `sys/sys/event.h:42`: `EVFILT_FS` is `-9`. - `sys/kern/vfs_subr.c:4952-4958`: `filt_fsattach` sets `EV_CLEAR` and adds the knote to `fs_knlist` whatever its ident; `filt_fsevent` ORs the hint into `kn_fflags`, so with no hint it never fires. - `sys/kern/kern_event.c`, `kqueue_register`: for a new knote `kev->fflags` and `kev->data` move into `kn_sfflags`/`kn_sdata` and are cleared, so the `EV_RECEIPT` event has `fflags` 0, as the test expects. For an existing knote `EV_FORCEONESHOT` (line 1431) sets `EV_ONESHOT` and activates it without leaving early, and `kn->kn_kevent.udata = kev->udata` follows, so the forced event carries the change's `udata`; `kn_flags` keeps `EV_RECEIPT` from the first add (line 1396 strips only the action flags). - `kqueue_scan`: an `EV_ONESHOT` knote is copied out from `kn_kevent` without calling `f_event` again and then dropped, so it is reported with `fflags` and `data` 0 and a later `EV_DELETE` fails with `ENOENT`. So every assertion in `FilesystemEvents()` matches 11.4. **What I ran** - `ctest -R '^guest_kqueue$' --repeat until-fail:3`: passes, 3 of 3. - Negative control: `main`'s `Equeue/src/Kqueue.cpp` with this PR's test: aborts with `kevent: filter -9 not implemented`. - `python tools/check_conventions.py --base upstream/main`: no errors; two `debt-length` warnings on the `kqueue and kevent` and `kevent measurements` entries, which are already over the limit on `main`. Looks good. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14894
No description provided.