@@ -23,6 +23,7 @@ use arraydeque::ArrayDeque;
2323use arrayvec:: ArrayVec ;
2424use core:: default:: Default ;
2525use core:: mem;
26+ use core:: pin:: Pin ;
2627use core:: sync:: atomic:: AtomicU32 ;
2728use spin:: RwLock ;
2829
@@ -92,7 +93,7 @@ pub enum VirtualMachineMsg {
9293struct VirtualMachineContext {
9394 core_id : percore:: CoreId ,
9495
95- vm : & ' static VirtualMachine ,
96+ vm : Pin < & ' static VirtualMachine > ,
9697
9798 /// The per-core RX message queue
9899 msgqueue : RwLock < ArrayDeque < [ VirtualMachineMsg ; MAX_PENDING_MSG ] > > ,
@@ -138,13 +139,13 @@ impl VirtualMachineSet {
138139 }
139140
140141 // Initialize the per-VM local apic access page
141- vm . setup_guest_local_apic_page ( ) ?;
142+ Pin :: static_ref ( vm ) . setup_guest_local_apic_page ( ) ?;
142143
143144 // Create the communication queues
144145 for cpu in vm. cpus . iter ( ) {
145146 self . contexts . push ( VirtualMachineContext {
146147 core_id : * cpu,
147- vm : vm ,
148+ vm : Pin :: static_ref ( vm ) ,
148149 msgqueue : RwLock :: new ( ArrayDeque :: new ( ) ) ,
149150 } )
150151 }
@@ -194,12 +195,15 @@ impl VirtualMachineSet {
194195 pub unsafe fn get_by_core_id (
195196 & self ,
196197 core_id : percore:: CoreId ,
197- ) -> Option < & ' static VirtualMachine > {
198+ ) -> Option < Pin < & ' static VirtualMachine > > {
198199 self . context_by_core_id ( core_id) . map ( |context| context. vm )
199200 }
200201
201202 /// Get a VirtualMachine by its vmid
202- pub fn get_by_vm_id ( & self , vmid : u32 ) -> Option < & ' static VirtualMachine > {
203+ pub fn get_by_vm_id (
204+ & self ,
205+ vmid : u32 ,
206+ ) -> Option < Pin < & ' static VirtualMachine > > {
203207 self . context_by_vm_id ( vmid) . map ( |context| context. vm )
204208 }
205209
@@ -479,7 +483,7 @@ impl VirtualMachine {
479483
480484 /// Setup the local APIC access page for the guest. This _must_ be called
481485 /// only once the VirtualMachine is in a final location.
482- pub fn setup_guest_local_apic_page ( & ' static self ) -> Result < ( ) > {
486+ pub fn setup_guest_local_apic_page ( self : Pin < & ' static Self > ) -> Result < ( ) > {
483487 // Map the guest local apic addr to the access page. This will be set in each
484488 // core's vmcs
485489 let apic_frame = memory:: HostPhysFrame :: from_start_address (
0 commit comments