License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
/* SPDX-License-Identifier: GPL-2.0 */
2009-06-03 01:17:38 +04:00
/ *
* This f i l e c o n t a i n s t h e 6 4 - b i t " s e r v e r " P o w e r P C v a r i a n t
* of t h e l o w l e v e l e x c e p t i o n h a n d l i n g i n c l u d i n g e x c e p t i o n
* vectors, e x c e p t i o n r e t u r n , p a r t o f t h e s l b a n d s t a b
* handling a n d o t h e r f i x e d o f f s e t s p e c i f i c t h i n g s .
*
* This f i l e i s m e a n t t o b e #i n c l u d e d f r o m h e a d _ 64 . S d u e t o
2011-03-31 05:57:33 +04:00
* position d e p e n d e n t a s s e m b l y .
2009-06-03 01:17:38 +04:00
*
* Most o f t h i s o r i g i n a t e s f r o m h e a d _ 6 4 . S a n d t h u s h a s t h e s a m e
* copyright h i s t o r y .
*
* /
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
# include < a s m / h w _ i r q . h >
2009-07-15 00:52:52 +04:00
# include < a s m / e x c e p t i o n - 6 4 s . h >
2010-11-18 18:06:17 +03:00
# include < a s m / p t r a c e . h >
2014-12-09 21:56:52 +03:00
# include < a s m / c p u i d l e . h >
2016-09-30 12:43:18 +03:00
# include < a s m / h e a d - 6 4 . h >
2018-07-05 19:25:01 +03:00
# include < a s m / f e a t u r e - f i x u p s . h >
2019-04-18 09:51:24 +03:00
# include < a s m / k u p . h >
2009-07-15 00:52:52 +04:00
2009-06-03 01:17:38 +04:00
/ *
2016-09-28 04:31:48 +03:00
* There a r e a f e w c o n s t r a i n t s t o b e c o n c e r n e d w i t h .
* - Real m o d e e x c e p t i o n s c o d e / d a t a m u s t b e l o c a t e d a t t h e i r p h y s i c a l l o c a t i o n .
* - Virtual m o d e e x c e p t i o n s m u s t b e m a p p e d a t t h e i r 0 x c00 0 . . . l o c a t i o n .
* - Fixed l o c a t i o n c o d e m u s t n o t c a l l d i r e c t l y b e y o n d t h e _ _ e n d _ i n t e r r u p t s
* area w h e n b u i l t w i t h C O N F I G _ R E L O C A T A B L E . L O A D _ H A N D L E R / b c t r s e q u e n c e
* must b e u s e d .
* - LOAD_ H A N D L E R t a r g e t s m u s t b e w i t h i n f i r s t 6 4 K o f p h y s i c a l 0 /
* virtual 0 x c00 . . .
* - Conditional b r a n c h t a r g e t s m u s t b e w i t h i n + / - 3 2 K o f c a l l e r .
*
* " Virtual e x c e p t i o n s " r u n w i t h r e l o c a t i o n o n ( M S R _ I R =1 , M S R _ D R =1 ) , a n d
* therefore d o n ' t h a v e t o r u n i n p h y s i c a l l y l o c a t e d c o d e o r r f i d t o
* virtual m o d e k e r n e l c o d e . H o w e v e r o n r e l o c a t a b l e k e r n e l s t h e y d o h a v e
* to b r a n c h t o K E R N E L B A S E o f f s e t b e c a u s e t h e r e s t o f t h e k e r n e l ( o u t s i d e
* the e x c e p t i o n v e c t o r s ) m a y b e l o c a t e d e l s e w h e r e .
*
* Virtual e x c e p t i o n s c o r r e s p o n d w i t h p h y s i c a l , e x c e p t t h e i r e n t r y p o i n t s
* are o f f s e t b y 0 x c00 0 0 0 0 0 0 0 0 0 0 0 0 0 a n d a l s o t e n d t o g e t a n a d d e d 0 x40 0 0
* offset a p p l i e d . V i r t u a l e x c e p t i o n s a r e e n a b l e d w i t h t h e A l t e r n a t e
* Interrupt L o c a t i o n ( A I L ) b i t s e t i n t h e L P C R . H o w e v e r t h i s d o e s n o t
* guarantee t h e y w i l l b e d e l i v e r e d v i r t u a l l y . S o m e c o n d i t i o n s ( s e e t h e I S A )
* cause e x c e p t i o n s t o b e d e l i v e r e d i n r e a l m o d e .
*
* It' s i m p o s s i b l e t o r e c e i v e i n t e r r u p t s b e l o w 0 x30 0 v i a A I L .
*
* KVM : None o f t h e v i r t u a l e x c e p t i o n s a r e f r o m t h e g u e s t . A n y t h i n g t h a t
* escalated t o H V =1 f r o m H V =0 i s d e l i v e r e d v i a r e a l m o d e h a n d l e r s .
*
*
2009-06-03 01:17:38 +04:00
* We l a y o u t p h y s i c a l m e m o r y a s f o l l o w s :
* 0 x0 0 0 0 - 0 x00 f f : S e c o n d a r y p r o c e s s o r s p i n c o d e
2016-09-28 04:31:48 +03:00
* 0 x0 1 0 0 - 0 x18 f f : R e a l m o d e p S e r i e s i n t e r r u p t v e c t o r s
* 0 x1 9 0 0 - 0 x3 f f f : R e a l m o d e t r a m p o l i n e s
* 0 x4 0 0 0 - 0 x58 f f : R e l o n ( I R =1 ,D R =1 ) m o d e p S e r i e s i n t e r r u p t v e c t o r s
* 0 x5 9 0 0 - 0 x6 f f f : R e l o n m o d e t r a m p o l i n e s
2009-06-03 01:17:38 +04:00
* 0 x7 0 0 0 - 0 x7 f f f : F W N M I d a t a a r e a
2016-09-28 04:31:48 +03:00
* 0 x8 0 0 0 - . . . . : C o m m o n i n t e r r u p t h a n d l e r s , r e m a i n i n g e a r l y
* setup c o d e , r e s t o f k e r n e l .
2016-09-21 10:44:07 +03:00
*
* We c o u l d r e c l a i m 0 x40 0 0 - 0 x42 f f f o r r e a l m o d e t r a m p o l i n e s i f t h e s p a c e
* is n e c e s s a r y . U n t i l t h e n i t ' s m o r e c o n s i s t e n t t o e x p l i c i t l y p u t V I R T _ N O N E
* vectors t h e r e .
2016-09-28 04:31:48 +03:00
* /
OPEN_ F I X E D _ S E C T I O N ( r e a l _ v e c t o r s , 0 x01 0 0 , 0 x19 0 0 )
OPEN_ F I X E D _ S E C T I O N ( r e a l _ t r a m p o l i n e s , 0 x19 0 0 , 0 x40 0 0 )
OPEN_ F I X E D _ S E C T I O N ( v i r t _ v e c t o r s , 0 x40 0 0 , 0 x59 0 0 )
OPEN_ F I X E D _ S E C T I O N ( v i r t _ t r a m p o l i n e s , 0 x59 0 0 , 0 x70 0 0 )
2019-02-26 11:51:07 +03:00
# ifdef C O N F I G _ P P C _ P O W E R N V
2019-03-01 15:56:36 +03:00
.globl start_real_trampolines
.globl end_real_trampolines
.globl start_virt_trampolines
.globl end_virt_trampolines
2019-02-26 11:51:07 +03:00
# endif
2016-09-28 04:31:48 +03:00
# if d e f i n e d ( C O N F I G _ P P C _ P S E R I E S ) | | d e f i n e d ( C O N F I G _ P P C _ P O W E R N V )
/ *
* Data a r e a r e s e r v e d f o r F W N M I o p t i o n .
* This a d d r e s s ( 0 x70 0 0 ) i s f i x e d b y t h e R P A .
* pseries a n d p o w e r n v n e e d t o k e e p t h e w h o l e p a g e f r o m
* 0 x7 0 0 0 t o 0 x80 0 0 f r e e f o r u s e b y t h e f i r m w a r e
2009-06-03 01:17:38 +04:00
* /
2016-09-28 04:31:48 +03:00
ZERO_ F I X E D _ S E C T I O N ( f w n m i _ p a g e , 0 x70 0 0 , 0 x80 0 0 )
OPEN_ T E X T _ S E C T I O N ( 0 x80 0 0 )
# else
OPEN_ T E X T _ S E C T I O N ( 0 x70 0 0 )
# endif
USE_ F I X E D _ S E C T I O N ( r e a l _ v e c t o r s )
2009-06-03 01:17:38 +04:00
/ *
* This i s t h e s t a r t o f t h e i n t e r r u p t h a n d l e r s f o r p S e r i e s
* This c o d e r u n s w i t h r e l o c a t i o n o f f .
* Code f r o m h e r e t o _ _ e n d _ i n t e r r u p t s g e t s c o p i e d d o w n t o r e a l
* address 0 x10 0 w h e n w e a r e r u n n i n g a r e l o c a t a b l e k e r n e l .
* Therefore a n y r e l a t i v e b r a n c h e s i n t h i s s e c t i o n m u s t o n l y
* branch t o l a b e l s i n t h i s s e c t i o n .
* /
.globl __start_interrupts
__start_interrupts :
2016-09-21 10:44:07 +03:00
/* No virt vectors corresponding with 0x0..0x100 */
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ N O N E ( 0 x40 0 0 , 0 x10 0 )
2016-09-21 10:44:07 +03:00
2016-10-13 05:17:14 +03:00
2011-01-24 10:42:41 +03:00
# ifdef C O N F I G _ P P C _ P 7 _ N A P
2016-10-13 05:17:14 +03:00
/ *
* If r u n n i n g n a t i v e o n a r c h 2 . 0 6 o r l a t e r , c h e c k i f w e a r e w a k i n g u p
2017-06-24 20:29:01 +03:00
* from n a p / s l e e p / w i n k l e , a n d b r a n c h t o i d l e h a n d l e r . T h i s t e s t s S R R 1
* bits 4 6 : 4 7 . A n o n - 0 v a l u e i n d i c a t e s t h a t w e a r e c o m i n g f r o m a p o w e r
* saving s t a t e . T h e i d l e w a k e u p h a n d l e r i n i t i a l l y r u n s i n r e a l m o d e ,
* but w e b r a n c h t o t h e 0 x c00 0 . . . a d d r e s s s o w e c a n t u r n o n r e l o c a t i o n
* with m t m s r .
2011-01-24 10:42:41 +03:00
* /
2016-10-13 05:17:14 +03:00
# define I D L E T E S T ( n ) \
BEGIN_ F T R _ S E C T I O N ; \
mfspr r10 ,S P R N _ S R R 1 ; \
rlwinm. r10 ,r10 ,4 7 - 3 1 ,3 0 ,3 1 ; \
beq- 1 f ; \
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 17:30:52 +03:00
cmpwi c r1 ,r10 ,2 ; \
mfspr r3 ,S P R N _ S R R 1 ; \
bltlr c r1 ; /* no state loss, return to idle caller */ \
2017-06-13 16:05:50 +03:00
BRANCH_ T O _ C 0 0 0 ( r10 , s y s t e m _ r e s e t _ i d l e _ c o m m o n ) ; \
2016-10-13 05:17:14 +03:00
1 : \
2017-11-05 15:33:55 +03:00
KVMTEST_ P R ( n ) ; \
2016-10-13 05:17:14 +03: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 | C P U _ F T R _ A R C H _ 2 0 6 )
# else
# define I D L E T E S T N O T E S T
# endif
KVM: PPC: Allow book3s_hv guests to use SMT processor modes
This lifts the restriction that book3s_hv guests can only run one
hardware thread per core, and allows them to use up to 4 threads
per core on POWER7. The host still has to run single-threaded.
This capability is advertised to qemu through a new KVM_CAP_PPC_SMT
capability. The return value of the ioctl querying this capability
is the number of vcpus per virtual CPU core (vcore), currently 4.
To use this, the host kernel should be booted with all threads
active, and then all the secondary threads should be offlined.
This will put the secondary threads into nap mode. KVM will then
wake them from nap mode and use them for running guest code (while
they are still offline). To wake the secondary threads, we send
them an IPI using a new xics_wake_cpu() function, implemented in
arch/powerpc/sysdev/xics/icp-native.c. In other words, at this stage
we assume that the platform has a XICS interrupt controller and
we are using icp-native.c to drive it. Since the woken thread will
need to acknowledge and clear the IPI, we also export the base
physical address of the XICS registers using kvmppc_set_xics_phys()
for use in the low-level KVM book3s code.
When a vcpu is created, it is assigned to a virtual CPU core.
The vcore number is obtained by dividing the vcpu number by the
number of threads per core in the host. This number is exported
to userspace via the KVM_CAP_PPC_SMT capability. If qemu wishes
to run the guest in single-threaded mode, it should make all vcpu
numbers be multiples of the number of threads per core.
We distinguish three states of a vcpu: runnable (i.e., ready to execute
the guest), blocked (that is, idle), and busy in host. We currently
implement a policy that the vcore can run only when all its threads
are runnable or blocked. This way, if a vcpu needs to execute elsewhere
in the kernel or in qemu, it can do so without being starved of CPU
by the other vcpus.
When a vcore starts to run, it executes in the context of one of the
vcpu threads. The other vcpu threads all go to sleep and stay asleep
until something happens requiring the vcpu thread to return to qemu,
or to wake up to run the vcore (this can happen when another vcpu
thread goes from busy in host state to blocked).
It can happen that a vcpu goes from blocked to runnable state (e.g.
because of an interrupt), and the vcore it belongs to is already
running. In that case it can start to run immediately as long as
the none of the vcpus in the vcore have started to exit the guest.
We send the next free thread in the vcore an IPI to get it to start
to execute the guest. It synchronizes with the other threads via
the vcore->entry_exit_count field to make sure that it doesn't go
into the guest if the other vcpus are exiting by the time that it
is ready to actually enter the guest.
Note that there is no fixed relationship between the hardware thread
number and the vcpu number. Hardware threads are assigned to vcpus
as they become runnable, so we will always use the lower-numbered
hardware threads in preference to higher-numbered threads if not all
the vcpus in the vcore are runnable, regardless of which vcpus are
runnable.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-06-29 04:23:08 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( s y s t e m _ r e s e t , 0 x10 0 , 0 x10 0 )
2016-10-13 05:17:14 +03:00
SET_ S C R A T C H 0 ( r13 )
2016-12-19 21:30:05 +03:00
/ *
* MSR_ R I i s n o t e n a b l e d , b e c a u s e P A C A _ E X N M I a n d n m i s t a c k i s
* being u s e d , s o a n e s t e d N M I e x c e p t i o n w o u l d c o r r u p t i t .
* /
2018-07-26 16:07:09 +03:00
EXCEPTION_ P R O L O G _ N O R I ( P A C A _ E X N M I , s y s t e m _ r e s e t _ c o m m o n , E X C _ S T D ,
IDLETEST, 0 x10 0 )
2016-10-13 05:17:14 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( s y s t e m _ r e s e t , 0 x10 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x41 0 0 , 0 x10 0 )
2017-11-05 15:33:55 +03:00
TRAMP_ K V M ( P A C A _ E X N M I , 0 x10 0 )
2016-10-13 05:17:14 +03:00
# ifdef C O N F I G _ P P C _ P 7 _ N A P
EXC_ C O M M O N _ B E G I N ( s y s t e m _ r e s e t _ i d l e _ c o m m o n )
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 17:30:52 +03:00
/ *
* This m u s t b e a d i r e c t b r a n c h ( w i t h o u t l i n k e r b r a n c h s t u b ) b e c a u s e
* we c a n n o t u s e T O C a t t h i s p o i n t a s r2 m a y n o t b e r e s t o r e d y e t .
* /
b i d l e _ r e t u r n _ g p r _ l o s s
KVM: PPC: Allow book3s_hv guests to use SMT processor modes
This lifts the restriction that book3s_hv guests can only run one
hardware thread per core, and allows them to use up to 4 threads
per core on POWER7. The host still has to run single-threaded.
This capability is advertised to qemu through a new KVM_CAP_PPC_SMT
capability. The return value of the ioctl querying this capability
is the number of vcpus per virtual CPU core (vcore), currently 4.
To use this, the host kernel should be booted with all threads
active, and then all the secondary threads should be offlined.
This will put the secondary threads into nap mode. KVM will then
wake them from nap mode and use them for running guest code (while
they are still offline). To wake the secondary threads, we send
them an IPI using a new xics_wake_cpu() function, implemented in
arch/powerpc/sysdev/xics/icp-native.c. In other words, at this stage
we assume that the platform has a XICS interrupt controller and
we are using icp-native.c to drive it. Since the woken thread will
need to acknowledge and clear the IPI, we also export the base
physical address of the XICS registers using kvmppc_set_xics_phys()
for use in the low-level KVM book3s code.
When a vcpu is created, it is assigned to a virtual CPU core.
The vcore number is obtained by dividing the vcpu number by the
number of threads per core in the host. This number is exported
to userspace via the KVM_CAP_PPC_SMT capability. If qemu wishes
to run the guest in single-threaded mode, it should make all vcpu
numbers be multiples of the number of threads per core.
We distinguish three states of a vcpu: runnable (i.e., ready to execute
the guest), blocked (that is, idle), and busy in host. We currently
implement a policy that the vcore can run only when all its threads
are runnable or blocked. This way, if a vcpu needs to execute elsewhere
in the kernel or in qemu, it can do so without being starved of CPU
by the other vcpus.
When a vcore starts to run, it executes in the context of one of the
vcpu threads. The other vcpu threads all go to sleep and stay asleep
until something happens requiring the vcpu thread to return to qemu,
or to wake up to run the vcore (this can happen when another vcpu
thread goes from busy in host state to blocked).
It can happen that a vcpu goes from blocked to runnable state (e.g.
because of an interrupt), and the vcore it belongs to is already
running. In that case it can start to run immediately as long as
the none of the vcpus in the vcore have started to exit the guest.
We send the next free thread in the vcore an IPI to get it to start
to execute the guest. It synchronizes with the other threads via
the vcore->entry_exit_count field to make sure that it doesn't go
into the guest if the other vcpus are exiting by the time that it
is ready to actually enter the guest.
Note that there is no fixed relationship between the hardware thread
number and the vcpu number. Hardware threads are assigned to vcpus
as they become runnable, so we will always use the lower-numbered
hardware threads in preference to higher-numbered threads if not all
the vcpus in the vcore are runnable, regardless of which vcpus are
runnable.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
2011-06-29 04:23:08 +04:00
# endif
2018-03-26 18:01:03 +03:00
/ *
* Set I R Q S _ A L L _ D I S A B L E D u n c o n d i t i o n a l l y s o a r c h _ i r q s _ d i s a b l e d d o e s
* the r i g h t t h i n g . W e d o n o t w a n t t o r e c o n c i l e b e c a u s e t h a t g o e s
* through i r q t r a c i n g w h i c h w e d o n ' t w a n t i n N M I .
*
* Save P A C A I R Q H A P P E N E D b e c a u s e s o m e c o d e w i l l d o a h a r d d i s a b l e
* ( e. g . , x m o n ) . S o w e w a n t t o r e s t o r e t h i s b a c k t o w h e r e i t w a s
* when w e r e t u r n . D A R i s u n u s e d i n t h e s t a c k , s o s a v e i t t h e r e .
* /
# define A D D _ R E C O N C I L E _ N M I \
li r10 ,I R Q S _ A L L _ D I S A B L E D ; \
stb r10 ,P A C A I R Q S O F T M A S K ( r13 ) ; \
lbz r10 ,P A C A I R Q H A P P E N E D ( r13 ) ; \
std r10 ,_ D A R ( r1 )
2016-12-19 21:30:04 +03:00
EXC_ C O M M O N _ B E G I N ( s y s t e m _ r e s e t _ c o m m o n )
2016-12-19 21:30:05 +03:00
/ *
* Increment p a c a - > i n _ n m i t h e n e n a b l e M S R _ R I . S L B o r M C E w i l l b e a b l e
* to r e c o v e r , b u t n e s t e d N M I w i l l n o t i c e i n _ n m i a n d n o t r e c o v e r
* because o f t h e u s e o f t h e N M I s t a c k . i n _ n m i r e e n t r a n c y i s t e s t e d i n
* system_ r e s e t _ e x c e p t i o n .
* /
lhz r10 ,P A C A _ I N _ N M I ( r13 )
addi r10 ,r10 ,1
sth r10 ,P A C A _ I N _ N M I ( r13 )
li r10 ,M S R _ R I
mtmsrd r10 ,1
2014-02-26 04:08:25 +04:00
2016-12-19 21:30:06 +03:00
mr r10 ,r1
ld r1 ,P A C A _ N M I _ E M E R G _ S P ( r13 )
subi r1 ,r1 ,I N T _ F R A M E _ S I Z E
EXCEPTION_ C O M M O N _ N O R E T _ S T A C K ( P A C A _ E X N M I , 0 x10 0 ,
system_ r e s e t , s y s t e m _ r e s e t _ e x c e p t i o n ,
2018-03-26 18:01:03 +03:00
ADD_ N V G P R S ;ADD_RECONCILE_NMI)
/* This (and MCE) can be simplified with mtmsrd L=1 */
/* Clear MSR_RI before setting SRR0 and SRR1. */
li r0 ,M S R _ R I
mfmsr r9
andc r9 ,r9 ,r0
mtmsrd r9 ,1
2016-12-19 21:30:05 +03:00
/ *
2018-03-26 18:01:03 +03:00
* MSR_ R I i s c l e a r , n o w w e c a n d e c r e m e n t p a c a - > i n _ n m i .
2016-12-19 21:30:05 +03:00
* /
lhz r10 ,P A C A _ I N _ N M I ( r13 )
subi r10 ,r10 ,1
sth r10 ,P A C A _ I N _ N M I ( r13 )
2018-03-26 18:01:03 +03:00
/ *
* Restore s o f t m a s k s e t t i n g s .
* /
ld r10 ,_ D A R ( r1 )
stb r10 ,P A C A I R Q H A P P E N E D ( r13 )
ld r10 ,S O F T E ( r1 )
stb r10 ,P A C A I R Q S O F T M A S K ( r13 )
/ *
* Keep b e l o w c o d e i n s y n c h w i t h M A C H I N E _ C H E C K _ H A N D L E R _ W I N D U P .
* Should s h a r e c o m m o n b i t s . . .
* /
/* Move original SRR0 and SRR1 into the respective regs */
ld r9 ,_ M S R ( r1 )
mtspr S P R N _ S R R 1 ,r9
ld r3 ,_ N I P ( r1 )
mtspr S P R N _ S R R 0 ,r3
ld r9 ,_ C T R ( r1 )
mtctr r9
ld r9 ,_ X E R ( r1 )
mtxer r9
ld r9 ,_ L I N K ( r1 )
mtlr r9
REST_ G P R ( 0 , r1 )
REST_ 8 G P R S ( 2 , r1 )
REST_ G P R ( 1 0 , r1 )
ld r11 ,_ C C R ( r1 )
mtcr r11
REST_ G P R ( 1 1 , r1 )
REST_ 2 G P R S ( 1 2 , r1 )
/* restore original r1. */
ld r1 ,G P R 1 ( r1 )
RFI_ T O _ U S E R _ O R _ K E R N E L
2016-09-21 10:43:30 +03:00
# ifdef C O N F I G _ P P C _ P S E R I E S
/ *
* Vectors f o r t h e F W N M I o p t i o n . S h a r e c o m m o n c o d e .
* /
TRAMP_ R E A L _ B E G I N ( s y s t e m _ r e s e t _ f w n m i )
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
2016-12-19 21:30:05 +03:00
/* See comment at system_reset exception */
2018-07-26 16:07:09 +03:00
EXCEPTION_ P R O L O G _ N O R I ( P A C A _ E X N M I , s y s t e m _ r e s e t _ c o m m o n , E X C _ S T D ,
NOTEST, 0 x10 0 )
2016-09-21 10:43:30 +03:00
# endif / * C O N F I G _ P P C _ P S E R I E S * /
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( m a c h i n e _ c h e c k , 0 x20 0 , 0 x10 0 )
2011-06-29 04:18:26 +04:00
/ * This i s m o v e d o u t o f l i n e a s i t c a n b e p a t c h e d b y F W , b u t
* some c o d e p a t h m i g h t s t i l l w a n t t o b r a n c h i n t o t h e o r i g i n a l
* vector
* /
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X M C )
powerpc/book3s: handle machine check in Linux host.
Move machine check entry point into Linux. So far we were dependent on
firmware to decode MCE error details and handover the high level info to OS.
This patch introduces early machine check routine that saves the MCE
information (srr1, srr0, dar and dsisr) to the emergency stack. We allocate
stack frame on emergency stack and set the r1 accordingly. This allows us to be
prepared to take another exception without loosing context. One thing to note
here that, if we get another machine check while ME bit is off then we risk a
checkstop. Hence we restrict ourselves to save only MCE information and
register saved on PACA_EXMC save are before we turn the ME bit on. We use
paca->in_mce flag to differentiate between first entry and nested machine check
entry which helps proper use of emergency stack. We increment paca->in_mce
every time we enter in early machine check handler and decrement it while
leaving. When we enter machine check early handler first time (paca->in_mce ==
0), we are sure nobody is using MC emergency stack and allocate a stack frame
at the start of the emergency stack. During subsequent entry (paca->in_mce >
0), we know that r1 points inside emergency stack and we allocate separate
stack frame accordingly. This prevents us from clobbering MCE information
during nested machine checks.
The early machine check handler changes are placed under CPU_FTR_HVMODE
section. This makes sure that the early machine check handler will get executed
only in hypervisor kernel.
This is the code flow:
Machine Check Interrupt
|
V
0x200 vector ME=0, IR=0, DR=0
|
V
+-----------------------------------------------+
|machine_check_pSeries_early: | ME=0, IR=0, DR=0
| Alloc frame on emergency stack |
| Save srr1, srr0, dar and dsisr on stack |
+-----------------------------------------------+
|
(ME=1, IR=0, DR=0, RFID)
|
V
machine_check_handle_early ME=1, IR=0, DR=0
|
V
+-----------------------------------------------+
| machine_check_early (r3=pt_regs) | ME=1, IR=0, DR=0
| Things to do: (in next patches) |
| Flush SLB for SLB errors |
| Flush TLB for TLB errors |
| Decode and save MCE info |
+-----------------------------------------------+
|
(Fall through existing exception handler routine.)
|
V
machine_check_pSerie ME=1, IR=0, DR=0
|
(ME=1, IR=1, DR=1, RFID)
|
V
machine_check_common ME=1, IR=1, DR=1
.
.
.
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-10-30 18:34:08 +04:00
BEGIN_ F T R _ S E C T I O N
2018-09-11 17:27:23 +03:00
b m a c h i n e _ c h e c k _ c o m m o n _ e a r l y
powerpc/book3s: handle machine check in Linux host.
Move machine check entry point into Linux. So far we were dependent on
firmware to decode MCE error details and handover the high level info to OS.
This patch introduces early machine check routine that saves the MCE
information (srr1, srr0, dar and dsisr) to the emergency stack. We allocate
stack frame on emergency stack and set the r1 accordingly. This allows us to be
prepared to take another exception without loosing context. One thing to note
here that, if we get another machine check while ME bit is off then we risk a
checkstop. Hence we restrict ourselves to save only MCE information and
register saved on PACA_EXMC save are before we turn the ME bit on. We use
paca->in_mce flag to differentiate between first entry and nested machine check
entry which helps proper use of emergency stack. We increment paca->in_mce
every time we enter in early machine check handler and decrement it while
leaving. When we enter machine check early handler first time (paca->in_mce ==
0), we are sure nobody is using MC emergency stack and allocate a stack frame
at the start of the emergency stack. During subsequent entry (paca->in_mce >
0), we know that r1 points inside emergency stack and we allocate separate
stack frame accordingly. This prevents us from clobbering MCE information
during nested machine checks.
The early machine check handler changes are placed under CPU_FTR_HVMODE
section. This makes sure that the early machine check handler will get executed
only in hypervisor kernel.
This is the code flow:
Machine Check Interrupt
|
V
0x200 vector ME=0, IR=0, DR=0
|
V
+-----------------------------------------------+
|machine_check_pSeries_early: | ME=0, IR=0, DR=0
| Alloc frame on emergency stack |
| Save srr1, srr0, dar and dsisr on stack |
+-----------------------------------------------+
|
(ME=1, IR=0, DR=0, RFID)
|
V
machine_check_handle_early ME=1, IR=0, DR=0
|
V
+-----------------------------------------------+
| machine_check_early (r3=pt_regs) | ME=1, IR=0, DR=0
| Things to do: (in next patches) |
| Flush SLB for SLB errors |
| Flush TLB for TLB errors |
| Decode and save MCE info |
+-----------------------------------------------+
|
(Fall through existing exception handler routine.)
|
V
machine_check_pSerie ME=1, IR=0, DR=0
|
(ME=1, IR=1, DR=1, RFID)
|
V
machine_check_common ME=1, IR=1, DR=1
.
.
.
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-10-30 18:34:08 +04:00
FTR_ S E C T I O N _ E L S E
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
b m a c h i n e _ c h e c k _ p S e r i e s _ 0
powerpc/book3s: handle machine check in Linux host.
Move machine check entry point into Linux. So far we were dependent on
firmware to decode MCE error details and handover the high level info to OS.
This patch introduces early machine check routine that saves the MCE
information (srr1, srr0, dar and dsisr) to the emergency stack. We allocate
stack frame on emergency stack and set the r1 accordingly. This allows us to be
prepared to take another exception without loosing context. One thing to note
here that, if we get another machine check while ME bit is off then we risk a
checkstop. Hence we restrict ourselves to save only MCE information and
register saved on PACA_EXMC save are before we turn the ME bit on. We use
paca->in_mce flag to differentiate between first entry and nested machine check
entry which helps proper use of emergency stack. We increment paca->in_mce
every time we enter in early machine check handler and decrement it while
leaving. When we enter machine check early handler first time (paca->in_mce ==
0), we are sure nobody is using MC emergency stack and allocate a stack frame
at the start of the emergency stack. During subsequent entry (paca->in_mce >
0), we know that r1 points inside emergency stack and we allocate separate
stack frame accordingly. This prevents us from clobbering MCE information
during nested machine checks.
The early machine check handler changes are placed under CPU_FTR_HVMODE
section. This makes sure that the early machine check handler will get executed
only in hypervisor kernel.
This is the code flow:
Machine Check Interrupt
|
V
0x200 vector ME=0, IR=0, DR=0
|
V
+-----------------------------------------------+
|machine_check_pSeries_early: | ME=0, IR=0, DR=0
| Alloc frame on emergency stack |
| Save srr1, srr0, dar and dsisr on stack |
+-----------------------------------------------+
|
(ME=1, IR=0, DR=0, RFID)
|
V
machine_check_handle_early ME=1, IR=0, DR=0
|
V
+-----------------------------------------------+
| machine_check_early (r3=pt_regs) | ME=1, IR=0, DR=0
| Things to do: (in next patches) |
| Flush SLB for SLB errors |
| Flush TLB for TLB errors |
| Decode and save MCE info |
+-----------------------------------------------+
|
(Fall through existing exception handler routine.)
|
V
machine_check_pSerie ME=1, IR=0, DR=0
|
(ME=1, IR=1, DR=1, RFID)
|
V
machine_check_common ME=1, IR=1, DR=1
.
.
.
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-10-30 18:34:08 +04:00
ALT_ F T R _ S E C T I O N _ E N D _ I F S E T ( C P U _ F T R _ H V M O D E )
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( m a c h i n e _ c h e c k , 0 x20 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x42 0 0 , 0 x10 0 )
2018-09-11 17:27:23 +03:00
TRAMP_ R E A L _ B E G I N ( m a c h i n e _ c h e c k _ c o m m o n _ e a r l y )
2016-09-21 10:43:31 +03:00
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X M C , N O T E S T , 0 x20 0 )
/ *
* Register c o n t e n t s :
* R1 3 = P A C A
* R9 = C R
* Original R 9 t o R 1 3 i s s a v e d o n P A C A _ E X M C
*
* Switch t o m c _ e m e r g e n c y s t a c k a n d h a n d l e r e - e n t r a n c y ( w e l i m i t
* the n e s t e d M C E u p t o l e v e l 4 t o a v o i d s t a c k o v e r f l o w ) .
* Save M C E r e g i s t e r s s r r1 , s r r0 , d a r a n d d s i s r a n d t h e n s e t M E =1
*
* We u s e p a c a - > i n _ m c e t o c h e c k w h e t h e r t h i s i s t h e f i r s t e n t r y o r
* nested m a c h i n e c h e c k . W e i n c r e m e n t p a c a - > i n _ m c e t o t r a c k n e s t e d
* machine c h e c k s .
*
* If t h i s i s t h e f i r s t e n t r y t h e n s e t s t a c k p o i n t e r t o
* paca- > m c _ e m e r g e n c y _ s p , o t h e r w i s e r1 i s a l r e a d y p o i n t i n g t o
* stack f r a m e o n m c _ e m e r g e n c y s t a c k .
*
* NOTE : We a r e h e r e w i t h M S R _ M E =0 ( o f f ) , w h i c h m e a n s w e r i s k a
* checkstop i f w e g e t a n o t h e r m a c h i n e c h e c k e x c e p t i o n b e f o r e w e d o
* rfid w i t h M S R _ M E =1 .
2017-04-19 16:05:47 +03:00
*
* This i n t e r r u p t c a n w a k e d i r e c t l y f r o m i d l e . I f t h a t i s t h e c a s e ,
* the m a c h i n e c h e c k i s h a n d l e d t h e n t h e i d l e w a k e u p c o d e i s c a l l e d
2018-07-05 11:47:00 +03:00
* to r e s t o r e s t a t e .
2016-09-21 10:43:31 +03:00
* /
mr r11 ,r1 / * S a v e r1 * /
lhz r10 ,P A C A _ I N _ M C E ( r13 )
cmpwi r10 ,0 / * A r e w e i n n e s t e d m a c h i n e c h e c k * /
bne 0 f / * Y e s , w e a r e . * /
/* First machine check entry */
ld r1 ,P A C A M C E M E R G S P ( r13 ) / * U s e M C e m e r g e n c y s t a c k * /
0 : subi r1 ,r1 ,I N T _ F R A M E _ S I Z E / * a l l o c s t a c k f r a m e * /
addi r10 ,r10 ,1 / * i n c r e m e n t p a c a - > i n _ m c e * /
sth r10 ,P A C A _ I N _ M C E ( r13 )
/* Limit nested MCE to level 4 to avoid stack overflow */
2017-09-29 07:26:53 +03:00
cmpwi r10 ,M A X _ M C E _ D E P T H
2016-09-21 10:43:31 +03:00
bgt 2 f / * C h e c k i f w e h i t l i m i t o f 4 * /
std r11 ,G P R 1 ( r1 ) / * S a v e r1 o n t h e s t a c k . * /
std r11 ,0 ( r1 ) / * m a k e s t a c k c h a i n p o i n t e r * /
mfspr r11 ,S P R N _ S R R 0 / * S a v e S R R 0 * /
std r11 ,_ N I P ( r1 )
mfspr r11 ,S P R N _ S R R 1 / * S a v e S R R 1 * /
std r11 ,_ M S R ( r1 )
mfspr r11 ,S P R N _ D A R / * S a v e D A R * /
std r11 ,_ D A R ( r1 )
mfspr r11 ,S P R N _ D S I S R / * S a v e D S I S R * /
std r11 ,_ D S I S R ( r1 )
std r9 ,_ C C R ( r1 ) / * S a v e C R i n s t a c k f r a m e * /
2019-06-22 01:55:54 +03:00
/* We don't touch AMR here, we never go to virtual mode */
2016-09-21 10:43:31 +03:00
/* Save r9 through r13 from EXMC save area to stack frame. */
EXCEPTION_ P R O L O G _ C O M M O N _ 2 ( P A C A _ E X M C )
mfmsr r11 / * g e t M S R v a l u e * /
2018-09-11 17:27:23 +03:00
BEGIN_ F T R _ S E C T I O N
2016-09-21 10:43:31 +03:00
ori r11 ,r11 ,M S R _ M E / * t u r n o n M E b i t * /
2018-09-11 17:27:23 +03: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 )
2016-09-21 10:43:31 +03:00
ori r11 ,r11 ,M S R _ R I / * t u r n o n R I b i t * /
LOAD_ H A N D L E R ( r12 , m a c h i n e _ c h e c k _ h a n d l e _ e a r l y )
1 : mtspr S P R N _ S R R 0 ,r12
mtspr S P R N _ S R R 1 ,r11
2018-01-09 19:07:15 +03:00
RFI_ T O _ K E R N E L
2016-09-21 10:43:31 +03:00
b . / * p r e v e n t s p e c u l a t i v e e x e c u t i o n * /
2 :
/ * Stack o v e r f l o w . S t a y o n e m e r g e n c y s t a c k a n d p a n i c .
* Keep t h e M E b i t o f f w h i l e p a n i c - i n g , s o t h a t i f w e h i t
* another m a c h i n e c h e c k w e c h e c k s t o p .
* /
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E / * g o b a c k t o p r e v i o u s s t a c k f r a m e * /
ld r11 ,P A C A K M S R ( r13 )
LOAD_ H A N D L E R ( r12 , u n r e c o v e r _ m c e )
li r10 ,M S R _ M E
andc r11 ,r11 ,r10 / * T u r n o f f M S R _ M E * /
b 1 b
b . / * p r e v e n t s p e c u l a t i v e e x e c u t i o n * /
TRAMP_ R E A L _ B E G I N ( m a c h i n e _ c h e c k _ p S e r i e s )
.globl machine_check_fwnmi
machine_check_fwnmi :
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X M C )
2018-09-11 17:27:00 +03:00
BEGIN_ F T R _ S E C T I O N
2018-09-11 17:27:23 +03:00
b m a c h i n e _ c h e c k _ c o m m o n _ e a r l y
2018-09-11 17:27:00 +03:00
END_ F T R _ S E C T I O N _ I F C L R ( C P U _ F T R _ H V M O D E )
2016-09-21 10:43:31 +03:00
machine_check_pSeries_0 :
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X M C , K V M T E S T _ P R , 0 x20 0 )
/ *
2016-12-19 21:30:02 +03:00
* MSR_ R I i s n o t e n a b l e d , b e c a u s e P A C A _ E X M C i s b e i n g u s e d , s o a
* nested m a c h i n e c h e c k c o r r u p t s i t . m a c h i n e _ c h e c k _ c o m m o n e n a b l e s
* MSR_ R I .
2016-09-21 10:43:31 +03:00
* /
2018-07-26 16:07:09 +03:00
EXCEPTION_ P R O L O G _ 2 _ N O R I ( m a c h i n e _ c h e c k _ c o m m o n , E X C _ S T D )
2016-09-21 10:43:31 +03:00
TRAMP_ K V M _ S K I P ( P A C A _ E X M C , 0 x20 0 )
EXC_ C O M M O N _ B E G I N ( m a c h i n e _ c h e c k _ c o m m o n )
/ *
* Machine c h e c k i s d i f f e r e n t b e c a u s e w e u s e a d i f f e r e n t
* save a r e a : P A C A _ E X M C i n s t e a d o f P A C A _ E X G E N .
* /
mfspr r10 ,S P R N _ D A R
std r10 ,P A C A _ E X M C + E X _ D A R ( r13 )
mfspr r10 ,S P R N _ D S I S R
stw r10 ,P A C A _ E X M C + E X _ D S I S R ( r13 )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x20 0 , P A C A _ E X M C )
FINISH_ N A P
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
ld r3 ,P A C A _ E X M C + E X _ D A R ( r13 )
lwz r4 ,P A C A _ E X M C + E X _ D S I S R ( r13 )
/* Enable MSR_RI when finished with PACA_EXMC */
li r10 ,M S R _ R I
mtmsrd r10 ,1
std r3 ,_ D A R ( r1 )
std r4 ,_ D S I S R ( r1 )
bl s a v e _ n v g p r s
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl m a c h i n e _ c h e c k _ e x c e p t i o n
b r e t _ f r o m _ e x c e p t
# define M A C H I N E _ C H E C K _ H A N D L E R _ W I N D U P \
/* Clear MSR_RI before setting SRR0 and SRR1. */ \
li r0 ,M S R _ R I ; \
mfmsr r9 ; /* get MSR value */ \
andc r9 ,r9 ,r0 ; \
mtmsrd r9 ,1 ; /* Clear MSR_RI */ \
/* Move original SRR0 and SRR1 into the respective regs */ \
ld r9 ,_ M S R ( r1 ) ; \
mtspr S P R N _ S R R 1 ,r9 ; \
ld r3 ,_ N I P ( r1 ) ; \
mtspr S P R N _ S R R 0 ,r3 ; \
ld r9 ,_ C T R ( r1 ) ; \
mtctr r9 ; \
ld r9 ,_ X E R ( r1 ) ; \
mtxer r9 ; \
ld r9 ,_ L I N K ( r1 ) ; \
mtlr r9 ; \
REST_ G P R ( 0 , r1 ) ; \
REST_ 8 G P R S ( 2 , r1 ) ; \
REST_ G P R ( 1 0 , r1 ) ; \
ld r11 ,_ C C R ( r1 ) ; \
mtcr r11 ; \
/* Decrement paca->in_mce. */ \
lhz r12 ,P A C A _ I N _ M C E ( r13 ) ; \
subi r12 ,r12 ,1 ; \
sth r12 ,P A C A _ I N _ M C E ( r13 ) ; \
REST_ G P R ( 1 1 , r1 ) ; \
REST_ 2 G P R S ( 1 2 , r1 ) ; \
/* restore original r1. */ \
ld r1 ,G P R 1 ( r1 )
2017-04-19 16:05:47 +03:00
# ifdef C O N F I G _ P P C _ P 7 _ N A P
/ *
* This i s a n i d l e w a k e u p . L o w l e v e l m a c h i n e c h e c k h a s a l r e a d y b e e n
* done. Q u e u e t h e e v e n t t h e n c a l l t h e i d l e c o d e t o d o t h e w a k e u p .
* /
EXC_ C O M M O N _ B E G I N ( m a c h i n e _ c h e c k _ i d l e _ c o m m o n )
bl m a c h i n e _ c h e c k _ q u e u e _ e v e n t
/ *
* We h a v e n o t u s e d a n y n o n - v o l a t i l e G P R s h e r e , a n d a s a r u l e
* most e x c e p t i o n c o d e i n c l u d i n g m a c h i n e c h e c k d o e s n o t .
* Therefore P A C A _ N A P S T A T E L O S T d o e s n o t n e e d t o b e s e t . I d l e
* wakeup w i l l r e s t o r e v o l a t i l e r e g i s t e r s .
*
* Load t h e o r i g i n a l S R R 1 i n t o r3 f o r p n v _ p o w e r s a v e _ w a k e u p _ m c e .
*
* Then d e c r e m e n t M C E n e s t i n g a f t e r f i n i s h i n g w i t h t h e s t a c k .
* /
ld r3 ,_ M S R ( r1 )
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 17:30:52 +03:00
ld r4 ,_ L I N K ( r1 )
2017-04-19 16:05:47 +03:00
lhz r11 ,P A C A _ I N _ M C E ( r13 )
subi r11 ,r11 ,1
sth r11 ,P A C A _ I N _ M C E ( r13 )
powerpc/64s: Reimplement book3s idle code in C
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.
Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.
The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.
This is not a strict translation to C code, there are some
significant differences:
- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
but saves and restores them itself.
- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
or change MSR is restored, because it's now simple to do. ESL=1
sleeps that do not lose GPRs can use this optimization too.
- KVM secondary entry and cede is now more of a call/return style
rather than branchy. nap_state_lost is not required because KVM
always returns via NVGPR restoring path.
- KVM secondary wakeup from offline sequence is moved entirely into
the offline wakeup, which avoids a hwsync in the normal idle wakeup
path.
Performance measured with context switch ping-pong on different
threads or cores, is possibly improved a small amount, 1-3% depending
on stop state and core vs thread test for shallow states. Deep states
it's in the noise compared with other latencies.
KVM improvements:
- Idle sleepers now always return to caller rather than branch out
to KVM first.
- This allows optimisations like very fast return to caller when no
state has been lost.
- KVM no longer requires nap_state_lost because it controls NVGPR
save/restore itself on the way in and out.
- The heavy idle wakeup KVM request check can be moved out of the
normal host idle code and into the not-performance-critical offline
code.
- KVM nap code now returns from where it is called, which makes the
flow a bit easier to follow.
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
[mpe: Squash the KVM changes in]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-04-12 17:30:52 +03:00
mtlr r4
rlwinm r10 ,r3 ,4 7 - 3 1 ,3 0 ,3 1
cmpwi c r1 ,r10 ,2
bltlr c r1 / * n o s t a t e l o s s , r e t u r n t o i d l e c a l l e r * /
b i d l e _ r e t u r n _ g p r _ l o s s
2017-04-19 16:05:47 +03:00
# endif
2016-09-21 10:43:31 +03:00
/ *
* Handle m a c h i n e c h e c k e a r l y i n r e a l m o d e . W e c o m e h e r e w i t h
* ME=1 , M M U ( I R =0 a n d D R =0 ) o f f a n d u s i n g M C e m e r g e n c y s t a c k .
* /
EXC_ C O M M O N _ B E G I N ( m a c h i n e _ c h e c k _ h a n d l e _ e a r l y )
std r0 ,G P R 0 ( r1 ) / * S a v e r0 * /
EXCEPTION_ P R O L O G _ C O M M O N _ 3 ( 0 x20 0 )
bl s a v e _ n v g p r s
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl m a c h i n e _ c h e c k _ e a r l y
std r3 ,R E S U L T ( r1 ) / * S a v e r e s u l t * /
ld r12 ,_ M S R ( r1 )
2018-09-11 17:27:23 +03:00
BEGIN_ F T R _ S E C T I O N
b 4 f
END_ F T R _ S E C T I O N _ I F C L R ( C P U _ F T R _ H V M O D E )
2017-04-19 16:05:47 +03:00
2016-09-21 10:43:31 +03:00
# ifdef C O N F I G _ P P C _ P 7 _ N A P
/ *
* Check i f t h r e a d w a s i n p o w e r s a v i n g m o d e . W e c o m e h e r e w h e n a n y
* of t h e f o l l o w i n g i s t r u e :
* a. t h r e a d w a s n ' t i n p o w e r s a v i n g m o d e
* b. t h r e a d w a s i n p o w e r s a v i n g m o d e w i t h n o s t a t e l o s s ,
* supervisor s t a t e l o s s o r h y p e r v i s o r s t a t e l o s s .
*
* Go b a c k t o n a p / s l e e p / w i n k l e m o d e a g a i n i f ( b ) i s t r u e .
* /
2017-04-19 16:05:47 +03:00
BEGIN_ F T R _ S E C T I O N
rlwinm. r11 ,r12 ,4 7 - 3 1 ,3 0 ,3 1
2017-05-04 13:41:12 +03:00
bne m a c h i n e _ c h e c k _ i d l e _ c o m m o n
2017-04-19 16:05:47 +03: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 | C P U _ F T R _ A R C H _ 2 0 6 )
2016-09-21 10:43:31 +03:00
# endif
2017-04-19 16:05:47 +03:00
2016-09-21 10:43:31 +03:00
/ *
* Check i f w e a r e c o m i n g f r o m h y p e r v i s o r u s e r s p a c e . I f y e s t h e n w e
* continue i n h o s t k e r n e l i n V m o d e t o d e l i v e r t h e M C e v e n t .
* /
rldicl. r11 ,r12 ,4 ,6 3 / * S e e i f M C h i t w h i l e i n H V m o d e . * /
beq 5 f
2018-09-11 17:27:23 +03:00
4 : andi. r11 ,r12 ,M S R _ P R / * S e e i f c o m i n g f r o m u s e r . * /
2016-09-21 10:43:31 +03:00
bne 9 f / * c o n t i n u e i n V m o d e i f w e a r e . * /
5 :
# ifdef C O N F I G _ K V M _ B O O K 3 S _ 6 4 _ H A N D L E R
2018-09-11 17:27:23 +03:00
BEGIN_ F T R _ S E C T I O N
2016-09-21 10:43:31 +03:00
/ *
* We a r e c o m i n g f r o m k e r n e l c o n t e x t . C h e c k i f w e a r e c o m i n g f r o m
* guest. i f y e s , t h e n w e c a n c o n t i n u e . W e w i l l f a l l t h r o u g h
* do_ k v m _ 2 0 0 - > k v m p p c _ i n t e r r u p t t o d e l i v e r t h e M C e v e n t t o g u e s t .
* /
lbz r11 ,H S T A T E _ I N _ G U E S T ( r13 )
cmpwi r11 ,0 / * C h e c k i f c o m i n g f r o m g u e s t * /
bne 9 f / * c o n t i n u e i f w e a r e . * /
2018-09-11 17:27:23 +03: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 )
2016-09-21 10:43:31 +03:00
# endif
/ *
* At t h i s p o i n t w e a r e n o t s u r e a b o u t w h a t c o n t e x t w e c o m e f r o m .
* Queue u p t h e M C E e v e n t a n d r e t u r n f r o m t h e i n t e r r u p t .
* But b e f o r e t h a t , c h e c k i f t h i s i s a n u n - r e c o v e r a b l e e x c e p t i o n .
* If y e s , t h e n s t a y o n e m e r g e n c y s t a c k a n d p a n i c .
* /
andi. r11 ,r12 ,M S R _ R I
bne 2 f
1 : mfspr r11 ,S P R N _ S R R 0
LOAD_ H A N D L E R ( r10 ,u n r e c o v e r _ m c e )
mtspr S P R N _ S R R 0 ,r10
ld r10 ,P A C A K M S R ( r13 )
/ *
* We a r e g o i n g d o w n . B u t t h e r e a r e c h a n c e s t h a t w e m i g h t g e t h i t b y
* another M C E d u r i n g p a n i c p a t h a n d w e m a y r u n i n t o u n s t a b l e s t a t e
* with n o w a y o u t . H e n c e , t u r n M E b i t o f f w h i l e g o i n g d o w n , s o t h a t
* when a n o t h e r M C E i s h i t d u r i n g p a n i c p a t h , s y s t e m w i l l c h e c k s t o p
* and h y p e r v i s o r w i l l g e t r e s t a r t e d c l e a n l y b y S P .
* /
li r3 ,M S R _ M E
andc r10 ,r10 ,r3 / * T u r n o f f M S R _ M E * /
mtspr S P R N _ S R R 1 ,r10
2018-01-09 19:07:15 +03:00
RFI_ T O _ K E R N E L
2016-09-21 10:43:31 +03:00
b .
2 :
/ *
* Check i f w e h a v e s u c c e s s f u l l y h a n d l e d / r e c o v e r e d f r o m e r r o r , i f n o t
* then s t a y o n e m e r g e n c y s t a c k a n d p a n i c .
* /
ld r3 ,R E S U L T ( r1 ) / * L o a d r e s u l t * /
cmpdi r3 ,0 / * s e e i f w e h a n d l e d M C E s u c c e s s f u l l y * /
beq 1 b / * i f ! h a n d l e d t h e n p a n i c * /
2018-09-11 17:27:23 +03:00
BEGIN_ F T R _ S E C T I O N
2016-09-21 10:43:31 +03:00
/ *
* Return f r o m M C i n t e r r u p t .
* Queue u p t h e M C E e v e n t s o t h a t w e c a n l o g i t l a t e r , w h i l e
* returning f r o m k e r n e l o r o p a l c a l l .
* /
bl m a c h i n e _ c h e c k _ q u e u e _ e v e n t
MACHINE_ C H E C K _ H A N D L E R _ W I N D U P
2018-01-09 19:07:15 +03:00
RFI_ T O _ U S E R _ O R _ K E R N E L
2018-09-11 17:27:23 +03:00
FTR_ S E C T I O N _ E L S E
/ *
* pSeries : Return f r o m M C i n t e r r u p t . B e f o r e t h a t s t a y o n e m e r g e n c y
* stack a n d c a l l m a c h i n e _ c h e c k _ e x c e p t i o n t o l o g t h e M C E e v e n t .
* /
LOAD_ H A N D L E R ( r10 ,m c e _ r e t u r n )
mtspr S P R N _ S R R 0 ,r10
ld r10 ,P A C A K M S R ( r13 )
mtspr S P R N _ S R R 1 ,r10
RFI_ T O _ K E R N E L
b .
ALT_ F T R _ S E C T I O N _ E N D _ I F S E T ( C P U _ F T R _ H V M O D E )
2016-09-21 10:43:31 +03:00
9 :
/* Deliver the machine check to host kernel in V mode. */
MACHINE_ C H E C K _ H A N D L E R _ W I N D U P
2018-09-11 17:27:23 +03:00
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X M C )
b m a c h i n e _ c h e c k _ p S e r i e s _ 0
2016-09-21 10:43:31 +03:00
EXC_ C O M M O N _ B E G I N ( u n r e c o v e r _ m c e )
/* Invoke machine_check_exception to print MCE event and panic. */
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl m a c h i n e _ c h e c k _ e x c e p t i o n
/ *
* We w i l l n o t r e a c h h e r e . E v e n i f w e d i d , t h e r e i s n o w a y o u t . C a l l
* unrecoverable_ e x c e p t i o n a n d d i e .
* /
1 : addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl u n r e c o v e r a b l e _ e x c e p t i o n
b 1 b
2018-09-11 17:27:00 +03:00
EXC_ C O M M O N _ B E G I N ( m c e _ r e t u r n )
/* Invoke machine_check_exception to print MCE event and return. */
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl m a c h i n e _ c h e c k _ e x c e p t i o n
2018-09-11 17:27:23 +03:00
MACHINE_ C H E C K _ H A N D L E R _ W I N D U P
2018-09-11 17:27:00 +03:00
RFI_ T O _ K E R N E L
b .
2009-06-03 01:17:38 +04:00
2019-02-26 11:51:09 +03:00
EXC_ R E A L _ B E G I N ( d a t a _ a c c e s s , 0 x30 0 , 0 x80 )
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X G E N )
b t r a m p _ r e a l _ d a t a _ a c c e s s
EXC_ R E A L _ E N D ( d a t a _ a c c e s s , 0 x30 0 , 0 x80 )
TRAMP_ R E A L _ B E G I N ( t r a m p _ r e a l _ d a t a _ a c c e s s )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X G E N , K V M T E S T _ P R , 0 x30 0 )
2019-02-26 11:51:10 +03:00
/ *
* DAR/ D S I S R m u s t b e r e a d b e f o r e s e t t i n g M S R [ R I ] , b e c a u s e
* a d - s i d e M C E w i l l c l o b b e r t h o s e r e g i s t e r s s o i s n o t
* recoverable i f t h e y a r e l i v e .
* /
mfspr r10 ,S P R N _ D A R
mfspr r11 ,S P R N _ D S I S R
std r10 ,P A C A _ E X G E N + E X _ D A R ( r13 )
stw r11 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
2019-02-26 11:51:09 +03:00
EXCEPTION_ P R O L O G _ 2 ( d a t a _ a c c e s s _ c o m m o n , E X C _ S T D )
EXC_ V I R T _ B E G I N ( d a t a _ a c c e s s , 0 x43 0 0 , 0 x80 )
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X G E N )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X G E N , N O T E S T , 0 x30 0 )
2019-02-26 11:51:10 +03:00
mfspr r10 ,S P R N _ D A R
mfspr r11 ,S P R N _ D S I S R
std r10 ,P A C A _ E X G E N + E X _ D A R ( r13 )
stw r11 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
2019-02-26 11:51:09 +03:00
EXCEPTION_ P R O L O G _ 2 _ R E L O N ( d a t a _ a c c e s s _ c o m m o n , E X C _ S T D )
EXC_ V I R T _ E N D ( d a t a _ a c c e s s , 0 x43 0 0 , 0 x80 )
2016-09-21 10:43:32 +03:00
TRAMP_ K V M _ S K I P ( P A C A _ E X G E N , 0 x30 0 )
EXC_ C O M M O N _ B E G I N ( d a t a _ a c c e s s _ c o m m o n )
/ *
* Here r13 p o i n t s t o t h e p a c a , r9 c o n t a i n s t h e s a v e d C R ,
* SRR0 a n d S R R 1 a r e s a v e d i n r11 a n d r12 ,
* r9 - r13 a r e s a v e d i n p a c a - > e x g e n .
2019-02-26 11:51:10 +03:00
* EX_ D A R a n d E X _ D S I S R h a v e s a v e d D A R / D S I S R
2016-09-21 10:43:32 +03:00
* /
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x30 0 , P A C A _ E X G E N )
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
ld r12 ,_ M S R ( r1 )
ld r3 ,P A C A _ E X G E N + E X _ D A R ( r13 )
lwz r4 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
li r5 ,0 x30 0
std r3 ,_ D A R ( r1 )
std r4 ,_ D S I S R ( r1 )
BEGIN_ M M U _ F T R _ S E C T I O N
b d o _ h a s h _ p a g e / * T r y t o h a n d l e a s h p t e f a u l t * /
MMU_ F T R _ S E C T I O N _ E L S E
b h a n d l e _ p a g e _ f a u l t
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F C L R ( M M U _ F T R _ T Y P E _ R A D I X )
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( d a t a _ a c c e s s _ s l b , 0 x38 0 , 0 x80 )
2019-02-26 11:51:09 +03:00
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X S L B )
b t r a m p _ r e a l _ d a t a _ a c c e s s _ s l b
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( d a t a _ a c c e s s _ s l b , 0 x38 0 , 0 x80 )
2009-06-03 01:17:38 +04:00
2019-02-26 11:51:09 +03:00
TRAMP_ R E A L _ B E G I N ( t r a m p _ r e a l _ d a t a _ a c c e s s _ s l b )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X S L B , K V M T E S T _ P R , 0 x38 0 )
2019-02-26 11:51:10 +03:00
mfspr r10 ,S P R N _ D A R
std r10 ,P A C A _ E X S L B + E X _ D A R ( r13 )
2019-02-26 11:51:09 +03:00
EXCEPTION_ P R O L O G _ 2 ( d a t a _ a c c e s s _ s l b _ c o m m o n , E X C _ S T D )
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ B E G I N ( d a t a _ a c c e s s _ s l b , 0 x43 8 0 , 0 x80 )
2019-02-26 11:51:09 +03:00
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X S L B )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X S L B , N O T E S T , 0 x38 0 )
2019-02-26 11:51:10 +03:00
mfspr r10 ,S P R N _ D A R
std r10 ,P A C A _ E X S L B + E X _ D A R ( r13 )
2019-02-26 11:51:09 +03:00
EXCEPTION_ P R O L O G _ 2 _ R E L O N ( d a t a _ a c c e s s _ s l b _ c o m m o n , E X C _ S T D )
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ E N D ( d a t a _ a c c e s s _ s l b , 0 x43 8 0 , 0 x80 )
2018-09-14 18:30:51 +03:00
2016-09-21 10:43:33 +03:00
TRAMP_ K V M _ S K I P ( P A C A _ E X S L B , 0 x38 0 )
2018-09-14 18:30:51 +03:00
EXC_ C O M M O N _ B E G I N ( d a t a _ a c c e s s _ s l b _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x38 0 , P A C A _ E X S L B )
ld r4 ,P A C A _ E X S L B + E X _ D A R ( r13 )
std r4 ,_ D A R ( r1 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2019-03-29 10:42:57 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
/* HPT case, do SLB fault */
2018-09-14 18:30:51 +03:00
bl d o _ s l b _ f a u l t
cmpdi r3 ,0
bne- 1 f
b f a s t _ e x c e p t i o n _ r e t u r n
1 : /* Error case */
2019-03-29 10:42:57 +03:00
MMU_ F T R _ S E C T I O N _ E L S E
/* Radix case, access is outside page table range */
li r3 ,- E F A U L T
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F C L R ( M M U _ F T R _ T Y P E _ R A D I X )
2018-09-14 18:30:51 +03:00
std r3 ,R E S U L T ( r1 )
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
ld r4 ,_ D A R ( r1 )
ld r5 ,R E S U L T ( r1 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl d o _ b a d _ s l b _ f a u l t
b r e t _ f r o m _ e x c e p t
2016-09-21 10:43:33 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( i n s t r u c t i o n _ a c c e s s , 0 x40 0 , 0 x80 )
EXC_ V I R T ( i n s t r u c t i o n _ a c c e s s , 0 x44 0 0 , 0 x80 , 0 x40 0 )
2016-09-21 10:43:34 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x40 0 )
EXC_ C O M M O N _ B E G I N ( i n s t r u c t i o n _ a c c e s s _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x40 0 , P A C A _ E X G E N )
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
ld r12 ,_ M S R ( r1 )
ld r3 ,_ N I P ( r1 )
powerpc/64s: Fix masking of SRR1 bits on instruction fault
On 64-bit Book3s, when we take an instruction fault the reason for the
fault may be reported in SRR1. For data faults the reason is reported
in DSISR (Data Storage Instruction Status Register).
The reasons reported in each do not necessarily correspond, so we mask
the SRR1 bits before copying them to the DSISR, which is then used by
the page fault code.
Prior to commit b4c001dc44f0 ("powerpc/mm: Use symbolic constants for
filtering SRR1 bits on ISIs") we used a hard-coded mask of 0x58200000,
which corresponds to:
DSISR_NOHPTE 0x40000000 /* no translation found */
DSISR_NOEXEC_OR_G 0x10000000 /* exec of no-exec or guarded */
DSISR_PROTFAULT 0x08000000 /* protection fault */
DSISR_KEYFAULT 0x00200000 /* Storage Key fault */
That commit added a #define for the mask, DSISR_SRR1_MATCH_64S, but
incorrectly used a different similarly named DSISR_BAD_FAULT_64S.
This had the effect of changing the mask to 0xa43a0000, which omits
everything but DSISR_KEYFAULT.
Luckily this had no visible effect, because in practice we hardly use
the DSISR bits. The lack of DSISR_NOHPTE means a TLB flush
optimisation was missed in the native HPTE code, and DSISR_NOEXEC_OR_G
and DSISR_PROTFAULT are both only used to trigger rare warnings.
So we got lucky, but let's fix it. The new value only has bits between
17 and 30 set, so we can continue to use andis.
Fixes: b4c001dc44f0 ("powerpc/mm: Use symbolic constants for filtering SRR1 bits on ISIs")
Cc: stable@vger.kernel.org # v4.14+
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-11-14 07:48:47 +03:00
andis. r4 ,r12 ,D S I S R _ S R R 1 _ M A T C H _ 6 4 S @h
2016-09-21 10:43:34 +03:00
li r5 ,0 x40 0
std r3 ,_ D A R ( r1 )
std r4 ,_ D S I S R ( r1 )
BEGIN_ M M U _ F T R _ S E C T I O N
b d o _ h a s h _ p a g e / * T r y t o h a n d l e a s h p t e f a u l t * /
MMU_ F T R _ S E C T I O N _ E L S E
b h a n d l e _ p a g e _ f a u l t
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F C L R ( M M U _ F T R _ T Y P E _ R A D I X )
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( i n s t r u c t i o n _ a c c e s s _ s l b , 0 x48 0 , 0 x80 )
2018-09-14 18:30:51 +03:00
EXCEPTION_ P R O L O G ( P A C A _ E X S L B , i n s t r u c t i o n _ a c c e s s _ s l b _ c o m m o n , E X C _ S T D , K V M T E S T _ P R , 0 x48 0 ) ;
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( i n s t r u c t i o n _ a c c e s s _ s l b , 0 x48 0 , 0 x80 )
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ B E G I N ( i n s t r u c t i o n _ a c c e s s _ s l b , 0 x44 8 0 , 0 x80 )
2018-09-14 18:30:51 +03:00
EXCEPTION_ R E L O N _ P R O L O G ( P A C A _ E X S L B , i n s t r u c t i o n _ a c c e s s _ s l b _ c o m m o n , E X C _ S T D , N O T E S T , 0 x48 0 ) ;
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ E N D ( i n s t r u c t i o n _ a c c e s s _ s l b , 0 x44 8 0 , 0 x80 )
2018-10-02 16:56:39 +03:00
2018-09-14 18:30:51 +03:00
TRAMP_ K V M ( P A C A _ E X S L B , 0 x48 0 )
2018-10-02 16:56:39 +03:00
2018-09-14 18:30:51 +03:00
EXC_ C O M M O N _ B E G I N ( i n s t r u c t i o n _ a c c e s s _ s l b _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x48 0 , P A C A _ E X S L B )
ld r4 ,_ N I P ( r1 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2019-03-29 10:42:57 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
/* HPT case, do SLB fault */
2018-09-14 18:30:51 +03:00
bl d o _ s l b _ f a u l t
cmpdi r3 ,0
bne- 1 f
b f a s t _ e x c e p t i o n _ r e t u r n
1 : /* Error case */
2019-03-29 10:42:57 +03:00
MMU_ F T R _ S E C T I O N _ E L S E
/* Radix case, access is outside page table range */
li r3 ,- E F A U L T
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F C L R ( M M U _ F T R _ T Y P E _ R A D I X )
2018-09-14 18:30:51 +03:00
std r3 ,R E S U L T ( r1 )
2016-09-21 10:43:35 +03:00
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
2018-09-14 18:30:51 +03:00
ld r4 ,_ N I P ( r1 )
ld r5 ,R E S U L T ( r1 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl d o _ b a d _ s l b _ f a u l t
2016-09-21 10:43:35 +03:00
b r e t _ f r o m _ e x c e p t
2018-09-14 18:30:51 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( h a r d w a r e _ i n t e r r u p t , 0 x50 0 , 0 x10 0 )
2011-04-05 08:27:11 +04:00
.globl hardware_ i n t e r r u p t _ h v ;
hardware_interrupt_hv :
2011-04-05 08:20:31 +04:00
BEGIN_ F T R _ S E C T I O N
2018-07-26 16:07:17 +03:00
MASKABLE_ E X C E P T I O N _ H V ( 0 x50 0 , h a r d w a r e _ i n t e r r u p t _ c o m m o n , I R Q S _ D I S A B L E D )
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
FTR_ S E C T I O N _ E L S E
2018-07-26 16:07:17 +03:00
MASKABLE_ E X C E P T I O N ( 0 x50 0 , h a r d w a r e _ i n t e r r u p t _ c o m m o n , I R Q S _ D I S A B L E D )
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
ALT_ F T R _ S E C T I O N _ E N D _ I F S E T ( C P U _ F T R _ H V M O D E | C P U _ F T R _ A R C H _ 2 0 6 )
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( h a r d w a r e _ i n t e r r u p t , 0 x50 0 , 0 x10 0 )
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ B E G I N ( h a r d w a r e _ i n t e r r u p t , 0 x45 0 0 , 0 x10 0 )
2016-09-21 10:43:36 +03:00
.globl hardware_ i n t e r r u p t _ r e l o n _ h v ;
hardware_interrupt_relon_hv :
BEGIN_ F T R _ S E C T I O N
2018-07-26 16:07:17 +03:00
MASKABLE_ R E L O N _ E X C E P T I O N _ H V ( 0 x50 0 , h a r d w a r e _ i n t e r r u p t _ c o m m o n ,
IRQS_ D I S A B L E D )
2016-09-21 10:43:36 +03:00
FTR_ S E C T I O N _ E L S E
2018-07-26 16:07:15 +03:00
_ _ MASKABLE_ R E L O N _ E X C E P T I O N ( 0 x50 0 , h a r d w a r e _ i n t e r r u p t _ c o m m o n ,
2018-07-26 16:07:17 +03:00
EXC_ S T D , S O F T E N _ T E S T _ P R , I R Q S _ D I S A B L E D )
2016-09-21 10:43:36 +03:00
ALT_ F T R _ S E C T I O N _ E N D _ I F S E T ( C P U _ F T R _ H V M O D E )
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ E N D ( h a r d w a r e _ i n t e r r u p t , 0 x45 0 0 , 0 x10 0 )
2016-09-21 10:43:36 +03:00
2016-12-21 21:29:26 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x50 0 )
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x50 0 )
2016-09-21 10:43:36 +03:00
EXC_ C O M M O N _ A S Y N C ( h a r d w a r e _ i n t e r r u p t _ c o m m o n , 0 x50 0 , d o _ I R Q )
2019-02-26 11:51:09 +03:00
EXC_ R E A L _ B E G I N ( a l i g n m e n t , 0 x60 0 , 0 x10 0 )
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X G E N )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X G E N , K V M T E S T _ P R , 0 x60 0 )
2019-02-26 11:51:10 +03:00
mfspr r10 ,S P R N _ D A R
mfspr r11 ,S P R N _ D S I S R
std r10 ,P A C A _ E X G E N + E X _ D A R ( r13 )
stw r11 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
2019-02-26 11:51:09 +03:00
EXCEPTION_ P R O L O G _ 2 ( a l i g n m e n t _ c o m m o n , E X C _ S T D )
EXC_ R E A L _ E N D ( a l i g n m e n t , 0 x60 0 , 0 x10 0 )
EXC_ V I R T _ B E G I N ( a l i g n m e n t , 0 x46 0 0 , 0 x10 0 )
SET_ S C R A T C H 0 ( r13 ) / * s a v e r13 * /
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X G E N )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X G E N , N O T E S T , 0 x60 0 )
2019-02-26 11:51:10 +03:00
mfspr r10 ,S P R N _ D A R
mfspr r11 ,S P R N _ D S I S R
std r10 ,P A C A _ E X G E N + E X _ D A R ( r13 )
stw r11 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
2019-02-26 11:51:09 +03:00
EXCEPTION_ P R O L O G _ 2 _ R E L O N ( a l i g n m e n t _ c o m m o n , E X C _ S T D )
EXC_ V I R T _ E N D ( a l i g n m e n t , 0 x46 0 0 , 0 x10 0 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x60 0 )
2016-09-21 10:43:37 +03:00
EXC_ C O M M O N _ B E G I N ( a l i g n m e n t _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x60 0 , P A C A _ E X G E N )
ld r3 ,P A C A _ E X G E N + E X _ D A R ( r13 )
lwz r4 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
std r3 ,_ D A R ( r1 )
std r4 ,_ D S I S R ( r1 )
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl a l i g n m e n t _ e x c e p t i o n
b r e t _ f r o m _ e x c e p t
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( p r o g r a m _ c h e c k , 0 x70 0 , 0 x10 0 )
EXC_ V I R T ( p r o g r a m _ c h e c k , 0 x47 0 0 , 0 x10 0 , 0 x70 0 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x70 0 )
2016-09-21 10:43:38 +03:00
EXC_ C O M M O N _ B E G I N ( p r o g r a m _ c h e c k _ c o m m o n )
powerpc/64s: Use emergency stack for kernel TM Bad Thing program checks
When using transactional memory (TM), the CPU can be in one of six
states as far as TM is concerned, encoded in the Machine State
Register (MSR). Certain state transitions are illegal and if attempted
trigger a "TM Bad Thing" type program check exception.
If we ever hit one of these exceptions it's treated as a bug, ie. we
oops, and kill the process and/or panic, depending on configuration.
One case where we can trigger a TM Bad Thing, is when returning to
userspace after a system call or interrupt, using RFID. When this
happens the CPU first restores the user register state, in particular
r1 (the stack pointer) and then attempts to update the MSR. However
the MSR update is not allowed and so we take the program check with
the user register state, but the kernel MSR.
This tricks the exception entry code into thinking we have a bad
kernel stack pointer, because the MSR says we're coming from the
kernel, but r1 is pointing to userspace.
To avoid this we instead always switch to the emergency stack if we
take a TM Bad Thing from the kernel. That way none of the user
register values are used, other than for printing in the oops message.
This is the fix for CVE-2017-1000255.
Fixes: 5d176f751ee3 ("powerpc: tm: Enable transactional memory (TM) lazily for userspace")
Cc: stable@vger.kernel.org # v4.9+
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
[mpe: Rewrite change log & comments, tweak asm slightly]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2017-08-17 13:42:26 +03:00
/ *
* It' s p o s s i b l e t o r e c e i v e a T M B a d T h i n g t y p e p r o g r a m c h e c k w i t h
* userspace r e g i s t e r v a l u e s ( i n p a r t i c u l a r r1 ) , b u t w i t h S R R 1 r e p o r t i n g
* that w e c a m e f r o m t h e k e r n e l . N o r m a l l y t h a t w o u l d c o n f u s e t h e b a d
* stack l o g i c , a n d w e w o u l d r e p o r t a b a d k e r n e l s t a c k p o i n t e r . I n s t e a d
* we s w i t c h t o t h e e m e r g e n c y s t a c k i f w e ' r e t a k i n g a T M B a d T h i n g f r o m
* the k e r n e l .
* /
li r10 ,M S R _ P R / * B u i l d a m a s k o f M S R _ P R . . * /
oris r10 ,r10 ,0 x20 0 0 0 0 @h /* .. and SRR1_PROGTM */
and r10 ,r10 ,r12 / * M a s k S R R 1 w i t h t h a t . * /
srdi r10 ,r10 ,8 / * S h i f t i t s o w e c a n c o m p a r e * /
cmpldi r10 ,( 0 x20 0 0 0 0 > > 8 ) / * . . w i t h a n i m m e d i a t e . * /
bne 1 f / * I f ! = g o t o n o r m a l p a t h . * /
/* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
andi. r10 ,r12 ,M S R _ P R ; /* Set CR0 correctly for label */
/* 3 in EXCEPTION_PROLOG_COMMON */
mr r10 ,r1 / * S a v e r1 * /
ld r1 ,P A C A E M E R G S P ( r13 ) / * U s e e m e r g e n c y s t a c k * /
subi r1 ,r1 ,I N T _ F R A M E _ S I Z E / * a l l o c s t a c k f r a m e * /
b 3 f / * J u m p i n t o t h e m a c r o ! ! * /
1 : EXCEPTION_ P R O L O G _ C O M M O N ( 0 x70 0 , P A C A _ E X G E N )
2016-09-21 10:43:38 +03:00
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl p r o g r a m _ c h e c k _ e x c e p t i o n
b r e t _ f r o m _ e x c e p t
2011-06-29 04:18:26 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( f p _ u n a v a i l a b l e , 0 x80 0 , 0 x10 0 )
EXC_ V I R T ( f p _ u n a v a i l a b l e , 0 x48 0 0 , 0 x10 0 , 0 x80 0 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x80 0 )
2016-09-21 10:43:39 +03:00
EXC_ C O M M O N _ B E G I N ( f p _ u n a v a i l a b l e _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x80 0 , P A C A _ E X G E N )
bne 1 f / * i f f r o m u s e r , j u s t l o a d i t u p * /
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl k e r n e l _ f p _ u n a v a i l a b l e _ e x c e p t i o n
BUG_ O P C O D E
1 :
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
BEGIN_ F T R _ S E C T I O N
/ * Test i f 2 T M s t a t e b i t s a r e z e r o . I f n o n - z e r o ( i e . u s e r s p a c e w a s i n
* transaction) , g o d o T M s t u f f
* /
rldicl. r0 , r12 , ( 6 4 - M S R _ T S _ L G ) , ( 6 4 - 2 )
bne- 2 f
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ T M )
# endif
bl l o a d _ u p _ f p u
b f a s t _ e x c e p t i o n _ r e t u r n
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
2 : /* User process was in a transaction */
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl f p _ u n a v a i l a b l e _ t m
b r e t _ f r o m _ e x c e p t
# endif
2011-04-05 08:20:31 +04:00
2018-05-22 02:00:00 +03:00
EXC_ R E A L _ O O L _ M A S K A B L E ( d e c r e m e n t e r , 0 x90 0 , 0 x80 , I R Q S _ D I S A B L E D )
2017-12-20 06:55:52 +03:00
EXC_ V I R T _ M A S K A B L E ( d e c r e m e n t e r , 0 x49 0 0 , 0 x80 , 0 x90 0 , I R Q S _ D I S A B L E D )
2016-09-21 10:43:40 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x90 0 )
EXC_ C O M M O N _ A S Y N C ( d e c r e m e n t e r _ c o m m o n , 0 x90 0 , t i m e r _ i n t e r r u p t )
powerpc: Fix "attempt to move .org backwards" error
Building a 64-bit powerpc kernel with PR KVM enabled currently gives
this error:
AS arch/powerpc/kernel/head_64.o
arch/powerpc/kernel/exceptions-64s.S: Assembler messages:
arch/powerpc/kernel/exceptions-64s.S:258: Error: attempt to move .org backwards
make[2]: *** [arch/powerpc/kernel/head_64.o] Error 1
This happens because the MASKABLE_EXCEPTION_PSERIES macro turns into
33 instructions, but we only have space for 32 at the decrementer
interrupt vector (from 0x900 to 0x980).
In the code generated by the MASKABLE_EXCEPTION_PSERIES macro, we
currently have two instances of the HMT_MEDIUM macro, which has the
effect of setting the SMT thread priority to medium. One is the
first instruction, and is overwritten by a no-op on processors where
we save the PPR (processor priority register), that is, POWER7 or
later. The other is after we have saved the PPR.
In order to reduce the code at 0x900 by one instruction, we omit the
first HMT_MEDIUM. On processors without SMT this will have no effect
since HMT_MEDIUM is a no-op there. On POWER5 and RS64 machines this
will mean that the first few instructions take a little longer in the
case where a decrementer interrupt occurs when the hardware thread is
running at low SMT priority. On POWER6 and later machines, the
hardware automatically boosts the thread priority when a decrementer
interrupt is taken if the thread priority was below medium, so this
change won't make any difference.
The alternative would be to branch out of line after saving the CFAR.
However, that would incur an extra overhead on all processors, whereas
the approach adopted here only adds overhead on older threaded processors.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-04-25 21:51:40 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ H V ( h d e c r e m e n t e r , 0 x98 0 , 0 x80 )
EXC_ V I R T _ H V ( h d e c r e m e n t e r , 0 x49 8 0 , 0 x80 , 0 x98 0 )
2016-09-21 10:43:41 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x98 0 )
EXC_ C O M M O N ( h d e c r e m e n t e r _ c o m m o n , 0 x98 0 , h d e c _ i n t e r r u p t )
2011-04-05 08:20:31 +04:00
2017-12-20 06:55:52 +03:00
EXC_ R E A L _ M A S K A B L E ( d o o r b e l l _ s u p e r , 0 x a00 , 0 x10 0 , I R Q S _ D I S A B L E D )
EXC_ V I R T _ M A S K A B L E ( d o o r b e l l _ s u p e r , 0 x4 a00 , 0 x10 0 , 0 x a00 , I R Q S _ D I S A B L E D )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x a00 )
2016-09-21 10:43:42 +03:00
# ifdef C O N F I G _ P P C _ D O O R B E L L
EXC_ C O M M O N _ A S Y N C ( d o o r b e l l _ s u p e r _ c o m m o n , 0 x a00 , d o o r b e l l _ e x c e p t i o n )
# else
EXC_ C O M M O N _ A S Y N C ( d o o r b e l l _ s u p e r _ c o m m o n , 0 x a00 , u n k n o w n _ e x c e p t i o n )
# endif
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( t r a p _ 0 b , 0 x b00 , 0 x10 0 )
EXC_ V I R T ( t r a p _ 0 b , 0 x4 b00 , 0 x10 0 , 0 x b00 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x b00 )
2016-09-21 10:43:43 +03:00
EXC_ C O M M O N ( t r a p _ 0 b _ c o m m o n , 0 x b00 , u n k n o w n _ e x c e p t i o n )
2017-06-08 18:35:04 +03:00
/ *
* system c a l l / h y p e r c a l l ( 0 x c00 , 0 x4 c00 )
*
* The s y s t e m c a l l e x c e p t i o n i s i n v o k e d w i t h " s c 0 " a n d d o e s n o t a l t e r H V b i t .
* There i s s u p p o r t f o r k e r n e l c o d e t o i n v o k e s y s t e m c a l l s b u t t h e r e a r e n o
* in- t r e e u s e r s .
*
* The h y p e r c a l l i s i n v o k e d w i t h " s c 1 " a n d s e t s H V =1 .
*
* In H P T , s c 1 a l w a y s g o e s t o 0 x c00 r e a l m o d e . I n R A D I X , s c 1 c a n g o t o
* 0 x4 c00 v i r t u a l m o d e .
*
* Call c o n v e n t i o n :
*
* syscall r e g i s t e r c o n v e n t i o n i s i n D o c u m e n t a t i o n / p o w e r p c / s y s c a l l 6 4 - a b i . t x t
*
* For h y p e r c a l l s , t h e r e g i s t e r c o n v e n t i o n i s a s f o l l o w s :
* r0 v o l a t i l e
* r1 - 2 n o n v o l a t i l e
* r3 v o l a t i l e p a r a m e t e r a n d r e t u r n v a l u e f o r s t a t u s
* r4 - r10 v o l a t i l e i n p u t a n d o u t p u t v a l u e
* r1 1 v o l a t i l e h y p e r c a l l n u m b e r a n d o u t p u t v a l u e
2017-07-18 08:32:44 +03:00
* r1 2 v o l a t i l e i n p u t a n d o u t p u t v a l u e
2017-06-08 18:35:04 +03:00
* r1 3 - r31 n o n v o l a t i l e
* LR n o n v o l a t i l e
* CTR v o l a t i l e
* XER v o l a t i l e
* CR0 - 1 C R 5 - 7 v o l a t i l e
* CR2 - 4 n o n v o l a t i l e
* Other r e g i s t e r s n o n v o l a t i l e
*
* The i n t e r s e c t i o n o f v o l a t i l e r e g i s t e r s t h a t d o n ' t c o n t a i n p o s s i b l e
2017-07-18 08:32:44 +03:00
* inputs i s : c r0 , x e r , c t r . W e m a y u s e t h e s e a s s c r a t c h r e g s u p o n e n t r y
* without s a v i n g , t h o u g h x e r i s n o t a g o o d i d e a t o u s e , a s h a r d w a r e m a y
* interpret s o m e b i t s s o i t m a y b e c o s t l y t o c h a n g e t h e m .
2017-06-08 18:35:04 +03:00
* /
2017-01-30 13:21:40 +03:00
# ifdef C O N F I G _ K V M _ B O O K 3 S _ 6 4 _ H A N D L E R
2017-06-08 18:35:04 +03:00
/ *
* There i s a l i t t l e b i t o f j u g g l i n g t o g e t s y s c a l l a n d h c a l l
2017-07-18 08:32:44 +03:00
* working w e l l . S a v e r13 i n c t r t o a v o i d u s i n g S P R G s c r a t c h
* register.
2017-06-08 18:35:04 +03:00
*
* Userspace s y s c a l l s h a v e a l r e a d y s a v e d t h e P P R , h c a l l s m u s t s a v e
* it b e f o r e s e t t i n g H M T _ M E D I U M .
* /
2017-01-30 13:21:40 +03:00
# define S Y S C A L L _ K V M T E S T \
2017-07-18 08:32:44 +03:00
mtctr r13 ; \
2017-01-30 13:21:40 +03:00
GET_ P A C A ( r13 ) ; \
2017-07-18 08:32:44 +03:00
std r10 ,P A C A _ E X G E N + E X _ R 1 0 ( r13 ) ; \
2018-05-22 02:00:00 +03:00
INTERRUPT_ T O _ K E R N E L ; \
2017-06-08 18:35:04 +03:00
KVMTEST_ P R ( 0 x c00 ) ; /* uses r10, branch to do_kvm_0xc00_system_call */ \
2017-01-30 13:21:40 +03:00
HMT_ M E D I U M ; \
2017-07-18 08:32:44 +03:00
mfctr r9 ;
2017-01-30 13:21:40 +03:00
# else
# define S Y S C A L L _ K V M T E S T \
2017-06-08 18:35:04 +03:00
HMT_ M E D I U M ; \
mr r9 ,r13 ; \
2018-05-22 02:00:00 +03:00
GET_ P A C A ( r13 ) ; \
INTERRUPT_ T O _ K E R N E L ;
2017-01-30 13:21:40 +03:00
# endif
2016-10-13 05:17:14 +03:00
# define L O A D _ S Y S C A L L _ H A N D L E R ( r e g ) \
_ _ LOAD_ H A N D L E R ( r e g , s y s t e m _ c a l l _ c o m m o n )
2016-09-21 10:43:44 +03:00
2017-06-08 18:35:04 +03:00
/ *
* After S Y S C A L L _ K V M T E S T , w e r e a c h h e r e w i t h P A C A i n r13 , r13 i n r9 ,
* and H M T _ M E D I U M .
* /
# define S Y S C A L L _ R E A L \
mfspr r11 ,S P R N _ S R R 0 ; \
2016-09-21 10:43:44 +03:00
mfspr r12 ,S P R N _ S R R 1 ; \
LOAD_ S Y S C A L L _ H A N D L E R ( r10 ) ; \
mtspr S P R N _ S R R 0 ,r10 ; \
ld r10 ,P A C A K M S R ( r13 ) ; \
mtspr S P R N _ S R R 1 ,r10 ; \
2018-01-09 19:07:15 +03:00
RFI_ T O _ K E R N E L ; \
2016-09-21 10:43:44 +03:00
b . ; /* prevent speculative execution */
2017-10-09 13:54:05 +03:00
# ifdef C O N F I G _ P P C _ F A S T _ E N D I A N _ S W I T C H
2017-10-09 13:54:04 +03:00
# define S Y S C A L L _ F A S T E N D I A N _ T E S T \
BEGIN_ F T R _ S E C T I O N \
cmpdi r0 ,0 x1 e b e ; \
beq- 1 f ; \
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ R E A L _ L E ) \
2017-06-08 18:35:04 +03:00
# define S Y S C A L L _ F A S T E N D I A N \
2016-09-21 10:43:44 +03:00
/* Fast LE/BE switch system call */ \
1 : mfspr r12 ,S P R N _ S R R 1 ; \
xori r12 ,r12 ,M S R _ L E ; \
mtspr S P R N _ S R R 1 ,r12 ; \
2017-06-08 18:35:04 +03:00
mr r13 ,r9 ; \
2018-01-09 19:07:15 +03:00
RFI_ T O _ U S E R ; /* return to userspace */ \
2016-09-21 10:43:44 +03:00
b . ; /* prevent speculative execution */
2017-10-09 13:54:05 +03:00
# else
# define S Y S C A L L _ F A S T E N D I A N _ T E S T
# define S Y S C A L L _ F A S T E N D I A N
# endif / * C O N F I G _ P P C _ F A S T _ E N D I A N _ S W I T C H * /
2016-09-21 10:43:44 +03:00
# if d e f i n e d ( C O N F I G _ R E L O C A T A B L E )
/ *
* We c a n ' t b r a n c h d i r e c t l y s o w e d o i t v i a t h e C T R w h i c h
* is v o l a t i l e a c r o s s s y s t e m c a l l s .
* /
2017-06-08 18:35:04 +03:00
# define S Y S C A L L _ V I R T \
LOAD_ S Y S C A L L _ H A N D L E R ( r10 ) ; \
mtctr r10 ; \
mfspr r11 ,S P R N _ S R R 0 ; \
2016-09-21 10:43:44 +03:00
mfspr r12 ,S P R N _ S R R 1 ; \
li r10 ,M S R _ R I ; \
mtmsrd r10 ,1 ; \
bctr ;
# else
/* We can branch directly */
2017-06-08 18:35:04 +03:00
# define S Y S C A L L _ V I R T \
mfspr r11 ,S P R N _ S R R 0 ; \
2016-09-21 10:43:44 +03:00
mfspr r12 ,S P R N _ S R R 1 ; \
li r10 ,M S R _ R I ; \
mtmsrd r10 ,1 ; /* Set RI (EE=0) */ \
b s y s t e m _ c a l l _ c o m m o n ;
# endif
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( s y s t e m _ c a l l , 0 x c00 , 0 x10 0 )
2017-06-08 18:35:04 +03:00
SYSCALL_ K V M T E S T / * l o a d s P A C A i n t o r13 , a n d s a v e s r13 t o r9 * /
SYSCALL_ F A S T E N D I A N _ T E S T
SYSCALL_ R E A L
SYSCALL_ F A S T E N D I A N
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( s y s t e m _ c a l l , 0 x c00 , 0 x10 0 )
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ B E G I N ( s y s t e m _ c a l l , 0 x4 c00 , 0 x10 0 )
2017-06-08 18:35:04 +03:00
SYSCALL_ K V M T E S T / * l o a d s P A C A i n t o r13 , a n d s a v e s r13 t o r9 * /
SYSCALL_ F A S T E N D I A N _ T E S T
SYSCALL_ V I R T
SYSCALL_ F A S T E N D I A N
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ E N D ( s y s t e m _ c a l l , 0 x4 c00 , 0 x10 0 )
2016-09-21 10:43:44 +03:00
2017-06-08 18:35:04 +03:00
# ifdef C O N F I G _ K V M _ B O O K 3 S _ 6 4 _ H A N D L E R
/ *
* This i s a h c a l l , s o r e g i s t e r c o n v e n t i o n i s a s a b o v e , w i t h t h e s e
* differences :
* r1 3 = P A C A
2017-07-18 08:32:44 +03:00
* ctr = o r i g r13
* orig r10 s a v e d i n P A C A
2017-06-08 18:35:04 +03:00
* /
TRAMP_ K V M _ B E G I N ( d o _ k v m _ 0 x c00 )
/ *
* Save t h e P P R ( o n s y s t e m s t h a t s u p p o r t i t ) b e f o r e c h a n g i n g t o
* HMT_ M E D I U M . T h a t a l l o w s t h e K V M c o d e t o s a v e t h a t v a l u e i n t o t h e
* guest s t a t e ( i t i s t h e g u e s t ' s P P R v a l u e ) .
* /
2017-07-18 08:32:44 +03:00
OPT_ G E T _ S P R ( r10 , S P R N _ P P R , C P U _ F T R _ H A S _ P P R )
2017-06-08 18:35:04 +03:00
HMT_ M E D I U M
2017-07-18 08:32:44 +03:00
OPT_ S A V E _ R E G _ T O _ P A C A ( P A C A _ E X G E N + E X _ P P R , r10 , C P U _ F T R _ H A S _ P P R )
2017-06-08 18:35:04 +03:00
mfctr r10
2017-07-18 08:32:44 +03:00
SET_ S C R A T C H 0 ( r10 )
2017-06-08 18:35:04 +03:00
std r9 ,P A C A _ E X G E N + E X _ R 9 ( r13 )
mfcr r9
KVM_ H A N D L E R ( P A C A _ E X G E N , E X C _ S T D , 0 x c00 )
# endif
2016-09-30 12:43:18 +03:00
2016-09-21 10:43:44 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( s i n g l e _ s t e p , 0 x d00 , 0 x10 0 )
EXC_ V I R T ( s i n g l e _ s t e p , 0 x4 d00 , 0 x10 0 , 0 x d00 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x d00 )
2016-09-21 10:43:45 +03:00
EXC_ C O M M O N ( s i n g l e _ s t e p _ c o m m o n , 0 x d00 , s i n g l e _ s t e p _ e x c e p t i o n )
2011-06-29 04:18:26 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L _ H V ( h _ d a t a _ s t o r a g e , 0 x e 0 0 , 0 x20 )
2017-02-14 09:18:29 +03:00
EXC_ V I R T _ O O L _ H V ( h _ d a t a _ s t o r a g e , 0 x4 e 0 0 , 0 x20 , 0 x e 0 0 )
2016-09-21 10:43:46 +03:00
TRAMP_ K V M _ H V _ S K I P ( P A C A _ E X G E N , 0 x e 0 0 )
EXC_ C O M M O N _ B E G I N ( h _ d a t a _ s t o r a g e _ c o m m o n )
mfspr r10 ,S P R N _ H D A R
std r10 ,P A C A _ E X G E N + E X _ D A R ( r13 )
mfspr r10 ,S P R N _ H D S I S R
stw r10 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x e 0 0 , P A C A _ E X G E N )
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2018-12-14 08:29:05 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
ld r4 ,P A C A _ E X G E N + E X _ D A R ( r13 )
lwz r5 ,P A C A _ E X G E N + E X _ D S I S R ( r13 )
std r4 ,_ D A R ( r1 )
std r5 ,_ D S I S R ( r1 )
li r5 ,S I G S E G V
bl b a d _ p a g e _ f a u l t
MMU_ F T R _ S E C T I O N _ E L S E
2016-09-21 10:43:46 +03:00
bl u n k n o w n _ e x c e p t i o n
2018-12-14 08:29:05 +03:00
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F S E T ( M M U _ F T R _ T Y P E _ R A D I X )
2016-09-21 10:43:46 +03:00
b r e t _ f r o m _ e x c e p t
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L _ H V ( h _ i n s t r _ s t o r a g e , 0 x e 2 0 , 0 x20 )
2017-02-14 09:18:29 +03:00
EXC_ V I R T _ O O L _ H V ( h _ i n s t r _ s t o r a g e , 0 x4 e 2 0 , 0 x20 , 0 x e 2 0 )
2016-09-21 10:43:47 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x e 2 0 )
EXC_ C O M M O N ( h _ i n s t r _ s t o r a g e _ c o m m o n , 0 x e 2 0 , u n k n o w n _ e x c e p t i o n )
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L _ H V ( e m u l a t i o n _ a s s i s t , 0 x e 4 0 , 0 x20 )
EXC_ V I R T _ O O L _ H V ( e m u l a t i o n _ a s s i s t , 0 x4 e 4 0 , 0 x20 , 0 x e 4 0 )
2016-09-21 10:43:48 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x e 4 0 )
EXC_ C O M M O N ( e m u l a t i o n _ a s s i s t _ c o m m o n , 0 x e 4 0 , e m u l a t i o n _ a s s i s t _ i n t e r r u p t )
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
2016-09-21 10:44:07 +03:00
/ *
* hmi_ e x c e p t i o n t r a m p o l i n e i s a s p e c i a l c a s e . I t j u m p s t o h m i _ e x c e p t i o n _ e a r l y
* first, a n d t h e n e v e n t a u l l y f r o m t h e r e t o t h e t r a m p o l i n e t o g e t i n t o v i r t u a l
* mode.
* /
2016-12-06 04:41:12 +03:00
_ _ EXC_ R E A L _ O O L _ H V _ D I R E C T ( h m i _ e x c e p t i o n , 0 x e 6 0 , 0 x20 , h m i _ e x c e p t i o n _ e a r l y )
2017-12-20 06:55:52 +03:00
_ _ TRAMP_ R E A L _ O O L _ M A S K A B L E _ H V ( h m i _ e x c e p t i o n , 0 x e 6 0 , I R Q S _ D I S A B L E D )
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ N O N E ( 0 x4 e 6 0 , 0 x20 )
2016-09-21 10:43:49 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x e 6 0 )
TRAMP_ R E A L _ B E G I N ( h m i _ e x c e p t i o n _ e a r l y )
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X G E N , K V M T E S T _ H V , 0 x e 6 0 )
powerpc/64s: Exception macro for stack frame and initial register save
This code is common to a few exceptions, and another user will be added.
This causes a trivial change to generated code:
- 604: std r9,416(r1)
- 608: mfspr r11,314
- 60c: std r11,368(r1)
- 610: mfspr r12,315
+ 604: mfspr r11,314
+ 608: mfspr r12,315
+ 60c: std r9,416(r1)
+ 610: std r11,368(r1)
machine_check_powernv_early could also use this, but that requires non
trivial changes to generated code, so that's for another patch.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2016-12-19 21:30:03 +03:00
mr r10 ,r1 / * S a v e r1 * /
ld r1 ,P A C A E M E R G S P ( r13 ) / * U s e e m e r g e n c y s t a c k f o r r e a l m o d e * /
2016-09-21 10:43:49 +03:00
subi r1 ,r1 ,I N T _ F R A M E _ S I Z E / * a l l o c s t a c k f r a m e * /
mfspr r11 ,S P R N _ H S R R 0 / * S a v e H S R R 0 * /
powerpc/64s: Exception macro for stack frame and initial register save
This code is common to a few exceptions, and another user will be added.
This causes a trivial change to generated code:
- 604: std r9,416(r1)
- 608: mfspr r11,314
- 60c: std r11,368(r1)
- 610: mfspr r12,315
+ 604: mfspr r11,314
+ 608: mfspr r12,315
+ 60c: std r9,416(r1)
+ 610: std r11,368(r1)
machine_check_powernv_early could also use this, but that requires non
trivial changes to generated code, so that's for another patch.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2016-12-19 21:30:03 +03:00
mfspr r12 ,S P R N _ H S R R 1 / * S a v e H S R R 1 * /
EXCEPTION_ P R O L O G _ C O M M O N _ 1 ( )
2019-04-18 09:51:24 +03:00
/* We don't touch AMR here, we never go to virtual mode */
2016-09-21 10:43:49 +03:00
EXCEPTION_ P R O L O G _ C O M M O N _ 2 ( P A C A _ E X G E N )
EXCEPTION_ P R O L O G _ C O M M O N _ 3 ( 0 x e 6 0 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2018-10-08 07:08:31 +03:00
BRANCH_ L I N K _ T O _ F A R ( D O T S Y M ( h m i _ e x c e p t i o n _ r e a l m o d e ) ) / * F u n c t i o n c a l l A B I * /
2017-09-15 08:25:48 +03:00
cmpdi c r0 ,r3 ,0
2016-09-21 10:43:49 +03:00
/* Windup the stack. */
/* Move original HSRR0 and HSRR1 into the respective regs */
ld r9 ,_ M S R ( r1 )
mtspr S P R N _ H S R R 1 ,r9
ld r3 ,_ N I P ( r1 )
mtspr S P R N _ H S R R 0 ,r3
ld r9 ,_ C T R ( r1 )
mtctr r9
ld r9 ,_ X E R ( r1 )
mtxer r9
ld r9 ,_ L I N K ( r1 )
mtlr r9
REST_ G P R ( 0 , r1 )
REST_ 8 G P R S ( 2 , r1 )
REST_ G P R ( 1 0 , r1 )
ld r11 ,_ C C R ( r1 )
2017-09-15 08:25:48 +03:00
REST_ 2 G P R S ( 1 2 , r1 )
bne 1 f
2016-09-21 10:43:49 +03:00
mtcr r11
REST_ G P R ( 1 1 , r1 )
2017-09-15 08:25:48 +03:00
ld r1 ,G P R 1 ( r1 )
2018-01-09 19:07:15 +03:00
HRFI_ T O _ U S E R _ O R _ K E R N E L
2017-09-15 08:25:48 +03:00
1 : mtcr r11
REST_ G P R ( 1 1 , r1 )
2016-09-21 10:43:49 +03:00
ld r1 ,G P R 1 ( r1 )
/ *
* Go t o v i r t u a l m o d e a n d p u l l t h e H M I e v e n t i n f o r m a t i o n f r o m
* firmware.
* /
.globl hmi_exception_after_realmode
hmi_exception_after_realmode :
SET_ S C R A T C H 0 ( r13 )
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X G E N )
b t r a m p _ r e a l _ h m i _ e x c e p t i o n
2017-09-15 08:25:48 +03:00
EXC_ C O M M O N _ B E G I N ( h m i _ e x c e p t i o n _ c o m m o n )
EXCEPTION_ C O M M O N ( P A C A _ E X G E N , 0 x e 6 0 , h m i _ e x c e p t i o n _ c o m m o n , h a n d l e _ h m i _ e x c e p t i o n ,
ret_ f r o m _ e x c e p t , F I N I S H _ N A P ;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
2017-12-20 06:55:52 +03:00
EXC_ R E A L _ O O L _ M A S K A B L E _ H V ( h _ d o o r b e l l , 0 x e 8 0 , 0 x20 , I R Q S _ D I S A B L E D )
EXC_ V I R T _ O O L _ M A S K A B L E _ H V ( h _ d o o r b e l l , 0 x4 e 8 0 , 0 x20 , 0 x e 8 0 , I R Q S _ D I S A B L E D )
2016-09-21 10:43:50 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x e 8 0 )
# ifdef C O N F I G _ P P C _ D O O R B E L L
EXC_ C O M M O N _ A S Y N C ( h _ d o o r b e l l _ c o m m o n , 0 x e 8 0 , d o o r b e l l _ e x c e p t i o n )
# else
EXC_ C O M M O N _ A S Y N C ( h _ d o o r b e l l _ c o m m o n , 0 x e 8 0 , u n k n o w n _ e x c e p t i o n )
# endif
2009-06-03 01:17:38 +04:00
2017-12-20 06:55:52 +03:00
EXC_ R E A L _ O O L _ M A S K A B L E _ H V ( h _ v i r t _ i r q , 0 x e a0 , 0 x20 , I R Q S _ D I S A B L E D )
EXC_ V I R T _ O O L _ M A S K A B L E _ H V ( h _ v i r t _ i r q , 0 x4 e a0 , 0 x20 , 0 x e a0 , I R Q S _ D I S A B L E D )
2016-09-21 10:43:51 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x e a0 )
EXC_ C O M M O N _ A S Y N C ( h _ v i r t _ i r q _ c o m m o n , 0 x e a0 , d o _ I R Q )
2016-07-08 09:37:06 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ N O N E ( 0 x e c0 , 0 x20 )
EXC_ V I R T _ N O N E ( 0 x4 e c0 , 0 x20 )
EXC_ R E A L _ N O N E ( 0 x e e 0 , 0 x20 )
EXC_ V I R T _ N O N E ( 0 x4 e e 0 , 0 x20 )
2016-09-21 10:43:52 +03:00
2009-06-03 01:17:38 +04:00
2017-12-20 06:55:53 +03:00
EXC_ R E A L _ O O L _ M A S K A B L E ( p e r f o r m a n c e _ m o n i t o r , 0 x f00 , 0 x20 , I R Q S _ P M I _ D I S A B L E D )
EXC_ V I R T _ O O L _ M A S K A B L E ( p e r f o r m a n c e _ m o n i t o r , 0 x4 f00 , 0 x20 , 0 x f00 , I R Q S _ P M I _ D I S A B L E D )
2016-09-21 10:43:53 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x f00 )
EXC_ C O M M O N _ A S Y N C ( p e r f o r m a n c e _ m o n i t o r _ c o m m o n , 0 x f00 , p e r f o r m a n c e _ m o n i t o r _ e x c e p t i o n )
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L ( a l t i v e c _ u n a v a i l a b l e , 0 x f20 , 0 x20 )
EXC_ V I R T _ O O L ( a l t i v e c _ u n a v a i l a b l e , 0 x4 f20 , 0 x20 , 0 x f20 )
2016-09-21 10:43:54 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x f20 )
EXC_ C O M M O N _ B E G I N ( a l t i v e c _ u n a v a i l a b l e _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x f20 , P A C A _ E X G E N )
# ifdef C O N F I G _ A L T I V E C
BEGIN_ F T R _ S E C T I O N
beq 1 f
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
BEGIN_ F T R _ S E C T I O N _ N E S T E D ( 6 9 )
/ * Test i f 2 T M s t a t e b i t s a r e z e r o . I f n o n - z e r o ( i e . u s e r s p a c e w a s i n
* transaction) , g o d o T M s t u f f
* /
rldicl. r0 , r12 , ( 6 4 - M S R _ T S _ L G ) , ( 6 4 - 2 )
bne- 2 f
END_ F T R _ S E C T I O N _ N E S T E D ( C P U _ F T R _ T M , C P U _ F T R _ T M , 6 9 )
# endif
bl l o a d _ u p _ a l t i v e c
b f a s t _ e x c e p t i o n _ r e t u r n
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
2 : /* User process was in a transaction */
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl a l t i v e c _ u n a v a i l a b l e _ t m
b r e t _ f r o m _ e x c e p t
# endif
1 :
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A L T I V E C )
# endif
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl a l t i v e c _ u n a v a i l a b l e _ e x c e p t i o n
b r e t _ f r o m _ e x c e p t
2009-06-03 01:17:38 +04:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L ( v s x _ u n a v a i l a b l e , 0 x f40 , 0 x20 )
EXC_ V I R T _ O O L ( v s x _ u n a v a i l a b l e , 0 x4 f40 , 0 x20 , 0 x f40 )
2016-09-21 10:43:55 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x f40 )
EXC_ C O M M O N _ B E G I N ( v s x _ u n a v a i l a b l e _ c o m m o n )
EXCEPTION_ P R O L O G _ C O M M O N ( 0 x f40 , P A C A _ E X G E N )
# ifdef C O N F I G _ V S X
BEGIN_ F T R _ S E C T I O N
beq 1 f
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
BEGIN_ F T R _ S E C T I O N _ N E S T E D ( 6 9 )
/ * Test i f 2 T M s t a t e b i t s a r e z e r o . I f n o n - z e r o ( i e . u s e r s p a c e w a s i n
* transaction) , g o d o T M s t u f f
* /
rldicl. r0 , r12 , ( 6 4 - M S R _ T S _ L G ) , ( 6 4 - 2 )
bne- 2 f
END_ F T R _ S E C T I O N _ N E S T E D ( C P U _ F T R _ T M , C P U _ F T R _ T M , 6 9 )
# endif
b l o a d _ u p _ v s x
# ifdef C O N F I G _ P P C _ T R A N S A C T I O N A L _ M E M
2 : /* User process was in a transaction */
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl v s x _ u n a v a i l a b l e _ t m
b r e t _ f r o m _ e x c e p t
# endif
1 :
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ V S X )
# endif
bl s a v e _ n v g p r s
RECONCILE_ I R Q _ S T A T E ( r10 , r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl v s x _ u n a v a i l a b l e _ e x c e p t i o n
b r e t _ f r o m _ e x c e p t
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L ( f a c i l i t y _ u n a v a i l a b l e , 0 x f60 , 0 x20 )
EXC_ V I R T _ O O L ( f a c i l i t y _ u n a v a i l a b l e , 0 x4 f60 , 0 x20 , 0 x f60 )
2016-09-21 10:43:56 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x f60 )
EXC_ C O M M O N ( f a c i l i t y _ u n a v a i l a b l e _ c o m m o n , 0 x f60 , f a c i l i t y _ u n a v a i l a b l e _ e x c e p t i o n )
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ O O L _ H V ( h _ f a c i l i t y _ u n a v a i l a b l e , 0 x f80 , 0 x20 )
EXC_ V I R T _ O O L _ H V ( h _ f a c i l i t y _ u n a v a i l a b l e , 0 x4 f80 , 0 x20 , 0 x f80 )
2016-09-21 10:43:57 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x f80 )
EXC_ C O M M O N ( h _ f a c i l i t y _ u n a v a i l a b l e _ c o m m o n , 0 x f80 , f a c i l i t y _ u n a v a i l a b l e _ e x c e p t i o n )
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ N O N E ( 0 x f a0 , 0 x20 )
EXC_ V I R T _ N O N E ( 0 x4 f a0 , 0 x20 )
EXC_ R E A L _ N O N E ( 0 x f c0 , 0 x20 )
EXC_ V I R T _ N O N E ( 0 x4 f c0 , 0 x20 )
EXC_ R E A L _ N O N E ( 0 x f e 0 , 0 x20 )
EXC_ V I R T _ N O N E ( 0 x4 f e 0 , 0 x20 )
EXC_ R E A L _ N O N E ( 0 x10 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x50 0 0 , 0 x10 0 )
EXC_ R E A L _ N O N E ( 0 x11 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x51 0 0 , 0 x10 0 )
2013-02-13 20:21:38 +04:00
2009-06-03 01:17:38 +04:00
# ifdef C O N F I G _ C B E _ R A S
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ H V ( c b e _ s y s t e m _ e r r o r , 0 x12 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x52 0 0 , 0 x10 0 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M _ H V _ S K I P ( P A C A _ E X G E N , 0 x12 0 0 )
2016-09-21 10:43:59 +03:00
EXC_ C O M M O N ( c b e _ s y s t e m _ e r r o r _ c o m m o n , 0 x12 0 0 , c b e _ s y s t e m _ e r r o r _ e x c e p t i o n )
2016-09-30 12:43:18 +03:00
# else / * C O N F I G _ C B E _ R A S * /
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ N O N E ( 0 x12 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x52 0 0 , 0 x10 0 )
2016-09-30 12:43:18 +03:00
# endif
2011-06-29 04:18:26 +04:00
2016-09-21 10:43:59 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( i n s t r u c t i o n _ b r e a k p o i n t , 0 x13 0 0 , 0 x10 0 )
EXC_ V I R T ( i n s t r u c t i o n _ b r e a k p o i n t , 0 x53 0 0 , 0 x10 0 , 0 x13 0 0 )
2016-09-30 12:43:18 +03:00
TRAMP_ K V M _ S K I P ( P A C A _ E X G E N , 0 x13 0 0 )
2016-09-21 10:44:00 +03:00
EXC_ C O M M O N ( i n s t r u c t i o n _ b r e a k p o i n t _ c o m m o n , 0 x13 0 0 , i n s t r u c t i o n _ b r e a k p o i n t _ e x c e p t i o n )
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ N O N E ( 0 x14 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x54 0 0 , 0 x10 0 )
2016-09-30 12:43:18 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ B E G I N ( d e n o r m _ e x c e p t i o n _ h v , 0 x15 0 0 , 0 x10 0 )
2012-09-10 04:35:26 +04:00
mtspr S P R N _ S P R G _ H S C R A T C H 0 ,r13
powerpc: Save CFAR before branching in interrupt entry paths
Some of the interrupt vectors on 64-bit POWER server processors are
only 32 bytes long, which is not enough for the full first-level
interrupt handler. For these we currently just have a branch to an
out-of-line handler. However, this means that we corrupt the CFAR
(come-from address register) on POWER7 and later processors.
To fix this, we split the EXCEPTION_PROLOG_1 macro into two pieces:
EXCEPTION_PROLOG_0 contains the part up to the point where the CFAR
is saved in the PACA, and EXCEPTION_PROLOG_1 contains the rest. We
then put EXCEPTION_PROLOG_0 in the short interrupt vectors before
we branch to the out-of-line handler, which contains the rest of the
first-level interrupt handler. To facilitate this, we define new
_OOL (out of line) variants of STD_EXCEPTION_PSERIES, etc.
In order to get EXCEPTION_PROLOG_0 to be short enough, i.e., no more
than 6 instructions, it was necessary to move the stores that move
the PPR and CFAR values into the PACA into __EXCEPTION_PROLOG_1 and
to get rid of one of the two HMT_MEDIUM instructions. Previously
there was a HMT_MEDIUM_PPR_DISCARD before the prolog, which was
nop'd out on processors with the PPR (POWER7 and later), and then
another HMT_MEDIUM inside the HMT_MEDIUM_PPR_SAVE macro call inside
__EXCEPTION_PROLOG_1, which was nop'd out on processors without PPR.
Now the HMT_MEDIUM inside EXCEPTION_PROLOG_0 is there unconditionally
and the HMT_MEDIUM_PPR_DISCARD is not strictly necessary, although
this leaves it in for the interrupt vectors where there is room for
it.
Previously we had a handler for hypervisor maintenance interrupts at
0xe50, which doesn't leave enough room for the vector for hypervisor
emulation assist interrupts at 0xe40, since we need 8 instructions.
The 0xe50 vector was only used on POWER6, as the HMI vector was moved
to 0xe60 on POWER7. Since we don't support running in hypervisor mode
on POWER6, we just remove the handler at 0xe50.
This also changes denorm_exception_hv to use EXCEPTION_PROLOG_0
instead of open-coding it, and removes the HMT_MEDIUM_PPR_DISCARD
from the relocation-on vectors (since any CPU that supports
relocation-on interrupts also has the PPR).
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-02-04 22:10:15 +04:00
EXCEPTION_ P R O L O G _ 0 ( P A C A _ E X G E N )
2013-08-12 10:12:06 +04:00
EXCEPTION_ P R O L O G _ 1 ( P A C A _ E X G E N , N O T E S T , 0 x15 0 0 )
2012-09-10 04:35:26 +04:00
# ifdef C O N F I G _ P P C _ D E N O R M A L I S A T I O N
mfspr r10 ,S P R N _ H S R R 1
2016-09-21 10:43:31 +03:00
andis. r10 ,r10 ,( H S R R 1 _ D E N O R M ) @h /* denorm? */
bne+ d e n o r m _ a s s i s t
# endif
powerpc/book3s: handle machine check in Linux host.
Move machine check entry point into Linux. So far we were dependent on
firmware to decode MCE error details and handover the high level info to OS.
This patch introduces early machine check routine that saves the MCE
information (srr1, srr0, dar and dsisr) to the emergency stack. We allocate
stack frame on emergency stack and set the r1 accordingly. This allows us to be
prepared to take another exception without loosing context. One thing to note
here that, if we get another machine check while ME bit is off then we risk a
checkstop. Hence we restrict ourselves to save only MCE information and
register saved on PACA_EXMC save are before we turn the ME bit on. We use
paca->in_mce flag to differentiate between first entry and nested machine check
entry which helps proper use of emergency stack. We increment paca->in_mce
every time we enter in early machine check handler and decrement it while
leaving. When we enter machine check early handler first time (paca->in_mce ==
0), we are sure nobody is using MC emergency stack and allocate a stack frame
at the start of the emergency stack. During subsequent entry (paca->in_mce >
0), we know that r1 points inside emergency stack and we allocate separate
stack frame accordingly. This prevents us from clobbering MCE information
during nested machine checks.
The early machine check handler changes are placed under CPU_FTR_HVMODE
section. This makes sure that the early machine check handler will get executed
only in hypervisor kernel.
This is the code flow:
Machine Check Interrupt
|
V
0x200 vector ME=0, IR=0, DR=0
|
V
+-----------------------------------------------+
|machine_check_pSeries_early: | ME=0, IR=0, DR=0
| Alloc frame on emergency stack |
| Save srr1, srr0, dar and dsisr on stack |
+-----------------------------------------------+
|
(ME=1, IR=0, DR=0, RFID)
|
V
machine_check_handle_early ME=1, IR=0, DR=0
|
V
+-----------------------------------------------+
| machine_check_early (r3=pt_regs) | ME=1, IR=0, DR=0
| Things to do: (in next patches) |
| Flush SLB for SLB errors |
| Flush TLB for TLB errors |
| Decode and save MCE info |
+-----------------------------------------------+
|
(Fall through existing exception handler routine.)
|
V
machine_check_pSerie ME=1, IR=0, DR=0
|
(ME=1, IR=1, DR=1, RFID)
|
V
machine_check_common ME=1, IR=1, DR=1
.
.
.
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2013-10-30 18:34:08 +04:00
KVM: PPC: Book3S HV: Work around transactional memory bugs in POWER9
POWER9 has hardware bugs relating to transactional memory and thread
reconfiguration (changes to hardware SMT mode). Specifically, the core
does not have enough storage to store a complete checkpoint of all the
architected state for all four threads. The DD2.2 version of POWER9
includes hardware modifications designed to allow hypervisor software
to implement workarounds for these problems. This patch implements
those workarounds in KVM code so that KVM guests see a full, working
transactional memory implementation.
The problems center around the use of TM suspended state, where the
CPU has a checkpointed state but execution is not transactional. The
workaround is to implement a "fake suspend" state, which looks to the
guest like suspended state but the CPU does not store a checkpoint.
In this state, any instruction that would cause a transition to
transactional state (rfid, rfebb, mtmsrd, tresume) or would use the
checkpointed state (treclaim) causes a "soft patch" interrupt (vector
0x1500) to the hypervisor so that it can be emulated. The trechkpt
instruction also causes a soft patch interrupt.
On POWER9 DD2.2, we avoid returning to the guest in any state which
would require a checkpoint to be present. The trechkpt in the guest
entry path which would normally create that checkpoint is replaced by
either a transition to fake suspend state, if the guest is in suspend
state, or a rollback to the pre-transactional state if the guest is in
transactional state. Fake suspend state is indicated by a flag in the
PACA plus a new bit in the PSSCR. The new PSSCR bit is write-only and
reads back as 0.
On exit from the guest, if the guest is in fake suspend state, we still
do the treclaim instruction as we would in real suspend state, in order
to get into non-transactional state, but we do not save the resulting
register state since there was no checkpoint.
Emulation of the instructions that cause a softpatch interrupt is
handled in two paths. If the guest is in real suspend mode, we call
kvmhv_p9_tm_emulation_early() to handle the cases where the guest is
transitioning to transactional state. This is called before we do the
treclaim in the guest exit path; because we haven't done treclaim, we
can get back to the guest with the transaction still active. If the
instruction is a case that kvmhv_p9_tm_emulation_early() doesn't
handle, or if the guest is in fake suspend state, then we proceed to
do the complete guest exit path and subsequently call
kvmhv_p9_tm_emulation() in host context with the MMU on. This handles
all the cases including the cases that generate program interrupts
(illegal instruction or TM Bad Thing) and facility unavailable
interrupts.
The emulation is reasonably straightforward and is mostly concerned
with checking for exception conditions and updating the state of
registers such as MSR and CR0. The treclaim emulation takes care to
ensure that the TEXASR register gets updated as if it were the guest
treclaim instruction that had done failure recording, not the treclaim
done in hypervisor state in the guest exit path.
With this, the KVM_CAP_PPC_HTM capability returns true (1) even if
transactional memory is not available to host userspace.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 13:32:01 +03:00
KVMTEST_ H V ( 0 x15 0 0 )
2018-07-26 16:07:08 +03:00
EXCEPTION_ P R O L O G _ 2 ( d e n o r m _ c o m m o n , E X C _ H V )
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ E N D ( d e n o r m _ e x c e p t i o n _ h v , 0 x15 0 0 , 0 x10 0 )
2016-08-10 13:48:43 +03:00
2016-09-21 10:44:01 +03:00
# ifdef C O N F I G _ P P C _ D E N O R M A L I S A T I O N
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ B E G I N ( d e n o r m _ e x c e p t i o n , 0 x55 0 0 , 0 x10 0 )
2016-09-21 10:44:01 +03:00
b e x c _ r e a l _ 0 x15 0 0 _ d e n o r m _ e x c e p t i o n _ h v
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ E N D ( d e n o r m _ e x c e p t i o n , 0 x55 0 0 , 0 x10 0 )
2016-09-21 10:44:01 +03:00
# else
2016-12-06 04:41:12 +03:00
EXC_ V I R T _ N O N E ( 0 x55 0 0 , 0 x10 0 )
2016-09-21 10:43:31 +03:00
# endif
KVM: PPC: Book3S HV: Work around transactional memory bugs in POWER9
POWER9 has hardware bugs relating to transactional memory and thread
reconfiguration (changes to hardware SMT mode). Specifically, the core
does not have enough storage to store a complete checkpoint of all the
architected state for all four threads. The DD2.2 version of POWER9
includes hardware modifications designed to allow hypervisor software
to implement workarounds for these problems. This patch implements
those workarounds in KVM code so that KVM guests see a full, working
transactional memory implementation.
The problems center around the use of TM suspended state, where the
CPU has a checkpointed state but execution is not transactional. The
workaround is to implement a "fake suspend" state, which looks to the
guest like suspended state but the CPU does not store a checkpoint.
In this state, any instruction that would cause a transition to
transactional state (rfid, rfebb, mtmsrd, tresume) or would use the
checkpointed state (treclaim) causes a "soft patch" interrupt (vector
0x1500) to the hypervisor so that it can be emulated. The trechkpt
instruction also causes a soft patch interrupt.
On POWER9 DD2.2, we avoid returning to the guest in any state which
would require a checkpoint to be present. The trechkpt in the guest
entry path which would normally create that checkpoint is replaced by
either a transition to fake suspend state, if the guest is in suspend
state, or a rollback to the pre-transactional state if the guest is in
transactional state. Fake suspend state is indicated by a flag in the
PACA plus a new bit in the PSSCR. The new PSSCR bit is write-only and
reads back as 0.
On exit from the guest, if the guest is in fake suspend state, we still
do the treclaim instruction as we would in real suspend state, in order
to get into non-transactional state, but we do not save the resulting
register state since there was no checkpoint.
Emulation of the instructions that cause a softpatch interrupt is
handled in two paths. If the guest is in real suspend mode, we call
kvmhv_p9_tm_emulation_early() to handle the cases where the guest is
transitioning to transactional state. This is called before we do the
treclaim in the guest exit path; because we haven't done treclaim, we
can get back to the guest with the transaction still active. If the
instruction is a case that kvmhv_p9_tm_emulation_early() doesn't
handle, or if the guest is in fake suspend state, then we proceed to
do the complete guest exit path and subsequently call
kvmhv_p9_tm_emulation() in host context with the MMU on. This handles
all the cases including the cases that generate program interrupts
(illegal instruction or TM Bad Thing) and facility unavailable
interrupts.
The emulation is reasonably straightforward and is mostly concerned
with checking for exception conditions and updating the state of
registers such as MSR and CR0. The treclaim emulation takes care to
ensure that the TEXASR register gets updated as if it were the guest
treclaim instruction that had done failure recording, not the treclaim
done in hypervisor state in the guest exit path.
With this, the KVM_CAP_PPC_HTM capability returns true (1) even if
transactional memory is not available to host userspace.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-03-21 13:32:01 +03:00
TRAMP_ K V M _ H V ( P A C A _ E X G E N , 0 x15 0 0 )
2011-06-29 04:18:26 +04:00
2012-09-10 04:35:26 +04:00
# ifdef C O N F I G _ P P C _ D E N O R M A L I S A T I O N
2016-09-30 12:43:18 +03:00
TRAMP_ R E A L _ B E G I N ( d e n o r m _ a s s i s t )
2012-09-10 04:35:26 +04:00
BEGIN_ F T R _ S E C T I O N
/ *
* To d e n o r m a l i s e w e n e e d t o m o v e a c o p y o f t h e r e g i s t e r t o i t s e l f .
* For P O W E R 6 d o t h a t h e r e f o r a l l F P r e g s .
* /
mfmsr r10
ori r10 ,r10 ,( M S R _ F P | M S R _ F E 0 | M S R _ F E 1 )
xori r10 ,r10 ,( M S R _ F E 0 | M S R _ F E 1 )
mtmsrd r10
sync
2013-05-30 01:33:18 +04:00
# define F M R 2 ( n ) f m r ( n ) , ( n ) ; fmr n+1, n+1
# define F M R 4 ( n ) F M R 2 ( n ) ; FMR2(n+2)
# define F M R 8 ( n ) F M R 4 ( n ) ; FMR4(n+4)
# define F M R 1 6 ( n ) F M R 8 ( n ) ; FMR8(n+8)
# define F M R 3 2 ( n ) F M R 1 6 ( n ) ; FMR16(n+16)
FMR3 2 ( 0 )
2012-09-10 04:35:26 +04:00
FTR_ S E C T I O N _ E L S E
/ *
* To d e n o r m a l i s e w e n e e d t o m o v e a c o p y o f t h e r e g i s t e r t o i t s e l f .
* For P O W E R 7 d o t h a t h e r e f o r t h e f i r s t 3 2 V S X r e g i s t e r s o n l y .
* /
mfmsr r10
oris r10 ,r10 ,M S R _ V S X @h
mtmsrd r10
sync
2013-05-30 01:33:18 +04:00
# define X V C P S G N D P 2 ( n ) X V C P S G N D P ( n ,n ,n ) ; XVCPSGNDP(n+1,n+1,n+1)
# define X V C P S G N D P 4 ( n ) X V C P S G N D P 2 ( n ) ; XVCPSGNDP2(n+2)
# define X V C P S G N D P 8 ( n ) X V C P S G N D P 4 ( n ) ; XVCPSGNDP4(n+4)
# define X V C P S G N D P 1 6 ( n ) X V C P S G N D P 8 ( n ) ; XVCPSGNDP8(n+8)
# define X V C P S G N D P 3 2 ( n ) X V C P S G N D P 1 6 ( n ) ; XVCPSGNDP16(n+16)
XVCPSGNDP3 2 ( 0 )
2012-09-10 04:35:26 +04:00
ALT_ F T R _ S E C T I O N _ E N D _ I F C L R ( C P U _ F T R _ A R C H _ 2 0 6 )
2013-05-30 01:33:19 +04:00
BEGIN_ F T R _ S E C T I O N
b d e n o r m _ d o n e
END_ F T R _ S E C T I O N _ I F C L R ( C P U _ F T R _ A R C H _ 2 0 7 S )
/ *
* To d e n o r m a l i s e w e n e e d t o m o v e a c o p y o f t h e r e g i s t e r t o i t s e l f .
* For P O W E R 8 w e n e e d t o d o t h a t f o r a l l 6 4 V S X r e g i s t e r s
* /
XVCPSGNDP3 2 ( 3 2 )
denorm_done :
2018-09-13 08:33:47 +03:00
mfspr r11 ,S P R N _ H S R R 0
subi r11 ,r11 ,4
2012-09-10 04:35:26 +04:00
mtspr S P R N _ H S R R 0 ,r11
mtcrf 0 x80 ,r9
ld r9 ,P A C A _ E X G E N + E X _ R 9 ( r13 )
2012-12-07 01:51:04 +04:00
RESTORE_ P P R _ P A C A ( P A C A _ E X G E N , r10 )
2013-08-12 10:12:06 +04:00
BEGIN_ F T R _ S E C T I O N
ld r10 ,P A C A _ E X G E N + E X _ C F A R ( r13 )
mtspr S P R N _ C F A R ,r10
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ C F A R )
2012-09-10 04:35:26 +04:00
ld r10 ,P A C A _ E X G E N + E X _ R 1 0 ( r13 )
ld r11 ,P A C A _ E X G E N + E X _ R 1 1 ( r13 )
ld r12 ,P A C A _ E X G E N + E X _ R 1 2 ( r13 )
ld r13 ,P A C A _ E X G E N + E X _ R 1 3 ( r13 )
2018-01-09 19:07:15 +03:00
HRFI_ T O _ U N K N O W N
2012-09-10 04:35:26 +04:00
b .
# endif
2018-01-12 05:28:48 +03:00
EXC_ C O M M O N ( d e n o r m _ c o m m o n , 0 x15 0 0 , u n k n o w n _ e x c e p t i o n )
2016-09-21 10:44:01 +03:00
# ifdef C O N F I G _ C B E _ R A S
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ H V ( c b e _ m a i n t e n a n c e , 0 x16 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x56 0 0 , 0 x10 0 )
2016-09-21 10:44:01 +03:00
TRAMP_ K V M _ H V _ S K I P ( P A C A _ E X G E N , 0 x16 0 0 )
2016-09-21 10:44:02 +03:00
EXC_ C O M M O N ( c b e _ m a i n t e n a n c e _ c o m m o n , 0 x16 0 0 , c b e _ m a i n t e n a n c e _ e x c e p t i o n )
2016-09-21 10:44:01 +03:00
# else / * C O N F I G _ C B E _ R A S * /
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ N O N E ( 0 x16 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x56 0 0 , 0 x10 0 )
2016-09-21 10:44:01 +03:00
# endif
2016-09-21 10:44:02 +03:00
2016-12-06 04:41:12 +03:00
EXC_ R E A L ( a l t i v e c _ a s s i s t , 0 x17 0 0 , 0 x10 0 )
EXC_ V I R T ( a l t i v e c _ a s s i s t , 0 x57 0 0 , 0 x10 0 , 0 x17 0 0 )
2016-09-21 10:44:01 +03:00
TRAMP_ K V M ( P A C A _ E X G E N , 0 x17 0 0 )
2016-09-21 10:44:03 +03:00
# ifdef C O N F I G _ A L T I V E C
EXC_ C O M M O N ( a l t i v e c _ a s s i s t _ c o m m o n , 0 x17 0 0 , a l t i v e c _ a s s i s t _ e x c e p t i o n )
# else
EXC_ C O M M O N ( a l t i v e c _ a s s i s t _ c o m m o n , 0 x17 0 0 , u n k n o w n _ e x c e p t i o n )
# endif
2016-09-21 10:44:01 +03:00
# ifdef C O N F I G _ C B E _ R A S
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ H V ( c b e _ t h e r m a l , 0 x18 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x58 0 0 , 0 x10 0 )
2016-09-21 10:44:01 +03:00
TRAMP_ K V M _ H V _ S K I P ( P A C A _ E X G E N , 0 x18 0 0 )
2016-09-21 10:44:04 +03:00
EXC_ C O M M O N ( c b e _ t h e r m a l _ c o m m o n , 0 x18 0 0 , c b e _ t h e r m a l _ e x c e p t i o n )
2016-09-21 10:44:01 +03:00
# else / * C O N F I G _ C B E _ R A S * /
2016-12-06 04:41:12 +03:00
EXC_ R E A L _ N O N E ( 0 x18 0 0 , 0 x10 0 )
EXC_ V I R T _ N O N E ( 0 x58 0 0 , 0 x10 0 )
2016-09-21 10:44:01 +03:00
# endif
2017-08-01 15:00:52 +03:00
# ifdef C O N F I G _ P P C _ W A T C H D O G
2017-07-13 00:35:52 +03:00
# define M A S K E D _ D E C _ H A N D L E R _ L A B E L 3 f
# define M A S K E D _ D E C _ H A N D L E R ( _ H ) \
3 : /* soft-nmi */ \
std r12 ,P A C A _ E X G E N + E X _ R 1 2 ( r13 ) ; \
GET_ S C R A T C H 0 ( r10 ) ; \
std r10 ,P A C A _ E X G E N + E X _ R 1 3 ( r13 ) ; \
2018-07-26 16:07:08 +03:00
EXCEPTION_ P R O L O G _ 2 ( s o f t _ n m i _ c o m m o n , _ H )
2017-07-13 00:35:52 +03:00
2017-07-29 15:50:27 +03:00
/ *
* Branch t o s o f t _ n m i _ i n t e r r u p t u s i n g t h e e m e r g e n c y s t a c k . T h e e m e r g e n c y
* stack i s o n e t h a t i s u s a b l e b y m a s k a b l e i n t e r r u p t s s o l o n g a s M S R _ E E
* remains o f f . I t i s u s e d f o r r e c o v e r y w h e n s o m e t h i n g h a s c o r r u p t e d t h e
* normal k e r n e l s t a c k , f o r e x a m p l e . T h e " s o f t N M I " m u s t n o t u s e t h e p r o c e s s
* stack b e c a u s e w e w a n t i r q d i s a b l e d s e c t i o n s t o a v o i d t o u c h i n g t h e s t a c k
* at a l l ( o t h e r t h a n P M U i n t e r r u p t s ) , s o u s e t h e e m e r g e n c y s t a c k f o r t h i s ,
* and r u n i t e n t i r e l y w i t h i n t e r r u p t s h a r d d i s a b l e d .
* /
2017-07-13 00:35:52 +03:00
EXC_ C O M M O N _ B E G I N ( s o f t _ n m i _ c o m m o n )
mr r10 ,r1
ld r1 ,P A C A E M E R G S P ( r13 )
subi r1 ,r1 ,I N T _ F R A M E _ S I Z E
EXCEPTION_ C O M M O N _ N O R E T _ S T A C K ( P A C A _ E X G E N , 0 x90 0 ,
system_ r e s e t , s o f t _ n m i _ i n t e r r u p t ,
ADD_ N V G P R S ;ADD_RECONCILE)
b r e t _ f r o m _ e x c e p t
2017-08-01 15:00:52 +03:00
# else / * C O N F I G _ P P C _ W A T C H D O G * /
2017-07-13 00:35:52 +03:00
# define M A S K E D _ D E C _ H A N D L E R _ L A B E L 2 f / * n o r m a l r e t u r n * /
# define M A S K E D _ D E C _ H A N D L E R ( _ H )
2017-08-01 15:00:52 +03:00
# endif / * C O N F I G _ P P C _ W A T C H D O G * /
2016-09-21 10:44:01 +03:00
2009-06-03 01:17:38 +04:00
/ *
2012-11-14 22:49:48 +04:00
* An i n t e r r u p t c a m e i n w h i l e s o f t - d i s a b l e d . W e s e t p a c a - > i r q _ h a p p e n e d , t h e n :
* - If i t w a s a d e c r e m e n t e r i n t e r r u p t , w e b u m p t h e d e c t o m a x a n d a n d r e t u r n .
* - If i t w a s a d o o r b e l l w e r e t u r n i m m e d i a t e l y s i n c e d o o r b e l l s a r e e d g e
* triggered a n d w o n ' t a u t o m a t i c a l l y r e f i r e .
2014-07-29 17:10:01 +04:00
* - If i t w a s a H M I w e r e t u r n i m m e d i a t e l y s i n c e w e h a n d l e d i t i n r e a l m o d e
* and i t w o n ' t r e f i r e .
2018-02-03 10:17:50 +03:00
* - Else i t i s o n e o f P A C A _ I R Q _ M U S T _ H A R D _ M A S K , s o h a r d d i s a b l e a n d r e t u r n .
2012-11-14 22:49:48 +04:00
* This i s c a l l e d w i t h r10 c o n t a i n i n g t h e v a l u e t o O R t o t h e p a c a f i e l d .
2009-06-03 01:17:38 +04:00
* /
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
# define M A S K E D _ I N T E R R U P T ( _ H ) \
masked_ ## _ H # # i n t e r r u p t : \
std r11 ,P A C A _ E X G E N + E X _ R 1 1 ( r13 ) ; \
lbz r11 ,P A C A I R Q H A P P E N E D ( r13 ) ; \
or r11 ,r11 ,r10 ; \
stb r11 ,P A C A I R Q H A P P E N E D ( r13 ) ; \
2012-11-14 22:49:48 +04:00
cmpwi r10 ,P A C A _ I R Q _ D E C ; \
bne 1 f ; \
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
lis r10 ,0 x7 f f f ; \
ori r10 ,r10 ,0 x f f f f ; \
mtspr S P R N _ D E C ,r10 ; \
2017-07-13 00:35:52 +03:00
b M A S K E D _ D E C _ H A N D L E R _ L A B E L ; \
2018-02-03 10:17:50 +03:00
1 : andi. r10 ,r10 ,P A C A _ I R Q _ M U S T _ H A R D _ M A S K ; \
beq 2 f ; \
2012-11-14 22:49:48 +04:00
mfspr r10 ,S P R N _ ## _ H # # S R R 1 ; \
2017-08-11 19:39:00 +03:00
xori r10 ,r10 ,M S R _ E E ; /* clear MSR_EE */ \
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
mtspr S P R N _ ## _ H # # S R R 1 ,r10 ; \
2018-06-03 15:24:32 +03:00
ori r11 ,r11 ,P A C A _ I R Q _ H A R D _ D I S ; \
stb r11 ,P A C A I R Q H A P P E N E D ( r13 ) ; \
2 : /* done */ \
mtcrf 0 x80 ,r9 ; \
2018-05-02 16:07:26 +03:00
std r1 ,P A C A R 1 ( r13 ) ; \
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
ld r9 ,P A C A _ E X G E N + E X _ R 9 ( r13 ) ; \
ld r10 ,P A C A _ E X G E N + E X _ R 1 0 ( r13 ) ; \
ld r11 ,P A C A _ E X G E N + E X _ R 1 1 ( r13 ) ; \
2017-08-11 19:39:01 +03:00
/* returns to kernel where r13 must be set up, so don't restore it */ \
2018-01-09 19:07:15 +03:00
# # _ H## R F I _ T O _ K E R N E L ; \
2017-07-13 00:35:52 +03:00
b . ; \
MASKED_ D E C _ H A N D L E R ( _ H )
2016-09-28 04:31:48 +03:00
2018-05-22 02:00:00 +03:00
TRAMP_ R E A L _ B E G I N ( s t f _ b a r r i e r _ f a l l b a c k )
std r9 ,P A C A _ E X R F I + E X _ R 9 ( r13 )
std r10 ,P A C A _ E X R F I + E X _ R 1 0 ( r13 )
sync
ld r9 ,P A C A _ E X R F I + E X _ R 9 ( r13 )
ld r10 ,P A C A _ E X R F I + E X _ R 1 0 ( r13 )
ori 3 1 ,3 1 ,0
.rept 14
b 1 f
1 :
.endr
blr
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
TRAMP_ R E A L _ B E G I N ( r f i _ f l u s h _ f a l l b a c k )
SET_ S C R A T C H 0 ( r13 ) ;
GET_ P A C A ( r13 ) ;
powerpc/64s: Make rfi_flush_fallback a little more robust
Because rfi_flush_fallback runs immediately before the return to
userspace it currently runs with the user r1 (stack pointer). This
means if we oops in there we will report a bad kernel stack pointer in
the exception entry path, eg:
Bad kernel stack pointer 7ffff7150e40 at c0000000000023b4
Oops: Bad kernel stack pointer, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1246 Comm: klogd Not tainted 4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3 #7
NIP: c0000000000023b4 LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000fffe7d40 TRAP: 4100 Not tainted (4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: c0000000f1e66a80
GPR00: 0000000002000000 00007ffff7150e40 00007fff93a99900 0000000000000020
...
NIP [c0000000000023b4] rfi_flush_fallback+0x34/0x80
LR [0000000010053e00] 0x10053e00
Although the NIP tells us where we were, and the TRAP number tells us
what happened, it would still be nicer if we could report the actual
exception rather than barfing about the stack pointer.
We an do that fairly simply by loading the kernel stack pointer on
entry and restoring the user value before returning. That way we see a
regular oops such as:
Unrecoverable exception 4100 at c00000000000239c
Oops: Unrecoverable exception, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1251 Comm: klogd Not tainted 4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty #40
NIP: c00000000000239c LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000f1e17bb0 TRAP: 4100 Not tainted (4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: 0
...
NIP [c00000000000239c] rfi_flush_fallback+0x3c/0x80
LR [0000000010053e00] 0x10053e00
Call Trace:
[c0000000f1e17e30] [c00000000000b9e4] system_call+0x5c/0x70 (unreliable)
Note this shouldn't make the kernel stack pointer vulnerable to a
meltdown attack, because it should be flushed from the cache before we
return to userspace. The user r1 value will be in the cache, because
we load it in the return path, but that is harmless.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
2018-07-26 15:42:44 +03:00
std r1 ,P A C A _ E X R F I + E X _ R 1 2 ( r13 )
ld r1 ,P A C A K S A V E ( r13 )
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
std r9 ,P A C A _ E X R F I + E X _ R 9 ( r13 )
std r10 ,P A C A _ E X R F I + E X _ R 1 0 ( r13 )
std r11 ,P A C A _ E X R F I + E X _ R 1 1 ( r13 )
mfctr r9
ld r10 ,P A C A _ R F I _ F L U S H _ F A L L B A C K _ A R E A ( r13 )
2018-01-17 16:58:18 +03:00
ld r11 ,P A C A _ L 1 D _ F L U S H _ S I Z E ( r13 )
srdi r11 ,r11 ,( 7 + 3 ) / * 1 2 8 b y t e l i n e s , u n r o l l e d 8 x * /
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
mtctr r11
2018-02-20 22:08:26 +03:00
DCBT_ B O O K 3 S _ S T O P _ A L L _ S T R E A M _ I D S ( r11 ) / * S t o p p r e f e t c h s t r e a m s * /
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
/* order ld/st prior to dcbt stop all streams with flushing */
sync
2018-01-17 16:58:18 +03:00
/ *
* The l o a d a d r e s s e s a r e a t s t a g g e r e d o f f s e t s w i t h i n c a c h e l i n e s ,
* which s u i t s s o m e p i p e l i n e s b e t t e r ( o n o t h e r s i t s h o u l d n o t
* hurt) .
* /
1 :
ld r11 ,( 0 x80 + 8 ) * 0 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 1 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 2 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 3 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 4 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 5 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 6 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 7 ( r10 )
addi r10 ,r10 ,0 x80 * 8
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
bdnz 1 b
mtctr r9
ld r9 ,P A C A _ E X R F I + E X _ R 9 ( r13 )
ld r10 ,P A C A _ E X R F I + E X _ R 1 0 ( r13 )
ld r11 ,P A C A _ E X R F I + E X _ R 1 1 ( r13 )
powerpc/64s: Make rfi_flush_fallback a little more robust
Because rfi_flush_fallback runs immediately before the return to
userspace it currently runs with the user r1 (stack pointer). This
means if we oops in there we will report a bad kernel stack pointer in
the exception entry path, eg:
Bad kernel stack pointer 7ffff7150e40 at c0000000000023b4
Oops: Bad kernel stack pointer, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1246 Comm: klogd Not tainted 4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3 #7
NIP: c0000000000023b4 LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000fffe7d40 TRAP: 4100 Not tainted (4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: c0000000f1e66a80
GPR00: 0000000002000000 00007ffff7150e40 00007fff93a99900 0000000000000020
...
NIP [c0000000000023b4] rfi_flush_fallback+0x34/0x80
LR [0000000010053e00] 0x10053e00
Although the NIP tells us where we were, and the TRAP number tells us
what happened, it would still be nicer if we could report the actual
exception rather than barfing about the stack pointer.
We an do that fairly simply by loading the kernel stack pointer on
entry and restoring the user value before returning. That way we see a
regular oops such as:
Unrecoverable exception 4100 at c00000000000239c
Oops: Unrecoverable exception, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1251 Comm: klogd Not tainted 4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty #40
NIP: c00000000000239c LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000f1e17bb0 TRAP: 4100 Not tainted (4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: 0
...
NIP [c00000000000239c] rfi_flush_fallback+0x3c/0x80
LR [0000000010053e00] 0x10053e00
Call Trace:
[c0000000f1e17e30] [c00000000000b9e4] system_call+0x5c/0x70 (unreliable)
Note this shouldn't make the kernel stack pointer vulnerable to a
meltdown attack, because it should be flushed from the cache before we
return to userspace. The user r1 value will be in the cache, because
we load it in the return path, but that is harmless.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
2018-07-26 15:42:44 +03:00
ld r1 ,P A C A _ E X R F I + E X _ R 1 2 ( r13 )
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
GET_ S C R A T C H 0 ( r13 ) ;
rfid
TRAMP_ R E A L _ B E G I N ( h r f i _ f l u s h _ f a l l b a c k )
SET_ S C R A T C H 0 ( r13 ) ;
GET_ P A C A ( r13 ) ;
powerpc/64s: Make rfi_flush_fallback a little more robust
Because rfi_flush_fallback runs immediately before the return to
userspace it currently runs with the user r1 (stack pointer). This
means if we oops in there we will report a bad kernel stack pointer in
the exception entry path, eg:
Bad kernel stack pointer 7ffff7150e40 at c0000000000023b4
Oops: Bad kernel stack pointer, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1246 Comm: klogd Not tainted 4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3 #7
NIP: c0000000000023b4 LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000fffe7d40 TRAP: 4100 Not tainted (4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: c0000000f1e66a80
GPR00: 0000000002000000 00007ffff7150e40 00007fff93a99900 0000000000000020
...
NIP [c0000000000023b4] rfi_flush_fallback+0x34/0x80
LR [0000000010053e00] 0x10053e00
Although the NIP tells us where we were, and the TRAP number tells us
what happened, it would still be nicer if we could report the actual
exception rather than barfing about the stack pointer.
We an do that fairly simply by loading the kernel stack pointer on
entry and restoring the user value before returning. That way we see a
regular oops such as:
Unrecoverable exception 4100 at c00000000000239c
Oops: Unrecoverable exception, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1251 Comm: klogd Not tainted 4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty #40
NIP: c00000000000239c LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000f1e17bb0 TRAP: 4100 Not tainted (4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: 0
...
NIP [c00000000000239c] rfi_flush_fallback+0x3c/0x80
LR [0000000010053e00] 0x10053e00
Call Trace:
[c0000000f1e17e30] [c00000000000b9e4] system_call+0x5c/0x70 (unreliable)
Note this shouldn't make the kernel stack pointer vulnerable to a
meltdown attack, because it should be flushed from the cache before we
return to userspace. The user r1 value will be in the cache, because
we load it in the return path, but that is harmless.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
2018-07-26 15:42:44 +03:00
std r1 ,P A C A _ E X R F I + E X _ R 1 2 ( r13 )
ld r1 ,P A C A K S A V E ( r13 )
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
std r9 ,P A C A _ E X R F I + E X _ R 9 ( r13 )
std r10 ,P A C A _ E X R F I + E X _ R 1 0 ( r13 )
std r11 ,P A C A _ E X R F I + E X _ R 1 1 ( r13 )
mfctr r9
ld r10 ,P A C A _ R F I _ F L U S H _ F A L L B A C K _ A R E A ( r13 )
2018-01-17 16:58:18 +03:00
ld r11 ,P A C A _ L 1 D _ F L U S H _ S I Z E ( r13 )
srdi r11 ,r11 ,( 7 + 3 ) / * 1 2 8 b y t e l i n e s , u n r o l l e d 8 x * /
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
mtctr r11
2018-02-20 22:08:26 +03:00
DCBT_ B O O K 3 S _ S T O P _ A L L _ S T R E A M _ I D S ( r11 ) / * S t o p p r e f e t c h s t r e a m s * /
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
/* order ld/st prior to dcbt stop all streams with flushing */
sync
2018-01-17 16:58:18 +03:00
/ *
* The l o a d a d r e s s e s a r e a t s t a g g e r e d o f f s e t s w i t h i n c a c h e l i n e s ,
* which s u i t s s o m e p i p e l i n e s b e t t e r ( o n o t h e r s i t s h o u l d n o t
* hurt) .
* /
1 :
ld r11 ,( 0 x80 + 8 ) * 0 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 1 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 2 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 3 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 4 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 5 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 6 ( r10 )
ld r11 ,( 0 x80 + 8 ) * 7 ( r10 )
addi r10 ,r10 ,0 x80 * 8
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
bdnz 1 b
mtctr r9
ld r9 ,P A C A _ E X R F I + E X _ R 9 ( r13 )
ld r10 ,P A C A _ E X R F I + E X _ R 1 0 ( r13 )
ld r11 ,P A C A _ E X R F I + E X _ R 1 1 ( r13 )
powerpc/64s: Make rfi_flush_fallback a little more robust
Because rfi_flush_fallback runs immediately before the return to
userspace it currently runs with the user r1 (stack pointer). This
means if we oops in there we will report a bad kernel stack pointer in
the exception entry path, eg:
Bad kernel stack pointer 7ffff7150e40 at c0000000000023b4
Oops: Bad kernel stack pointer, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1246 Comm: klogd Not tainted 4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3 #7
NIP: c0000000000023b4 LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000fffe7d40 TRAP: 4100 Not tainted (4.18.0-rc2-gcc-7.3.1-00175-g0443f8a69ba3)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: c0000000f1e66a80
GPR00: 0000000002000000 00007ffff7150e40 00007fff93a99900 0000000000000020
...
NIP [c0000000000023b4] rfi_flush_fallback+0x34/0x80
LR [0000000010053e00] 0x10053e00
Although the NIP tells us where we were, and the TRAP number tells us
what happened, it would still be nicer if we could report the actual
exception rather than barfing about the stack pointer.
We an do that fairly simply by loading the kernel stack pointer on
entry and restoring the user value before returning. That way we see a
regular oops such as:
Unrecoverable exception 4100 at c00000000000239c
Oops: Unrecoverable exception, sig: 6 [#1]
LE SMP NR_CPUS=32 NUMA PowerNV
Modules linked in:
CPU: 0 PID: 1251 Comm: klogd Not tainted 4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty #40
NIP: c00000000000239c LR: 0000000010053e00 CTR: 0000000000000040
REGS: c0000000f1e17bb0 TRAP: 4100 Not tainted (4.18.0-rc3-gcc-7.3.1-00097-g4ebfcac65acd-dirty)
MSR: 9000000002803031 <SF,HV,VEC,VSX,FP,ME,IR,DR,LE> CR: 44000442 XER: 20000000
CFAR: c00000000000bac8 IRQMASK: 0
...
NIP [c00000000000239c] rfi_flush_fallback+0x3c/0x80
LR [0000000010053e00] 0x10053e00
Call Trace:
[c0000000f1e17e30] [c00000000000b9e4] system_call+0x5c/0x70 (unreliable)
Note this shouldn't make the kernel stack pointer vulnerable to a
meltdown attack, because it should be flushed from the cache before we
return to userspace. The user r1 value will be in the cache, because
we load it in the return path, but that is harmless.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
2018-07-26 15:42:44 +03:00
ld r1 ,P A C A _ E X R F I + E X _ R 1 2 ( r13 )
powerpc/64s: Add support for RFI flush of L1-D cache
On some CPUs we can prevent the Meltdown vulnerability by flushing the
L1-D cache on exit from kernel to user mode, and from hypervisor to
guest.
This is known to be the case on at least Power7, Power8 and Power9. At
this time we do not know the status of the vulnerability on other CPUs
such as the 970 (Apple G5), pasemi CPUs (AmigaOne X1000) or Freescale
CPUs. As more information comes to light we can enable this, or other
mechanisms on those CPUs.
The vulnerability occurs when the load of an architecturally
inaccessible memory region (eg. userspace load of kernel memory) is
speculatively executed to the point where its result can influence the
address of a subsequent speculatively executed load.
In order for that to happen, the first load must hit in the L1,
because before the load is sent to the L2 the permission check is
performed. Therefore if no kernel addresses hit in the L1 the
vulnerability can not occur. We can ensure that is the case by
flushing the L1 whenever we return to userspace. Similarly for
hypervisor vs guest.
In order to flush the L1-D cache on exit, we add a section of nops at
each (h)rfi location that returns to a lower privileged context, and
patch that with some sequence. Newer firmwares are able to advertise
to us that there is a special nop instruction that flushes the L1-D.
If we do not see that advertised, we fall back to doing a displacement
flush in software.
For guest kernels we support migration between some CPU versions, and
different CPUs may use different flush instructions. So that we are
prepared to migrate to a machine with a different flush instruction
activated, we may have to patch more than one flush instruction at
boot if the hypervisor tells us to.
In the end this patch is mostly the work of Nicholas Piggin and
Michael Ellerman. However a cast of thousands contributed to analysis
of the issue, earlier versions of the patch, back ports testing etc.
Many thanks to all of them.
Tested-by: Jon Masters <jcm@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-01-09 19:07:15 +03:00
GET_ S C R A T C H 0 ( r13 ) ;
hrfid
2016-09-28 04:31:48 +03:00
/ *
* Real m o d e e x c e p t i o n s a c t u a l l y u s e t h i s t o o , b u t a l t e r n a t e
* instruction c o d e p a t c h e s ( w h i c h e n d u p i n t h e c o m m o n . t e x t a r e a )
* cannot r e a c h t h e s e i f t h e y a r e p u t t h e r e .
* /
USE_ F I X E D _ S E C T I O N ( v i r t _ t r a m p o l i n e s )
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
MASKED_ I N T E R R U P T ( )
MASKED_ I N T E R R U P T ( H )
2009-06-03 01:17:38 +04:00
2013-09-20 08:52:50 +04:00
# ifdef C O N F I G _ K V M _ B O O K 3 S _ 6 4 _ H A N D L E R
2016-09-30 12:43:18 +03:00
TRAMP_ R E A L _ B E G I N ( k v m p p c _ s k i p _ i n t e r r u p t )
2013-09-20 08:52:50 +04:00
/ *
* Here a l l G P R s a r e u n c h a n g e d f r o m w h e n t h e i n t e r r u p t h a p p e n e d
* except f o r r13 , w h i c h i s s a v e d i n S P R G _ S C R A T C H 0 .
* /
mfspr r13 , S P R N _ S R R 0
addi r13 , r13 , 4
mtspr S P R N _ S R R 0 , r13
GET_ S C R A T C H 0 ( r13 )
2018-01-09 19:07:15 +03:00
RFI_ T O _ K E R N E L
2013-09-20 08:52:50 +04:00
b .
2016-09-30 12:43:18 +03:00
TRAMP_ R E A L _ B E G I N ( k v m p p c _ s k i p _ H i n t e r r u p t )
2013-09-20 08:52:50 +04:00
/ *
* Here a l l G P R s a r e u n c h a n g e d f r o m w h e n t h e i n t e r r u p t h a p p e n e d
* except f o r r13 , w h i c h i s s a v e d i n S P R G _ S C R A T C H 0 .
* /
mfspr r13 , S P R N _ H S R R 0
addi r13 , r13 , 4
mtspr S P R N _ H S R R 0 , r13
GET_ S C R A T C H 0 ( r13 )
2018-01-09 19:07:15 +03:00
HRFI_ T O _ K E R N E L
2013-09-20 08:52:50 +04:00
b .
# endif
2009-06-03 01:17:38 +04:00
/ *
2016-04-08 01:00:34 +03:00
* Ensure t h a t a n y h a n d l e r s t h a t g e t i n v o k e d f r o m t h e e x c e p t i o n p r o l o g s
* above a r e b e l o w t h e f i r s t 6 4 K B ( 0 x10 0 0 0 ) o f t h e k e r n e l i m a g e b e c a u s e
* the p r o l o g s a s s e m b l e t h e a d d r e s s e s o f t h e s e h a n d l e r s u s i n g t h e
* LOAD_ H A N D L E R m a c r o , w h i c h u s e s a n o r i i n s t r u c t i o n .
2009-06-03 01:17:38 +04:00
* /
/*** Common interrupt handlers ***/
2012-11-02 10:21:43 +04:00
/ *
* Relocation- o n i n t e r r u p t s : A s u b s e t o f t h e i n t e r r u p t s c a n b e d e l i v e r e d
* with I R =1 / D R =1 , i f A I L = =2 a n d M S R . H V w o n ' t b e c h a n g e d b y d e l i v e r i n g
* it. A d d r e s s e s a r e t h e s a m e a s t h e o r i g i n a l i n t e r r u p t a d d r e s s e s , b u t
* offset b y 0 x c00 0 0 0 0 0 0 0 0 0 4 0 0 0 .
* It' s i m p o s s i b l e t o r e c e i v e i n t e r r u p t s b e l o w 0 x30 0 v i a t h i s m e c h a n i s m .
* KVM : None o f t h e s e t r a p s a r e f r o m t h e g u e s t ; anything that escalated
* to H V =1 f r o m H V =0 i s d e l i v e r e d v i a r e a l m o d e h a n d l e r s .
* /
/ *
* This u s e s t h e s t a n d a r d m a c r o , s i n c e t h e o r i g i n a l 0 x30 0 v e c t o r
* only h a s e x t r a g u f f f o r S T A B - b a s e d p r o c e s s o r s - - w h i c h n e v e r
* come h e r e .
* /
2016-09-30 12:43:18 +03:00
2016-09-28 04:31:48 +03:00
EXC_ C O M M O N _ B E G I N ( p p c64 _ r u n l a t c h _ o n _ t r a m p o l i n e )
2014-02-04 09:04:35 +04:00
b _ _ p p c64 _ r u n l a t c h _ o n
2012-03-01 05:45:27 +04:00
2016-09-28 04:31:48 +03:00
USE_ F I X E D _ S E C T I O N ( v i r t _ t r a m p o l i n e s )
powerpc/book3s64: Fix branching to OOL handlers in relocatable kernel
Some of the interrupt vectors on 64-bit POWER server processors are only
32 bytes long (8 instructions), which is not enough for the full
first-level interrupt handler. For these we need to branch to an
out-of-line (OOL) handler. But when we are running a relocatable kernel,
interrupt vectors till __end_interrupts marker are copied down to real
address 0x100. So, branching to labels (ie. OOL handlers) outside this
section must be handled differently (see LOAD_HANDLER()), considering
relocatable kernel, which would need at least 4 instructions.
However, branching from interrupt vector means that we corrupt the
CFAR (come-from address register) on POWER7 and later processors as
mentioned in commit 1707dd16. So, EXCEPTION_PROLOG_0 (6 instructions)
that contains the part up to the point where the CFAR is saved in the
PACA should be part of the short interrupt vectors before we branch out
to OOL handlers.
But as mentioned already, there are interrupt vectors on 64-bit POWER
server processors that are only 32 bytes long (like vectors 0x4f00,
0x4f20, etc.), which cannot accomodate the above two cases at the same
time owing to space constraint. Currently, in these interrupt vectors,
we simply branch out to OOL handlers, without using LOAD_HANDLER(),
which leaves us vulnerable when running a relocatable kernel (eg. kdump
case). While this has been the case for sometime now and kdump is used
widely, we were fortunate not to see any problems so far, for three
reasons:
1. In almost all cases, production kernel (relocatable) is used for
kdump as well, which would mean that crashed kernel's OOL handler
would be at the same place where we end up branching to, from short
interrupt vector of kdump kernel.
2. Also, OOL handler was unlikely the reason for crash in almost all
the kdump scenarios, which meant we had a sane OOL handler from
crashed kernel that we branched to.
3. On most 64-bit POWER server processors, page size is large enough
that marking interrupt vector code as executable (see commit
429d2e83) leads to marking OOL handler code from crashed kernel,
that sits right below interrupt vector code from kdump kernel, as
executable as well.
Let us fix this by moving the __end_interrupts marker down past OOL
handlers to make sure that we also copy OOL handlers to real address
0x100 when running a relocatable kernel.
This fix has been tested successfully in kdump scenario, on an LPAR with
4K page size by using different default/production kernel and kdump
kernel.
Also tested by manually corrupting the OOL handlers in the first kernel
and then kdump'ing, and then causing the OOL handlers to fire - mpe.
Fixes: c1fb6816fb1b ("powerpc: Add relocation on exception vector handlers")
Cc: stable@vger.kernel.org
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2016-04-15 15:48:02 +03:00
/ *
* The _ _ e n d _ i n t e r r u p t s m a r k e r m u s t b e p a s t t h e o u t - o f - l i n e ( O O L )
* handlers, s o t h a t t h e y a r e c o p i e d t o r e a l a d d r e s s 0 x10 0 w h e n r u n n i n g
* a r e l o c a t a b l e k e r n e l . T h i s e n s u r e s t h e y c a n b e r e a c h e d f r o m t h e s h o r t
* trampoline h a n d l e r s ( l i k e 0 x4 f00 , 0 x4 f20 , e t c . ) w h i c h b r a n c h
* directly, w i t h o u t u s i n g L O A D _ H A N D L E R ( ) .
* /
.align 7
.globl __end_interrupts
__end_interrupts :
2016-09-28 04:31:48 +03:00
DEFINE_ F I X E D _ S Y M B O L ( _ _ e n d _ i n t e r r u p t s )
2013-01-10 10:44:19 +04:00
2013-03-25 05:31:31 +04:00
# ifdef C O N F I G _ P P C _ 9 7 0 _ N A P
2016-10-11 10:47:56 +03:00
EXC_ C O M M O N _ B E G I N ( p o w e r4 _ f i x u p _ n a p )
2013-03-25 05:31:31 +04:00
andc r9 ,r9 ,r10
std r9 ,T I _ L O C A L _ F L A G S ( r11 )
ld r10 ,_ L I N K ( r1 ) / * m a k e i d l e t a s k d o t h e * /
std r10 ,_ N I P ( r1 ) / * e q u i v a l e n t o f a b l r * /
blr
# endif
2016-09-28 04:31:48 +03:00
CLOSE_ F I X E D _ S E C T I O N ( r e a l _ v e c t o r s ) ;
CLOSE_ F I X E D _ S E C T I O N ( r e a l _ t r a m p o l i n e s ) ;
CLOSE_ F I X E D _ S E C T I O N ( v i r t _ v e c t o r s ) ;
CLOSE_ F I X E D _ S E C T I O N ( v i r t _ t r a m p o l i n e s ) ;
USE_ T E X T _ S E C T I O N ( )
2009-06-03 01:17:38 +04:00
/ *
* Hash t a b l e s t u f f
* /
2016-10-13 06:43:52 +03:00
.balign IFETCH_ALIGN_BYTES
2014-02-04 09:06:11 +04:00
do_hash_page :
2017-10-19 07:08:43 +03:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 6 4
2018-01-19 04:50:40 +03:00
lis r0 ,( D S I S R _ B A D _ F A U L T _ 6 4 S | D S I S R _ D A B R M A T C H | D S I S R _ K E Y F A U L T ) @h
2017-07-19 07:49:27 +03:00
ori r0 ,r0 ,D S I S R _ B A D _ F A U L T _ 6 4 S @l
and. r0 ,r4 ,r0 / * w e i r d e r r o r ? * /
2009-06-03 01:17:38 +04:00
bne- h a n d l e _ p a g e _ f a u l t / * i f n o t , t r y t o i n s e r t a H P T E * /
2019-01-12 12:55:50 +03:00
ld r11 , P A C A _ T H R E A D _ I N F O ( r13 )
powerpc: Allow perf_counters to access user memory at interrupt time
This provides a mechanism to allow the perf_counters code to access
user memory in a PMU interrupt routine. Such an access can cause
various kinds of interrupt: SLB miss, MMU hash table miss, segment
table miss, or TLB miss, depending on the processor. This commit
only deals with 64-bit classic/server processors, which use an MMU
hash table. 32-bit processors are already able to access user memory
at interrupt time. Since we don't soft-disable on 32-bit, we avoid
the possibility of reentering hash_page or the TLB miss handlers,
since they run with interrupts disabled.
On 64-bit processors, an SLB miss interrupt on a user address will
update the slb_cache and slb_cache_ptr fields in the paca. This is
OK except in the case where a PMU interrupt occurs in switch_slb,
which also accesses those fields. To prevent this, we hard-disable
interrupts in switch_slb. Interrupts are already soft-disabled at
this point, and will get hard-enabled when they get soft-enabled
later.
This also reworks slb_flush_and_rebolt: to avoid hard-disabling twice,
and to make sure that it clears the slb_cache_ptr when called from
other callers than switch_slb, the existing routine is renamed to
__slb_flush_and_rebolt, which is called by switch_slb and the new
version of slb_flush_and_rebolt.
Similarly, switch_stab (used on POWER3 and RS64 processors) gets a
hard_irq_disable() to protect the per-cpu variables used there and
in ste_allocate.
If a MMU hashtable miss interrupt occurs, normally we would call
hash_page to look up the Linux PTE for the address and create a HPTE.
However, hash_page is fairly complex and takes some locks, so to
avoid the possibility of deadlock, we check the preemption count
to see if we are in a (pseudo-)NMI handler, and if so, we don't call
hash_page but instead treat it like a bad access that will get
reported up through the exception table mechanism. An interrupt
whose handler runs even though the interrupt occurred when
soft-disabled (such as the PMU interrupt) is considered a pseudo-NMI
handler, which should use nmi_enter()/nmi_exit() rather than
irq_enter()/irq_exit().
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2009-08-17 09:17:54 +04:00
lwz r0 ,T I _ P R E E M P T ( r11 ) / * I f w e ' r e i n a n " N M I " * /
andis. r0 ,r0 ,N M I _ M A S K @h /* (i.e. an irq when soft-disabled) */
bne 7 7 f / * t h e n d o n ' t c a l l h a s h _ p a g e n o w * /
2009-06-03 01:17:38 +04:00
/ *
* r3 c o n t a i n s t h e f a u l t i n g a d d r e s s
2015-12-01 06:36:44 +03:00
* r4 m s r
2009-06-03 01:17:38 +04:00
* r5 c o n t a i n s t h e t r a p n u m b e r
2014-12-04 08:30:14 +03:00
* r6 c o n t a i n s d s i s r
2009-06-03 01:17:38 +04:00
*
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
* at r e t u r n r3 = 0 f o r s u c c e s s , 1 f o r p a g e f a u l t , n e g a t i v e f o r e r r o r
2009-06-03 01:17:38 +04:00
* /
2015-12-01 06:36:44 +03:00
mr r4 ,r12
2014-12-04 08:30:14 +03:00
ld r6 ,_ D S I S R ( r1 )
2015-12-01 06:36:44 +03:00
bl _ _ h a s h _ p a g e / * b u i l d H P T E i f p o s s i b l e * /
cmpdi r3 ,0 / * s e e i f _ _ h a s h _ p a g e s u c c e e d e d * /
2009-06-03 01:17:38 +04:00
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
/* Success */
2009-06-03 01:17:38 +04:00
beq f a s t _ e x c _ r e t u r n _ i r q / * R e t u r n f r o m e x c e p t i o n o n s u c c e s s * /
powerpc: Rework lazy-interrupt handling
The current implementation of lazy interrupts handling has some
issues that this tries to address.
We don't do the various workarounds we need to do when re-enabling
interrupts in some cases such as when returning from an interrupt
and thus we may still lose or get delayed decrementer or doorbell
interrupts.
The current scheme also makes it much harder to handle the external
"edge" interrupts provided by some BookE processors when using the
EPR facility (External Proxy) and the Freescale Hypervisor.
Additionally, we tend to keep interrupts hard disabled in a number
of cases, such as decrementer interrupts, external interrupts, or
when a masked decrementer interrupt is pending. This is sub-optimal.
This is an attempt at fixing it all in one go by reworking the way
we do the lazy interrupt disabling from the ground up.
The base idea is to replace the "hard_enabled" field with a
"irq_happened" field in which we store a bit mask of what interrupt
occurred while soft-disabled.
When re-enabling, either via arch_local_irq_restore() or when returning
from an interrupt, we can now decide what to do by testing bits in that
field.
We then implement replaying of the missed interrupts either by
re-using the existing exception frame (in exception exit case) or via
the creation of a new one from an assembly trampoline (in the
arch_local_irq_enable case).
This removes the need to play with the decrementer to try to create
fake interrupts, among others.
In addition, this adds a few refinements:
- We no longer hard disable decrementer interrupts that occur
while soft-disabled. We now simply bump the decrementer back to max
(on BookS) or leave it stopped (on BookE) and continue with hard interrupts
enabled, which means that we'll potentially get better sample quality from
performance monitor interrupts.
- Timer, decrementer and doorbell interrupts now hard-enable
shortly after removing the source of the interrupt, which means
they no longer run entirely hard disabled. Again, this will improve
perf sample quality.
- On Book3E 64-bit, we now make the performance monitor interrupt
act as an NMI like Book3S (the necessary C code for that to work
appear to already be present in the FSL perf code, notably calling
nmi_enter instead of irq_enter). (This also fixes a bug where BookE
perfmon interrupts could clobber r14 ... oops)
- We could make "masked" decrementer interrupts act as NMIs when doing
timer-based perf sampling to improve the sample quality.
Signed-off-by-yet: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
v2:
- Add hard-enable to decrementer, timer and doorbells
- Fix CR clobber in masked irq handling on BookE
- Make embedded perf interrupt act as an NMI
- Add a PACA_HAPPENED_EE_EDGE for use by FSL if they want
to retrigger an interrupt without preventing hard-enable
v3:
- Fix or vs. ori bug on Book3E
- Fix enabling of interrupts for some exceptions on Book3E
v4:
- Fix resend of doorbells on return from interrupt on Book3E
v5:
- Rebased on top of my latest series, which involves some significant
rework of some aspects of the patch.
v6:
- 32-bit compile fix
- more compile fixes with various .config combos
- factor out the asm code to soft-disable interrupts
- remove the C wrapper around preempt_schedule_irq
v7:
- Fix a bug with hard irq state tracking on native power7
2012-03-06 11:27:59 +04:00
/* Error */
blt- 1 3 f
2017-06-13 21:42:00 +03:00
/* Reload DSISR into r4 for the DABR check below */
ld r4 ,_ D S I S R ( r1 )
2017-10-19 07:08:43 +03:00
# endif / * C O N F I G _ P P C _ B O O K 3 S _ 6 4 * /
2010-03-30 03:59:25 +04:00
2009-06-03 01:17:38 +04:00
/* Here we have a page fault that hash_page can't handle. */
handle_page_fault :
2017-06-13 21:42:00 +03:00
11 : andis. r0 ,r4 ,D S I S R _ D A B R M A T C H @h
bne- h a n d l e _ d a b r _ f a u l t
ld r4 ,_ D A R ( r1 )
2009-06-03 01:17:38 +04:00
ld r5 ,_ D S I S R ( r1 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2014-02-04 09:04:35 +04:00
bl d o _ p a g e _ f a u l t
2009-06-03 01:17:38 +04:00
cmpdi r3 ,0
powerpc/watchpoint: Restore NV GPRs while returning from exception
powerpc hardware triggers watchpoint before executing the instruction.
To make trigger-after-execute behavior, kernel emulates the
instruction. If the instruction is 'load something into non-volatile
register', exception handler should restore emulated register state
while returning back, otherwise there will be register state
corruption. eg, adding a watchpoint on a list can corrput the list:
# cat /proc/kallsyms | grep kthread_create_list
c00000000121c8b8 d kthread_create_list
Add watchpoint on kthread_create_list->prev:
# perf record -e mem:0xc00000000121c8c0
Run some workload such that new kthread gets invoked. eg, I just
logged out from console:
list_add corruption. next->prev should be prev (c000000001214e00), \
but was c00000000121c8b8. (next=c00000000121c8b8).
WARNING: CPU: 59 PID: 309 at lib/list_debug.c:25 __list_add_valid+0xb4/0xc0
CPU: 59 PID: 309 Comm: kworker/59:0 Kdump: loaded Not tainted 5.1.0-rc7+ #69
...
NIP __list_add_valid+0xb4/0xc0
LR __list_add_valid+0xb0/0xc0
Call Trace:
__list_add_valid+0xb0/0xc0 (unreliable)
__kthread_create_on_node+0xe0/0x260
kthread_create_on_node+0x34/0x50
create_worker+0xe8/0x260
worker_thread+0x444/0x560
kthread+0x160/0x1a0
ret_from_kernel_thread+0x5c/0x70
List corruption happened because it uses 'load into non-volatile
register' instruction:
Snippet from __kthread_create_on_node:
c000000000136be8: addis r29,r2,-19
c000000000136bec: ld r29,31424(r29)
if (!__list_add_valid(new, prev, next))
c000000000136bf0: mr r3,r30
c000000000136bf4: mr r5,r28
c000000000136bf8: mr r4,r29
c000000000136bfc: bl c00000000059a2f8 <__list_add_valid+0x8>
Register state from WARN_ON():
GPR00: c00000000059a3a0 c000007ff23afb50 c000000001344e00 0000000000000075
GPR04: 0000000000000000 0000000000000000 0000001852af8bc1 0000000000000000
GPR08: 0000000000000001 0000000000000007 0000000000000006 00000000000004aa
GPR12: 0000000000000000 c000007ffffeb080 c000000000137038 c000005ff62aaa00
GPR16: 0000000000000000 0000000000000000 c000007fffbe7600 c000007fffbe7370
GPR20: c000007fffbe7320 c000007fffbe7300 c000000001373a00 0000000000000000
GPR24: fffffffffffffef7 c00000000012e320 c000007ff23afcb0 c000000000cb8628
GPR28: c00000000121c8b8 c000000001214e00 c000007fef5b17e8 c000007fef5b17c0
Watchpoint hit at 0xc000000000136bec.
addis r29,r2,-19
=> r29 = 0xc000000001344e00 + (-19 << 16)
=> r29 = 0xc000000001214e00
ld r29,31424(r29)
=> r29 = *(0xc000000001214e00 + 31424)
=> r29 = *(0xc00000000121c8c0)
0xc00000000121c8c0 is where we placed a watchpoint and thus this
instruction was emulated by emulate_step. But because handle_dabr_fault
did not restore emulated register state, r29 still contains stale
value in above register state.
Fixes: 5aae8a5370802 ("powerpc, hw_breakpoints: Implement hw_breakpoints for 64-bit server processors")
Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: stable@vger.kernel.org # 2.6.36+
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-06-13 06:30:14 +03:00
beq+ r e t _ f r o m _ e x c e p t _ l i t e
2014-02-04 09:04:35 +04:00
bl s a v e _ n v g p r s
2009-06-03 01:17:38 +04:00
mr r5 ,r3
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
lwz r4 ,_ D A R ( r1 )
2014-02-04 09:04:35 +04:00
bl b a d _ p a g e _ f a u l t
b r e t _ f r o m _ e x c e p t
2009-06-03 01:17:38 +04:00
2012-03-07 09:48:45 +04:00
/* We have a data breakpoint exception - handle it */
handle_dabr_fault :
2014-02-04 09:04:35 +04:00
bl s a v e _ n v g p r s
2012-03-07 09:48:45 +04:00
ld r4 ,_ D A R ( r1 )
ld r5 ,_ D S I S R ( r1 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2014-02-04 09:04:35 +04:00
bl d o _ b r e a k
powerpc/watchpoint: Restore NV GPRs while returning from exception
powerpc hardware triggers watchpoint before executing the instruction.
To make trigger-after-execute behavior, kernel emulates the
instruction. If the instruction is 'load something into non-volatile
register', exception handler should restore emulated register state
while returning back, otherwise there will be register state
corruption. eg, adding a watchpoint on a list can corrput the list:
# cat /proc/kallsyms | grep kthread_create_list
c00000000121c8b8 d kthread_create_list
Add watchpoint on kthread_create_list->prev:
# perf record -e mem:0xc00000000121c8c0
Run some workload such that new kthread gets invoked. eg, I just
logged out from console:
list_add corruption. next->prev should be prev (c000000001214e00), \
but was c00000000121c8b8. (next=c00000000121c8b8).
WARNING: CPU: 59 PID: 309 at lib/list_debug.c:25 __list_add_valid+0xb4/0xc0
CPU: 59 PID: 309 Comm: kworker/59:0 Kdump: loaded Not tainted 5.1.0-rc7+ #69
...
NIP __list_add_valid+0xb4/0xc0
LR __list_add_valid+0xb0/0xc0
Call Trace:
__list_add_valid+0xb0/0xc0 (unreliable)
__kthread_create_on_node+0xe0/0x260
kthread_create_on_node+0x34/0x50
create_worker+0xe8/0x260
worker_thread+0x444/0x560
kthread+0x160/0x1a0
ret_from_kernel_thread+0x5c/0x70
List corruption happened because it uses 'load into non-volatile
register' instruction:
Snippet from __kthread_create_on_node:
c000000000136be8: addis r29,r2,-19
c000000000136bec: ld r29,31424(r29)
if (!__list_add_valid(new, prev, next))
c000000000136bf0: mr r3,r30
c000000000136bf4: mr r5,r28
c000000000136bf8: mr r4,r29
c000000000136bfc: bl c00000000059a2f8 <__list_add_valid+0x8>
Register state from WARN_ON():
GPR00: c00000000059a3a0 c000007ff23afb50 c000000001344e00 0000000000000075
GPR04: 0000000000000000 0000000000000000 0000001852af8bc1 0000000000000000
GPR08: 0000000000000001 0000000000000007 0000000000000006 00000000000004aa
GPR12: 0000000000000000 c000007ffffeb080 c000000000137038 c000005ff62aaa00
GPR16: 0000000000000000 0000000000000000 c000007fffbe7600 c000007fffbe7370
GPR20: c000007fffbe7320 c000007fffbe7300 c000000001373a00 0000000000000000
GPR24: fffffffffffffef7 c00000000012e320 c000007ff23afcb0 c000000000cb8628
GPR28: c00000000121c8b8 c000000001214e00 c000007fef5b17e8 c000007fef5b17c0
Watchpoint hit at 0xc000000000136bec.
addis r29,r2,-19
=> r29 = 0xc000000001344e00 + (-19 << 16)
=> r29 = 0xc000000001214e00
ld r29,31424(r29)
=> r29 = *(0xc000000001214e00 + 31424)
=> r29 = *(0xc00000000121c8c0)
0xc00000000121c8c0 is where we placed a watchpoint and thus this
instruction was emulated by emulate_step. But because handle_dabr_fault
did not restore emulated register state, r29 still contains stale
value in above register state.
Fixes: 5aae8a5370802 ("powerpc, hw_breakpoints: Implement hw_breakpoints for 64-bit server processors")
Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: stable@vger.kernel.org # 2.6.36+
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-06-13 06:30:14 +03:00
/ *
* do_ b r e a k ( ) m a y h a v e c h a n g e d t h e N V G P R S w h i l e h a n d l i n g a b r e a k p o i n t .
* If s o , w e n e e d t o r e s t o r e t h e m w i t h t h e i r u p d a t e d v a l u e s . D o n ' t u s e
* ret_ f r o m _ e x c e p t _ l i t e h e r e .
* /
b r e t _ f r o m _ e x c e p t
2012-03-07 09:48:45 +04:00
2009-06-03 01:17:38 +04:00
2017-10-19 07:08:43 +03:00
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 6 4
2009-06-03 01:17:38 +04:00
/ * We h a v e a p a g e f a u l t t h a t h a s h _ p a g e c o u l d h a n d l e b u t H V r e f u s e d
* the P T E i n s e r t i o n
* /
2014-02-04 09:04:35 +04:00
13 : bl s a v e _ n v g p r s
2009-06-03 01:17:38 +04:00
mr r5 ,r3
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
ld r4 ,_ D A R ( r1 )
2014-02-04 09:04:35 +04:00
bl l o w _ h a s h _ f a u l t
b r e t _ f r o m _ e x c e p t
2016-04-29 16:26:07 +03:00
# endif
2009-06-03 01:17:38 +04:00
powerpc: Allow perf_counters to access user memory at interrupt time
This provides a mechanism to allow the perf_counters code to access
user memory in a PMU interrupt routine. Such an access can cause
various kinds of interrupt: SLB miss, MMU hash table miss, segment
table miss, or TLB miss, depending on the processor. This commit
only deals with 64-bit classic/server processors, which use an MMU
hash table. 32-bit processors are already able to access user memory
at interrupt time. Since we don't soft-disable on 32-bit, we avoid
the possibility of reentering hash_page or the TLB miss handlers,
since they run with interrupts disabled.
On 64-bit processors, an SLB miss interrupt on a user address will
update the slb_cache and slb_cache_ptr fields in the paca. This is
OK except in the case where a PMU interrupt occurs in switch_slb,
which also accesses those fields. To prevent this, we hard-disable
interrupts in switch_slb. Interrupts are already soft-disabled at
this point, and will get hard-enabled when they get soft-enabled
later.
This also reworks slb_flush_and_rebolt: to avoid hard-disabling twice,
and to make sure that it clears the slb_cache_ptr when called from
other callers than switch_slb, the existing routine is renamed to
__slb_flush_and_rebolt, which is called by switch_slb and the new
version of slb_flush_and_rebolt.
Similarly, switch_stab (used on POWER3 and RS64 processors) gets a
hard_irq_disable() to protect the per-cpu variables used there and
in ste_allocate.
If a MMU hashtable miss interrupt occurs, normally we would call
hash_page to look up the Linux PTE for the address and create a HPTE.
However, hash_page is fairly complex and takes some locks, so to
avoid the possibility of deadlock, we check the preemption count
to see if we are in a (pseudo-)NMI handler, and if so, we don't call
hash_page but instead treat it like a bad access that will get
reported up through the exception table mechanism. An interrupt
whose handler runs even though the interrupt occurred when
soft-disabled (such as the PMU interrupt) is considered a pseudo-NMI
handler, which should use nmi_enter()/nmi_exit() rather than
irq_enter()/irq_exit().
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2009-08-17 09:17:54 +04:00
/ *
* We c o m e h e r e a s a r e s u l t o f a D S I a t a p o i n t w h e r e w e d o n ' t w a n t
* to c a l l h a s h _ p a g e , s u c h a s w h e n w e a r e a c c e s s i n g m e m o r y ( p o s s i b l y
* user m e m o r y ) i n s i d e a P M U i n t e r r u p t t h a t o c c u r r e d w h i l e i n t e r r u p t s
* were s o f t - d i s a b l e d . W e w a n t t o i n v o k e t h e e x c e p t i o n h a n d l e r f o r
* the a c c e s s , o r p a n i c i f t h e r e i s n ' t a h a n d l e r .
* /
2014-02-04 09:04:35 +04:00
77 : bl s a v e _ n v g p r s
powerpc: Allow perf_counters to access user memory at interrupt time
This provides a mechanism to allow the perf_counters code to access
user memory in a PMU interrupt routine. Such an access can cause
various kinds of interrupt: SLB miss, MMU hash table miss, segment
table miss, or TLB miss, depending on the processor. This commit
only deals with 64-bit classic/server processors, which use an MMU
hash table. 32-bit processors are already able to access user memory
at interrupt time. Since we don't soft-disable on 32-bit, we avoid
the possibility of reentering hash_page or the TLB miss handlers,
since they run with interrupts disabled.
On 64-bit processors, an SLB miss interrupt on a user address will
update the slb_cache and slb_cache_ptr fields in the paca. This is
OK except in the case where a PMU interrupt occurs in switch_slb,
which also accesses those fields. To prevent this, we hard-disable
interrupts in switch_slb. Interrupts are already soft-disabled at
this point, and will get hard-enabled when they get soft-enabled
later.
This also reworks slb_flush_and_rebolt: to avoid hard-disabling twice,
and to make sure that it clears the slb_cache_ptr when called from
other callers than switch_slb, the existing routine is renamed to
__slb_flush_and_rebolt, which is called by switch_slb and the new
version of slb_flush_and_rebolt.
Similarly, switch_stab (used on POWER3 and RS64 processors) gets a
hard_irq_disable() to protect the per-cpu variables used there and
in ste_allocate.
If a MMU hashtable miss interrupt occurs, normally we would call
hash_page to look up the Linux PTE for the address and create a HPTE.
However, hash_page is fairly complex and takes some locks, so to
avoid the possibility of deadlock, we check the preemption count
to see if we are in a (pseudo-)NMI handler, and if so, we don't call
hash_page but instead treat it like a bad access that will get
reported up through the exception table mechanism. An interrupt
whose handler runs even though the interrupt occurred when
soft-disabled (such as the PMU interrupt) is considered a pseudo-NMI
handler, which should use nmi_enter()/nmi_exit() rather than
irq_enter()/irq_exit().
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2009-08-17 09:17:54 +04:00
mr r4 ,r3
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
li r5 ,S I G S E G V
2014-02-04 09:04:35 +04:00
bl b a d _ p a g e _ f a u l t
b r e t _ f r o m _ e x c e p t
2014-07-15 14:25:02 +04:00
/ *
* Here w e h a v e d e t e c t e d t h a t t h e k e r n e l s t a c k p o i n t e r i s b a d .
* R9 c o n t a i n s t h e s a v e d C R , r13 p o i n t s t o t h e p a c a ,
* r1 0 c o n t a i n s t h e ( b a d ) k e r n e l s t a c k p o i n t e r ,
* r1 1 a n d r12 c o n t a i n t h e s a v e d S R R 0 a n d S R R 1 .
* We s w i t c h t o u s i n g a n e m e r g e n c y s t a c k , s a v e t h e r e g i s t e r s t h e r e ,
* and c a l l k e r n e l _ b a d _ s t a c k ( ) , w h i c h p a n i c s .
* /
bad_stack :
ld r1 ,P A C A E M E R G S P ( r13 )
subi r1 ,r1 ,6 4 + I N T _ F R A M E _ S I Z E
std r9 ,_ C C R ( r1 )
std r10 ,G P R 1 ( r1 )
std r11 ,_ N I P ( r1 )
std r12 ,_ M S R ( r1 )
mfspr r11 ,S P R N _ D A R
mfspr r12 ,S P R N _ D S I S R
std r11 ,_ D A R ( r1 )
std r12 ,_ D S I S R ( r1 )
mflr r10
mfctr r11
mfxer r12
std r10 ,_ L I N K ( r1 )
std r11 ,_ C T R ( r1 )
std r12 ,_ X E R ( r1 )
SAVE_ G P R ( 0 ,r1 )
SAVE_ G P R ( 2 ,r1 )
ld r10 ,E X _ R 3 ( r3 )
std r10 ,G P R 3 ( r1 )
SAVE_ G P R ( 4 ,r1 )
SAVE_ 4 G P R S ( 5 ,r1 )
ld r9 ,E X _ R 9 ( r3 )
ld r10 ,E X _ R 1 0 ( r3 )
SAVE_ 2 G P R S ( 9 ,r1 )
ld r9 ,E X _ R 1 1 ( r3 )
ld r10 ,E X _ R 1 2 ( r3 )
ld r11 ,E X _ R 1 3 ( r3 )
std r9 ,G P R 1 1 ( r1 )
std r10 ,G P R 1 2 ( r1 )
std r11 ,G P R 1 3 ( r1 )
BEGIN_ F T R _ S E C T I O N
ld r10 ,E X _ C F A R ( r3 )
std r10 ,O R I G _ G P R 3 ( r1 )
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ C F A R )
SAVE_ 8 G P R S ( 1 4 ,r1 )
SAVE_ 1 0 G P R S ( 2 2 ,r1 )
lhz r12 ,P A C A _ T R A P _ S A V E ( r13 )
std r12 ,_ T R A P ( r1 )
addi r11 ,r1 ,I N T _ F R A M E _ S I Z E
std r11 ,0 ( r1 )
li r12 ,0
std r12 ,0 ( r11 )
ld r2 ,P A C A T O C ( r13 )
ld r11 ,e x c e p t i o n _ m a r k e r @toc(r2)
std r12 ,R E S U L T ( r1 )
std r11 ,S T A C K _ F R A M E _ O V E R H E A D - 1 6 ( r1 )
1 : addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
bl k e r n e l _ b a d _ s t a c k
b 1 b
2017-06-29 20:49:19 +03:00
_ ASM_ N O K P R O B E _ S Y M B O L ( b a d _ s t a c k ) ;
2016-09-21 10:44:05 +03:00
2017-06-13 16:05:48 +03:00
/ *
* When d o o r b e l l i s t r i g g e r e d f r o m s y s t e m r e s e t w a k e u p , t h e m e s s a g e i s
* not c l e a r e d , s o i t w o u l d f i r e a g a i n w h e n E E i s e n a b l e d .
*
* When c o m i n g f r o m l o c a l _ i r q _ e n a b l e , t h e r e m a y b e t h e s a m e p r o b l e m i f
* we w e r e h a r d d i s a b l e d .
*
* Execute m s g c l r t o c l e a r p e n d i n g e x c e p t i o n s b e f o r e h a n d l i n g i t .
* /
h_doorbell_common_msgclr :
LOAD_ R E G _ I M M E D I A T E ( r3 , P P C _ D B E L L _ M S G T Y P E < < ( 6 3 - 3 6 ) )
PPC_ M S G C L R ( 3 )
b h _ d o o r b e l l _ c o m m o n
doorbell_super_common_msgclr :
LOAD_ R E G _ I M M E D I A T E ( r3 , P P C _ D B E L L _ M S G T Y P E < < ( 6 3 - 3 6 ) )
PPC_ M S G C L R P ( 3 )
b d o o r b e l l _ s u p e r _ c o m m o n
2016-09-21 10:44:05 +03:00
/ *
* Called f r o m a r c h _ l o c a l _ i r q _ e n a b l e w h e n a n i n t e r r u p t n e e d s
* to b e r e s e n t . r3 c o n t a i n s 0 x50 0 , 0 x90 0 , 0 x a00 o r 0 x e 8 0 t o i n d i c a t e
* which k i n d o f i n t e r r u p t . M S R : E E i s a l r e a d y o f f . W e g e n e r a t e a
* stackframe l i k e i f a r e a l i n t e r r u p t h a d h a p p e n e d .
*
* Note : While M S R : E E i s o f f , w e n e e d t o m a k e s u r e t h a t _ M S R
* in t h e g e n e r a t e d f r a m e h a s E E s e t t o 1 o r t h e e x c e p t i o n
* handler w i l l n o t p r o p e r l y r e - e n a b l e t h e m .
2017-06-13 16:05:49 +03:00
*
* Note t h a t w e d o n ' t s p e c i f y L R a s t h e N I P ( r e t u r n a d d r e s s ) f o r
* the i n t e r r u p t b e c a u s e t h a t w o u l d u n b a l a n c e t h e r e t u r n b r a n c h
* predictor.
2016-09-21 10:44:05 +03:00
* /
_ GLOBAL( _ _ r e p l a y _ i n t e r r u p t )
/ * We a r e g o i n g t o j u m p t o t h e e x c e p t i o n c o m m o n c o d e w h i c h
* will r e t r i e v e v a r i o u s r e g i s t e r v a l u e s f r o m t h e P A C A w h i c h
* we d o n ' t g i v e a d a m n a b o u t , s o w e d o n ' t b o t h e r s t o r i n g t h e m .
* /
mfmsr r12
2017-08-22 04:51:37 +03:00
LOAD_ R E G _ A D D R ( r11 , r e p l a y _ i n t e r r u p t _ r e t u r n )
2016-09-21 10:44:05 +03:00
mfcr r9
ori r12 ,r12 ,M S R _ E E
cmpwi r3 ,0 x90 0
beq d e c r e m e n t e r _ c o m m o n
cmpwi r3 ,0 x50 0
2017-08-11 19:39:04 +03:00
BEGIN_ F T R _ S E C T I O N
beq h _ v i r t _ i r q _ c o m m o n
FTR_ S E C T I O N _ E L S E
2016-09-21 10:44:05 +03:00
beq h a r d w a r e _ i n t e r r u p t _ c o m m o n
2017-08-11 19:39:04 +03:00
ALT_ F T R _ S E C T I O N _ E N D _ I F S E T ( C P U _ F T R _ H V M O D E | C P U _ F T R _ A R C H _ 3 0 0 )
2017-12-20 06:55:53 +03:00
cmpwi r3 ,0 x f00
beq p e r f o r m a n c e _ m o n i t o r _ c o m m o n
2016-09-21 10:44:05 +03:00
BEGIN_ F T R _ S E C T I O N
2017-08-11 19:39:03 +03:00
cmpwi r3 ,0 x a00
2017-06-13 16:05:48 +03:00
beq h _ d o o r b e l l _ c o m m o n _ m s g c l r
2016-09-21 10:44:05 +03:00
cmpwi r3 ,0 x e 6 0
beq h m i _ e x c e p t i o n _ c o m m o n
FTR_ S E C T I O N _ E L S E
cmpwi r3 ,0 x a00
2017-06-13 16:05:48 +03:00
beq d o o r b e l l _ s u p e r _ c o m m o n _ m s g c l r
2016-09-21 10:44:05 +03:00
ALT_ F T R _ S E C T I O N _ E N D _ I F S E T ( C P U _ F T R _ H V M O D E )
2017-08-22 04:51:37 +03:00
replay_interrupt_return :
2016-09-21 10:44:05 +03:00
blr
2017-06-13 16:05:49 +03:00
2017-06-29 20:49:19 +03:00
_ ASM_ N O K P R O B E _ S Y M B O L ( _ _ r e p l a y _ i n t e r r u p t )