kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: mtosatti@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH 3/3] Reenter guest after instruction emulation failure if emulation was due to access to non-mmio address.
Date: Thu, 8 Jul 2010 12:17:50 +0300	[thread overview]
Message-ID: <20100708091750.GR4689@redhat.com> (raw)
In-Reply-To: <4C359726.8090908@redhat.com>

On Thu, Jul 08, 2010 at 12:15:18PM +0300, Avi Kivity wrote:
> On 07/08/2010 12:06 PM, Avi Kivity wrote:
> >On 07/07/2010 08:16 PM, Gleb Natapov wrote:
> >>When shadow pages are in use sometimes KVM try to emulate an instruction
> >>when it accesses a shadowed page. If emulation fails KVM un-shadows the
> >>page and reenter guest to allow vcpu to execute the instruction. If page
> >>is not in shadow page hash KVM assumes that this was attempt to do MMIO
> >>and reports emulation failure to userspace since there is no way to fix
> >>the situation. This logic has a race though. If two vcpus tries to write
> >>to the same shadowed page simultaneously both will enter emulator, but
> >>only one of them will find the page in shadow page hash since
> >>the one who
> >>founds it also removes it from there, so another cpu will report failure
> >>to userspace and will abort the guest.
> >>
> >>Fix this by checking (in addition to checking shadowed page hash) that
> >>page that caused the emulation belongs to valid memory slot. If it is
> >>then reenter the guest to allow vcpu to reexecute the instruction.
> >>
> >>
> >>diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> >>index 7070b41..dd7b241 100644
> >>--- a/arch/x86/kvm/x86.c
> >>+++ b/arch/x86/kvm/x86.c
> >>@@ -4000,6 +4000,8 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
> >>          if (r)  {
> >>              if (kvm_mmu_unprotect_page_virt(vcpu, cr2))
> >>                  return EMULATE_DONE;
> >>+            if (!kvm_is_error_hva(gfn_to_hva(vcpu->kvm, cr2)))
> >>+                return EMULATE_DONE;
> >
> >cr2 is a gva, not a gfn.
> 
> btw, that will mean another page walk, so better fold into
> kvm_mmu_unprotect_page_virt() (which needs a new name, since it does
> more than unprotect a page now).
> 
But this code will be taken very rarely and usually on the way to
failure anyway, do you think additional page walk is a problem?

> Say, kvm_make_guest_writeable().
> 
> -- 
> error compiling committee.c: too many arguments to function

--
			Gleb.

  reply	other threads:[~2010-07-08  9:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-07 17:16 [PATCH 1/3] define hwpoison variables static Gleb Natapov
2010-07-07 17:16 ` [PATCH 2/3] Return EFAULT from kvm ioctl when guest access bad area Gleb Natapov
2010-07-07 17:16 ` [PATCH 3/3] Reenter guest after instruction emulation failure if emulation was due to access to non-mmio address Gleb Natapov
2010-07-08  9:06   ` Avi Kivity
2010-07-08  9:15     ` Avi Kivity
2010-07-08  9:17       ` Gleb Natapov [this message]
2010-07-08  9:18         ` Avi Kivity
2010-07-08  9:41 ` [PATCH v2 " Gleb Natapov
2010-07-08  9:46   ` Avi Kivity

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=20100708091750.GR4689@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).