mte.h 1.8 KB
Newer Older
1 2 3 4 5 6 7
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2020 ARM Ltd.
 */
#ifndef __ASM_MTE_H
#define __ASM_MTE_H

8 9 10 11 12
#define MTE_GRANULE_SIZE	UL(16)
#define MTE_GRANULE_MASK	(~(MTE_GRANULE_SIZE - 1))
#define MTE_TAG_SHIFT		56
#define MTE_TAG_SIZE		4

13 14
#ifndef __ASSEMBLY__

15 16 17 18 19
#include <linux/page-flags.h>

#include <asm/pgtable-types.h>

void mte_clear_page_tags(void *addr);
20 21 22 23
unsigned long mte_copy_tags_from_user(void *to, const void __user *from,
				      unsigned long n);
unsigned long mte_copy_tags_to_user(void __user *to, void *from,
				    unsigned long n);
24

25 26
#ifdef CONFIG_ARM64_MTE

27 28 29 30
/* track which pages have valid allocation tags */
#define PG_mte_tagged	PG_arch_2

void mte_sync_tags(pte_t *ptep, pte_t pte);
31
void mte_copy_page_tags(void *kto, const void *kfrom);
32
void flush_mte_state(void);
33
void mte_thread_switch(struct task_struct *next);
34
void mte_suspend_exit(void);
35 36
long set_mte_ctrl(struct task_struct *task, unsigned long arg);
long get_mte_ctrl(struct task_struct *task);
37 38
int mte_ptrace_copy_tags(struct task_struct *child, long request,
			 unsigned long addr, unsigned long data);
39 40 41

#else

42 43 44 45 46 47
/* unused if !CONFIG_ARM64_MTE, silence the compiler */
#define PG_mte_tagged	0

static inline void mte_sync_tags(pte_t *ptep, pte_t pte)
{
}
48 49 50
static inline void mte_copy_page_tags(void *kto, const void *kfrom)
{
}
51 52 53
static inline void flush_mte_state(void)
{
}
54 55 56
static inline void mte_thread_switch(struct task_struct *next)
{
}
57 58 59
static inline void mte_suspend_exit(void)
{
}
60
static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg)
61 62 63
{
	return 0;
}
64
static inline long get_mte_ctrl(struct task_struct *task)
65 66 67
{
	return 0;
}
68 69 70 71 72 73
static inline int mte_ptrace_copy_tags(struct task_struct *child,
				       long request, unsigned long addr,
				       unsigned long data)
{
	return -EIO;
}
74 75 76 77 78

#endif

#endif /* __ASSEMBLY__ */
#endif /* __ASM_MTE_H  */