2012-03-05 15:49:27 +04:00
/ *
* Low- l e v e l C P U i n i t i a l i s a t i o n
* Based o n a r c h / a r m / k e r n e l / h e a d . S
*
* Copyright ( C ) 1 9 9 4 - 2 0 0 2 R u s s e l l K i n g
* Copyright ( C ) 2 0 0 3 - 2 0 1 2 A R M L t d .
* Authors : Catalin M a r i n a s < c a t a l i n . m a r i n a s @arm.com>
* Will D e a c o n < w i l l . d e a c o n @arm.com>
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify
* it u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e v e r s i o n 2 a s
* published b y t h e F r e e S o f t w a r e F o u n d a t i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* along w i t h t h i s p r o g r a m . I f n o t , s e e < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > .
* /
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / i n i t . h >
2014-06-30 19:01:31 +04:00
# include < l i n u x / i r q c h i p / a r m - g i c - v3 . h >
2012-03-05 15:49:27 +04:00
# include < a s m / a s s e m b l e r . h >
# include < a s m / p t r a c e . h >
# include < a s m / a s m - o f f s e t s . h >
2014-03-26 22:25:55 +04:00
# include < a s m / c a c h e . h >
2012-08-29 21:32:18 +04:00
# include < a s m / c p u t y p e . h >
2016-01-26 11:13:44 +03:00
# include < a s m / e l f . h >
2015-10-19 16:19:27 +03:00
# include < a s m / k e r n e l - p g t a b l e . h >
2012-03-05 15:49:27 +04:00
# include < a s m / m e m o r y . h >
# include < a s m / p g t a b l e - h w d e f . h >
# include < a s m / p g t a b l e . h >
# include < a s m / p a g e . h >
2015-10-19 16:19:35 +03:00
# include < a s m / s y s r e g . h >
# include < a s m / t h r e a d _ i n f o . h >
2012-10-26 18:40:05 +04:00
# include < a s m / v i r t . h >
2012-03-05 15:49:27 +04:00
2015-03-17 11:14:29 +03:00
# define _ _ P H Y S _ O F F S E T ( K E R N E L _ S T A R T - T E X T _ O F F S E T )
2012-03-05 15:49:27 +04:00
2014-08-13 21:53:03 +04:00
# if ( T E X T _ O F F S E T & 0 x f f f ) ! = 0
# error T E X T _ O F F S E T m u s t b e a t l e a s t 4 K B a l i g n e d
# elif ( P A G E _ O F F S E T & 0 x1 f f f f f ) ! = 0
2014-06-24 19:51:37 +04:00
# error P A G E _ O F F S E T m u s t b e a t l e a s t 2 M B a l i g n e d
2014-08-13 21:53:03 +04:00
# elif T E X T _ O F F S E T > 0 x1 f f f f f
2014-06-24 19:51:37 +04:00
# error T E X T _ O F F S E T m u s t b e l e s s t h a n 2 M B
2012-03-05 15:49:27 +04:00
# endif
2015-03-17 11:14:29 +03:00
# define K E R N E L _ S T A R T _ t e x t
2012-03-05 15:49:27 +04:00
# define K E R N E L _ E N D _ e n d
/ *
* Kernel s t a r t u p e n t r y p o i n t .
* - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* The r e q u i r e m e n t s a r e :
* MMU = o f f , D - c a c h e = o f f , I - c a c h e = o n o r o f f ,
* x0 = p h y s i c a l a d d r e s s t o t h e F D T b l o b .
*
* This c o d e i s m o s t l y p o s i t i o n i n d e p e n d e n t s o y o u c a l l t h i s a t
* _ _ pa( P A G E _ O F F S E T + T E X T _ O F F S E T ) .
*
* Note t h a t t h e c a l l e e - s a v e d r e g i s t e r s a r e u s e d f o r s t o r i n g v a r i a b l e s
* that a r e u s e f u l b e f o r e t h e M M U i s e n a b l e d . T h e a l l o c a t i o n s a r e d e s c r i b e d
* in t h e e n t r y r o u t i n e s .
* /
_ _ HEAD
2015-12-26 14:46:40 +03:00
_head :
2012-03-05 15:49:27 +04:00
/ *
* DO N O T M O D I F Y . I m a g e h e a d e r e x p e c t e d b y L i n u x b o o t - l o a d e r s .
* /
2014-04-16 06:47:52 +04:00
# ifdef C O N F I G _ E F I
/ *
* This a d d i n s t r u c t i o n h a s n o m e a n i n g f u l e f f e c t e x c e p t t h a t
* its o p c o d e f o r m s t h e m a g i c " M Z " s i g n a t u r e r e q u i r e d b y U E F I .
* /
add x13 , x18 , #0x16
b s t e x t
# else
2012-03-05 15:49:27 +04:00
b s t e x t / / b r a n c h t o k e r n e l s t a r t , m a g i c
.long 0 / / reserved
2014-04-16 06:47:52 +04:00
# endif
2015-12-26 15:48:02 +03:00
le6 4 s y m _ k e r n e l _ o f f s e t _ l e / / I m a g e l o a d o f f s e t f r o m s t a r t o f R A M , l i t t l e - e n d i a n
le6 4 s y m _ k e r n e l _ s i z e _ l e / / E f f e c t i v e s i z e o f k e r n e l i m a g e , l i t t l e - e n d i a n
le6 4 s y m _ k e r n e l _ f l a g s _ l e / / I n f o r m a t i v e f l a g s , l i t t l e - e n d i a n
2013-08-15 03:10:00 +04:00
.quad 0 / / reserved
.quad 0 / / reserved
.quad 0 / / reserved
.byte 0x41 / / Magic n u m b e r , " A R M \ x64 "
.byte 0x52
.byte 0x4d
.byte 0x64
2014-04-16 06:47:52 +04:00
# ifdef C O N F I G _ E F I
2015-12-26 14:46:40 +03:00
.long pe_header - _ head / / O f f s e t t o t h e P E h e a d e r .
2014-04-16 06:47:52 +04:00
# else
2013-08-15 03:10:00 +04:00
.word 0 / / reserved
2014-04-16 06:47:52 +04:00
# endif
# ifdef C O N F I G _ E F I
2015-10-08 22:02:04 +03:00
.globl __efistub_stext_offset
2015-12-26 14:46:40 +03:00
.set _ _ efistub_ s t e x t _ o f f s e t , s t e x t - _ h e a d
2014-04-16 06:47:52 +04:00
.align 3
pe_header :
.ascii " PE"
.short 0
coff_header :
.short 0xaa64 / / AArch6 4
.short 2 / / nr_ s e c t i o n s
.long 0 / / TimeDateStamp
.long 0 / / PointerToSymbolTable
.long 1 / / NumberOfSymbols
.short section_table - optional_ h e a d e r / / S i z e O f O p t i o n a l H e a d e r
.short 0x206 / / Characteristics.
/ / IMAGE_ F I L E _ D E B U G _ S T R I P P E D |
/ / IMAGE_ F I L E _ E X E C U T A B L E _ I M A G E |
/ / IMAGE_ F I L E _ L I N E _ N U M S _ S T R I P P E D
optional_header :
.short 0x20b / / PE3 2 + f o r m a t
.byte 0x02 / / MajorLinkerVersion
.byte 0x14 / / MinorLinkerVersion
2014-07-30 14:59:03 +04:00
.long _end - stext / / S i z e O f C o d e
2014-04-16 06:47:52 +04:00
.long 0 / / SizeOfInitializedData
.long 0 / / SizeOfUninitializedData
2015-12-26 14:46:40 +03:00
.long __efistub_entry - _ head / / A d d r e s s O f E n t r y P o i n t
2015-10-08 22:02:04 +03:00
.long __efistub_stext_offset / / BaseOfCode
2014-04-16 06:47:52 +04:00
extra_header_fields :
.quad 0 / / ImageBase
2014-10-10 13:25:24 +04:00
.long 0x1000 / / SectionAlignment
2014-10-10 20:42:55 +04:00
.long PECOFF_FILE_ALIGNMENT / / FileAlignment
2014-04-16 06:47:52 +04:00
.short 0 / / MajorOperatingSystemVersion
.short 0 / / MinorOperatingSystemVersion
.short 0 / / MajorImageVersion
.short 0 / / MinorImageVersion
.short 0 / / MajorSubsystemVersion
.short 0 / / MinorSubsystemVersion
.long 0 / / Win3 2 V e r s i o n V a l u e
2015-12-26 14:46:40 +03:00
.long _end - _ head / / S i z e O f I m a g e
2014-04-16 06:47:52 +04:00
/ / Everything b e f o r e t h e k e r n e l i m a g e i s c o n s i d e r e d p a r t o f t h e h e a d e r
2015-10-08 22:02:04 +03:00
.long __efistub_stext_offset / / SizeOfHeaders
2014-04-16 06:47:52 +04:00
.long 0 / / CheckSum
.short 0xa / / Subsystem ( E F I a p p l i c a t i o n )
.short 0 / / DllCharacteristics
.quad 0 / / SizeOfStackReserve
.quad 0 / / SizeOfStackCommit
.quad 0 / / SizeOfHeapReserve
.quad 0 / / SizeOfHeapCommit
.long 0 / / LoaderFlags
.long 0x6 / / NumberOfRvaAndSizes
.quad 0 / / ExportTable
.quad 0 / / ImportTable
.quad 0 / / ResourceTable
.quad 0 / / ExceptionTable
.quad 0 / / CertificationTable
.quad 0 / / BaseRelocationTable
/ / Section t a b l e
section_table :
/ *
* The E F I a p p l i c a t i o n l o a d e r r e q u i r e s a r e l o c a t i o n s e c t i o n
* because E F I a p p l i c a t i o n s m u s t b e r e l o c a t a b l e . T h i s i s a
* dummy s e c t i o n a s f a r a s w e a r e c o n c e r n e d .
* /
.ascii " .reloc "
.byte 0
.byte 0 / / end o f 0 p a d d i n g o f s e c t i o n n a m e
.long 0
.long 0
.long 0 / / SizeOfRawData
.long 0 / / PointerToRawData
.long 0 / / PointerToRelocations
.long 0 / / PointerToLineNumbers
.short 0 / / NumberOfRelocations
.short 0 / / NumberOfLineNumbers
.long 0x42100040 / / Characteristics ( s e c t i o n f l a g s )
.ascii " .text "
.byte 0
.byte 0
.byte 0 / / end o f 0 p a d d i n g o f s e c t i o n n a m e
2014-07-30 14:59:03 +04:00
.long _end - stext / / V i r t u a l S i z e
2015-10-08 22:02:04 +03:00
.long __efistub_stext_offset / / VirtualAddress
2014-04-16 06:47:52 +04:00
.long _edata - stext / / S i z e O f R a w D a t a
2015-10-08 22:02:04 +03:00
.long __efistub_stext_offset / / PointerToRawData
2014-04-16 06:47:52 +04:00
.long 0 / / PointerToRelocations ( 0 f o r e x e c u t a b l e s )
.long 0 / / PointerToLineNumbers ( 0 f o r e x e c u t a b l e s )
.short 0 / / NumberOfRelocations ( 0 f o r e x e c u t a b l e s )
.short 0 / / NumberOfLineNumbers ( 0 f o r e x e c u t a b l e s )
.long 0xe0500020 / / Characteristics ( s e c t i o n f l a g s )
2014-10-10 13:25:24 +04:00
/ *
* EFI w i l l l o a d s t e x t o n w a r d s a t t h e 4 k s e c t i o n a l i g n m e n t
* described i n t h e P E / C O F F h e a d e r . T o e n s u r e t h a t i n s t r u c t i o n
* sequences u s i n g a n a d r p a n d a : l o 1 2 : i m m e d i a t e w i l l f u n c t i o n
* correctly a t t h i s a l i g n m e n t , w e m u s t e n s u r e t h a t s t e x t i s
* placed a t a 4 k b o u n d a r y i n t h e I m a g e t o b e g i n w i t h .
* /
.align 12
2014-04-16 06:47:52 +04:00
# endif
2012-03-05 15:49:27 +04:00
ENTRY( s t e x t )
2015-03-17 12:55:12 +03:00
bl p r e s e r v e _ b o o t _ a r g s
2013-10-11 17:52:16 +04:00
bl e l 2 _ s e t u p / / D r o p t o E L 1 , w20 =cpu_boot_mode
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
mov x23 , x z r / / K A S L R o f f s e t , d e f a u l t s t o 0
2015-03-17 11:14:29 +03:00
adrp x24 , _ _ P H Y S _ O F F S E T
2013-10-11 17:52:16 +04:00
bl s e t _ c p u _ b o o t _ m o d e _ f l a g
2012-03-05 15:49:27 +04:00
bl _ _ c r e a t e _ p a g e _ t a b l e s / / x25 =TTBR0 , x26 =TTBR1
/ *
2015-03-18 17:55:20 +03:00
* The f o l l o w i n g c a l l s C P U s e t u p c o d e , s e e a r c h / a r m 6 4 / m m / p r o c . S f o r
* details.
2012-03-05 15:49:27 +04:00
* On r e t u r n , t h e C P U w i l l b e r e a d y f o r t h e M M U t o b e t u r n e d o n a n d
* the T C R w i l l h a v e b e e n s e t .
* /
2015-12-26 14:46:40 +03:00
ldr x27 , 0 f / / a d d r e s s t o j u m p t o a f t e r
2012-03-05 15:49:27 +04:00
/ / MMU h a s b e e n e n a b l e d
2015-03-17 10:59:53 +03:00
adr_ l l r , _ _ e n a b l e _ m m u / / r e t u r n ( P I C ) a d d r e s s
2015-03-18 17:55:20 +03:00
b _ _ c p u _ s e t u p / / i n i t i a l i s e p r o c e s s o r
2012-03-05 15:49:27 +04:00
ENDPROC( s t e x t )
2015-12-26 14:46:40 +03:00
.align 3
0 : .quad _ _ m m a p _ s w i t c h e d - ( _ h e a d - T E X T _ O F F S E T ) + K I M A G E _ V A D D R
2012-03-05 15:49:27 +04:00
2015-03-17 12:55:12 +03:00
/ *
* Preserve t h e a r g u m e n t s p a s s e d b y t h e b o o t l o a d e r i n x0 . . x3
* /
preserve_boot_args :
mov x21 , x0 / / x21 =FDT
adr_ l x0 , b o o t _ a r g s / / r e c o r d t h e c o n t e n t s o f
stp x21 , x1 , [ x0 ] / / x0 . . x3 a t k e r n e l e n t r y
stp x2 , x3 , [ x0 , #16 ]
dmb s y / / n e e d e d b e f o r e d c i v a c w i t h
/ / MMU o f f
add x1 , x0 , #0x20 / / 4 x 8 b y t e s
b _ _ i n v a l _ c a c h e _ r a n g e / / t a i l c a l l
ENDPROC( p r e s e r v e _ b o o t _ a r g s )
2014-11-22 00:50:41 +03:00
/ *
* Macro t o c r e a t e a t a b l e e n t r y t o t h e n e x t p a g e .
*
* tbl : page t a b l e a d d r e s s
* virt : virtual a d d r e s s
* shift : # imm p a g e t a b l e s h i f t
* ptrs : # imm p o i n t e r s p e r t a b l e p a g e
*
* Preserves : virt
* Corrupts : tmp1 , t m p2
* Returns : tbl - > n e x t l e v e l t a b l e p a g e a d d r e s s
* /
.macro create_ t a b l e _ e n t r y , t b l , v i r t , s h i f t , p t r s , t m p1 , t m p2
lsr \ t m p1 , \ v i r t , #\ s h i f t
and \ t m p1 , \ t m p1 , #\ p t r s - 1 / / t a b l e i n d e x
add \ t m p2 , \ t b l , #P A G E _ S I Z E
orr \ t m p2 , \ t m p2 , #P M D _ T Y P E _ T A B L E / / a d d r e s s o f n e x t t a b l e a n d e n t r y t y p e
str \ t m p2 , [ \ t b l , \ t m p1 , l s l #3 ]
add \ t b l , \ t b l , #P A G E _ S I Z E / / n e x t l e v e l t a b l e p a g e
.endm
/ *
* Macro t o p o p u l a t e t h e P G D ( a n d p o s s i b i l y P U D ) f o r t h e c o r r e s p o n d i n g
* block e n t r y i n t h e n e x t l e v e l ( t b l ) f o r t h e g i v e n v i r t u a l a d d r e s s .
*
* Preserves : tbl, n e x t , v i r t
* Corrupts : tmp1 , t m p2
* /
.macro create_ p g d _ e n t r y , t b l , v i r t , t m p1 , t m p2
create_ t a b l e _ e n t r y \ t b l , \ v i r t , P G D I R _ S H I F T , P T R S _ P E R _ P G D , \ t m p1 , \ t m p2
2015-10-19 16:19:31 +03:00
# if S W A P P E R _ P G T A B L E _ L E V E L S > 3
create_ t a b l e _ e n t r y \ t b l , \ v i r t , P U D _ S H I F T , P T R S _ P E R _ P U D , \ t m p1 , \ t m p2
# endif
# if S W A P P E R _ P G T A B L E _ L E V E L S > 2
2015-10-19 16:19:27 +03:00
create_ t a b l e _ e n t r y \ t b l , \ v i r t , S W A P P E R _ T A B L E _ S H I F T , P T R S _ P E R _ P T E , \ t m p1 , \ t m p2
2014-11-22 00:50:41 +03:00
# endif
.endm
/ *
* Macro t o p o p u l a t e b l o c k e n t r i e s i n t h e p a g e t a b l e f o r t h e s t a r t . . e n d
* virtual r a n g e ( i n c l u s i v e ) .
*
* Preserves : tbl, f l a g s
* Corrupts : phys, s t a r t , e n d , p s t a t e
* /
.macro create_ b l o c k _ m a p , t b l , f l a g s , p h y s , s t a r t , e n d
2015-10-19 16:19:27 +03:00
lsr \ p h y s , \ p h y s , #S W A P P E R _ B L O C K _ S H I F T
lsr \ s t a r t , \ s t a r t , #S W A P P E R _ B L O C K _ S H I F T
2014-11-22 00:50:41 +03:00
and \ s t a r t , \ s t a r t , #P T R S _ P E R _ P T E - 1 / / t a b l e i n d e x
2015-10-19 16:19:27 +03:00
orr \ p h y s , \ f l a g s , \ p h y s , l s l #S W A P P E R _ B L O C K _ S H I F T / / t a b l e e n t r y
lsr \ e n d , \ e n d , #S W A P P E R _ B L O C K _ S H I F T
2014-11-22 00:50:41 +03:00
and \ e n d , \ e n d , #P T R S _ P E R _ P T E - 1 / / t a b l e e n d i n d e x
9999 : str \ p h y s , [ \ t b l , \ s t a r t , l s l #3 ] / / s t o r e t h e e n t r y
add \ s t a r t , \ s t a r t , #1 / / n e x t e n t r y
2015-10-19 16:19:27 +03:00
add \ p h y s , \ p h y s , #S W A P P E R _ B L O C K _ S I Z E / / n e x t b l o c k
2014-11-22 00:50:41 +03:00
cmp \ s t a r t , \ e n d
b. l s 9 9 9 9 b
.endm
/ *
* Setup t h e i n i t i a l p a g e t a b l e s . W e o n l y s e t u p t h e b a r e s t a m o u n t w h i c h i s
* required t o g e t t h e k e r n e l r u n n i n g . T h e f o l l o w i n g s e c t i o n s a r e r e q u i r e d :
* - identity m a p p i n g t o e n a b l e t h e M M U ( l o w a d d r e s s , T T B R 0 )
* - first f e w M B o f t h e k e r n e l l i n e a r m a p p i n g t o j u m p t o o n c e t h e M M U h a s
2015-06-01 14:40:32 +03:00
* been e n a b l e d
2014-11-22 00:50:41 +03:00
* /
__create_page_tables :
2015-03-17 11:14:29 +03:00
adrp x25 , i d m a p _ p g _ d i r
adrp x26 , s w a p p e r _ p g _ d i r
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
mov x28 , l r
2014-11-22 00:50:41 +03:00
/ *
* Invalidate t h e i d m a p a n d s w a p p e r p a g e t a b l e s t o a v o i d p o t e n t i a l
* dirty c a c h e l i n e s b e i n g e v i c t e d .
* /
mov x0 , x25
add x1 , x26 , #S W A P P E R _ D I R _ S I Z E
bl _ _ i n v a l _ c a c h e _ r a n g e
/ *
* Clear t h e i d m a p a n d s w a p p e r p a g e t a b l e s .
* /
mov x0 , x25
add x6 , x26 , #S W A P P E R _ D I R _ S I Z E
1 : stp x z r , x z r , [ x0 ] , #16
stp x z r , x z r , [ x0 ] , #16
stp x z r , x z r , [ x0 ] , #16
stp x z r , x z r , [ x0 ] , #16
cmp x0 , x6
b. l o 1 b
2015-10-19 16:19:27 +03:00
ldr x7 , =SWAPPER_MM_MMUFLAGS
2014-11-22 00:50:41 +03:00
/ *
* Create t h e i d e n t i t y m a p p i n g .
* /
mov x0 , x25 / / i d m a p _ p g _ d i r
2015-06-01 14:40:33 +03:00
adrp x3 , _ _ i d m a p _ t e x t _ s t a r t / / _ _ p a ( _ _ i d m a p _ t e x t _ s t a r t )
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
# ifndef C O N F I G _ A R M 6 4 _ V A _ B I T S _ 4 8
# define E X T R A _ S H I F T ( P G D I R _ S H I F T + P A G E _ S H I F T - 3 )
# define E X T R A _ P T R S ( 1 < < ( 4 8 - E X T R A _ S H I F T ) )
/ *
* If V A _ B I T S < 4 8 , i t m a y b e t o o s m a l l t o a l l o w f o r a n I D m a p p i n g t o b e
* created t h a t c o v e r s s y s t e m R A M i f t h a t i s l o c a t e d s u f f i c i e n t l y h i g h
* in t h e p h y s i c a l a d d r e s s s p a c e . S o f o r t h e I D m a p , u s e a n e x t e n d e d
* virtual r a n g e i n t h a t c a s e , b y c o n f i g u r i n g a n a d d i t i o n a l t r a n s l a t i o n
* level.
* First, w e h a v e t o v e r i f y o u r a s s u m p t i o n t h a t t h e c u r r e n t v a l u e o f
* VA_ B I T S w a s c h o s e n s u c h t h a t a l l t r a n s l a t i o n l e v e l s a r e f u l l y
* utilised, a n d t h a t l o w e r i n g T 0 S Z w i l l a l w a y s r e s u l t i n a n a d d i t i o n a l
* translation l e v e l t o b e c o n f i g u r e d .
* /
# if V A _ B I T S ! = E X T R A _ S H I F T
# error " M i s m a t c h b e t w e e n V A _ B I T S a n d p a g e s i z e / n u m b e r o f t r a n s l a t i o n l e v e l s "
# endif
/ *
* Calculate t h e m a x i m u m a l l o w e d v a l u e f o r T C R _ E L 1 . T 0 S Z s o t h a t t h e
2015-06-01 14:40:33 +03:00
* entire I D m a p r e g i o n c a n b e m a p p e d . A s T 0 S Z = = ( 6 4 - #b i t s u s e d ) ,
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
* this n u m b e r c o n v e n i e n t l y e q u a l s t h e n u m b e r o f l e a d i n g z e r o e s i n
2015-06-01 14:40:33 +03:00
* the p h y s i c a l a d d r e s s o f _ _ i d m a p _ t e x t _ e n d .
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
* /
2015-06-01 14:40:33 +03:00
adrp x5 , _ _ i d m a p _ t e x t _ e n d
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
clz x5 , x5
cmp x5 , T C R _ T 0 S Z ( V A _ B I T S ) / / d e f a u l t T 0 S Z s m a l l e n o u g h ?
b. g e 1 f / / . . t h e n s k i p a d d i t i o n a l l e v e l
2015-03-24 18:10:21 +03:00
adr_ l x6 , i d m a p _ t 0 s z
str x5 , [ x6 ]
dmb s y
dc i v a c , x6 / / I n v a l i d a t e p o t e n t i a l l y s t a l e c a c h e l i n e
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
create_ t a b l e _ e n t r y x0 , x3 , E X T R A _ S H I F T , E X T R A _ P T R S , x5 , x6
1 :
# endif
2014-11-22 00:50:41 +03:00
create_ p g d _ e n t r y x0 , x3 , x5 , x6
2015-06-01 14:40:33 +03:00
mov x5 , x3 / / _ _ p a ( _ _ i d m a p _ t e x t _ s t a r t )
adr_ l x6 , _ _ i d m a p _ t e x t _ e n d / / _ _ p a ( _ _ i d m a p _ t e x t _ e n d )
2014-11-22 00:50:41 +03:00
create_ b l o c k _ m a p x0 , x7 , x3 , x5 , x6
/ *
* Map t h e k e r n e l i m a g e ( s t a r t i n g w i t h P H Y S _ O F F S E T ) .
* /
mov x0 , x26 / / s w a p p e r _ p g _ d i r
2016-02-16 15:52:36 +03:00
ldr x5 , =KIMAGE_VADDR
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
add x5 , x5 , x23 / / a d d K A S L R d i s p l a c e m e n t
2014-11-22 00:50:41 +03:00
create_ p g d _ e n t r y x0 , x5 , x3 , x6
2015-12-26 14:46:40 +03:00
ldr w6 , k e r n e l _ i m g _ s i z e
add x6 , x6 , x5
2014-11-22 00:50:41 +03:00
mov x3 , x24 / / p h y s o f f s e t
create_ b l o c k _ m a p x0 , x7 , x3 , x5 , x6
/ *
* Since t h e p a g e t a b l e s h a v e b e e n p o p u l a t e d w i t h n o n - c a c h e a b l e
* accesses ( M M U d i s a b l e d ) , i n v a l i d a t e t h e i d m a p a n d s w a p p e r p a g e
* tables a g a i n t o r e m o v e a n y s p e c u l a t i v e l y l o a d e d c a c h e l i n e s .
* /
mov x0 , x25
add x1 , x26 , #S W A P P E R _ D I R _ S I Z E
2015-03-24 16:50:27 +03:00
dmb s y
2014-11-22 00:50:41 +03:00
bl _ _ i n v a l _ c a c h e _ r a n g e
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
ret x28
2014-11-22 00:50:41 +03:00
ENDPROC( _ _ c r e a t e _ p a g e _ t a b l e s )
2015-12-26 14:46:40 +03:00
kernel_img_size :
.long _end - ( _ head - T E X T _ O F F S E T )
2014-11-22 00:50:41 +03:00
.ltorg
/ *
2015-03-04 13:51:48 +03:00
* The f o l l o w i n g f r a g m e n t o f c o d e i s e x e c u t e d w i t h t h e M M U e n a b l e d .
2014-11-22 00:50:41 +03:00
* /
2015-03-04 13:51:48 +03:00
.set initial_ s p , i n i t _ t h r e a d _ u n i o n + T H R E A D _ S T A R T _ S P
2014-11-22 00:50:41 +03:00
__mmap_switched :
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
mov x28 , l r / / p r e s e r v e L R
2015-12-26 14:46:40 +03:00
adr_ l x8 , v e c t o r s / / l o a d V B A R _ E L 1 w i t h v i r t u a l
msr v b a r _ e l 1 , x8 / / v e c t o r t a b l e a d d r e s s
isb
2016-01-06 14:05:27 +03:00
/ / Clear B S S
adr_ l x0 , _ _ b s s _ s t a r t
mov x1 , x z r
adr_ l x2 , _ _ b s s _ s t o p
sub x2 , x2 , x0
bl _ _ p i _ m e m s e t
arm64: mm: place empty_zero_page in bss
Currently the zero page is set up in paging_init, and thus we cannot use
the zero page earlier. We use the zero page as a reserved TTBR value
from which no TLB entries may be allocated (e.g. when uninstalling the
idmap). To enable such usage earlier (as may be required for invasive
changes to the kernel page tables), and to minimise the time that the
idmap is active, we need to be able to use the zero page before
paging_init.
This patch follows the example set by x86, by allocating the zero page
at compile time, in .bss. This means that the zero page itself is
available immediately upon entry to start_kernel (as we zero .bss before
this), and also means that the zero page takes up no space in the raw
Image binary. The associated struct page is allocated in bootmem_init,
and remains unavailable until this time.
Outside of arch code, the only users of empty_zero_page assume that the
empty_zero_page symbol refers to the zeroed memory itself, and that
ZERO_PAGE(x) must be used to acquire the associated struct page,
following the example of x86. This patch also brings arm64 inline with
these assumptions.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Jeremy Linton <jeremy.linton@arm.com>
Cc: Laura Abbott <labbott@fedoraproject.org>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-25 14:44:57 +03:00
dsb i s h s t / / M a k e z e r o p a g e v i s i b l e t o P T W
2016-01-06 14:05:27 +03:00
2016-01-26 11:13:44 +03:00
# ifdef C O N F I G _ R E L O C A T A B L E
/ *
* Iterate o v e r e a c h e n t r y i n t h e r e l o c a t i o n t a b l e , a n d a p p l y t h e
* relocations i n p l a c e .
* /
adr_ l x8 , _ _ d y n s y m _ s t a r t / / s t a r t o f s y m b o l t a b l e
adr_ l x9 , _ _ r e l o c _ s t a r t / / s t a r t o f r e l o c t a b l e
adr_ l x10 , _ _ r e l o c _ e n d / / e n d o f r e l o c t a b l e
0 : cmp x9 , x10
b. h s 2 f
ldp x11 , x12 , [ x9 ] , #24
ldr x13 , [ x9 , #- 8 ]
cmp w12 , #R _ A A R C H 64 _ R E L A T I V E
b. n e 1 f
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
add x13 , x13 , x23 / / r e l o c a t e
str x13 , [ x11 , x23 ]
2016-01-26 11:13:44 +03:00
b 0 b
1 : cmp w12 , #R _ A A R C H 64 _ A B S 6 4
b. n e 0 b
add x12 , x12 , x12 , l s l #1 / / s y m t a b o f f s e t : 2 4 x t o p w o r d
add x12 , x8 , x12 , l s r #( 32 - 3 ) / / . . . s h i f t e d i n t o b o t t o m w o r d
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
ldrsh w14 , [ x12 , #6 ] / / E l f64 _ S y m : : s t _ s h n d x
2016-01-26 11:13:44 +03:00
ldr x15 , [ x12 , #8 ] / / E l f64 _ S y m : : s t _ v a l u e
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
cmp w14 , #- 0xf / / S H N _ A B S ( 0 x f f f1 ) ?
add x14 , x15 , x23 / / r e l o c a t e
csel x15 , x14 , x15 , n e
2016-01-26 11:13:44 +03:00
add x15 , x13 , x15
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
str x15 , [ x11 , x23 ]
2016-01-26 11:13:44 +03:00
b 0 b
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
2 : adr_ l x8 , k i m a g e _ v a d d r / / m a k e r e l o c a t e d k i m a g e _ v a d d r
dc c v a c , x8 / / v a l u e v i s i b l e t o s e c o n d a r i e s
dsb s y / / w i t h M M U o f f
2016-01-26 11:13:44 +03:00
# endif
2015-03-04 13:51:48 +03:00
adr_ l s p , i n i t i a l _ s p , x4
2015-12-04 14:02:25 +03:00
mov x4 , s p
and x4 , x4 , #~ ( T H R E A D _ S I Z E - 1 )
msr s p _ e l 0 , x4 / / S a v e t h r e a d _ i n f o
2015-03-04 13:51:48 +03:00
str_ l x21 , _ _ f d t _ p o i n t e r , x5 / / S a v e F D T p o i n t e r
2016-02-16 15:52:42 +03:00
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
ldr_ l x4 , k i m a g e _ v a d d r / / S a v e t h e o f f s e t b e t w e e n
2016-02-16 15:52:42 +03:00
sub x4 , x4 , x24 / / t h e k e r n e l v i r t u a l a n d
str_ l x4 , k i m a g e _ v o f f s e t , x5 / / p h y s i c a l m a p p i n g s
2014-11-22 00:50:41 +03:00
mov x29 , #0
2015-10-12 18:52:58 +03:00
# ifdef C O N F I G _ K A S A N
bl k a s a n _ e a r l y _ i n i t
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
# endif
# ifdef C O N F I G _ R A N D O M I Z E _ B A S E
cbnz x23 , 0 f / / a l r e a d y r u n n i n g r a n d o m i z e d ?
mov x0 , x21 / / p a s s F D T a d d r e s s i n x0
bl k a s l r _ e a r l y _ i n i t / / p a r s e F D T f o r K A S L R o p t i o n s
cbz x0 , 0 f / / K A S L R d i s a b l e d ? j u s t p r o c e e d
mov x23 , x0 / / r e c o r d K A S L R o f f s e t
ret x28 / / w e m u s t e n a b l e K A S L R , r e t u r n
/ / to _ _ e n a b l e _ m m u ( )
0 :
2015-10-12 18:52:58 +03:00
# endif
2014-11-22 00:50:41 +03:00
b s t a r t _ k e r n e l
ENDPROC( _ _ m m a p _ s w i t c h e d )
/ *
* end e a r l y h e a d s e c t i o n , b e g i n h e a d c o d e t h a t i s a l s o u s e d f o r
* hotplug a n d n e e d s t o h a v e t h e s a m e p r o t e c t i o n s a s t h e t e x t r e g i o n
* /
.section " .text " , " ax"
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
ENTRY( k i m a g e _ v a d d r )
.quad _text - TEXT_ O F F S E T
2012-03-05 15:49:27 +04:00
/ *
* If w e ' r e f o r t u n a t e e n o u g h t o b o o t a t E L 2 , e n s u r e t h a t t h e w o r l d i s
* sane b e f o r e d r o p p i n g t o E L 1 .
2013-10-11 17:52:16 +04:00
*
* Returns e i t h e r B O O T _ C P U _ M O D E _ E L 1 o r B O O T _ C P U _ M O D E _ E L 2 i n x20 i f
* booted i n E L 1 o r E L 2 r e s p e c t i v e l y .
2012-03-05 15:49:27 +04:00
* /
ENTRY( e l 2 _ s e t u p )
mrs x0 , C u r r e n t E L
2014-06-06 17:16:21 +04:00
cmp x0 , #C u r r e n t E L _ E L 2
2013-10-11 17:52:17 +04:00
b. n e 1 f
mrs x0 , s c t l r _ e l 2
CPU_ B E ( o r r x0 , x0 , #( 1 < < 2 5 ) ) / / S e t t h e E E b i t f o r E L 2
CPU_ L E ( b i c x0 , x0 , #( 1 < < 2 5 ) ) / / C l e a r t h e E E b i t f o r E L 2
msr s c t l r _ e l 2 , x0
b 2 f
1 : mrs x0 , s c t l r _ e l 1
CPU_ B E ( o r r x0 , x0 , #( 3 < < 2 4 ) ) / / S e t t h e E E a n d E 0 E b i t s f o r E L 1
CPU_ L E ( b i c x0 , x0 , #( 3 < < 2 4 ) ) / / C l e a r t h e E E a n d E 0 E b i t s f o r E L 1
msr s c t l r _ e l 1 , x0
2013-10-11 17:52:16 +04:00
mov w20 , #B O O T _ C P U _ M O D E _ E L 1 / / T h i s c p u b o o t e d i n E L 1
2013-10-11 17:52:17 +04:00
isb
2012-03-05 15:49:27 +04:00
ret
/* Hyp configuration. */
2013-10-11 17:52:17 +04:00
2 : mov x0 , #( 1 < < 3 1 ) / / 6 4 - b i t E L 1
2012-03-05 15:49:27 +04:00
msr h c r _ e l 2 , x0
/* Generic timers. */
mrs x0 , c n t h c t l _ e l 2
orr x0 , x0 , #3 / / E n a b l e E L 1 p h y s i c a l t i m e r s
msr c n t h c t l _ e l 2 , x0
2012-11-30 02:48:31 +04:00
msr c n t v o f f _ e l 2 , x z r / / C l e a r v i r t u a l o f f s e t
2012-03-05 15:49:27 +04:00
2014-06-30 19:01:31 +04:00
# ifdef C O N F I G _ A R M _ G I C _ V 3
/* GICv3 system register access */
mrs x0 , i d _ a a64 p f r0 _ e l 1
ubfx x0 , x0 , #24 , #4
cmp x0 , #1
b. n e 3 f
2014-07-24 17:14:42 +04:00
mrs_ s x0 , I C C _ S R E _ E L 2
2014-06-30 19:01:31 +04:00
orr x0 , x0 , #I C C _ S R E _ E L 2 _ S R E / / S e t I C C _ S R E _ E L 2 . S R E = =1
orr x0 , x0 , #I C C _ S R E _ E L 2 _ E N A B L E / / S e t I C C _ S R E _ E L 2 . E n a b l e = =1
2014-07-24 17:14:42 +04:00
msr_ s I C C _ S R E _ E L 2 , x0
2014-06-30 19:01:31 +04:00
isb / / M a k e s u r e S R E i s n o w s e t
2015-09-30 13:39:59 +03:00
mrs_ s x0 , I C C _ S R E _ E L 2 / / R e a d S R E b a c k ,
tbz x0 , #0 , 3 f / / a n d c h e c k t h a t i t s t i c k s
2014-07-24 17:14:42 +04:00
msr_ s I C H _ H C R _ E L 2 , x z r / / R e s e t I C C _ H C R _ E L 2 t o d e f a u l t s
2014-06-30 19:01:31 +04:00
3 :
# endif
2012-03-05 15:49:27 +04:00
/* Populate ID registers. */
mrs x0 , m i d r _ e l 1
mrs x1 , m p i d r _ e l 1
msr v p i d r _ e l 2 , x0
msr v m p i d r _ e l 2 , x1
/* sctlr_el1 */
mov x0 , #0x0800 / / S e t / c l e a r R E S { 1 ,0 } b i t s
2013-10-11 17:52:17 +04:00
CPU_ B E ( m o v k x0 , #0x33d0 , l s l #16 ) / / S e t E E a n d E 0 E o n B E s y s t e m s
CPU_ L E ( m o v k x0 , #0x30d0 , l s l #16 ) / / C l e a r E E a n d E 0 E o n L E s y s t e m s
2012-03-05 15:49:27 +04:00
msr s c t l r _ e l 1 , x0
/* Coprocessor traps. */
mov x0 , #0x33ff
msr c p t r _ e l 2 , x0 / / D i s a b l e c o p r o . t r a p s t o E L 2
# ifdef C O N F I G _ C O M P A T
msr h s t r _ e l 2 , x z r / / D i s a b l e C P 1 5 t r a p s t o E L 2
# endif
2015-09-02 20:49:28 +03:00
/* EL2 debug */
2016-01-13 17:50:03 +03:00
mrs x0 , i d _ a a64 d f r0 _ e l 1 / / C h e c k I D _ A A 6 4 D F R 0 _ E L 1 P M U V e r
sbfx x0 , x0 , #8 , #4
cmp x0 , #1
b. l t 4 f / / S k i p i f n o P M U p r e s e n t
2015-09-02 20:49:28 +03:00
mrs x0 , p m c r _ e l 0 / / D i s a b l e d e b u g a c c e s s t r a p s
ubfx x0 , x0 , #11 , #5 / / t o E L 2 a n d a l l o w a c c e s s t o
msr m d c r _ e l 2 , x0 / / a l l P M U c o u n t e r s f r o m E L 1
2016-01-13 17:50:03 +03:00
4 :
2015-09-02 20:49:28 +03:00
2012-11-06 23:27:59 +04:00
/* Stage-2 translation */
msr v t t b r _ e l 2 , x z r
2012-10-19 20:46:27 +04:00
/* Hypervisor stub */
2014-11-22 00:50:39 +03:00
adrp x0 , _ _ h y p _ s t u b _ v e c t o r s
add x0 , x0 , #: l o 12 : _ _ h y p _ s t u b _ v e c t o r s
2012-10-19 20:46:27 +04:00
msr v b a r _ e l 2 , x0
2012-03-05 15:49:27 +04:00
/* spsr */
mov x0 , #( P S R _ F _ B I T | P S R _ I _ B I T | P S R _ A _ B I T | P S R _ D _ B I T | \
PSR_ M O D E _ E L 1 h )
msr s p s r _ e l 2 , x0
msr e l r _ e l 2 , l r
2013-10-11 17:52:16 +04:00
mov w20 , #B O O T _ C P U _ M O D E _ E L 2 / / T h i s C P U b o o t e d i n E L 2
2012-03-05 15:49:27 +04:00
eret
ENDPROC( e l 2 _ s e t u p )
2013-10-11 17:52:16 +04:00
/ *
* Sets t h e _ _ b o o t _ c p u _ m o d e f l a g d e p e n d i n g o n t h e C P U b o o t m o d e p a s s e d
* in x20 . S e e a r c h / a r m 6 4 / i n c l u d e / a s m / v i r t . h f o r m o r e i n f o .
* /
ENTRY( s e t _ c p u _ b o o t _ m o d e _ f l a g )
2015-03-17 11:14:29 +03:00
adr_ l x1 , _ _ b o o t _ c p u _ m o d e
2013-10-11 17:52:16 +04:00
cmp w20 , #B O O T _ C P U _ M O D E _ E L 2
b. n e 1 f
add x1 , x1 , #4
2014-05-02 19:24:13 +04:00
1 : str w20 , [ x1 ] / / T h i s C P U h a s b o o t e d i n E L 1
dmb s y
dc i v a c , x1 / / I n v a l i d a t e p o t e n t i a l l y s t a l e c a c h e l i n e
2013-10-11 17:52:16 +04:00
ret
ENDPROC( s e t _ c p u _ b o o t _ m o d e _ f l a g )
2012-10-26 18:40:05 +04:00
/ *
* We n e e d t o f i n d o u t t h e C P U b o o t m o d e l o n g a f t e r b o o t , s o w e n e e d t o
* store i t i n a w r i t a b l e v a r i a b l e .
*
* This i s n o t i n . b s s , b e c a u s e w e s e t i t s u f f i c i e n t l y e a r l y t h a t t h e b o o t - t i m e
* zeroing o f . b s s w o u l d c l o b b e r i t .
* /
2014-03-26 22:25:55 +04:00
.pushsection .data . .cacheline_aligned
.align L1_CACHE_SHIFT
2015-03-13 18:21:18 +03:00
ENTRY( _ _ b o o t _ c p u _ m o d e )
2012-10-26 18:40:05 +04:00
.long BOOT_CPU_MODE_EL2
2015-03-13 19:14:36 +03:00
.long BOOT_CPU_MODE_EL1
2012-10-26 18:40:05 +04:00
.popsection
2012-03-05 15:49:27 +04:00
/ *
* This p r o v i d e s a " h o l d i n g p e n " f o r p l a t f o r m s t o h o l d a l l s e c o n d a r y
* cores a r e h e l d u n t i l w e ' r e r e a d y f o r t h e m t o i n i t i a l i s e .
* /
ENTRY( s e c o n d a r y _ h o l d i n g _ p e n )
2013-10-11 17:52:16 +04:00
bl e l 2 _ s e t u p / / D r o p t o E L 1 , w20 =cpu_boot_mode
bl s e t _ c p u _ b o o t _ m o d e _ f l a g
2012-03-05 15:49:27 +04:00
mrs x0 , m p i d r _ e l 1
2012-08-29 21:32:18 +04:00
ldr x1 , =MPIDR_HWID_BITMASK
and x0 , x0 , x1
2015-03-10 17:00:03 +03:00
adr_ l x3 , s e c o n d a r y _ h o l d i n g _ p e n _ r e l e a s e
2012-03-05 15:49:27 +04:00
pen : ldr x4 , [ x3 ]
cmp x4 , x0
b. e q s e c o n d a r y _ s t a r t u p
wfe
b p e n
ENDPROC( s e c o n d a r y _ h o l d i n g _ p e n )
arm64: factor out spin-table boot method
The arm64 kernel has an internal holding pen, which is necessary for
some systems where we can't bring CPUs online individually and must hold
multiple CPUs in a safe area until the kernel is able to handle them.
The current SMP infrastructure for arm64 is closely coupled to this
holding pen, and alternative boot methods must launch CPUs into the pen,
where they sit before they are launched into the kernel proper.
With PSCI (and possibly other future boot methods), we can bring CPUs
online individually, and need not perform the secondary_holding_pen
dance. Instead, this patch factors the holding pen management code out
to the spin-table boot method code, as it is the only boot method
requiring the pen.
A new entry point for secondaries, secondary_entry is added for other
boot methods to use, which bypasses the holding pen and its associated
overhead when bringing CPUs online. The smp.pen.text section is also
removed, as the pen can live in head.text without problem.
The cpu_operations structure is extended with two new functions,
cpu_boot and cpu_postboot, for bringing a cpu into the kernel and
performing any post-boot cleanup required by a bootmethod (e.g.
resetting the secondary_holding_pen_release to INVALID_HWID).
Documentation is added for cpu_operations.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2013-10-24 23:30:16 +04:00
/ *
* Secondary e n t r y p o i n t t h a t j u m p s s t r a i g h t i n t o t h e k e r n e l . O n l y t o
* be u s e d w h e r e C P U s a r e b r o u g h t o n l i n e d y n a m i c a l l y b y t h e k e r n e l .
* /
ENTRY( s e c o n d a r y _ e n t r y )
bl e l 2 _ s e t u p / / D r o p t o E L 1
2013-11-18 22:56:42 +04:00
bl s e t _ c p u _ b o o t _ m o d e _ f l a g
arm64: factor out spin-table boot method
The arm64 kernel has an internal holding pen, which is necessary for
some systems where we can't bring CPUs online individually and must hold
multiple CPUs in a safe area until the kernel is able to handle them.
The current SMP infrastructure for arm64 is closely coupled to this
holding pen, and alternative boot methods must launch CPUs into the pen,
where they sit before they are launched into the kernel proper.
With PSCI (and possibly other future boot methods), we can bring CPUs
online individually, and need not perform the secondary_holding_pen
dance. Instead, this patch factors the holding pen management code out
to the spin-table boot method code, as it is the only boot method
requiring the pen.
A new entry point for secondaries, secondary_entry is added for other
boot methods to use, which bypasses the holding pen and its associated
overhead when bringing CPUs online. The smp.pen.text section is also
removed, as the pen can live in head.text without problem.
The cpu_operations structure is extended with two new functions,
cpu_boot and cpu_postboot, for bringing a cpu into the kernel and
performing any post-boot cleanup required by a bootmethod (e.g.
resetting the secondary_holding_pen_release to INVALID_HWID).
Documentation is added for cpu_operations.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2013-10-24 23:30:16 +04:00
b s e c o n d a r y _ s t a r t u p
ENDPROC( s e c o n d a r y _ e n t r y )
2012-03-05 15:49:27 +04:00
ENTRY( s e c o n d a r y _ s t a r t u p )
/ *
* Common e n t r y p o i n t f o r s e c o n d a r y C P U s .
* /
2015-03-17 11:14:29 +03:00
adrp x25 , i d m a p _ p g _ d i r
adrp x26 , s w a p p e r _ p g _ d i r
2015-03-18 17:55:20 +03:00
bl _ _ c p u _ s e t u p / / i n i t i a l i s e p r o c e s s o r
2012-03-05 15:49:27 +04:00
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
ldr x8 , k i m a g e _ v a d d r
2015-12-26 14:46:40 +03:00
ldr w9 , 0 f
sub x27 , x8 , w9 , s x t w / / a d d r e s s t o j u m p t o a f t e r e n a b l i n g t h e M M U
2012-03-05 15:49:27 +04:00
b _ _ e n a b l e _ m m u
ENDPROC( s e c o n d a r y _ s t a r t u p )
2015-12-26 14:46:40 +03:00
0 : .long ( _ t e x t - T E X T _ O F F S E T ) - _ _ s e c o n d a r y _ s w i t c h e d
2012-03-05 15:49:27 +04:00
ENTRY( _ _ s e c o n d a r y _ s w i t c h e d )
2015-12-26 14:46:40 +03:00
adr_ l x5 , v e c t o r s
msr v b a r _ e l 1 , x5
isb
ldr_ l x0 , s e c o n d a r y _ d a t a / / g e t s e c o n d a r y _ d a t a . s t a c k
2012-03-05 15:49:27 +04:00
mov s p , x0
2015-12-04 14:02:25 +03:00
and x0 , x0 , #~ ( T H R E A D _ S I Z E - 1 )
msr s p _ e l 0 , x0 / / s a v e t h r e a d _ i n f o
2012-03-05 15:49:27 +04:00
mov x29 , #0
b s e c o n d a r y _ s t a r t _ k e r n e l
ENDPROC( _ _ s e c o n d a r y _ s w i t c h e d )
/ *
2015-03-17 10:59:53 +03:00
* Enable t h e M M U .
2012-03-05 15:49:27 +04:00
*
2015-03-17 10:59:53 +03:00
* x0 = S C T L R _ E L 1 v a l u e f o r t u r n i n g o n t h e M M U .
* x2 7 = * v i r t u a l * a d d r e s s t o j u m p t o u p o n c o m p l e t i o n
*
2015-10-19 16:19:35 +03:00
* Other r e g i s t e r s d e p e n d o n t h e f u n c t i o n c a l l e d u p o n c o m p l e t i o n .
*
* Checks i f t h e s e l e c t e d g r a n u l e s i z e i s s u p p o r t e d b y t h e C P U .
* If i t i s n ' t , p a r k t h e C P U
2012-03-05 15:49:27 +04:00
* /
2015-06-01 14:40:33 +03:00
.section " .idmap .text " , " ax"
2012-03-05 15:49:27 +04:00
__enable_mmu :
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
mrs x18 , s c t l r _ e l 1 / / p r e s e r v e o l d S C T L R _ E L 1 v a l u e
2015-10-19 16:19:35 +03:00
mrs x1 , I D _ A A 6 4 M M F R 0 _ E L 1
ubfx x2 , x1 , #I D _ A A 64 M M F R 0 _ T G R A N _ S H I F T , 4
cmp x2 , #I D _ A A 64 M M F R 0 _ T G R A N _ S U P P O R T E D
b. n e _ _ n o _ g r a n u l e _ s u p p o r t
2012-03-05 15:49:27 +04:00
msr t t b r0 _ e l 1 , x25 / / l o a d T T B R 0
msr t t b r1 _ e l 1 , x26 / / l o a d T T B R 1
isb
msr s c t l r _ e l 1 , x0
isb
2015-08-04 19:49:36 +03:00
/ *
* Invalidate t h e l o c a l I - c a c h e s o t h a t a n y i n s t r u c t i o n s f e t c h e d
* speculatively f r o m t h e P o C a r e d i s c a r d e d , s i n c e t h e y m a y h a v e
* been d y n a m i c a l l y p a t c h e d a t t h e P o U .
* /
ic i a l l u
dsb n s h
isb
arm64: add support for kernel ASLR
This adds support for KASLR is implemented, based on entropy provided by
the bootloader in the /chosen/kaslr-seed DT property. Depending on the size
of the address space (VA_BITS) and the page size, the entropy in the
virtual displacement is up to 13 bits (16k/2 levels) and up to 25 bits (all
4 levels), with the sidenote that displacements that result in the kernel
image straddling a 1GB/32MB/512MB alignment boundary (for 4KB/16KB/64KB
granule kernels, respectively) are not allowed, and will be rounded up to
an acceptable value.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is enabled, the module region is
randomized independently from the core kernel. This makes it less likely
that the location of core kernel data structures can be determined by an
adversary, but causes all function calls from modules into the core kernel
to be resolved via entries in the module PLTs.
If CONFIG_RANDOMIZE_MODULE_REGION_FULL is not enabled, the module region is
randomized by choosing a page aligned 128 MB region inside the interval
[_etext - 128 MB, _stext + 128 MB). This gives between 10 and 14 bits of
entropy (depending on page size), independently of the kernel randomization,
but still guarantees that modules are within the range of relative branch
and jump instructions (with the caveat that, since the module region is
shared with other uses of the vmalloc area, modules may need to be loaded
further away if the module region is exhausted)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2016-01-26 16:12:01 +03:00
# ifdef C O N F I G _ R A N D O M I Z E _ B A S E
mov x19 , x0 / / p r e s e r v e n e w S C T L R _ E L 1 v a l u e
blr x27
/ *
* If w e r e t u r n h e r e , w e h a v e a K A S L R d i s p l a c e m e n t i n x23 w h i c h w e n e e d
* to t a k e i n t o a c c o u n t b y d i s c a r d i n g t h e c u r r e n t k e r n e l m a p p i n g a n d
* creating a n e w o n e .
* /
msr s c t l r _ e l 1 , x18 / / d i s a b l e t h e M M U
isb
bl _ _ c r e a t e _ p a g e _ t a b l e s / / r e c r e a t e k e r n e l m a p p i n g
msr s c t l r _ e l 1 , x19 / / r e - e n a b l e t h e M M U
isb
ic i a l l u i s / / f l u s h i n s t r u c t i o n s f e t c h e d
isb / / v i a o l d m a p p i n g
add x27 , x27 , x23 / / r e l o c a t e d _ _ m m a p _ s w i t c h e d
# endif
2012-03-05 15:49:27 +04:00
br x27
2015-03-17 10:59:53 +03:00
ENDPROC( _ _ e n a b l e _ m m u )
2015-10-19 16:19:35 +03:00
__no_granule_support :
wfe
b _ _ n o _ g r a n u l e _ s u p p o r t
ENDPROC( _ _ n o _ g r a n u l e _ s u p p o r t )