2009-10-30 05:47:09 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/ppc_asm.h>
|
|
|
|
#include <asm/kvm_asm.h>
|
|
|
|
#include <asm/reg.h>
|
2011-07-23 07:41:11 +00:00
|
|
|
#include <asm/mmu.h>
|
2009-10-30 05:47:09 +00:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/asm-offsets.h>
|
2010-04-15 22:11:46 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
2009-10-30 05:47:09 +00:00
|
|
|
#include <asm/exception-64s.h>
|
2010-04-15 22:11:46 +00:00
|
|
|
#endif
|
2009-10-30 05:47:09 +00:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* *
|
|
|
|
* Real Mode handlers that need to be in low physical memory *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-04-15 22:11:46 +00:00
|
|
|
#if defined(CONFIG_PPC_BOOK3S_64)
|
|
|
|
|
|
|
|
#define FUNC(name) GLUE(.,name)
|
|
|
|
|
2011-06-29 00:18:26 +00:00
|
|
|
#elif defined(CONFIG_PPC_BOOK3S_32)
|
2010-04-15 22:11:46 +00:00
|
|
|
|
|
|
|
#define FUNC(name) name
|
|
|
|
|
2009-10-30 05:47:09 +00:00
|
|
|
.macro INTERRUPT_TRAMPOLINE intno
|
|
|
|
|
|
|
|
.global kvmppc_trampoline_\intno
|
|
|
|
kvmppc_trampoline_\intno:
|
|
|
|
|
2011-06-29 00:18:26 +00:00
|
|
|
mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
|
2009-10-30 05:47:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First thing to do is to find out if we're coming
|
|
|
|
* from a KVM guest or a Linux process.
|
|
|
|
*
|
2010-04-15 22:11:46 +00:00
|
|
|
* To distinguish, we check a magic byte in the PACA/current
|
2009-10-30 05:47:09 +00:00
|
|
|
*/
|
2011-06-29 00:18:26 +00:00
|
|
|
mfspr r13, SPRN_SPRG_THREAD
|
|
|
|
lwz r13, THREAD_KVM_SVCPU(r13)
|
|
|
|
/* PPC32 can have a NULL pointer - let's check for that */
|
|
|
|
mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */
|
2009-10-30 05:47:09 +00:00
|
|
|
mfcr r12
|
2011-06-29 00:18:26 +00:00
|
|
|
cmpwi r13, 0
|
|
|
|
bne 1f
|
|
|
|
2: mtcr r12
|
|
|
|
mfspr r12, SPRN_SPRG_SCRATCH1
|
|
|
|
mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
|
|
|
|
b kvmppc_resume_\intno /* Get back original handler */
|
|
|
|
|
|
|
|
1: tophys(r13, r13)
|
2011-06-29 00:20:58 +00:00
|
|
|
stw r12, HSTATE_SCRATCH1(r13)
|
2011-06-29 00:18:26 +00:00
|
|
|
mfspr r12, SPRN_SPRG_SCRATCH1
|
2011-06-29 00:20:58 +00:00
|
|
|
stw r12, HSTATE_SCRATCH0(r13)
|
|
|
|
lbz r12, HSTATE_IN_GUEST(r13)
|
2010-01-08 01:58:04 +00:00
|
|
|
cmpwi r12, KVM_GUEST_MODE_NONE
|
2009-10-30 05:47:09 +00:00
|
|
|
bne ..kvmppc_handler_hasmagic_\intno
|
|
|
|
/* No KVM guest? Then jump back to the Linux handler! */
|
2011-06-29 00:20:58 +00:00
|
|
|
lwz r12, HSTATE_SCRATCH1(r13)
|
2011-06-29 00:18:26 +00:00
|
|
|
b 2b
|
2009-10-30 05:47:09 +00:00
|
|
|
|
|
|
|
/* Now we know we're handling a KVM guest */
|
|
|
|
..kvmppc_handler_hasmagic_\intno:
|
2010-01-08 01:58:04 +00:00
|
|
|
|
|
|
|
/* Should we just skip the faulting instruction? */
|
|
|
|
cmpwi r12, KVM_GUEST_MODE_SKIP
|
|
|
|
beq kvmppc_handler_skip_ins
|
|
|
|
|
2009-10-30 05:47:09 +00:00
|
|
|
/* Let's store which interrupt we're handling */
|
|
|
|
li r12, \intno
|
|
|
|
|
|
|
|
/* Jump into the SLB exit code that goes to the highmem handler */
|
|
|
|
b kvmppc_handler_trampoline_exit
|
|
|
|
|
|
|
|
.endm
|
|
|
|
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
|
|
|
|
INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
|
2010-04-15 22:11:46 +00:00
|
|
|
|
2010-01-08 01:58:04 +00:00
|
|
|
/*
|
|
|
|
* Bring us back to the faulting code, but skip the
|
|
|
|
* faulting instruction.
|
|
|
|
*
|
|
|
|
* This is a generic exit path from the interrupt
|
|
|
|
* trampolines above.
|
|
|
|
*
|
|
|
|
* Input Registers:
|
|
|
|
*
|
2010-04-15 22:11:46 +00:00
|
|
|
* R12 = free
|
|
|
|
* R13 = Shadow VCPU (PACA)
|
2011-06-29 00:20:58 +00:00
|
|
|
* HSTATE.SCRATCH0 = guest R12
|
|
|
|
* HSTATE.SCRATCH1 = guest CR
|
2010-04-15 22:11:46 +00:00
|
|
|
* SPRG_SCRATCH0 = guest R13
|
2010-01-08 01:58:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
kvmppc_handler_skip_ins:
|
|
|
|
|
|
|
|
/* Patch the IP to the next instruction */
|
|
|
|
mfsrr0 r12
|
|
|
|
addi r12, r12, 4
|
|
|
|
mtsrr0 r12
|
|
|
|
|
|
|
|
/* Clean up all state */
|
2011-06-29 00:20:58 +00:00
|
|
|
lwz r12, HSTATE_SCRATCH1(r13)
|
2010-01-08 01:58:04 +00:00
|
|
|
mtcr r12
|
2011-06-29 00:20:58 +00:00
|
|
|
PPC_LL r12, HSTATE_SCRATCH0(r13)
|
2011-04-05 03:59:58 +00:00
|
|
|
GET_SCRATCH0(r13)
|
2010-01-08 01:58:04 +00:00
|
|
|
|
|
|
|
/* And get back into the code */
|
|
|
|
RFI
|
2011-06-29 00:18:26 +00:00
|
|
|
#endif
|
2010-01-08 01:58:04 +00:00
|
|
|
|
2009-10-30 05:47:09 +00:00
|
|
|
/*
|
2011-07-23 07:41:44 +00:00
|
|
|
* Call kvmppc_handler_trampoline_enter in real mode
|
2009-10-30 05:47:09 +00:00
|
|
|
*
|
2011-07-23 07:41:44 +00:00
|
|
|
* On entry, r4 contains the guest shadow MSR
|
2012-08-12 23:04:19 +00:00
|
|
|
* MSR.EE has to be 0 when calling this function
|
2009-10-30 05:47:09 +00:00
|
|
|
*/
|
2011-07-23 07:41:44 +00:00
|
|
|
_GLOBAL(kvmppc_entry_trampoline)
|
|
|
|
mfmsr r5
|
|
|
|
LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
|
|
|
|
toreal(r7)
|
|
|
|
|
|
|
|
li r6, MSR_IR | MSR_DR
|
2012-08-12 23:04:19 +00:00
|
|
|
andc r6, r5, r6 /* Clear DR and IR in MSR value */
|
KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu
Currently PR-style KVM keeps the volatile guest register values
(R0 - R13, CR, LR, CTR, XER, PC) in a shadow_vcpu struct rather than
the main kvm_vcpu struct. For 64-bit, the shadow_vcpu exists in two
places, a kmalloc'd struct and in the PACA, and it gets copied back
and forth in kvmppc_core_vcpu_load/put(), because the real-mode code
can't rely on being able to access the kmalloc'd struct.
This changes the code to copy the volatile values into the shadow_vcpu
as one of the last things done before entering the guest. Similarly
the values are copied back out of the shadow_vcpu to the kvm_vcpu
immediately after exiting the guest. We arrange for interrupts to be
still disabled at this point so that we can't get preempted on 64-bit
and end up copying values from the wrong PACA.
This means that the accessor functions in kvm_book3s.h for these
registers are greatly simplified, and are same between PR and HV KVM.
In places where accesses to shadow_vcpu fields are now replaced by
accesses to the kvm_vcpu, we can also remove the svcpu_get/put pairs.
Finally, on 64-bit, we don't need the kmalloc'd struct at all any more.
With this, the time to read the PVR one million times in a loop went
from 567.7ms to 575.5ms (averages of 6 values), an increase of about
1.4% for this worse-case test for guest entries and exits. The
standard deviation of the measurements is about 11ms, so the
difference is only marginally significant statistically.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 04:52:43 +00:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
2012-08-12 23:04:19 +00:00
|
|
|
/*
|
|
|
|
* Set EE in HOST_MSR so that it's enabled when we get into our
|
KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu
Currently PR-style KVM keeps the volatile guest register values
(R0 - R13, CR, LR, CTR, XER, PC) in a shadow_vcpu struct rather than
the main kvm_vcpu struct. For 64-bit, the shadow_vcpu exists in two
places, a kmalloc'd struct and in the PACA, and it gets copied back
and forth in kvmppc_core_vcpu_load/put(), because the real-mode code
can't rely on being able to access the kmalloc'd struct.
This changes the code to copy the volatile values into the shadow_vcpu
as one of the last things done before entering the guest. Similarly
the values are copied back out of the shadow_vcpu to the kvm_vcpu
immediately after exiting the guest. We arrange for interrupts to be
still disabled at this point so that we can't get preempted on 64-bit
and end up copying values from the wrong PACA.
This means that the accessor functions in kvm_book3s.h for these
registers are greatly simplified, and are same between PR and HV KVM.
In places where accesses to shadow_vcpu fields are now replaced by
accesses to the kvm_vcpu, we can also remove the svcpu_get/put pairs.
Finally, on 64-bit, we don't need the kmalloc'd struct at all any more.
With this, the time to read the PVR one million times in a loop went
from 567.7ms to 575.5ms (averages of 6 values), an increase of about
1.4% for this worse-case test for guest entries and exits. The
standard deviation of the measurements is about 11ms, so the
difference is only marginally significant statistically.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 04:52:43 +00:00
|
|
|
* C exit handler function. On 64-bit we delay enabling
|
|
|
|
* interrupts until we have finished transferring stuff
|
|
|
|
* to or from the PACA.
|
2012-08-12 23:04:19 +00:00
|
|
|
*/
|
|
|
|
ori r5, r5, MSR_EE
|
KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu
Currently PR-style KVM keeps the volatile guest register values
(R0 - R13, CR, LR, CTR, XER, PC) in a shadow_vcpu struct rather than
the main kvm_vcpu struct. For 64-bit, the shadow_vcpu exists in two
places, a kmalloc'd struct and in the PACA, and it gets copied back
and forth in kvmppc_core_vcpu_load/put(), because the real-mode code
can't rely on being able to access the kmalloc'd struct.
This changes the code to copy the volatile values into the shadow_vcpu
as one of the last things done before entering the guest. Similarly
the values are copied back out of the shadow_vcpu to the kvm_vcpu
immediately after exiting the guest. We arrange for interrupts to be
still disabled at this point so that we can't get preempted on 64-bit
and end up copying values from the wrong PACA.
This means that the accessor functions in kvm_book3s.h for these
registers are greatly simplified, and are same between PR and HV KVM.
In places where accesses to shadow_vcpu fields are now replaced by
accesses to the kvm_vcpu, we can also remove the svcpu_get/put pairs.
Finally, on 64-bit, we don't need the kmalloc'd struct at all any more.
With this, the time to read the PVR one million times in a loop went
from 567.7ms to 575.5ms (averages of 6 values), an increase of about
1.4% for this worse-case test for guest entries and exits. The
standard deviation of the measurements is about 11ms, so the
difference is only marginally significant statistically.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2013-09-20 04:52:43 +00:00
|
|
|
#endif
|
2012-08-12 23:04:19 +00:00
|
|
|
mtsrr0 r7
|
2010-01-08 01:58:03 +00:00
|
|
|
mtsrr1 r6
|
2010-01-08 01:58:06 +00:00
|
|
|
RFI
|
|
|
|
|
2010-04-15 22:11:48 +00:00
|
|
|
#include "book3s_segment.S"
|