2019-06-03 07:44:50 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2012-03-05 11:49:32 +00:00
/ *
* Copyright ( C ) 2 0 1 2 A R M L t d .
* /
# include < l i n u x / l i n k a g e . h >
2015-07-22 19:05:54 +01:00
2016-12-26 04:10:19 -05:00
# include < a s m / a s m - u a c c e s s . h >
2018-12-07 18:08:20 +00:00
# include < a s m / a s s e m b l e r . h >
# include < a s m / c a c h e . h >
2012-03-05 11:49:32 +00:00
/ *
* Copy f r o m u s e r s p a c e t o a k e r n e l b u f f e r ( a l i g n m e n t h a n d l e d b y t h e h a r d w a r e )
*
* Parameters :
* x0 - t o
* x1 - f r o m
* x2 - n
* Returns :
* x0 - b y t e s n o t c o p i e d
* /
2015-09-23 11:55:39 -07:00
2020-04-29 19:37:02 +01:00
.macro ldrb1 reg, p t r , v a l
2020-12-02 13:15:54 +00:00
user_ l d s t 9 9 9 8 f , l d t r b , \ r e g , \ p t r , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro strb1 reg, p t r , v a l
strb \ r e g , [ \ p t r ] , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro ldrh1 reg, p t r , v a l
2021-07-12 15:27:46 +01:00
user_ l d s t 9 9 9 7 f , l d t r h , \ r e g , \ p t r , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro strh1 reg, p t r , v a l
strh \ r e g , [ \ p t r ] , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro ldr1 reg, p t r , v a l
2021-07-12 15:27:46 +01:00
user_ l d s t 9 9 9 7 f , l d t r , \ r e g , \ p t r , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro str1 reg, p t r , v a l
str \ r e g , [ \ p t r ] , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro ldp1 reg1 , r e g 2 , p t r , v a l
2021-07-12 15:27:46 +01:00
user_ l d p 9 9 9 7 f , \ r e g 1 , \ r e g 2 , \ p t r , \ v a l
2015-09-23 11:55:39 -07:00
.endm
2020-04-29 19:37:02 +01:00
.macro stp1 reg1 , r e g 2 , p t r , v a l
stp \ r e g 1 , \ r e g 2 , [ \ p t r ] , \ v a l
2015-09-23 11:55:39 -07:00
.endm
end . r e q x5
2021-07-12 15:27:46 +01:00
srcin . r e q x15
2020-01-06 19:58:17 +00:00
SYM_ F U N C _ S T A R T ( _ _ a r c h _ c o p y _ f r o m _ u s e r )
2015-09-23 11:55:39 -07:00
add e n d , x0 , x2
2021-07-12 15:27:46 +01:00
mov s r c i n , x1
2015-09-23 11:55:39 -07:00
# include " c o p y _ t e m p l a t e . S "
mov x0 , #0 / / N o t h i n g t o c o p y
2012-03-05 11:49:32 +00:00
ret
arm64: lib: __arch_copy_from_user(): fold fixups into body
Like other functions, __arch_copy_from_user() places its exception
fixups in the `.fixup` section without any clear association with
__arch_copy_from_user() itself. If we backtrace the fixup code, it will
be symbolized as an offset from the nearest prior symbol, which happens
to be `__entry_tramp_text_end`. Further, since the PC adjustment for the
fixup is akin to a direct branch rather than a function call,
__arch_copy_from_user() itself will be missing from the backtrace.
This is confusing and hinders debugging. In general this pattern will
also be problematic for CONFIG_LIVEPATCH, since fixups often return to
their associated function, but this isn't accurately captured in the
stacktrace.
To solve these issues for assembly functions, we must move fixups into
the body of the functions themselves, after the usual fast-path returns.
This patch does so for __arch_copy_from_user().
Inline assembly will be dealt with in subsequent patches.
Other than the improved backtracing, there should be no functional
change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20211019160219.5202-3-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-10-19 17:02:08 +01:00
/ / Exception f i x u p s
2021-07-12 15:27:46 +01:00
9997 : cmp d s t , d s t i n
b. n e 9 9 9 8 f
/ / Before b e i n g a b s o l u t e l y s u r e w e c o u l d n ' t c o p y a n y t h i n g , t r y h a r d e r
USER( 9 9 9 8 f , l d t r b t m p1 w , [ s r c i n ] )
strb t m p1 w , [ d s t ] , #1
2016-09-10 16:50:00 -04:00
9998 : sub x0 , e n d , d s t / / b y t e s n o t c o p i e d
2012-03-05 11:49:32 +00:00
ret
arm64: lib: __arch_copy_from_user(): fold fixups into body
Like other functions, __arch_copy_from_user() places its exception
fixups in the `.fixup` section without any clear association with
__arch_copy_from_user() itself. If we backtrace the fixup code, it will
be symbolized as an offset from the nearest prior symbol, which happens
to be `__entry_tramp_text_end`. Further, since the PC adjustment for the
fixup is akin to a direct branch rather than a function call,
__arch_copy_from_user() itself will be missing from the backtrace.
This is confusing and hinders debugging. In general this pattern will
also be problematic for CONFIG_LIVEPATCH, since fixups often return to
their associated function, but this isn't accurately captured in the
stacktrace.
To solve these issues for assembly functions, we must move fixups into
the body of the functions themselves, after the usual fast-path returns.
This patch does so for __arch_copy_from_user().
Inline assembly will be dealt with in subsequent patches.
Other than the improved backtracing, there should be no functional
change as a result of this patch.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20211019160219.5202-3-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-10-19 17:02:08 +01:00
SYM_ F U N C _ E N D ( _ _ a r c h _ c o p y _ f r o m _ u s e r )
EXPORT_ S Y M B O L ( _ _ a r c h _ c o p y _ f r o m _ u s e r )