Skip to content

Commit 17fbb1b

Browse files
committed
use 3 level ept paging
1 parent 5b7307d commit 17fbb1b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ repository = "https://github.com/arceos-hypervisor/arm_vcpu"
1515
categories = ["embedded", "no-std"]
1616
keywords = ["hypervisor", "aarch64", "vcpu"]
1717

18+
[features]
19+
4-level-page = []
1820

1921
[dependencies]
2022
log = "0.4"

src/vcpu.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,33 @@ impl<H: AxVCpuHal> Aarch64VCpu<H> {
171171
// - 4KiB granule (TG0)
172172
// - 39-bit address space (T0_SZ)
173173
// - start at level 1 (SL0)
174-
// self.guest_system_regs.vtcr_el2 = (VTCR_EL2::PS::PA_40B_1TB
175-
// + VTCR_EL2::TG0::Granule4KB
176-
// + VTCR_EL2::SH0::Inner
177-
// + VTCR_EL2::ORGN0::NormalWBRAWA
178-
// + VTCR_EL2::IRGN0::NormalWBRAWA
179-
// + VTCR_EL2::SL0.val(0b01)
180-
// + VTCR_EL2::T0SZ.val(64 - 39))
181-
// .into();
174+
#[cfg(not(feature = "4-level-page"))]
175+
{
176+
self.guest_system_regs.vtcr_el2 = (VTCR_EL2::PS::PA_40B_1TB
177+
+ VTCR_EL2::TG0::Granule4KB
178+
+ VTCR_EL2::SH0::Inner
179+
+ VTCR_EL2::ORGN0::NormalWBRAWA
180+
+ VTCR_EL2::IRGN0::NormalWBRAWA
181+
+ VTCR_EL2::SL0.val(0b01)
182+
+ VTCR_EL2::T0SZ.val(64 - 39))
183+
.into();
184+
}
182185

183186
// use 4 level ept paging
184187
// - 4KiB granule (TG0)
185188
// - 48-bit address space (T0_SZ)
186189
// - start at level 0 (SL0)
187-
self.guest_system_regs.vtcr_el2 = (VTCR_EL2::PS::PA_48B_256TB
190+
#[cfg(feature = "4-level-page")]
191+
{
192+
self.guest_system_regs.vtcr_el2 = (VTCR_EL2::PS::PA_48B_256TB
188193
+ VTCR_EL2::TG0::Granule4KB
189194
+ VTCR_EL2::SH0::Inner
190195
+ VTCR_EL2::ORGN0::NormalWBRAWA
191196
+ VTCR_EL2::IRGN0::NormalWBRAWA
192197
+ VTCR_EL2::SL0.val(0b10) // 0b10 means start at level 0
193198
+ VTCR_EL2::T0SZ.val(64 - 48))
194-
.into();
199+
.into();
200+
}
195201

196202
let mut hcr_el2 = HCR_EL2::VM::Enable
197203
+ HCR_EL2::RW::EL1IsAarch64

0 commit comments

Comments
 (0)