mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-04 04:25:45 +00:00
hypervisor: Add translate_gva
for x86/KVM
This commit adds `translate_gva` for x86/KVM. The same name function is
already implemented for MSHV, but the implementation differs as
KVM_TRANSLATE does not take the flag argument and does not return status
code. This change requires the newer version of kvm-ioctls [1].
[1]
97ff779b6e
Signed-off-by: Akira Moroo <retrage01@gmail.com>
This commit is contained in:
parent
7c6bdf8804
commit
603ca0e21b
@ -457,7 +457,7 @@ pub trait Vcpu: Send + Sync {
|
|||||||
/// Triggers the running of the current virtual CPU returning an exit reason.
|
/// Triggers the running of the current virtual CPU returning an exit reason.
|
||||||
///
|
///
|
||||||
fn run(&self) -> std::result::Result<VmExit, HypervisorCpuError>;
|
fn run(&self) -> std::result::Result<VmExit, HypervisorCpuError>;
|
||||||
#[cfg(all(feature = "mshv", target_arch = "x86_64"))]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
/// Translate guest virtual address to guest physical address
|
/// Translate guest virtual address to guest physical address
|
||||||
///
|
///
|
||||||
|
@ -981,6 +981,24 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
.set_xcrs(xcrs)
|
.set_xcrs(xcrs)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetXcsr(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetXcsr(e.into()))
|
||||||
}
|
}
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
///
|
||||||
|
/// Translates guest virtual address to guest physical address using the `KVM_TRANSLATE` ioctl.
|
||||||
|
///
|
||||||
|
fn translate_gva(&self, gva: u64, _flags: u64) -> cpu::Result<(u64, u32)> {
|
||||||
|
let tr = self
|
||||||
|
.fd
|
||||||
|
.translate_gva(gva)
|
||||||
|
.map_err(|e| cpu::HypervisorCpuError::TranslateVirtualAddress(e.into()))?;
|
||||||
|
// tr.valid is set if the GVA is mapped to valid GPA.
|
||||||
|
match tr.valid {
|
||||||
|
0 => Err(cpu::HypervisorCpuError::TranslateVirtualAddress(anyhow!(
|
||||||
|
"Invalid GVA: {:#x}",
|
||||||
|
gva
|
||||||
|
))),
|
||||||
|
_ => Ok((tr.physical_address, 0)),
|
||||||
|
}
|
||||||
|
}
|
||||||
///
|
///
|
||||||
/// Triggers the running of the current virtual CPU returning an exit reason.
|
/// Triggers the running of the current virtual CPU returning an exit reason.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user