[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <E7912D02-373F-4822-8F38-E259038EFA19@gmail.com>
Date: Mon, 18 Aug 2014 21:53:11 +0300
From: Nadav Amit <nadav.amit@...il.com>
To: Paolo Bonzini <pbonzini@...hat.com>
Cc: gleb@...nel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>,
the arch/x86 maintainers <x86@...nel.org>,
KVM <kvm@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Nadav Amit <namit@...technion.ac.il>
Subject: Re: [PATCH] KVM: x86: Avoid emulating instructions on #UD mistakenly
On Aug 18, 2014, at 11:31 AM, Paolo Bonzini <pbonzini@...hat.com> wrote:
> Il 13/08/2014 16:21, Nadav Amit ha scritto:
>> Correction: the word “never” in the message is too harsh.
>> Nonetheless, there is a regression bug. I encountered it with “wrfsbase” instruction.
>
> So KVM is emulating wrfsbase even if the host doesn't support it?
KVM doesn’t know wrfsbase - wrfsbase is encoded like clflush with rep-prefix.
Therefore, the emulator thinks it can emulate it as clflush, and eliminates the #UD.
>
> I'm swapping the order of the two operands of &&, since the first one will almost
> always be true and the second one will almost always be false.
>
> Also, there's now no need to test EmulateOnUD in the condition below. Does the
> below look good to you?
>
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 37a83b24e040..ef117b842334 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -4394,11 +4394,11 @@ done_prefixes:
>
> ctxt->execute = opcode.u.execute;
>
> - if (!(ctxt->d & EmulateOnUD) && ctxt->ud)
> + if (unlikely(ctxt->ud) && likely(!(ctxt->d & EmulateOnUD)))
> return EMULATION_FAILED;
>
> if (unlikely(ctxt->d &
> - (NotImpl|EmulateOnUD|Stack|Op3264|Sse|Mmx|Intercept|CheckPerm))) {
> + (NotImpl|Stack|Op3264|Sse|Mmx|Intercept|CheckPerm))) {
> /*
> * These are copied unconditionally here, and checked unconditionally
> * in x86_emulate_insn.
>
Sure. Until I find some bugs in it. ;-)
Thanks,
Nadav
Download attachment "signature.asc" of type "application/pgp-signature" (496 bytes)
Powered by blists - more mailing lists