18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2020 ARM Ltd. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef __ASM_MTE_H 68c2ecf20Sopenharmony_ci#define __ASM_MTE_H 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#define MTE_GRANULE_SIZE UL(16) 98c2ecf20Sopenharmony_ci#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1)) 108c2ecf20Sopenharmony_ci#define MTE_TAG_SHIFT 56 118c2ecf20Sopenharmony_ci#define MTE_TAG_SIZE 4 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/page-flags.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <asm/pgtable-types.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_civoid mte_clear_page_tags(void *addr); 208c2ecf20Sopenharmony_ciunsigned long mte_copy_tags_from_user(void *to, const void __user *from, 218c2ecf20Sopenharmony_ci unsigned long n); 228c2ecf20Sopenharmony_ciunsigned long mte_copy_tags_to_user(void __user *to, void *from, 238c2ecf20Sopenharmony_ci unsigned long n); 248c2ecf20Sopenharmony_ciint mte_save_tags(struct page *page); 258c2ecf20Sopenharmony_civoid mte_save_page_tags(const void *page_addr, void *tag_storage); 268c2ecf20Sopenharmony_cibool mte_restore_tags(swp_entry_t entry, struct page *page); 278c2ecf20Sopenharmony_civoid mte_restore_page_tags(void *page_addr, const void *tag_storage); 288c2ecf20Sopenharmony_civoid mte_invalidate_tags(int type, pgoff_t offset); 298c2ecf20Sopenharmony_civoid mte_invalidate_tags_area(int type); 308c2ecf20Sopenharmony_civoid *mte_allocate_tag_storage(void); 318c2ecf20Sopenharmony_civoid mte_free_tag_storage(char *storage); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM64_MTE 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* track which pages have valid allocation tags */ 368c2ecf20Sopenharmony_ci#define PG_mte_tagged PG_arch_2 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_civoid mte_sync_tags(pte_t *ptep, pte_t pte); 398c2ecf20Sopenharmony_civoid mte_copy_page_tags(void *kto, const void *kfrom); 408c2ecf20Sopenharmony_civoid flush_mte_state(void); 418c2ecf20Sopenharmony_civoid mte_thread_switch(struct task_struct *next); 428c2ecf20Sopenharmony_civoid mte_suspend_exit(void); 438c2ecf20Sopenharmony_cilong set_mte_ctrl(struct task_struct *task, unsigned long arg); 448c2ecf20Sopenharmony_cilong get_mte_ctrl(struct task_struct *task); 458c2ecf20Sopenharmony_ciint mte_ptrace_copy_tags(struct task_struct *child, long request, 468c2ecf20Sopenharmony_ci unsigned long addr, unsigned long data); 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#else 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* unused if !CONFIG_ARM64_MTE, silence the compiler */ 518c2ecf20Sopenharmony_ci#define PG_mte_tagged 0 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic inline void mte_sync_tags(pte_t *ptep, pte_t pte) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_cistatic inline void mte_copy_page_tags(void *kto, const void *kfrom) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci} 598c2ecf20Sopenharmony_cistatic inline void flush_mte_state(void) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_cistatic inline void mte_thread_switch(struct task_struct *next) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_cistatic inline void mte_suspend_exit(void) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_cistatic inline long set_mte_ctrl(struct task_struct *task, unsigned long arg) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return 0; 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_cistatic inline long get_mte_ctrl(struct task_struct *task) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci return 0; 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_cistatic inline int mte_ptrace_copy_tags(struct task_struct *child, 778c2ecf20Sopenharmony_ci long request, unsigned long addr, 788c2ecf20Sopenharmony_ci unsigned long data) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci return -EIO; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#endif 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 868c2ecf20Sopenharmony_ci#endif /* __ASM_MTE_H */ 87