[PATCH 23/27] KVM: PPC: PV assembler helpers

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Alexander Graf
Date: Thursday, July 1, 2010 - 3:42 am

When we hook an instruction we need to make sure we don't clobber any of
the registers at that point. So we write them out to scratch space in the
magic page. To make sure we don't fall into a race with another piece of
hooked code, we need to disable interrupts.

To make the later patches and code in general easier readable, let's introduce
a set of defines that save and restore r30, r31 and cr. Let's also define some
helpers to read the lower 32 bits of a 64 bit field on 32 bit systems.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/kernel/kvm_emul.S |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/kvm_emul.S b/arch/powerpc/kernel/kvm_emul.S
index c7b9fc9..7da835a 100644
--- a/arch/powerpc/kernel/kvm_emul.S
+++ b/arch/powerpc/kernel/kvm_emul.S
@@ -25,3 +25,32 @@
 
 #define KVM_MAGIC_PAGE		(-4096)
 
+#ifdef CONFIG_64BIT
+#define LL64(reg, offs, reg2)	ld	reg, (offs)(reg2)
+#define STL64(reg, offs, reg2)	std	reg, (offs)(reg2)
+#else
+#define LL64(reg, offs, reg2)	lwz	reg, (offs + 4)(reg2)
+#define STL64(reg, offs, reg2)	stw	reg, (offs + 4)(reg2)
+#endif
+
+#define SCRATCH_SAVE							\
+	/* Enable critical section. We are critical if			\
+	   shared->critical == r1 */					\
+	STL64(r1, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0);		\
+									\
+	/* Save state */						\
+	PPC_STL	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH1)(0);		\
+	PPC_STL	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH2)(0);		\
+	mfcr	r31;							\
+	stw	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH3)(0);
+
+#define SCRATCH_RESTORE							\
+	/* Restore state */						\
+	PPC_LL	r31, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH1)(0);		\
+	lwz	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH3)(0);		\
+	mtcr	r30;							\
+	PPC_LL	r30, (KVM_MAGIC_PAGE + KVM_MAGIC_SCRATCH2)(0);		\
+									\
+	/* Disable critical section. We are critical if			\
+	   shared->critical == r1 and r2 is always != r1 */		\
+	STL64(r2, KVM_MAGIC_PAGE + KVM_MAGIC_CRITICAL, 0);
-- 
1.6.0.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/27] KVM PPC PV framework, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 01/27] KVM: PPC: Introduce shared page, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 02/27] KVM: PPC: Convert MSR to shared page, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 03/27] KVM: PPC: Convert DSISR to shared page, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 04/27] KVM: PPC: Convert DAR to shared page., Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 07/27] KVM: PPC: Implement hypervisor interface, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 08/27] KVM: PPC: Add PV guest critical sections, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 09/27] KVM: PPC: Add PV guest scratch registers, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 11/27] KVM: PPC: Make RMO a define, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 13/27] KVM: PPC: Magic Page Book3s support, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 14/27] KVM: PPC: Magic Page BookE support, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 17/27] KVM: PPC: Generic KVM PV guest support, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 18/27] KVM: PPC: KVM PV guest stubs, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 20/27] KVM: PPC: PV tlbsync to nop, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 21/27] KVM: PPC: Introduce kvm_tmp framework, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 22/27] KVM: PPC: Introduce branch patching helper, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 23/27] KVM: PPC: PV assembler helpers, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 24/27] KVM: PPC: PV mtmsrd L=1, Alexander Graf, (Thu Jul 1, 3:42 am)
[PATCH 25/27] KVM: PPC: PV mtmsrd L=0 and mtmsr, Alexander Graf, (Thu Jul 1, 3:43 am)
[PATCH 26/27] KVM: PPC: PV wrteei, Alexander Graf, (Thu Jul 1, 3:43 am)
Re: [PATCH 14/27] KVM: PPC: Magic Page BookE support, Alexander Graf, (Thu Jul 1, 5:25 am)
Re: [PATCH 16/27] KVM: Move kvm_guest_init out of generic code, Geert Uytterhoeven, (Fri Jul 2, 12:41 am)
Re: [PATCH 13/27] KVM: PPC: Magic Page Book3s support, Alexander Graf, (Fri Jul 2, 8:37 am)
Re: [PATCH 00/27] KVM PPC PV framework, Segher Boessenkool, (Fri Jul 2, 9:22 am)
Re: [PATCH 11/27] KVM: PPC: Make RMO a define, Segher Boessenkool, (Fri Jul 2, 9:23 am)
Re: [PATCH 27/27] KVM: PPC: Add Documentation about PV int ..., Segher Boessenkool, (Fri Jul 2, 9:27 am)
Re: [PATCH 00/27] KVM PPC PV framework, Alexander Graf, (Fri Jul 2, 9:59 am)
Re: [PATCH 27/27] KVM: PPC: Add Documentation about PV int ..., Benjamin Herrenschmidt, (Sat Jul 3, 3:41 pm)
Re: [PATCH 27/27] KVM: PPC: Add Documentation about PV int ..., Benjamin Herrenschmidt, (Sat Jul 3, 3:42 pm)
Re: [PATCH 00/27] KVM PPC PV framework, MJ embd, (Thu Jul 8, 9:57 pm)
Re: [PATCH 00/27] KVM PPC PV framework, Alexander Graf, (Thu Jul 8, 11:33 pm)
RE: [PATCH 14/27] KVM: PPC: Magic Page BookE support, Liu Yu-B13201, (Mon Jul 12, 4:24 am)