mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nadav Amit <nadav.amit@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: gleb@kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	the arch/x86 maintainers <x86@kernel.org>,
	KVM <kvm@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Nadav Amit <namit@cs.technion.ac.il>
Subject: Re: [PATCH] KVM: x86: Avoid emulating instructions on #UD mistakenly
Date: Mon, 18 Aug 2014 21:53:11 +0300	[thread overview]
Message-ID: <E7912D02-373F-4822-8F38-E259038EFA19@gmail.com> (raw)
In-Reply-To: <53F1B9E4.2090008@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]


On Aug 18, 2014, at 11:31 AM, Paolo Bonzini <pbonzini@redhat.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

[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

      reply	other threads:[~2014-08-18 18:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13 13:50 Nadav Amit
2014-08-13 14:21 ` Nadav Amit
2014-08-18  8:31   ` Paolo Bonzini
2014-08-18 18:53     ` Nadav Amit [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E7912D02-373F-4822-8F38-E259038EFA19@gmail.com \
    --to=nadav.amit@gmail.com \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namit@cs.technion.ac.il \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®