Skip to content

Commit fd8ca6d

Browse files
ubizjakbonzini
authored andcommitted
KVM/x86: Use CC_SET()/CC_OUT in arch/x86/kvm/vmx.c
Remove open-coded uses of set instructions to use CC_SET()/CC_OUT() in arch/x86/kvm/vmx.c. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> [Mark error paths as unlikely while touching this. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent aaffcfd commit fd8ca6d

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

arch/x86/kvm/vmx.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "kvm_cache_regs.h"
3939
#include "x86.h"
4040

41+
#include <asm/asm.h>
4142
#include <asm/cpu.h>
4243
#include <asm/io.h>
4344
#include <asm/desc.h>
@@ -1916,23 +1917,25 @@ static inline void __invvpid(int ext, u16 vpid, gva_t gva)
19161917
u64 rsvd : 48;
19171918
u64 gva;
19181919
} operand = { vpid, 0, gva };
1920+
bool error;
19191921

1920-
asm volatile (__ex(ASM_VMX_INVVPID)
1921-
/* CF==1 or ZF==1 --> rc = -1 */
1922-
"; ja 1f ; ud2 ; 1:"
1923-
: : "a"(&operand), "c"(ext) : "cc", "memory");
1922+
asm volatile (__ex(ASM_VMX_INVVPID) CC_SET(na)
1923+
: CC_OUT(na) (error) : "a"(&operand), "c"(ext)
1924+
: "memory");
1925+
BUG_ON(error);
19241926
}
19251927

19261928
static inline void __invept(int ext, u64 eptp, gpa_t gpa)
19271929
{
19281930
struct {
19291931
u64 eptp, gpa;
19301932
} operand = {eptp, gpa};
1933+
bool error;
19311934

1932-
asm volatile (__ex(ASM_VMX_INVEPT)
1933-
/* CF==1 or ZF==1 --> rc = -1 */
1934-
"; ja 1f ; ud2 ; 1:\n"
1935-
: : "a" (&operand), "c" (ext) : "cc", "memory");
1935+
asm volatile (__ex(ASM_VMX_INVEPT) CC_SET(na)
1936+
: CC_OUT(na) (error) : "a" (&operand), "c" (ext)
1937+
: "memory");
1938+
BUG_ON(error);
19361939
}
19371940

19381941
static struct shared_msr_entry *find_msr_entry(struct vcpu_vmx *vmx, u32 msr)
@@ -1948,12 +1951,12 @@ static struct shared_msr_entry *find_msr_entry(struct vcpu_vmx *vmx, u32 msr)
19481951
static void vmcs_clear(struct vmcs *vmcs)
19491952
{
19501953
u64 phys_addr = __pa(vmcs);
1951-
u8 error;
1954+
bool error;
19521955

1953-
asm volatile (__ex(ASM_VMX_VMCLEAR_RAX) "; setna %0"
1954-
: "=qm"(error) : "a"(&phys_addr), "m"(phys_addr)
1955-
: "cc", "memory");
1956-
if (error)
1956+
asm volatile (__ex(ASM_VMX_VMCLEAR_RAX) CC_SET(na)
1957+
: CC_OUT(na) (error) : "a"(&phys_addr), "m"(phys_addr)
1958+
: "memory");
1959+
if (unlikely(error))
19571960
printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n",
19581961
vmcs, phys_addr);
19591962
}
@@ -1970,15 +1973,15 @@ static inline void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs)
19701973
static void vmcs_load(struct vmcs *vmcs)
19711974
{
19721975
u64 phys_addr = __pa(vmcs);
1973-
u8 error;
1976+
bool error;
19741977

19751978
if (static_branch_unlikely(&enable_evmcs))
19761979
return evmcs_load(phys_addr);
19771980

1978-
asm volatile (__ex(ASM_VMX_VMPTRLD_RAX) "; setna %0"
1979-
: "=qm"(error) : "a"(&phys_addr), "m"(phys_addr)
1980-
: "cc", "memory");
1981-
if (error)
1981+
asm volatile (__ex(ASM_VMX_VMPTRLD_RAX) CC_SET(na)
1982+
: CC_OUT(na) (error) : "a"(&phys_addr), "m"(phys_addr)
1983+
: "memory");
1984+
if (unlikely(error))
19821985
printk(KERN_ERR "kvm: vmptrld %p/%llx failed\n",
19831986
vmcs, phys_addr);
19841987
}
@@ -2203,10 +2206,10 @@ static noinline void vmwrite_error(unsigned long field, unsigned long value)
22032206

22042207
static __always_inline void __vmcs_writel(unsigned long field, unsigned long value)
22052208
{
2206-
u8 error;
2209+
bool error;
22072210

2208-
asm volatile (__ex(ASM_VMX_VMWRITE_RAX_RDX) "; setna %0"
2209-
: "=q"(error) : "a"(value), "d"(field) : "cc");
2211+
asm volatile (__ex(ASM_VMX_VMWRITE_RAX_RDX) CC_SET(na)
2212+
: CC_OUT(na) (error) : "a"(value), "d"(field));
22102213
if (unlikely(error))
22112214
vmwrite_error(field, value);
22122215
}

0 commit comments

Comments
 (0)