Fix soundness issues with MMIO and shared memory #18
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
volatile
crate 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 newvolatile
module 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.