-
Notifications
You must be signed in to change notification settings - Fork 111
I/O virtual memory (IOMMU) support #327
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
Open
XanClic
wants to merge
12
commits into
rust-vmm:main
Choose a base branch
from
XanClic:iommu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,909
−55
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3540534
GuestMemory: Add lifetimes to try_access()
XanClic 9bcd5ac
Bytes: Fix read() and write()
XanClic 2b83c72
Bytes: Do not use to_region_addr()
XanClic 5b0e1ae
Add IoMemory trait
XanClic 45985f4
Switch to IoMemory as the primary memory type
XanClic 254db08
Add Iommu trait and Iotlb struct
XanClic efa0a9c
Add IommuMemory
XanClic 284a200
mmap: Wrap MmapRegion in Arc<>
XanClic c33415a
IoMemory: Add IOVA-space bitmap
XanClic 64c309e
Add tests for IOMMU functionality
XanClic ef37f4d
DESIGN: Document I/O virtual memory
XanClic 37686ac
CHANGELOG: Add I/O virtual memory entry
XanClic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
use std::convert::From; | ||
use std::fs::File; | ||
use std::io; | ||
use std::mem::size_of; | ||
use std::ops::{BitAnd, BitOr, Deref}; | ||
use std::rc::Rc; | ||
use std::sync::atomic::Ordering; | ||
|
@@ -374,9 +375,9 @@ pub trait GuestMemory { | |
/// - the error code returned by the callback 'f' | ||
/// - the size of the already handled data when encountering the first hole | ||
/// - the size of the already handled data when the whole range has been handled | ||
fn try_access<F>(&self, count: usize, addr: GuestAddress, mut f: F) -> Result<usize> | ||
fn try_access<'a, F>(&'a self, count: usize, addr: GuestAddress, mut f: F) -> Result<usize> | ||
where | ||
F: FnMut(usize, usize, MemoryRegionAddress, &Self::R) -> Result<usize>, | ||
F: FnMut(usize, usize, MemoryRegionAddress, &'a Self::R) -> Result<usize>, | ||
{ | ||
let mut cur = addr; | ||
let mut total = 0; | ||
|
@@ -464,8 +465,8 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T { | |
self.try_access( | ||
buf.len(), | ||
addr, | ||
|offset, _count, caddr, region| -> Result<usize> { | ||
region.write(&buf[offset..], caddr) | ||
|offset, count, caddr, region| -> Result<usize> { | ||
region.write(&buf[offset..(offset + count)], caddr) | ||
}, | ||
) | ||
} | ||
|
@@ -474,8 +475,8 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T { | |
self.try_access( | ||
buf.len(), | ||
addr, | ||
|offset, _count, caddr, region| -> Result<usize> { | ||
region.read(&mut buf[offset..], caddr) | ||
|offset, count, caddr, region| -> Result<usize> { | ||
region.read(&mut buf[offset..(offset + count)], caddr) | ||
}, | ||
) | ||
} | ||
|
@@ -591,17 +592,62 @@ impl<T: GuestMemory + ?Sized> Bytes<GuestAddress> for T { | |
} | ||
|
||
fn store<O: AtomicAccess>(&self, val: O, addr: GuestAddress, order: Ordering) -> Result<()> { | ||
// `find_region` should really do what `to_region_addr` is doing right now, except | ||
// it should keep returning a `Result`. | ||
self.to_region_addr(addr) | ||
.ok_or(Error::InvalidGuestAddress(addr)) | ||
.and_then(|(region, region_addr)| region.store(val, region_addr, order)) | ||
let expected = size_of::<O>(); | ||
|
||
let completed = self.try_access( | ||
expected, | ||
addr, | ||
|offset, len, region_addr, region| -> Result<usize> { | ||
assert_eq!(offset, 0); | ||
if len < expected { | ||
return Err(Error::PartialBuffer { | ||
expected, | ||
completed: len, | ||
}); | ||
} | ||
region.store(val, region_addr, order).map(|()| expected) | ||
}, | ||
)?; | ||
|
||
if completed < expected { | ||
Err(Error::PartialBuffer { | ||
expected, | ||
completed, | ||
}) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn load<O: AtomicAccess>(&self, addr: GuestAddress, order: Ordering) -> Result<O> { | ||
self.to_region_addr(addr) | ||
.ok_or(Error::InvalidGuestAddress(addr)) | ||
.and_then(|(region, region_addr)| region.load(region_addr, order)) | ||
let expected = size_of::<O>(); | ||
let mut result = None::<O>; | ||
|
||
let completed = self.try_access( | ||
expected, | ||
addr, | ||
|offset, len, region_addr, region| -> Result<usize> { | ||
assert_eq!(offset, 0); | ||
if len < expected { | ||
return Err(Error::PartialBuffer { | ||
expected, | ||
completed: len, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
}); | ||
} | ||
result = Some(region.load(region_addr, order)?); | ||
Ok(expected) | ||
}, | ||
)?; | ||
|
||
if completed < expected { | ||
Err(Error::PartialBuffer { | ||
expected, | ||
completed, | ||
}) | ||
} else { | ||
// Must be set because `completed == expected` | ||
Ok(result.unwrap()) | ||
} | ||
} | ||
} | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completed
should be 0, since you didn't read anything. So here you could also returnOk(0)
("no more data") and let theif
below returnError::PartialBuffer
.