-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arch: implement SHM region management
We have multiple devices (fs and gpu) that can use SHM regions. So far, we were creating a single SHM region so only one device could make use of it. In this commit, we implement SHM region management so multiple devices can request their own regions. A perhaps controversial decision is to NOT use the GuestMemory abstraction to manage the SHM regions, and instead operate them naked. The reason behind this is that GuestMemory is primarily designed with the intention of self-managing the memory mappings, which is exactly the opposite of what we need to do with SHM regions. Also, SHM regions operate in very different ways on Linux/KVM and macOS/HVF. On the first, we need to create a large mapping, register it with KVM, and then lay SHM windows on top of it as nested mappings. On the latter, nested mappings aren't supported, so each SHM window must be explicitly registered with HVF, so we don't need to create nor register an initial large mapping. In addition to this, SHM windows on Linux/KVM operate with offsets on top of the host address, while macOS/HVF operate with offsets on top of the guest address. For the moment, we're hardcoding the SHM region sizes for gpu and fs. A future commit will extend the API so users can configure those sizes as desired. Signed-off-by: Sergio Lopez <[email protected]>
- Loading branch information
Showing
11 changed files
with
196 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::round_up; | ||
|
||
use super::ArchMemoryInfo; | ||
#[derive(Debug)] | ||
pub enum Error { | ||
OutOfSpace, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct ShmRegion { | ||
pub guest_addr: u64, | ||
pub size: usize, | ||
} | ||
|
||
pub struct ShmManager { | ||
next_guest_addr: u64, | ||
page_size: usize, | ||
} | ||
|
||
impl ShmManager { | ||
pub fn new(info: &ArchMemoryInfo) -> ShmManager { | ||
Self { | ||
next_guest_addr: info.shm_start_addr, | ||
page_size: info.page_size, | ||
} | ||
} | ||
|
||
pub fn get_region(&mut self, size: usize) -> Result<ShmRegion, Error> { | ||
let size = round_up(size, self.page_size); | ||
|
||
let region = ShmRegion { | ||
guest_addr: self.next_guest_addr, | ||
size, | ||
}; | ||
|
||
if let Some(addr) = self.next_guest_addr.checked_add(size as u64) { | ||
self.next_guest_addr = addr; | ||
Ok(region) | ||
} else { | ||
Err(Error::OutOfSpace) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.