Skip to content

Commit aabba3c

Browse files
committed
KVM: x86: add asm_safe wrapper
Move the existing exception handling for inline assembly into a macro and switch its return values to X86EMUL type. Signed-off-by: Radim Krčmář <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4852018 commit aabba3c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

arch/x86/kvm/emulate.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,26 @@ FOP_END;
448448
FOP_START(salc) "pushf; sbb %al, %al; popf \n\t" FOP_RET
449449
FOP_END;
450450

451+
/*
452+
* XXX: inoutclob user must know where the argument is being expanded.
453+
* Relying on CC_HAVE_ASM_GOTO would allow us to remove _fault.
454+
*/
455+
#define asm_safe(insn, inoutclob...) \
456+
({ \
457+
int _fault = 0; \
458+
\
459+
asm volatile("1:" insn "\n" \
460+
"2:\n" \
461+
".pushsection .fixup, \"ax\"\n" \
462+
"3: movl $1, %[_fault]\n" \
463+
" jmp 2b\n" \
464+
".popsection\n" \
465+
_ASM_EXTABLE(1b, 3b) \
466+
: [_fault] "+qm"(_fault) inoutclob ); \
467+
\
468+
_fault ? X86EMUL_UNHANDLEABLE : X86EMUL_CONTINUE; \
469+
})
470+
451471
static int emulator_check_intercept(struct x86_emulate_ctxt *ctxt,
452472
enum x86_intercept intercept,
453473
enum x86_intercept_stage stage)
@@ -5087,21 +5107,13 @@ static bool string_insn_completed(struct x86_emulate_ctxt *ctxt)
50875107

50885108
static int flush_pending_x87_faults(struct x86_emulate_ctxt *ctxt)
50895109
{
5090-
bool fault = false;
5110+
int rc;
50915111

50925112
ctxt->ops->get_fpu(ctxt);
5093-
asm volatile("1: fwait \n\t"
5094-
"2: \n\t"
5095-
".pushsection .fixup,\"ax\" \n\t"
5096-
"3: \n\t"
5097-
"movb $1, %[fault] \n\t"
5098-
"jmp 2b \n\t"
5099-
".popsection \n\t"
5100-
_ASM_EXTABLE(1b, 3b)
5101-
: [fault]"+qm"(fault));
5113+
rc = asm_safe("fwait");
51025114
ctxt->ops->put_fpu(ctxt);
51035115

5104-
if (unlikely(fault))
5116+
if (unlikely(rc != X86EMUL_CONTINUE))
51055117
return emulate_exception(ctxt, MF_VECTOR, 0, false);
51065118

51075119
return X86EMUL_CONTINUE;

0 commit comments

Comments
 (0)