mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nadav Amit <namit@cs.technion.ac.il>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Nadav Amit <namit@cs.technion.ac.il>,
	Nadav Amit <nadav.amit@gmail.com>
Subject: [PATCH 2/2] KVM: Fix writeback on page boundary that propagate changes in spite of #PF
Date: Wed, 11 Jan 2012 18:53:31 +0200	[thread overview]
Message-ID: <1326300811-17065-2-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1326300811-17065-1-git-send-email-namit@cs.technion.ac.il>

Consider the case in which an instruction emulation writeback is performed on a page boundary.
In such case, if a #PF occurs on the second page, the write to the first page already occurred and cannot be retracted.
Therefore, validation of the second page access must be performed prior to writeback.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 arch/x86/kvm/x86.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 05fd3d7..7af3d67 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3626,6 +3626,8 @@ struct read_write_emulator_ops {
 			       int bytes, void *val);
 	int (*read_write_exit_mmio)(struct kvm_vcpu *vcpu, gpa_t gpa,
 				    void *val, int bytes);
+	gpa_t (*read_write_validate)(struct kvm_vcpu *vcpu, gva_t gva,
+				     struct x86_exception *exception);
 	bool write;
 };
 
@@ -3686,6 +3688,7 @@ static struct read_write_emulator_ops write_emultor = {
 	.read_write_emulate = write_emulate,
 	.read_write_mmio = write_mmio,
 	.read_write_exit_mmio = write_exit_mmio,
+	.read_write_validate = kvm_mmu_gva_to_gpa_write,
 	.write = true,
 };
 
@@ -3750,6 +3753,16 @@ int emulator_read_write(struct x86_emulate_ctxt *ctxt, unsigned long addr,
 		int rc, now;
 
 		now = -addr & ~PAGE_MASK;
+
+		/* First check there is no page-fault on the next page */
+		if (ops->read_write_validate &&
+			ops->read_write_validate(vcpu, addr+now, exception) ==
+			UNMAPPED_GVA) {
+			/* #PF on the first page should be reported first */
+			ops->read_write_validate(vcpu, addr, exception);
+			return X86EMUL_PROPAGATE_FAULT;
+		}
+
 		rc = emulator_read_write_onepage(addr, val, now, exception,
 						 vcpu, ops);
 
-- 
1.7.4.1


  reply	other threads:[~2012-01-11 16:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-11 16:53 [PATCH 1/2] KVM: Exception during emulation decode should propagate Nadav Amit
2012-01-11 16:53 ` Nadav Amit [this message]
2012-01-12 10:12   ` [PATCH 2/2] KVM: Fix writeback on page boundary that propagate changes in spite of #PF Gleb Natapov
2012-01-12 10:21     ` Avi Kivity
2012-01-12 10:27       ` Gleb Natapov
2012-01-14 18:27         ` Nadav Amit
2012-01-11 22:11 ` [PATCH 1/2] KVM: Exception during emulation decode should propagate Takuya Yoshikawa
2012-01-12  0:26   ` Takuya Yoshikawa
2012-01-12  9:07     ` Nadav Amit
2012-01-12  9:14       ` Takuya Yoshikawa
2012-01-12 10:16       ` 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=1326300811-17065-2-git-send-email-namit@cs.technion.ac.il \
    --to=namit@cs.technion.ac.il \
    --cc=avi@redhat.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=nadav.amit@gmail.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®