xref: /linux/arch/arm64/include/asm/scs.h (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_SCS_H
3 #define _ASM_SCS_H
4 
5 #ifdef __ASSEMBLER__
6 
7 #include <asm/asm-offsets.h>
8 #include <asm/sysreg.h>
9 
10 #ifdef CONFIG_SHADOW_CALL_STACK
11 	scs_sp	.req	x18
12 
13 	.macro scs_load_current_base
14 	get_current_task scs_sp
15 	ldr	scs_sp, [scs_sp, #TSK_TI_SCS_BASE]
16 	.endm
17 
18 	.macro scs_load_current
19 	get_current_task scs_sp
20 	ldr	scs_sp, [scs_sp, #TSK_TI_SCS_SP]
21 	.endm
22 
23 	.macro scs_save tsk
24 	str	scs_sp, [\tsk, #TSK_TI_SCS_SP]
25 	.endm
26 #else
27 	.macro scs_load_current_base
28 	.endm
29 
30 	.macro scs_load_current
31 	.endm
32 
33 	.macro scs_save tsk
34 	.endm
35 #endif /* CONFIG_SHADOW_CALL_STACK */
36 
37 
38 #else
39 
40 #include <linux/scs.h>
41 #include <asm/cpufeature.h>
42 
43 #ifdef CONFIG_UNWIND_PATCH_PAC_INTO_SCS
44 static inline void dynamic_scs_init(void)
45 {
46 	extern bool __pi_dynamic_scs_is_enabled;
47 
48 	if (__pi_dynamic_scs_is_enabled) {
49 		pr_info("Enabling dynamic shadow call stack\n");
50 		static_branch_enable(&dynamic_scs_enabled);
51 	}
52 }
53 #else
54 static inline void dynamic_scs_init(void) {}
55 #endif
56 
57 enum {
58 	EDYNSCS_INVALID_CIE_HEADER		= 1,
59 	EDYNSCS_INVALID_CIE_SDATA_SIZE		= 2,
60 	EDYNSCS_INVALID_FDE_AUGM_DATA_SIZE	= 3,
61 	EDYNSCS_INVALID_CFA_OPCODE		= 4,
62 };
63 
64 int __pi_scs_patch(const u8 eh_frame[], int size, bool skip_dry_run);
65 
66 #endif /* __ASSEMBLER__ */
67 
68 #endif /* _ASM_SCS_H */
69