linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Hogan <james.hogan@imgtec.com>
To: linux-mips@linux-mips.org
Cc: "James Hogan" <james.hogan@imgtec.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Ralf Baechle" <ralf@linux-mips.org>,
	kvm@vger.kernel.org
Subject: [PATCH 7/10] KVM: MIPS/T&E: Use lockless GVA helpers for dyntrans
Date: Mon, 9 Jan 2017 20:51:59 +0000	[thread overview]
Message-ID: <8b8b6c1d2c495d1d5caf53c3386de34d19980576.1483993967.git-series.james.hogan@imgtec.com> (raw)
Message-ID: <20170109205159.IxCu0JB1I1yYrrVoCgiu-IwxIK0TzK432fs_iPq2uOA@z> (raw)
In-Reply-To: <cover.4133d2f24fd73c1889a46ea05bb8924867b33747.1483993967.git-series.james.hogan@imgtec.com>

Use the lockless GVA helpers to implement the dynamic translation of
guest instructions. This will allow it to handle asynchronous TLB
flushes when they are implemented.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
---
 arch/mips/kvm/dyntrans.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kvm/dyntrans.c b/arch/mips/kvm/dyntrans.c
index 60ebf5862d2b..f8e772564d74 100644
--- a/arch/mips/kvm/dyntrans.c
+++ b/arch/mips/kvm/dyntrans.c
@@ -33,10 +33,32 @@ static int kvm_mips_trans_replace(struct kvm_vcpu *vcpu, u32 *opc,
 	unsigned long vaddr = (unsigned long)opc;
 	int err;
 
+retry:
+	/* The GVA page table is still active so use the Linux TLB handlers */
+	kvm_trap_emul_gva_lockless_begin(vcpu);
 	err = put_user(replace.word, opc);
+	kvm_trap_emul_gva_lockless_end(vcpu);
+
 	if (unlikely(err)) {
-		kvm_err("%s: Invalid address: %p\n", __func__, opc);
-		return err;
+		/*
+		 * We write protect clean pages in GVA page table so normal
+		 * Linux TLB mod handler doesn't silently dirty the page.
+		 * Its also possible we raced with a GVA invalidation.
+		 * Try to force the page to become dirty.
+		 */
+		err = kvm_trap_emul_gva_fault(vcpu, vaddr, true);
+		if (unlikely(err)) {
+			kvm_info("%s: Address unwriteable: %p\n",
+				 __func__, opc);
+			return -EFAULT;
+		}
+
+		/*
+		 * Try again. This will likely trigger a TLB refill, which will
+		 * fetch the new dirty entry from the GVA page table, which
+		 * should then succeed.
+		 */
+		goto retry;
 	}
 	__local_flush_icache_user_range(vaddr, vaddr + 4);
 
-- 
git-series 0.8.10

  parent reply	other threads:[~2017-01-09 20:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-09 20:51 [PATCH 0/10] KVM: MIPS: Implement GPA page tables and shadow flushing James Hogan
2017-01-09 20:51 ` James Hogan
2017-01-09 20:51 ` [PATCH 1/10] MIPS: Add return errors to protected cache ops James Hogan
2017-01-09 20:51   ` James Hogan
2017-01-17 16:05   ` Ralf Baechle
2017-01-09 20:51 ` [PATCH 2/10] KVM: MIPS/MMU: Convert guest physical map to page table James Hogan
2017-01-09 20:51   ` James Hogan
2017-01-09 20:51 ` [PATCH 3/10] KVM: MIPS: Update vcpu->mode and vcpu->cpu James Hogan
2017-01-09 20:51   ` James Hogan
2017-01-09 20:51 ` [PATCH 4/10] KVM: MIPS/T&E: Handle TLB invalidation requests James Hogan
2017-01-09 20:51   ` James Hogan
2017-01-09 20:51 ` [PATCH 5/10] KVM: MIPS/T&E: Reduce stale ASID checks James Hogan
2017-01-09 20:51   ` James Hogan
2017-01-09 20:51 ` [PATCH 6/10] KVM: MIPS/T&E: Add lockless GVA access helpers James Hogan
2017-01-09 20:51   ` James Hogan
2017-01-09 20:51 ` James Hogan [this message]
2017-01-09 20:51   ` [PATCH 7/10] KVM: MIPS/T&E: Use lockless GVA helpers for dyntrans James Hogan
2017-01-09 20:52 ` [PATCH 8/10] KVM: MIPS/MMU: Use lockless GVA helpers for get_inst() James Hogan
2017-01-09 20:52   ` James Hogan
2017-01-09 20:52 ` [PATCH 9/10] KVM: MIPS/Emulate: Use lockless GVA helpers for cache emulation James Hogan
2017-01-09 20:52   ` James Hogan
2017-01-09 20:52 ` [PATCH 10/10] KVM: MIPS: Implement kvm_arch_flush_shadow_all/memslot James Hogan
2017-01-09 20:52   ` James Hogan

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=8b8b6c1d2c495d1d5caf53c3386de34d19980576.1483993967.git-series.james.hogan@imgtec.com \
    --to=james.hogan@imgtec.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=pbonzini@redhat.com \
    --cc=ralf@linux-mips.org \
    --cc=rkrcmar@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).