Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 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 | |
Catalin Marinas | 18ddbaa | 2020-03-30 10:29:38 +0100 | [diff] [blame] | 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 | |
Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 13 | #ifndef __ASSEMBLY__ |
| 14 | |
Catalin Marinas | 34bfeea | 2020-05-04 14:42:36 +0100 | [diff] [blame] | 15 | #include <linux/page-flags.h> |
| 16 | |
| 17 | #include <asm/pgtable-types.h> |
| 18 | |
| 19 | void mte_clear_page_tags(void *addr); |
Catalin Marinas | 18ddbaa | 2020-03-30 10:29:38 +0100 | [diff] [blame] | 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); |
Steven Price | 36943ab | 2020-05-13 16:37:50 +0100 | [diff] [blame] | 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); |
Catalin Marinas | 34bfeea | 2020-05-04 14:42:36 +0100 | [diff] [blame] | 32 | |
Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 33 | #ifdef CONFIG_ARM64_MTE |
| 34 | |
Catalin Marinas | 34bfeea | 2020-05-04 14:42:36 +0100 | [diff] [blame] | 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); |
Vincenzo Frascino | 2563776 | 2019-08-06 11:37:53 +0100 | [diff] [blame] | 39 | void mte_copy_page_tags(void *kto, const void *kfrom); |
Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 40 | void flush_mte_state(void); |
Catalin Marinas | 1c101da | 2019-11-27 10:30:15 +0000 | [diff] [blame] | 41 | void mte_thread_switch(struct task_struct *next); |
Catalin Marinas | 39d08e8 | 2020-04-17 18:29:35 +0100 | [diff] [blame] | 42 | void mte_suspend_exit(void); |
Catalin Marinas | 93f067f6 | 2020-07-03 14:25:50 +0100 | [diff] [blame] | 43 | long set_mte_ctrl(struct task_struct *task, unsigned long arg); |
| 44 | long get_mte_ctrl(struct task_struct *task); |
Catalin Marinas | 18ddbaa | 2020-03-30 10:29:38 +0100 | [diff] [blame] | 45 | int mte_ptrace_copy_tags(struct task_struct *child, long request, |
| 46 | unsigned long addr, unsigned long data); |
Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 47 | |
| 48 | #else |
| 49 | |
Catalin Marinas | 34bfeea | 2020-05-04 14:42:36 +0100 | [diff] [blame] | 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 | } |
Vincenzo Frascino | 2563776 | 2019-08-06 11:37:53 +0100 | [diff] [blame] | 56 | static inline void mte_copy_page_tags(void *kto, const void *kfrom) |
| 57 | { |
| 58 | } |
Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 59 | static inline void flush_mte_state(void) |
| 60 | { |
| 61 | } |
Catalin Marinas | 1c101da | 2019-11-27 10:30:15 +0000 | [diff] [blame] | 62 | static inline void mte_thread_switch(struct task_struct *next) |
| 63 | { |
| 64 | } |
Catalin Marinas | 39d08e8 | 2020-04-17 18:29:35 +0100 | [diff] [blame] | 65 | static inline void mte_suspend_exit(void) |
| 66 | { |
| 67 | } |
Catalin Marinas | 93f067f6 | 2020-07-03 14:25:50 +0100 | [diff] [blame] | 68 | static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg) |
Catalin Marinas | 1c101da | 2019-11-27 10:30:15 +0000 | [diff] [blame] | 69 | { |
| 70 | return 0; |
| 71 | } |
Catalin Marinas | 93f067f6 | 2020-07-03 14:25:50 +0100 | [diff] [blame] | 72 | static inline long get_mte_ctrl(struct task_struct *task) |
Catalin Marinas | 1c101da | 2019-11-27 10:30:15 +0000 | [diff] [blame] | 73 | { |
| 74 | return 0; |
| 75 | } |
Catalin Marinas | 18ddbaa | 2020-03-30 10:29:38 +0100 | [diff] [blame] | 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 | } |
Vincenzo Frascino | 637ec83 | 2019-09-16 11:51:17 +0100 | [diff] [blame] | 82 | |
| 83 | #endif |
| 84 | |
| 85 | #endif /* __ASSEMBLY__ */ |
| 86 | #endif /* __ASM_MTE_H */ |