Fix soundness issues with MMIO and shared memory#18
Merged
wangrunji0408 merged 8 commits intorcore-os:masterfrom Sep 29, 2022
Merged
Fix soundness issues with MMIO and shared memory#18wangrunji0408 merged 8 commits intorcore-os:masterfrom
wangrunji0408 merged 8 commits intorcore-os:masterfrom
Conversation
The queue is just shared memory, not MMIO memory, so there is no need to use volatile reads and writes.
wangrunji0408
approved these changes
Sep 29, 2022
Member
wangrunji0408
left a comment
There was a problem hiding this comment.
LGTM. I didn't realize this problem before. Thanks for your work!
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
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.
The way the
volatilecrate handles MMIO regions is not sound, because it creates references to memory which shouldn't be considered dereferenceable. There is an attempt to fix this in rust-osdev/volatile#22 (and lots of discussion), but that PR has been open since May 2021 and doesn't seem near being submitted. Instead, I've implemented the functionality we need in a newvolatilemodule here using theaddr_of!andaddr_of_mut!macros, keeping all MMIO regions as pointers and never creating references.This works for the MMIO transport and config regions. For the Virtqueue, I don't think we need volatile access at all because it's just shared memory, not MMIO. We still shouldn't be using references, however, as DMA to these shared regions by the device violates Rust's aliasing rules, so I've changed the implementation to use pointers instead.