From 030a86db17e3c9bcfb61efb0216ca5d3e58c57cc Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 1 Mar 2021 15:13:04 +0000 Subject: [PATCH] hypervisor: mshv: simplify GVA to GPA cache So far we've only had the need to emulate one instruction. There is no need to use a HashMap when a simple tuple for the initial mapping will do. We can bring back the HashMap once more sophisticated use cases surface. No functional change. Signed-off-by: Wei Liu --- hypervisor/src/mshv/mod.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 9002352c6..3a6a4b22c 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -379,12 +379,9 @@ impl cpu::Vcpu for MshvVcpu { let mut context = MshvEmulatorContext { vcpu: self, - addr_map: HashMap::new(), + map: (info.guest_virtual_address, info.guest_physical_address), }; - // Add the GVA <-> GPA mapping. - context.add_mapping(info.guest_virtual_address, info.guest_physical_address); - // Create a new emulator. let mut emul = Emulator::new(&mut context); @@ -535,24 +532,19 @@ impl cpu::Vcpu for MshvVcpu { struct MshvEmulatorContext<'a> { vcpu: &'a MshvVcpu, - addr_map: HashMap, + map: (u64, u64), // Initial GVA to GPA mapping provided by the hypervisor } impl<'a> MshvEmulatorContext<'a> { - // Adds a gva -> gpa mapping into the TLB. - fn add_mapping(&mut self, gva: u64, gpa: u64) { - *self.addr_map.entry(gva).or_insert(gpa) = gpa; - } - // Do the actual gva -> gpa translation fn translate(&self, gva: u64) -> Result { - self.addr_map - .get(&gva) - .ok_or_else(|| PlatformError::UnmappedGVA(anyhow!("{:#?}", gva))) - .map(|v| *v) + if self.map.0 == gva { + return Ok(self.map.1); + } // TODO Check if we could fallback to e.g. an hypercall for doing // the translation for us. + todo!() } }