blob: 1c99fcadb58ca6b9732f74ead07e63c4a94b2312 [file] [log] [blame]
Vincenzo Frascino637ec832019-09-16 11:51:17 +01001/* 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
Catalin Marinas18ddbaa2020-03-30 10:29:38 +01008#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
Vincenzo Frascino637ec832019-09-16 11:51:17 +010013#ifndef __ASSEMBLY__
14
Catalin Marinas34bfeea2020-05-04 14:42:36 +010015#include <linux/page-flags.h>
16
17#include <asm/pgtable-types.h>
18
19void mte_clear_page_tags(void *addr);
Catalin Marinas18ddbaa2020-03-30 10:29:38 +010020unsigned 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);
Steven Price36943ab2020-05-13 16:37:50 +010024int 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);
Catalin Marinas34bfeea2020-05-04 14:42:36 +010032
Vincenzo Frascino637ec832019-09-16 11:51:17 +010033#ifdef CONFIG_ARM64_MTE
34
Catalin Marinas34bfeea2020-05-04 14:42:36 +010035/* track which pages have valid allocation tags */
36#define PG_mte_tagged PG_arch_2
37
38void mte_sync_tags(pte_t *ptep, pte_t pte);
Vincenzo Frascino25637762019-08-06 11:37:53 +010039void mte_copy_page_tags(void *kto, const void *kfrom);
Vincenzo Frascino637ec832019-09-16 11:51:17 +010040void flush_mte_state(void);
Catalin Marinas1c101da2019-11-27 10:30:15 +000041void mte_thread_switch(struct task_struct *next);
Catalin Marinas39d08e82020-04-17 18:29:35 +010042void mte_suspend_exit(void);
Catalin Marinas93f067f62020-07-03 14:25:50 +010043long set_mte_ctrl(struct task_struct *task, unsigned long arg);
44long get_mte_ctrl(struct task_struct *task);
Catalin Marinas18ddbaa2020-03-30 10:29:38 +010045int mte_ptrace_copy_tags(struct task_struct *child, long request,
46 unsigned long addr, unsigned long data);
Vincenzo Frascino637ec832019-09-16 11:51:17 +010047
48#else
49
Catalin Marinas34bfeea2020-05-04 14:42:36 +010050/* unused if !CONFIG_ARM64_MTE, silence the compiler */
51#define PG_mte_tagged 0
52
53static inline void mte_sync_tags(pte_t *ptep, pte_t pte)
54{
55}
Vincenzo Frascino25637762019-08-06 11:37:53 +010056static inline void mte_copy_page_tags(void *kto, const void *kfrom)
57{
58}
Vincenzo Frascino637ec832019-09-16 11:51:17 +010059static inline void flush_mte_state(void)
60{
61}
Catalin Marinas1c101da2019-11-27 10:30:15 +000062static inline void mte_thread_switch(struct task_struct *next)
63{
64}
Catalin Marinas39d08e82020-04-17 18:29:35 +010065static inline void mte_suspend_exit(void)
66{
67}
Catalin Marinas93f067f62020-07-03 14:25:50 +010068static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg)
Catalin Marinas1c101da2019-11-27 10:30:15 +000069{
70 return 0;
71}
Catalin Marinas93f067f62020-07-03 14:25:50 +010072static inline long get_mte_ctrl(struct task_struct *task)
Catalin Marinas1c101da2019-11-27 10:30:15 +000073{
74 return 0;
75}
Catalin Marinas18ddbaa2020-03-30 10:29:38 +010076static 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}
Vincenzo Frascino637ec832019-09-16 11:51:17 +010082
83#endif
84
85#endif /* __ASSEMBLY__ */
86#endif /* __ASM_MTE_H */