1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _MCSAFE_TEST_H_
3 #define _MCSAFE_TEST_H_
4 
5 #ifndef __ASSEMBLY__
6 #ifdef CONFIG_MCSAFE_TEST
7 extern unsigned long mcsafe_test_src;
8 extern unsigned long mcsafe_test_dst;
9 
mcsafe_inject_src(void * addr)10 static inline void mcsafe_inject_src(void *addr)
11 {
12 	if (addr)
13 		mcsafe_test_src = (unsigned long) addr;
14 	else
15 		mcsafe_test_src = ~0UL;
16 }
17 
mcsafe_inject_dst(void * addr)18 static inline void mcsafe_inject_dst(void *addr)
19 {
20 	if (addr)
21 		mcsafe_test_dst = (unsigned long) addr;
22 	else
23 		mcsafe_test_dst = ~0UL;
24 }
25 #else /* CONFIG_MCSAFE_TEST */
mcsafe_inject_src(void * addr)26 static inline void mcsafe_inject_src(void *addr)
27 {
28 }
29 
mcsafe_inject_dst(void * addr)30 static inline void mcsafe_inject_dst(void *addr)
31 {
32 }
33 #endif /* CONFIG_MCSAFE_TEST */
34 
35 #else /* __ASSEMBLY__ */
36 #include <asm/export.h>
37 
38 #ifdef CONFIG_MCSAFE_TEST
39 .macro MCSAFE_TEST_CTL
40 	.pushsection .data
41 	.align 8
42 	.globl mcsafe_test_src
43 	mcsafe_test_src:
44 		.quad 0
45 	EXPORT_SYMBOL_GPL(mcsafe_test_src)
46 	.globl mcsafe_test_dst
47 	mcsafe_test_dst:
48 		.quad 0
49 	EXPORT_SYMBOL_GPL(mcsafe_test_dst)
50 	.popsection
51 .endm
52 
53 .macro MCSAFE_TEST_SRC reg count target
54 	leaq \count(\reg), %r9
55 	cmp mcsafe_test_src, %r9
56 	ja \target
57 .endm
58 
59 .macro MCSAFE_TEST_DST reg count target
60 	leaq \count(\reg), %r9
61 	cmp mcsafe_test_dst, %r9
62 	ja \target
63 .endm
64 #else
65 .macro MCSAFE_TEST_CTL
66 .endm
67 
68 .macro MCSAFE_TEST_SRC reg count target
69 .endm
70 
71 .macro MCSAFE_TEST_DST reg count target
72 .endm
73 #endif /* CONFIG_MCSAFE_TEST */
74 #endif /* __ASSEMBLY__ */
75 #endif /* _MCSAFE_TEST_H_ */
76