mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
hypervisor: mhsv: Define software emulated TLB
A software emulated TLB. This is mostly used by the instruction emulator to cache gva to gpa translations passed from the hypervisor. Co-Developed-by: Nuno Das Neves <nudasnev@microsoft.com> Signed-off-by: Nuno Das Neves <nudasnev@microsoft.com> Co-Developed-by: Praveen Paladugu <prapal@microsoft.com> Signed-off-by: Praveen Paladugu <prapal@microsoft.com> Co-Developed-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Co-Developed-by: Wei Liu <liuwe@microsoft.com> Signed-off-by: Wei Liu <liuwe@microsoft.com> Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
parent
fd0ef6cfb5
commit
63f356b75b
@ -327,6 +327,46 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
// A software emulated TLB.
|
||||
// This is mostly used by the instruction emulator to cache gva to gpa translations
|
||||
// passed from the hypervisor.
|
||||
struct SoftTLB {
|
||||
addr_map: HashMap<u64, u64>,
|
||||
}
|
||||
|
||||
impl SoftTLB {
|
||||
fn new() -> SoftTLB {
|
||||
SoftTLB {
|
||||
addr_map: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a gva -> gpa mapping into the TLB.
|
||||
fn add_mapping(&mut self, gva: u64, gpa: u64) -> Result<(), PlatformError> {
|
||||
*self.addr_map.entry(gva).or_insert(gpa) = gpa;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Do the actual gva -> gpa translation
|
||||
fn translate(&self, gva: u64) -> Result<u64, PlatformError> {
|
||||
self.addr_map
|
||||
.get(&gva)
|
||||
.ok_or_else(|| PlatformError::UnmappedGVA(anyhow!("{:#?}", gva)))
|
||||
.map(|v| *v)
|
||||
|
||||
// TODO Check if we could fallback to e.g. an hypercall for doing
|
||||
// the translation for us.
|
||||
}
|
||||
|
||||
// FLush the TLB, all mappings are removed.
|
||||
fn flush(&mut self) -> Result<(), PlatformError> {
|
||||
self.addr_map.clear();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
/// Vcpu struct for Microsoft Hypervisor
|
||||
pub struct MshvVcpu {
|
||||
|
Loading…
Reference in New Issue
Block a user