Skip to content

Commit

Permalink
Propagate MemoryFault exit reason in KVM_RUN
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Kalyazin <[email protected]>
  • Loading branch information
kalyazin committed Aug 1, 2024
1 parent 0fb6fb7 commit 51e30f8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ pub enum VcpuExit<'a> {
X86Rdmsr(ReadMsrExit<'a>),
/// Corresponds to KVM_EXIT_X86_WRMSR.
X86Wrmsr(WriteMsrExit<'a>),
/// Corresponds to KVM_EXIT_MEMORY_FAULT.
MemoryFault(
u64, /* flags */
u64, /* gpa */
u64, /* size */
),
/// Corresponds to an exit reason that is unknown from the current version
/// of the kvm-ioctls crate. Let the consumer decide about what to do with
/// it.
Expand Down Expand Up @@ -1568,6 +1574,17 @@ impl VcpuFd {
KVM_EXIT_HYPERV => Ok(VcpuExit::Hyperv),
r => Ok(VcpuExit::Unsupported(r)),
}
} else if ret == -1 && errno::Error::last() == errno::Error::new(libc::EFAULT) {
let run = self.kvm_run_ptr.as_mut_ref();
match run.exit_reason {
KVM_EXIT_MEMORY_FAULT => {
// SAFETY: Safe because the exit_reason (which comes from the kernel) told us
// which union field to use.
let fault = unsafe { &mut run.__bindgen_anon_1.memory_fault };
Ok(VcpuExit::MemoryFault(fault.flags, fault.gpa, fault.size))
}
_ => Err(errno::Error::last())
}
} else {
Err(errno::Error::last())
}
Expand Down

0 comments on commit 51e30f8

Please sign in to comment.