Skip to content
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

Track regions of the TVM guest physical address space #4

Merged
merged 5 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions page-tracking/src/collections/page_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ impl<T> RawPageVec<T> {
self.0.retain(f)
}

/// See `std::vec::insert`
pub fn insert(&mut self, index: usize, element: T) {
self.0.insert(index, element);
}

/// See `std::vec::remove`
pub fn remove(&mut self, index: usize) -> T {
self.0.remove(index)
Expand Down Expand Up @@ -154,8 +159,14 @@ impl<T> From<SequentialPages<InternalClean>> for RawPageVec<T> {
impl<T> Deref for RawPageVec<T> {
type Target = [T];

fn deref(&self) -> &[T] {
unsafe { core::slice::from_raw_parts(self.0.as_ptr(), self.0.len()) }
fn deref(&self) -> &Self::Target {
self.0.as_slice()
}
}

impl<T> DerefMut for RawPageVec<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.0.as_mut_slice()
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use crate::guest_tracking::{GuestState, Guests};
use crate::print_util::*;
use crate::smp;
use crate::vm_cpu::{VirtualRegister, VmCpuExit, VmCpuStatus, VmCpus, VM_CPU_BYTES};
use crate::vm_pages::{self, ActiveVmPages, VmPages, TVM_STATE_PAGES};
use crate::vm_pages::{
self, ActiveVmPages, VmPages, VmRegionList, TVM_REGION_LIST_PAGES, TVM_STATE_PAGES,
};
use crate::{print, println};

const GUEST_ID_SELF_MEASUREMENT: u64 = 0;
Expand Down Expand Up @@ -966,6 +968,7 @@ impl<T: GuestStagePageTable> HostVm<T, VmStateInitializing> {
.take_pages_for_host_state(num_pte_pages as usize)
.into_iter();
let guest_tracking_pages = hyp_mem.take_pages_for_host_state(2);
let region_vec_pages = hyp_mem.take_pages_for_host_state(TVM_REGION_LIST_PAGES as usize);

// Pages for the array of vCPUs.
let num_vcpu_pages = PageSize::num_4k_pages(VM_CPU_BYTES * MAX_CPUS as u64);
Expand All @@ -975,7 +978,8 @@ impl<T: GuestStagePageTable> HostVm<T, VmStateInitializing> {
let root =
PlatformPageTable::new(root_table_pages, PageOwnerId::host(), page_tracker.clone())
.unwrap();
let vm_pages = VmPages::new(root, 0);
let region_vec = VmRegionList::new(region_vec_pages, page_tracker.clone());
let vm_pages = VmPages::new(root, region_vec, 0);
for p in pte_pages {
vm_pages.add_pte_page(p).unwrap();
}
Expand Down Expand Up @@ -1029,6 +1033,7 @@ impl<T: GuestStagePageTable> HostVm<T, VmStateInitializing> {
.unwrap();
mapper.map_page_with_measurement(vm_addr, mappable).unwrap();
}
mapper.finish();
}

/// Add pages which need not be measured to the host page tables. For RAM pages, requires that
Expand Down Expand Up @@ -1059,6 +1064,7 @@ impl<T: GuestStagePageTable> HostVm<T, VmStateInitializing> {
.unwrap();
mapper.map_page(vm_addr, mappable).unwrap();
}
mapper.finish();
}

/// Completes intialization of the host, returning it in a finalized state.
Expand Down
Loading