2005-04-17 02:20:36 +04:00
/ *
* Low- l e v e l S L B r o u t i n e s
*
* Copyright ( C ) 2 0 0 4 D a v i d G i b s o n < d w g @au.ibm.com>, IBM
*
* Based o n e a r l i e r C v e r s i o n :
* Dave E n g e b r e t s e n a n d M i k e C o r r i g a n { e n g e b r e t | m i k e j c } @us.ibm.com
* Copyright ( c ) 2 0 0 1 D a v e E n g e b r e t s e n
* Copyright ( C ) 2 0 0 2 A n t o n B l a n c h a r d < a n t o n @au.ibm.com>, IBM
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
* /
# include < a s m / p r o c e s s o r . h >
# include < a s m / p p c _ a s m . h >
2005-09-09 22:57:26 +04:00
# include < a s m / a s m - o f f s e t s . h >
2005-04-17 02:20:36 +04:00
# include < a s m / c p u t a b l e . h >
2005-11-07 03:06:55 +03:00
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / p g t a b l e . h >
2006-09-25 12:19:00 +04:00
# include < a s m / f i r m w a r e . h >
2005-04-17 02:20:36 +04:00
2017-03-29 09:21:53 +03:00
/ *
* This m a c r o g e n e r a t e s a s m c o d e t o c o m p u t e t h e V S I D s c r a m b l e
* function. U s e d i n s l b _ a l l o c a t e ( ) a n d d o _ s t a b _ b o l t e d . T h e f u n c t i o n
* computed i s : ( p r o t o v s i d * V S I D _ M U L T I P L I E R ) % V S I D _ M O D U L U S
*
* rt = r e g i s t e r c o n t a i n i n g t h e p r o t o - V S I D a n d i n t o w h i c h t h e
* VSID w i l l b e s t o r e d
* rx = s c r a t c h r e g i s t e r ( c l o b b e r e d )
* rf = f l a g s
*
* - rt a n d r x m u s t b e d i f f e r e n t r e g i s t e r s
* - The a n s w e r w i l l e n d u p i n t h e l o w V S I D _ B I T S b i t s o f r t . T h e h i g h e r
* bits m a y c o n t a i n o t h e r g a r b a g e , s o y o u m a y n e e d t o m a s k t h e
* result.
* /
# define A S M _ V S I D _ S C R A M B L E ( r t , r x , r f , s i z e ) \
lis r x ,V S I D _ M U L T I P L I E R _ ## s i z e @ h ; \
ori r x ,r x ,V S I D _ M U L T I P L I E R _ ## s i z e @ l ; \
mulld r t ,r t ,r x ; /* rt = rt * MULTIPLIER */ \
/ * \
* powermac g e t s l b f a u l t b e f o r e f e a t u r e f i x u p , s o m a k e 6 5 b i t p a r t \
* the d e f a u l t p a r t o f f e a t u r e f i x u p \
* / \
BEGIN_ M M U _ F T R _ S E C T I O N \
srdi r x ,r t ,V S I D _ B I T S _ 6 5 _ ## s i z e ; \
clrldi r t ,r t ,( 6 4 - V S I D _ B I T S _ 6 5 _ ## s i z e ) ; \
add r t ,r t ,r x ; \
addi r x ,r t ,1 ; \
srdi r x ,r x ,V S I D _ B I T S _ 6 5 _ ## s i z e ; \
add r t ,r t ,r x ; \
rldimi r f ,r t ,S L B _ V S I D _ S H I F T _ ## s i z e , ( 64 - ( S L B _ V S I D _ S H I F T _ ## s i z e + V S I D _ B I T S _ 65 _ ## s i z e ) ) ; \
MMU_ F T R _ S E C T I O N _ E L S E \
srdi r x ,r t ,V S I D _ B I T S _ ## s i z e ; \
clrldi r t ,r t ,( 6 4 - V S I D _ B I T S _ ## s i z e ) ; \
add r t ,r t ,r x ; /* add high and low bits */ \
addi r x ,r t ,1 ; \
srdi r x ,r x ,V S I D _ B I T S _ ## s i z e ; / * e x t r a c t 2 ^ V S I D _ B I T S b i t * / \
add r t ,r t ,r x ; \
rldimi r f ,r t ,S L B _ V S I D _ S H I F T _ ## s i z e , ( 64 - ( S L B _ V S I D _ S H I F T _ ## s i z e + V S I D _ B I T S _ # # s i z e ) ) ; \
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 _ 6 8 _ B I T _ V A )
2017-06-19 14:57:33 +03:00
/ * void s l b _ a l l o c a t e ( u n s i g n e d l o n g e a ) ;
2005-04-17 02:20:36 +04:00
*
* Create a n S L B e n t r y f o r t h e g i v e n E A ( u s e r o r k e r n e l ) .
* r3 = f a u l t i n g a d d r e s s , r13 = P A C A
* r9 , r10 , r11 a r e c l o b b e r e d b y t h i s f u n c t i o n
2017-05-21 16:15:42 +03:00
* r3 i s p r e s e r v e d .
2005-04-17 02:20:36 +04:00
* No o t h e r r e g i s t e r s a r e e x a m i n e d o r c h a n g e d .
* /
2017-06-19 14:57:33 +03:00
_ GLOBAL( s l b _ a l l o c a t e )
2013-03-13 07:34:54 +04:00
/ *
* check f o r b a d k e r n e l / u s e r a d d r e s s
* ( ea & ~ R E G I O N _ M A S K ) > = P G T A B L E _ R A N G E
* /
2016-04-29 16:25:49 +03:00
rldicr. r9 ,r3 ,4 ,( 6 3 - H _ P G T A B L E _ E A D D R _ S I Z E - 4 )
2013-03-13 07:34:54 +04:00
bne- 8 f
2005-04-17 02:20:36 +04:00
srdi r9 ,r3 ,6 0 / * g e t r e g i o n * /
2013-03-13 07:34:54 +04:00
srdi r10 ,r3 ,S I D _ S H I F T / * g e t e s i d * /
2005-12-05 19:24:33 +03:00
cmpldi c r7 ,r9 ,0 x c / * c m p P A G E _ O F F S E T f o r l a t e r u s e * /
2005-04-17 02:20:36 +04:00
2005-12-05 19:24:33 +03:00
/* r3 = address, r10 = esid, cr7 = <> PAGE_OFFSET */
2005-04-17 02:20:36 +04:00
blt c r7 ,0 f / * u s e r o r k e r n e l ? * /
[POWERPC] vmemmap fixes to use smaller pages
This changes vmemmap to use a different region (region 0xf) of the
address space, and to configure the page size of that region
dynamically at boot.
The problem with the current approach of always using 16M pages is that
it's not well suited to machines that have small amounts of memory such
as small partitions on pseries, or PS3's.
In fact, on the PS3, failure to allocate the 16M page backing vmmemmap
tends to prevent hotplugging the HV's "additional" memory, thus limiting
the available memory even more, from my experience down to something
like 80M total, which makes it really not very useable.
The logic used by my match to choose the vmemmap page size is:
- If 16M pages are available and there's 1G or more RAM at boot,
use that size.
- Else if 64K pages are available, use that
- Else use 4K pages
I've tested on a POWER6 (16M pages) and on an iSeries POWER3 (4K pages)
and it seems to work fine.
Note that I intend to change the way we organize the kernel regions &
SLBs so the actual region will change from 0xf back to something else at
one point, as I simplify the SLB miss handler, but that will be for a
later patch.
Signed-off-by: Paul Mackerras <paulus@samba.org>
2008-04-30 09:41:48 +04:00
/ * Check i f h i t t i n g t h e l i n e a r m a p p i n g o r s o m e o t h e r k e r n e l s p a c e
2005-11-07 03:06:55 +03:00
* /
bne c r7 ,1 f
/ * Linear m a p p i n g e n c o d i n g b i t s , t h e " l i " i n s t r u c t i o n b e l o w w i l l
* be p a t c h e d b y t h e k e r n e l a t b o o t
* /
2014-03-10 02:44:22 +04:00
.globl slb_miss_kernel_load_linear
slb_miss_kernel_load_linear :
2005-11-07 03:06:55 +03:00
li r11 ,0
2012-09-10 06:52:55 +04:00
/ *
2017-03-29 15:10:22 +03:00
* context = ( e a > > 6 0 ) - ( 0 x c - 1 )
2013-03-13 07:34:54 +04:00
* r9 = r e g i o n i d .
2012-09-10 06:52:55 +04:00
* /
2017-03-29 15:10:22 +03:00
subi r9 ,r9 ,K E R N E L _ R E G I O N _ C O N T E X T _ O F F S E T
2013-03-13 07:34:54 +04:00
2007-10-11 14:37:10 +04:00
BEGIN_ F T R _ S E C T I O N
2017-02-13 07:26:40 +03:00
b . L s l b _ f i n i s h _ l o a d
2011-04-06 23:48:50 +04:00
END_ M M U _ F T R _ S E C T I O N _ I F C L R ( M M U _ F T R _ 1 T _ S E G M E N T )
2017-02-13 07:26:40 +03:00
b . L s l b _ f i n i s h _ l o a d _ 1 T
2005-11-07 03:06:55 +03:00
[POWERPC] vmemmap fixes to use smaller pages
This changes vmemmap to use a different region (region 0xf) of the
address space, and to configure the page size of that region
dynamically at boot.
The problem with the current approach of always using 16M pages is that
it's not well suited to machines that have small amounts of memory such
as small partitions on pseries, or PS3's.
In fact, on the PS3, failure to allocate the 16M page backing vmmemmap
tends to prevent hotplugging the HV's "additional" memory, thus limiting
the available memory even more, from my experience down to something
like 80M total, which makes it really not very useable.
The logic used by my match to choose the vmemmap page size is:
- If 16M pages are available and there's 1G or more RAM at boot,
use that size.
- Else if 64K pages are available, use that
- Else use 4K pages
I've tested on a POWER6 (16M pages) and on an iSeries POWER3 (4K pages)
and it seems to work fine.
Note that I intend to change the way we organize the kernel regions &
SLBs so the actual region will change from 0xf back to something else at
one point, as I simplify the SLB miss handler, but that will be for a
later patch.
Signed-off-by: Paul Mackerras <paulus@samba.org>
2008-04-30 09:41:48 +04:00
1 :
# ifdef C O N F I G _ S P A R S E M E M _ V M E M M A P
cmpldi c r0 ,r9 ,0 x f
bne 1 f
2017-03-29 15:10:22 +03:00
/* Check virtual memmap region. To be patched at kernel boot */
2014-03-10 02:44:22 +04:00
.globl slb_miss_kernel_load_vmemmap
slb_miss_kernel_load_vmemmap :
[POWERPC] vmemmap fixes to use smaller pages
This changes vmemmap to use a different region (region 0xf) of the
address space, and to configure the page size of that region
dynamically at boot.
The problem with the current approach of always using 16M pages is that
it's not well suited to machines that have small amounts of memory such
as small partitions on pseries, or PS3's.
In fact, on the PS3, failure to allocate the 16M page backing vmmemmap
tends to prevent hotplugging the HV's "additional" memory, thus limiting
the available memory even more, from my experience down to something
like 80M total, which makes it really not very useable.
The logic used by my match to choose the vmemmap page size is:
- If 16M pages are available and there's 1G or more RAM at boot,
use that size.
- Else if 64K pages are available, use that
- Else use 4K pages
I've tested on a POWER6 (16M pages) and on an iSeries POWER3 (4K pages)
and it seems to work fine.
Note that I intend to change the way we organize the kernel regions &
SLBs so the actual region will change from 0xf back to something else at
one point, as I simplify the SLB miss handler, but that will be for a
later patch.
Signed-off-by: Paul Mackerras <paulus@samba.org>
2008-04-30 09:41:48 +04:00
li r11 ,0
b 6 f
1 :
# endif / * C O N F I G _ S P A R S E M E M _ V M E M M A P * /
powerpc/mm/hash64: Make vmalloc 56T on hash
On 64-bit book3s, with the hash MMU, we currently define the kernel
virtual space (vmalloc, ioremap etc.), to be 16T in size. This is a
leftover from pre v3.7 when our user VM was also 16T.
Of that 16T we split it 50/50, with half used for PCI IO and ioremap
and the other 8T for vmalloc.
We never bothered to make it any bigger because 8T of vmalloc ought to
be enough for anybody. But it turns out that's not true, the per cpu
allocator wants large amounts of vmalloc space, not to make large
allocations, but to allow a large stride between allocations, because
we use pcpu_embed_first_chunk().
With a bit of juggling we can increase the entire kernel virtual space
to 64T. The only real complication is the check of the address in the
SLB miss handler, see the comment in the code.
Although we could continue to split virtual space 50/50 as we do now,
no one seems to be running out of PCI IO or ioremap space. So instead
keep that as 8T, and use the remaining 56T for vmalloc.
In future we should be able to increase the kernel virtual space to
512T, the code already supports that, it just needs testing on older
hardware.
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
2017-08-01 13:29:24 +03:00
/ *
* r1 0 c o n t a i n s t h e E S I D , w h i c h i s t h e o r i g i n a l f a u l t i n g E A s h i f t e d
* right b y 2 8 b i t s . W e n e e d t o c o m p a r e t h a t w i t h ( H _ V M A L L O C _ E N D > > 2 8 )
* which i s 0 x d00 0 3 8 0 0 0 . T h a t c a n ' t b e u s e d a s a n i m m e d i a t e , e v e n i f w e
* ignored t h e 0 x d , s o w e h a v e t o l o a d i t i n t o a r e g i s t e r , a n d w e o n l y
* have o n e r e g i s t e r f r e e . S o w e m u s t l o a d a l l o f ( H _ V M A L L O C _ E N D > > 2 8 )
* into a r e g i s t e r a n d c o m p a r e E S I D a g a i n s t t h a t .
* /
lis r11 ,( H _ V M A L L O C _ E N D > > 3 2 ) @h // r11 = 0xffffffffd0000000
ori r11 ,r11 ,( H _ V M A L L O C _ E N D > > 3 2 ) @l // r11 = 0xffffffffd0003800
/ / Rotate l e f t 4 , t h e n m a s k w i t h 0 x f f f f f f f f0
rldic r11 ,r11 ,4 ,2 8 / / r11 = 0 x d00 0 3 8 0 0 0
cmpld r10 ,r11 / / i f r10 > = r11
bge 5 f / / g o t o i o _ m a p p i n g
2017-08-01 13:29:23 +03:00
/ *
* vmalloc m a p p i n g g e t s t h e e n c o d i n g f r o m t h e P A C A a s t h e m a p p i n g
* can b e d e m o t e d f r o m 6 4 K - > 4 K d y n a m i c a l l y o n s o m e m a c h i n e s .
* /
2006-06-15 04:45:18 +04:00
lhz r11 ,P A C A V M A L L O C S L L P ( r13 )
2007-10-11 14:37:10 +04:00
b 6 f
2006-06-15 04:45:18 +04:00
5 :
2009-10-13 00:43:47 +04:00
/* IO mapping */
2014-03-10 02:44:22 +04:00
.globl slb_miss_kernel_load_io
slb_miss_kernel_load_io :
2005-11-07 03:06:55 +03:00
li r11 ,0
2007-10-11 14:37:10 +04:00
6 :
2012-09-10 06:52:55 +04:00
/ *
2017-03-29 15:10:22 +03:00
* context = ( e a > > 6 0 ) - ( 0 x c - 1 )
2013-03-13 07:34:54 +04:00
* r9 = r e g i o n i d .
2012-09-10 06:52:55 +04:00
* /
2017-03-29 15:10:22 +03:00
subi r9 ,r9 ,K E R N E L _ R E G I O N _ C O N T E X T _ O F F S E T
2013-03-13 07:34:54 +04:00
2007-10-11 14:37:10 +04:00
BEGIN_ F T R _ S E C T I O N
2017-02-13 07:26:40 +03:00
b . L s l b _ f i n i s h _ l o a d
2011-04-06 23:48:50 +04:00
END_ M M U _ F T R _ S E C T I O N _ I F C L R ( M M U _ F T R _ 1 T _ S E G M E N T )
2017-02-13 07:26:40 +03:00
b . L s l b _ f i n i s h _ l o a d _ 1 T
2005-11-07 03:06:55 +03:00
2016-09-02 14:47:59 +03:00
0 : / *
* For u s e r s p a c e a d d r e s s e s , m a k e s u r e t h i s i s r e g i o n 0 .
* /
cmpdi r9 , 0
2017-03-22 06:36:59 +03:00
bne- 8 f
/ *
* user s p a c e m a k e s u r e w e a r e w i t h i n t h e a l l o w e d l i m i t
* /
2017-11-09 20:27:40 +03:00
ld r11 ,P A C A _ S L B _ A D D R _ L I M I T ( r13 )
2017-03-22 06:36:59 +03:00
cmpld r3 ,r11
bge- 8 f
2016-09-02 14:47:59 +03:00
2007-05-08 10:27:27 +04:00
/ * when u s i n g s l i c e s , w e e x t r a c t t h e p s i z e o f f t h e s l i c e b i t m a p s
* and t h e n w e n e e d t o g e t t h e s l l p e n c o d i n g o f f t h e m m u _ p s i z e _ d e f s
* array.
*
* XXX T h i s i s a b i t i n e f f i c i e n t e s p e c i a l l y f o r t h e n o r m a l c a s e ,
* so w e s h o u l d t r y t o i m p l e m e n t a f a s t p a t h f o r t h e s t a n d a r d p a g e
* size u s i n g t h e o l d s l l p v a l u e s o w e a v o i d t h e a r r a y . W e c a n n o t
* really d o d y n a m i c p a t c h i n g u n f o r t u n a t e l y a s p r o c e s s e s m i g h t f l i p
* between 4 k a n d 6 4 k s t a n d a r d p a g e s i z e
* /
# ifdef C O N F I G _ P P C _ M M _ S L I C E S
2012-09-10 06:52:52 +04:00
/* r10 have esid */
[PATCH] ppc64: Fix bug in SLB miss handler for hugepages
This patch, however, should be applied on top of the 64k-page-size patch to
fix some problems with hugepage (some pre-existing, another introduced by
this patch).
The patch fixes a bug in the SLB miss handler for hugepages on ppc64
introduced by the dynamic hugepage patch (commit id
c594adad5653491813959277fb87a2fef54c4e05) due to a misunderstanding of the
srd instruction's behaviour (mea culpa). The problem arises when a 64-bit
process maps some hugepages in the low 4GB of the address space (unusual).
In this case, as well as the 256M segment in question being marked for
hugepages, other segments at 32G intervals will be incorrectly marked for
hugepages.
In the process, this patch tweaks the semantics of the hugepage bitmaps to
be more sensible. Previously, an address below 4G was marked for hugepages
if the appropriate segment bit in the "low areas" bitmask was set *or* if
the low bit in the "high areas" bitmap was set (which would mark all
addresses below 1TB for hugepage). With this patch, any given address is
governed by a single bitmap. Addresses below 4GB are marked for hugepage
if and only if their bit is set in the "low areas" bitmap (256M
granularity). Addresses between 4GB and 1TB are marked for hugepage iff
the low bit in the "high areas" bitmap is set. Higher addresses are marked
for hugepage iff their bit in the "high areas" bitmap is set (1TB
granularity).
To avoid conflicts, this patch must be applied on top of BenH's pending
patch for 64k base page size [0]. As such, this patch also addresses a
hugepage problem introduced by that patch. That patch allows hugepages of
1MB in size on hardware which supports it, however, that won't work when
using 4k pages (4 level pagetable), because in that case hugepage PTEs are
stored at the PMD level, and each PMD entry maps 2MB. This patch simply
disallows hugepages in that case (we can do something cleverer to re-enable
them some other day).
Built, booted, and a handful of hugepage related tests passed on POWER5
LPAR (both ARCH=powerpc and ARCH=ppc64).
[0] http://gate.crashing.org/~benh/ppc64-64k-pages.diff
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-07 11:57:52 +03:00
cmpldi r10 ,1 6
2012-09-10 06:52:52 +04:00
/* below SLICE_LOW_TOP */
[PATCH] ppc64: Fix bug in SLB miss handler for hugepages
This patch, however, should be applied on top of the 64k-page-size patch to
fix some problems with hugepage (some pre-existing, another introduced by
this patch).
The patch fixes a bug in the SLB miss handler for hugepages on ppc64
introduced by the dynamic hugepage patch (commit id
c594adad5653491813959277fb87a2fef54c4e05) due to a misunderstanding of the
srd instruction's behaviour (mea culpa). The problem arises when a 64-bit
process maps some hugepages in the low 4GB of the address space (unusual).
In this case, as well as the 256M segment in question being marked for
hugepages, other segments at 32G intervals will be incorrectly marked for
hugepages.
In the process, this patch tweaks the semantics of the hugepage bitmaps to
be more sensible. Previously, an address below 4G was marked for hugepages
if the appropriate segment bit in the "low areas" bitmask was set *or* if
the low bit in the "high areas" bitmap was set (which would mark all
addresses below 1TB for hugepage). With this patch, any given address is
governed by a single bitmap. Addresses below 4GB are marked for hugepage
if and only if their bit is set in the "low areas" bitmap (256M
granularity). Addresses between 4GB and 1TB are marked for hugepage iff
the low bit in the "high areas" bitmap is set. Higher addresses are marked
for hugepage iff their bit in the "high areas" bitmap is set (1TB
granularity).
To avoid conflicts, this patch must be applied on top of BenH's pending
patch for 64k base page size [0]. As such, this patch also addresses a
hugepage problem introduced by that patch. That patch allows hugepages of
1MB in size on hardware which supports it, however, that won't work when
using 4k pages (4 level pagetable), because in that case hugepage PTEs are
stored at the PMD level, and each PMD entry maps 2MB. This patch simply
disallows hugepages in that case (we can do something cleverer to re-enable
them some other day).
Built, booted, and a handful of hugepage related tests passed on POWER5
LPAR (both ARCH=powerpc and ARCH=ppc64).
[0] http://gate.crashing.org/~benh/ppc64-64k-pages.diff
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-07 11:57:52 +03:00
blt 5 f
2012-09-10 06:52:52 +04:00
/ *
* Handle h p s i z e s ,
* r9 i s g e t _ p a c a ( ) - > c o n t e x t . h i g h _ s l i c e s _ p s i z e [ i n d e x ] , r11 i s m a s k _ i n d e x
* /
srdi r11 ,r10 ,( S L I C E _ H I G H _ S H I F T - S L I C E _ L O W _ S H I F T + 1 ) / * i n d e x * /
addi r9 ,r11 ,P A C A H I G H S L I C E P S I Z E
lbzx r9 ,r13 ,r9 / * r9 i s h p s i z e s [ r11 ] * /
/* r11 = (r10 >> (SLICE_HIGH_SHIFT - SLICE_LOW_SHIFT)) & 0x1 */
rldicl r11 ,r10 ,( 6 4 - ( S L I C E _ H I G H _ S H I F T - S L I C E _ L O W _ S H I F T ) ) ,6 3
b 6 f
[PATCH] ppc64: Fix bug in SLB miss handler for hugepages
This patch, however, should be applied on top of the 64k-page-size patch to
fix some problems with hugepage (some pre-existing, another introduced by
this patch).
The patch fixes a bug in the SLB miss handler for hugepages on ppc64
introduced by the dynamic hugepage patch (commit id
c594adad5653491813959277fb87a2fef54c4e05) due to a misunderstanding of the
srd instruction's behaviour (mea culpa). The problem arises when a 64-bit
process maps some hugepages in the low 4GB of the address space (unusual).
In this case, as well as the 256M segment in question being marked for
hugepages, other segments at 32G intervals will be incorrectly marked for
hugepages.
In the process, this patch tweaks the semantics of the hugepage bitmaps to
be more sensible. Previously, an address below 4G was marked for hugepages
if the appropriate segment bit in the "low areas" bitmask was set *or* if
the low bit in the "high areas" bitmap was set (which would mark all
addresses below 1TB for hugepage). With this patch, any given address is
governed by a single bitmap. Addresses below 4GB are marked for hugepage
if and only if their bit is set in the "low areas" bitmap (256M
granularity). Addresses between 4GB and 1TB are marked for hugepage iff
the low bit in the "high areas" bitmap is set. Higher addresses are marked
for hugepage iff their bit in the "high areas" bitmap is set (1TB
granularity).
To avoid conflicts, this patch must be applied on top of BenH's pending
patch for 64k base page size [0]. As such, this patch also addresses a
hugepage problem introduced by that patch. That patch allows hugepages of
1MB in size on hardware which supports it, however, that won't work when
using 4k pages (4 level pagetable), because in that case hugepage PTEs are
stored at the PMD level, and each PMD entry maps 2MB. This patch simply
disallows hugepages in that case (we can do something cleverer to re-enable
them some other day).
Built, booted, and a handful of hugepage related tests passed on POWER5
LPAR (both ARCH=powerpc and ARCH=ppc64).
[0] http://gate.crashing.org/~benh/ppc64-64k-pages.diff
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-11-07 11:57:52 +03:00
2012-09-10 06:52:52 +04:00
5 :
/ *
* Handle l p s i z e s
* r9 i s g e t _ p a c a ( ) - > c o n t e x t . l o w _ s l i c e s _ p s i z e , r11 i s i n d e x
* /
ld r9 ,P A C A L O W S L I C E S P S I Z E ( r13 )
mr r11 ,r10
6 :
sldi r11 ,r11 ,2 / * i n d e x * 4 * /
/* Extract the psize and multiply to get an array offset */
2007-05-08 10:27:27 +04:00
srd r9 ,r9 ,r11
andi. r9 ,r9 ,0 x f
mulli r9 ,r9 ,M M U P S I Z E D E F S I Z E
2005-08-11 10:55:21 +04:00
2007-05-08 10:27:27 +04:00
/ * Now g e t t o t h e a r r a y a n d o b t a i n t h e s l l p
* /
ld r11 ,P A C A T O C ( r13 )
ld r11 ,m m u _ p s i z e _ d e f s @got(r11)
add r11 ,r11 ,r9
ld r11 ,M M U P S I Z E S L L P ( r11 )
ori r11 ,r11 ,S L B _ V S I D _ U S E R
# else
/* paca context sllp already contains the SLB_VSID_USER bits */
2006-06-15 04:45:18 +04:00
lhz r11 ,P A C A C O N T E X T S L L P ( r13 )
2007-05-08 10:27:27 +04:00
# endif / * C O N F I G _ P P C _ M M _ S L I C E S * /
2005-11-07 03:06:55 +03:00
ld r9 ,P A C A C O N T E X T I D ( r13 )
2007-10-11 14:37:10 +04:00
BEGIN_ F T R _ S E C T I O N
cmpldi r10 ,0 x10 0 0
2017-02-13 07:26:40 +03:00
bge . L s l b _ f i n i s h _ l o a d _ 1 T
2011-04-06 23:48:50 +04:00
END_ M M U _ F T R _ S E C T I O N _ I F S E T ( M M U _ F T R _ 1 T _ S E G M E N T )
2017-02-13 07:26:40 +03:00
b . L s l b _ f i n i s h _ l o a d
2005-11-07 03:06:55 +03:00
powerpc/mm: Preserve CFAR value on SLB miss caused by access to bogus address
Currently, if userspace or the kernel accesses a completely bogus address,
for example with any of bits 46-59 set, we first take an SLB miss interrupt,
install a corresponding SLB entry with VSID 0, retry the instruction, then
take a DSI/ISI interrupt because there is no HPT entry mapping the address.
However, by the time of the second interrupt, the Come-From Address Register
(CFAR) has been overwritten by the rfid instruction at the end of the SLB
miss interrupt handler. Since bogus accesses can often be caused by a
function return after the stack has been overwritten, the CFAR value would
be very useful as it could indicate which function it was whose return had
led to the bogus address.
This patch adds code to create a full exception frame in the SLB miss handler
in the case of a bogus address, rather than inserting an SLB entry with a
zero VSID field. Then we call a new slb_miss_bad_addr() function in C code,
which delivers a signal for a user access or creates an oops for a kernel
access. In the latter case the oops message will show the CFAR value at the
time of the access.
In the case of the radix MMU, a segment miss interrupt indicates an access
outside the ranges mapped by the page tables. Previously this was handled
by the code for an unrecoverable SLB miss (one with MSR[RI] = 0), which is
not really correct. With this patch, we now handle these interrupts with
slb_miss_bad_addr(), which is much more consistent.
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2016-09-02 14:49:21 +03:00
8 : /* invalid EA - return an error indication */
crset 4 * c r0 + e q / * i n d i c a t e f a i l u r e * /
blr
2005-11-07 03:06:55 +03:00
/ *
* Finish l o a d i n g o f a n S L B e n t r y a n d r e t u r n
*
2013-03-13 07:34:54 +04:00
* r3 = E A , r9 = c o n t e x t , r10 = E S I D , r11 = f l a g s , c l o b b e r s r9 , c r7 = < > P A G E _ O F F S E T
2005-11-07 03:06:55 +03:00
* /
2017-02-13 07:26:40 +03:00
.Lslb_finish_load :
2013-03-13 07:34:55 +04:00
rldimi r10 ,r9 ,E S I D _ B I T S ,0
2017-03-29 09:21:53 +03:00
ASM_ V S I D _ S C R A M B L E ( r10 ,r9 ,r11 ,2 5 6 M )
2005-11-07 03:06:55 +03:00
/* r3 = EA, r11 = VSID data */
/ *
* Find a s l o t , r o u n d r o b i n . P r e v i o u s l y w e t r i e d t o f i n d a
* free s l o t f i r s t b u t t h a t t o o k t o o l o n g . U n f o r t u n a t e l y w e
* dont h a v e a n y L R U i n f o r m a t i o n t o h e l p u s c h o o s e a s l o t .
* /
2017-05-21 16:15:42 +03:00
mr r9 ,r3
/* slb_finish_load_1T continues here. r9=EA with non-ESID bits clear */
2007-10-11 14:37:10 +04:00
7 : ld r10 ,P A C A S T A B R R ( r13 )
2005-11-07 03:06:55 +03:00
addi r10 ,r10 ,1
2007-12-06 09:24:48 +03:00
/* This gets soft patched on boot. */
2014-03-10 02:44:22 +04:00
.globl slb_compare_rr_to_size
slb_compare_rr_to_size :
2007-12-06 09:24:48 +03:00
cmpldi r10 ,0
2005-11-07 03:06:55 +03:00
blt+ 4 f
li r10 ,S L B _ N U M _ B O L T E D
4 :
std r10 ,P A C A S T A B R R ( r13 )
3 :
2017-05-21 16:15:42 +03:00
rldimi r9 ,r10 ,0 ,3 6 / * r9 = E A [ 0 : 3 5 ] | e n t r y * /
oris r10 ,r9 ,S L B _ E S I D _ V @h /* r10 = r9 | SLB_ESID_V */
2005-11-07 03:06:55 +03:00
2017-05-21 16:15:42 +03:00
/* r9 = ESID data, r11 = VSID data */
2005-04-17 02:20:36 +04:00
/ *
* No n e e d f o r a n i s y n c b e f o r e o r a f t e r t h i s s l b m t e . T h e e x c e p t i o n
* we e n t e r w i t h a n d t h e r f i d w e e x i t w i t h a r e c o n t e x t s y n c h r o n i z i n g .
* /
slbmte r11 ,r10
2005-11-07 03:06:55 +03:00
/* we're done for kernel addresses */
crclr 4 * c r0 + e q / * s e t r e s u l t t o " s u c c e s s " * /
bgelr c r7
2005-04-17 02:20:36 +04:00
/* Update the slb cache */
2017-05-21 16:15:42 +03:00
lhz r9 ,P A C A S L B C A C H E P T R ( r13 ) / * o f f s e t = p a c a - > s l b _ c a c h e _ p t r * /
cmpldi r9 ,S L B _ C A C H E _ E N T R I E S
2005-04-17 02:20:36 +04:00
bge 1 f
/* still room in the slb cache */
2017-05-21 16:15:42 +03:00
sldi r11 ,r9 ,2 / * r11 = o f f s e t * s i z e o f ( u 3 2 ) * /
2012-09-10 06:52:54 +04:00
srdi r10 ,r10 ,2 8 / * g e t t h e 3 6 b i t s o f t h e E S I D * /
add r11 ,r11 ,r13 / * r11 = ( u 3 2 * ) p a c a + o f f s e t * /
stw r10 ,P A C A S L B C A C H E ( r11 ) / * p a c a - > s l b _ c a c h e [ o f f s e t ] = e s i d * /
2017-05-21 16:15:42 +03:00
addi r9 ,r9 ,1 / * o f f s e t + + * /
2005-04-17 02:20:36 +04:00
b 2 f
1 : /* offset >= SLB_CACHE_ENTRIES */
2017-05-21 16:15:42 +03:00
li r9 ,S L B _ C A C H E _ E N T R I E S + 1
2005-04-17 02:20:36 +04:00
2 :
2017-05-21 16:15:42 +03:00
sth r9 ,P A C A S L B C A C H E P T R ( r13 ) / * p a c a - > s l b _ c a c h e _ p t r = o f f s e t * /
2005-11-07 03:06:55 +03:00
crclr 4 * c r0 + e q / * s e t r e s u l t t o " s u c c e s s " * /
2005-04-17 02:20:36 +04:00
blr
2007-10-11 14:37:10 +04:00
/ *
* Finish l o a d i n g o f a 1 T S L B e n t r y ( f o r t h e k e r n e l l i n e a r m a p p i n g ) a n d r e t u r n .
*
2013-03-13 07:34:54 +04:00
* r3 = E A , r9 = c o n t e x t , r10 = E S I D ( 2 5 6 M B ) , r11 = f l a g s , c l o b b e r s r9
2007-10-11 14:37:10 +04:00
* /
2017-02-13 07:26:40 +03:00
.Lslb_finish_load_1T :
2013-03-13 07:34:54 +04:00
srdi r10 ,r10 ,( S I D _ S H I F T _ 1 T - S I D _ S H I F T ) / * g e t 1 T E S I D * /
2013-03-13 07:34:55 +04:00
rldimi r10 ,r9 ,E S I D _ B I T S _ 1 T ,0
2017-03-29 09:21:53 +03:00
ASM_ V S I D _ S C R A M B L E ( r10 ,r9 ,r11 ,1 T )
2007-10-11 14:37:10 +04:00
li r10 ,M M U _ S E G S I Z E _ 1 T
rldimi r11 ,r10 ,S L B _ V S I D _ S S I Z E _ S H I F T ,0 / * i n s e r t s e g m e n t s i z e * /
/* r3 = EA, r11 = VSID data */
2017-05-21 16:15:42 +03:00
clrrdi r9 ,r3 ,S I D _ S H I F T _ 1 T / * c l e a r o u t n o n - E S I D b i t s * /
2007-10-11 14:37:10 +04:00
b 7 b
2017-02-13 07:30:19 +03:00
2017-06-19 14:57:33 +03:00
_ ASM_ N O K P R O B E _ S Y M B O L ( s l b _ a l l o c a t e )
2017-02-13 07:30:19 +03:00
_ ASM_ N O K P R O B E _ S Y M B O L ( s l b _ m i s s _ k e r n e l _ l o a d _ l i n e a r )
_ ASM_ N O K P R O B E _ S Y M B O L ( s l b _ m i s s _ k e r n e l _ l o a d _ i o )
_ ASM_ N O K P R O B E _ S Y M B O L ( s l b _ c o m p a r e _ r r _ t o _ s i z e )
# ifdef C O N F I G _ S P A R S E M E M _ V M E M M A P
_ ASM_ N O K P R O B E _ S Y M B O L ( s l b _ m i s s _ k e r n e l _ l o a d _ v m e m m a p )
# endif