Skip to content

Commit f484d8b

Browse files
committed
feat: 添加 pt_level 字段以支持不同的页表级别配置
1 parent b7cd8e4 commit f484d8b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/vcpu.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct Aarch64VCpu {
4848
guest_system_regs: GuestSystemRegisters,
4949
/// The MPIDR_EL1 value for the vCPU.
5050
mpidr: u64,
51+
pub pt_level: usize,
5152
}
5253

5354
/// Configuration for creating a new `Aarch64VCpu`
@@ -60,6 +61,7 @@ pub struct Aarch64VCpuCreateConfig {
6061
pub mpidr_el1: u64,
6162
/// The address of the device tree blob.
6263
pub dtb_addr: usize,
64+
pub pt_level: usize,
6365
}
6466

6567
/// Configuration for setting up a new `Aarch64VCpu`
@@ -81,6 +83,7 @@ impl Aarch64VCpu {
8183
host_stack_top: 0,
8284
guest_system_regs: GuestSystemRegisters::default(),
8385
mpidr: config.mpidr_el1,
86+
pt_level: config.pt_level,
8487
})
8588
}
8689

@@ -110,6 +113,17 @@ impl Aarch64VCpu {
110113
pub fn setup_current_cpu(&mut self, vmid: usize) -> AxResult {
111114
// Set VMID then invalidate stage-2 TLB for this VMID to avoid stale translations.
112115
let vmid_mask: u64 = 0xffff << 48;
116+
let val = match self.pt_level {
117+
4 => VTCR_EL2::SL0::Granule4KBLevel0 + VTCR_EL2::T0SZ.val(64 - 48),
118+
_ => VTCR_EL2::SL0::Granule4KBLevel1 + VTCR_EL2::T0SZ.val(64 - 39),
119+
} + (VTCR_EL2::TG0::Granule4KB
120+
+ VTCR_EL2::SH0::Inner
121+
+ VTCR_EL2::ORGN0::NormalWBRAWA
122+
+ VTCR_EL2::IRGN0::NormalWBRAWA)
123+
.value;
124+
self.guest_system_regs.vtcr_el2 = val.value;
125+
VTCR_EL2.set(self.guest_system_regs.vtcr_el2);
126+
113127
let mut vttbr = self.guest_system_regs.vttbr_el2;
114128
vttbr = (vttbr & !vmid_mask) | ((vmid as u64 & 0xffff) << 48);
115129
VTTBR_EL2.set(vttbr);
@@ -182,12 +196,12 @@ impl Aarch64VCpu {
182196
self.guest_system_regs.sctlr_el1 = 0x30C50830;
183197
self.guest_system_regs.pmcr_el0 = 0;
184198

185-
self.guest_system_regs.vtcr_el2 = probe_vtcr_support()
186-
+ (VTCR_EL2::TG0::Granule4KB
187-
+ VTCR_EL2::SH0::Inner
188-
+ VTCR_EL2::ORGN0::NormalWBRAWA
189-
+ VTCR_EL2::IRGN0::NormalWBRAWA)
190-
.value;
199+
// self.guest_system_regs.vtcr_el2 = probe_vtcr_support()
200+
// + (VTCR_EL2::TG0::Granule4KB
201+
// + VTCR_EL2::SH0::Inner
202+
// + VTCR_EL2::ORGN0::NormalWBRAWA
203+
// + VTCR_EL2::IRGN0::NormalWBRAWA)
204+
// .value;
191205

192206
let mut hcr_el2 =
193207
HCR_EL2::VM::Enable + HCR_EL2::TSC::EnableTrapEl1SmcToEl2 + HCR_EL2::RW::EL1IsAarch64;

0 commit comments

Comments
 (0)