arm64: mte: Enable swap of tagged pages
[linux-2.6-microblaze.git] / arch / arm64 / include / asm / mte.h
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 #define MTE_GRANULE_SIZE        UL(16)
9 #define MTE_GRANULE_MASK        (~(MTE_GRANULE_SIZE - 1))
10 #define MTE_TAG_SHIFT           56
11 #define MTE_TAG_SIZE            4
12
13 #ifndef __ASSEMBLY__
14
15 #include <linux/page-flags.h>
16
17 #include <asm/pgtable-types.h>
18
19 void mte_clear_page_tags(void *addr);
20 unsigned long mte_copy_tags_from_user(void *to, const void __user *from,
21                                       unsigned long n);
22 unsigned long mte_copy_tags_to_user(void __user *to, void *from,
23                                     unsigned long n);
24 int mte_save_tags(struct page *page);
25 void mte_save_page_tags(const void *page_addr, void *tag_storage);
26 bool mte_restore_tags(swp_entry_t entry, struct page *page);
27 void mte_restore_page_tags(void *page_addr, const void *tag_storage);
28 void mte_invalidate_tags(int type, pgoff_t offset);
29 void mte_invalidate_tags_area(int type);
30 void *mte_allocate_tag_storage(void);
31 void mte_free_tag_storage(char *storage);
32
33 #ifdef CONFIG_ARM64_MTE
34
35 /* track which pages have valid allocation tags */
36 #define PG_mte_tagged   PG_arch_2
37
38 void mte_sync_tags(pte_t *ptep, pte_t pte);
39 void mte_copy_page_tags(void *kto, const void *kfrom);
40 void flush_mte_state(void);
41 void mte_thread_switch(struct task_struct *next);
42 void mte_suspend_exit(void);
43 long set_mte_ctrl(struct task_struct *task, unsigned long arg);
44 long get_mte_ctrl(struct task_struct *task);
45 int mte_ptrace_copy_tags(struct task_struct *child, long request,
46                          unsigned long addr, unsigned long data);
47
48 #else
49
50 /* unused if !CONFIG_ARM64_MTE, silence the compiler */
51 #define PG_mte_tagged   0
52
53 static inline void mte_sync_tags(pte_t *ptep, pte_t pte)
54 {
55 }
56 static inline void mte_copy_page_tags(void *kto, const void *kfrom)
57 {
58 }
59 static inline void flush_mte_state(void)
60 {
61 }
62 static inline void mte_thread_switch(struct task_struct *next)
63 {
64 }
65 static inline void mte_suspend_exit(void)
66 {
67 }
68 static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg)
69 {
70         return 0;
71 }
72 static inline long get_mte_ctrl(struct task_struct *task)
73 {
74         return 0;
75 }
76 static inline int mte_ptrace_copy_tags(struct task_struct *child,
77                                        long request, unsigned long addr,
78                                        unsigned long data)
79 {
80         return -EIO;
81 }
82
83 #endif
84
85 #endif /* __ASSEMBLY__ */
86 #endif /* __ASM_MTE_H  */