From 1e967697c21d979180834a057556d5ff900aa3e6 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Tue, 6 Aug 2024 15:29:50 -0700 Subject: [PATCH] vmm: pass AccessPlatform implementation for SEV-SNP guest Passing AccessPlatform trait to virtio-device for requesting restricting page access during IO for SEV-SNP guest. Signed-off-by: Muminul Islam --- vmm/src/device_manager.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index a76d9cdc1..99ad52088 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -3741,15 +3741,22 @@ impl DeviceManager { // Create the AccessPlatform trait from the implementation IommuMapping. // This will provide address translation for any virtio device sitting // behind a vIOMMU. - let access_platform: Option> = if let Some(mapping) = iommu_mapping - { - Some(Arc::new(AccessPlatformMapping::new( + let mut access_platform: Option> = None; + + if let Some(mapping) = iommu_mapping { + access_platform = Some(Arc::new(AccessPlatformMapping::new( pci_device_bdf.into(), mapping.clone(), - ))) - } else { - None - }; + ))); + } + + // If SEV-SNP is enabled create the AccessPlatform from SevSnpPageAccessProxy + #[cfg(feature = "sev_snp")] + if self.config.lock().unwrap().is_sev_snp_enabled() { + access_platform = Some(Arc::new(SevSnpPageAccessProxy::new( + self.address_manager.vm.clone(), + ))); + } let memory = self.memory_manager.lock().unwrap().guest_memory();