[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 32/45] linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG
From: |
Peter Maydell |
Subject: |
[PULL 32/45] linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG |
Date: |
Thu, 11 Feb 2021 12:58:47 +0000 |
From: Richard Henderson <richard.henderson@linaro.org>
These prctl fields are required for the function of MTE.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20210210000223.884088-24-richard.henderson@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
linux-user/aarch64/target_syscall.h | 9 ++++++
linux-user/syscall.c | 43 +++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
diff --git a/linux-user/aarch64/target_syscall.h
b/linux-user/aarch64/target_syscall.h
index 820601dfcc8..76f6c3391d3 100644
--- a/linux-user/aarch64/target_syscall.h
+++ b/linux-user/aarch64/target_syscall.h
@@ -33,5 +33,14 @@ struct target_pt_regs {
#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55
#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56
# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0)
+/* MTE tag check fault modes */
+# define TARGET_PR_MTE_TCF_SHIFT 1
+# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT)
+# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT)
+# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT)
+# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT)
+/* MTE tag inclusion mask */
+# define TARGET_PR_MTE_TAG_SHIFT 3
+# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT)
#endif /* AARCH64_TARGET_SYSCALL_H */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ba4da7f8a67..61bf6148e7f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -10985,17 +10985,53 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
{
abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE;
CPUARMState *env = cpu_env;
+ ARMCPU *cpu = env_archcpu(env);
+
+ if (cpu_isar_feature(aa64_mte, cpu)) {
+ valid_mask |= TARGET_PR_MTE_TCF_MASK;
+ valid_mask |= TARGET_PR_MTE_TAG_MASK;
+ }
if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) {
return -TARGET_EINVAL;
}
env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE;
+
+ if (cpu_isar_feature(aa64_mte, cpu)) {
+ switch (arg2 & TARGET_PR_MTE_TCF_MASK) {
+ case TARGET_PR_MTE_TCF_NONE:
+ case TARGET_PR_MTE_TCF_SYNC:
+ case TARGET_PR_MTE_TCF_ASYNC:
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /*
+ * Write PR_MTE_TCF to SCTLR_EL1[TCF0].
+ * Note that the syscall values are consistent with hw.
+ */
+ env->cp15.sctlr_el[1] =
+ deposit64(env->cp15.sctlr_el[1], 38, 2,
+ arg2 >> TARGET_PR_MTE_TCF_SHIFT);
+
+ /*
+ * Write PR_MTE_TAG to GCR_EL1[Exclude].
+ * Note that the syscall uses an include mask,
+ * and hardware uses an exclude mask -- invert.
+ */
+ env->cp15.gcr_el1 =
+ deposit64(env->cp15.gcr_el1, 0, 16,
+ ~arg2 >> TARGET_PR_MTE_TAG_SHIFT);
+ arm_rebuild_hflags(env);
+ }
return 0;
}
case TARGET_PR_GET_TAGGED_ADDR_CTRL:
{
abi_long ret = 0;
CPUARMState *env = cpu_env;
+ ARMCPU *cpu = env_archcpu(env);
if (arg2 || arg3 || arg4 || arg5) {
return -TARGET_EINVAL;
@@ -11003,6 +11039,13 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
if (env->tagged_addr_enable) {
ret |= TARGET_PR_TAGGED_ADDR_ENABLE;
}
+ if (cpu_isar_feature(aa64_mte, cpu)) {
+ /* See above. */
+ ret |= (extract64(env->cp15.sctlr_el[1], 38, 2)
+ << TARGET_PR_MTE_TCF_SHIFT);
+ ret = deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16,
+ ~env->cp15.gcr_el1);
+ }
return ret;
}
#endif /* AARCH64 */
--
2.20.1
- [PULL 24/45] exec: Rename guest_{addr,range}_valid to *_untagged, (continued)
- [PULL 24/45] exec: Rename guest_{addr,range}_valid to *_untagged, Peter Maydell, 2021/02/11
- [PULL 29/45] linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE, Peter Maydell, 2021/02/11
- [PULL 35/45] linux-user/aarch64: Pass syndrome to EXC_*_ABORT, Peter Maydell, 2021/02/11
- [PULL 31/45] target/arm: Use the proper TBI settings for linux-user, Peter Maydell, 2021/02/11
- [PULL 39/45] target/arm: Enable MTE for user-only, Peter Maydell, 2021/02/11
- [PULL 22/45] linux-user: Explicitly untag memory management syscalls, Peter Maydell, 2021/02/11
- [PULL 26/45] linux-user: Move lock_user et al out of line, Peter Maydell, 2021/02/11
- [PULL 28/45] linux-user: Handle tags in lock_user/unlock_user, Peter Maydell, 2021/02/11
- [PULL 27/45] linux-user: Fix types in uaccess.c, Peter Maydell, 2021/02/11
- [PULL 30/45] target/arm: Improve gen_top_byte_ignore, Peter Maydell, 2021/02/11
- [PULL 32/45] linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG,
Peter Maydell <=
- [PULL 33/45] linux-user/aarch64: Implement PROT_MTE, Peter Maydell, 2021/02/11
- [PULL 34/45] target/arm: Split out syndrome.h from internals.h, Peter Maydell, 2021/02/11
- [PULL 36/45] linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault, Peter Maydell, 2021/02/11
- [PULL 43/45] tests/qtests: Add npcm7xx emc model test, Peter Maydell, 2021/02/11
- [PULL 41/45] hw/net: Add npcm7xx emc model, Peter Maydell, 2021/02/11
- [PULL 37/45] linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error, Peter Maydell, 2021/02/11
- [PULL 44/45] hw/arm: versal: Use nr_apu_cpus in favor of hard coding 2, Peter Maydell, 2021/02/11
- [PULL 38/45] target/arm: Add allocation tag storage for user mode, Peter Maydell, 2021/02/11
- [PULL 40/45] tests/tcg/aarch64: Add mte smoke tests, Peter Maydell, 2021/02/11
- [PULL 42/45] hw/arm: Add npcm7xx emc model, Peter Maydell, 2021/02/11