xref: /openbmc/linux/arch/arm64/include/asm/mte.h (revision d9fd5a71)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020 ARM Ltd.
4  */
5 #ifndef __ASM_MTE_H
6 #define __ASM_MTE_H
7 
8 #include <asm/compiler.h>
9 #include <asm/mte-def.h>
10 
11 #define __MTE_PREAMBLE		ARM64_ASM_PREAMBLE ".arch_extension memtag\n"
12 
13 #ifndef __ASSEMBLY__
14 
15 #include <linux/bitfield.h>
16 #include <linux/page-flags.h>
17 #include <linux/types.h>
18 
19 #include <asm/pgtable-types.h>
20 
21 extern u64 gcr_kernel_excl;
22 
23 void mte_clear_page_tags(void *addr);
24 unsigned long mte_copy_tags_from_user(void *to, const void __user *from,
25 				      unsigned long n);
26 unsigned long mte_copy_tags_to_user(void __user *to, void *from,
27 				    unsigned long n);
28 int mte_save_tags(struct page *page);
29 void mte_save_page_tags(const void *page_addr, void *tag_storage);
30 bool mte_restore_tags(swp_entry_t entry, struct page *page);
31 void mte_restore_page_tags(void *page_addr, const void *tag_storage);
32 void mte_invalidate_tags(int type, pgoff_t offset);
33 void mte_invalidate_tags_area(int type);
34 void *mte_allocate_tag_storage(void);
35 void mte_free_tag_storage(char *storage);
36 
37 #ifdef CONFIG_ARM64_MTE
38 
39 /* track which pages have valid allocation tags */
40 #define PG_mte_tagged	PG_arch_2
41 
42 void mte_sync_tags(pte_t *ptep, pte_t pte);
43 void mte_copy_page_tags(void *kto, const void *kfrom);
44 void flush_mte_state(void);
45 void mte_thread_switch(struct task_struct *next);
46 void mte_suspend_exit(void);
47 long set_mte_ctrl(struct task_struct *task, unsigned long arg);
48 long get_mte_ctrl(struct task_struct *task);
49 int mte_ptrace_copy_tags(struct task_struct *child, long request,
50 			 unsigned long addr, unsigned long data);
51 
52 void mte_assign_mem_tag_range(void *addr, size_t size);
53 
54 #else /* CONFIG_ARM64_MTE */
55 
56 /* unused if !CONFIG_ARM64_MTE, silence the compiler */
57 #define PG_mte_tagged	0
58 
59 static inline void mte_sync_tags(pte_t *ptep, pte_t pte)
60 {
61 }
62 static inline void mte_copy_page_tags(void *kto, const void *kfrom)
63 {
64 }
65 static inline void flush_mte_state(void)
66 {
67 }
68 static inline void mte_thread_switch(struct task_struct *next)
69 {
70 }
71 static inline void mte_suspend_exit(void)
72 {
73 }
74 static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg)
75 {
76 	return 0;
77 }
78 static inline long get_mte_ctrl(struct task_struct *task)
79 {
80 	return 0;
81 }
82 static inline int mte_ptrace_copy_tags(struct task_struct *child,
83 				       long request, unsigned long addr,
84 				       unsigned long data)
85 {
86 	return -EIO;
87 }
88 
89 static inline void mte_assign_mem_tag_range(void *addr, size_t size)
90 {
91 }
92 
93 #endif /* CONFIG_ARM64_MTE */
94 
95 #endif /* __ASSEMBLY__ */
96 #endif /* __ASM_MTE_H  */
97