From 52ca0fe8fc0fa4b59e16e16b7cd3e287c1fcdda4 Mon Sep 17 00:00:00 2001 From: Zhao Yakui Date: Thu, 10 May 2018 11:13:55 +0800 Subject: [PATCH] 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 Signed-off-by: Zheng Gen Reviewed-by: Jason Chen CJ Acked-by: Anthony Xu Acked-by: Eddie Dong --- hypervisor/arch/x86/cpu.c | 4 +++- hypervisor/arch/x86/vmx.c | 6 +++--- hypervisor/include/arch/x86/cpu.h | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 02fb4b6f4..106d434bd 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -347,7 +347,9 @@ static uint64_t get_random_value(void) asm volatile ("1: rdrand %%rax\n" "jnc 1b\n" "mov %%rax, %0\n" - : "=r"(random) :: ); + : "=r"(random) + : + :"%rax"); return random; } diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index 123087f06..9696f097a 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -82,7 +82,7 @@ static inline int exec_vmxon(void *addr) "pushfq\n" "pop %0\n":"=r" (rflags) : "r"(addr) - : "%rax"); + : "%rax", "cc", "memory"); /* if carry and zero flags are clear operation success */ if (rflags & (RFLAGS_C | RFLAGS_Z)) @@ -140,7 +140,7 @@ int exec_vmclear(void *addr) "pushfq\n" "pop %0\n":"=r" (rflags) : "r"(addr) - : "%rax"); + : "%rax", "cc", "memory"); /* if carry and zero flags are clear operation success */ if (rflags & (RFLAGS_C | RFLAGS_Z)) @@ -165,7 +165,7 @@ int exec_vmptrld(void *addr) "pop %0\n" : "=r" (rflags) : "r"(addr) - : "%rax"); + : "%rax", "cc"); /* if carry and zero flags are clear operation success */ if (rflags & (RFLAGS_C | RFLAGS_Z)) diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h index dc4a41e30..9b2862239 100644 --- a/hypervisor/include/arch/x86/cpu.h +++ b/hypervisor/include/arch/x86/cpu.h @@ -379,8 +379,9 @@ void load_cpu_state_data(void); /* Macro to restore rflags register */ #define CPU_RFLAGS_RESTORE(rflags) \ { \ - asm volatile (" push %0" : : "r" (rflags)); \ - asm volatile (" popf"); \ + asm volatile (" push %0\n\t" \ + "popf \n\t": : "r" (rflags) \ + :"cc"); \ } /* This macro locks out interrupts and saves the current architecture status