public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: kvm-ppc@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 04/15] KVM: PPC: Book3S_32 guest MMU fixes
Date: Mon,  8 Mar 2010 19:03:11 +0100	[thread overview]
Message-ID: <1268071402-27112-5-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1268071402-27112-1-git-send-email-agraf@suse.de>

This patch makes the VSID of mapped pages always reflecting all special cases
we have, like split mode.

It also changes the tlbie mask to 0x0ffff000 according to the spec. The mask
we used before was incorrect.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/include/asm/kvm_book3s.h |    1 +
 arch/powerpc/kvm/book3s_32_mmu.c      |   30 +++++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/asm/kvm_book3s.h
index 9f5a992..b47b2f5 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -44,6 +44,7 @@ struct kvmppc_sr {
 	bool Ks;
 	bool Kp;
 	bool nx;
+	bool valid;
 };
 
 struct kvmppc_bat {
diff --git a/arch/powerpc/kvm/book3s_32_mmu.c b/arch/powerpc/kvm/book3s_32_mmu.c
index 1483a9b..7071e22 100644
--- a/arch/powerpc/kvm/book3s_32_mmu.c
+++ b/arch/powerpc/kvm/book3s_32_mmu.c
@@ -57,6 +57,8 @@ static inline bool check_debug_ip(struct kvm_vcpu *vcpu)
 
 static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr,
 					  struct kvmppc_pte *pte, bool data);
+static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, u64 esid,
+					     u64 *vsid);
 
 static struct kvmppc_sr *find_sr(struct kvmppc_vcpu_book3s *vcpu_book3s, gva_t eaddr)
 {
@@ -66,13 +68,14 @@ static struct kvmppc_sr *find_sr(struct kvmppc_vcpu_book3s *vcpu_book3s, gva_t e
 static u64 kvmppc_mmu_book3s_32_ea_to_vp(struct kvm_vcpu *vcpu, gva_t eaddr,
 					 bool data)
 {
-	struct kvmppc_sr *sre = find_sr(to_book3s(vcpu), eaddr);
+	u64 vsid;
 	struct kvmppc_pte pte;
 
 	if (!kvmppc_mmu_book3s_32_xlate_bat(vcpu, eaddr, &pte, data))
 		return pte.vpage;
 
-	return (((u64)eaddr >> 12) & 0xffff) | (((u64)sre->vsid) << 16);
+	kvmppc_mmu_book3s_32_esid_to_vsid(vcpu, eaddr >> SID_SHIFT, &vsid);
+	return (((u64)eaddr >> 12) & 0xffff) | (vsid << 16);
 }
 
 static void kvmppc_mmu_book3s_32_reset_msr(struct kvm_vcpu *vcpu)
@@ -142,8 +145,13 @@ static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr,
 				    bat->bepi_mask);
 		}
 		if ((eaddr & bat->bepi_mask) == bat->bepi) {
+			u64 vsid;
+			kvmppc_mmu_book3s_32_esid_to_vsid(vcpu,
+				eaddr >> SID_SHIFT, &vsid);
+			vsid <<= 16;
+			pte->vpage = (((u64)eaddr >> 12) & 0xffff) | vsid;
+
 			pte->raddr = bat->brpn | (eaddr & ~bat->bepi_mask);
-			pte->vpage = (eaddr >> 12) | VSID_BAT;
 			pte->may_read = bat->pp;
 			pte->may_write = bat->pp > 1;
 			pte->may_execute = true;
@@ -302,6 +310,7 @@ static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum,
 	/* And then put in the new SR */
 	sre->raw = value;
 	sre->vsid = (value & 0x0fffffff);
+	sre->valid = (value & 0x80000000) ? false : true;
 	sre->Ks = (value & 0x40000000) ? true : false;
 	sre->Kp = (value & 0x20000000) ? true : false;
 	sre->nx = (value & 0x10000000) ? true : false;
@@ -312,7 +321,7 @@ static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum,
 
 static void kvmppc_mmu_book3s_32_tlbie(struct kvm_vcpu *vcpu, ulong ea, bool large)
 {
-	kvmppc_mmu_pte_flush(vcpu, ea, ~0xFFFULL);
+	kvmppc_mmu_pte_flush(vcpu, ea, 0x0FFFF000);
 }
 
 static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, u64 esid,
@@ -333,15 +342,22 @@ static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, u64 esid,
 		break;
 	case MSR_DR|MSR_IR:
 	{
-		ulong ea;
-		ea = esid << SID_SHIFT;
-		*vsid = find_sr(to_book3s(vcpu), ea)->vsid;
+		ulong ea = esid << SID_SHIFT;
+		struct kvmppc_sr *sr = find_sr(to_book3s(vcpu), ea);
+
+		if (!sr->valid)
+			return -1;
+
+		*vsid = sr->vsid;
 		break;
 	}
 	default:
 		BUG();
 	}
 
+	if (vcpu->arch.msr & MSR_PR)
+		*vsid |= VSID_PR;
+
 	return 0;
 }
 
-- 
1.6.0.2


  parent reply	other threads:[~2010-03-08 18:03 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-08 18:03 [PATCH 00/15] KVM: PPC: MOL bringup patches Alexander Graf
2010-03-08 18:03 ` [PATCH 02/15] KVM: PPC: Allow userspace to unset the IRQ line Alexander Graf
     [not found]   ` <1268071402-27112-3-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2010-03-09 12:50     ` Avi Kivity
     [not found]       ` <4B964412.8030708-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-03-09 12:54         ` Alexander Graf
     [not found]           ` <954C5195-A8E4-4CA5-8D5E-AA21E2E21C5B-l3A5Bk7waGM@public.gmane.org>
2010-03-09 13:05             ` Avi Kivity
2010-03-08 18:03 ` Alexander Graf [this message]
2010-03-08 18:03 ` [PATCH 06/15] KVM: PPC: Don't reload FPU with invalid values Alexander Graf
     [not found] ` <1268071402-27112-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2010-03-08 18:03   ` [PATCH 01/15] KVM: PPC: Ensure split mode works Alexander Graf
2010-03-08 18:03   ` [PATCH 03/15] KVM: PPC: Make DSISR 32 bits wide Alexander Graf
2010-03-08 18:03   ` [PATCH 05/15] KVM: PPC: Split instruction reading out Alexander Graf
2010-03-08 18:03   ` [PATCH 07/15] KVM: PPC: Load VCPU for register fetching Alexander Graf
2010-03-08 18:03   ` [PATCH 08/15] KVM: PPC: Implement mfsr emulation Alexander Graf
2010-03-08 18:03   ` [PATCH 12/15] KVM: PPC: Implement alignment interrupt Alexander Graf
2010-03-08 18:03   ` [PATCH 13/15] KVM: Add support for enabling capabilities per-vcpu Alexander Graf
2010-03-09 12:56     ` Avi Kivity
2010-03-09 13:01       ` Alexander Graf
2010-03-09 13:09         ` Avi Kivity
2010-03-08 18:03   ` [PATCH 14/15] KVM: PPC: Add OSI hypercall interface Alexander Graf
2010-03-09 13:00     ` Avi Kivity
2010-03-09 13:04       ` Alexander Graf
2010-03-09 13:11         ` Avi Kivity
2010-03-09 13:12           ` Alexander Graf
     [not found]             ` <3D0D6963-FEC8-4A53-ACCE-570BEAF3721B-l3A5Bk7waGM@public.gmane.org>
2010-03-09 13:19               ` Avi Kivity
     [not found]                 ` <4B964ADE.5030200-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-03-09 13:20                   ` Alexander Graf
2010-03-08 18:03   ` [PATCH 15/15] KVM: PPC: Make build work without CONFIG_VSX/ALTIVEC Alexander Graf
2010-03-08 18:03 ` [PATCH 09/15] KVM: PPC: Implement BAT reads Alexander Graf
2010-03-08 18:03 ` [PATCH 10/15] KVM: PPC: Make XER load 32 bit Alexander Graf
2010-03-08 18:03 ` [PATCH 11/15] KVM: PPC: Implement emulation for lbzux and lhax Alexander Graf
2010-03-08 18:06 ` [PATCH 00/15] KVM: PPC: MOL bringup patches Alexander Graf

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=1268071402-27112-5-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.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