Skip to content

Commit f3831cd

Browse files
fyin1lijinxia
authored andcommitted
hv: don't combine the trampline code with AP start
Cleanup "cpu_secondary_xx" in the symbols/section/functions/variables name in trampline code. There is item left: the default C entry is Ap start c entry. Before ACRN enter S3, the c entry will be updated to high level S3 C entry. So s3 resume will go s3 resume path instead of AP startup path. Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Signed-off-by: Zheng Gen <gen.zheng@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
1 parent 11df803 commit f3831cd

File tree

5 files changed

+50
-49
lines changed

5 files changed

+50
-49
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <schedule.h>
99
#include <version.h>
1010

11-
spinlock_t cpu_secondary_spinlock = {
11+
spinlock_t trampline_spinlock = {
1212
.head = 0,
1313
.tail = 0
1414
};
@@ -574,7 +574,7 @@ void cpu_secondary_init(void)
574574
/* Release secondary boot spin-lock to allow one of the next CPU(s) to
575575
* perform this common initialization
576576
*/
577-
spinlock_release(&cpu_secondary_spinlock);
577+
spinlock_release(&trampline_spinlock);
578578

579579
/* Initialize secondary processor interrupts. */
580580
interrupt_init(get_cpu_id());
@@ -615,10 +615,10 @@ void start_cpus()
615615
uint32_t expected_up;
616616

617617
/*Copy segment for AP initialization code below 1MB */
618-
memcpy_s(_ld_cpu_secondary_reset_start,
619-
(unsigned long)&_ld_cpu_secondary_reset_size,
620-
_ld_cpu_secondary_reset_load,
621-
(unsigned long)&_ld_cpu_secondary_reset_size);
618+
memcpy_s(_ld_trampline_start,
619+
(unsigned long)&_ld_trampline_size,
620+
_ld_trampline_load,
621+
(unsigned long)&_ld_trampline_size);
622622

623623
/* Set flag showing number of CPUs expected to be up to all
624624
* cpus
@@ -627,7 +627,7 @@ void start_cpus()
627627

628628
/* Broadcast IPIs to all other CPUs */
629629
send_startup_ipi(INTR_CPU_STARTUP_ALL_EX_SELF,
630-
-1U, ((uint64_t) cpu_secondary_reset));
630+
-1U, ((uint64_t) trampline_start16));
631631

632632
/* Wait until global count is equal to expected CPU up count or
633633
* configured time-out has expired

hypervisor/arch/x86/guest/guest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,10 @@ int prepare_vm0_memmap_and_e820(struct vm *vm)
573573
* FIXME: here using hard code GUEST_INIT_PAGE_TABLE_START as guest init page
574574
* table gpa start, and it will occupy at most GUEST_INIT_PT_PAGE_NUM pages.
575575
* Some check here:
576-
* - guest page table space should not override cpu_secondary_reset code area
576+
* - guest page table space should not override trampline code area
577577
* (it's a little tricky here, as under current identical mapping, HV & SOS
578578
* share same memory under 1M; under uefi boot mode, the defered AP startup
579-
* need cpu_secondary_reset code area which reserved by uefi stub keep there
579+
* need trampline code area which reserved by uefi stub keep there
580580
* no change even after SOS startup)
581581
* - guest page table space should not override possible RSDP fix segment
582582
*
@@ -604,8 +604,8 @@ uint64_t create_guest_initial_paging(struct vm *vm)
604604
RSDP_F_ADDR, "RSDP fix segment could be override");
605605

606606
if (GUEST_INIT_PAGE_TABLE_SKIP_SIZE <
607-
(unsigned long)&_ld_cpu_secondary_reset_size) {
608-
panic("guest init PTs override cpu_secondary_reset code");
607+
(unsigned long)&_ld_trampline_size) {
608+
panic("guest init PTs override trampline code");
609609
}
610610

611611
/* Using continuous memory for guest page tables, the total 4K page

hypervisor/arch/x86/trampline.S

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
.extern _ld_bss_end
1717
.extern HOST_GDTR
1818

19-
.section .cpu_secondary_reset,"ax"
19+
.section .trampline_reset,"ax"
2020

2121
.align 4
2222
.code16
23-
.global cpu_secondary_reset
24-
cpu_secondary_reset:
23+
.global trampline_start16
24+
trampline_start16:
2525

2626
/* Disable local interrupts */
2727

@@ -54,14 +54,14 @@ cpu_secondary_reset:
5454
mov %ebx, %cr0
5555

5656
/* Load temportary GDT pointer value */
57-
lgdt (cpu_secondary_gdt_ptr - cpu_secondary_reset)
57+
lgdt (trampline_gdt_ptr - trampline_start16)
5858

5959
/* Perform a long jump based to start executing in 64-bit mode */
6060

61-
data32 ljmp $HOST_GDT_RING0_CODE_SEL, $cpu_secondary_long_mode
61+
data32 ljmp $HOST_GDT_RING0_CODE_SEL, $trampline_start64
6262

6363
.code64
64-
cpu_secondary_long_mode:
64+
trampline_start64:
6565

6666
/* Set up all other data segment registers */
6767

@@ -72,10 +72,8 @@ cpu_secondary_long_mode:
7272
mov %eax, %fs
7373
mov %eax, %gs
7474

75-
/* Obtain secondary CPU spin-lock to serialize
76-
booting of secondary cores for a bit */
77-
78-
spinlock_obtain(cpu_secondary_spinlock)
75+
/* Obtain CPU spin-lock to serialize trampline for different APs */
76+
spinlock_obtain(trampline_spinlock)
7977

8078
/* Initialize temporary stack pointer
8179
NOTE: Using the PML4 memory (PDPT address is top of memory
@@ -86,51 +84,54 @@ cpu_secondary_long_mode:
8684
used for a VERY short period of time, so
8785
this reuse of PML4 memory should be acceptable. */
8886

89-
movq $cpu_secondary_pdpt_addr, %rsp
87+
movq $trampline_pdpt_addr, %rsp
9088

9189
/* Push sp magic to top of stack for call trace */
9290
pushq $SP_BOTTOM_MAGIC
9391

94-
/* Jump to C entry for the AP */
95-
96-
call cpu_secondary_init
97-
98-
cpu_secondary_error:
92+
/* Jump to C entry */
93+
movq main_entry(%rip), %rax
94+
jmp %rax
9995

100-
/* Error condition trap */
96+
trampline_error: /* should never come here */
97+
jmp trampline_error
10198

102-
jmp cpu_secondary_error
99+
/* main entry */
100+
.align 8
101+
.global main_entry
102+
main_entry:
103+
.quad cpu_secondary_init /* default entry is AP start entry */
103104

104105
/* GDT table */
105106
.align 4
106-
cpu_secondary_gdt:
107+
trampline_gdt:
107108
.quad 0x0000000000000000
108109
.quad 0x00af9b000000ffff
109110
.quad 0x00cf93000000ffff
110-
cpu_secondary_gdt_end:
111+
trampline_gdt_end:
111112

112113
/* GDT pointer */
113114
.align 2
114-
cpu_secondary_gdt_ptr:
115-
.short (cpu_secondary_gdt_end - cpu_secondary_gdt) - 1
116-
.quad cpu_secondary_gdt
115+
trampline_gdt_ptr:
116+
.short (trampline_gdt_end - trampline_gdt) - 1
117+
.quad trampline_gdt
117118

118119
/* PML4, PDPT, and PD tables initialized to map first 4 GBytes of memory */
119120

120121
.align CPU_PAGE_SIZE
121122
.global CPU_Boot_Page_Tables_Start
122123
CPU_Boot_Page_Tables_Start:
123-
.quad cpu_secondary_pdpt_addr + (IA32E_COMM_P_BIT | IA32E_COMM_RW_BIT)
124+
.quad trampline_pdpt_addr + (IA32E_COMM_P_BIT | IA32E_COMM_RW_BIT)
124125
.align CPU_PAGE_SIZE
125-
cpu_secondary_pdpt_addr:
126+
trampline_pdpt_addr:
126127
address = 0
127128
.rept 4
128-
.quad cpu_secondary_pdt_addr + address + \
129+
.quad trampline_pdt_addr + address + \
129130
(IA32E_COMM_P_BIT | IA32E_COMM_RW_BIT)
130131
address = address + CPU_PAGE_SIZE
131132
.endr
132133
.align CPU_PAGE_SIZE
133-
cpu_secondary_pdt_addr:
134+
trampline_pdt_addr:
134135
address = 0
135136
.rept 2048
136137
.quad address + (IA32E_PDPTE_PS_BIT | IA32E_COMM_P_BIT | IA32E_COMM_RW_BIT)

hypervisor/bsp/ld/link_ram.ld.in

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ SECTIONS
3939

4040
} > ram
4141

42-
_ld_cpu_secondary_reset_load = .;
42+
_ld_trampline_load = .;
4343

44-
.cpu_secondary : AT (_ld_cpu_secondary_reset_load)
44+
.trampline : AT (_ld_trampline_load)
4545
{
46-
_ld_cpu_secondary_reset_start = .;
47-
*(.cpu_secondary_reset);
46+
_ld_trampline_start = .;
47+
*(.trampline_reset);
4848
. = ALIGN(4);
49-
_ld_cpu_secondary_reset_end = .;
49+
_ld_trampline_end = .;
5050

5151
} > lowram
5252

53-
_ld_cpu_secondary_reset_size = _ld_cpu_secondary_reset_end - _ld_cpu_secondary_reset_start;
53+
_ld_trampline_size = _ld_trampline_end - _ld_trampline_start;
5454

55-
.data (_ld_cpu_secondary_reset_load + _ld_cpu_secondary_reset_size):
55+
.data (_ld_trampline_load + _ld_trampline_size):
5656
{
5757
*(.data) ;
5858
*(.data*) ;

hypervisor/include/arch/x86/cpu.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ int cpu_find_logical_id(uint32_t lapic_id);
156156
/**********************************/
157157
/* EXTERNAL VARIABLES */
158158
/**********************************/
159-
extern const uint8_t _ld_cpu_secondary_reset_load[];
160-
extern uint8_t _ld_cpu_secondary_reset_start[];
161-
extern const uint64_t _ld_cpu_secondary_reset_size;
159+
extern const uint8_t _ld_trampline_load[];
160+
extern uint8_t _ld_trampline_start[];
161+
extern const uint64_t _ld_trampline_size;
162162
extern uint8_t _ld_bss_start[];
163163
extern uint8_t _ld_bss_end[];
164164

@@ -239,7 +239,7 @@ extern struct cpuinfo_x86 boot_cpu_data;
239239

240240
/* Function prototypes */
241241
void cpu_dead(uint32_t logical_id);
242-
void cpu_secondary_reset(void);
242+
void trampline_start16(void);
243243
int hv_main(int cpu_id);
244244
bool is_vapic_supported(void);
245245
bool is_vapic_intr_delivery_supported(void);

0 commit comments

Comments
 (0)