hypervisor: tdx: do not use u64 to represent pointers
Also drop support for building the TDX code for 32-bit targets. All CPUs with TDX support are 64-bit so supporting 32-bit targets is not needed. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
parent
42522a88c0
commit
199d2d05d8
3 changed files with 25 additions and 15 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!()
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue