Skip to content

Commit b2cadfe

Browse files
yakuizhaojren1
authored andcommitted
HV: Fix the incorrect operand-constraints for inline assembly
The RFLAGS will be touched in some inline assembly.(exec_vmxon/ RFLAGS_RESTORE). The "cc" constraint should be added. Otherwise it won't be handled under -O2 option. And "%%XXX" register should also be added into constraints. Otherwise it will be optimized incorrectly. Signed-off-by: Zhao Yakui <yakui.zhao@intel.com> Signed-off-by: Zheng Gen <gen.zheng@intel.com> Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 9dd7d27 commit b2cadfe

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ static uint64_t get_random_value(void)
347347
asm volatile ("1: rdrand %%rax\n"
348348
"jnc 1b\n"
349349
"mov %%rax, %0\n"
350-
: "=r"(random) :: );
350+
: "=r"(random)
351+
:
352+
:"%rax");
351353
return random;
352354
}
353355

hypervisor/arch/x86/vmx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static inline int exec_vmxon(void *addr)
8282
"pushfq\n"
8383
"pop %0\n":"=r" (rflags)
8484
: "r"(addr)
85-
: "%rax");
85+
: "%rax", "cc", "memory");
8686

8787
/* if carry and zero flags are clear operation success */
8888
if (rflags & (RFLAGS_C | RFLAGS_Z))
@@ -140,7 +140,7 @@ int exec_vmclear(void *addr)
140140
"pushfq\n"
141141
"pop %0\n":"=r" (rflags)
142142
: "r"(addr)
143-
: "%rax");
143+
: "%rax", "cc", "memory");
144144

145145
/* if carry and zero flags are clear operation success */
146146
if (rflags & (RFLAGS_C | RFLAGS_Z))
@@ -165,7 +165,7 @@ int exec_vmptrld(void *addr)
165165
"pop %0\n"
166166
: "=r" (rflags)
167167
: "r"(addr)
168-
: "%rax");
168+
: "%rax", "cc");
169169

170170
/* if carry and zero flags are clear operation success */
171171
if (rflags & (RFLAGS_C | RFLAGS_Z))

hypervisor/include/arch/x86/cpu.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ void load_cpu_state_data(void);
379379
/* Macro to restore rflags register */
380380
#define CPU_RFLAGS_RESTORE(rflags) \
381381
{ \
382-
asm volatile (" push %0" : : "r" (rflags)); \
383-
asm volatile (" popf"); \
382+
asm volatile (" push %0\n\t" \
383+
"popf \n\t": : "r" (rflags) \
384+
:"cc"); \
384385
}
385386

386387
/* This macro locks out interrupts and saves the current architecture status

0 commit comments

Comments
 (0)