From f8fbdbe7ec2b0fb91046df1120f9f8e77756a1fd Mon Sep 17 00:00:00 2001 From: lijinxia Date: Wed, 9 May 2018 10:28:17 +0000 Subject: [PATCH] Revert "HV: Make AP trampoline code relocatable" This reverts commit 31bf2befbfe459ca0a0c471f68bef6ba840d8dca. --- hypervisor/arch/x86/cpu.c | 66 +++++----------------------- hypervisor/bsp/uefi/efi/boot.c | 13 +++--- hypervisor/bsp/uefi/efi/boot.h | 1 - hypervisor/bsp/uefi/uefi.c | 7 +-- hypervisor/include/arch/x86/cpu.h | 8 +--- hypervisor/include/common/acrn_efi.h | 2 - 6 files changed, 18 insertions(+), 79 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 9d947be82..02fb4b6f4 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -39,12 +38,9 @@ #include #ifdef CONFIG_EFI_STUB -#include extern uint32_t efi_physical_available_ap_bitmap; #endif -uint64_t trampoline_code_paddr = 0; - spinlock_t cpu_secondary_spinlock = { .head = 0, .tail = 0 @@ -92,7 +88,6 @@ int cpu_find_logical_id(uint32_t lapic_id); #ifndef CONFIG_EFI_STUB static void start_cpus(void); #endif -static uint64_t relocate_trampoline_code(void); static void pcpu_sync_sleep(unsigned long *sync, int mask_bit); int ibrs_type; @@ -553,7 +548,10 @@ void bsp_boot_init(void) /* Trigger event to allow secondary CPUs to continue */ bitmap_set(0, &pcpu_sync); #else - relocate_trampoline_code(); + memcpy_s(_ld_cpu_secondary_reset_start, + (unsigned long)&_ld_cpu_secondary_reset_size, + _ld_cpu_secondary_reset_load, + (unsigned long)&_ld_cpu_secondary_reset_size); #endif ASSERT(get_cpu_id() == CPU_BOOT_ID, ""); @@ -662,9 +660,12 @@ static void start_cpus() { uint32_t timeout; uint32_t expected_up; - uint64_t startup_paddr; - startup_paddr = relocate_trampoline_code(); + /*Copy segment for AP initialization code below 1MB */ + memcpy_s(_ld_cpu_secondary_reset_start, + (unsigned long)&_ld_cpu_secondary_reset_size, + _ld_cpu_secondary_reset_load, + (unsigned long)&_ld_cpu_secondary_reset_size); /* Set flag showing number of CPUs expected to be up to all * cpus @@ -673,7 +674,7 @@ static void start_cpus() /* Broadcast IPIs to all other CPUs */ send_startup_ipi(INTR_CPU_STARTUP_ALL_EX_SELF, - -1U, startup_paddr); + -1U, ((uint64_t) cpu_secondary_reset)); /* Wait until global count is equal to expected CPU up count or * configured time-out has expired @@ -699,53 +700,6 @@ static void start_cpus() } #endif -static void update_trampoline_code_refs(uint64_t dest_pa) -{ - void *ptr; - int i; - - if (dest_pa == 0) - return; - - /* Update temporary page tables */ - ptr = HPA2HVA(dest_pa + (uint64_t)CPU_Boot_Page_Tables_ptr); - *(uint32_t *)(ptr) += dest_pa; - - ptr = HPA2HVA(dest_pa + (uint64_t)CPU_Boot_Page_Tables_Start); - *(uint64_t *)(ptr) += dest_pa; - - ptr = HPA2HVA(dest_pa + (uint64_t)cpu_secondary_pdpt_addr); - for (i = 0; i < 4; i++ ) { - *(uint64_t *)(ptr + sizeof(uint64_t) * i) += dest_pa; - } - - /* update the gdt base pointer with relocated offset */ - ptr = HPA2HVA(dest_pa + (uint64_t)cpu_secondary_gdt_ptr); - *(uint64_t *)(ptr + 2) += dest_pa; - - /* update trampoline jump pointer with relocated offset */ - ptr = HPA2HVA(dest_pa + (uint64_t)ap_long_mode_jump_ref); - *(uint32_t *)ptr += dest_pa; -} - -static uint64_t relocate_trampoline_code(void) -{ - uint64_t size, dest_pa; - - size = (uint64_t)_ld_cpu_secondary_reset_end - (uint64_t)cpu_secondary_reset; -#ifndef CONFIG_EFI_STUB - dest_pa = e820_alloc_low_memory(CONFIG_LOW_RAM_SIZE); -#else - dest_pa = (uint64_t)get_ap_trampoline_buf(); -#endif - - /* printf("AP trampoline code: %llx size %x\n", dest_pa, size); */ - memcpy_s(HPA2HVA(dest_pa), size, _ld_cpu_secondary_reset_load, size); - update_trampoline_code_refs(dest_pa); - trampoline_code_paddr = dest_pa; - return dest_pa; -} - void cpu_dead(uint32_t logical_id) { /* For debug purposes, using a stack variable in the while loop enables diff --git a/hypervisor/bsp/uefi/efi/boot.c b/hypervisor/bsp/uefi/efi/boot.c index 6baf70ce7..7a6721103 100644 --- a/hypervisor/bsp/uefi/efi/boot.c +++ b/hypervisor/bsp/uefi/efi/boot.c @@ -189,6 +189,12 @@ again: mmap[j].mm_type = E820_RAM; j++; + /* reserve secondary memory region(0x1000 ~ 0x10000) for hv */ + err = __emalloc(CONFIG_LOW_RAM_SIZE, CONFIG_LOW_RAM_START, + &addr, EfiReservedMemoryType); + if (err != EFI_SUCCESS) + goto out; + mbi->mi_flags |= MULTIBOOT_INFO_HAS_MMAP | MULTIBOOT_INFO_HAS_CMDLINE; mbi->mi_mmap_length = j*sizeof(struct multiboot_mmap); @@ -222,13 +228,6 @@ switch_to_guest_mode(EFI_HANDLE image) efi_ctx = (struct efi_ctx *)(UINTN)addr; - /* reserve secondary memory region for hv */ - err = emalloc_for_low_mem(&addr, CONFIG_LOW_RAM_SIZE); - if (err != EFI_SUCCESS) - goto out; - - efi_ctx->ap_trampoline_buf = (void *)addr; - config_table = sys_table->ConfigurationTable; for (i = 0; i < sys_table->NumberOfTableEntries; i++) { diff --git a/hypervisor/bsp/uefi/efi/boot.h b/hypervisor/bsp/uefi/efi/boot.h index bc4382dba..2968a4c84 100644 --- a/hypervisor/bsp/uefi/efi/boot.h +++ b/hypervisor/bsp/uefi/efi/boot.h @@ -96,7 +96,6 @@ struct e820_entry { struct efi_ctx { uint64_t rip; VOID *rsdp; - VOID *ap_trampoline_buf; dt_addr_t gdt; dt_addr_t idt; uint16_t tr_sel; diff --git a/hypervisor/bsp/uefi/uefi.c b/hypervisor/bsp/uefi/uefi.c index 7d95a4cae..88514f6bb 100644 --- a/hypervisor/bsp/uefi/uefi.c +++ b/hypervisor/bsp/uefi/uefi.c @@ -100,11 +100,6 @@ int sipi_from_efi_boot_service_exit(uint32_t dest, uint32_t mode, uint32_t vec) return 0; } -void *get_ap_trampoline_buf(void) -{ - return efi_ctx->ap_trampoline_buf; -} - void efi_deferred_wakeup_pcpu(int cpu_id) { uint32_t timeout; @@ -119,7 +114,7 @@ void efi_deferred_wakeup_pcpu(int cpu_id) expected_up = up_count + 1; send_startup_ipi(INTR_CPU_STARTUP_USE_DEST, - cpu_id, (uint64_t)get_ap_trampoline_buf()); + cpu_id, (uint64_t)cpu_secondary_reset); timeout = CPU_UP_TIMEOUT * 1000; diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h index 29975ff0e..dc4a41e30 100644 --- a/hypervisor/include/arch/x86/cpu.h +++ b/hypervisor/include/arch/x86/cpu.h @@ -157,17 +157,11 @@ int cpu_find_logical_id(uint32_t lapic_id); /**********************************/ extern const uint8_t _ld_cpu_secondary_reset_load[]; extern uint8_t _ld_cpu_secondary_reset_start[]; -extern uint8_t _ld_cpu_secondary_reset_end[]; extern const uint64_t _ld_cpu_secondary_reset_size; extern uint8_t _ld_bss_start[]; extern uint8_t _ld_bss_end[]; -extern uint8_t _ld_cpu_data_start[]; +extern uint8_t _ld_cpu_data_start[]; extern uint8_t _ld_cpu_data_end[]; -extern uint8_t CPU_Boot_Page_Tables_Start[]; -extern uint8_t CPU_Boot_Page_Tables_ptr[]; -extern uint8_t cpu_secondary_pdpt_addr[]; -extern uint8_t cpu_secondary_gdt_ptr[]; -extern uint8_t ap_long_mode_jump_ref[]; extern int ibrs_type; diff --git a/hypervisor/include/common/acrn_efi.h b/hypervisor/include/common/acrn_efi.h index 966445530..2a7cba451 100644 --- a/hypervisor/include/common/acrn_efi.h +++ b/hypervisor/include/common/acrn_efi.h @@ -39,7 +39,6 @@ typedef struct { struct efi_ctx { uint64_t rip; void *rsdp; - void *ap_trampoline_buf; dt_addr_t gdt; dt_addr_t idt; uint16_t tr_sel; @@ -75,6 +74,5 @@ struct efi_ctx { }__attribute__((packed)); void *get_rsdp_from_uefi(void); -void *get_ap_trampoline_buf(void); #endif /* UEFI_H*/