Module Name:    src
Committed By:   ryo
Date:           Wed Apr 27 23:38:31 UTC 2022

Modified Files:
        src/sys/arch/aarch64/aarch64: efi_machdep.c pmap.c

Log Message:
since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() 
again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
  arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/aarch64/efi_machdep.c
cvs rdiff -u -r1.135 -r1.136 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/efi_machdep.c
diff -u src/sys/arch/aarch64/aarch64/efi_machdep.c:1.11 src/sys/arch/aarch64/aarch64/efi_machdep.c:1.12
--- src/sys/arch/aarch64/aarch64/efi_machdep.c:1.11	Sat Apr  2 11:16:06 2022
+++ src/sys/arch/aarch64/aarch64/efi_machdep.c	Wed Apr 27 23:38:31 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: efi_machdep.c,v 1.11 2022/04/02 11:16:06 skrll Exp $ */
+/* $NetBSD: efi_machdep.c,v 1.12 2022/04/27 23:38:31 ryo Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.11 2022/04/02 11:16:06 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.12 2022/04/27 23:38:31 ryo Exp $");
 
 #include <sys/param.h>
 #include <uvm/uvm_extern.h>
@@ -106,9 +106,12 @@ arm_efirt_md_map_range(vaddr_t va, paddr
 int
 arm_efirt_md_enter(void)
 {
-	struct lwp *l = curlwp;
+	struct lwp *l;
 	int err;
 
+	kpreempt_disable();
+	l = curlwp;
+
 	/* Save FPU state */
 	arm_efirt_state.fpu_used = fpu_used_p(l) != 0;
 	if (arm_efirt_state.fpu_used)
@@ -126,8 +129,12 @@ arm_efirt_md_enter(void)
 	if (err)
 		return err;
 
-	if (efi_userva)
+	if (efi_userva) {
+		if ((l->l_flag & LW_SYSTEM) == 0) {
+			pmap_deactivate(l);
+		}
 		pmap_activate_efirt();
+	}
 
 	return 0;
 }
@@ -137,8 +144,13 @@ arm_efirt_md_exit(void)
 {
 	struct lwp *l = curlwp;
 
-	if (efi_userva)
+	if (efi_userva) {
 		pmap_deactivate_efirt();
+		if ((l->l_flag & LW_SYSTEM) == 0) {
+			pmap_activate(l);
+		}
+	}
+
 
 	/* Disable FP access */
 	reg_cpacr_el1_write(CPACR_FPEN_NONE);
@@ -150,4 +162,6 @@ arm_efirt_md_exit(void)
 
 	/* Remove custom fault handler */
 	cpu_unset_onfault();
+
+	kpreempt_enable();
 }

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.135 src/sys/arch/aarch64/aarch64/pmap.c:1.136
--- src/sys/arch/aarch64/aarch64/pmap.c:1.135	Sun Apr 17 15:20:36 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Wed Apr 27 23:38:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.135 2022/04/17 15:20:36 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.136 2022/04/27 23:38:31 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <r...@nerv.org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.135 2022/04/17 15:20:36 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.136 2022/04/27 23:38:31 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1495,8 +1495,6 @@ pmap_protect(struct pmap *pm, vaddr_t sv
 void
 pmap_activate_efirt(void)
 {
-	kpreempt_disable();
-
 	struct cpu_info *ci = curcpu();
 	struct pmap *pm = &efirt_pmap;
 	struct pmap_asid_info * const pai = PMAP_PAI(pm, cpu_tlb_info(ci));
@@ -1577,8 +1575,6 @@ pmap_deactivate_efirt(void)
 	pm->pm_activated = false;
 
 	PMAP_COUNT(deactivate);
-
-	kpreempt_enable();
 }
 #endif
 

Reply via email to