Skip to content

Fix memory layout deadlock caused by virtio devices - #519

Draft
Lencerf wants to merge 1 commit into
google:mainfrom
Lencerf:fix/virtio/mem-deadlock
Draft

Lencerf wants to merge 1 commit into
google:mainfrom
Lencerf:fix/virtio/mem-deadlock

Conversation

@Lencerf

@Lencerf Lencerf commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@coveralls

coveralls commented Oct 5, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 37281200351

Coverage increased (+0.05%) to 39.089%

Details

  • Coverage increased (+0.05%) from the base build.
  • Patch coverage: 17 uncovered changes across 3 files (51 of 68 lines covered, 75.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
alioth/src/mem/mem.rs 34 20 58.82%
alioth/src/virtio/vu/backend.rs 2 0 0.0%
alioth/src/cpu/cpu_amd64/sev.rs 1 0 0.0%
Total (5 files) 68 51 75.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15583
Covered Lines: 5920
Line Coverage: 37.99%
Relevant Branches: 1642
Covered Branches: 813
Branch Coverage: 49.51%
Branches in Coverage %: Yes
Coverage Strength: 918.21 hits per line

💛 - Coveralls

Virtio workers used to hold RamBus::lock_layout() for as long as a
device was running, so any runtime change of the guest RAM layout,
e.g. memory hot-plug, blocked forever on the write lock.

Borrowing the read-copy-update idea from Linux RCU,

- Readers call RamBus::load() to get an immutable snapshot. The read
  lock is only held while cloning the Arc.
- Writers call RamBus::update(), which copies the layout, applies the
  change and publishes the result atomically. A failed update
  publishes nothing, and Memory batches all RAM ranges of a region
  into a single update.
- Each published layout carries a generation number, so a reader can
  detect a stale snapshot with a single atomic load by comparing
  Ram::generation() with RamBus::generation().

Since ArcMemPages is reference counted, a snapshot keeps every host
mapping it refers to alive, even after the slot is removed from the
bus.

This commit fixes the deadlock, but a running virtio worker still uses
the snapshot taken when the device was activated. Follow-up commits
make workers pick up new snapshots.

Assisted-by: Antigravity:Claude-Fable-5.1
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@Lencerf
Lencerf force-pushed the fix/virtio/mem-deadlock branch from 5d94d21 to 37ac48e Compare October 5, 2026 08:02
@Lencerf
Lencerf marked this pull request as draft October 5, 2026 08:20
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