xref: /openbmc/linux/arch/arm64/include/asm/mte-kasan.h (revision 630dce2810b9f09d312aed4189300e785254c24b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020 ARM Ltd.
4  */
5 #ifndef __ASM_MTE_KASAN_H
6 #define __ASM_MTE_KASAN_H
7 
8 #include <asm/mte-def.h>
9 
10 #ifndef __ASSEMBLY__
11 
12 #include <linux/types.h>
13 
14 /*
15  * The functions below are meant to be used only for the
16  * KASAN_HW_TAGS interface defined in asm/memory.h.
17  */
18 #ifdef CONFIG_ARM64_MTE
19 
20 static inline u8 mte_get_ptr_tag(void *ptr)
21 {
22 	/* Note: The format of KASAN tags is 0xF<x> */
23 	u8 tag = 0xF0 | (u8)(((u64)(ptr)) >> MTE_TAG_SHIFT);
24 
25 	return tag;
26 }
27 
28 u8 mte_get_mem_tag(void *addr);
29 u8 mte_get_random_tag(void);
30 void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag);
31 
32 void mte_enable_kernel(void);
33 void mte_init_tags(u64 max_tag);
34 
35 #else /* CONFIG_ARM64_MTE */
36 
37 static inline u8 mte_get_ptr_tag(void *ptr)
38 {
39 	return 0xFF;
40 }
41 
42 static inline u8 mte_get_mem_tag(void *addr)
43 {
44 	return 0xFF;
45 }
46 static inline u8 mte_get_random_tag(void)
47 {
48 	return 0xFF;
49 }
50 static inline void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag)
51 {
52 	return addr;
53 }
54 
55 static inline void mte_enable_kernel(void)
56 {
57 }
58 
59 static inline void mte_init_tags(u64 max_tag)
60 {
61 }
62 
63 #endif /* CONFIG_ARM64_MTE */
64 
65 #endif /* __ASSEMBLY__ */
66 
67 #endif /* __ASM_MTE_KASAN_H  */
68