Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mshv-bindings: Derive constant instead of hard-coding #142

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion mshv-bindings/src/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,30 @@ pub struct MiscRegs {
pub hypercall: u64,
}

const fn initialize_comp_sizes() -> [usize; MSHV_VP_STATE_COUNT as usize] {
let mut vp_state_comp_size = [0; MSHV_VP_STATE_COUNT as usize];

vp_state_comp_size[MSHV_VP_STATE_LAPIC as usize] = std::mem::size_of::<LapicState>();
vp_state_comp_size[MSHV_VP_STATE_XSAVE as usize] = std::mem::size_of::<XSave>();
vp_state_comp_size[MSHV_VP_STATE_SIMP as usize] = HV_PAGE_SIZE; // Assuming SIMP page is
// allocated by the Hypervisor
// which is of PAGE_SIZE
vp_state_comp_size[MSHV_VP_STATE_SIEFP as usize] = HV_PAGE_SIZE; // Assuming SIEFP page is
// allocated by the Hypervisor
// which is of PAGE_SIZE
vp_state_comp_size[MSHV_VP_STATE_SYNTHETIC_TIMERS as usize] =
std::mem::size_of::<hv_synthetic_timers_state>();

vp_state_comp_size
}

// Total size: 13512 bytes
// 1. MSHV_VP_STATE_LAPIC, Size: 1024 bytes;
// 2. MSHV_VP_STATE_XSAVE, Size: 4096 bytes;
// 3. MSHV_VP_STATE_SIMP, Size: 4096 bytes;
// 4. MSHV_VP_STATE_SIEFP, Size: 4096 bytes;
// 5. MSHV_VP_STATE_SYNTHETIC_TIMERS, Size: 200 bytes;
const VP_STATE_COMP_SIZES: [usize; 5] = [0x400, 0x1000, 0x1000, 0x1000, 0xC8];
const VP_STATE_COMP_SIZES: [usize; MSHV_VP_STATE_COUNT as usize] = initialize_comp_sizes();

pub const VP_STATE_COMPONENTS_BUFFER_SIZE: usize = VP_STATE_COMP_SIZES
[MSHV_VP_STATE_LAPIC as usize]
Expand Down