Skip to content

fix(sched/credit2): check the cap before changing the weight - #122

Merged
alexandermerritt merged 2 commits into
edera/4.22from
alexm/credit2-check-cap-first
Nov 19, 2026
Merged

alexandermerritt merged 2 commits into
edera/4.22from
alexm/credit2-check-cap-first

Conversation

@alexandermerritt

@alexandermerritt alexandermerritt commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

part of ENG-172

Bug fix: scheduler parameter mutation happened before validating all parameters. The weight was updated prior to validating the cap value. We move the cap check ahead of the mutation.

We avoided this bug because our tooling validated the inputs first.

Supports https://github.com/edera-dev/protect/pull/5068

XEN_DOMCTL_SCHEDOP_putinfo set the domain's weight first and only
then checked the cap against 100 * nr_units. A request with a
nonzero weight and a cap that is too high returned -EINVAL after the
weight had changed, so a refused request still changed the domain.
A caller cannot tell that from the error, and cannot retry without
knowing the old weight.

Check the cap before any change, under the same lock the check
already took, so a refused request leaves the domain as it was.

Signed-off-by: Alexander M. Merritt <[email protected]>
@alexandermerritt
alexandermerritt force-pushed the alexm/credit2-check-cap-first branch from 64067f9 to aff2a02 Compare November 19, 2026 18:03
@alexandermerritt
alexandermerritt marked this pull request as ready for review November 19, 2026 18:03
@alexandermerritt alexandermerritt changed the title sched/credit2: check the cap before changing the weight fix(sched/credit2): check the cap before changing the weight Nov 19, 2026
antoineco
antoineco previously approved these changes Nov 19, 2026

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review

Reviewed at 3cb0d0e.

A refused credit2 putinfo now leaves the weight alone, and the hoisted check cannot fire when cap is 0, so weight-only requests and cap removal are unaffected. The new XTF test would fail against the old ordering. Nothing concerning.

Test Coverage

Reviewed at 3cb0d0e.

The new sched-credit2-cap-refused XTF test runs on the shipped x86_64 build as a PV and a PVH dom0 under credit2. It fails if a putinfo refused for its cap leaves dom0 at the new weight, and if the same request without a cap does not change it.

azenla
azenla previously approved these changes Nov 19, 2026
Nothing on a pull request issues XEN_DOMCTL_scheduler_op, so a
putinfo that returns -EINVAL after it changed the domain's weight
would reach a release unnoticed, as it did before the previous
commit.

Add an XTF test that sends dom0 a putinfo with a new weight and a
cap no vCPU count can allow, and checks that it fails and that
getinfo still reports the old weight. The same request with no cap
must then change the weight, so a getinfo that never changes cannot
pass. The test skips on a hypervisor that does not run credit2.

XTF has no domctl header at the pinned commit, so the test defines
the few structures it needs, as gnttab-copy-ops does. It runs as a PV
and as a PVH dom0.

Signed-off-by: Alexander M. Merritt <[email protected]>
@alexandermerritt
alexandermerritt dismissed stale reviews from azenla and antoineco via 3cb0d0e November 19, 2026 18:25
@alexandermerritt

Copy link
Copy Markdown
Contributor Author

added a unit test in xtf

@alexandermerritt
alexandermerritt merged commit e2a94c5 into edera/4.22 Nov 19, 2026
27 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants