summaryrefslogtreecommitdiff
path: root/arch/arm64/include/asm/nospec-branch.h
blob: cc261d5f1afdaa26c2fd8010a69f815e22ca9089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef _ASM_ARM64_NOSPEC_BRANCH_H_
#define _ASM_ARM64_NOSPEC_BRANCH_H_

#ifdef __ASSEMBLY__

.macro retpoline
	str	x30, [sp, #-16]!
	bl	101f
100: //speculation trap
	wfe
	b	100b
101: //do ROP
	adrp	x30, 102f
	add	x30, x30, :lo12:102f
	ret
102: //non-spec code
	ldr	x30, [sp], #16
.endm

.macro br_nospec reg
#ifdef CONFIG_RETPOLINE
	b	__aarch64_indirect_thunk_\reg
#else
	br	\reg
#endif
.endm

.macro blr_nospec reg
#ifdef CONFIG_RETPOLINE
	bl	__aarch64_indirect_thunk_\reg
#else
	blr	\reg
#endif
.endm

/*
 * In case of "blr lr" we need to inline the retpoline
 * as we cannot do a bl to the indirect_thunk, because
 * it would destroy the contents of our link register.
 */
.macro blr_nospec_lr
#ifdef CONFIG_RETPOLINE
	retpoline
	blr	lr
#else
	blr	lr
#endif
.endm

#else /* __ASSEMBLY__ */

extern char __indirect_thunk_start[];
extern char __indirect_thunk_end[];

#endif /* __ASSEMBLY__ */

#endif /* _ASM_ARM64_NOSPEC_BRANCH_H_ */