Skip to content

Commit 538702b

Browse files
committed
fix(test): dont drop guest memory before using it
Dropping a GuestMemoryMmap causes the memory to get unmapped, so if we try to KVM_RUN after dropping it, we'll just get EFAULT. Admittedly no idea how we didn't run into this issue before. Signed-off-by: Patrick Roy <[email protected]>
1 parent 76d9095 commit 538702b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/vmm/src/vstate/vcpu/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ pub(crate) mod tests {
969969
entry_addr.unwrap().kernel_load
970970
}
971971

972-
fn vcpu_configured_for_boot() -> (VcpuHandle, vmm_sys_util::eventfd::EventFd) {
972+
fn vcpu_configured_for_boot() -> (VcpuHandle, EventFd, GuestMemoryMmap) {
973973
Vcpu::register_kick_signal_handler();
974974
// Need enough mem to boot linux.
975975
let mem_size = 64 << 20;
@@ -1021,7 +1021,7 @@ pub(crate) mod tests {
10211021
// Wait for vCPUs to initialize their TLS before moving forward.
10221022
barrier.wait();
10231023

1024-
(vcpu_handle, vcpu_exit_evt)
1024+
(vcpu_handle, vcpu_exit_evt, vm_mem)
10251025
}
10261026

10271027
#[test]
@@ -1034,7 +1034,7 @@ pub(crate) mod tests {
10341034

10351035
#[test]
10361036
fn test_vcpu_tls() {
1037-
let (_, _, mut vcpu, _) = setup_vcpu(0x1000);
1037+
let (_, _, mut vcpu, _mem) = setup_vcpu(0x1000);
10381038

10391039
// Running on the TLS vcpu should fail before we actually initialize it.
10401040
unsafe {
@@ -1075,7 +1075,7 @@ pub(crate) mod tests {
10751075
#[test]
10761076
fn test_vcpu_kick() {
10771077
Vcpu::register_kick_signal_handler();
1078-
let (_, vm, mut vcpu, _) = setup_vcpu(0x1000);
1078+
let (_, vm, mut vcpu, _mem) = setup_vcpu(0x1000);
10791079

10801080
let mut kvm_run =
10811081
kvm_ioctls::KvmRunWrapper::mmap_from_fd(&vcpu.kvm_vcpu.fd, vm.fd().run_size())
@@ -1130,7 +1130,7 @@ pub(crate) mod tests {
11301130

11311131
#[test]
11321132
fn test_immediate_exit_shortcircuits_execution() {
1133-
let (_, _, mut vcpu, _) = setup_vcpu(0x1000);
1133+
let (_, _, mut vcpu, _mem) = setup_vcpu(0x1000);
11341134

11351135
vcpu.kvm_vcpu.fd.set_kvm_immediate_exit(1);
11361136
// Set a dummy value to be returned by the emulate call
@@ -1155,7 +1155,7 @@ pub(crate) mod tests {
11551155

11561156
#[test]
11571157
fn test_vcpu_pause_resume() {
1158-
let (vcpu_handle, vcpu_exit_evt) = vcpu_configured_for_boot();
1158+
let (vcpu_handle, vcpu_exit_evt, _mem) = vcpu_configured_for_boot();
11591159

11601160
// Queue a Resume event, expect a response.
11611161
queue_event_expect_response(&vcpu_handle, VcpuEvent::Resume, VcpuResponse::Resumed);
@@ -1187,7 +1187,7 @@ pub(crate) mod tests {
11871187

11881188
#[test]
11891189
fn test_vcpu_save_state_events() {
1190-
let (vcpu_handle, _vcpu_exit_evt) = vcpu_configured_for_boot();
1190+
let (vcpu_handle, _vcpu_exit_evt, _mem) = vcpu_configured_for_boot();
11911191

11921192
// Queue a Resume event, expect a response.
11931193
queue_event_expect_response(&vcpu_handle, VcpuEvent::Resume, VcpuResponse::Resumed);
@@ -1220,7 +1220,7 @@ pub(crate) mod tests {
12201220

12211221
#[test]
12221222
fn test_vcpu_dump_cpu_config() {
1223-
let (vcpu_handle, _) = vcpu_configured_for_boot();
1223+
let (vcpu_handle, _, _mem) = vcpu_configured_for_boot();
12241224

12251225
// Queue a DumpCpuConfig event, expect a DumpedCpuConfig response.
12261226
vcpu_handle

0 commit comments

Comments
 (0)