diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index d9dc9b754..cb21c28e2 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -1001,7 +1001,7 @@ impl vm::Vm for KvmVm { &self.fd.as_raw_fd(), TdxCommand::InitVm, 0, - &data as *const _ as u64, + &data as *const _ as *const _, ) .map_err(vm::HypervisorVmError::InitializeTdx) } @@ -1011,8 +1011,13 @@ impl vm::Vm for KvmVm { /// #[cfg(feature = "tdx")] fn tdx_finalize(&self) -> vm::Result<()> { - tdx_command(&self.fd.as_raw_fd(), TdxCommand::Finalize, 0, 0) - .map_err(vm::HypervisorVmError::FinalizeTdx) + tdx_command( + &self.fd.as_raw_fd(), + TdxCommand::Finalize, + 0, + std::ptr::null(), + ) + .map_err(vm::HypervisorVmError::FinalizeTdx) } /// @@ -1021,9 +1026,9 @@ impl vm::Vm for KvmVm { #[cfg(feature = "tdx")] fn tdx_init_memory_region( &self, - host_address: u64, + host_address: *mut u8, guest_address: u64, - size: u64, + size: usize, measure: bool, ) -> vm::Result<()> { #[repr(C)] @@ -1033,16 +1038,16 @@ impl vm::Vm for KvmVm { pages: u64, } let data = TdxInitMemRegion { - host_address, + host_address: host_address as _, guest_address, - pages: size / 4096, + pages: (size / 4096).try_into().unwrap(), }; tdx_command( &self.fd.as_raw_fd(), TdxCommand::InitMemRegion, u32::from(measure), - &data as *const _ as u64, + &data as *const _ as *const _, ) .map_err(vm::HypervisorVmError::InitMemRegionTdx) } @@ -1058,7 +1063,7 @@ fn tdx_command( fd: &RawFd, command: TdxCommand, flags: u32, - data: u64, + data: *const libc::c_void, ) -> std::result::Result<(), std::io::Error> { #[repr(C)] struct TdxIoctlCmd { @@ -1071,7 +1076,7 @@ fn tdx_command( let cmd = TdxIoctlCmd { command, flags, - data, + data: data as _, error: 0, unused: 0, }; @@ -1287,7 +1292,7 @@ impl hypervisor::Hypervisor for KvmHypervisor { &self.kvm.as_raw_fd(), TdxCommand::Capabilities, 0, - &data as *const _ as u64, + &data as *const _ as *const _, ) .map_err(|e| hypervisor::HypervisorError::TdxCapabilities(e.into()))?; @@ -2648,6 +2653,11 @@ impl cpu::Vcpu for KvmVcpu { /// #[cfg(feature = "tdx")] fn tdx_init(&self, hob_address: u64) -> cpu::Result<()> { + // On 32-bit, the next cast would clobber the high 32 bits. + #[cfg(not(target_pointer_width = "64"))] + compile_error!("32-bit TDX not supported"); + let hob_address = hob_address as *const _; + tdx_command(&self.fd.as_raw_fd(), TdxCommand::InitVcpu, 0, hob_address) .map_err(cpu::HypervisorCpuError::InitializeTdx) } diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index 9d4bf5c3d..5e1cf7ea8 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -403,9 +403,9 @@ pub trait Vm: Send + Sync + Any { /// Initialize a TDX memory region for this VM fn tdx_init_memory_region( &self, - _host_address: u64, + _host_address: *mut u8, _guest_address: u64, - _size: u64, + _size: usize, _measure: bool, ) -> Result<()> { unimplemented!() diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 8803f68aa..24d859b14 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -2251,9 +2251,9 @@ impl Vm { for section in sections { self.vm .tdx_init_memory_region( - mem.get_host_address(GuestAddress(section.address)).unwrap() as u64, + mem.get_host_address(GuestAddress(section.address)).unwrap(), section.address, - section.size, + section.size.try_into().unwrap(), /* TDVF_SECTION_ATTRIBUTES_EXTENDMR */ section.attributes == 1, )