Kernel KVM-PPC virtualization development
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 03/27] KVM: PPC: Add SR swapping code
Date: Thu, 15 Apr 2010 22:11:34 +0000	[thread overview]
Message-ID: <1271369518-11247-4-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1271369518-11247-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>

Later in this series we will move the current segment switch code to
generic code and make that call hooks for the specific sub-archs (32
vs. 64 bit). This is the hook for 32 bits.

It enabled the entry and exit code to swap segment registers with
values from the shadow cpu structure.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/powerpc/kvm/book3s_32_sr.S |  143 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/kvm/book3s_32_sr.S

diff --git a/arch/powerpc/kvm/book3s_32_sr.S b/arch/powerpc/kvm/book3s_32_sr.S
new file mode 100644
index 0000000..3608471
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_32_sr.S
@@ -0,0 +1,143 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf <agraf@suse.de>
+ */
+
+/******************************************************************************
+ *                                                                            *
+ *                               Entry code                                   *
+ *                                                                            *
+ *****************************************************************************/
+
+.macro LOAD_GUEST_SEGMENTS
+
+	/* Required state:
+	 *
+	 * MSR = ~IR|DR
+	 * R1 = host R1
+	 * R2 = host R2
+	 * R3 = shadow vcpu
+	 * all other volatile GPRS = free
+	 * SVCPU[CR]  = guest CR
+	 * SVCPU[XER] = guest XER
+	 * SVCPU[CTR] = guest CTR
+	 * SVCPU[LR]  = guest LR
+	 */
+
+#define XCHG_SR(n)	lwz	r9, (SVCPU_SR+(n*4))(r3);  \
+			mtsr	n, r9
+
+	XCHG_SR(0)
+	XCHG_SR(1)
+	XCHG_SR(2)
+	XCHG_SR(3)
+	XCHG_SR(4)
+	XCHG_SR(5)
+	XCHG_SR(6)
+	XCHG_SR(7)
+	XCHG_SR(8)
+	XCHG_SR(9)
+	XCHG_SR(10)
+	XCHG_SR(11)
+	XCHG_SR(12)
+	XCHG_SR(13)
+	XCHG_SR(14)
+	XCHG_SR(15)
+
+	/* Clear BATs. */
+
+#define KVM_KILL_BAT(n, reg)		\
+        mtspr   SPRN_IBAT##n##U,reg;	\
+        mtspr   SPRN_IBAT##n##L,reg;	\
+        mtspr   SPRN_DBAT##n##U,reg;	\
+        mtspr   SPRN_DBAT##n##L,reg;	\
+
+        li	r9, 0
+	KVM_KILL_BAT(0, r9)
+	KVM_KILL_BAT(1, r9)
+	KVM_KILL_BAT(2, r9)
+	KVM_KILL_BAT(3, r9)
+
+.endm
+
+/******************************************************************************
+ *                                                                            *
+ *                               Exit code                                    *
+ *                                                                            *
+ *****************************************************************************/
+
+.macro LOAD_HOST_SEGMENTS
+
+	/* Register usage at this point:
+	 *
+	 * R1         = host R1
+	 * R2         = host R2
+	 * R12        = exit handler id
+	 * R13        = shadow vcpu - SHADOW_VCPU_OFF
+	 * SVCPU.*    = guest *
+	 * SVCPU[CR]  = guest CR
+	 * SVCPU[XER] = guest XER
+	 * SVCPU[CTR] = guest CTR
+	 * SVCPU[LR]  = guest LR
+	 *
+	 */
+
+	/* Restore BATs */
+
+	/* We only overwrite the upper part, so we only restoree
+	   the upper part. */
+#define KVM_LOAD_BAT(n, reg, RA, RB)	\
+	lwz	RA,(n*16)+0(reg);	\
+	lwz	RB,(n*16)+4(reg);	\
+	mtspr	SPRN_IBAT##n##U,RA;	\
+	mtspr	SPRN_IBAT##n##L,RB;	\
+	lwz	RA,(n*16)+8(reg);	\
+	lwz	RB,(n*16)+12(reg);	\
+	mtspr	SPRN_DBAT##n##U,RA;	\
+	mtspr	SPRN_DBAT##n##L,RB;	\
+
+	lis     r9, BATS@ha
+	addi    r9, r9, BATS@l
+	tophys(r9, r9)
+	KVM_LOAD_BAT(0, r9, r10, r11)
+	KVM_LOAD_BAT(1, r9, r10, r11)
+	KVM_LOAD_BAT(2, r9, r10, r11)
+	KVM_LOAD_BAT(3, r9, r10, r11)
+
+	/* Restore Segment Registers */
+
+	/* 0xc - 0xf */
+
+        li      r0, 4
+        mtctr   r0
+	LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc))
+        lis     r4, 0xc000
+3:      mtsrin  r3, r4
+        addi    r3, r3, 0x111     /* increment VSID */
+        addis   r4, r4, 0x1000    /* address of next segment */
+        bdnz    3b
+
+	/* 0x0 - 0xb */
+
+	/* 'current->mm' needs to be in r4 */
+	tophys(r4, r2)
+	lwz	r4, MM(r4)
+	tophys(r4, r4)
+	/* This only clobbers r0, r3, r4 and r5 */
+	bl	switch_mmu_context
+
+.endm
-- 
1.6.0.2


  parent reply	other threads:[~2010-04-15 22:11 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-15 22:11 [PATCH 00/27] Book3S_32 (PPC32) KVM support Alexander Graf
2010-04-15 22:11 ` [PATCH 05/27] PPC: Split context init/destroy functions Alexander Graf
2010-04-16  6:46   ` Benjamin Herrenschmidt
2010-04-15 22:11 ` [PATCH 06/27] KVM: PPC: Add kvm_book3s_64.h Alexander Graf
2010-04-15 22:11 ` [PATCH 07/27] KVM: PPC: Add kvm_book3s_32.h Alexander Graf
2010-04-15 22:11 ` [PATCH 08/27] KVM: PPC: Add fields to shadow vcpu Alexander Graf
     [not found] ` <1271369518-11247-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2010-04-15 22:11   ` [PATCH 01/27] KVM: PPC: Name generic 64-bit code generic Alexander Graf
2010-04-21  9:29     ` Avi Kivity
2010-04-15 22:11   ` [PATCH 02/27] KVM: PPC: Add host MMU Support Alexander Graf
2010-04-15 22:11   ` Alexander Graf [this message]
2010-04-15 22:11   ` [PATCH 04/27] KVM: PPC: Add generic segment switching code Alexander Graf
2010-04-15 22:11   ` [PATCH 09/27] KVM: PPC: Improve indirect svcpu accessors Alexander Graf
2010-04-15 22:11   ` [PATCH 10/27] KVM: PPC: Use KVM_BOOK3S_HANDLER Alexander Graf
2010-04-15 22:11   ` [PATCH 11/27] KVM: PPC: Use CONFIG_PPC_BOOK3S define Alexander Graf
2010-04-15 22:11   ` [PATCH 13/27] KVM: PPC: Use now shadowed vcpu fields Alexander Graf
2010-04-15 22:11   ` [PATCH 14/27] KVM: PPC: Extract MMU init Alexander Graf
2010-04-15 22:11   ` [PATCH 15/27] KVM: PPC: Make real mode handler generic Alexander Graf
2010-04-15 22:11   ` [PATCH 16/27] KVM: PPC: Make highmem code generic Alexander Graf
2010-04-15 22:11   ` [PATCH 17/27] KVM: PPC: Make SLB switching code the new segment framework Alexander Graf
2010-04-15 22:11   ` [PATCH 18/27] KVM: PPC: Release clean pages as clean Alexander Graf
2010-04-15 22:11   ` [PATCH 23/27] KVM: PPC: Export MMU variables Alexander Graf
     [not found]     ` <1271369518-11247-24-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2010-04-16  6:47       ` Benjamin Herrenschmidt
2010-04-16  9:07         ` Alexander Graf
     [not found]           ` <41F9F369-9F53-43E8-AC1F-1C67DD918991-l3A5Bk7waGM@public.gmane.org>
2010-04-16  9:22             ` Benjamin Herrenschmidt
2010-04-16  9:25               ` Alexander Graf
2010-04-16  9:31                 ` Alexander Graf
     [not found]                   ` <8EEEAFCF-CB31-4BD9-A917-08B5B6E40400-l3A5Bk7waGM@public.gmane.org>
2010-04-16 11:18                     ` Alexander Graf
2010-04-15 22:11   ` [PATCH 24/27] PPC: Export SWITCH_FRAME_SIZE Alexander Graf
2010-04-16  6:48     ` Benjamin Herrenschmidt
2010-04-15 22:11   ` [PATCH 25/27] KVM: PPC: Check max IRQ prio Alexander Graf
2010-04-21  9:42   ` [PATCH 00/27] Book3S_32 (PPC32) KVM support Avi Kivity
2010-04-15 22:11 ` [PATCH 12/27] PPC: Add STLU Alexander Graf
2010-04-16  6:47   ` Benjamin Herrenschmidt
2010-04-15 22:11 ` [PATCH 19/27] KVM: PPC: Remove fetch fail code Alexander Graf
2010-04-15 22:11 ` [PATCH 20/27] KVM: PPC: Add SVCPU to Book3S_32 Alexander Graf
2010-04-15 22:11 ` [PATCH 21/27] KVM: PPC: Emulate segment fault Alexander Graf
2010-04-15 22:11 ` [PATCH 22/27] KVM: PPC: Add Book3S compatibility code Alexander Graf
2010-04-15 22:11 ` [PATCH 26/27] KVM: PPC: Add KVM intercept handlers Alexander Graf
     [not found]   ` <1271369518-11247-27-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2010-04-16  6:48     ` Benjamin Herrenschmidt
2010-04-15 22:11 ` [PATCH 27/27] KVM: PPC: Enable Book3S_32 KVM building 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=1271369518-11247-4-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.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