-
Notifications
You must be signed in to change notification settings - Fork 2.1k
refactor: de-duplicate virtio queue validation logic #5276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+136
−168
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Just call initialize() again. It does some needless alignment checking, but that's not really harmful. Signed-off-by: Patrick Roy <[email protected]>
6fbb59c to
f8cff4e
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5276 +/- ##
==========================================
+ Coverage 82.83% 82.91% +0.08%
==========================================
Files 250 250
Lines 26968 26902 -66
==========================================
- Hits 22338 22306 -32
+ Misses 4630 4596 -34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Factor out the alignment checks on the vring components into get_slice_ptr, instead of writing them out 3 times in initialize(). While we're at it, also explain why its okay to only alignment check the GPA and not the HVAs as well. Signed-off-by: Patrick Roy <[email protected]>
Vring validation was a bit awkwardly split across two functions which did overlapping sets of checks: Queue::initialize verified alignment and memory accesses, while Queue::is_valid additionally checked Queue::ready and Queue::size. However, on the activation path, both were called, meanign we checked alignment twice (.initialize() is called in .activate(), but we only call .activate() if .is_valid() returned true). This is confusing at best, and at worst made us potentially virtio spec incompliant: If the quest tried to activate a virtio device, but this failed because some vring was not valid (in terms of Queue::is_valid), then Firecracker would silently ignore the activation request. Now, it instead marks the device as needing reset, and notifies the guest of its failure to properly configure the vrings. While we're at it, also remove some duplicated checks from the vring restoration code: .initialize() is called for activated devices, so there's no need to later validate the size specifically again, and also no need for the additional call to is_valid(). Fix up some unit tests that activate virtio devices where some queues do not satisfy the old Queue::is_valid() checks, as now these checks must pass for activation to succeed. The only interesting fix here is in test_virtiodev_sanity_checks in virtio/persist.rs, which can be seen as a symptom of a bug fix: Previously, restoration code refused to load snapshots that had their queue size set to a value larger than Queue::max_size, even if a device was not activated. This is arguably wrong, as The guest can configure a queue to have a size greater than max size no problem, and never activate the device for example, in which case prior to this commit Firecracker would refuse to resume snapshots taken of such VMs. Signed-off-by: Patrick Roy <[email protected]>
verify_size only had assertions about our mocks, which is not very useful (in fact, the second assertion was trivially true, no matter what we did). So let's just remove it. Signed-off-by: Patrick Roy <[email protected]>
ShadowCurse
approved these changes
Jun 23, 2025
Manciukic
approved these changes
Jun 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As part of #5260 we noticed that parts of our virtio queue validation logic was duplicated between
Queue::is_validandQueue::initialize, resulting in most queue invariants being checked twice needlessly. This PR fixed this by merging the two functions, and having all validation happen right before activation (refusing to activate the device if validation of any of its queues fails).License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.PR Checklist
tools/devtool checkstyleto verify that the PR passes theautomated style checks.
how they are solving the problem in a clear and encompassing way.
in the PR.
CHANGELOG.md.Runbook for Firecracker API changes.
integration tests.
TODO.rust-vmm.