-
Notifications
You must be signed in to change notification settings - Fork 13
Implement MMIO gap #38
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -8,13 +8,13 @@ extern crate linux_loader; | |
| extern crate vm_memory; | ||
| extern crate vm_superio; | ||
|
|
||
| use std::fs::File; | ||
| use std::io::stdout; | ||
| use std::os::unix::io::AsRawFd; | ||
| use std::os::unix::prelude::RawFd; | ||
| use std::sync::{Arc, Mutex}; | ||
| use std::thread; | ||
| use std::{io, path::PathBuf}; | ||
| use std::fs::File; | ||
|
|
||
| use kvm_bindings::{kvm_userspace_memory_region, KVM_MAX_CPUID_ENTRIES}; | ||
| use kvm_ioctls::{Kvm, VmFd}; | ||
|
|
@@ -30,6 +30,13 @@ mod epoll_context; | |
| use epoll_context::{EpollContext, EPOLL_EVENTS_LEN}; | ||
| mod kernel; | ||
|
|
||
| /// End the mmio gap at the last 32-bit address | ||
| const MMIO_GAP_END: usize = 1 << 32; | ||
| /// Size of the MMIO gap | ||
| const MMIO_GAP_SIZE: usize = 32 << 20; | ||
| /// Start of the MMIO gap | ||
| const MMIO_GAP_START: usize = MMIO_GAP_END - MMIO_GAP_SIZE; | ||
|
|
||
| #[derive(Debug)] | ||
|
|
||
| /// VMM errors. | ||
|
|
@@ -112,8 +119,19 @@ impl VMM { | |
| // Convert memory size from MBytes to bytes. | ||
| let mem_size = ((mem_size_mb as u64) << 20) as usize; | ||
|
|
||
| // Create one single memory region, from zero to mem_size. | ||
| let mem_regions = vec![(GuestAddress(0), mem_size)]; | ||
| // Check if the memory is overlapping with the MMIO gap. | ||
| // If it is, split the memory into two regions. | ||
|
|
||
| let mem_regions = if mem_size < MMIO_GAP_START { | ||
| vec![(GuestAddress(0), mem_size)] | ||
| } else { | ||
| vec![ | ||
| (GuestAddress(0), MMIO_GAP_START), | ||
| (GuestAddress(MMIO_GAP_END as u64), mem_size - MMIO_GAP_END), | ||
| ] | ||
| }; | ||
|
|
||
| let mem_regions = vec![(GuestAddress(0), MMIO_GAP_START)]; | ||
|
|
||
| // Allocate the guest memory from the memory region. | ||
| let guest_memory = GuestMemoryMmap::from_ranges(&mem_regions).map_err(Error::Memory)?; | ||
|
|
@@ -164,10 +182,7 @@ impl VMM { | |
| Ok(()) | ||
| } | ||
|
|
||
| pub fn configure_console( | ||
| &mut self, | ||
| console_path: Option<String> | ||
| ) -> Result<()> { | ||
| pub fn configure_console(&mut self, console_path: Option<String>) -> Result<()> { | ||
|
Contributor
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. unneeded reformatting. |
||
| if let Some(console_path) = console_path { | ||
| // We create the file if it does not exist, else we open | ||
| let file = File::create(&console_path).map_err(Error::ConsoleError)?; | ||
|
|
@@ -266,7 +281,13 @@ impl VMM { | |
| } | ||
| } | ||
|
|
||
| pub fn configure(&mut self, num_vcpus: u8, mem_size_mb: u32, kernel_path: &str, console: Option<String>) -> Result<()> { | ||
| pub fn configure( | ||
| &mut self, | ||
| num_vcpus: u8, | ||
| mem_size_mb: u32, | ||
| kernel_path: &str, | ||
| console: Option<String>, | ||
| ) -> Result<()> { | ||
|
Contributor
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. ditto. |
||
| self.configure_console(console)?; | ||
| self.configure_memory(mem_size_mb)?; | ||
| let kernel_load = kernel::kernel_setup(&self.guest_memory, PathBuf::from(kernel_path))?; | ||
|
|
||
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.
FWIW, placing the MMIO gap under 32 bits is meant for supporting 32-bit architecture. The PCI memory hole (Which MMIO is taking advantage of) is a legacy burden that's carried over to support MMIO based devices on 32-bit CPUs.
It does not matter where you place it, and at the end of the 32-bit address space is fine. But you should know that this could be placed e.g. way further in the 64-bit address space, and leave RAM unfragmented.
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.
I don't think we need to support 32bit OSes ? Then we could instead use something like an allocator to place the MMIO devices after the guest's memory ?