1
2
3
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#ifndef __ASSEMBLY__
12
13#include <linux/bitfield.h>
14#include <linux/page-flags.h>
15#include <linux/types.h>
16
17#include <asm/pgtable-types.h>
18
19void mte_clear_page_tags(void *addr);
20unsigned long mte_copy_tags_from_user(void *to, const void __user *from,
21 unsigned long n);
22unsigned long mte_copy_tags_to_user(void __user *to, void *from,
23 unsigned long n);
24int mte_save_tags(struct page *page);
25void mte_save_page_tags(const void *page_addr, void *tag_storage);
26bool mte_restore_tags(swp_entry_t entry, struct page *page);
27void mte_restore_page_tags(void *page_addr, const void *tag_storage);
28void mte_invalidate_tags(int type, pgoff_t offset);
29void mte_invalidate_tags_area(int type);
30void *mte_allocate_tag_storage(void);
31void mte_free_tag_storage(char *storage);
32
33#ifdef CONFIG_ARM64_MTE
34
35
36#define PG_mte_tagged PG_arch_2
37
38void mte_zero_clear_page_tags(void *addr);
39void mte_sync_tags(pte_t old_pte, pte_t pte);
40void mte_copy_page_tags(void *kto, const void *kfrom);
41void mte_thread_init_user(void);
42void mte_thread_switch(struct task_struct *next);
43void mte_suspend_enter(void);
44long set_mte_ctrl(struct task_struct *task, unsigned long arg);
45long get_mte_ctrl(struct task_struct *task);
46int mte_ptrace_copy_tags(struct task_struct *child, long request,
47 unsigned long addr, unsigned long data);
48
49#else
50
51
52#define PG_mte_tagged 0
53
54static inline void mte_zero_clear_page_tags(void *addr)
55{
56}
57static inline void mte_sync_tags(pte_t old_pte, pte_t pte)
58{
59}
60static inline void mte_copy_page_tags(void *kto, const void *kfrom)
61{
62}
63static inline void mte_thread_init_user(void)
64{
65}
66static inline void mte_thread_switch(struct task_struct *next)
67{
68}
69static inline void mte_suspend_enter(void)
70{
71}
72static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg)
73{
74 return 0;
75}
76static inline long get_mte_ctrl(struct task_struct *task)
77{
78 return 0;
79}
80static inline int mte_ptrace_copy_tags(struct task_struct *child,
81 long request, unsigned long addr,
82 unsigned long data)
83{
84 return -EIO;
85}
86
87#endif
88
89#ifdef CONFIG_KASAN_HW_TAGS
90
91DECLARE_STATIC_KEY_FALSE(mte_async_mode);
92
93static inline bool system_uses_mte_async_mode(void)
94{
95 return static_branch_unlikely(&mte_async_mode);
96}
97
98void mte_check_tfsr_el1(void);
99
100static inline void mte_check_tfsr_entry(void)
101{
102 if (!system_supports_mte())
103 return;
104
105 mte_check_tfsr_el1();
106}
107
108static inline void mte_check_tfsr_exit(void)
109{
110 if (!system_supports_mte())
111 return;
112
113
114
115
116
117
118 dsb(nsh);
119 isb();
120
121 mte_check_tfsr_el1();
122}
123#else
124static inline bool system_uses_mte_async_mode(void)
125{
126 return false;
127}
128static inline void mte_check_tfsr_el1(void)
129{
130}
131static inline void mte_check_tfsr_entry(void)
132{
133}
134static inline void mte_check_tfsr_exit(void)
135{
136}
137#endif
138
139#endif
140#endif
141