File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -270,13 +270,19 @@ unsafe fn kmain(mut boot_info: BootInfo) -> ! {
270270
271271 debug ! ( "AP_STARTUP address: 0x{:x}" , AP_STARTUP_ADDR ) ;
272272
273- //TODO(alschwalm): Only the cores that are actually associated with a VM
274- // should be started
275273 for ( idx, apic_id) in apic_ids. into_iter ( ) . enumerate ( ) {
276274 if apic_id == local_apic. id ( ) {
277275 continue ;
278276 }
279277
278+ let core_id = percore:: CoreId :: from ( idx as u32 ) ;
279+
280+ // Do not setup cores that are not allocated to any guest
281+ if !vm:: is_assigned_core_id ( core_id) {
282+ debug ! ( "Not starting core ID '{}' because it is not assigned to a guest" , core_id) ;
283+ continue ;
284+ }
285+
280286 // Allocate a stack for the AP
281287 let stack = vec ! [ 0u8 ; 100 * 1024 ] ;
282288
@@ -289,7 +295,7 @@ unsafe fn kmain(mut boot_info: BootInfo) -> ! {
289295 core:: ptr:: write_volatile ( & mut AP_STACK_ADDR as * mut u64 , stack_bottom) ;
290296
291297 // Map the APIC ids to a sequential list and pass it to the AP
292- core:: ptr:: write_volatile ( & mut AP_IDX as * mut u64 , idx as u64 ) ;
298+ core:: ptr:: write_volatile ( & mut AP_IDX as * mut u64 , core_id . raw as u64 ) ;
293299
294300 // mfence to ensure that the APs see the new stack address
295301 core:: sync:: atomic:: fence ( core:: sync:: atomic:: Ordering :: SeqCst ) ;
Original file line number Diff line number Diff line change @@ -34,11 +34,16 @@ pub fn mp_entry_point() -> ! {
3434 . expect ( "Failed to initialize per-core timer wheel" ) ;
3535 }
3636
37+ let core_id = percore:: read_core_id ( ) ;
3738 let vm = unsafe {
38- let core_id = percore:: read_core_id ( ) ;
3939 vm:: get_vm_for_core_id ( core_id)
4040 . expect ( & format ! ( "Failed to find VM associated with {}" , core_id) )
4141 } ;
42+ debug ! (
43+ "Starting core ID '{}' as part of vm id '{}'" ,
44+ core_id,
45+ vm. read( ) . id
46+ ) ;
4247
4348 let vcpu = VCpu :: new ( vm) . expect ( "Failed to create vcpu" ) ;
4449 vcpu. launch ( ) . expect ( "Failed to launch vm" )
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ pub fn max_vm_id() -> u32 {
7171 VIRTUAL_MACHINES . count ( )
7272}
7373
74+ pub fn is_assigned_core_id ( core_id : percore:: CoreId ) -> bool {
75+ VIRTUAL_MACHINES . is_assigned_core_id ( core_id)
76+ }
77+
7478const MAX_PENDING_MSG : usize = 100 ;
7579
7680pub enum VirtualMachineMsg {
@@ -113,6 +117,10 @@ impl VirtualMachines {
113117 self . machine_count
114118 }
115119
120+ pub fn is_assigned_core_id ( & self , core_id : percore:: CoreId ) -> bool {
121+ self . map . contains_key ( & core_id)
122+ }
123+
116124 pub fn get_by_core_id (
117125 & self ,
118126 core_id : percore:: CoreId ,
You can’t perform that action at this time.
0 commit comments