This commit is contained in:
Masato Imai
2025-04-30 18:25:58 +00:00
parent a49731217d
commit cdca92e9f0
2 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,5 @@
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use alloc::vec::Vec;
use bitfield::bitfield; use bitfield::bitfield;
use x86_64::{ use x86_64::{
structures::paging::{FrameAllocator, PhysFrame, Size4KiB}, structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
@ -67,6 +66,9 @@ impl EPT {
lv4_entry.set_phys(frame.start_address().as_u64() >> 12); lv4_entry.set_phys(frame.start_address().as_u64() >> 12);
lv4_entry.set_map_memory(false); lv4_entry.set_map_memory(false);
lv4_entry.set_typ(0); lv4_entry.set_typ(0);
lv4_entry.set_read(true);
lv4_entry.set_write(true);
lv4_entry.set_exec_super(true);
table_ptr table_ptr
} else { } else {
let frame = let frame =
@ -84,6 +86,9 @@ impl EPT {
lv3_entry.set_phys(frame.start_address().as_u64() >> 12); lv3_entry.set_phys(frame.start_address().as_u64() >> 12);
lv3_entry.set_map_memory(false); lv3_entry.set_map_memory(false);
lv3_entry.set_typ(0); lv3_entry.set_typ(0);
lv3_entry.set_read(true);
lv3_entry.set_write(true);
lv3_entry.set_exec_super(true);
table_ptr table_ptr
} else { } else {
let frame = let frame =
@ -94,6 +99,10 @@ impl EPT {
let lv2_entry = &mut lv2_table[lv2_index as usize]; let lv2_entry = &mut lv2_table[lv2_index as usize];
lv2_entry.set_phys(hpa >> 12); lv2_entry.set_phys(hpa >> 12);
lv2_entry.set_map_memory(true); lv2_entry.set_map_memory(true);
lv2_entry.set_typ(0);
lv2_entry.set_read(true);
lv2_entry.set_write(true);
lv2_entry.set_exec_super(true);
info!("{:#x}", lv2_entry as *const _ as u64); info!("{:#x}", lv2_entry as *const _ as u64);
Ok(()) Ok(())

View File

@ -10,11 +10,12 @@ use x86_64::VirtAddr;
use core::{ use core::{
arch::{asm, naked_asm}, arch::{asm, naked_asm},
mem::offset_of, mem::offset_of,
sync::atomic::Ordering,
}; };
use crate::{ use crate::{
info, info,
memory::BootInfoFrameAllocator, memory::{self, BootInfoFrameAllocator},
vmm::vmcs::{ vmm::vmcs::{
DescriptorType, EntryControls, Granularity, PrimaryExitControls, DescriptorType, EntryControls, Granularity, PrimaryExitControls,
PrimaryProcessorBasedVmExecutionControls, SecondaryProcessorBasedVmExecutionControls, PrimaryProcessorBasedVmExecutionControls, SecondaryProcessorBasedVmExecutionControls,
@ -380,7 +381,8 @@ impl VCpu {
info!("Entering VM loop"); info!("Entering VM loop");
let guest_ptr = Self::guest as u64; let guest_ptr = Self::guest as u64;
let guest_addr = self.ept.get_phys_addr(0).unwrap(); let guest_addr = self.ept.get_phys_addr(0).unwrap()
+ memory::PHYSICAL_MEMORY_OFFSET.load(Ordering::Relaxed);
unsafe { unsafe {
core::ptr::copy_nonoverlapping(guest_ptr as *const u8, guest_addr as *mut u8, 200); core::ptr::copy_nonoverlapping(guest_ptr as *const u8, guest_addr as *mut u8, 200);
vmwrite(vmcs::guest::RIP, 0).unwrap(); vmwrite(vmcs::guest::RIP, 0).unwrap();