mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tdx: Update support based on kvm-upstream v5.19
In order to comply with latest TDX version, we rely onto the branch kvm-upstream-2022.08.07-v5.19-rc8 from https://github.com/intel/tdx repository. Updates are based on changes that happened in arch/x86/include/uapi/asm/kvm.h headers file. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
f6c058da56
commit
e4ae668bcd
@@ -106,7 +106,7 @@ pub use {
|
|||||||
const KVM_CAP_SGX_ATTRIBUTE: u32 = 196;
|
const KVM_CAP_SGX_ATTRIBUTE: u32 = 196;
|
||||||
|
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
const KVM_EXIT_TDX: u32 = 35;
|
const KVM_EXIT_TDX: u32 = 50;
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
const TDG_VP_VMCALL_GET_QUOTE: u64 = 0x10002;
|
const TDG_VP_VMCALL_GET_QUOTE: u64 = 0x10002;
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
@@ -746,36 +746,32 @@ impl vm::Vm for KvmVm {
|
|||||||
///
|
///
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
fn tdx_init(&self, cpuid: &[CpuIdEntry], max_vcpus: u32) -> vm::Result<()> {
|
fn tdx_init(&self, cpuid: &[CpuIdEntry], max_vcpus: u32) -> vm::Result<()> {
|
||||||
use std::io::{Error, ErrorKind};
|
let mut cpuid: Vec<kvm_bindings::kvm_cpuid_entry2> =
|
||||||
let cpuid: Vec<kvm_bindings::kvm_cpuid_entry2> =
|
|
||||||
cpuid.iter().map(|e| (*e).into()).collect();
|
cpuid.iter().map(|e| (*e).into()).collect();
|
||||||
let kvm_cpuid = kvm_bindings::CpuId::from_entries(&cpuid).map_err(|_| {
|
cpuid.resize(256, kvm_bindings::kvm_cpuid_entry2::default());
|
||||||
vm::HypervisorVmError::InitializeTdx(Error::new(
|
|
||||||
ErrorKind::Other,
|
|
||||||
"failed to allocate CpuId",
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct TdxInitVm {
|
struct TdxInitVm {
|
||||||
max_vcpus: u32,
|
|
||||||
tsc_khz: u32,
|
|
||||||
attributes: u64,
|
attributes: u64,
|
||||||
cpuid: u64,
|
max_vcpus: u32,
|
||||||
|
padding: u32,
|
||||||
mrconfigid: [u64; 6],
|
mrconfigid: [u64; 6],
|
||||||
mrowner: [u64; 6],
|
mrowner: [u64; 6],
|
||||||
mrownerconfig: [u64; 6],
|
mrownerconfig: [u64; 6],
|
||||||
reserved: [u64; 43],
|
cpuid_nent: u32,
|
||||||
|
cpuid_padding: u32,
|
||||||
|
cpuid_entries: [kvm_bindings::kvm_cpuid_entry2; 256],
|
||||||
}
|
}
|
||||||
let data = TdxInitVm {
|
let data = TdxInitVm {
|
||||||
max_vcpus,
|
|
||||||
tsc_khz: 0,
|
|
||||||
attributes: 0,
|
attributes: 0,
|
||||||
cpuid: kvm_cpuid.as_fam_struct_ptr() as u64,
|
max_vcpus,
|
||||||
|
padding: 0,
|
||||||
mrconfigid: [0; 6],
|
mrconfigid: [0; 6],
|
||||||
mrowner: [0; 6],
|
mrowner: [0; 6],
|
||||||
mrownerconfig: [0; 6],
|
mrownerconfig: [0; 6],
|
||||||
reserved: [0; 43],
|
cpuid_nent: cpuid.len() as u32,
|
||||||
|
cpuid_padding: 0,
|
||||||
|
cpuid_entries: cpuid.as_slice().try_into().unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
tdx_command(
|
tdx_command(
|
||||||
@@ -837,19 +833,23 @@ impl vm::Vm for KvmVm {
|
|||||||
fn tdx_command(
|
fn tdx_command(
|
||||||
fd: &RawFd,
|
fd: &RawFd,
|
||||||
command: TdxCommand,
|
command: TdxCommand,
|
||||||
metadata: u32,
|
flags: u32,
|
||||||
data: u64,
|
data: u64,
|
||||||
) -> std::result::Result<(), std::io::Error> {
|
) -> std::result::Result<(), std::io::Error> {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct TdxIoctlCmd {
|
struct TdxIoctlCmd {
|
||||||
command: TdxCommand,
|
command: TdxCommand,
|
||||||
metadata: u32,
|
flags: u32,
|
||||||
data: u64,
|
data: u64,
|
||||||
|
error: u64,
|
||||||
|
unused: u64,
|
||||||
}
|
}
|
||||||
let cmd = TdxIoctlCmd {
|
let cmd = TdxIoctlCmd {
|
||||||
command,
|
command,
|
||||||
metadata,
|
flags,
|
||||||
data,
|
data,
|
||||||
|
error: 0,
|
||||||
|
unused: 0,
|
||||||
};
|
};
|
||||||
// SAFETY: FFI call. All input parameters are valid.
|
// SAFETY: FFI call. All input parameters are valid.
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
|
|||||||
@@ -833,13 +833,11 @@ impl Vm {
|
|||||||
) -> Result<Arc<dyn hypervisor::Vm>> {
|
) -> Result<Arc<dyn hypervisor::Vm>> {
|
||||||
hypervisor.check_required_extensions().unwrap();
|
hypervisor.check_required_extensions().unwrap();
|
||||||
|
|
||||||
|
// 0 for KVM_X86_LEGACY_VM
|
||||||
|
// 1 for KVM_X86_TDX_VM
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
let vm = hypervisor
|
let vm = hypervisor
|
||||||
.create_vm_with_type(if tdx_enabled {
|
.create_vm_with_type(u64::from(tdx_enabled))
|
||||||
2 // KVM_X86_TDX_VM
|
|
||||||
} else {
|
|
||||||
0 // KVM_X86_LEGACY_VM
|
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
#[cfg(not(feature = "tdx"))]
|
#[cfg(not(feature = "tdx"))]
|
||||||
let vm = hypervisor.create_vm().unwrap();
|
let vm = hypervisor.create_vm().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user