Skip to content

Commit c07d874

Browse files
committed
Reorder to minimize diff
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent ee7545e commit c07d874

File tree

3 files changed

+323
-303
lines changed

3 files changed

+323
-303
lines changed

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -90,41 +90,6 @@ impl MshvVm {
9090
}
9191

9292
impl Hypervisor for MshvVm {
93-
fn regs(&self) -> Result<CommonRegisters> {
94-
Ok((&self.vcpu_fd.get_regs()?).into())
95-
}
96-
97-
fn set_regs(&self, regs: &CommonRegisters) -> Result<()> {
98-
Ok(self.vcpu_fd.set_regs(&regs.into())?)
99-
}
100-
101-
fn sregs(&self) -> Result<CommonSpecialRegisters> {
102-
Ok((&self.vcpu_fd.get_sregs()?).into())
103-
}
104-
105-
fn set_sregs(&self, sregs: &CommonSpecialRegisters) -> Result<()> {
106-
self.vcpu_fd.set_sregs(&sregs.into())?;
107-
Ok(())
108-
}
109-
110-
fn fpu(&self) -> Result<CommonFpu> {
111-
Ok((&self.vcpu_fd.get_fpu()?).into())
112-
}
113-
114-
fn set_fpu(&self, fpu: &CommonFpu) -> Result<()> {
115-
self.vcpu_fd.set_fpu(&fpu.into())?;
116-
Ok(())
117-
}
118-
119-
#[cfg(crashdump)]
120-
fn xsave(&self) -> Result<Vec<u8>> {
121-
let xsave = self.vcpu_fd.get_xsave()?;
122-
Ok(xsave.buffer.to_vec())
123-
}
124-
125-
/// # Safety
126-
/// The caller must ensure that the memory region is valid and points to valid memory,
127-
/// and lives long enough for the VM to use it.
12893
unsafe fn map_memory(&mut self, (_slot, region): (u32, &MemoryRegion)) -> Result<()> {
12994
let mshv_region: mshv_user_mem_region = region.into();
13095
self.vm_fd.map_user_memory(mshv_region)?;
@@ -209,6 +174,38 @@ impl Hypervisor for MshvVm {
209174
};
210175
Ok(result)
211176
}
177+
178+
fn regs(&self) -> Result<CommonRegisters> {
179+
Ok((&self.vcpu_fd.get_regs()?).into())
180+
}
181+
182+
fn set_regs(&self, regs: &CommonRegisters) -> Result<()> {
183+
Ok(self.vcpu_fd.set_regs(&regs.into())?)
184+
}
185+
186+
fn fpu(&self) -> Result<CommonFpu> {
187+
Ok((&self.vcpu_fd.get_fpu()?).into())
188+
}
189+
190+
fn set_fpu(&self, fpu: &CommonFpu) -> Result<()> {
191+
self.vcpu_fd.set_fpu(&fpu.into())?;
192+
Ok(())
193+
}
194+
195+
fn sregs(&self) -> Result<CommonSpecialRegisters> {
196+
Ok((&self.vcpu_fd.get_sregs()?).into())
197+
}
198+
199+
fn set_sregs(&self, sregs: &CommonSpecialRegisters) -> Result<()> {
200+
self.vcpu_fd.set_sregs(&sregs.into())?;
201+
Ok(())
202+
}
203+
204+
#[cfg(crashdump)]
205+
fn xsave(&self) -> Result<Vec<u8>> {
206+
let xsave = self.vcpu_fd.get_xsave()?;
207+
Ok(xsave.buffer.to_vec())
208+
}
212209
}
213210

214211
#[cfg(gdb)]
@@ -229,37 +226,36 @@ impl DebuggableVm for MshvVm {
229226

230227
fn set_debug(&mut self, enabled: bool) -> Result<()> {
231228
use mshv_bindings::{
232-
HV_INTERCEPT_ACCESS_MASK_EXECUTE, hv_intercept_parameters,
233-
hv_intercept_type_HV_INTERCEPT_TYPE_EXCEPTION, mshv_install_intercept,
229+
HV_INTERCEPT_ACCESS_MASK_EXECUTE, HV_INTERCEPT_ACCESS_MASK_NONE,
230+
hv_intercept_parameters, hv_intercept_type_HV_INTERCEPT_TYPE_EXCEPTION,
231+
mshv_install_intercept,
234232
};
235233

236234
use crate::hypervisor::gdb::arch::{BP_EX_ID, DB_EX_ID};
237235

238-
if enabled {
239-
self.vm_fd
240-
.install_intercept(mshv_install_intercept {
241-
access_type_mask: HV_INTERCEPT_ACCESS_MASK_EXECUTE,
242-
intercept_type: hv_intercept_type_HV_INTERCEPT_TYPE_EXCEPTION,
243-
// Exception handler #DB (1)
244-
intercept_parameter: hv_intercept_parameters {
245-
exception_vector: DB_EX_ID as u16,
246-
},
247-
})
248-
.map_err(|e| new_error!("Cannot install debug exception intercept: {}", e))?;
236+
let access_type_mask = if enabled {
237+
HV_INTERCEPT_ACCESS_MASK_EXECUTE
238+
} else {
239+
HV_INTERCEPT_ACCESS_MASK_NONE
240+
};
249241

250-
// Install intercept for #BP (3) exception
242+
for vector in [DB_EX_ID, BP_EX_ID] {
251243
self.vm_fd
252244
.install_intercept(mshv_install_intercept {
253-
access_type_mask: HV_INTERCEPT_ACCESS_MASK_EXECUTE,
245+
access_type_mask,
254246
intercept_type: hv_intercept_type_HV_INTERCEPT_TYPE_EXCEPTION,
255-
// Exception handler #BP (3)
256247
intercept_parameter: hv_intercept_parameters {
257-
exception_vector: BP_EX_ID as u16,
248+
exception_vector: vector as u16,
258249
},
259250
})
260-
.map_err(|e| new_error!("Cannot install breakpoint exception intercept: {}", e))?;
261-
} else {
262-
// There doesn't seem to be any way to remove installed intercepts. But that's okay.
251+
.map_err(|e| {
252+
new_error!(
253+
"Cannot {} exception intercept for vector {}: {}",
254+
if enabled { "install" } else { "remove" },
255+
vector,
256+
e
257+
)
258+
})?;
263259
}
264260
Ok(())
265261
}

0 commit comments

Comments
 (0)