Skip to content

Commit 285b64f

Browse files
JasonChenCJwenlingz
authored andcommitted
replace arch_switch_to with pure asm code instead of inline asm
after compile, the compiled code could change rsp, so use pure asm code to avoid such problem which will cause schedule switch failure. Tracked-On: #2410 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent c233bf5 commit 285b64f

File tree

5 files changed

+44
-39
lines changed

5 files changed

+44
-39
lines changed

hypervisor/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ C_SRCS += arch/x86/pm.c
170170
S_SRCS += arch/x86/wakeup.S
171171
C_SRCS += arch/x86/static_checks.c
172172
C_SRCS += arch/x86/trampoline.c
173-
C_SRCS += arch/x86/sched.c
173+
S_SRCS += arch/x86/sched.S
174174
C_SRCS += arch/x86/guest/vcpuid.c
175175
C_SRCS += arch/x86/guest/vcpu.c
176176
C_SRCS += arch/x86/guest/vm.c

hypervisor/arch/x86/sched.S

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*
8+
* Function schedule() will finally call arch_switch_to here for x86 platform, which use
9+
* the pointer of previous & next sched_obj->host_sp as the input parameters (rdi & rsi).
10+
*
11+
* Function arch_switch_to will save rflags, rbx, rbp, r12~r15, and rdi in the previous
12+
* sched_obj's stack, then switch stack pointer(rsp) from previous to next sched_obj (saved
13+
* in sched_obj->host_sp) and restore above registers from next sched_obj's stack.
14+
* It make sure the execution context return to the same point of next sched_obj when it got
15+
* scheduled last time.
16+
*/
17+
.text
18+
19+
.code64
20+
.align 8
21+
.global arch_switch_to
22+
arch_switch_to:
23+
pushf
24+
pushq %rbx
25+
pushq %rbp
26+
pushq %r12
27+
pushq %r13
28+
pushq %r14
29+
pushq %r15
30+
pushq %rdi
31+
movq %rsp, (%rdi)
32+
movq (%rsi), %rsp
33+
popq %rdi
34+
popq %r15
35+
popq %r14
36+
popq %r13
37+
popq %r12
38+
popq %rbp
39+
popq %rbx
40+
popf
41+
retq

hypervisor/arch/x86/sched.c

Lines changed: 0 additions & 36 deletions
This file was deleted.

hypervisor/common/schedule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void schedule(void)
164164
prepare_switch(prev, next);
165165
release_schedule_lock(pcpu_id);
166166

167-
arch_switch_to(prev, next);
167+
arch_switch_to(&prev->host_sp, &next->host_sp);
168168
}
169169
}
170170

hypervisor/include/common/schedule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ int32_t need_offline(uint16_t pcpu_id);
5050
void schedule(void);
5151
void run_sched_thread(struct sched_object *obj);
5252

53-
void arch_switch_to(struct sched_object *prev, struct sched_object *next);
53+
void arch_switch_to(void *prev_sp, void *next_sp);
5454
#endif /* SCHEDULE_H */
5555

0 commit comments

Comments
 (0)