Skip to content

Commit 3a269e5

Browse files
committed
vmm: fix immediate_exit handling for PIO/MMIO code paths
To finish the emulation of PIO or MMIO code paths [0], we need to get back into KVM_RUN. In order to not lose any signal that we received, we must preserve the original `immediate_exit` flag in case it was already set by the signal handler. [0] https://elixir.bootlin.com/linux/v6.12/source/arch/x86/kvm/x86.c#L11555
1 parent 9b26f67 commit 3a269e5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

vmm/src/cpu.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,12 +1165,18 @@ impl CpuManager {
11651165

11661166
#[cfg(feature = "kvm")]
11671167
if matches!(hypervisor_type, HypervisorType::Kvm) {
1168+
let old_immediate_exit_flag = {
1169+
let kvm_run: *mut kvm_run = KVM_RUN.get();
1170+
// SAFETY: the mapping is valid
1171+
let kvm_run = unsafe { kvm_run.as_mut().unwrap() };
1172+
kvm_run.immediate_exit != 0
1173+
};
11681174
vcpu.lock().as_ref().unwrap().vcpu.set_immediate_exit(true);
11691175
if !matches!(vcpu.lock().unwrap().run(), Ok(VmExit::Ignore)) {
11701176
error!("Unexpected VM exit on \"immediate_exit\" run");
11711177
break;
11721178
}
1173-
vcpu.lock().as_ref().unwrap().vcpu.set_immediate_exit(false);
1179+
vcpu.lock().as_ref().unwrap().vcpu.set_immediate_exit(old_immediate_exit_flag);
11741180
}
11751181

11761182
vcpu_run_interrupted.store(true, Ordering::SeqCst);

0 commit comments

Comments
 (0)