2010-04-16 02:11:35 +04:00
/ *
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify
* it u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e , v e r s i o n 2 , a s
* published b y t h e F r e e S o f t w a r e F o u n d a t i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* along w i t h t h i s p r o g r a m ; if not, write to the Free Software
* Foundation, 5 1 F r a n k l i n S t r e e t , F i f t h F l o o r , B o s t o n , M A 0 2 1 1 0 - 1 3 0 1 , U S A .
*
* Copyright S U S E L i n u x P r o d u c t s G m b H 2 0 1 0
*
* Authors : Alexander G r a f < a g r a f @suse.de>
* /
/* Real mode helpers */
# if d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 6 4 )
# define G E T _ S H A D O W _ V C P U ( r e g ) \
2011-06-29 04:20:58 +04:00
mr r e g , r13
2010-04-16 02:11:35 +04:00
# elif d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 3 2 )
# define G E T _ S H A D O W _ V C P U ( r e g ) \
tophys( r e g , r2 ) ; \
lwz r e g , ( T H R E A D + T H R E A D _ K V M _ S V C P U ) ( r e g ) ; \
tophys( r e g , r e g )
# endif
/* Disable for nested KVM */
# define U S E _ Q U I C K _ L A S T _ I N S T
/* Get helper functions for subarch specific functionality */
# if d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 6 4 )
# include " b o o k 3 s _ 6 4 _ s l b . S "
# elif d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 3 2 )
# include " b o o k 3 s _ 3 2 _ s r . S "
# endif
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Entry c o d e *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
.global kvmppc_handler_trampoline_enter
kvmppc_handler_trampoline_enter :
/ * Required s t a t e :
*
* MSR = ~ I R | D R
* R1 = h o s t R 1
* R2 = h o s t R 2
2011-07-23 11:41:44 +04:00
* R4 = g u e s t s h a d o w M S R
* R5 = n o r m a l h o s t M S R
* R6 = c u r r e n t h o s t M S R ( E E , I R , D R o f f )
* LR = h i g h m e m g u e s t e x i t c o d e
2010-04-16 02:11:35 +04:00
* all o t h e r v o l a t i l e G P R S = f r e e
* SVCPU[ C R ] = g u e s t C R
* SVCPU[ X E R ] = g u e s t X E R
* SVCPU[ C T R ] = g u e s t C T R
* SVCPU[ L R ] = g u e s t L R
* /
/* r3 = shadow vcpu */
GET_ S H A D O W _ V C P U ( r3 )
2011-07-23 11:41:44 +04:00
/* Save guest exit handler address and MSR */
mflr r0
PPC_ S T L r0 , H S T A T E _ V M H A N D L E R ( r3 )
PPC_ S T L r5 , H S T A T E _ H O S T _ M S R ( r3 )
2011-06-29 04:20:58 +04:00
/* Save R1/R2 in the PACA (64-bit) or shadow_vcpu (32-bit) */
PPC_ S T L r1 , H S T A T E _ H O S T _ R 1 ( r3 )
PPC_ S T L r2 , H S T A T E _ H O S T _ R 2 ( r3 )
2010-04-16 02:11:35 +04:00
/* Activate guest mode, so faults get handled by KVM */
li r11 , K V M _ G U E S T _ M O D E _ G U E S T
2011-06-29 04:20:58 +04:00
stb r11 , H S T A T E _ I N _ G U E S T ( r3 )
2010-04-16 02:11:35 +04:00
/* Switch to guest segment. This is subarch specific. */
LOAD_ G U E S T _ S E G M E N T S
2011-07-23 11:41:44 +04:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 6 4
2014-04-29 18:48:44 +04:00
BEGIN_ F T R _ S E C T I O N
/* Save host FSCR */
mfspr r8 , S P R N _ F S C R
std r8 , H S T A T E _ H O S T _ F S C R ( r13 )
/* Set FSCR during guest execution */
ld r9 , S V C P U _ S H A D O W _ F S C R ( r13 )
mtspr S P R N _ F S C R , r9
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A R C H _ 2 0 7 S )
2011-07-23 11:41:44 +04:00
/ * Some g u e s t s m a y n e e d t o h a v e d c b z s e t t o 3 2 b y t e l e n g t h .
*
* Usually w e e n s u r e t h a t b y p a t c h i n g t h e g u e s t ' s i n s t r u c t i o n s
* to t r a p o n d c b z a n d e m u l a t e i t i n t h e h y p e r v i s o r .
*
* If w e c a n , w e s h o u l d t e l l t h e C P U t o u s e 3 2 b y t e d c b z t h o u g h ,
* because t h a t ' s a l o t f a s t e r .
* /
lbz r0 , H S T A T E _ R E S T O R E _ H I D 5 ( r3 )
cmpwi r0 , 0
beq n o _ d c b z 3 2 _ o n
mfspr r0 ,S P R N _ H I D 5
ori r0 , r0 , 0 x80 / * X X X H I D 5 _ d c b z 3 2 = 0 x80 * /
mtspr S P R N _ H I D 5 ,r0
no_dcbz32_on :
# endif / * C O N F I G _ P P C _ B O O K 3 S _ 6 4 * /
2010-04-16 02:11:35 +04:00
/* Enter guest */
2011-07-23 11:41:44 +04:00
PPC_ L L r8 , S V C P U _ C T R ( r3 )
PPC_ L L r9 , S V C P U _ L R ( r3 )
lwz r10 , S V C P U _ C R ( r3 )
2015-05-27 02:56:57 +03:00
PPC_ L L r11 , S V C P U _ X E R ( r3 )
2011-07-23 11:41:44 +04:00
mtctr r8
mtlr r9
mtcr r10
mtxer r11
2010-04-16 02:11:35 +04:00
2011-07-23 11:41:44 +04:00
/* Move SRR0 and SRR1 into the respective regs */
PPC_ L L r9 , S V C P U _ P C ( r3 )
/* First clear RI in our current MSR value */
li r0 , M S R _ R I
andc r6 , r6 , r0
2010-04-16 02:11:35 +04:00
KVM: PPC: Add support for Book3S processors in hypervisor mode
This adds support for KVM running on 64-bit Book 3S processors,
specifically POWER7, in hypervisor mode. Using hypervisor mode means
that the guest can use the processor's supervisor mode. That means
that the guest can execute privileged instructions and access privileged
registers itself without trapping to the host. This gives excellent
performance, but does mean that KVM cannot emulate a processor
architecture other than the one that the hardware implements.
This code assumes that the guest is running paravirtualized using the
PAPR (Power Architecture Platform Requirements) interface, which is the
interface that IBM's PowerVM hypervisor uses. That means that existing
Linux distributions that run on IBM pSeries machines will also run
under KVM without modification. In order to communicate the PAPR
hypercalls to qemu, this adds a new KVM_EXIT_PAPR_HCALL exit code
to include/linux/kvm.h.
Currently the choice between book3s_hv support and book3s_pr support
(i.e. the existing code, which runs the guest in user mode) has to be
made at kernel configuration time, so a given kernel binary can only
do one or the other.
This new book3s_hv code doesn't support MMIO emulation at present.
Since we are running paravirtualized guests, this isn't a serious
restriction.
With the guest running in supervisor mode, most exceptions go straight
to the guest. We will never get data or instruction storage or segment
interrupts, alignment interrupts, decrementer interrupts, program
interrupts, single-step interrupts, etc., coming to the hypervisor from
the guest. Therefore this introduces a new KVMTEST_NONHV macro for the
exception entry path so that we don't have to do the KVM test on entry
to those exception handlers.
We do however get hypervisor decrementer, hypervisor data storage,
hypervisor instruction storage, and hypervisor emulation assist
interrupts, so we have to handle those.
In hypervisor mode, real-mode accesses can access all of RAM, not just
a limited amount. Therefore we put all the guest state in the vcpu.arch
and use the shadow_vcpu in the PACA only for temporary scratch space.
We allocate the vcpu with kzalloc rather than vzalloc, and we don't use
anything in the kvmppc_vcpu_book3s struct, so we don't allocate it.
We don't have a shared page with the guest, but we still need a
kvm_vcpu_arch_shared struct to store the values of various registers,
so we include one in the vcpu_arch struct.
The POWER7 processor has a restriction that all threads in a core have
to be in the same partition. MMU-on kernel code counts as a partition
(partition 0), so we have to do a partition switch on every entry to and
exit from the guest. At present we require the host and guest to run
in single-thread mode because of this hardware restriction.
This code allocates a hashed page table for the guest and initializes
it with HPTEs for the guest's Virtual Real Memory Area (VRMA). We
require that the guest memory is allocated using 16MB huge pages, in
order to simplify the low-level memory management. This also means that
we can get away without tracking paging activity in the host for now,
since huge pages can't be paged or swapped.
This also adds a few new exports needed by the book3s_hv code.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-06-29 04:21:34 +04:00
PPC_ L L r0 , S V C P U _ R 0 ( r3 )
PPC_ L L r1 , S V C P U _ R 1 ( r3 )
PPC_ L L r2 , S V C P U _ R 2 ( r3 )
PPC_ L L r5 , S V C P U _ R 5 ( r3 )
PPC_ L L r7 , S V C P U _ R 7 ( r3 )
PPC_ L L r8 , S V C P U _ R 8 ( r3 )
PPC_ L L r10 , S V C P U _ R 1 0 ( r3 )
PPC_ L L r11 , S V C P U _ R 1 1 ( r3 )
PPC_ L L r12 , S V C P U _ R 1 2 ( r3 )
PPC_ L L r13 , S V C P U _ R 1 3 ( r3 )
2010-04-16 02:11:35 +04:00
2012-04-25 16:28:23 +04:00
MTMSR_ E E R I ( r6 )
mtsrr0 r9
mtsrr1 r4
PPC_ L L r4 , S V C P U _ R 4 ( r3 )
PPC_ L L r6 , S V C P U _ R 6 ( r3 )
PPC_ L L r9 , S V C P U _ R 9 ( r3 )
2010-04-16 02:11:35 +04:00
PPC_ L L r3 , ( S V C P U _ R 3 ) ( r3 )
RFI
kvmppc_handler_trampoline_enter_end :
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Exit c o d e *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
.global kvmppc_handler_trampoline_exit
kvmppc_handler_trampoline_exit :
2013-10-07 20:47:55 +04:00
.global kvmppc_interrupt_pr
kvmppc_interrupt_pr :
2011-06-29 04:18:26 +04:00
2010-04-16 02:11:35 +04:00
/ * Register u s a g e a t t h i s p o i n t :
*
* SPRG_ S C R A T C H 0 = g u e s t R 1 3
* R1 2 = e x i t h a n d l e r i d
2011-06-29 04:20:58 +04:00
* R1 3 = s h a d o w v c p u ( 3 2 - b i t ) o r P A C A ( 6 4 - b i t )
* HSTATE. S C R A T C H 0 = g u e s t R 1 2
* HSTATE. S C R A T C H 1 = g u e s t C R
2010-04-16 02:11:35 +04:00
*
* /
/* Save registers */
2011-06-29 04:20:58 +04:00
PPC_ S T L r0 , S V C P U _ R 0 ( r13 )
PPC_ S T L r1 , S V C P U _ R 1 ( r13 )
PPC_ S T L r2 , S V C P U _ R 2 ( r13 )
PPC_ S T L r3 , S V C P U _ R 3 ( r13 )
PPC_ S T L r4 , S V C P U _ R 4 ( r13 )
PPC_ S T L r5 , S V C P U _ R 5 ( r13 )
PPC_ S T L r6 , S V C P U _ R 6 ( r13 )
PPC_ S T L r7 , S V C P U _ R 7 ( r13 )
PPC_ S T L r8 , S V C P U _ R 8 ( r13 )
PPC_ S T L r9 , S V C P U _ R 9 ( r13 )
PPC_ S T L r10 , S V C P U _ R 1 0 ( r13 )
PPC_ S T L r11 , S V C P U _ R 1 1 ( r13 )
2010-04-16 02:11:35 +04:00
/* Restore R1/R2 so we can handle faults */
2011-06-29 04:20:58 +04:00
PPC_ L L r1 , H S T A T E _ H O S T _ R 1 ( r13 )
PPC_ L L r2 , H S T A T E _ H O S T _ R 2 ( r13 )
2010-04-16 02:11:35 +04:00
/* Save guest PC and MSR */
2011-06-29 04:18:26 +04:00
# ifdef C O N F I G _ P P C 6 4
BEGIN_ F T R _ S E C T I O N
2012-05-10 05:58:50 +04:00
andi. r0 , r12 , 0 x2
cmpwi c r1 , r0 , 0
2011-04-05 08:20:31 +04:00
beq 1 f
mfspr r3 ,S P R N _ H S R R 0
mfspr r4 ,S P R N _ H S R R 1
andi. r12 ,r12 ,0 x3 f f d
b 2 f
powerpc, KVM: Split HVMODE_206 cpu feature bit into separate HV and architecture bits
This replaces the single CPU_FTR_HVMODE_206 bit with two bits, one to
indicate that we have a usable hypervisor mode, and another to indicate
that the processor conforms to PowerISA version 2.06. We also add
another bit to indicate that the processor conforms to ISA version 2.01
and set that for PPC970 and derivatives.
Some PPC970 chips (specifically those in Apple machines) have a
hypervisor mode in that MSR[HV] is always 1, but the hypervisor mode
is not useful in the sense that there is no way to run any code in
supervisor mode (HV=0 PR=0). On these processors, the LPES0 and LPES1
bits in HID4 are always 0, and we use that as a way of detecting that
hypervisor mode is not useful.
Where we have a feature section in assembly code around code that
only applies on POWER7 in hypervisor mode, we use a construct like
END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
The definition of END_FTR_SECTION_IFSET is such that the code will
be enabled (not overwritten with nops) only if all bits in the
provided mask are set.
Note that the CPU feature check in __tlbie() only needs to check the
ARCH_206 bit, not the HVMODE bit, because __tlbie() can only get called
if we are running bare-metal, i.e. in hypervisor mode.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-06-29 04:26:11 +04:00
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ H V M O D E )
2011-06-29 04:18:26 +04:00
# endif
2011-04-05 08:20:31 +04:00
1 : mfsrr0 r3
2010-04-16 02:11:35 +04:00
mfsrr1 r4
2011-04-05 08:20:31 +04:00
2 :
2011-06-29 04:20:58 +04:00
PPC_ S T L r3 , S V C P U _ P C ( r13 )
PPC_ S T L r4 , S V C P U _ S H A D O W _ S R R 1 ( r13 )
2010-04-16 02:11:35 +04:00
/* Get scratch'ed off registers */
2011-04-05 07:59:58 +04:00
GET_ S C R A T C H 0 ( r9 )
2011-06-29 04:20:58 +04:00
PPC_ L L r8 , H S T A T E _ S C R A T C H 0 ( r13 )
lwz r7 , H S T A T E _ S C R A T C H 1 ( r13 )
2010-04-16 02:11:35 +04:00
2011-06-29 04:20:58 +04:00
PPC_ S T L r9 , S V C P U _ R 1 3 ( r13 )
PPC_ S T L r8 , S V C P U _ R 1 2 ( r13 )
stw r7 , S V C P U _ C R ( r13 )
2010-04-16 02:11:35 +04:00
/* Save more register state */
mfxer r5
mfdar r6
mfdsisr r7
mfctr r8
mflr r9
2015-05-27 02:56:57 +03:00
PPC_ S T L r5 , S V C P U _ X E R ( r13 )
2011-06-29 04:20:58 +04:00
PPC_ S T L r6 , S V C P U _ F A U L T _ D A R ( r13 )
stw r7 , S V C P U _ F A U L T _ D S I S R ( r13 )
PPC_ S T L r8 , S V C P U _ C T R ( r13 )
PPC_ S T L r9 , S V C P U _ L R ( r13 )
2010-04-16 02:11:35 +04:00
/ *
* In o r d e r f o r u s t o e a s i l y g e t t h e l a s t i n s t r u c t i o n ,
* we g o t t h e #v m e x i t a t , w e e x p l o i t t h e f a c t t h a t t h e
* virtual l a y o u t i s s t i l l t h e s a m e h e r e , s o w e c a n j u s t
* ld f r o m t h e g u e s t ' s P C a d d r e s s
* /
/* We only load the last instruction when it's safe */
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ D A T A _ S T O R A G E
beq l d _ l a s t _ i n s t
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ P R O G R A M
beq l d _ l a s t _ i n s t
2011-08-08 18:11:36 +04:00
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ S Y S C A L L
beq l d _ l a s t _ p r e v _ i n s t
2010-04-20 04:49:49 +04:00
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ A L I G N M E N T
beq- l d _ l a s t _ i n s t
2012-05-10 05:54:58 +04:00
# ifdef C O N F I G _ P P C 6 4
BEGIN_ F T R _ S E C T I O N
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ H _ E M U L _ A S S I S T
beq- l d _ l a s t _ i n s t
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ H V M O D E )
2014-04-29 18:48:44 +04:00
BEGIN_ F T R _ S E C T I O N
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ F A C _ U N A V A I L
beq- l d _ l a s t _ i n s t
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A R C H _ 2 0 7 S )
2012-05-10 05:54:58 +04:00
# endif
2010-04-16 02:11:35 +04:00
b n o _ l d _ l a s t _ i n s t
2011-08-08 18:11:36 +04:00
ld_last_prev_inst :
addi r3 , r3 , - 4
2010-04-16 02:11:35 +04:00
ld_last_inst :
/* Save off the guest instruction we're at */
/* In case lwz faults */
li r0 , K V M _ I N S T _ F E T C H _ F A I L E D
# ifdef U S E _ Q U I C K _ L A S T _ I N S T
/ * Set g u e s t m o d e t o ' j u m p o v e r i n s t r u c t i o n ' s o i f l w z f a u l t s
* we' l l j u s t c o n t i n u e a t t h e n e x t I P . * /
li r9 , K V M _ G U E S T _ M O D E _ S K I P
2011-06-29 04:20:58 +04:00
stb r9 , H S T A T E _ I N _ G U E S T ( r13 )
2010-04-16 02:11:35 +04:00
/* 1) enable paging for data */
mfmsr r9
ori r11 , r9 , M S R _ D R / * E n a b l e p a g i n g f o r d a t a * /
mtmsr r11
sync
/* 2) fetch the instruction */
lwz r0 , 0 ( r3 )
/* 3) disable paging again */
mtmsr r9
sync
# endif
2011-06-29 04:20:58 +04:00
stw r0 , S V C P U _ L A S T _ I N S T ( r13 )
2010-04-16 02:11:35 +04:00
no_ld_last_inst :
/* Unset guest mode */
li r9 , K V M _ G U E S T _ M O D E _ N O N E
2011-06-29 04:20:58 +04:00
stb r9 , H S T A T E _ I N _ G U E S T ( r13 )
2010-04-16 02:11:35 +04:00
/* Switch back to host MMU */
LOAD_ H O S T _ S E G M E N T S
2011-07-23 11:41:44 +04:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 6 4
lbz r5 , H S T A T E _ R E S T O R E _ H I D 5 ( r13 )
cmpwi r5 , 0
beq n o _ d c b z 3 2 _ o f f
li r4 , 0
mfspr r5 ,S P R N _ H I D 5
rldimi r5 ,r4 ,6 ,5 6
mtspr S P R N _ H I D 5 ,r5
no_dcbz32_off :
2014-04-29 18:48:44 +04:00
BEGIN_ F T R _ S E C T I O N
/* Save guest FSCR on a FAC_UNAVAIL interrupt */
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ F A C _ U N A V A I L
bne+ n o _ f s c r _ s a v e
mfspr r7 , S P R N _ F S C R
std r7 , S V C P U _ S H A D O W _ F S C R ( r13 )
no_fscr_save :
/* Restore host FSCR */
ld r8 , H S T A T E _ H O S T _ F S C R ( r13 )
mtspr S P R N _ F S C R , r8
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A R C H _ 2 0 7 S )
2011-07-23 11:41:44 +04:00
# endif / * C O N F I G _ P P C _ B O O K 3 S _ 6 4 * /
/ *
* For s o m e i n t e r r u p t s , w e n e e d t o c a l l t h e r e a l L i n u x
* handler, s o i t c a n d o w o r k f o r u s . T h i s h a s t o h a p p e n
* as i f t h e i n t e r r u p t a r r i v e d f r o m t h e k e r n e l t h o u g h ,
* so l e t ' s f a k e i t h e r e w h e r e m o s t s t a t e i s r e s t o r e d .
*
* Having s e t u p S R R 0 / 1 w i t h t h e a d d r e s s w h e r e w e w a n t
* to c o n t i n u e w i t h r e l o c a t i o n o n ( p o t e n t i a l l y i n m o d u l e
* space) , w e e i t h e r j u s t g o s t r a i g h t t h e r e w i t h r f i [ d ] ,
2012-04-27 18:33:35 +04:00
* or w e j u m p t o a n i n t e r r u p t h a n d l e r i f t h e r e i s a n
* interrupt t o b e h a n d l e d f i r s t . I n t h e l a t t e r c a s e ,
* the r f i [ d ] a t t h e e n d o f t h e i n t e r r u p t h a n d l e r w i l l
* get u s b a c k t o w h e r e w e w a n t t o c o n t i n u e .
2011-07-23 11:41:44 +04:00
* /
2010-04-16 02:11:35 +04:00
/ * Register u s a g e a t t h i s p o i n t :
*
* R1 = h o s t R 1
* R2 = h o s t R 2
2012-04-27 18:33:35 +04:00
* R1 0 = r a w e x i t h a n d l e r i d
2010-04-16 02:11:35 +04:00
* R1 2 = e x i t h a n d l e r i d
2011-06-29 04:20:58 +04:00
* R1 3 = s h a d o w v c p u ( 3 2 - b i t ) o r P A C A ( 6 4 - b i t )
2010-04-16 02:11:35 +04:00
* SVCPU. * = g u e s t *
*
* /
2011-07-23 11:41:44 +04:00
PPC_ L L r6 , H S T A T E _ H O S T _ M S R ( r13 )
2011-06-29 04:20:58 +04:00
PPC_ L L r8 , H S T A T E _ V M H A N D L E R ( r13 )
2011-07-23 11:41:44 +04:00
2012-04-27 18:33:35 +04:00
# ifdef C O N F I G _ P P C 6 4
BEGIN_ F T R _ S E C T I O N
2012-05-10 05:58:50 +04:00
beq c r1 , 1 f
2012-04-27 18:33:35 +04:00
mtspr S P R N _ H S R R 1 , r6
mtspr S P R N _ H S R R 0 , r8
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ H V M O D E )
# endif
1 : /* Restore host msr -> SRR1 */
2011-07-23 11:41:44 +04:00
mtsrr1 r6
/* Load highmem handler address */
2010-04-16 02:11:35 +04:00
mtsrr0 r8
2011-07-23 11:41:44 +04:00
/* RFI into the highmem handler, or jump to interrupt handler */
2012-04-27 18:33:35 +04:00
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ E X T E R N A L
beqa B O O K 3 S _ I N T E R R U P T _ E X T E R N A L
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ D E C R E M E N T E R
beqa B O O K 3 S _ I N T E R R U P T _ D E C R E M E N T E R
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ P E R F M O N
beqa B O O K 3 S _ I N T E R R U P T _ P E R F M O N
KVM: PPC: Book3S PR: Cope with doorbell interrupts
When the PR host is running on a POWER8 machine in POWER8 mode, it
will use doorbell interrupts for IPIs. If one of them arrives while
we are in the guest, we pop out of the guest with trap number 0xA00,
which isn't handled by kvmppc_handle_exit_pr, leading to the following
BUG_ON:
[ 331.436215] exit_nr=0xa00 | pc=0x1d2c | msr=0x800000000000d032
[ 331.437522] ------------[ cut here ]------------
[ 331.438296] kernel BUG at arch/powerpc/kvm/book3s_pr.c:982!
[ 331.439063] Oops: Exception in kernel mode, sig: 5 [#2]
[ 331.439819] SMP NR_CPUS=1024 NUMA pSeries
[ 331.440552] Modules linked in: tun nf_conntrack_netbios_ns nf_conntrack_broadcast ipt_MASQUERADE ip6t_REJECT xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw virtio_net kvm binfmt_misc ibmvscsi scsi_transport_srp scsi_tgt virtio_blk
[ 331.447614] CPU: 11 PID: 1296 Comm: qemu-system-ppc Tainted: G D 3.11.7-200.2.fc19.ppc64p7 #1
[ 331.448920] task: c0000003bdc8c000 ti: c0000003bd32c000 task.ti: c0000003bd32c000
[ 331.450088] NIP: d0000000025d6b9c LR: d0000000025d6b98 CTR: c0000000004cfdd0
[ 331.451042] REGS: c0000003bd32f420 TRAP: 0700 Tainted: G D (3.11.7-200.2.fc19.ppc64p7)
[ 331.452331] MSR: 800000000282b032 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI> CR: 28004824 XER: 20000000
[ 331.454616] SOFTE: 1
[ 331.455106] CFAR: c000000000848bb8
[ 331.455726]
GPR00: d0000000025d6b98 c0000003bd32f6a0 d0000000026017b8 0000000000000032
GPR04: c0000000018627f8 c000000001873208 320d0a3030303030 3030303030643033
GPR08: c000000000c490a8 0000000000000000 0000000000000000 0000000000000002
GPR12: 0000000028004822 c00000000fdc6300 0000000000000000 00000100076ec310
GPR16: 000000002ae343b8 00003ffffd397398 0000000000000000 0000000000000000
GPR20: 00000100076f16f4 00000100076ebe60 0000000000000008 ffffffffffffffff
GPR24: 0000000000000000 0000008001041e60 0000000000000000 0000008001040ce8
GPR28: c0000003a2d80000 0000000000000a00 0000000000000001 c0000003a2681810
[ 331.466504] NIP [d0000000025d6b9c] .kvmppc_handle_exit_pr+0x75c/0xa80 [kvm]
[ 331.466999] LR [d0000000025d6b98] .kvmppc_handle_exit_pr+0x758/0xa80 [kvm]
[ 331.467517] Call Trace:
[ 331.467909] [c0000003bd32f6a0] [d0000000025d6b98] .kvmppc_handle_exit_pr+0x758/0xa80 [kvm] (unreliable)
[ 331.468553] [c0000003bd32f750] [d0000000025d98f0] kvm_start_lightweight+0xb4/0xc4 [kvm]
[ 331.469189] [c0000003bd32f920] [d0000000025d7648] .kvmppc_vcpu_run_pr+0xd8/0x270 [kvm]
[ 331.469838] [c0000003bd32f9c0] [d0000000025cf748] .kvmppc_vcpu_run+0xc8/0xf0 [kvm]
[ 331.470790] [c0000003bd32fa50] [d0000000025cc19c] .kvm_arch_vcpu_ioctl_run+0x5c/0x1b0 [kvm]
[ 331.471401] [c0000003bd32fae0] [d0000000025c4888] .kvm_vcpu_ioctl+0x478/0x730 [kvm]
[ 331.472026] [c0000003bd32fc90] [c00000000026192c] .do_vfs_ioctl+0x4dc/0x7a0
[ 331.472561] [c0000003bd32fd80] [c000000000261cc4] .SyS_ioctl+0xd4/0xf0
[ 331.473095] [c0000003bd32fe30] [c000000000009ed8] syscall_exit+0x0/0x98
[ 331.473633] Instruction dump:
[ 331.473766] 4bfff9b4 2b9d0800 419efc18 60000000 60420000 3d220000 e8bf11a0 e8df12a8
[ 331.474733] 7fa4eb78 e8698660 48015165 e8410028 <0fe00000> 813f00e4 3ba00000 39290001
[ 331.475386] ---[ end trace 49fc47d994c1f8f2 ]---
[ 331.479817]
This fixes the problem by making kvmppc_handle_exit_pr() recognize the
interrupt. We also need to jump to the doorbell interrupt handler in
book3s_segment.S to handle the interrupt on the way out of the guest.
Having done that, there's nothing further to be done in
kvmppc_handle_exit_pr().
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-01-08 14:25:36 +04:00
cmpwi r12 , B O O K 3 S _ I N T E R R U P T _ D O O R B E L L
beqa B O O K 3 S _ I N T E R R U P T _ D O O R B E L L
2012-04-27 18:33:35 +04:00
2010-04-16 02:11:35 +04:00
RFI
kvmppc_handler_trampoline_exit_end :