Skip to content

Commit 587ee91

Browse files
committed
Fix a BSOD triggered by Windows 10 20H1.
The bugcheck is caused by an APC interrupt delivered in the middle of fastop emulation, where original KVM will overwrite host eflags. With SMAP on, AC of eflags is very sensitive.
1 parent 8db1a4a commit 587ee91

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

arch/x86/kvm/emulate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5213,7 +5213,7 @@ extern void __asm_fastop(size_t *flags,void *fop,
52135213
struct x86_emulate_ctxt *ctxt);
52145214
static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
52155215
{
5216-
size_t flags = (ctxt->eflags & EFLAGS_MASK) | X86_EFLAGS_IF;
5216+
size_t flags = ctxt->eflags & EFLAGS_MASK;
52175217
char *__fop = (char *)fop;
52185218

52195219
if (!(ctxt->d & ByteOp))

assembly/x64/assembly.asm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,17 @@ __asm_fastop proc frame
629629

630630
; save host eflags
631631
pushfq
632-
push qword ptr[rdi]
632+
mov r10, qword ptr[rdi]
633+
mov r9, qword ptr[rsp]
634+
and r9d, 0fffff72ah
635+
or r10, r9
636+
push r10
633637
popfq
634638
call rsi
635639
pushfq
636-
pop qword ptr[rdi]
640+
pop r10
641+
and r10, 8D5h ; keep status flags
642+
mov qword ptr[rdi], r10
637643
popfq
638644

639645
mov qword ptr CXT_TO_DST[r8], rax
@@ -646,12 +652,6 @@ __asm_fastop proc frame
646652
ret
647653
__asm_fastop endp
648654

649-
public kvm_fastop_exception
650-
kvm_fastop_exception proc
651-
xor esi, esi
652-
ret
653-
kvm_fastop_exception endp
654-
655655
; ---------------------------------------------------------------------------
656656
align 8
657657

0 commit comments

Comments
 (0)