2019-06-04 10:11:33 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2018-03-08 08:00:13 +00:00
/ *
* Copyright ( C ) 2 0 1 8 L i n a r o L t d < a r d . b i e s h e u v e l @linaro.org>
* /
# include < l i n u x / l i n k a g e . h >
2023-01-09 12:41:46 +01:00
# include < a s m / a s s e m b l e r . h >
2018-03-08 08:00:13 +00:00
2020-05-01 12:54:29 +01:00
SYM_ F U N C _ S T A R T ( _ _ e f i _ r t _ a s m _ w r a p p e r )
arm64: efi: Recover from synchronous exceptions occurring in firmware
Unlike x86, which has machinery to deal with page faults that occur
during the execution of EFI runtime services, arm64 has nothing like
that, and a synchronous exception raised by firmware code brings down
the whole system.
With more EFI based systems appearing that were not built to run Linux
(such as the Windows-on-ARM laptops based on Qualcomm SOCs), as well as
the introduction of PRM (platform specific firmware routines that are
callable just like EFI runtime services), we are more likely to run into
issues of this sort, and it is much more likely that we can identify and
work around such issues if they don't bring down the system entirely.
Since we already use a EFI runtime services call wrapper in assembler,
we can quite easily add some code that captures the execution state at
the point where the call is made, allowing us to revert to this state
and proceed execution if the call triggered a synchronous exception.
Given that the kernel and the firmware don't share any data structures
that could end up in an indeterminate state, we can happily continue
running, as long as we mark the EFI runtime services as unavailable from
that point on.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
2022-10-28 16:39:14 +02:00
stp x29 , x30 , [ s p , #- 112 ] !
2018-03-08 08:00:13 +00:00
mov x29 , s p
/ *
* Register x18 i s d e s i g n a t e d a s t h e ' p l a t f o r m ' r e g i s t e r b y t h e A A P C S ,
* which m e a n s f i r m w a r e r u n n i n g a t t h e s a m e e x c e p t i o n l e v e l a s t h e O S
* ( such a s U E F I ) s h o u l d n e v e r t o u c h i t .
* /
stp x1 , x18 , [ s p , #16 ]
arm64: efi: Recover from synchronous exceptions occurring in firmware
Unlike x86, which has machinery to deal with page faults that occur
during the execution of EFI runtime services, arm64 has nothing like
that, and a synchronous exception raised by firmware code brings down
the whole system.
With more EFI based systems appearing that were not built to run Linux
(such as the Windows-on-ARM laptops based on Qualcomm SOCs), as well as
the introduction of PRM (platform specific firmware routines that are
callable just like EFI runtime services), we are more likely to run into
issues of this sort, and it is much more likely that we can identify and
work around such issues if they don't bring down the system entirely.
Since we already use a EFI runtime services call wrapper in assembler,
we can quite easily add some code that captures the execution state at
the point where the call is made, allowing us to revert to this state
and proceed execution if the call triggered a synchronous exception.
Given that the kernel and the firmware don't share any data structures
that could end up in an indeterminate state, we can happily continue
running, as long as we mark the EFI runtime services as unavailable from
that point on.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
2022-10-28 16:39:14 +02:00
/ *
* Preserve a l l c a l l e e s a v e d r e g i s t e r s a n d p r e s e r v e t h e s t a c k p o i n t e r
* value a t t h e b a s e o f t h e E F I r u n t i m e s t a c k s o w e c a n r e c o v e r f r o m
* synchronous e x c e p t i o n s o c c u r r i n g w h i l e e x e c u t i n g t h e f i r m w a r e
* routines.
* /
stp x19 , x20 , [ s p , #32 ]
stp x21 , x22 , [ s p , #48 ]
stp x23 , x24 , [ s p , #64 ]
stp x25 , x26 , [ s p , #80 ]
stp x27 , x28 , [ s p , #96 ]
2022-12-05 11:31:25 +01:00
ldr_ l x16 , e f i _ r t _ s t a c k _ t o p
mov s p , x16
arm64: efi: Recover from synchronous exceptions occurring in firmware
Unlike x86, which has machinery to deal with page faults that occur
during the execution of EFI runtime services, arm64 has nothing like
that, and a synchronous exception raised by firmware code brings down
the whole system.
With more EFI based systems appearing that were not built to run Linux
(such as the Windows-on-ARM laptops based on Qualcomm SOCs), as well as
the introduction of PRM (platform specific firmware routines that are
callable just like EFI runtime services), we are more likely to run into
issues of this sort, and it is much more likely that we can identify and
work around such issues if they don't bring down the system entirely.
Since we already use a EFI runtime services call wrapper in assembler,
we can quite easily add some code that captures the execution state at
the point where the call is made, allowing us to revert to this state
and proceed execution if the call triggered a synchronous exception.
Given that the kernel and the firmware don't share any data structures
that could end up in an indeterminate state, we can happily continue
running, as long as we mark the EFI runtime services as unavailable from
that point on.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
2022-10-28 16:39:14 +02:00
stp x18 , x29 , [ s p , #- 16 ] !
2022-12-05 11:31:25 +01:00
2018-03-08 08:00:13 +00:00
/ *
* We a r e l u c k y e n o u g h t h a t n o E F I r u n t i m e s e r v i c e s t a k e m o r e t h a n
* 5 arguments, s o a l l a r e p a s s e d i n r e g i s t e r s r a t h e r t h a n v i a t h e
* stack.
* /
mov x8 , x0
mov x0 , x2
mov x1 , x3
mov x2 , x4
mov x3 , x5
mov x4 , x6
blr x8
2022-10-28 16:39:14 +02:00
mov x16 , s p
2022-12-05 11:31:25 +01:00
mov s p , x29
2022-10-28 16:39:14 +02:00
str x z r , [ x16 , #8 ] / / c l e a r r e c o r d e d t a s k S P v a l u e
2018-03-08 08:00:13 +00:00
ldp x1 , x2 , [ s p , #16 ]
cmp x2 , x18
arm64: efi: Recover from synchronous exceptions occurring in firmware
Unlike x86, which has machinery to deal with page faults that occur
during the execution of EFI runtime services, arm64 has nothing like
that, and a synchronous exception raised by firmware code brings down
the whole system.
With more EFI based systems appearing that were not built to run Linux
(such as the Windows-on-ARM laptops based on Qualcomm SOCs), as well as
the introduction of PRM (platform specific firmware routines that are
callable just like EFI runtime services), we are more likely to run into
issues of this sort, and it is much more likely that we can identify and
work around such issues if they don't bring down the system entirely.
Since we already use a EFI runtime services call wrapper in assembler,
we can quite easily add some code that captures the execution state at
the point where the call is made, allowing us to revert to this state
and proceed execution if the call triggered a synchronous exception.
Given that the kernel and the firmware don't share any data structures
that could end up in an indeterminate state, we can happily continue
running, as long as we mark the EFI runtime services as unavailable from
that point on.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
2022-10-28 16:39:14 +02:00
ldp x29 , x30 , [ s p ] , #112
2018-03-08 08:00:13 +00:00
b. n e 0 f
ret
2020-04-27 09:00:13 -07:00
0 :
/ *
* With C O N F I G _ S H A D O W _ C A L L _ S T A C K , t h e k e r n e l u s e s x18 t o s t o r e a
* shadow s t a c k p o i n t e r , w h i c h w e n e e d t o r e s t o r e b e f o r e r e t u r n i n g t o
* potentially i n s t r u m e n t e d c o d e . T h i s i s s a f e b e c a u s e t h e w r a p p e r i s
* called w i t h p r e e m p t i o n d i s a b l e d a n d a s e p a r a t e s h a d o w s t a c k i s u s e d
* for i n t e r r u p t s .
* /
2022-12-05 11:31:25 +01:00
# ifdef C O N F I G _ S H A D O W _ C A L L _ S T A C K
ldr_ l x18 , e f i _ r t _ s t a c k _ t o p
ldr x18 , [ x18 , #- 16 ]
# endif
2020-04-27 09:00:13 -07:00
b e f i _ h a n d l e _ c o r r u p t e d _ x18 / / t a i l c a l l
2020-05-01 12:54:29 +01:00
SYM_ F U N C _ E N D ( _ _ e f i _ r t _ a s m _ w r a p p e r )
arm64: efi: Recover from synchronous exceptions occurring in firmware
Unlike x86, which has machinery to deal with page faults that occur
during the execution of EFI runtime services, arm64 has nothing like
that, and a synchronous exception raised by firmware code brings down
the whole system.
With more EFI based systems appearing that were not built to run Linux
(such as the Windows-on-ARM laptops based on Qualcomm SOCs), as well as
the introduction of PRM (platform specific firmware routines that are
callable just like EFI runtime services), we are more likely to run into
issues of this sort, and it is much more likely that we can identify and
work around such issues if they don't bring down the system entirely.
Since we already use a EFI runtime services call wrapper in assembler,
we can quite easily add some code that captures the execution state at
the point where the call is made, allowing us to revert to this state
and proceed execution if the call triggered a synchronous exception.
Given that the kernel and the firmware don't share any data structures
that could end up in an indeterminate state, we can happily continue
running, as long as we mark the EFI runtime services as unavailable from
that point on.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
2022-10-28 16:39:14 +02:00
SYM_ C O D E _ S T A R T ( _ _ e f i _ r t _ a s m _ r e c o v e r )
mov s p , x30
2022-10-28 16:39:14 +02:00
ldr_ l x16 , e f i _ r t _ s t a c k _ t o p / / c l e a r r e c o r d e d t a s k S P v a l u e
str x z r , [ x16 , #- 8 ]
arm64: efi: Recover from synchronous exceptions occurring in firmware
Unlike x86, which has machinery to deal with page faults that occur
during the execution of EFI runtime services, arm64 has nothing like
that, and a synchronous exception raised by firmware code brings down
the whole system.
With more EFI based systems appearing that were not built to run Linux
(such as the Windows-on-ARM laptops based on Qualcomm SOCs), as well as
the introduction of PRM (platform specific firmware routines that are
callable just like EFI runtime services), we are more likely to run into
issues of this sort, and it is much more likely that we can identify and
work around such issues if they don't bring down the system entirely.
Since we already use a EFI runtime services call wrapper in assembler,
we can quite easily add some code that captures the execution state at
the point where the call is made, allowing us to revert to this state
and proceed execution if the call triggered a synchronous exception.
Given that the kernel and the firmware don't share any data structures
that could end up in an indeterminate state, we can happily continue
running, as long as we mark the EFI runtime services as unavailable from
that point on.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
2022-10-28 16:39:14 +02:00
ldp x19 , x20 , [ s p , #32 ]
ldp x21 , x22 , [ s p , #48 ]
ldp x23 , x24 , [ s p , #64 ]
ldp x25 , x26 , [ s p , #80 ]
ldp x27 , x28 , [ s p , #96 ]
ldp x29 , x30 , [ s p ] , #112
ret
SYM_ C O D E _ E N D ( _ _ e f i _ r t _ a s m _ r e c o v e r )