fix(libkernel): keep the nice value at 0 after setpriority as measured on a PS5 #11108

Merged
orezraey merged 4 commits from upstream-pr/11108 into main 2026-10-26 22:00:53 +00:00
orezraey commented 2026-10-25 17:52:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T17:52:38Z.


What

getpriority and setpriority measured on a retail PS5 (firmware 13.60) with a homebrew probe calling libkernel_sys.sprx from a payload process (pid 128, process group 105, uid 1, euid 0). The source and console log are in this gist (pnice). The probe restores the starting value after every set.

setpriority clamped the value to -20…20 and stored it, and getpriority returned the stored value. On the console setpriority(PRIO_PROCESS, 0, v) returns 0 for -25, -5, 5 and 25, and getpriority reads 0 after every one of them: raising the value does not stick either, so it is not a privilege question. setpriority now keeps its which/who checks and returns 0 without storing anything, and getpriority always returns 0.

Already matching: getpriority returns 0 for PRIO_PROCESS 0 and the own pid, PRIO_PGRP 0 and PRIO_USER 0, ESRCH for an unknown pid or user, and EINVAL for which 3 and -1.

Not measured: the probe set only PRIO_PROCESS 0. setpriority with PRIO_PGRP or PRIO_USER and a valid id now throws, naming the selector and value, and the debt entry says that this is unverified; unknown ids and which values still fail with ESRCH and EINVAL first.

Not changed: on the console PRIO_PROCESS with pid 1, PRIO_PGRP with the loader's group (105) and PRIO_USER with uid 1 also return 0. A payload is not a title and has other processes around it, so these ids say nothing about what a title sees; AnyPS5 keeps ESRCH for ids other than its own.

Before and after

Case PS5 AnyPS5 before AnyPS5 now
setpriority(PRIO_PROCESS, 0, v) for -25, -5, 5, 25 returns 0 returns 0, stores v clamped to -20…20 returns 0, stores nothing
getpriority after it 0 the stored value 0
getpriority with an unknown id, which 3 or -1 ESRCH, EINVAL the same the same
setpriority with PRIO_PGRP or PRIO_USER and a valid id not measured stored throws (debt)

Tested

Head 757e90c8c5 on main 7a25f87620.

  • Windows 11 Pro 26200, WinLibs GCC 15.2, Release: guest_sched_priority passes three runs in a row.
  • Linux (Arch Linux on WSL2, GCC 16.2.1): guest_sched_priority passes three runs in a row.
  • The test sets -25, -5, 5, 10, 25, 99 and -99 through PRIO_PROCESS 0 and checks that getpriority reads 0 for the process, its pid, its group and its user after each, next to the existing target and error checks. The PRIO_PGRP and PRIO_USER sets still throw in the code, but no test asserts it, so implementing them later does not break a test.
  • On the previous code it fails: before 2a0604d3e9 the stored value was read back.
  • No other code calls either function.
  • tools/check_conventions.py passes.

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: #9442 (it adds the lchflags entry on the line next to the getpriority one; merge order only); #11403 edits the neighbouring libkernel.md lines (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007184265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11108). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T17:52:38Z. --- ### What `getpriority` and `setpriority` measured on a retail PS5 (firmware 13.60) with a homebrew probe calling `libkernel_sys.sprx` from a payload process (pid 128, process group 105, uid 1, euid 0). The source and console log are in [this gist](https://gist.github.com/orezraey/353589fe3656987a7c75b4bd82cd7080) (`pnice`). The probe restores the starting value after every set. **`setpriority`** clamped the value to -20…20 and stored it, and `getpriority` returned the stored value. On the console `setpriority(PRIO_PROCESS, 0, v)` returns 0 for -25, -5, 5 and 25, and `getpriority` reads 0 after every one of them: raising the value does not stick either, so it is not a privilege question. `setpriority` now keeps its `which`/`who` checks and returns 0 without storing anything, and `getpriority` always returns 0. **Already matching:** `getpriority` returns 0 for `PRIO_PROCESS` 0 and the own pid, `PRIO_PGRP` 0 and `PRIO_USER` 0, `ESRCH` for an unknown pid or user, and `EINVAL` for `which` 3 and -1. **Not measured:** the probe set only `PRIO_PROCESS` 0. `setpriority` with `PRIO_PGRP` or `PRIO_USER` and a valid id now throws, naming the selector and value, and the debt entry says that this is unverified; unknown ids and `which` values still fail with `ESRCH` and `EINVAL` first. **Not changed:** on the console `PRIO_PROCESS` with pid 1, `PRIO_PGRP` with the loader's group (105) and `PRIO_USER` with uid 1 also return 0. A payload is not a title and has other processes around it, so these ids say nothing about what a title sees; AnyPS5 keeps `ESRCH` for ids other than its own. **Before and after** | Case | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | `setpriority(PRIO_PROCESS, 0, v)` for -25, -5, 5, 25 | returns 0 | returns 0, stores v clamped to -20…20 | returns 0, stores nothing | | `getpriority` after it | 0 | the stored value | 0 | | `getpriority` with an unknown id, `which` 3 or -1 | `ESRCH`, `EINVAL` | the same | the same | | `setpriority` with `PRIO_PGRP` or `PRIO_USER` and a valid id | not measured | stored | throws (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. --> Head `757e90c8c5` on `main` `7a25f87620`. - Windows 11 Pro 26200, WinLibs GCC 15.2, Release: `guest_sched_priority` passes three runs in a row. - Linux (Arch Linux on WSL2, GCC 16.2.1): `guest_sched_priority` passes three runs in a row. - The test sets -25, -5, 5, 10, 25, 99 and -99 through `PRIO_PROCESS` 0 and checks that `getpriority` reads 0 for the process, its pid, its group and its user after each, next to the existing target and error checks. The `PRIO_PGRP` and `PRIO_USER` sets still throw in the code, but no test asserts it, so implementing them later does not break a test. - On the previous code it fails: before `2a0604d3e9` the stored value was read back. - No other code calls either function. - `tools/check_conventions.py` passes. ### 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: #9442 (it adds the `lchflags` entry on the line next to the `getpriority` one; merge order only); #11403 edits the neighbouring `libkernel.md` lines (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 18:07:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T18:07:29Z.

Review: CHANGES_REQUESTED


Reviewed exact head 642f6fc7ef2cacb2a6b6b6d2aea6bd3063705dc0.

The PS5 probe evidence supports the PRIO_PROCESS, 0 case, and the description/debt entry now correctly says the group and user selector behavior is unverified. However, setpriority_nid_postfix still returns success without storing for valid PRIO_PGRP and PRIO_USER inputs as well. The repository guidance says to throw and record behavior that is not known; documenting the uncertainty alone does not make the current no-op implementation conform to that rule.

Please either provide matching PS5 set/readback evidence for the accepted group and user selectors, with tests, or have those unverified cases fail explicitly and retain the debt entry. The tested PRIO_PROCESS, 0 behavior can remain as implemented.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644559931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11108#pullrequestreview-5644559931). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:07:29Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head `642f6fc7ef2cacb2a6b6b6d2aea6bd3063705dc0`. The PS5 probe evidence supports the `PRIO_PROCESS, 0` case, and the description/debt entry now correctly says the group and user selector behavior is unverified. However, `setpriority_nid_postfix` still returns success without storing for valid `PRIO_PGRP` and `PRIO_USER` inputs as well. The repository guidance says to throw and record behavior that is not known; documenting the uncertainty alone does not make the current no-op implementation conform to that rule. Please either provide matching PS5 set/readback evidence for the accepted group and user selectors, with tests, or have those unverified cases fail explicitly and retain the debt entry. The tested `PRIO_PROCESS, 0` behavior can remain as implemented.
MarcZX10 commented 2026-10-25 18:36:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T18:36:37Z.

Review: APPROVED


Reviewed exact head fc938dcedb. The update resolves my prior request: only the measured PRIO_PROCESS path returns success without storing, while valid PRIO_PGRP and PRIO_USER sets now throw and the debt entry records that those cases remain unverified. Invalid selectors and unknown IDs retain the existing EINVAL/ESRCH behavior. The focused test now checks the measured process values and explicitly exercises the unverified selector failures. The author reports three focused test runs on Linux and Windows; the current hosted product test jobs are marked skipped, and I did not run the full local build. I found no remaining blocking issue in this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644675451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11108#pullrequestreview-5644675451). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T18:36:37Z. **Review:** APPROVED --- Reviewed exact head fc938dcedb7be231bdfac100f2c600009a9324d4. The update resolves my prior request: only the measured PRIO_PROCESS path returns success without storing, while valid PRIO_PGRP and PRIO_USER sets now throw and the debt entry records that those cases remain unverified. Invalid selectors and unknown IDs retain the existing EINVAL/ESRCH behavior. The focused test now checks the measured process values and explicitly exercises the unverified selector failures. The author reports three focused test runs on Linux and Windows; the current hosted product test jobs are marked skipped, and I did not run the full local build. I found no remaining blocking issue in this change.
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!11108
No description provided.