hypervisor: Add support for TDX exit reason to KVM

Relying on the recent additions to the kvm-ioctls crate, this commit
implements the support for providing the exit reason details to the
caller, which allows the identification of the type of hypercall that
was issued. It also introduces a way for the consumer to set the status
code that must be sent back to the guest.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-02-16 15:39:54 +01:00
parent a3dfe726f8
commit cb844ecd1d
2 changed files with 83 additions and 2 deletions

View File

@@ -27,6 +27,8 @@ use crate::MpState;
use crate::SuspendRegisters;
#[cfg(target_arch = "x86_64")]
use crate::Xsave;
#[cfg(feature = "tdx")]
use crate::{TdxExitDetails, TdxExitStatus};
#[cfg(feature = "mshv")]
use mshv_bindings::*;
use thiserror::Error;
@@ -240,6 +242,12 @@ pub enum HypervisorCpuError {
#[cfg(feature = "tdx")]
#[error("Failed to initialize TDX: {0}")]
InitializeTdx(#[source] std::io::Error),
///
/// Unknown TDX VM call
///
#[cfg(feature = "tdx")]
#[error("Unknown TDX VM call")]
UnknownTdxVmCall,
}
#[derive(Debug)]
@@ -256,6 +264,8 @@ pub enum VmExit<'a> {
Reset,
Shutdown,
Hyperv,
#[cfg(feature = "tdx")]
Tdx,
}
///
@@ -469,4 +479,14 @@ pub trait Vcpu: Send + Sync {
/// Set the "immediate_exit" state
///
fn set_immediate_exit(&self, exit: bool);
#[cfg(feature = "tdx")]
///
/// Returns the details about TDX exit reason
///
fn get_tdx_exit_details(&mut self) -> Result<TdxExitDetails>;
#[cfg(feature = "tdx")]
///
/// Set the status code for TDX exit
///
fn set_tdx_status(&mut self, status: TdxExitStatus);
}