| 1314 | /// |
| 1315 | #[cfg(feature = "tdx")] |
| 1316 | fn tdx_init(&self, cpuid: &[CpuIdEntry], max_vcpus: u32) -> vm::Result<()> { |
| 1317 | const TDX_ATTR_SEPT_VE_DISABLE: usize = 28; |
| 1318 | |
| 1319 | let mut cpuid: Vec<kvm_bindings::kvm_cpuid_entry2> = |
| 1320 | cpuid.iter().map(|e| (*e).into()).collect(); |
| 1321 | cpuid.resize(256, kvm_bindings::kvm_cpuid_entry2::default()); |
| 1322 | |
| 1323 | #[repr(C)] |
| 1324 | struct TdxInitVm { |
| 1325 | attributes: u64, |
| 1326 | max_vcpus: u32, |
| 1327 | padding: u32, |
| 1328 | mrconfigid: [u64; 6], |
| 1329 | mrowner: [u64; 6], |
| 1330 | mrownerconfig: [u64; 6], |
| 1331 | cpuid_nent: u32, |
| 1332 | cpuid_padding: u32, |
| 1333 | cpuid_entries: [kvm_bindings::kvm_cpuid_entry2; 256], |
| 1334 | } |
| 1335 | let data = TdxInitVm { |
| 1336 | attributes: 1 << TDX_ATTR_SEPT_VE_DISABLE, |
| 1337 | max_vcpus, |
| 1338 | padding: 0, |
| 1339 | mrconfigid: [0; 6], |
| 1340 | mrowner: [0; 6], |
| 1341 | mrownerconfig: [0; 6], |
| 1342 | cpuid_nent: cpuid.len() as u32, |
| 1343 | cpuid_padding: 0, |
| 1344 | cpuid_entries: cpuid.as_slice().try_into().unwrap(), |
| 1345 | }; |
| 1346 | |
| 1347 | tdx_command( |
| 1348 | &self.fd.as_raw_fd(), |
| 1349 | TdxCommand::InitVm, |
| 1350 | 0, |
| 1351 | (&raw const data).cast(), |
| 1352 | ) |
| 1353 | .map_err(vm::HypervisorVmError::InitializeTdx) |
| 1354 | } |
| 1355 | |
| 1356 | /// |
| 1357 | /// Finalize the TDX setup for this VM |