Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/aarch64 SCTLR_EnIA should be enabled in the caller(...
details: https://anonhg.NetBSD.org/src/rev/b32c7de63170
branches: trunk
changeset: 972067:b32c7de63170
user: ryo <ryo%NetBSD.org@localhost>
date: Fri May 15 04:55:40 2020 +0000
description:
SCTLR_EnIA should be enabled in the caller(locore).
For some reason, gcc make aarch64_pac_init() function non-leaf, and it uses paciasp/autiasp.
diffstat:
sys/arch/aarch64/aarch64/cpufunc.c | 24 ++++++++++++------------
sys/arch/aarch64/aarch64/genassym.cf | 3 ++-
sys/arch/aarch64/aarch64/locore.S | 14 ++++++++++++--
sys/arch/aarch64/include/cpufunc.h | 4 ++--
4 files changed, 28 insertions(+), 17 deletions(-)
diffs (136 lines):
diff -r 87083342ddcd -r b32c7de63170 sys/arch/aarch64/aarch64/cpufunc.c
--- a/sys/arch/aarch64/aarch64/cpufunc.c Fri May 15 01:43:47 2020 +0000
+++ b/sys/arch/aarch64/aarch64/cpufunc.c Fri May 15 04:55:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufunc.c,v 1.17 2020/04/12 07:49:58 maxv Exp $ */
+/* $NetBSD: cpufunc.c,v 1.18 2020/05/15 04:55:40 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -30,7 +30,7 @@
#include "opt_multiprocessor.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.17 2020/04/12 07:49:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.18 2020/05/15 04:55:40 ryo Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -443,14 +443,15 @@
}
/*
- * TODO: this function should have a "no-pac" attribute. Right now it
- * doesn't use PAC so that's fine.
+ * In order to avoid inconsistencies with pointer authentication
+ * in this function itself, the caller must enable PAC according
+ * to the return value.
*/
-void
+int
aarch64_pac_init(int primary)
{
#ifdef ARMV83_PAC
- uint64_t reg, sctlr;
+ uint64_t reg;
/* CPU0 does the detection. */
if (primary) {
@@ -470,15 +471,14 @@
}
if (!aarch64_pac_enabled)
- return;
-
- /* Enable PAC on the CPU. */
- sctlr = reg_sctlr_el1_read();
- sctlr |= SCTLR_EnIA;
- reg_sctlr_el1_write(sctlr);
+ return -1;
/* Set the key. Curlwp here is the CPU's idlelwp. */
reg_APIAKeyLo_EL1_write(curlwp->l_md.md_ia_kern_lo);
reg_APIAKeyHi_EL1_write(curlwp->l_md.md_ia_kern_hi);
+
+ return 0;
+#else
+ return -1;
#endif
}
diff -r 87083342ddcd -r b32c7de63170 sys/arch/aarch64/aarch64/genassym.cf
--- a/sys/arch/aarch64/aarch64/genassym.cf Fri May 15 01:43:47 2020 +0000
+++ b/sys/arch/aarch64/aarch64/genassym.cf Fri May 15 04:55:40 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.23 2020/04/12 07:49:58 maxv Exp $
+# $NetBSD: genassym.cf,v 1.24 2020/05/15 04:55:40 ryo Exp $
#-
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -363,6 +363,7 @@
define SCTLR_UCI SCTLR_UCI
define SCTLR_nTLSMD SCTLR_nTLSMD
define SCTLR_LSMAOE SCTLR_LSMAOE
+define SCTLR_EnIA SCTLR_EnIA
define ICC_SRE_EL2_EN ICC_SRE_EL2_EN
define ICC_SRE_EL2_SRE ICC_SRE_EL2_SRE
diff -r 87083342ddcd -r b32c7de63170 sys/arch/aarch64/aarch64/locore.S
--- a/sys/arch/aarch64/aarch64/locore.S Fri May 15 01:43:47 2020 +0000
+++ b/sys/arch/aarch64/aarch64/locore.S Fri May 15 04:55:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.59 2020/04/12 07:49:58 maxv Exp $ */
+/* $NetBSD: locore.S,v 1.60 2020/05/15 04:55:40 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -38,7 +38,7 @@
#include <aarch64/hypervisor.h>
#include "assym.h"
-RCSID("$NetBSD: locore.S,v 1.59 2020/04/12 07:49:58 maxv Exp $")
+RCSID("$NetBSD: locore.S,v 1.60 2020/05/15 04:55:40 ryo Exp $")
#ifdef AARCH64_DEVICE_MEM_STRONGLY_ORDERED
#define MAIR_DEVICE_MEM MAIR_DEVICE_nGnRnE
@@ -181,6 +181,11 @@
/* init PAC if supported */
mov x0, #1
bl aarch64_pac_init
+ cbnz w0, 1f /* if (aarch64_pac_init() == 0) */
+ mrs x0, sctlr_el1
+ orr x0, x0, #SCTLR_EnIA /* enable PAC */
+ msr sctlr_el1, x0
+1:
/* set topology information */
mrs x0, tpidr_el1 /* curcpu */
@@ -509,6 +514,11 @@
/* init PAC if supported */
mov x0, #0
bl aarch64_pac_init
+ cbnz w0, 1f /* if (aarch64_pac_init() == 0) */
+ mrs x0, sctlr_el1
+ orr x0, x0, #SCTLR_EnIA /* enable PAC */
+ msr sctlr_el1, x0
+1:
mov fp, xzr /* trace back starts here */
mrs x0, tpidr_el1 /* curcpu() */
diff -r 87083342ddcd -r b32c7de63170 sys/arch/aarch64/include/cpufunc.h
--- a/sys/arch/aarch64/include/cpufunc.h Fri May 15 01:43:47 2020 +0000
+++ b/sys/arch/aarch64/include/cpufunc.h Fri May 15 04:55:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufunc.h,v 1.13 2020/05/13 06:08:51 ryo Exp $ */
+/* $NetBSD: cpufunc.h,v 1.14 2020/05/15 04:55:40 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -70,7 +70,7 @@
extern int aarch64_pac_enabled;
-void aarch64_pac_init(int);
+int aarch64_pac_init(int);
int set_cpufuncs(void);
void aarch64_getcacheinfo(int);
Home |
Main Index |
Thread Index |
Old Index