2013-01-18 13:42:19 +04:00
/ *
* TLB E x c e p t i o n H a n d l i n g f o r A R C
*
* Copyright ( C ) 2 0 0 4 , 2 0 0 7 - 2 0 1 0 , 2 0 1 1 - 2 0 1 2 S y n o p s y s , I n c . ( w w w . s y n o p s y s . c o m )
*
* 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 .
*
* Vineetg : April 2 0 1 1 :
* - MMU v1 : m o v e d o u t l e g a c y c o d e i n t o a s e p e r a t e f i l e
* - MMU v3 : P D { 0 ,1 } b i t s l a y o u t c h a n g e d : T h e y d o n ' t o v e r l a p a n y m o r e ,
* helps a v o i d a s h i f t w h e n p r e p a r i n g P D 0 f r o m P T E
*
* Vineetg : July 2 0 0 9
* - For M M U V 2 , w e n e e d n o t d o h e u r i s t i c s a t t h e t i m e o f c o m m i t i n g a D - T L B
* entry, s o t h a t i t d o e s n ' t k n o c k o u t i t ' s I - T L B e n t r y
* - Some m o r e f i n e t u n i n g :
* bmsk i n s t e a d o f a d d , a s l . c c i n s t e a d o f b r a n c h , d e l a y s l o t u t i l i s e e t c
*
* Vineetg : July 2 0 0 9
* - Practically r e w r o t e t h e I / D T L B M i s s h a n d l e r s
* Now 4 0 a n d 1 3 5 i n s t r u c t i o n s a p e i c e a s c o m p a r e d t o 1 3 1 a n d 4 4 9 r e s p .
* Hence L e a n e r b y 1 . 5 K
* Used C o n d i t i o n a l a r i t h m e t i c t o r e p l a c e e x c e s s i v e b r a n c h i n g
* Also u s e d s h o r t i n s t r u c t i o n s w h e r e v e r p o s s i b l e
*
* Vineetg : Aug 1 3 t h 2 0 0 8
* - Passing E C R ( E x c e p t i o n C a u s e R E G ) t o d o _ p a g e _ f a u l t ( ) f o r p r i n t i n g
* more i n f o r m a t i o n i n c a s e o f a F a t a l i t y
*
* Vineetg : March 2 5 t h B u g #92690
* - Added D e b u g C o d e t o c h e c k i f s w - A S I D = = h w - A S I D
* Rahul T r i v e d i , A m i t B h o r : C o d i t o T e c h n o l o g i e s 2 0 0 4
* /
.cpu A7
# include < l i n u x / l i n k a g e . h >
# include < a s m / e n t r y . h >
2013-05-14 11:58:17 +04:00
# include < a s m / m m u . h >
2013-01-18 13:42:19 +04:00
# include < a s m / p g t a b l e . h >
# include < a s m / a r c r e g s . h >
# include < a s m / c a c h e . h >
# include < a s m / p r o c e s s o r . h >
# include < a s m / t l b - m m u 1 . h >
2013-07-10 10:10:27 +04:00
;-----------------------------------------------------------------
; ARC700 Exception Handling doesn't auto-switch stack and it only provides
; ONE scratch AUX reg "ARC_REG_SCRATCH_DATA0"
;
; For Non-SMP, the scratch AUX reg is repurposed to cache task PGD, so a
; "global" is used to free-up FIRST core reg to be able to code the rest of
; exception prologue (IRQ auto-disabled on Exceptions, so it's IRQ-safe).
; Since the Fast Path TLB Miss handler is coded with 4 regs, the remaining 3
; need to be saved as well by extending the "global" to be 4 words. Hence
; ".size ex_saved_reg1, 16"
; [All of this dance is to avoid stack switching for each TLB Miss, since we
; only need to save only a handful of regs, as opposed to complete reg file]
;
; For ARC700 SMP, the "global" obviously can't be used for free up the FIRST
; core reg as it will not be SMP safe.
; Thus scratch AUX reg is used (and no longer used to cache task PGD).
; To save the rest of 3 regs - per cpu, the global is made "per-cpu".
; Epilogue thus has to locate the "per-cpu" storage for regs.
; To avoid cache line bouncing the per-cpu global is aligned/sized per
; L1_CACHE_SHIFT, despite fundamentally needing to be 12 bytes only. Hence
; ".size ex_saved_reg1, (CONFIG_NR_CPUS << L1_CACHE_SHIFT)"
; As simple as that....
2013-01-18 13:42:19 +04:00
;--------------------------------------------------------------------------
2013-07-10 10:10:27 +04:00
; scratch memory to save [r0-r3] used to code TLB refill Handler
2013-01-18 13:42:25 +04:00
ARCFP_ D A T A e x _ s a v e d _ r e g 1
2013-07-10 10:10:27 +04:00
.align 1 < < L1 _ C A C H E _ S H I F T
2013-01-18 13:42:19 +04:00
.type ex_ s a v e d _ r e g 1 , @object
2013-01-18 13:42:23 +04:00
# ifdef C O N F I G _ S M P
.size ex_ s a v e d _ r e g 1 , ( C O N F I G _ N R _ C P U S < < L 1 _ C A C H E _ S H I F T )
ex_saved_reg1 :
.zero ( CONFIG_ N R _ C P U S < < L 1 _ C A C H E _ S H I F T )
# else
2013-01-18 13:42:19 +04:00
.size ex_ s a v e d _ r e g 1 , 1 6
ex_saved_reg1 :
.zero 16
2013-01-18 13:42:23 +04:00
# endif
2013-01-18 13:42:19 +04:00
2013-07-10 10:10:27 +04:00
.macro TLBMISS_FREEUP_REGS
# ifdef C O N F I G _ S M P
sr r0 , [ A R C _ R E G _ S C R A T C H _ D A T A 0 ] ; freeup r0 to code with
GET_ C P U _ I D r0 ; get to per cpu scratch mem,
lsl r0 , r0 , L 1 _ C A C H E _ S H I F T ; cache line wide per cpu
add r0 , @ex_saved_reg1, r0
# else
st r0 , [ @ex_saved_reg1]
mov_ s r0 , @ex_saved_reg1
# endif
st_ s r1 , [ r0 , 4 ]
st_ s r2 , [ r0 , 8 ]
st_ s r3 , [ r0 , 1 2 ]
; VERIFY if the ASID in MMU-PID Reg is same as
; one in Linux data structures
2013-08-23 16:07:18 +04:00
tlb_ p a r a n o i d _ c h e c k _ a s m
2013-07-10 10:10:27 +04:00
.endm
.macro TLBMISS_RESTORE_REGS
# ifdef C O N F I G _ S M P
GET_ C P U _ I D r0 ; get to per cpu scratch mem
lsl r0 , r0 , L 1 _ C A C H E _ S H I F T ; each is cache line wide
add r0 , @ex_saved_reg1, r0
ld_ s r3 , [ r0 ,1 2 ]
ld_ s r2 , [ r0 , 8 ]
ld_ s r1 , [ r0 , 4 ]
lr r0 , [ A R C _ R E G _ S C R A T C H _ D A T A 0 ]
# else
mov_ s r0 , @ex_saved_reg1
ld_ s r3 , [ r0 ,1 2 ]
ld_ s r2 , [ r0 , 8 ]
ld_ s r1 , [ r0 , 4 ]
ld_ s r0 , [ r0 ]
# endif
.endm
2013-01-18 13:42:19 +04:00
;============================================================================
; Troubleshooting Stuff
;============================================================================
; Linux keeps ASID (Address Space ID) in task->active_mm->context.asid
; When Creating TLB Entries, instead of doing 3 dependent loads from memory,
; we use the MMU PID Reg to get current ASID.
; In bizzare scenrios SW and HW ASID can get out-of-sync which is trouble.
; So we try to detect this in TLB Mis shandler
2013-08-23 16:07:18 +04:00
.macro tlb_paranoid_check_asm
2013-01-18 13:42:19 +04:00
# ifdef C O N F I G _ A R C _ D B G _ T L B _ P A R A N O I A
GET_ C U R R _ T A S K _ O N _ C P U r3
ld r0 , [ r3 , T A S K _ A C T _ M M ]
ld r0 , [ r0 , M M _ C T X T + M M _ C T X T _ A S I D ]
ARC: [ASID] Track ASID allocation cycles/generations
This helps remove asid-to-mm reverse map
While mm->context.id contains the ASID assigned to a process, our ASID
allocator also used asid_mm_map[] reverse map. In a new allocation
cycle (mm->ASID >= @asid_cache), the Round Robin ASID allocator used this
to check if new @asid_cache belonged to some mm2 (from prev cycle).
If so, it could locate that mm using the ASID reverse map, and mark that
mm as unallocated ASID, to force it to refresh at the time of switch_mm()
However, for SMP, the reverse map has to be maintained per CPU, so
becomes 2 dimensional, hence got rid of it.
With reverse map gone, it is NOT possible to reach out to current
assignee. So we track the ASID allocation generation/cycle and
on every switch_mm(), check if the current generation of CPU ASID is
same as mm's ASID; If not it is refreshed.
(Based loosely on arch/sh implementation)
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-07-26 02:45:50 +04:00
breq r0 , 0 , 5 5 f ; Error if no ASID allocated
2013-01-18 13:42:19 +04:00
lr r1 , [ A R C _ R E G _ P I D ]
and r1 , r1 , 0 x F F
2013-08-23 16:07:18 +04:00
ARC: [ASID] Track ASID allocation cycles/generations
This helps remove asid-to-mm reverse map
While mm->context.id contains the ASID assigned to a process, our ASID
allocator also used asid_mm_map[] reverse map. In a new allocation
cycle (mm->ASID >= @asid_cache), the Round Robin ASID allocator used this
to check if new @asid_cache belonged to some mm2 (from prev cycle).
If so, it could locate that mm using the ASID reverse map, and mark that
mm as unallocated ASID, to force it to refresh at the time of switch_mm()
However, for SMP, the reverse map has to be maintained per CPU, so
becomes 2 dimensional, hence got rid of it.
With reverse map gone, it is NOT possible to reach out to current
assignee. So we track the ASID allocation generation/cycle and
on every switch_mm(), check if the current generation of CPU ASID is
same as mm's ASID; If not it is refreshed.
(Based loosely on arch/sh implementation)
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-07-26 02:45:50 +04:00
and r2 , r0 , 0 x F F ; MMU PID bits only for comparison
breq r1 , r2 , 5 f
2013-01-18 13:42:19 +04:00
ARC: [ASID] Track ASID allocation cycles/generations
This helps remove asid-to-mm reverse map
While mm->context.id contains the ASID assigned to a process, our ASID
allocator also used asid_mm_map[] reverse map. In a new allocation
cycle (mm->ASID >= @asid_cache), the Round Robin ASID allocator used this
to check if new @asid_cache belonged to some mm2 (from prev cycle).
If so, it could locate that mm using the ASID reverse map, and mark that
mm as unallocated ASID, to force it to refresh at the time of switch_mm()
However, for SMP, the reverse map has to be maintained per CPU, so
becomes 2 dimensional, hence got rid of it.
With reverse map gone, it is NOT possible to reach out to current
assignee. So we track the ASID allocation generation/cycle and
on every switch_mm(), check if the current generation of CPU ASID is
same as mm's ASID; If not it is refreshed.
(Based loosely on arch/sh implementation)
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-07-26 02:45:50 +04:00
55 :
2013-01-18 13:42:19 +04:00
; Error if H/w and S/w ASID don't match, but NOT if in kernel mode
2013-08-23 16:07:18 +04:00
lr r2 , [ e r s t a t u s ]
bbit0 r2 , S T A T U S _ U _ B I T , 5 f
2013-01-18 13:42:19 +04:00
; We sure are in troubled waters, Flag the error, but to do so
; need to switch to kernel mode stack to call error routine
GET_ T S K _ S T A C K _ B A S E r3 , s p
; Call printk to shoutout aloud
2013-08-23 16:07:18 +04:00
mov r2 , 1
2013-01-18 13:42:19 +04:00
j p r i n t _ a s i d _ m i s m a t c h
2013-08-23 16:07:18 +04:00
5 : ; ASIDs match so proceed normally
2013-01-18 13:42:19 +04:00
nop
# endif
.endm
;============================================================================
;TLB Miss handling Code
;============================================================================
;-----------------------------------------------------------------------------
; This macro does the page-table lookup for the faulting address.
; OUT: r0 = PTE faulted on, r1 = ptr to PTE, r2 = Faulting V-address
.macro LOAD_FAULT_PTE
lr r2 , [ e f a ]
2013-01-18 13:42:23 +04:00
# ifndef C O N F I G _ S M P
2013-01-18 13:42:19 +04:00
lr r1 , [ A R C _ R E G _ S C R A T C H _ D A T A 0 ] ; current pgd
2013-01-18 13:42:23 +04:00
# else
GET_ C U R R _ T A S K _ O N _ C P U r1
ld r1 , [ r1 , T A S K _ A C T _ M M ]
ld r1 , [ r1 , M M _ P G D ]
# endif
2013-01-18 13:42:19 +04:00
lsr r0 , r2 , P G D I R _ S H I F T ; Bits for indexing into PGD
ld. a s r1 , [ r1 , r0 ] ; PGD entry corresp to faulting addr
and. f r1 , r1 , P A G E _ M A S K ; Ignoring protection and other flags
; contains Ptr to Page Table
bz. d d o _ s l o w _ p a t h _ p f ; if no Page Table, do page fault
; Get the PTE entry: The idea is
; (1) x = addr >> PAGE_SHIFT -> masks page-off bits from @fault-addr
; (2) y = x & (PTRS_PER_PTE - 1) -> to get index
; (3) z = pgtbl[y]
; To avoid the multiply by in end, we do the -2, <<2 below
lsr r0 , r2 , ( P A G E _ S H I F T - 2 )
and r0 , r0 , ( ( P T R S _ P E R _ P T E - 1 ) < < 2 )
ld. a w r0 , [ r1 , r0 ] ; get PTE and PTE ptr for fault addr
2013-01-18 13:42:23 +04:00
# ifdef C O N F I G _ A R C _ D B G _ T L B _ M I S S _ C O U N T
and. f 0 , r0 , _ P A G E _ P R E S E N T
bz 1 f
2013-06-17 13:03:15 +04:00
ld r3 , [ n u m _ p t e _ n o t _ p r e s e n t ]
add r3 , r3 , 1
st r3 , [ n u m _ p t e _ n o t _ p r e s e n t ]
2013-01-18 13:42:23 +04:00
1 :
# endif
2013-01-18 13:42:19 +04:00
.endm
;-----------------------------------------------------------------
; Convert Linux PTE entry into TLB entry
; A one-word PTE entry is programmed as two-word TLB Entry [PD0:PD1] in mmu
; IN: r0 = PTE, r1 = ptr to PTE
.macro CONV_PTE_TO_TLB
ARC: MMUv4 preps/1 - Fold PTE K/U access flags
The current ARC VM code has 13 flags in Page Table entry: some software
(accesed/dirty/non-linear-maps) and rest hardware specific. With 8k MMU
page, we need 19 bits for addressing page frame so remaining 13 bits is
just about enough to accomodate the current flags.
In MMUv4 there are 2 additional flags, SZ (normal or super page) and WT
(cache access mode write-thru) - and additionally PFN is 20 bits (vs. 19
before for 8k). Thus these can't be held in current PTE w/o making each
entry 64bit wide.
It seems there is some scope of compressing the current PTE flags (and
freeing up a few bits). Currently PTE contains fully orthogonal distinct
access permissions for kernel and user mode (Kr, Kw, Kx; Ur, Uw, Ux)
which can be folded into one set (R, W, X). The translation of 3 PTE
bits into 6 TLB bits (when programming the MMU) can be done based on
following pre-requites/assumptions:
1. For kernel-mode-only translations (vmalloc: 0x7000_0000 to
0x7FFF_FFFF), PTE additionally has PAGE_GLOBAL flag set (and user
space entries can never be global). Thus such a PTE can translate
to Kr, Kw, Kx (as appropriate) and zero for User mode counterparts.
2. For non global entries, the PTE flags can be used to create mirrored
K and U TLB bits. This is true after commit a950549c675f2c8c504
"ARC: copy_(to|from)_user() to honor usermode-access permissions"
which ensured that user-space translations _MUST_ have same access
permissions for both U/K mode accesses so that copy_{to,from}_user()
play fair with fault based CoW break and such...
There is no such thing as free lunch - the cost is slightly infalted
TLB-Miss Handlers.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-06-17 16:42:13 +04:00
and r3 , r0 , P T E _ B I T S _ R W X ; r w x
lsl r2 , r3 , 3 ; r w x 0 0 0
and. f 0 , r0 , _ P A G E _ G L O B A L
or. z r2 , r2 , r3 ; r w x r w x
and r3 , r0 , P T E _ B I T S _ N O N _ R W X _ I N _ P D 1 ; Extract PFN+cache bits from PTE
or r3 , r3 , r2
sr r3 , [ A R C _ R E G _ T L B P D 1 ] ; these go in PD1
2013-01-18 13:42:19 +04:00
and r2 , r0 , P T E _ B I T S _ I N _ P D 0 ; Extract other PTE flags: (V)alid, (G)lb
lr r3 ,[ A R C _ R E G _ T L B P D 0 ] ; MMU prepares PD0 with vaddr and asid
or r3 , r3 , r2 ; S | vaddr | {sasid|asid}
sr r3 ,[ A R C _ R E G _ T L B P D 0 ] ; rewrite PD0
.endm
;-----------------------------------------------------------------
; Commit the TLB entry into MMU
.macro COMMIT_ENTRY_TO_MMU
/* Get free TLB slot: Set = computed from vaddr, way = random */
sr T L B G e t I n d e x , [ A R C _ R E G _ T L B C O M M A N D ]
/* Commit the Write */
# if ( C O N F I G _ A R C _ M M U _ V E R > = 2 ) / * i n t r o d u c e d i n v2 * /
sr T L B W r i t e N I , [ A R C _ R E G _ T L B C O M M A N D ]
# else
sr T L B W r i t e , [ A R C _ R E G _ T L B C O M M A N D ]
# endif
.endm
2013-01-18 13:42:25 +04:00
ARCFP_ C O D E ;Fast Path Code, candidate for ICCM
2013-01-18 13:42:19 +04:00
;-----------------------------------------------------------------------------
; I-TLB Miss Exception Handler
;-----------------------------------------------------------------------------
ARC_ E N T R Y E V _ T L B M i s s I
TLBMISS_ F R E E U P _ R E G S
2013-01-18 13:42:23 +04:00
# ifdef C O N F I G _ A R C _ D B G _ T L B _ M I S S _ C O U N T
ld r0 , [ @numitlb]
add r0 , r0 , 1
st r0 , [ @numitlb]
# endif
2013-01-18 13:42:19 +04:00
;----------------------------------------------------------------
2013-06-17 13:03:15 +04:00
; Get the PTE corresponding to V-addr accessed, r2 is setup with EFA
2013-01-18 13:42:19 +04:00
LOAD_ F A U L T _ P T E
;----------------------------------------------------------------
; VERIFY_PTE: Check if PTE permissions approp for executing code
cmp_ s r2 , V M A L L O C _ S T A R T
ARC: MMUv4 preps/1 - Fold PTE K/U access flags
The current ARC VM code has 13 flags in Page Table entry: some software
(accesed/dirty/non-linear-maps) and rest hardware specific. With 8k MMU
page, we need 19 bits for addressing page frame so remaining 13 bits is
just about enough to accomodate the current flags.
In MMUv4 there are 2 additional flags, SZ (normal or super page) and WT
(cache access mode write-thru) - and additionally PFN is 20 bits (vs. 19
before for 8k). Thus these can't be held in current PTE w/o making each
entry 64bit wide.
It seems there is some scope of compressing the current PTE flags (and
freeing up a few bits). Currently PTE contains fully orthogonal distinct
access permissions for kernel and user mode (Kr, Kw, Kx; Ur, Uw, Ux)
which can be folded into one set (R, W, X). The translation of 3 PTE
bits into 6 TLB bits (when programming the MMU) can be done based on
following pre-requites/assumptions:
1. For kernel-mode-only translations (vmalloc: 0x7000_0000 to
0x7FFF_FFFF), PTE additionally has PAGE_GLOBAL flag set (and user
space entries can never be global). Thus such a PTE can translate
to Kr, Kw, Kx (as appropriate) and zero for User mode counterparts.
2. For non global entries, the PTE flags can be used to create mirrored
K and U TLB bits. This is true after commit a950549c675f2c8c504
"ARC: copy_(to|from)_user() to honor usermode-access permissions"
which ensured that user-space translations _MUST_ have same access
permissions for both U/K mode accesses so that copy_{to,from}_user()
play fair with fault based CoW break and such...
There is no such thing as free lunch - the cost is slightly infalted
TLB-Miss Handlers.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-06-17 16:42:13 +04:00
mov_ s r2 , ( _ P A G E _ P R E S E N T | _ P A G E _ E X E C U T E )
or. h s r2 , r2 , _ P A G E _ G L O B A L
2013-01-18 13:42:19 +04:00
and r3 , r0 , r2 ; Mask out NON Flag bits from PTE
xor. f r3 , r3 , r2 ; check ( ( pte & flags_test ) == flags_test )
bnz d o _ s l o w _ p a t h _ p f
; Let Linux VM know that the page was accessed
2013-06-17 10:05:15 +04:00
or r0 , r0 , _ P A G E _ A C C E S S E D ; set Accessed Bit
st_ s r0 , [ r1 ] ; Write back PTE
2013-01-18 13:42:19 +04:00
CONV_ P T E _ T O _ T L B
COMMIT_ E N T R Y _ T O _ M M U
TLBMISS_ R E S T O R E _ R E G S
rtie
ARC_ E X I T E V _ T L B M i s s I
;-----------------------------------------------------------------------------
; D-TLB Miss Exception Handler
;-----------------------------------------------------------------------------
ARC_ E N T R Y E V _ T L B M i s s D
TLBMISS_ F R E E U P _ R E G S
2013-01-18 13:42:23 +04:00
# ifdef C O N F I G _ A R C _ D B G _ T L B _ M I S S _ C O U N T
ld r0 , [ @numdtlb]
add r0 , r0 , 1
st r0 , [ @numdtlb]
# endif
2013-01-18 13:42:19 +04:00
;----------------------------------------------------------------
; Get the PTE corresponding to V-addr accessed
2013-06-17 13:03:15 +04:00
; If PTE exists, it will setup, r0 = PTE, r1 = Ptr to PTE, r2 = EFA
2013-01-18 13:42:19 +04:00
LOAD_ F A U L T _ P T E
;----------------------------------------------------------------
; VERIFY_PTE: Chk if PTE permissions approp for data access (R/W/R+W)
ARC: MMUv4 preps/1 - Fold PTE K/U access flags
The current ARC VM code has 13 flags in Page Table entry: some software
(accesed/dirty/non-linear-maps) and rest hardware specific. With 8k MMU
page, we need 19 bits for addressing page frame so remaining 13 bits is
just about enough to accomodate the current flags.
In MMUv4 there are 2 additional flags, SZ (normal or super page) and WT
(cache access mode write-thru) - and additionally PFN is 20 bits (vs. 19
before for 8k). Thus these can't be held in current PTE w/o making each
entry 64bit wide.
It seems there is some scope of compressing the current PTE flags (and
freeing up a few bits). Currently PTE contains fully orthogonal distinct
access permissions for kernel and user mode (Kr, Kw, Kx; Ur, Uw, Ux)
which can be folded into one set (R, W, X). The translation of 3 PTE
bits into 6 TLB bits (when programming the MMU) can be done based on
following pre-requites/assumptions:
1. For kernel-mode-only translations (vmalloc: 0x7000_0000 to
0x7FFF_FFFF), PTE additionally has PAGE_GLOBAL flag set (and user
space entries can never be global). Thus such a PTE can translate
to Kr, Kw, Kx (as appropriate) and zero for User mode counterparts.
2. For non global entries, the PTE flags can be used to create mirrored
K and U TLB bits. This is true after commit a950549c675f2c8c504
"ARC: copy_(to|from)_user() to honor usermode-access permissions"
which ensured that user-space translations _MUST_ have same access
permissions for both U/K mode accesses so that copy_{to,from}_user()
play fair with fault based CoW break and such...
There is no such thing as free lunch - the cost is slightly infalted
TLB-Miss Handlers.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-06-17 16:42:13 +04:00
cmp_ s r2 , V M A L L O C _ S T A R T
mov_ s r2 , _ P A G E _ P R E S E N T ; common bit for K/U PTE
or. h s r2 , r2 , _ P A G E _ G L O B A L ; kernel PTE only
; Linux PTE [RWX] bits are semantically overloaded:
; -If PAGE_GLOBAL set, they refer to kernel-only flags (vmalloc)
; -Otherwise they are user-mode permissions, and those are exactly
; same for kernel mode as well (e.g. copy_(to|from)_user)
2013-01-18 13:42:19 +04:00
lr r3 , [ e c r ]
btst_ s r3 , E C R _ C _ B I T _ D T L B _ L D _ M I S S ; Read Access
ARC: MMUv4 preps/1 - Fold PTE K/U access flags
The current ARC VM code has 13 flags in Page Table entry: some software
(accesed/dirty/non-linear-maps) and rest hardware specific. With 8k MMU
page, we need 19 bits for addressing page frame so remaining 13 bits is
just about enough to accomodate the current flags.
In MMUv4 there are 2 additional flags, SZ (normal or super page) and WT
(cache access mode write-thru) - and additionally PFN is 20 bits (vs. 19
before for 8k). Thus these can't be held in current PTE w/o making each
entry 64bit wide.
It seems there is some scope of compressing the current PTE flags (and
freeing up a few bits). Currently PTE contains fully orthogonal distinct
access permissions for kernel and user mode (Kr, Kw, Kx; Ur, Uw, Ux)
which can be folded into one set (R, W, X). The translation of 3 PTE
bits into 6 TLB bits (when programming the MMU) can be done based on
following pre-requites/assumptions:
1. For kernel-mode-only translations (vmalloc: 0x7000_0000 to
0x7FFF_FFFF), PTE additionally has PAGE_GLOBAL flag set (and user
space entries can never be global). Thus such a PTE can translate
to Kr, Kw, Kx (as appropriate) and zero for User mode counterparts.
2. For non global entries, the PTE flags can be used to create mirrored
K and U TLB bits. This is true after commit a950549c675f2c8c504
"ARC: copy_(to|from)_user() to honor usermode-access permissions"
which ensured that user-space translations _MUST_ have same access
permissions for both U/K mode accesses so that copy_{to,from}_user()
play fair with fault based CoW break and such...
There is no such thing as free lunch - the cost is slightly infalted
TLB-Miss Handlers.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-06-17 16:42:13 +04:00
or. n z r2 , r2 , _ P A G E _ R E A D ; chk for Read flag in PTE
2013-01-18 13:42:19 +04:00
btst_ s r3 , E C R _ C _ B I T _ D T L B _ S T _ M I S S ; Write Access
ARC: MMUv4 preps/1 - Fold PTE K/U access flags
The current ARC VM code has 13 flags in Page Table entry: some software
(accesed/dirty/non-linear-maps) and rest hardware specific. With 8k MMU
page, we need 19 bits for addressing page frame so remaining 13 bits is
just about enough to accomodate the current flags.
In MMUv4 there are 2 additional flags, SZ (normal or super page) and WT
(cache access mode write-thru) - and additionally PFN is 20 bits (vs. 19
before for 8k). Thus these can't be held in current PTE w/o making each
entry 64bit wide.
It seems there is some scope of compressing the current PTE flags (and
freeing up a few bits). Currently PTE contains fully orthogonal distinct
access permissions for kernel and user mode (Kr, Kw, Kx; Ur, Uw, Ux)
which can be folded into one set (R, W, X). The translation of 3 PTE
bits into 6 TLB bits (when programming the MMU) can be done based on
following pre-requites/assumptions:
1. For kernel-mode-only translations (vmalloc: 0x7000_0000 to
0x7FFF_FFFF), PTE additionally has PAGE_GLOBAL flag set (and user
space entries can never be global). Thus such a PTE can translate
to Kr, Kw, Kx (as appropriate) and zero for User mode counterparts.
2. For non global entries, the PTE flags can be used to create mirrored
K and U TLB bits. This is true after commit a950549c675f2c8c504
"ARC: copy_(to|from)_user() to honor usermode-access permissions"
which ensured that user-space translations _MUST_ have same access
permissions for both U/K mode accesses so that copy_{to,from}_user()
play fair with fault based CoW break and such...
There is no such thing as free lunch - the cost is slightly infalted
TLB-Miss Handlers.
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
2013-06-17 16:42:13 +04:00
or. n z r2 , r2 , _ P A G E _ W R I T E ; chk for Write flag in PTE
; Above laddering takes care of XCHG access (both R and W)
2013-01-18 13:42:19 +04:00
; By now, r2 setup with all the Flags we need to check in PTE
and r3 , r0 , r2 ; Mask out NON Flag bits from PTE
brne. d r3 , r2 , d o _ s l o w _ p a t h _ p f ; is ((pte & flags_test) == flags_test)
;----------------------------------------------------------------
; UPDATE_PTE: Let Linux VM know that page was accessed/dirty
lr r3 , [ e c r ]
2013-06-17 10:05:15 +04:00
or r0 , r0 , _ P A G E _ A C C E S S E D ; Accessed bit always
2013-01-18 13:42:19 +04:00
btst_ s r3 , E C R _ C _ B I T _ D T L B _ S T _ M I S S ; See if it was a Write Access ?
or. n z r0 , r0 , _ P A G E _ M O D I F I E D ; if Write, set Dirty bit as well
st_ s r0 , [ r1 ] ; Write back PTE
CONV_ P T E _ T O _ T L B
# if ( C O N F I G _ A R C _ M M U _ V E R = = 1 )
; MMU with 2 way set assoc J-TLB, needs some help in pathetic case of
; memcpy where 3 parties contend for 2 ways, ensuing a livelock.
; But only for old MMU or one with Metal Fix
TLB_ W R I T E _ H E U R I S T I C S
# endif
COMMIT_ E N T R Y _ T O _ M M U
TLBMISS_ R E S T O R E _ R E G S
rtie
;-------- Common routine to call Linux Page Fault Handler -----------
do_slow_path_pf :
; Restore the 4-scratch regs saved by fast path miss handler
TLBMISS_ R E S T O R E _ R E G S
; Slow path TLB Miss handled as a regular ARC Exception
; (stack switching / save the complete reg-file).
2013-07-09 13:37:13 +04:00
EXCEPTION_ P R O L O G U E
2013-01-18 13:42:19 +04:00
; ------- setup args for Linux Page fault Hanlder ---------
mov_ s r0 , s p
2013-06-12 12:19:02 +04:00
lr r1 , [ e f a ]
2013-01-18 13:42:19 +04:00
; We don't want exceptions to be disabled while the fault is handled.
; Now that we have saved the context we return from exception hence
; exceptions get re-enable
FAKE_ R E T _ F R O M _ E X C P N r9
bl d o _ p a g e _ f a u l t
b r e t _ f r o m _ e x c e p t i o n
ARC_ E X I T E V _ T L B M i s s D
ARC_ E N T R Y E V _ T L B M i s s B ; Bogus entry to measure sz of DTLBMiss hdlr