@@ -30,6 +30,7 @@ use crate::vmm_config::drive::{BlockDeviceConfig, BlockDeviceUpdateConfig, Drive
3030use crate :: vmm_config:: entropy:: { EntropyDeviceConfig , EntropyDeviceError } ;
3131use crate :: vmm_config:: instance_info:: InstanceInfo ;
3232use crate :: vmm_config:: machine_config:: { MachineConfig , MachineConfigError , MachineConfigUpdate } ;
33+ use crate :: vmm_config:: meminfo:: MemoryMapingsResponse ;
3334use crate :: vmm_config:: memory_hotplug:: {
3435 MemoryHotplugConfig , MemoryHotplugConfigError , MemoryHotplugSizeUpdate ,
3536} ;
@@ -146,6 +147,8 @@ pub enum VmmAction {
146147 /// Update the microVM configuration (memory & vcpu) using `VmUpdateConfig` as input. This
147148 /// action can only be called before the microVM has booted.
148149 UpdateMachineConfiguration ( MachineConfigUpdate ) ,
150+ /// Get the guest memory mappings to host memory
151+ GetMemoryMappings ,
149152}
150153
151154/// Wrapper for all errors associated with VMM actions.
@@ -228,6 +231,8 @@ pub enum VmmData {
228231 VirtioMemStatus ( VirtioMemStatus ) ,
229232 /// The status of the virtio-balloon hinting run
230233 HintingStatus ( HintingStatus ) ,
234+ /// The guest memory mapping information.
235+ MemoryMappings ( MemoryMapingsResponse ) ,
231236}
232237
233238/// Trait used for deduplicating the MMDS request handling across the two ApiControllers.
@@ -495,7 +500,8 @@ impl<'a> PrebootApiController<'a> {
495500 | UpdateNetworkInterface ( _)
496501 | StartFreePageHinting ( _)
497502 | GetFreePageHintingStatus
498- | StopFreePageHinting => Err ( VmmActionError :: OperationNotSupportedPreBoot ) ,
503+ | StopFreePageHinting
504+ | GetMemoryMappings => Err ( VmmActionError :: OperationNotSupportedPreBoot ) ,
499505 #[ cfg( target_arch = "x86_64" ) ]
500506 SendCtrlAltDel => Err ( VmmActionError :: OperationNotSupportedPreBoot ) ,
501507 }
@@ -771,6 +777,7 @@ impl RuntimeApiController {
771777 . update_memory_hotplug_size ( cfg. requested_size_mib )
772778 . map ( |_| VmmData :: Empty )
773779 . map_err ( VmmActionError :: MemoryHotplugUpdate ) ,
780+ GetMemoryMappings => self . get_guest_memory_mappings ( ) ,
774781 // Operations not allowed post-boot.
775782 ConfigureBootSource ( _)
776783 | ConfigureLogger ( _)
@@ -937,6 +944,14 @@ impl RuntimeApiController {
937944 . map_err ( NetworkInterfaceError :: DeviceUpdate )
938945 . map_err ( VmmActionError :: NetworkConfig )
939946 }
947+
948+ /// Get guest memory mappings
949+ fn get_guest_memory_mappings ( & self ) -> Result < VmmData , VmmActionError > {
950+ let vmm = self . vmm . lock ( ) . expect ( "Poisoned lock" ) ;
951+ let page_size = self . vm_resources . machine_config . huge_pages . page_size ( ) ;
952+ let mappings = vmm. guest_memory_mappings ( page_size) ;
953+ Ok ( VmmData :: MemoryMappings ( MemoryMapingsResponse { mappings } ) )
954+ }
940955}
941956
942957#[ cfg( test) ]
0 commit comments