Module Name: src
Committed By: jmcneill
Date: Sun Sep 22 13:57:55 UTC 2019
Modified Files:
src/sys/arch/aarch64/aarch64: pmap.c
Log Message:
Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.
To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/aarch64/aarch64/pmap.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/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.46 src/sys/arch/aarch64/aarch64/pmap.c:1.47
--- src/sys/arch/aarch64/aarch64/pmap.c:1.46 Fri Sep 20 05:35:27 2019
+++ src/sys/arch/aarch64/aarch64/pmap.c Sun Sep 22 13:57:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.46 2019/09/20 05:35:27 ryo Exp $ */
+/* $NetBSD: pmap.c,v 1.47 2019/09/22 13:57:55 jmcneill Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.46 2019/09/20 05:35:27 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.47 2019/09/22 13:57:55 jmcneill Exp $");
#include "opt_arm_debug.h"
#include "opt_ddb.h"
@@ -1274,7 +1274,7 @@ void
pmap_activate(struct lwp *l)
{
struct pmap *pm = l->l_proc->p_vmspace->vm_map.pmap;
- uint64_t ttbr0;
+ uint64_t ttbr0, tcr;
UVMHIST_FUNC(__func__);
UVMHIST_CALLED(pmaphist);
@@ -1288,6 +1288,11 @@ pmap_activate(struct lwp *l)
UVMHIST_LOG(pmaphist, "lwp=%p (pid=%d)", l, l->l_proc->p_pid, 0, 0);
+ /* Disable translation table walks using TTBR0 */
+ tcr = reg_tcr_el1_read();
+ reg_tcr_el1_write(tcr | TCR_EPD0);
+ __asm __volatile("isb" ::: "memory");
+
/* XXX */
CTASSERT(PID_MAX <= 65535); /* 16bit ASID */
if (pm->pm_asid == -1)
@@ -1296,6 +1301,11 @@ pmap_activate(struct lwp *l)
ttbr0 = ((uint64_t)pm->pm_asid << 48) | pm->pm_l0table_pa;
cpu_set_ttbr0(ttbr0);
+ /* Re-enable translation table walks using TTBR0 */
+ tcr = reg_tcr_el1_read();
+ reg_tcr_el1_write(tcr & ~TCR_EPD0);
+ __asm __volatile("isb" ::: "memory");
+
pm->pm_activated = true;
PMAP_COUNT(activate);
@@ -1305,6 +1315,7 @@ void
pmap_deactivate(struct lwp *l)
{
struct pmap *pm = l->l_proc->p_vmspace->vm_map.pmap;
+ uint64_t tcr;
UVMHIST_FUNC(__func__);
UVMHIST_CALLED(pmaphist);
@@ -1314,6 +1325,11 @@ pmap_deactivate(struct lwp *l)
UVMHIST_LOG(pmaphist, "lwp=%p, asid=%d", l, pm->pm_asid, 0, 0);
+ /* Disable translation table walks using TTBR0 */
+ tcr = reg_tcr_el1_read();
+ reg_tcr_el1_write(tcr | TCR_EPD0);
+ __asm __volatile("isb" ::: "memory");
+
/* XXX */
pm->pm_activated = false;