fix(libkernel): accept EVFILT_TIMER re-adds with a time unit or on a disabled timer as measured on a PS5 #11236

Merged
orezraey merged 2 commits from upstream-pr/11236 into main 2026-10-27 13:28:06 +00:00
orezraey commented 2026-10-25 22:26:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T22:26:27Z.


What

Re-adding an existing EVFILT_TIMER with EV_ADD now works in two cases that used to throw, as a retail PS5 (firmware 13.60) handles them:

  • a re-add whose fflags carry a time unit (NOTE_SECONDS, NOTE_MSECONDS, NOTE_USECONDS or NOTE_NSECONDS);
  • a re-add of a disabled timer.

Measured with a homebrew probe from a payload process; the source and console log are in this gist (ptimer2).

On the console:

  • A unit in fflags. A 30 ms timer re-added with NOTE_MSECONDS and 30 fired at 30, 60 and 90 ms. Re-added with NOTE_NSECONDS, it fired first at its armed expiry and then at the new period. That is the rule AnyPS5 already follows for re-adds with fflags 0: keep the armed expiry, apply the new period after it. So the re-add path now accepts any single unit with a positive period. A combination of units or any other fflags bit still throws.
  • A disabled timer. After EV_DISABLE, re-adding with EV_ADD and 30 or 60 ms returned 0, and nothing fired within 400 ms: the timer stays disabled. It now takes the new period and udata and stays disabled.
  • Already matching: a fired EV_ONESHOT timer re-added (one fire), data 0 on a new timer (fires at once), data -1 (EV_ERROR with 22), EV_CLEAR and EV_DISPATCH.
  • Still different, recorded. A modify with data 0 (EV_ADD, or EV_DISABLE/EV_ENABLE) zeroes the period on the console, as FreeBSD's kqueue_register copies data onto the note. The timer then fires about every millisecond with 10 to 13 expiries each, and an enable after 120 ms disabled reported about 912. AnyPS5 keeps the period there. That gap leads the debt entry. Reproducing it would mean modelling the console's callout granularity.

Before and after

EV_ADD on an existing EVFILT_TIMER PS5 AnyPS5 before AnyPS5 now
re-add with one time unit in fflags keeps the armed expiry, then the new period throws keeps the armed expiry, then the new period
re-add of a disabled timer returns 0, stays disabled throws returns 0, new period, stays disabled
combination of units, other fflags bits not measured throws throws
modify with data 0 period becomes 0, fires about every ms keeps the period keeps the period (debt)

Tested

Windows 11, WinLibs GCC 15.2, full build. The seven tests matching kqueue|equeue|kevent|timer pass 3 times out of 3. guest_kqueue's TimerReadd now checks:

  • a re-add with NOTE_MSECONDS returns 0 and fires no earlier than the armed expiry;
  • NOTE_MSECONDS|NOTE_USECONDS and fflags 0x10 still throw;
  • a disabled timer re-added with 5 ms returns 0 and does not fire within 60 ms.

tools/check_conventions.py passes. Head 4c9e31f18c on main eeb7760717 (the sem_timedwait debt line now comes from main, as merged by #10105). On WSL Ubuntu with GCC 13, the six of them registered on Linux (guest_kqueue, guest_equeue_events, guest_itimer, guest_itimer_pending_default, guest_getitimer, guest_kernel_sys_ktimer) pass 3 times out of 3 at the same head.

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: #9491, #10105 and #10137 (mine), and #11267 (kallmek3nny) (they edit the debt entries next to the kevent one; merge order only); #11862 (ionut27001) rewrites the setrlimit debt entry next to the EVFILT_TIMER one (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009339701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11236). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T22:26:27Z. --- ### What Re-adding an existing `EVFILT_TIMER` with `EV_ADD` now works in two cases that used to throw, as a retail PS5 (firmware 13.60) handles them: - a re-add whose `fflags` carry a time unit (`NOTE_SECONDS`, `NOTE_MSECONDS`, `NOTE_USECONDS` or `NOTE_NSECONDS`); - a re-add of a disabled timer. Measured with a homebrew probe from a payload process; the source and console log are in [this gist](https://gist.github.com/orezraey/c351d109ca00ab6cfc2721df8d076437) (`ptimer2`). On the console: - **A unit in `fflags`.** A 30 ms timer re-added with `NOTE_MSECONDS` and 30 fired at 30, 60 and 90 ms. Re-added with `NOTE_NSECONDS`, it fired first at its armed expiry and then at the new period. That is the rule AnyPS5 already follows for re-adds with `fflags` 0: keep the armed expiry, apply the new period after it. So the re-add path now accepts any single unit with a positive period. A combination of units or any other `fflags` bit still throws. - **A disabled timer.** After `EV_DISABLE`, re-adding with `EV_ADD` and 30 or 60 ms returned 0, and nothing fired within 400 ms: the timer stays disabled. It now takes the new period and `udata` and stays disabled. - **Already matching:** a fired `EV_ONESHOT` timer re-added (one fire), `data` 0 on a new timer (fires at once), `data` -1 (`EV_ERROR` with 22), `EV_CLEAR` and `EV_DISPATCH`. - **Still different, recorded.** A modify with `data` 0 (`EV_ADD`, or `EV_DISABLE`/`EV_ENABLE`) zeroes the period on the console, as FreeBSD's `kqueue_register` copies `data` onto the note. The timer then fires about every millisecond with 10 to 13 expiries each, and an enable after 120 ms disabled reported about 912. AnyPS5 keeps the period there. That gap leads the debt entry. Reproducing it would mean modelling the console's callout granularity. **Before and after** | `EV_ADD` on an existing `EVFILT_TIMER` | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | re-add with one time unit in `fflags` | keeps the armed expiry, then the new period | throws | keeps the armed expiry, then the new period | | re-add of a disabled timer | returns 0, stays disabled | throws | returns 0, new period, stays disabled | | combination of units, other `fflags` bits | not measured | throws | throws | | modify with `data` 0 | period becomes 0, fires about every ms | keeps the period | keeps the period (debt) | ### 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, WinLibs GCC 15.2, full build. The seven tests matching `kqueue|equeue|kevent|timer` pass 3 times out of 3. `guest_kqueue`'s `TimerReadd` now checks: - a re-add with `NOTE_MSECONDS` returns 0 and fires no earlier than the armed expiry; - `NOTE_MSECONDS|NOTE_USECONDS` and `fflags` 0x10 still throw; - a disabled timer re-added with 5 ms returns 0 and does not fire within 60 ms. `tools/check_conventions.py` passes. Head `4c9e31f18c` on `main` `eeb7760717` (the `sem_timedwait` debt line now comes from `main`, as merged by #10105). On WSL Ubuntu with GCC 13, the six of them registered on Linux (`guest_kqueue`, `guest_equeue_events`, `guest_itimer`, `guest_itimer_pending_default`, `guest_getitimer`, `guest_kernel_sys_ktimer`) pass 3 times out of 3 at the same head. ### 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: #9491, #10105 and #10137 (mine), and #11267 (kallmek3nny) (they edit the debt entries next to the `kevent` one; merge order only); #11862 (ionut27001) rewrites the `setrlimit` debt entry next to the `EVFILT_TIMER` one (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 22:30:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:30:16Z.

Review: APPROVED


Reviewed exact head c7392b3fca6fb3dc36d3d53c1ff78016e4b576dc. The cited firmware 13.60 probe log records successful re-adds with NOTE_MSECONDS/NOTE_NSECONDS, preservation of the original armed expiry, and disabled re-adds producing no events; the code keeps that expiry, updates the interval and udata, and leaves disabled timers disabled. The regression covers a millisecond re-add, rejected combined/unknown units and disabled behavior. Current-main conventions and git diff --check pass; conventions reports only pre-existing debt-length warnings. Hosted product jobs were skipped by path policy; the author reports the focused Windows timer tests, which I did not rerun locally. The three declared debt-file merge-order PRs remain open.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645685546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11236#pullrequestreview-5645685546). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:30:16Z. **Review:** APPROVED --- Reviewed exact head `c7392b3fca6fb3dc36d3d53c1ff78016e4b576dc`. The cited firmware 13.60 probe log records successful re-adds with `NOTE_MSECONDS`/`NOTE_NSECONDS`, preservation of the original armed expiry, and disabled re-adds producing no events; the code keeps that expiry, updates the interval and `udata`, and leaves disabled timers disabled. The regression covers a millisecond re-add, rejected combined/unknown units and disabled behavior. Current-main conventions and `git diff --check` pass; conventions reports only pre-existing debt-length warnings. Hosted product jobs were skipped by path policy; the author reports the focused Windows timer tests, which I did not rerun locally. The three declared debt-file merge-order PRs remain open.
MarcZX10 commented 2026-10-25 23:51:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:51:10Z.

Review: CHANGES_REQUESTED


Rechecked exact head c7392b3fca6fb3dc36d3d53c1ff78016e4b576dc. I still have no code finding in the timer implementation. A new overlap report identifies open #11267, and I verified the exact current heads (c7392b3... and 118f0b8...) with git merge-tree --write-tree; they conflict in docs/dev/debt/libkernel.md. CONTRIBUTING.md requires the agreed order and actual prerequisite on the checklist. Please coordinate with #11267’s author and add it to Depends on if it must land first, then rebase/resolve and rerun the focused timer tests. Existing hosted policy checks pass; product jobs are skipped, and the Windows focused tests are author-reported.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646017006 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11236#pullrequestreview-5646017006). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T23:51:10Z. **Review:** CHANGES_REQUESTED --- Rechecked exact head `c7392b3fca6fb3dc36d3d53c1ff78016e4b576dc`. I still have no code finding in the timer implementation. A new overlap report identifies open #11267, and I verified the exact current heads (`c7392b3...` and `118f0b8...`) with `git merge-tree --write-tree`; they conflict in `docs/dev/debt/libkernel.md`. `CONTRIBUTING.md` requires the agreed order and actual prerequisite on the checklist. Please coordinate with #11267’s author and add it to `Depends on` if it must land first, then rebase/resolve and rerun the focused timer tests. Existing hosted policy checks pass; product jobs are skipped, and the Windows focused tests are author-reported.
MarcZX10 commented 2026-10-26 05:41:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T05:41:06Z.

Review: DISMISSED


The Depends on: #11267 checklist correction and the added repeated Windows/Linux timer runs resolve my earlier merge-order request; I found no code issue in the unchanged implementation. Current main has since advanced: this branch is 1 ahead /242 behind 14c99b52ac, with merge preview clean, and #11267 remains open. After the stated merge order, please refresh onto current main and rerun the focused timer tests on the resulting exact head. This request is only for the required current-head validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5647833430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11236#pullrequestreview-5647833430). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T05:41:06Z. **Review:** DISMISSED --- The `Depends on: #11267` checklist correction and the added repeated Windows/Linux timer runs resolve my earlier merge-order request; I found no code issue in the unchanged implementation. Current `main` has since advanced: this branch is 1 ahead /242 behind `14c99b52ac`, with merge preview clean, and #11267 remains open. After the stated merge order, please refresh onto current main and rerun the focused timer tests on the resulting exact head. This request is only for the required current-head validation.
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!11236
No description provided.