Skip to content

virtio: skip redundant memory check #4723

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 3 commits into from
Aug 13, 2024

Conversation

ihciah
Copy link
Contributor

@ihciah ihciah commented Aug 6, 2024

Changes

Remove redundant memory check for DescriptorChain::new.

Reason

Since we already validated the queue layout and desc index, there's no need to check it again.

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

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this
    PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet
    contribution quality standards.

  • This functionality cannot be added in rust-vmm.

@ihciah ihciah force-pushed the skip-redundant-check branch from 6df7337 to 63e5adb Compare August 6, 2024 16:41
Copy link
Contributor

@roypat roypat left a comment

Choose a reason for hiding this comment

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

You're right, this check is superfluous and can be omitted without marking the function as unsafe. The same range checks on guest memory are also performed by mem.read_obj a few lines down, and as long as the caller validated index to be less than queue_size (happens in DescriptorChain::has_next), and that the in-memory layout of the virtio queues is valid (happens in Queue::is_valid), we are even guaranteed to read from inside the virtio queue structure. However, reading from inside the queue structure is just a functional requirement, not a safety one in Rust's sense.

I think we should still add a doc comment to the function that notes this additional requirement (e.g. callers need to make sure that index and queue layout are valid). All current callers do indeed guarantee this, so no further code changes are needed.

@ihciah ihciah force-pushed the skip-redundant-check branch from 7c40c00 to b099584 Compare August 8, 2024 16:21
@roypat roypat added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Aug 9, 2024
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.00%. Comparing base (b9f4c6c) to head (dca8801).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4723      +/-   ##
==========================================
+ Coverage   81.99%   82.00%   +0.01%     
==========================================
  Files         254      254              
  Lines       31193    31195       +2     
==========================================
+ Hits        25576    25581       +5     
+ Misses       5617     5614       -3     
Flag Coverage Δ
5.10-c5n.metal 82.01% <100.00%> (+0.01%) ⬆️
5.10-m5n.metal 82.00% <100.00%> (+0.01%) ⬆️
5.10-m6a.metal 81.30% <100.00%> (+<0.01%) ⬆️
5.10-m6g.metal 79.05% <100.00%> (+0.01%) ⬆️
5.10-m6i.metal 82.00% <100.00%> (+0.01%) ⬆️
5.10-m7g.metal 79.05% <100.00%> (+0.01%) ⬆️
6.1-c5n.metal 82.01% <100.00%> (+0.01%) ⬆️
6.1-m5n.metal 82.00% <100.00%> (+0.01%) ⬆️
6.1-m6a.metal 81.31% <100.00%> (+0.01%) ⬆️
6.1-m6g.metal 79.05% <100.00%> (+0.01%) ⬆️
6.1-m6i.metal 82.00% <100.00%> (+0.01%) ⬆️
6.1-m7g.metal 79.05% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@ShadowCurse ShadowCurse left a comment

Choose a reason for hiding this comment

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

Good change. Just couple of things to fix:

@ihciah ihciah force-pushed the skip-redundant-check branch from b099584 to f038f21 Compare August 12, 2024 16:02
Remove redundant memory check in descriptor chain creation.

Signed-off-by: ihciah <[email protected]>
@ihciah ihciah force-pushed the skip-redundant-check branch from f038f21 to e09658a Compare August 12, 2024 16:04
@roypat roypat merged commit 7025008 into firecracker-microvm:main Aug 13, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants