mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 11:25:20 +00:00
hypervisor: kvm: Import TDX vmcall structure
Consistent with the other data structures and constants used in TDX support code import the necessary structures from the kernel for accessing the vmcall structure. Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
parent
2c9cf8d8af
commit
3993663e5c
@ -71,8 +71,6 @@ pub use x86_64::{CpuId, ExtendedControlRegisters, MsrEntries, VcpuKvmState, Xsav
|
|||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub mod aarch64;
|
pub mod aarch64;
|
||||||
pub use kvm_bindings;
|
pub use kvm_bindings;
|
||||||
#[cfg(feature = "tdx")]
|
|
||||||
use kvm_bindings::KVMIO;
|
|
||||||
pub use kvm_bindings::{
|
pub use kvm_bindings::{
|
||||||
kvm_clock_data, kvm_create_device, kvm_device_type_KVM_DEV_TYPE_VFIO, kvm_guest_debug,
|
kvm_clock_data, kvm_create_device, kvm_device_type_KVM_DEV_TYPE_VFIO, kvm_guest_debug,
|
||||||
kvm_irq_routing, kvm_irq_routing_entry, kvm_mp_state, kvm_userspace_memory_region,
|
kvm_irq_routing, kvm_irq_routing_entry, kvm_mp_state, kvm_userspace_memory_region,
|
||||||
@ -86,6 +84,8 @@ use kvm_bindings::{
|
|||||||
KVM_REG_ARM64_SYSREG_OP0_MASK, KVM_REG_ARM64_SYSREG_OP1_MASK, KVM_REG_ARM64_SYSREG_OP2_MASK,
|
KVM_REG_ARM64_SYSREG_OP0_MASK, KVM_REG_ARM64_SYSREG_OP1_MASK, KVM_REG_ARM64_SYSREG_OP2_MASK,
|
||||||
KVM_REG_ARM_CORE, KVM_REG_SIZE_U128, KVM_REG_SIZE_U32, KVM_REG_SIZE_U64,
|
KVM_REG_ARM_CORE, KVM_REG_SIZE_U128, KVM_REG_SIZE_U32, KVM_REG_SIZE_U64,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "tdx")]
|
||||||
|
use kvm_bindings::{kvm_run__bindgen_ty_1, KVMIO};
|
||||||
pub use kvm_ioctls;
|
pub use kvm_ioctls;
|
||||||
pub use kvm_ioctls::{Cap, Kvm};
|
pub use kvm_ioctls::{Cap, Kvm};
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
@ -169,6 +169,52 @@ pub struct TdxCapabilities {
|
|||||||
pub cpuid_configs: [TdxCpuidConfig; TDX_MAX_NR_CPUID_CONFIGS],
|
pub cpuid_configs: [TdxCpuidConfig; TDX_MAX_NR_CPUID_CONFIGS],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tdx")]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct KvmTdxExit {
|
||||||
|
pub type_: u32,
|
||||||
|
pub pad: u32,
|
||||||
|
pub u: KvmTdxExitU,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tdx")]
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub union KvmTdxExitU {
|
||||||
|
pub vmcall: KvmTdxExitVmcall,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "tdx")]
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Default, Copy, Clone, PartialEq)]
|
||||||
|
pub struct KvmTdxExitVmcall {
|
||||||
|
pub type_: u64,
|
||||||
|
pub subfunction: u64,
|
||||||
|
pub reg_mask: u64,
|
||||||
|
pub in_r12: u64,
|
||||||
|
pub in_r13: u64,
|
||||||
|
pub in_r14: u64,
|
||||||
|
pub in_r15: u64,
|
||||||
|
pub in_rbx: u64,
|
||||||
|
pub in_rdi: u64,
|
||||||
|
pub in_rsi: u64,
|
||||||
|
pub in_r8: u64,
|
||||||
|
pub in_r9: u64,
|
||||||
|
pub in_rdx: u64,
|
||||||
|
pub status_code: u64,
|
||||||
|
pub out_r11: u64,
|
||||||
|
pub out_r12: u64,
|
||||||
|
pub out_r13: u64,
|
||||||
|
pub out_r14: u64,
|
||||||
|
pub out_r15: u64,
|
||||||
|
pub out_rbx: u64,
|
||||||
|
pub out_rdi: u64,
|
||||||
|
pub out_rsi: u64,
|
||||||
|
pub out_r8: u64,
|
||||||
|
pub out_r9: u64,
|
||||||
|
pub out_rdx: u64,
|
||||||
|
}
|
||||||
|
|
||||||
impl From<kvm_userspace_memory_region> for UserMemoryRegion {
|
impl From<kvm_userspace_memory_region> for UserMemoryRegion {
|
||||||
fn from(region: kvm_userspace_memory_region) -> Self {
|
fn from(region: kvm_userspace_memory_region) -> Self {
|
||||||
let mut flags = USER_MEMORY_REGION_READ;
|
let mut flags = USER_MEMORY_REGION_READ;
|
||||||
@ -2139,7 +2185,12 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_tdx_exit_details(&mut self) -> cpu::Result<TdxExitDetails> {
|
fn get_tdx_exit_details(&mut self) -> cpu::Result<TdxExitDetails> {
|
||||||
let kvm_run = self.fd.get_kvm_run();
|
let kvm_run = self.fd.get_kvm_run();
|
||||||
// SAFETY: accessing a union field in a valid structure
|
// SAFETY: accessing a union field in a valid structure
|
||||||
let tdx_vmcall = unsafe { &mut kvm_run.__bindgen_anon_1.tdx.u.vmcall };
|
let tdx_vmcall = unsafe {
|
||||||
|
&mut (*((&mut kvm_run.__bindgen_anon_1) as *mut kvm_run__bindgen_ty_1
|
||||||
|
as *mut KvmTdxExit))
|
||||||
|
.u
|
||||||
|
.vmcall
|
||||||
|
};
|
||||||
|
|
||||||
tdx_vmcall.status_code = TDG_VP_VMCALL_INVALID_OPERAND;
|
tdx_vmcall.status_code = TDG_VP_VMCALL_INVALID_OPERAND;
|
||||||
|
|
||||||
@ -2163,7 +2214,12 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn set_tdx_status(&mut self, status: TdxExitStatus) {
|
fn set_tdx_status(&mut self, status: TdxExitStatus) {
|
||||||
let kvm_run = self.fd.get_kvm_run();
|
let kvm_run = self.fd.get_kvm_run();
|
||||||
// SAFETY: accessing a union field in a valid structure
|
// SAFETY: accessing a union field in a valid structure
|
||||||
let tdx_vmcall = unsafe { &mut kvm_run.__bindgen_anon_1.tdx.u.vmcall };
|
let tdx_vmcall = unsafe {
|
||||||
|
&mut (*((&mut kvm_run.__bindgen_anon_1) as *mut kvm_run__bindgen_ty_1
|
||||||
|
as *mut KvmTdxExit))
|
||||||
|
.u
|
||||||
|
.vmcall
|
||||||
|
};
|
||||||
|
|
||||||
tdx_vmcall.status_code = match status {
|
tdx_vmcall.status_code = match status {
|
||||||
TdxExitStatus::Success => TDG_VP_VMCALL_SUCCESS,
|
TdxExitStatus::Success => TDG_VP_VMCALL_SUCCESS,
|
||||||
|
Loading…
Reference in New Issue
Block a user