From: Varad Gautam <varad.gautam@suse.com> To: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: pbonzini@redhat.com, drjones@redhat.com, jroedel@suse.de, bp@suse.de, thomas.lendacky@amd.com, brijesh.singh@amd.com, varad.gautam@suse.com Subject: [kvm-unit-tests PATCH 5/6] cstart64.S: x86_64 bootstrapping after exiting EFI Date: Fri, 2 Jul 2021 13:48:19 +0200 [thread overview] Message-ID: <20210702114820.16712-6-varad.gautam@suse.com> (raw) In-Reply-To: <20210702114820.16712-1-varad.gautam@suse.com> EFI sets up long mode with arbitrary state before calling the image entrypoint. To run the testcases at hand, it is necessary to redo some of the bootstrapping to not rely on what EFI provided. Adapt start64() for EFI testcases to fixup %rsp/GDT/IDT/TSS and friends, and jump here after relocation from efi_main. Switch to RIP-relative addressing where necessary. Initially leave out: - AP init - leave EFI to single CPU - Testcase arg passing Signed-off-by: Varad Gautam <varad.gautam@suse.com> --- x86/cstart64.S | 57 ++++++++++++++++++++++++++++++++++++++++++++------ x86/efi_main.c | 1 + 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/x86/cstart64.S b/x86/cstart64.S index 98e7848..d4448c2 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -242,16 +242,17 @@ ap_start32: .code64 save_id: -#ifndef CONFIG_EFI movl $(APIC_DEFAULT_PHYS_BASE + APIC_ID), %eax movl (%rax), %eax shrl $24, %eax +#ifdef CONFIG_EFI + lock btsl %eax, online_cpus(%rip) +#else lock btsl %eax, online_cpus #endif retq ap_start64: -#ifndef CONFIG_EFI call reset_apic call load_tss call enable_apic @@ -259,12 +260,37 @@ ap_start64: call enable_x2apic sti nop +#ifdef CONFIG_EFI + lock incw cpu_online_count(%rip) +#else lock incw cpu_online_count #endif + 1: hlt jmp 1b #ifdef CONFIG_EFI +setup_gdt64: + lgdt gdt64_desc(%rip) + + setup_segments + + movabsq $flush_cs, %rax + pushq $0x8 + pushq %rax + retfq +flush_cs: + ret + +setup_idt64: + lidtq idt_descr(%rip) + ret + +setup_cr3: + movabsq $ptl4, %rax + mov %rax, %cr3 + ret + .globl _efi_pe_entry _efi_pe_entry: # EFI image loader calls this with rcx=efi_handle, @@ -276,15 +302,25 @@ _efi_pe_entry: pushq %rsi call efi_main -#endif +.globl start64 start64: -#ifndef CONFIG_EFI + cli + lea stacktop(%rip), %rsp + + setup_percpu_area + call setup_gdt64 + call setup_idt64 + call setup_cr3 +#else +start64: +#endif call reset_apic call load_tss call mask_pic_interrupts call enable_apic call save_id +#ifndef CONFIG_EFI mov mb_boot_info(%rip), %rbx mov %rbx, %rdi call setup_multiboot @@ -292,18 +328,24 @@ start64: mov mb_cmdline(%rbx), %eax mov %rax, __args(%rip) call __setup_args +#endif call ap_init call enable_x2apic call smp_init +#ifdef CONFIG_EFI + mov $0, %edi + mov $0, %rsi + mov $0, %rdx +#else mov __argc(%rip), %edi lea __argv(%rip), %rsi lea __environ(%rip), %rdx +#endif call main mov %eax, %edi call exit -#endif .globl setup_5level_page_table setup_5level_page_table: @@ -328,7 +370,10 @@ online_cpus: .fill (max_cpus + 7) / 8, 1, 0 load_tss: -#ifndef CONFIG_EFI +#ifdef CONFIG_EFI + mov $(tss_descr - gdt64), %rax + ltr %ax +#else lidtq idt_descr mov $(APIC_DEFAULT_PHYS_BASE + APIC_ID), %eax mov (%rax), %eax diff --git a/x86/efi_main.c b/x86/efi_main.c index be3f9ab..c542fb9 100644 --- a/x86/efi_main.c +++ b/x86/efi_main.c @@ -7,6 +7,7 @@ efi_system_table_t *efi_system_table = NULL; extern char ImageBase; extern char _DYNAMIC; +extern void start64(void); static void efi_free_pool(void *ptr) { -- 2.30.2
WARNING: multiple messages have this Message-ID (diff)
From: Varad Gautam via Virtualization <virtualization@lists.linux-foundation.org> To: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: thomas.lendacky@amd.com, drjones@redhat.com, jroedel@suse.de, brijesh.singh@amd.com, pbonzini@redhat.com, bp@suse.de Subject: [kvm-unit-tests PATCH 5/6] cstart64.S: x86_64 bootstrapping after exiting EFI Date: Fri, 2 Jul 2021 13:48:19 +0200 [thread overview] Message-ID: <20210702114820.16712-6-varad.gautam@suse.com> (raw) In-Reply-To: <20210702114820.16712-1-varad.gautam@suse.com> EFI sets up long mode with arbitrary state before calling the image entrypoint. To run the testcases at hand, it is necessary to redo some of the bootstrapping to not rely on what EFI provided. Adapt start64() for EFI testcases to fixup %rsp/GDT/IDT/TSS and friends, and jump here after relocation from efi_main. Switch to RIP-relative addressing where necessary. Initially leave out: - AP init - leave EFI to single CPU - Testcase arg passing Signed-off-by: Varad Gautam <varad.gautam@suse.com> --- x86/cstart64.S | 57 ++++++++++++++++++++++++++++++++++++++++++++------ x86/efi_main.c | 1 + 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/x86/cstart64.S b/x86/cstart64.S index 98e7848..d4448c2 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -242,16 +242,17 @@ ap_start32: .code64 save_id: -#ifndef CONFIG_EFI movl $(APIC_DEFAULT_PHYS_BASE + APIC_ID), %eax movl (%rax), %eax shrl $24, %eax +#ifdef CONFIG_EFI + lock btsl %eax, online_cpus(%rip) +#else lock btsl %eax, online_cpus #endif retq ap_start64: -#ifndef CONFIG_EFI call reset_apic call load_tss call enable_apic @@ -259,12 +260,37 @@ ap_start64: call enable_x2apic sti nop +#ifdef CONFIG_EFI + lock incw cpu_online_count(%rip) +#else lock incw cpu_online_count #endif + 1: hlt jmp 1b #ifdef CONFIG_EFI +setup_gdt64: + lgdt gdt64_desc(%rip) + + setup_segments + + movabsq $flush_cs, %rax + pushq $0x8 + pushq %rax + retfq +flush_cs: + ret + +setup_idt64: + lidtq idt_descr(%rip) + ret + +setup_cr3: + movabsq $ptl4, %rax + mov %rax, %cr3 + ret + .globl _efi_pe_entry _efi_pe_entry: # EFI image loader calls this with rcx=efi_handle, @@ -276,15 +302,25 @@ _efi_pe_entry: pushq %rsi call efi_main -#endif +.globl start64 start64: -#ifndef CONFIG_EFI + cli + lea stacktop(%rip), %rsp + + setup_percpu_area + call setup_gdt64 + call setup_idt64 + call setup_cr3 +#else +start64: +#endif call reset_apic call load_tss call mask_pic_interrupts call enable_apic call save_id +#ifndef CONFIG_EFI mov mb_boot_info(%rip), %rbx mov %rbx, %rdi call setup_multiboot @@ -292,18 +328,24 @@ start64: mov mb_cmdline(%rbx), %eax mov %rax, __args(%rip) call __setup_args +#endif call ap_init call enable_x2apic call smp_init +#ifdef CONFIG_EFI + mov $0, %edi + mov $0, %rsi + mov $0, %rdx +#else mov __argc(%rip), %edi lea __argv(%rip), %rsi lea __environ(%rip), %rdx +#endif call main mov %eax, %edi call exit -#endif .globl setup_5level_page_table setup_5level_page_table: @@ -328,7 +370,10 @@ online_cpus: .fill (max_cpus + 7) / 8, 1, 0 load_tss: -#ifndef CONFIG_EFI +#ifdef CONFIG_EFI + mov $(tss_descr - gdt64), %rax + ltr %ax +#else lidtq idt_descr mov $(APIC_DEFAULT_PHYS_BASE + APIC_ID), %eax mov (%rax), %eax diff --git a/x86/efi_main.c b/x86/efi_main.c index be3f9ab..c542fb9 100644 --- a/x86/efi_main.c +++ b/x86/efi_main.c @@ -7,6 +7,7 @@ efi_system_table_t *efi_system_table = NULL; extern char ImageBase; extern char _DYNAMIC; +extern void start64(void); static void efi_free_pool(void *ptr) { -- 2.30.2 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2021-07-02 11:48 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-02 11:48 [kvm-unit-tests PATCH 0/6] Initial x86_64 UEFI support Varad Gautam 2021-07-02 11:48 ` Varad Gautam via Virtualization 2021-07-02 11:48 ` [kvm-unit-tests PATCH 1/6] x86: Build tests as PE objects for the EFI loader Varad Gautam 2021-07-02 11:48 ` Varad Gautam via Virtualization 2021-07-02 11:48 ` [kvm-unit-tests PATCH 2/6] x86: Call efi_main from _efi_pe_entry Varad Gautam 2021-07-02 11:48 ` Varad Gautam via Virtualization 2021-07-02 11:48 ` [kvm-unit-tests PATCH 3/6] x86: efi_main: Get EFI memory map and exit boot services Varad Gautam 2021-07-02 11:48 ` Varad Gautam via Virtualization 2021-07-02 11:48 ` [kvm-unit-tests PATCH 4/6] x86: efi_main: Self-relocate ELF .dynamic addresses Varad Gautam 2021-07-02 11:48 ` Varad Gautam via Virtualization 2021-07-02 11:48 ` Varad Gautam [this message] 2021-07-02 11:48 ` [kvm-unit-tests PATCH 5/6] cstart64.S: x86_64 bootstrapping after exiting EFI Varad Gautam via Virtualization 2021-07-02 11:48 ` [kvm-unit-tests PATCH 6/6] x86: Disable some breaking tests for EFI and modify vmexit test Varad Gautam 2021-07-02 11:48 ` Varad Gautam via Virtualization 2021-07-12 16:29 ` [kvm-unit-tests PATCH 0/6] Initial x86_64 UEFI support Andrew Jones 2021-07-12 16:29 ` Andrew Jones 2021-08-13 18:44 ` Marc Orr 2021-08-16 7:26 ` Andrew Jones 2021-08-16 7:26 ` Andrew Jones 2021-08-17 3:41 ` Marc Orr 2021-08-17 10:49 ` Joerg Roedel 2021-08-17 10:49 ` Joerg Roedel 2021-08-18 1:52 ` Marc Orr 2021-08-18 8:38 ` Varad Gautam 2021-08-18 8:38 ` Varad Gautam via Virtualization 2021-08-19 1:32 ` Marc Orr 2021-08-19 1:42 ` Nadav Amit 2021-08-19 1:42 ` Nadav Amit 2021-08-19 1:54 ` Zixuan Wang 2021-08-19 11:36 ` Varad Gautam 2021-08-19 11:36 ` Varad Gautam via Virtualization 2021-08-20 17:29 ` Marc Orr
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210702114820.16712-6-varad.gautam@suse.com \ --to=varad.gautam@suse.com \ --cc=bp@suse.de \ --cc=brijesh.singh@amd.com \ --cc=drjones@redhat.com \ --cc=jroedel@suse.de \ --cc=kvm@vger.kernel.org \ --cc=pbonzini@redhat.com \ --cc=thomas.lendacky@amd.com \ --cc=virtualization@lists.linux-foundation.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.