memN0ps / illusion-rs

Rusty Hypervisor - Windows UEFI Blue Pill Type-1 Hypervisor in Rust (Codename: Illusion)
MIT License
239 stars 29 forks source link

Optimize EPT Structure for Space and Speed #1

Closed memN0ps closed 8 months ago

memN0ps commented 8 months ago

Description:

This PR refines our Extended Page Tables (EPT) setup, moving away from the initial broad pre-allocation of Page Tables (Pt) for every Page Directory (Pd) entry (option A) to a better allocation model (option B). This adjustment, coupled with the introduction of split_2mb_to_4kb, remap_gpa_to_hpa, and modify_page_permissions functions, really helps boost the hypervisor's efficiency and flexibility.

Option A:

#[repr(C, align(4096))]
pub struct Ept {
    pml4: Pml4,
    pdpt: Pdpt,
    pd: [Pd; 512],
    pt: [[Pt; 512]; 512],
}

Option B:

#[repr(C, align(4096))]
pub struct Ept {
    pml4: Pml4,
    pdpt: Pdpt,
    pd: [Pd; 512],
    pt: Pt,
}

Option C:

#[repr(C, align(4096))]
pub struct Ept {
    pml4: Pml4,
    pdpt: Pdpt,
    pd: Pd,
    pt: Pt,
}

Key Changes:

Benefits: