Skip to content

Commit 59cae55

Browse files
committed
skipped unnecessary kvm_immediate_exits
Skipped switches in the presence of run_emulation and VcpuEvent::Resume Signed-off-by: Matias Teragni <mteragni@amazon.com>
1 parent 256e402 commit 59cae55

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{fmt, io, thread};
1616
use kvm_bindings::{KVM_SYSTEM_EVENT_RESET, KVM_SYSTEM_EVENT_SHUTDOWN};
1717
use kvm_ioctls::VcpuExit;
1818
use libc::{c_int, c_void, siginfo_t};
19-
use log::{error, info};
19+
use log::{error, info, warn};
2020
use seccompiler::{BpfProgram, BpfProgramRef};
2121
use utils::errno;
2222
use utils::eventfd::EventFd;
@@ -341,6 +341,13 @@ impl Vcpu {
341341
match self.event_receiver.recv() {
342342
// Paused ---- Resume ----> Running
343343
Ok(VcpuEvent::Resume) => {
344+
if self.kvm_vcpu.fd.get_kvm_run().immediate_exit == 1u8 {
345+
warn!(
346+
"Received a VcpuEvent::Resume message with immediate_exit enabled. \
347+
immediate_exit was disabled before proceeding"
348+
);
349+
self.kvm_vcpu.fd.set_kvm_immediate_exit(0);
350+
}
344351
// Nothing special to do.
345352
self.response_sender
346353
.send(VcpuResponse::Resumed)
@@ -445,7 +452,12 @@ impl Vcpu {
445452
/// Runs the vCPU in KVM context and handles the kvm exit reason.
446453
///
447454
/// Returns error or enum specifying whether emulation was handled or interrupted.
448-
pub fn run_emulation(&self) -> Result<VcpuEmulation, VcpuError> {
455+
pub fn run_emulation(&mut self) -> Result<VcpuEmulation, VcpuError> {
456+
if self.kvm_vcpu.fd.get_kvm_run().immediate_exit == 1u8 {
457+
warn!("Requested a vCPU run with immediate_exit enabled. The operation was skipped");
458+
self.kvm_vcpu.fd.set_kvm_immediate_exit(0);
459+
return Ok(VcpuEmulation::Interrupted);
460+
}
449461
match self.emulate() {
450462
Ok(run) => match run {
451463
VcpuExit::MmioRead(addr, data) => {

0 commit comments

Comments
 (0)