Skip to content

fix(virtio): respect PAGE_POISON in balloon config and free page reporting - #542

Open
Lencerf wants to merge 1 commit into
google:mainfrom
Lencerf:fix/balloon-page-poison
Open

Lencerf wants to merge 1 commit into
google:mainfrom
Lencerf:fix/balloon-page-poison

Conversation

@Lencerf

@Lencerf Lencerf commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Support driver writes (including byte/word sub-field accesses in little-endian) to BalloonConfig::poison_val as well as BalloonConfig::actual, while continuing to reject writes to read-only fields (num_pages, free_page_hint_cmd_id), cross-field boundaries, invalid access widths, and out-of-bounds offsets.
  • Track negotiated BalloonFeature bits on Balloon during VirtioMio::activate, and clear driver_feature, actual, and poison_val on VirtioMio::reset.
  • Respect Virtio v1.4 Sec 5.5.6.6 (Free Page Reporting) when VIRTIO_BALLOON_F_PAGE_POISON is negotiated: skip madvise(..., MADV_DONTNEED) when poison_val != 0 so reported free pages are not overwritten with zeroes, while continuing to reclaim reported pages when PAGE_POISON is not negotiated or poison_val == 0.
  • Add unit tests in alioth/src/virtio/dev/balloon_test.rs covering BalloonConfigMmio read/write validation, free_reporting under all PAGE_POISON / poison_val combinations, and device reset + re-activation on both 4 KiB and 16 KiB page hosts.

Verification

  • cargo +nightly fmt --check
  • cargo test -p alioth virtio::dev::balloon
  • cargo clippy --all-targets -- -D warnings
  • cargo clippy --all-targets --target x86_64-unknown-linux-gnu -- -D warnings

…rting

Allow driver writes (including byte/word sub-field accesses) to both
writable virtio-balloon configuration fields (`actual` and `poison_val`)
while continuing to reject writes to read-only or out-of-bounds offsets.

Track negotiated `BalloonFeature` flags in `Balloon::activate` (and
clear `driver_feature`, `actual`, and `poison_val` in `Balloon::reset`).
Per Virtio v1.4 Sec 5.5.6.6, when `VIRTIO_BALLOON_F_PAGE_POISON` is
negotiated, the device must not modify reported free pages to a value
other than `poison_val`. Skip `madvise(MADV_DONTNEED)` in
`free_reporting` when `PAGE_POISON` is negotiated with a non-zero
`poison_val`, while continuing to reclaim pages when `PAGE_POISON` is
not negotiated or `poison_val == 0`.

Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 42955367146

Coverage increased (+0.9%) to 44.524%

Details

  • Coverage increased (+0.9%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (66 of 68 lines covered, 97.06%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
alioth/src/virtio/dev/balloon.rs 68 66 97.06%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 16491
Covered Lines: 7131
Line Coverage: 43.24%
Relevant Branches: 1778
Covered Branches: 1003
Branch Coverage: 56.41%
Branches in Coverage %: Yes
Coverage Strength: 907.07 hits per line

💛 - Coveralls

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.

2 participants