From: Peter Dinda Date: Tue, 3 Aug 2010 18:03:13 +0000 (-0500) Subject: Now correctly boots 2, 4, 8 core kitten X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=d25220596e7ceb6b06a4b715f722a47afd8b48bb;p=palacios.git Now correctly boots 2, 4, 8 core kitten Fixed issue with memory region search on even number of cores (>2) Cleaning up debugging output throughout Added CONFIG_DEBUG_VMX and CONFIG_DEBUG_SVM --- diff --git a/Kconfig b/Kconfig index c94fcb0..5c851ce 100644 --- a/Kconfig +++ b/Kconfig @@ -259,6 +259,21 @@ config DEBUG_ON This turns on debugging support +config DEBUG_SVM + bool "AMD SVM" + default n + depends on DEBUG_ON + help + This turns on debugging for the AMD SVM-specific code + +config DEBUG_VMX + bool "Intel VT" + default n + depends on DEBUG_ON + help + This turns on debugging for the Intel VT-specific code + + config DEBUG_SHADOW_PAGING bool "Shadow paging" default n diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index af388e3..b13f462 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -106,8 +106,9 @@ struct guest_info { struct v3_vm_info * vm_info; - // the logical cpu this guest context is executing on - int cpu_id; + + // the logical cpu on which this core runs + uint32_t cpu_id; }; diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 73bee31..ad684f1 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -917,7 +917,7 @@ static int apic_intr_pending(struct guest_info * info, void * private_data) { int req_irq = get_highest_irr(apic); int svc_irq = get_highest_isr(apic); - PrintDebug("apic %u: core %u: req_irq=%d, svc_irq=%d\n",apic->lapic_id.val,info->cpu_id,req_irq,svc_irq); + // PrintDebug("apic %u: core %u: req_irq=%d, svc_irq=%d\n",apic->lapic_id.val,info->cpu_id,req_irq,svc_irq); if ((req_irq >= 0) && (req_irq > svc_irq)) { diff --git a/palacios/src/palacios/svm.c b/palacios/src/palacios/svm.c index 4e362b5..34fed45 100644 --- a/palacios/src/palacios/svm.c +++ b/palacios/src/palacios/svm.c @@ -478,13 +478,6 @@ int v3_svm_enter(struct guest_info * info) { //V3_Print("Calling v3_svm_launch\n"); -#if 0 - if (info->cpu_id==1) { - V3_Print("Entering Core 1\n"); - v3_print_guest_state(info); - } -#endif - v3_svm_launch((vmcb_t *)V3_PAddr(info->vmm_data), &(info->vm_regs), (vmcb_t *)host_vmcbs[info->cpu_id]); //V3_Print("SVM Returned: Exit Code: %x, guest_rip=%lx\n", (uint32_t)(guest_ctrl->exit_code), (unsigned long)guest_state->rip); @@ -549,31 +542,12 @@ int v3_svm_enter(struct guest_info * info) { -#if 0 - if (info->cpu_id==1) { - V3_Print("Exited Core 1, before handler\n"); - v3_print_guest_state(info); - PrintDebugVMCB((vmcb_t*)(info->vmm_data)); - } -#endif - - if (v3_handle_svm_exit(info, exit_code, exit_info1, exit_info2) != 0) { PrintError("Error in SVM exit handler\n"); return -1; } -#if 0 - if (info->cpu_id==1) { - V3_Print("Exited Core 1, after handler\n"); - v3_print_guest_state(info); - PrintDebugVMCB((vmcb_t*)(info->vmm_data)); - } -#endif - - - return 0; } diff --git a/palacios/src/palacios/svm_handler.c b/palacios/src/palacios/svm_handler.c index 9088af3..d8b47c5 100644 --- a/palacios/src/palacios/svm_handler.c +++ b/palacios/src/palacios/svm_handler.c @@ -34,6 +34,10 @@ #include #include +#ifndef CONFIG_DEBUG_SVM +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif #ifdef CONFIG_TELEMETRY #include @@ -50,11 +54,6 @@ int v3_handle_svm_exit(struct guest_info * info, addr_t exit_code, addr_t exit_i #endif -#if 0 - if (info->cpu_id==1) { - V3_Print("Core 1 SVM Exit: %s rip=0x%p\n", vmexit_code_to_str(exit_code), (void *) get_addr_linear(info, info->rip, &(info->segments.cs))); - } -#endif //PrintDebug("SVM Returned: Exit Code: %x\n",exit_code); switch (exit_code) { @@ -170,12 +169,6 @@ int v3_handle_svm_exit(struct guest_info * info, addr_t exit_code, addr_t exit_i PrintDebug("PageFault at %p (error=%d)\n", (void *)fault_addr, *(uint_t *)error_code); #endif -#if 0 - if (info->cpu_id==1) { - V3_Print("SVM Core 1: PageFault at %p (error=%d)\n", - (void *)fault_addr, *(uint_t *)error_code); - } -#endif if (info->shdw_pg_mode == SHADOW_PAGING) { if (v3_handle_shadow_pagefault(info, fault_addr, *error_code) == -1) { return -1; diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index dae7d34..8e45d5b 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -63,7 +63,7 @@ static void init_cpu(void * arg) { } else #endif { - PrintError("CPU has no virtualization Extensions\n"); + PrintError("CPU has no virtualizationExtensions\n"); } } @@ -156,7 +156,7 @@ static int start_core(void *p) break; #endif default: - PrintError("Attemping to enter a guest on an invalid CPU\n"); + PrintError("Attempting to enter a guest on an invalid CPU\n"); return -1; } // should not happen @@ -203,6 +203,9 @@ int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) { proc_to_use=get_next_core(cpu_mask,last_proc); last_proc=proc_to_use; + // vm->cores[i].cpu_id=i; + // vm->cores[i].physical_cpu_id=proc_to_use; + PrintDebug("Starting virtual core %u on logical core %u\n",i,proc_to_use); sprintf(tname,"core%u",i); @@ -217,6 +220,9 @@ int v3_start_vm(struct v3_vm_info * vm, unsigned int cpu_mask) { } } + // vm->cores[0].cpu_id=0; + // vm->cores[0].physical_cpu_id=0; + // Finally launch the BSP on core 0 sprintf(tname,"core%u",0); if (!os_hooks->start_thread_on_cpu(0,start_core,&(vm->cores[0]),tname)) { diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index 42a53ac..80e17a3 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -176,7 +176,7 @@ struct v3_mem_region * __insert_mem_region(struct v3_vm_info * vm, return tmp_region; } else if (region->core_id < tmp_region->core_id) { p = &(*p)->rb_left; - } else { + } else { p = &(*p)->rb_right; } } @@ -246,6 +246,7 @@ struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_i struct v3_mem_region * reg = NULL; while (n) { + reg = rb_entry(n, struct v3_mem_region, tree_node); if (guest_addr < reg->guest_start) { @@ -253,11 +254,21 @@ struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_i } else if (guest_addr >= reg->guest_end) { n = n->rb_right; } else { - if ((core_id == reg->core_id) || - (reg->core_id == V3_MEM_CORE_ANY)) { - return reg; - } else { + if (reg->core_id == V3_MEM_CORE_ANY) { + // found relevant region, it's available on all cores + return reg; + } else if (core_id==reg->core_id) { + // found relevant region, it's available on the indicated core + return reg; + } else if (core_id < reg->core_id) { + // go left, core too big + n = n->rb_left; + } else if (core_id > reg->core_id) { + // go right, core too small n = n->rb_right; + } else { + PrintDebug("v3_get_mem_region: Impossible!\n"); + return NULL; } } } @@ -266,13 +277,14 @@ struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_i // There is not registered region, so we check if its a valid address in the base region if (guest_addr > vm->mem_map.base_region.guest_end) { - PrintError("Guest Address Exceeds Base Memory Size (ga=%p), (limit=%p)\n", - (void *)guest_addr, (void *)vm->mem_map.base_region.guest_end); + PrintError("Guest Address Exceeds Base Memory Size (ga=0x%p), (limit=0x%p) (core=0x%x)\n", + (void *)guest_addr, (void *)vm->mem_map.base_region.guest_end, core_id); v3_print_mem_map(vm); return NULL; } + return &(vm->mem_map.base_region); } @@ -335,10 +347,10 @@ void v3_print_mem_map(struct v3_vm_info * vm) { struct v3_mem_region * reg = &(vm->mem_map.base_region); int i = 0; - V3_Print("Memory Layout:\n"); + V3_Print("Memory Layout (all cores):\n"); - V3_Print("Base Region: 0x%p - 0x%p -> 0x%p\n", + V3_Print("Base Region (all cores): 0x%p - 0x%p -> 0x%p\n", (void *)(reg->guest_start), (void *)(reg->guest_end - 1), (void *)(reg->host_addr)); @@ -357,9 +369,10 @@ void v3_print_mem_map(struct v3_vm_info * vm) { (void *)(reg->guest_end - 1), (void *)(reg->host_addr)); - V3_Print("\t(flags=%x) (unhandled = 0x%p)\n", - reg->flags.value, - reg->unhandled); + V3_Print("\t(flags=0x%x) (core=0x%x) (unhandled = 0x%p)\n", + reg->flags.value, + reg->core_id, + reg->unhandled); i++; } while ((node = v3_rb_next(node))); diff --git a/palacios/src/palacios/vmm_mptable.c b/palacios/src/palacios/vmm_mptable.c index 578beed..2d02540 100644 --- a/palacios/src/palacios/vmm_mptable.c +++ b/palacios/src/palacios/vmm_mptable.c @@ -219,7 +219,6 @@ static int check_table(void *target) uint8_t sum; struct mp_table_header *header; - V3_Print("Checksuming mptable header and entries at %p\n",target); header=(struct mp_table_header *)target; sum=0; @@ -227,10 +226,9 @@ static int check_table(void *target) sum+=((uint8_t *)target)[i]; } if (sum==0) { - V3_Print("Checksum passed\n"); return 1; } else { - V3_Print("Checksum FAILED\n"); + // failed checksum return 0; } } @@ -242,18 +240,16 @@ static int check_pointer(void *target) uint8_t sum; struct mp_floating_pointer *p; - V3_Print("Checksuming mptable floating pointer at %p\n",target); - p=(struct mp_floating_pointer *)target; sum=0; for (i=0;ilength*16;i++) { sum+=((uint8_t *)target)[i]; } if (sum==0) { - V3_Print("Checksum passed\n"); + // passed return 1; } else { - V3_Print("Checksum FAILED\n"); + // failed return 0; } } @@ -281,8 +277,6 @@ static int write_pointer(void *target, uint32_t mptable_gpa) } p->checksum=(255-sum)+1; - V3_Print("MP Floating Pointer written to %p\n",target); - return 0; } @@ -405,7 +399,7 @@ int v3_inject_mptable(struct v3_vm_info *vm) return -1; } - V3_Print("Starting mptable pointer, header, and entry construction for %u cores at %p\n",vm->num_cores,target); + V3_Print("Constructing mptable for %u cores at %p\n",vm->num_cores,target); if (-1==write_pointer(target,BIOS_MP_TABLE_DEFAULT_LOCATION+sizeof(struct mp_floating_pointer))) { PrintError("Unable to write mptable floating pointer, aborting.\n"); @@ -427,7 +421,6 @@ int v3_inject_mptable(struct v3_vm_info *vm) return -1; } - V3_Print("Done with mptable pointer, header, and entry construction\n"); return 0; diff --git a/palacios/src/palacios/vmx.c b/palacios/src/palacios/vmx.c index b9f99bd..18d183b 100644 --- a/palacios/src/palacios/vmx.c +++ b/palacios/src/palacios/vmx.c @@ -33,6 +33,13 @@ #include #include + +#ifndef CONFIG_DEBUG_VMX +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + + static addr_t host_vmcs_ptrs[CONFIG_MAX_CPUS] = { [0 ... CONFIG_MAX_CPUS - 1] = 0}; diff --git a/palacios/src/palacios/vmx_handler.c b/palacios/src/palacios/vmx_handler.c index 91b5604..d88210d 100644 --- a/palacios/src/palacios/vmx_handler.c +++ b/palacios/src/palacios/vmx_handler.c @@ -32,6 +32,11 @@ #include #include +#ifndef CONFIG_DEBUG_VMX +#undef PrintDebug +#define PrintDebug(fmt, args...) +#endif + #ifdef CONFIG_TELEMETRY #include #endif