Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 8604cd8

Browse files
committed
Minor fixed
1 parent a40665e commit 8604cd8

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

driver/src/virtualize.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ use {
44
hypervisor::{
55
intel::{
66
capture::GuestRegisters, page::Page,
7-
ept::paging::{Ept, AccessType},
87
shared_data::SharedData,
98
},
109
vmm::start_hypervisor,
11-
error::HypervisorError,
1210
},
1311
log::debug,
1412
uefi::{
1513
proto::loaded_image::LoadedImage,
1614
table::{Boot, SystemTable},
1715
},
18-
alloc::boxed::Box,
1916
};
2017

2118
pub fn virtualize_system(guest_registers: &GuestRegisters, shared_data: &mut SharedData, system_table: &SystemTable<Boot>) {

hypervisor/src/intel/descriptor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,5 @@ impl Default for TaskStateSegment {
146146
}
147147

148148
/// See: Figure 8-11. 64-Bit TSS Format
149-
149+
#[allow(dead_code)]
150150
struct TaskStateSegmentRaw([u8; 104]);

hypervisor/src/intel/paging.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl PageTables {
112112
///
113113
/// Reference: Intel® 64 and IA-32 Architectures Software Developer's Manual: 4.5 Paging
114114
#[derive(Debug, Clone, Copy)]
115-
struct Pml4(Table);
115+
pub struct Pml4(Table);
116116

117117
/// Represents a Page-Directory-Pointer-Table Entry (PDPTE) that references a Page Directory.
118118
///
119119
/// PDPTEs are part of the second level in the standard x86-64 paging hierarchy.
120120
///
121121
/// Reference: Intel® 64 and IA-32 Architectures Software Developer's Manual: 4.5 Paging
122122
#[derive(Debug, Clone, Copy)]
123-
struct Pdpt(Table);
123+
pub struct Pdpt(Table);
124124

125125
/// Represents a Page-Directory Entry (PDE) that references a Page Table.
126126
///
@@ -130,22 +130,24 @@ struct Pdpt(Table);
130130
#[derive(Debug, Clone, Copy)]
131131
struct Pd(Table);
132132

133+
/*
133134
/// Represents a Page-Table Entry (PTE) that maps a 4-KByte Page.
134135
///
135136
/// PTEs are the lowest level in the standard x86-64 paging hierarchy and are used to map individual
136137
/// pages to physical addresses.
137138
///
138139
/// Reference: Intel® 64 and IA-32 Architectures Software Developer's Manual: 4.5 Paging
139140
#[derive(Debug, Clone, Copy)]
140-
struct Pt(Table);
141+
pub struct Pt(Table);
142+
*/
141143

142144
/// General struct to represent a table in the standard paging structure.
143145
///
144146
/// This struct is used as a basis for PML4, PDPT, PD, and PT. It contains an array of entries
145147
/// where each entry can represent different levels of the paging hierarchy.
146148
#[repr(C, align(4096))]
147149
#[derive(Debug, Clone, Copy)]
148-
struct Table {
150+
pub struct Table {
149151
entries: [Entry; 512],
150152
}
151153

hypervisor/src/intel/vm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use {
2020

2121
pub struct Vm {
2222
/// The VMCS (Virtual Machine Control Structure) for the VM.
23-
pub vmcs_region: Vmcs,
23+
pub vmcs_region: Box<Vmcs>,
2424

2525
/// The guest's descriptor tables.
2626
pub guest_descriptor: Descriptors,
@@ -45,7 +45,7 @@ impl Vm {
4545
pub fn new(guest_registers: &GuestRegisters, shared_data: &mut SharedData) -> Self {
4646
log::debug!("Creating VM");
4747

48-
let vmcs = Vmcs::default();
48+
let vmcs_region = Box::new(Vmcs::default());
4949
let guest_descriptor_table = Descriptors::new_from_current();
5050
let host_descriptor_table = Descriptors::new_for_host();
5151
let mut host_paging = unsafe { Box::<PageTables>::new_zeroed().assume_init() };
@@ -57,7 +57,7 @@ impl Vm {
5757
log::debug!("VM created");
5858

5959
Self {
60-
vmcs_region: vmcs,
60+
vmcs_region,
6161
host_paging,
6262
host_descriptor: host_descriptor_table,
6363
guest_descriptor: guest_descriptor_table,
@@ -72,11 +72,11 @@ impl Vm {
7272
self.vmcs_region.revision_id.set_bit(31, false);
7373

7474
// Clear the VMCS region.
75-
vmclear(&mut self.vmcs_region as *mut _ as _);
75+
vmclear(self.vmcs_region.as_ref() as *const _ as _);
7676
log::trace!("VMCLEAR successful!");
7777

7878
// Load current VMCS pointer.
79-
vmptrld(&mut self.vmcs_region as *mut _ as _);
79+
vmptrld(self.vmcs_region.as_ref() as *const _ as _);
8080
log::trace!("VMPTRLD successful!");
8181

8282
self.setup_vmcs()?;

hypervisor/src/intel/vmcs.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ use {
44
fmt,
55
ptr::NonNull,
66
},
7-
bit_field::BitField,
87
x86::{
98
bits64::{
109
paging::BASE_PAGE_SIZE,
1110
rflags,
1211
},
13-
controlregs, dtables, msr, task,
12+
controlregs, dtables, msr,
1413
segmentation::{cs, ds, es, fs, gs, SegmentSelector, ss},
1514
vmx::vmcs,
1615
debugregs::dr7,
1716
},
18-
x86_64::registers::control::{Cr0, Cr3, Cr4},
17+
x86_64::registers::control::Cr4,
1918
crate::{
2019
error::HypervisorError,
2120
intel::{
@@ -25,10 +24,7 @@ use {
2524
paging::PageTables,
2625
segmentation::SegmentDescriptor,
2726
shared_data::SharedData,
28-
support::{rdmsr, sidt, vmclear, vmptrld, vmread, vmwrite},
29-
vm::Vm,
30-
vmx::Vmx,
31-
vmxon::Vmxon,
27+
support::{rdmsr, sidt, vmread, vmwrite},
3228
invvpid::{invvpid_single_context, VPID_TAG},
3329
invept::invept_single_context,
3430
page::Page,

hypervisor/src/intel/vmx.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use {
2-
alloc::boxed::Box,
32
bit_field::BitField,
43
crate::{
54
error::HypervisorError,
@@ -8,16 +7,17 @@ use {
87
vmxon::Vmxon,
98
},
109
},
10+
alloc::boxed::Box,
1111
};
1212

1313
pub struct Vmx {
14-
pub vmxon_region: Vmxon,
14+
pub vmxon_region: Box<Vmxon>,
1515
}
1616

1717
impl Vmx {
1818
pub fn new() -> Self {
1919
Self {
20-
vmxon_region: Vmxon::default(),
20+
vmxon_region: Box::new(Vmxon::default()),
2121
}
2222
}
2323

@@ -27,7 +27,7 @@ impl Vmx {
2727
log::trace!("VMXON region setup successfully!");
2828

2929
log::trace!("Executing VMXON instruction");
30-
vmxon(&mut self.vmxon_region as *mut _ as _);
30+
vmxon(self.vmxon_region.as_ref() as *const _ as _);
3131
log::trace!("VMXON executed successfully!");
3232

3333
Ok(())

0 commit comments

Comments
 (0)