kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: kvm-ppc@vger.kernel.org
Cc: Linuxppc-dev <linuxppc-dev@ozlabs.org>, KVM list <kvm@vger.kernel.org>
Subject: [PATCH 18/35] KVM: PPC: Make PV mtmsr work with r30 and r31
Date: Tue, 31 Aug 2010 04:31:59 +0200	[thread overview]
Message-ID: <1283221937-21006-19-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1283221937-21006-1-git-send-email-agraf@suse.de>

So far we've been restricting ourselves to r0-r29 as registers an mtmsr
instruction could use. This was bad, as there are some code paths in
Linux actually using r30.

So let's instead handle all registers gracefully and get rid of that
stupid limitation

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/kernel/kvm.c      |   39 ++++++++++++++++++++++++++++++++-------
 arch/powerpc/kernel/kvm_emul.S |   17 ++++++++---------
 2 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 43ec78a..517967d 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -43,6 +43,7 @@
 #define KVM_INST_B_MAX		0x01ffffff
 
 #define KVM_MASK_RT		0x03e00000
+#define KVM_RT_30		0x03c00000
 #define KVM_MASK_RB		0x0000f800
 #define KVM_INST_MFMSR		0x7c0000a6
 #define KVM_INST_MFSPR_SPRG0	0x7c1042a6
@@ -83,6 +84,15 @@ static inline void kvm_patch_ins(u32 *inst, u32 new_inst)
 	flush_icache_range((ulong)inst, (ulong)inst + 4);
 }
 
+static void kvm_patch_ins_ll(u32 *inst, long addr, u32 rt)
+{
+#ifdef CONFIG_64BIT
+	kvm_patch_ins(inst, KVM_INST_LD | rt | (addr & 0x0000fffc));
+#else
+	kvm_patch_ins(inst, KVM_INST_LWZ | rt | (addr & 0x0000fffc));
+#endif
+}
+
 static void kvm_patch_ins_ld(u32 *inst, long addr, u32 rt)
 {
 #ifdef CONFIG_64BIT
@@ -187,7 +197,6 @@ static void kvm_patch_ins_mtmsrd(u32 *inst, u32 rt)
 extern u32 kvm_emulate_mtmsr_branch_offs;
 extern u32 kvm_emulate_mtmsr_reg1_offs;
 extern u32 kvm_emulate_mtmsr_reg2_offs;
-extern u32 kvm_emulate_mtmsr_reg3_offs;
 extern u32 kvm_emulate_mtmsr_orig_ins_offs;
 extern u32 kvm_emulate_mtmsr_len;
 extern u32 kvm_emulate_mtmsr[];
@@ -217,9 +226,27 @@ static void kvm_patch_ins_mtmsr(u32 *inst, u32 rt)
 	/* Modify the chunk to fit the invocation */
 	memcpy(p, kvm_emulate_mtmsr, kvm_emulate_mtmsr_len * 4);
 	p[kvm_emulate_mtmsr_branch_offs] |= distance_end & KVM_INST_B_MASK;
-	p[kvm_emulate_mtmsr_reg1_offs] |= rt;
-	p[kvm_emulate_mtmsr_reg2_offs] |= rt;
-	p[kvm_emulate_mtmsr_reg3_offs] |= rt;
+
+	/* Make clobbered registers work too */
+	switch (get_rt(rt)) {
+	case 30:
+		kvm_patch_ins_ll(&p[kvm_emulate_mtmsr_reg1_offs],
+				 magic_var(scratch2), KVM_RT_30);
+		kvm_patch_ins_ll(&p[kvm_emulate_mtmsr_reg2_offs],
+				 magic_var(scratch2), KVM_RT_30);
+		break;
+	case 31:
+		kvm_patch_ins_ll(&p[kvm_emulate_mtmsr_reg1_offs],
+				 magic_var(scratch1), KVM_RT_30);
+		kvm_patch_ins_ll(&p[kvm_emulate_mtmsr_reg2_offs],
+				 magic_var(scratch1), KVM_RT_30);
+		break;
+	default:
+		p[kvm_emulate_mtmsr_reg1_offs] |= rt;
+		p[kvm_emulate_mtmsr_reg2_offs] |= rt;
+		break;
+	}
+
 	p[kvm_emulate_mtmsr_orig_ins_offs] = *inst;
 	flush_icache_range((ulong)p, (ulong)p + kvm_emulate_mtmsr_len * 4);
 
@@ -403,9 +430,7 @@ static void kvm_check_ins(u32 *inst, u32 features)
 		break;
 	case KVM_INST_MTMSR:
 	case KVM_INST_MTMSRD_L0:
-		/* We use r30 and r31 during the hook */
-		if (get_rt(inst_rt) < 30)
-			kvm_patch_ins_mtmsr(inst, inst_rt);
+		kvm_patch_ins_mtmsr(inst, inst_rt);
 		break;
 	}
 
diff --git a/arch/powerpc/kernel/kvm_emul.S b/arch/powerpc/kernel/kvm_emul.S
index a6e97e7..6530532 100644
--- a/arch/powerpc/kernel/kvm_emul.S
+++ b/arch/powerpc/kernel/kvm_emul.S
@@ -135,7 +135,8 @@ kvm_emulate_mtmsr:
 
 	/* Find the changed bits between old and new MSR */
 kvm_emulate_mtmsr_reg1:
-	xor	r31, r0, r31
+	ori	r30, r0, 0
+	xor	r31, r30, r31
 
 	/* Check if we need to really do mtmsr */
 	LOAD_REG_IMMEDIATE(r30, MSR_CRITICAL_BITS)
@@ -156,14 +157,17 @@ kvm_emulate_mtmsr_orig_ins:
 
 maybe_stay_in_guest:
 
+	/* Get the target register in r30 */
+kvm_emulate_mtmsr_reg2:
+	ori	r30, r0, 0
+
 	/* Check if we have to fetch an interrupt */
 	lwz	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_INT)(0)
 	cmpwi	r31, 0
 	beq+	no_mtmsr
 
 	/* Check if we may trigger an interrupt */
-kvm_emulate_mtmsr_reg2:
-	andi.	r31, r0, MSR_EE
+	andi.	r31, r30, MSR_EE
 	beq	no_mtmsr
 
 	b	do_mtmsr
@@ -171,8 +175,7 @@ kvm_emulate_mtmsr_reg2:
 no_mtmsr:
 
 	/* Put MSR into magic page because we don't call mtmsr */
-kvm_emulate_mtmsr_reg3:
-	STL64(r0, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
+	STL64(r30, KVM_MAGIC_PAGE + KVM_MAGIC_MSR, 0)
 
 	SCRATCH_RESTORE
 
@@ -193,10 +196,6 @@ kvm_emulate_mtmsr_reg1_offs:
 kvm_emulate_mtmsr_reg2_offs:
 	.long (kvm_emulate_mtmsr_reg2 - kvm_emulate_mtmsr) / 4
 
-.global kvm_emulate_mtmsr_reg3_offs
-kvm_emulate_mtmsr_reg3_offs:
-	.long (kvm_emulate_mtmsr_reg3 - kvm_emulate_mtmsr) / 4
-
 .global kvm_emulate_mtmsr_orig_ins_offs
 kvm_emulate_mtmsr_orig_ins_offs:
 	.long (kvm_emulate_mtmsr_orig_ins - kvm_emulate_mtmsr) / 4
-- 
1.6.0.2


  parent reply	other threads:[~2010-08-31  2:32 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-31  2:31 [PULL 00/35] KVM: PPC: End-August patch queue Alexander Graf
2010-08-31  2:31 ` [PATCH 01/35] KVM: PPC: Move EXIT_DEBUG partially to tracepoints Alexander Graf
2010-08-31  2:31 ` [PATCH 02/35] KVM: PPC: Move book3s_64 mmu map debug print to trace point Alexander Graf
2010-08-31  2:31 ` [PATCH 07/35] KVM: PPC: Preload magic page when in kernel mode Alexander Graf
2010-08-31  2:31 ` [PATCH 08/35] KVM: PPC: Don't flush PTEs on NX/RO hit Alexander Graf
2010-08-31  2:31 ` [PATCH 10/35] KVM: PPC: Move slb debugging to tracepoints Alexander Graf
     [not found] ` <1283221937-21006-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2010-08-31  2:31   ` [PATCH 03/35] KVM: PPC: Add tracepoint for generic mmu map Alexander Graf
2010-08-31  2:31   ` [PATCH 04/35] KVM: PPC: Move pte invalidate debug code to tracepoint Alexander Graf
2010-08-31  2:31   ` [PATCH 05/35] KVM: PPC: Fix sid map search after flush Alexander Graf
2010-08-31  2:31   ` [PATCH 06/35] KVM: PPC: Add tracepoints for generic spte flushes Alexander Graf
2010-08-31  2:31   ` [PATCH 09/35] KVM: PPC: Make invalidation code more reliable Alexander Graf
2010-08-31  2:31   ` [PATCH 11/35] KVM: PPC: Revert "KVM: PPC: Use kernel hash function" Alexander Graf
2010-08-31  2:31   ` [PATCH 12/35] KVM: PPC: Remove unused define Alexander Graf
2010-08-31  2:31   ` [PATCH 16/35] KVM: PPC: Put segment registers in shared page Alexander Graf
2010-08-31  2:32   ` [PATCH 19/35] KVM: PPC: Update int_pending also on dequeue Alexander Graf
2010-08-31  2:32   ` [PATCH 21/35] KVM: PPC: Force enable nap on KVM Alexander Graf
2010-08-31  2:32   ` [PATCH 24/35] KVM: PPC: initialize IVORs in addition to IVPR Alexander Graf
2010-08-31  2:32   ` [PATCH 29/35] KVM: PPC: Fix CONFIG_KVM_GUEST && !CONFIG_KVM case Alexander Graf
2010-08-31  2:32   ` [PATCH 33/35] KVM: PPC: e500_tlb: Fix a minor copy-paste tracing bug Alexander Graf
2010-08-31  2:32   ` [PATCH 35/35] KVM: PPC: Add documentation for magic page enhancements Alexander Graf
2010-08-31  2:31 ` [PATCH 13/35] KVM: PPC: Add feature bitmap for magic page Alexander Graf
2010-08-31  2:31 ` [PATCH 14/35] KVM: PPC: Move BAT handling code into spr handler Alexander Graf
2010-08-31  2:31 ` [PATCH 15/35] KVM: PPC: Interpret SR registers on demand Alexander Graf
2010-08-31  2:31 ` [PATCH 17/35] KVM: PPC: Add mtsrin PV code Alexander Graf
2010-08-31  2:31 ` Alexander Graf [this message]
2010-08-31  2:32 ` [PATCH 20/35] KVM: PPC: Make PV mtmsrd L=1 work with r30 and r31 Alexander Graf
2010-08-31  2:32 ` [PATCH 22/35] KVM: PPC: Implement correct SID mapping on Book3s_32 Alexander Graf
2010-08-31  2:32 ` [PATCH 23/35] KVM: PPC: Don't put MSR_POW in MSR Alexander Graf
2010-08-31  2:32 ` [PATCH 25/35] KVM: PPC: fix compilation of "dump tlbs" debug function Alexander Graf
2010-08-31  2:32 ` [PATCH 26/35] KVM: PPC: allow ppc440gp to pass the compatibility check Alexander Graf
2010-08-31  2:32 ` [PATCH 27/35] KVM: PPC: Enable napping only for Book3s_64 Alexander Graf
2010-08-31  2:32 ` [PATCH 28/35] KVM: PPC: Implement Level interrupts on Book3S Alexander Graf
2010-08-31  2:32 ` [PATCH 30/35] KVM: PPC: Expose level based interrupt cap Alexander Graf
2010-08-31  2:32 ` [PATCH 31/35] KVM: PPC: Implement level interrupts for BookE Alexander Graf
2010-08-31  2:32 ` [PATCH 32/35] KVM: PPC: Document KVM_INTERRUPT ioctl Alexander Graf
2010-08-31  2:32 ` [PATCH 34/35] KVM: PPC: Fix compile error in e500_tlb.c Alexander Graf
2010-09-01  7:50 ` [PULL 00/35] KVM: PPC: End-August patch queue 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=1283221937-21006-19-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.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;
as well as URLs for NNTP newsgroup(s).