Module Name: src
Committed By: ryo
Date: Sat Feb 29 21:36:03 UTC 2020
Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c
Log Message:
add support userspace tagged address for aarch64 (experimental)
'sysctl machdep.tagged_address' to set/clear TCR_EL1.TBI0 to enable/disable
address tagging.
with 'machdep.tagged_address=1', some syscalls may cause problems?
To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/aarch64/aarch64/aarch64_machdep.c
diff -u src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.39 src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.40
--- src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.39 Sat Feb 29 21:09:11 2020
+++ src/sys/arch/aarch64/aarch64/aarch64_machdep.c Sat Feb 29 21:36:03 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.39 2020/02/29 21:09:11 ryo Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.40 2020/02/29 21:36:03 ryo Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.39 2020/02/29 21:09:11 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.40 2020/02/29 21:36:03 ryo Exp $");
#include "opt_arm_debug.h"
#include "opt_ddb.h"
@@ -50,6 +50,7 @@ __KERNEL_RCSID(1, "$NetBSD: aarch64_mach
#include <sys/msgbuf.h>
#include <sys/reboot.h>
#include <sys/sysctl.h>
+#include <sys/xcall.h>
#include <dev/mm.h>
@@ -397,6 +398,66 @@ initarm_common(vaddr_t kvm_base, vsize_t
return (vaddr_t)tf;
}
+/*
+ * machine dependent system variables.
+ */
+static xcfunc_t
+set_user_tagged_address(void *arg1, void *arg2)
+{
+ uint64_t enable = PTRTOUINT64(arg1);
+ uint64_t tcr = reg_tcr_el1_read();
+ if (enable)
+ tcr |= TCR_TBI0;
+ else
+ tcr &= ~TCR_TBI0;
+ reg_tcr_el1_write(tcr);
+
+ return 0;
+}
+
+static int
+sysctl_machdep_tagged_address(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node;
+ int error, cur, val;
+ uint64_t tcr;
+
+ tcr = reg_tcr_el1_read();
+ cur = val = (tcr & TCR_TBI0) ? 1 : 0;
+
+ node = *rnode;
+ node.sysctl_data = &val;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+ if (val < 0 || val > 1)
+ return EINVAL;
+
+ if (cur != val) {
+ uint64_t where = xc_broadcast(0,
+ (xcfunc_t)set_user_tagged_address, UINT64TOPTR(val), NULL);
+ xc_wait(where);
+ }
+
+ return 0;
+}
+
+SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
+{
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "machdep", NULL,
+ NULL, 0, NULL, 0,
+ CTL_MACHDEP, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "tagged_address",
+ SYSCTL_DESCR("top byte ignored in the address calculation"),
+ sysctl_machdep_tagged_address, 0, NULL, 0,
+ CTL_MACHDEP, CTL_CREATE, CTL_EOL);
+}
+
void
parse_mi_bootargs(char *args)
{