CVS commit: src/sys/arch/aarch64/aarch64

2024-06-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 30 17:55:52 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c

Log Message:
aarch64: print NUMA ID


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/aarch64/aarch64/cpu.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/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.76 src/sys/arch/aarch64/aarch64/cpu.c:1.77
--- src/sys/arch/aarch64/aarch64/cpu.c:1.76	Thu May  9 12:41:08 2024
+++ src/sys/arch/aarch64/aarch64/cpu.c	Sun Jun 30 17:55:52 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.76 2024/05/09 12:41:08 pho Exp $ */
+/* $NetBSD: cpu.c,v 1.77 2024/06/30 17:55:52 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.76 2024/05/09 12:41:08 pho Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.77 2024/06/30 17:55:52 jmcneill Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -272,8 +272,8 @@ cpu_identify(device_t self, struct cpu_i
 
 	aprint_naive("\n");
 	aprint_normal(": %s, id 0x%lx\n", model, ci->ci_cpuid);
-	aprint_normal_dev(ci->ci_dev, "package %u, core %u, smt %u\n",
-	ci->ci_package_id, ci->ci_core_id, ci->ci_smt_id);
+	aprint_normal_dev(ci->ci_dev, "package %u, core %u, smt %u, numa %u\n",
+	ci->ci_package_id, ci->ci_core_id, ci->ci_smt_id, ci->ci_numa_id);
 
 	if (ci->ci_index == 0) {
 		m = cpu_getmodel();



CVS commit: src/sys/arch/aarch64/aarch64

2024-06-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 30 17:55:52 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c

Log Message:
aarch64: print NUMA ID


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/arch/aarch64/aarch64/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2024-06-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 30 09:36:43 UTC 2024

Modified Files:
src/sys/arch/aarch64/include: vmparam.h

Log Message:
aarch64: Bump VM_PHYSSEG_MAX to match DRAM_BANKS / FDT_MEMORY_RANGES.

On aarch64 there is a single free list, so VM_PHYSSEG_MAX needs to be
the same as FDT_MEMORY_RANGES (which needs to be the same as DRAM_BANKS).
Future cleanup should be done to fold these into a single define.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/include/vmparam.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2024-06-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 30 09:36:43 UTC 2024

Modified Files:
src/sys/arch/aarch64/include: vmparam.h

Log Message:
aarch64: Bump VM_PHYSSEG_MAX to match DRAM_BANKS / FDT_MEMORY_RANGES.

On aarch64 there is a single free list, so VM_PHYSSEG_MAX needs to be
the same as FDT_MEMORY_RANGES (which needs to be the same as DRAM_BANKS).
Future cleanup should be done to fold these into a single define.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/include/vmparam.h

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/include/vmparam.h
diff -u src/sys/arch/aarch64/include/vmparam.h:1.20 src/sys/arch/aarch64/include/vmparam.h:1.21
--- src/sys/arch/aarch64/include/vmparam.h:1.20	Sun Apr 16 14:01:51 2023
+++ src/sys/arch/aarch64/include/vmparam.h	Sun Jun 30 09:36:43 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.20 2023/04/16 14:01:51 skrll Exp $ */
+/* $NetBSD: vmparam.h,v 1.21 2024/06/30 09:36:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -179,7 +179,7 @@
 #define AARCH64_KVA_TO_PA(va)	((paddr_t) ((va) & ~AARCH64_DIRECTMAP_MASK))
 
 /* */
-#define VM_PHYSSEG_MAX		64  /* XXX */
+#define VM_PHYSSEG_MAX		256  /* XXX */
 #define VM_PHYSSEG_STRAT	VM_PSTRAT_BSEARCH
 
 #define VM_NFREELIST		1



CVS commit: src/sys/arch/aarch64/aarch64

2024-06-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Jun 18 13:29:56 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: netbsd32_machdep.c

Log Message:
aarch64: cpu_getmcontext32: Fix sign compare for ras_lookup(9)

Now, compare with `(void *)-1` is done for x0, instead of w0.
No binary changes except for that.

Found by WARNS=5 build (as a module).


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/aarch64/aarch64/netbsd32_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/netbsd32_machdep.c
diff -u src/sys/arch/aarch64/aarch64/netbsd32_machdep.c:1.24 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c:1.25
--- src/sys/arch/aarch64/aarch64/netbsd32_machdep.c:1.24	Wed Feb  7 04:20:26 2024
+++ src/sys/arch/aarch64/aarch64/netbsd32_machdep.c	Tue Jun 18 13:29:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.24 2024/02/07 04:20:26 msaitoh Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.25 2024/06/18 13:29:56 rin Exp $	*/
 
 /*
  * Copyright (c) 2018 Ryo Shimizu
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.24 2024/02/07 04:20:26 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.25 2024/06/18 13:29:56 rin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -424,7 +424,7 @@ cpu_getmcontext32(struct lwp *l, mcontex
 {
 	struct trapframe * const tf = lwp_trapframe(l);
 	__greg32_t *gr = mcp->__gregs;
-	__greg32_t ras_pc;
+	void *ras_pc;
 
 	gr[_REG_R0]  = tf->tf_reg[0];
 	gr[_REG_R1]  = tf->tf_reg[1];
@@ -444,9 +444,9 @@ cpu_getmcontext32(struct lwp *l, mcontex
 	gr[_REG_R15] = tf->tf_pc;
 	gr[_REG_CPSR] = tf->tf_spsr;
 
-	if ((ras_pc = (__greg32_t)(uintptr_t)ras_lookup(l->l_proc,
-	(void *)(uintptr_t)gr[_REG_R15])) != -1) {
-		gr[_REG_R15] = ras_pc;
+	ras_pc = ras_lookup(l->l_proc, (void *)(uintptr_t)gr[_REG_R15]);
+	if (ras_pc != (void *)-1) {
+		gr[_REG_R15] = (__greg32_t)(uintptr_t)ras_pc;
 	}
 	*flagsp |= _UC_CPU;
 



CVS commit: src/sys/arch/aarch64/aarch64

2024-06-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Jun 18 13:29:56 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: netbsd32_machdep.c

Log Message:
aarch64: cpu_getmcontext32: Fix sign compare for ras_lookup(9)

Now, compare with `(void *)-1` is done for x0, instead of w0.
No binary changes except for that.

Found by WARNS=5 build (as a module).


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2024-06-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Jun 17 21:27:46 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: netbsd32_machdep_13.c
netbsd32_machdep_16.c

Log Message:
Include required headers


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/aarch64/netbsd32_machdep_13.c \
src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2024-06-17 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Mon Jun 17 21:27:46 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: netbsd32_machdep_13.c
netbsd32_machdep_16.c

Log Message:
Include required headers


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/aarch64/netbsd32_machdep_13.c \
src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.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/netbsd32_machdep_13.c
diff -u src/sys/arch/aarch64/aarch64/netbsd32_machdep_13.c:1.3 src/sys/arch/aarch64/aarch64/netbsd32_machdep_13.c:1.4
--- src/sys/arch/aarch64/aarch64/netbsd32_machdep_13.c:1.3	Sun Nov 14 15:12:01 2021
+++ src/sys/arch/aarch64/aarch64/netbsd32_machdep_13.c	Mon Jun 17 21:27:46 2024
@@ -29,12 +29,14 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: netbsd32_machdep_13.c,v 1.3 2021/11/14 15:12:01 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: netbsd32_machdep_13.c,v 1.4 2024/06/17 21:27:46 pgoyette Exp $");
 
 #if defined (_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
 #endif
 
+#include 
+
 void
 netbsd32_machdep_md_13_init(void)
 {
Index: src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.c
diff -u src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.c:1.3 src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.c:1.4
--- src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.c:1.3	Sun Nov 14 15:12:01 2021
+++ src/sys/arch/aarch64/aarch64/netbsd32_machdep_16.c	Mon Jun 17 21:27:46 2024
@@ -29,12 +29,14 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: netbsd32_machdep_16.c,v 1.3 2021/11/14 15:12:01 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: netbsd32_machdep_16.c,v 1.4 2024/06/17 21:27:46 pgoyette Exp $");
 
 #if defined (_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
 #endif
 
+#include 
+
 void
 netbsd32_machdep_md_16_init(void)
 {



CVS commit: src/sys/arch/aarch64/include

2024-05-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May  5 15:18:10 UTC 2024

Modified Files:
src/sys/arch/aarch64/include: sljit_machdep.h

Log Message:
aarch64/sljit_machdep.h: Make this work in compat32 context.

Should fix clang build of compat32 eabi libsljit:

dependall ===> compat/arm/eabi/../../../lib/../external/bsd/sljit/lib
In file included from 
/home/source/ab/HEAD-llvm/src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c:1678:
/home/source/ab/HEAD-llvm/src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_64.c:142:54:
 error: shift count >= width of type [-Werror,-Wshift-count-overflow]
FAIL_IF(push_inst(compiler, MOVK | RD(dst) | (((imm >> 32) & 0x) << 
5) | (2 << 21)));
^  ~~


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/sljit_machdep.h

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/include/sljit_machdep.h
diff -u src/sys/arch/aarch64/include/sljit_machdep.h:1.4 src/sys/arch/aarch64/include/sljit_machdep.h:1.5
--- src/sys/arch/aarch64/include/sljit_machdep.h:1.4	Tue Apr  2 22:37:34 2024
+++ src/sys/arch/aarch64/include/sljit_machdep.h	Sun May  5 15:18:10 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sljit_machdep.h,v 1.4 2024/04/02 22:37:34 riastradh Exp $	*/
+/*	$NetBSD: sljit_machdep.h,v 1.5 2024/05/05 15:18:10 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 Alexander Nasonov.
@@ -29,6 +29,12 @@
 #ifndef _AARCH64_SLJITARCH_H
 #define _AARCH64_SLJITARCH_H
 
+#ifndef __aarch64__		/* compat32 */
+
+#include 
+
+#else  /* __aarch64__ */
+
 #include 
 
 #ifdef _KERNEL
@@ -56,4 +62,6 @@
 	(void)__builtin___clear_cache((char *)(from), (char *)(to))
 #endif
 
-#endif
+#endif	/* __aarch64__ (vs compat32) */
+
+#endif	/* _AARCH64_SLJITARCH_H */



CVS commit: src/sys/arch/aarch64/include

2024-05-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May  5 15:18:10 UTC 2024

Modified Files:
src/sys/arch/aarch64/include: sljit_machdep.h

Log Message:
aarch64/sljit_machdep.h: Make this work in compat32 context.

Should fix clang build of compat32 eabi libsljit:

dependall ===> compat/arm/eabi/../../../lib/../external/bsd/sljit/lib
In file included from 
/home/source/ab/HEAD-llvm/src/sys/external/bsd/sljit/dist/sljit_src/sljitLir.c:1678:
/home/source/ab/HEAD-llvm/src/sys/external/bsd/sljit/dist/sljit_src/sljitNativeARM_64.c:142:54:
 error: shift count >= width of type [-Werror,-Wshift-count-overflow]
FAIL_IF(push_inst(compiler, MOVK | RD(dst) | (((imm >> 32) & 0x) << 
5) | (2 << 21)));
^  ~~


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/sljit_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2024-04-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Apr 14 12:51:17 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: cpu_machdep.c sig_machdep.c

Log Message:
kern/58149: aarch64: Cannot return from a signal handler if SP was misaligned 
when the signal arrived

Apply the kernel diff from the PR

1. sendsig_siginfo() previously assumed that user SP was always aligned to
   16 bytes and could call signal handlers with SP misaligned. This is a
   wrong assumption because aarch64 demands that SP is aligned *only while*
   it's being used to access memory. Now it properly aligns it before
   pusing anything on the stack.

2. cpu_mcontext_validate() used to check if _REG_SP was aligned and
   considered the ucontext invalid otherwise. This meant if a signal was
   sent to a process whose SP was misaligned, the signal handler would fail
   to return because the ucontext passed from the kernel was an invalid
   one. Now setcontext(2) doesn't complain about misaligned SP.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/aarch64/aarch64/cpu_machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/sig_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/cpu_machdep.c
diff -u src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.14 src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.15
--- src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.14	Sat Feb 25 00:40:22 2023
+++ src/sys/arch/aarch64/aarch64/cpu_machdep.c	Sun Apr 14 12:51:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_machdep.c,v 1.14 2023/02/25 00:40:22 riastradh Exp $ */
+/* $NetBSD: cpu_machdep.c,v 1.15 2024/04/14 12:51:16 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.14 2023/02/25 00:40:22 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.15 2024/04/14 12:51:16 skrll Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -158,9 +158,13 @@ dosoftints(void)
 int
 cpu_mcontext_validate(struct lwp *l, const mcontext_t *mcp)
 {
+	/*
+	 * We intentionally don't verify that _REG_SP is aligned to
+	 * 16-bytes boundaries because it can be legally misaligned as long
+	 * as it's not used for accessing memory.
+	 */
 	if ((mcp->__gregs[_REG_SPSR] & ~SPSR_NZCV)
-	|| (mcp->__gregs[_REG_PC] & 3)
-	|| (mcp->__gregs[_REG_SP] & 15))
+	|| (mcp->__gregs[_REG_PC] & 3))
 		return EINVAL;
 
 	return 0;

Index: src/sys/arch/aarch64/aarch64/sig_machdep.c
diff -u src/sys/arch/aarch64/aarch64/sig_machdep.c:1.8 src/sys/arch/aarch64/aarch64/sig_machdep.c:1.9
--- src/sys/arch/aarch64/aarch64/sig_machdep.c:1.8	Mon Nov  1 05:07:15 2021
+++ src/sys/arch/aarch64/aarch64/sig_machdep.c	Sun Apr 14 12:51:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: sig_machdep.c,v 1.8 2021/11/01 05:07:15 thorpej Exp $ */
+/* $NetBSD: sig_machdep.c,v 1.9 2024/04/14 12:51:16 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: sig_machdep.c,v 1.8 2021/11/01 05:07:15 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sig_machdep.c,v 1.9 2024/04/14 12:51:16 skrll Exp $");
 
 #include 
 #include 
@@ -58,8 +58,14 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 
 	vaddr_t sp;
 
-	sp = onstack_p ? ((vaddr_t)ss->ss_sp + ss->ss_size) & -16 : tf->tf_sp;
+	/*
+	 * The user stack isn't guaranteed to be aligned to 16 bytes. Align
+	 * it before pushing anything onto it.
+	 */
+	sp = onstack_p ? ((vaddr_t)ss->ss_sp + ss->ss_size) : tf->tf_sp;
+	sp &= -16;
 
+	__CTASSERT(sizeof(ucontext_t) % 16 == 0);
 	sp -= sizeof(ucontext_t);
 	const vaddr_t ucp = sp;
 



CVS commit: src/sys/arch/aarch64/aarch64

2024-04-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Apr 14 12:51:17 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: cpu_machdep.c sig_machdep.c

Log Message:
kern/58149: aarch64: Cannot return from a signal handler if SP was misaligned 
when the signal arrived

Apply the kernel diff from the PR

1. sendsig_siginfo() previously assumed that user SP was always aligned to
   16 bytes and could call signal handlers with SP misaligned. This is a
   wrong assumption because aarch64 demands that SP is aligned *only while*
   it's being used to access memory. Now it properly aligns it before
   pusing anything on the stack.

2. cpu_mcontext_validate() used to check if _REG_SP was aligned and
   considered the ucontext invalid otherwise. This meant if a signal was
   sent to a process whose SP was misaligned, the signal handler would fail
   to return because the ucontext passed from the kernel was an invalid
   one. Now setcontext(2) doesn't complain about misaligned SP.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/aarch64/aarch64/cpu_machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/sig_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64

2024-02-18 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Feb 18 09:03:44 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c
src/sys/arch/aarch64/conf: files.aarch64

Log Message:
Change KDB to KGDB, including "sys/kgdb.h", which were likely meant to be 
defined.

Also comment out kgdb_machdep.c in files.aarch64, it doesn't exist yet.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/aarch64/conf/files.aarch64

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/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.50 src/sys/arch/aarch64/aarch64/trap.c:1.51
--- src/sys/arch/aarch64/aarch64/trap.c:1.50	Wed Oct  4 20:28:05 2023
+++ src/sys/arch/aarch64/aarch64/trap.c	Sun Feb 18 09:03:44 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.50 2023/10/04 20:28:05 ad Exp $ */
+/* $NetBSD: trap.c,v 1.51 2024/02/18 09:03:44 andvar Exp $ */
 
 /*-
  * Copyright (c) 2014, 2023 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.50 2023/10/04 20:28:05 ad Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.51 2024/02/18 09:03:44 andvar Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -43,8 +43,8 @@ __KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.5
 #include 
 #include 
 #include 
-#ifdef KDB
-#include 
+#ifdef KGDB
+#include 
 #endif
 #include 
 #include 
@@ -73,7 +73,7 @@ __KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.5
 
 #include 
 
-#ifdef KDB
+#ifdef KGDB
 #include 
 #endif
 #ifdef DDB

Index: src/sys/arch/aarch64/conf/files.aarch64
diff -u src/sys/arch/aarch64/conf/files.aarch64:1.43 src/sys/arch/aarch64/conf/files.aarch64:1.44
--- src/sys/arch/aarch64/conf/files.aarch64:1.43	Thu Apr 20 08:28:02 2023
+++ src/sys/arch/aarch64/conf/files.aarch64	Sun Feb 18 09:03:44 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aarch64,v 1.43 2023/04/20 08:28:02 skrll Exp $
+#	$NetBSD: files.aarch64,v 1.44 2024/02/18 09:03:44 andvar Exp $
 
 defflag opt_cpuoptions.h	AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h	AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -68,7 +68,7 @@ file	arch/aarch64/aarch64/db_interface.c
 file	arch/aarch64/aarch64/db_trace.c			ddb
 file	arch/aarch64/aarch64/db_machdep.c		ddb
 file	arch/aarch64/aarch64/disasm.c			ddb
-file	arch/aarch64/aarch64/kgdb_machdep.c		kgdb
+#file	arch/aarch64/aarch64/kgdb_machdep.c		kgdb # XXX: not implemented
 
 # mainbus files
 device	mainbus { [addr = -1], [size = 0], [intr = -1] }



CVS commit: src/sys/arch/aarch64

2024-02-18 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Feb 18 09:03:44 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: trap.c
src/sys/arch/aarch64/conf: files.aarch64

Log Message:
Change KDB to KGDB, including "sys/kgdb.h", which were likely meant to be 
defined.

Also comment out kgdb_machdep.c in files.aarch64, it doesn't exist yet.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/aarch64/conf/files.aarch64

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2024-02-16 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Feb 16 21:32:17 UTC 2024

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

Log Message:
Replace obsolete pv_dump() call with pmap_db_mdpg_print().

It was rewritten on rev 1.107, but not replaced with new implementation in
PMAP_PV_DEBUG guarded block.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 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.150 src/sys/arch/aarch64/aarch64/pmap.c:1.151
--- src/sys/arch/aarch64/aarch64/pmap.c:1.150	Wed Feb  7 04:20:26 2024
+++ src/sys/arch/aarch64/aarch64/pmap.c	Fri Feb 16 21:32:17 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.150 2024/02/07 04:20:26 msaitoh Exp $	*/
+/*	$NetBSD: pmap.c,v 1.151 2024/02/16 21:32:17 andvar Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.150 2024/02/07 04:20:26 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.151 2024/02/16 21:32:17 andvar Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1192,7 +1192,7 @@ _pmap_enter_pv(struct pmap_page *pp, str
 
 #ifdef PMAP_PV_DEBUG
 	printf("pv %p alias added va=%016lx -> pa=%016lx\n", pv, va, pa);
-	pv_dump(pp, printf);
+	pmap_db_mdpg_print(PHYS_TO_VM_PAGE(pa), printf);
 #endif
 
 	return 0;



CVS commit: src/sys/arch/aarch64/aarch64

2024-02-16 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Feb 16 21:32:17 UTC 2024

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

Log Message:
Replace obsolete pv_dump() call with pmap_db_mdpg_print().

It was rewritten on rev 1.107, but not replaced with new implementation in
PMAP_PV_DEBUG guarded block.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 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.



CVS commit: src/sys/arch/aarch64/aarch64

2024-02-16 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Feb 16 17:18:19 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: kobj_machdep.c

Log Message:
Fix closing bracket for strdisasm() function.

Fixes KOBJ_MACHDEP_DEBUG enabled build for aarch64.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/kobj_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2024-02-16 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Feb 16 17:18:19 UTC 2024

Modified Files:
src/sys/arch/aarch64/aarch64: kobj_machdep.c

Log Message:
Fix closing bracket for strdisasm() function.

Fixes KOBJ_MACHDEP_DEBUG enabled build for aarch64.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/kobj_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/kobj_machdep.c
diff -u src/sys/arch/aarch64/aarch64/kobj_machdep.c:1.8 src/sys/arch/aarch64/aarch64/kobj_machdep.c:1.9
--- src/sys/arch/aarch64/aarch64/kobj_machdep.c:1.8	Wed Feb  7 04:20:26 2024
+++ src/sys/arch/aarch64/aarch64/kobj_machdep.c	Fri Feb 16 17:18:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: kobj_machdep.c,v 1.8 2024/02/07 04:20:26 msaitoh Exp $	*/
+/*	$NetBSD: kobj_machdep.c,v 1.9 2024/02/16 17:18:19 andvar Exp $	*/
 
 /*
  * Copyright (c) 2018 Ryo Shimizu
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.8 2024/02/07 04:20:26 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.9 2024/02/16 17:18:19 andvar Exp $");
 
 #define ELFSIZE		ARCH_ELFSIZE
 
@@ -190,7 +190,7 @@ kobj_reloc(kobj_t ko, uintptr_t relocbas
 	old = *where;
 #ifdef DDB
 	snprintf(disasmbuf, sizeof(disasmbuf), "%08x %s",
-	le32toh(*insn), strdisasm((vaddr_t)insn), 0);
+	le32toh(*insn), strdisasm((vaddr_t)insn, 0));
 #endif
 #endif /* KOBJ_MACHDEP_DEBUG */
 



CVS commit: src/sys/arch/aarch64/include

2024-01-03 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Wed Jan  3 18:13:19 UTC 2024

Modified Files:
src/sys/arch/aarch64/include: armreg.h

Log Message:
ddress->address in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/aarch64/include/armreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2024-01-03 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Wed Jan  3 18:13:19 UTC 2024

Modified Files:
src/sys/arch/aarch64/include: armreg.h

Log Message:
ddress->address in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/aarch64/include/armreg.h

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/include/armreg.h
diff -u src/sys/arch/aarch64/include/armreg.h:1.65 src/sys/arch/aarch64/include/armreg.h:1.66
--- src/sys/arch/aarch64/include/armreg.h:1.65	Sun Sep 24 10:13:44 2023
+++ src/sys/arch/aarch64/include/armreg.h	Wed Jan  3 18:13:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: armreg.h,v 1.65 2023/09/24 10:13:44 skrll Exp $ */
+/* $NetBSD: armreg.h,v 1.66 2024/01/03 18:13:19 andvar Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -1153,7 +1153,7 @@ AARCH64REG_WRITE_INLINE(tcr_el2)
 #define TCR_EL2_DS		__BIT(32)	// 52-bit output address (FEAT_LPA2)
 //__BIT(31)	// Res1
 #define TCR_EL2_TCMA		__BIT(30)	// Unchecked accesses control (FEAT_MTE2)
-#define TCR_EL2_TBID		__BIT(29)	// Top Byte Instruction ddress matching (FEAT_PAuth)
+#define TCR_EL2_TBID		__BIT(29)	// Top Byte Instruction address matching (FEAT_PAuth)
 #define TCR_EL2_HWU62		__BIT(28)	// Hardware use bit 62 (FEAT_HPDS2)
 #define TCR_EL2_HWU61		__BIT(27)	// Hardware use bit 61 (FEAT_HPDS2)
 #define TCR_EL2_HWU60		__BIT(26)	// Hardware use bit 60 (FEAT_HPDS2)



CVS commit: src/sys/arch/aarch64/include

2023-09-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Sep 24 10:13:44 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: armreg.h

Log Message:
Add a bunch of system registers and their bit / bit field definitions.
Taken from ryo's nvmm branch with updates from me.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/aarch64/include/armreg.h

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/include/armreg.h
diff -u src/sys/arch/aarch64/include/armreg.h:1.64 src/sys/arch/aarch64/include/armreg.h:1.65
--- src/sys/arch/aarch64/include/armreg.h:1.64	Sat May  6 21:53:26 2023
+++ src/sys/arch/aarch64/include/armreg.h	Sun Sep 24 10:13:44 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: armreg.h,v 1.64 2023/05/06 21:53:26 andvar Exp $ */
+/* $NetBSD: armreg.h,v 1.65 2023/09/24 10:13:44 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -229,7 +229,13 @@ AARCH64REG_READ_INLINE(clidr_el1)
 #define	 CLIDR_TYPE_IDCACHE	 3		//  Separate inst and data caches
 #define	 CLIDR_TYPE_UNIFIEDCACHE 4		//  Unified cache
 
+AARCH64REG_READ_INLINE(contextidr_el1)
+AARCH64REG_WRITE_INLINE(contextidr_el1)
+
 AARCH64REG_READ_INLINE(currentel)
+
+#define	CURRENTEL_EL		__BITS(3,2)	// Current exception Level
+
 AARCH64REG_READ_INLINE(id_aa64afr0_el1)
 AARCH64REG_READ_INLINE(id_aa64afr1_el1)
 AARCH64REG_READ_INLINE(id_aa64dfr0_el1)
@@ -661,6 +667,8 @@ AARCH64REG_WRITE_INLINE(esr_el1)
 #define	 ESR_EC_CP14_DT		 0x06	// A32: LDC/STC access to CP14
 #define	 ESR_EC_FP_ACCESS	 0x07	// AXX: Access to SIMD/FP Registers
 #define	 ESR_EC_FPID		 0x08	// A32: MCR/MRC access to CP10 !EC=7
+#define	 ESR_EC_PAUTH		 0x09	// A64: Pointer auth trap (FEAT_PAUTH)
+#define	 ESR_EC_LS64		 0x0a	// AXX: LD64B/ST64B instruction (FEAT_LS64)		// XXXNH
 #define	 ESR_EC_CP14_RRT	 0x0c	// A32: MRRC access to CP14
 #define	 ESR_EC_BTE_A64		 0x0d	// A64: Branch Target Exception (V8.5)
 #define	 ESR_EC_ILL_STATE	 0x0e	// AXX: Illegal Execution State
@@ -671,29 +679,54 @@ AARCH64REG_WRITE_INLINE(esr_el1)
 #define	 ESR_EC_HVC_A64		 0x16	// A64: HVC Instruction Execution
 #define	 ESR_EC_SMC_A64		 0x17	// A64: SMC Instruction Execution
 #define	 ESR_EC_SYS_REG		 0x18	// A64: MSR/MRS/SYS instruction (!EC0/1/7)
-#define	 ESR_EC_INSN_ABT_EL0	 0x20	// AXX: Instruction Abort (EL0)
-#define	 ESR_EC_INSN_ABT_EL1	 0x21	// AXX: Instruction Abort (EL1)
+#define	 ESR_EC_SVE		 0x19	// AXX: SVE Instruction Execution (FEAT_SVE)
+#define	 ESR_EC_PAUTH_ERET	 0x1a	// A64: ERET/ERETAA/ERETAB (FEAT_PAUTH and FEAT_NV)
+#define	 ESR_EC_TME		 0x1b	// A64: TSTART instruction (FEAT_TME)
+#define	 ESR_EC_FRAC		 0x1c	// A64: Pointer auth trap (FEAT_FPAC)
+#define	 ESR_EC_SME		 0x1d	// AXX: Access to SME (FEAT_SME)
+#define	 ESR_EC_RME		 0x1e	// A64: Granule Protection  Check (FEAT_RME)
+#define	 ESR_EC_INSN_ABT_EL_LOW	 0x20	// AXX: Instruction Abort from lower level
+#define	 ESR_EC_INSN_ABT_EL_CUR	 0x21	// AXX: Instruction Abort from current level
 #define	 ESR_EC_PC_ALIGNMENT	 0x22	// AXX: Misaligned PC
-#define	 ESR_EC_DATA_ABT_EL0	 0x24	// AXX: Data Abort (EL0)
-#define	 ESR_EC_DATA_ABT_EL1	 0x25	// AXX: Data Abort (EL1)
-#define	 ESR_EC_SP_ALIGNMENT 	 0x26	// AXX: Misaligned SP
+#define	 ESR_EC_DATA_ABT_EL_LOW	 0x24	// AXX: Data Abort from lower level
+#define	 ESR_EC_DATA_ABT_EL_CUR	 0x25	// AXX: Data Abort from current level
+#define	 ESR_EC_SP_ALIGNMENT	 0x26	// AXX: Misaligned SP
+#define	 ESR_EC_MOPS		 0x27	// A64: Memory Operation Exception (FEAT_MOPS)
 #define	 ESR_EC_FP_TRAP_A32	 0x28	// A32: FP Exception
 #define	 ESR_EC_FP_TRAP_A64	 0x2c	// A64: FP Exception
-#define	 ESR_EC_SERROR	 	 0x2f	// AXX: SError Interrupt
-#define	 ESR_EC_BRKPNT_EL0	 0x30	// AXX: Breakpoint Exception (EL0)
-#define	 ESR_EC_BRKPNT_EL1	 0x31	// AXX: Breakpoint Exception (EL1)
-#define	 ESR_EC_SW_STEP_EL0	 0x32	// AXX: Software Step (EL0)
-#define	 ESR_EC_SW_STEP_EL1	 0x33	// AXX: Software Step (EL1)
-#define	 ESR_EC_WTCHPNT_EL0	 0x34	// AXX: Watchpoint (EL0)
-#define	 ESR_EC_WTCHPNT_EL1	 0x35	// AXX: Watchpoint (EL1)
+#define	 ESR_EC_SERROR		 0x2f	// AXX: SError Interrupt
+#define	 ESR_EC_BRKPNT_EL_LOW	 0x30	// AXX: Breakpoint Exception from lower level
+#define	 ESR_EC_BRKPNT_EL_CUR	 0x31	// AXX: Breakpoint Exception from current level
+#define	 ESR_EC_SW_STEP_EL_LOW	 0x32	// AXX: Software Step from lower level
+#define	 ESR_EC_SW_STEP_EL_CUR	 0x33	// AXX: Software Step from current level
+#define	 ESR_EC_WTCHPNT_EL_LOW	 0x34	// AXX: Watchpoint from lower level
+#define	 ESR_EC_WTCHPNT_EL_CUR	 0x35	// AXX: Watchpoint from current level
 #define	 ESR_EC_BKPT_INSN_A32	 0x38	// A32: BKPT Instruction Execution
 #define	 ESR_EC_VECTOR_CATCH	 0x3a	// A32: Vector Catch Exception
 #define	 ESR_EC_BKPT_INSN_A64	 0x3c	// A64: BKPT Instruction Execution
+/* alias for EL1 kernel */
+#define	 ESR_EC_INSN_ABT_EL0	 ESR_EC_INSN_ABT_EL_LOW
+#define	 

CVS commit: src/sys/arch/aarch64/include

2023-09-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Sep 24 10:13:44 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: armreg.h

Log Message:
Add a bunch of system registers and their bit / bit field definitions.
Taken from ryo's nvmm branch with updates from me.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/aarch64/include/armreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-08-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Aug  2 14:45:04 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: db_interface.c

Log Message:
Relax the TLB invalidation from full to by va for writing to kernel text
in db_write_text.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/aarch64/aarch64/db_interface.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-08-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Aug  2 14:45:04 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: db_interface.c

Log Message:
Relax the TLB invalidation from full to by va for writing to kernel text
in db_write_text.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/aarch64/aarch64/db_interface.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/db_interface.c
diff -u src/sys/arch/aarch64/aarch64/db_interface.c:1.22 src/sys/arch/aarch64/aarch64/db_interface.c:1.23
--- src/sys/arch/aarch64/aarch64/db_interface.c:1.22	Wed Nov  2 08:37:32 2022
+++ src/sys/arch/aarch64/aarch64/db_interface.c	Wed Aug  2 14:45:04 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: db_interface.c,v 1.22 2022/11/02 08:37:32 skrll Exp $ */
+/* $NetBSD: db_interface.c,v 1.23 2023/08/02 14:45:04 skrll Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.22 2022/11/02 08:37:32 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.23 2023/08/02 14:45:04 skrll Exp $");
 
 #include 
 #include 
@@ -171,7 +171,8 @@ db_write_text(vaddr_t addr, size_t size,
 		 */
 		/* old pte is returned by pmap_kvattr */
 		pte = pmap_kvattr(ptep, VM_PROT_EXECUTE | VM_PROT_READ | VM_PROT_WRITE);
-		aarch64_tlbi_all();
+		/* dsb(ishst) included in aarch64_tlbi_by_va */
+		aarch64_tlbi_by_va(addr);
 
 		s = size;
 		if (size > PAGE_SIZE)
@@ -182,7 +183,8 @@ db_write_text(vaddr_t addr, size_t size,
 
 		/* restore pte */
 		*ptep = pte;
-		aarch64_tlbi_all();
+		/* dsb(ishst) included in aarch64_tlbi_by_va */
+		aarch64_tlbi_by_va(addr);
 
 		addr += s;
 		size -= s;



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 07:00:32 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
blank line audit


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/include/pmap_machdep.h

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/include/pmap_machdep.h
diff -u src/sys/arch/aarch64/include/pmap_machdep.h:1.7 src/sys/arch/aarch64/include/pmap_machdep.h:1.8
--- src/sys/arch/aarch64/include/pmap_machdep.h:1.7	Wed Jul 26 06:58:34 2023
+++ src/sys/arch/aarch64/include/pmap_machdep.h	Wed Jul 26 07:00:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.h,v 1.7 2023/07/26 06:58:34 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.h,v 1.8 2023/07/26 07:00:31 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -388,7 +388,6 @@ pte_pde_set(pd_entry_t *pdep, pd_entry_t
 }
 
 
-
 static inline pt_entry_t
 pte_memattr(u_int flags)
 {
@@ -439,6 +438,7 @@ pte_make_kenter_pa(paddr_t pa, struct vm
 	return pte;
 }
 
+
 static inline pt_entry_t
 pte_make_enter_efirt(paddr_t pa, vm_prot_t prot, u_int flags)
 {
@@ -464,6 +464,7 @@ pte_make_enter_efirt(paddr_t pa, vm_prot
 	return npte;
 }
 
+
 static inline pt_entry_t
 pte_make_enter(paddr_t pa, const struct vm_page_md *mdpg, vm_prot_t prot,
 u_int flags, bool is_kernel_pmap_p)



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 07:00:32 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
blank line audit


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/aarch64/include/pmap_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 06:47:38 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
Reduce #ifdefs


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/include/pmap_machdep.h

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/include/pmap_machdep.h
diff -u src/sys/arch/aarch64/include/pmap_machdep.h:1.5 src/sys/arch/aarch64/include/pmap_machdep.h:1.6
--- src/sys/arch/aarch64/include/pmap_machdep.h:1.5	Wed Jul 26 06:45:41 2023
+++ src/sys/arch/aarch64/include/pmap_machdep.h	Wed Jul 26 06:47:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.h,v 1.5 2023/07/26 06:45:41 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.h,v 1.6 2023/07/26 06:47:38 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -204,9 +204,7 @@ pmap_md_nptep(pt_entry_t *ptep)
 	return ptep + 1;
 }
 
-#endif	/* __PMAP_PRIVATE */
 
-#ifdef __PMAP_PRIVATE
 static __inline paddr_t
 pte_to_paddr(pt_entry_t pte)
 {



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 06:47:38 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
Reduce #ifdefs


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/include/pmap_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 06:45:41 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
Wrap long lines in a comment block.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/pmap_machdep.h

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/include/pmap_machdep.h
diff -u src/sys/arch/aarch64/include/pmap_machdep.h:1.4 src/sys/arch/aarch64/include/pmap_machdep.h:1.5
--- src/sys/arch/aarch64/include/pmap_machdep.h:1.4	Wed Jul 26 06:43:53 2023
+++ src/sys/arch/aarch64/include/pmap_machdep.h	Wed Jul 26 06:45:41 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.h,v 1.4 2023/07/26 06:43:53 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.h,v 1.5 2023/07/26 06:45:41 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -321,11 +321,11 @@ pte_set(pt_entry_t *ptep, pt_entry_t pte
 	*ptep = pte;
 	dsb(ishst);
 	/*
-	 * if this mapping is going to be used by userland then the eret *can* act
-	 * as the isb, but might not (apple m1).
+	 * if this mapping is going to be used by userland then the eret *can*
+	 * act as the isb, but might not (apple m1).
 	 *
-	 * if this mapping is kernel then the isb is always needed (for some micro-
-	 * architectures)
+	 * if this mapping is kernel then the isb is always needed (for some
+	 * micro-architectures)
 	 */
 
 	isb();



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 06:45:41 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
Wrap long lines in a comment block.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/pmap_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 06:43:53 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
spaces to tabs.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/include/pmap_machdep.h

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/include/pmap_machdep.h
diff -u src/sys/arch/aarch64/include/pmap_machdep.h:1.3 src/sys/arch/aarch64/include/pmap_machdep.h:1.4
--- src/sys/arch/aarch64/include/pmap_machdep.h:1.3	Thu Apr 20 08:28:03 2023
+++ src/sys/arch/aarch64/include/pmap_machdep.h	Wed Jul 26 06:43:53 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.h,v 1.3 2023/04/20 08:28:03 skrll Exp $	*/
+/*	$NetBSD: pmap_machdep.h,v 1.4 2023/07/26 06:43:53 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -64,9 +64,9 @@
 #define	NSEGPG		(1 << SEGLENGTH)
 
 
-#ifndef __BSD_PTENTRY_T__
+#ifndef	__BSD_PTENTRY_T__
 #define	__BSD_PTENTRY_T__
-#define	PRIxPTE PRIx64
+#define	PRIxPTE		PRIx64
 #endif /* __BSD_PTENTRY_T__ */
 
 #define	KERNEL_PID	0
@@ -92,12 +92,14 @@ struct pmap_md {
 
 #define	pm_l0_pa	pm_md.pmd_l0_pa
 
-void pmap_md_pdetab_init(struct pmap *);
-void pmap_md_pdetab_fini(struct pmap *);
+void	pmap_md_pdetab_init(struct pmap *);
+void	pmap_md_pdetab_fini(struct pmap *);
 
-vaddr_t pmap_md_map_poolpage(paddr_t, size_t);
-paddr_t pmap_md_unmap_poolpage(vaddr_t, size_t);
-struct vm_page *pmap_md_alloc_poolpage(int);
+vaddr_t	pmap_md_map_poolpage(paddr_t, size_t);
+paddr_t	pmap_md_unmap_poolpage(vaddr_t, size_t);
+
+struct vm_page *
+	pmap_md_alloc_poolpage(int);
 
 bool	pmap_md_kernel_vaddr_p(vaddr_t);
 paddr_t	pmap_md_kernel_vaddr_to_paddr(vaddr_t);
@@ -140,7 +142,7 @@ struct pmap_page {
 static inline paddr_t
 pmap_l0pa(struct pmap *pm)
 {
-return pm->pm_l0_pa;
+	return pm->pm_l0_pa;
 }
 
 #if defined(__PMAP_PRIVATE)
@@ -159,7 +161,7 @@ bool	pmap_md_ok_to_steal_p(const uvm_phy
 void	pmap_md_xtab_activate(pmap_t, struct lwp *);
 void	pmap_md_xtab_deactivate(pmap_t);
 
-vaddr_t pmap_md_direct_map_paddr(paddr_t);
+vaddr_t	pmap_md_direct_map_paddr(paddr_t);
 
 
 #ifdef MULTIPROCESSOR
@@ -239,7 +241,7 @@ static inline bool
 pte_wired_p(pt_entry_t pte)
 {
 
-return (pte & LX_BLKPAG_OS_WIRED) != 0;
+	return (pte & LX_BLKPAG_OS_WIRED) != 0;
 }
 
 
@@ -247,7 +249,7 @@ static inline pt_entry_t
 pte_wire_entry(pt_entry_t pte)
 {
 
-return pte | LX_BLKPAG_OS_WIRED;
+	return pte | LX_BLKPAG_OS_WIRED;
 }
 
 
@@ -255,7 +257,7 @@ static inline pt_entry_t
 pte_unwire_entry(pt_entry_t pte)
 {
 
-return pte & ~LX_BLKPAG_OS_WIRED;
+	return pte & ~LX_BLKPAG_OS_WIRED;
 }
 
 



CVS commit: src/sys/arch/aarch64/include

2023-07-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jul 26 06:43:53 UTC 2023

Modified Files:
src/sys/arch/aarch64/include: pmap_machdep.h

Log Message:
spaces to tabs.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/include/pmap_machdep.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-07-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 16 21:36:40 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c trap.c

Log Message:
aarch64: Omit needless xcfunc_t casts by using xcfunc_t correctly.

No functional change intended, except for avoiding possible undefined
behaviour that could have made demons come flying out your nose.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/aarch64/aarch64/trap.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.69 src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.70
--- src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.69	Tue Apr 18 07:53:31 2023
+++ src/sys/arch/aarch64/aarch64/aarch64_machdep.c	Sun Jul 16 21:36:40 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.69 2023/04/18 07:53:31 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.70 2023/07/16 21:36:40 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.69 2023/04/18 07:53:31 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.70 2023/07/16 21:36:40 riastradh Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -454,18 +454,17 @@ initarm_common(vaddr_t kvm_base, vsize_t
 /*
  * machine dependent system variables.
  */
-static xcfunc_t
+static void
 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
@@ -487,8 +486,8 @@ sysctl_machdep_tagged_address(SYSCTLFN_A
 		return EINVAL;
 
 	if (cur != val) {
-		uint64_t where = xc_broadcast(0,
-		(xcfunc_t)set_user_tagged_address, UINT64TOPTR(val), NULL);
+		uint64_t where = xc_broadcast(0, set_user_tagged_address,
+		UINT64TOPTR(val), NULL);
 		xc_wait(where);
 	}
 

Index: src/sys/arch/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.48 src/sys/arch/aarch64/aarch64/trap.c:1.49
--- src/sys/arch/aarch64/aarch64/trap.c:1.48	Sat Feb 25 00:40:22 2023
+++ src/sys/arch/aarch64/aarch64/trap.c	Sun Jul 16 21:36:40 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.48 2023/02/25 00:40:22 riastradh Exp $ */
+/* $NetBSD: trap.c,v 1.49 2023/07/16 21:36:40 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.48 2023/02/25 00:40:22 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.49 2023/07/16 21:36:40 riastradh Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -274,7 +274,7 @@ trap_el1h_sync(struct trapframe *tf)
 	(CTR_EL0_DIC | CTR_EL0_IDC | CTR_EL0_DMIN_LINE | CTR_EL0_IMIN_LINE)
 uint64_t ctr_el0_usr __read_mostly;
 
-static xcfunc_t
+static void
 configure_cpu_traps0(void *arg1, void *arg2)
 {
 	struct cpu_info * const ci = curcpu();
@@ -307,7 +307,7 @@ configure_cpu_traps0(void *arg1, void *a
 		goto need_ctr_trap;
 #endif
 
-	return 0;
+	return;
 
  need_ctr_trap:
 	evcnt_attach_dynamic(>ci_uct_trap, EVCNT_TYPE_MISC, NULL,
@@ -317,8 +317,6 @@ configure_cpu_traps0(void *arg1, void *a
 	sctlr = reg_sctlr_el1_read();
 	sctlr &= ~SCTLR_UCT;
 	reg_sctlr_el1_write(sctlr);
-
-	return 0;
 }
 
 void
@@ -374,8 +372,7 @@ configure_cpu_traps(void)
 		}
 	}
 
-	where = xc_broadcast(0,
-	(xcfunc_t)configure_cpu_traps0, NULL, NULL);
+	where = xc_broadcast(0, configure_cpu_traps0, NULL, NULL);
 	xc_wait(where);
 }
 



CVS commit: src/sys/arch/aarch64/aarch64

2023-07-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 16 21:36:40 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c trap.c

Log Message:
aarch64: Omit needless xcfunc_t casts by using xcfunc_t correctly.

No functional change intended, except for avoiding possible undefined
behaviour that could have made demons come flying out your nose.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/aarch64/aarch64/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-06-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Jun 10 07:33:32 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpufunc.c

Log Message:
KASSERT(kpreempt_disabled()) before accessing curcpu() to reflect why
preemption needs to be disabled more clearly.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/aarch64/aarch64/cpufunc.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/cpufunc.c
diff -u src/sys/arch/aarch64/aarch64/cpufunc.c:1.34 src/sys/arch/aarch64/aarch64/cpufunc.c:1.35
--- src/sys/arch/aarch64/aarch64/cpufunc.c:1.34	Sat Feb 25 00:40:22 2023
+++ src/sys/arch/aarch64/aarch64/cpufunc.c	Sat Jun 10 07:33:32 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.c,v 1.34 2023/02/25 00:40:22 riastradh Exp $	*/
+/*	$NetBSD: cpufunc.c,v 1.35 2023/06/10 07:33:32 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -30,7 +30,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.34 2023/02/25 00:40:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.35 2023/06/10 07:33:32 skrll Exp $");
 
 #include 
 #include 
@@ -365,12 +365,12 @@ ln_dcache_inv_all(int level, struct aarc
 void
 aarch64_dcache_wbinv_all(void)
 {
+	KASSERT(kpreempt_disabled());
+
 	struct cpu_info * const ci = curcpu();
 	struct aarch64_cache_info * const cinfo = ci->ci_cacheinfo;
 	int level;
 
-	KASSERT(kpreempt_disabled());
-
 	for (level = 0; level < MAX_CACHE_LEVEL; level++) {
 		if (cinfo[level].cacheable == CACHE_CACHEABLE_NONE)
 			break;
@@ -384,12 +384,12 @@ aarch64_dcache_wbinv_all(void)
 void
 aarch64_dcache_inv_all(void)
 {
+	KASSERT(kpreempt_disabled());
+
 	struct cpu_info * const ci = curcpu();
 	struct aarch64_cache_info * const cinfo = ci->ci_cacheinfo;
 	int level;
 
-	KASSERT(kpreempt_disabled());
-
 	for (level = 0; level < MAX_CACHE_LEVEL; level++) {
 		if (cinfo[level].cacheable == CACHE_CACHEABLE_NONE)
 			break;
@@ -403,12 +403,12 @@ aarch64_dcache_inv_all(void)
 void
 aarch64_dcache_wb_all(void)
 {
+	KASSERT(kpreempt_disabled());
+
 	struct cpu_info * const ci = curcpu();
 	struct aarch64_cache_info * const cinfo = ci->ci_cacheinfo;
 	int level;
 
-	KASSERT(kpreempt_disabled());
-
 	for (level = 0; level < MAX_CACHE_LEVEL; level++) {
 		if (cinfo[level].cacheable == CACHE_CACHEABLE_NONE)
 			break;



CVS commit: src/sys/arch/aarch64/aarch64

2023-06-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Jun 10 07:33:32 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpufunc.c

Log Message:
KASSERT(kpreempt_disabled()) before accessing curcpu() to reflect why
preemption needs to be disabled more clearly.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/aarch64/aarch64/cpufunc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-04-18 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Apr 18 07:53:31 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c

Log Message:
G/C an outdated comment.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 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.68 src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.69
--- src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.68	Sun Apr 16 14:01:51 2023
+++ src/sys/arch/aarch64/aarch64/aarch64_machdep.c	Tue Apr 18 07:53:31 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.68 2023/04/16 14:01:51 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.69 2023/04/18 07:53:31 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.68 2023/04/16 14:01:51 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.69 2023/04/18 07:53:31 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -289,7 +289,6 @@ initarm_common(vaddr_t kvm_base, vsize_t
 	paddr_t kernstart_phys __unused = KERN_VTOPHYS(kernstart);
 	paddr_t kernend_phys __unused = KERN_VTOPHYS(kernend);
 
-	/* XXX: arm/arm32/bus_dma.c refers physical_{start,end} */
 	physical_start = bootconfig.dram[0].address;
 	physical_end = bootconfig.dram[bootconfig.dramblocks - 1].address +
 		   ptoa(bootconfig.dram[bootconfig.dramblocks - 1].pages);



CVS commit: src/sys/arch/aarch64/aarch64

2023-04-18 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Apr 18 07:53:31 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c

Log Message:
G/C an outdated comment.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 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.



CVS commit: src/sys/arch/aarch64/aarch64

2023-04-12 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Apr 12 06:57:28 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: pmap_machdep.c

Log Message:
Use CACHE_LINE_SIZE instead of magic number 128.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/aarch64/pmap_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/pmap_machdep.c
diff -u src/sys/arch/aarch64/aarch64/pmap_machdep.c:1.3 src/sys/arch/aarch64/aarch64/pmap_machdep.c:1.4
--- src/sys/arch/aarch64/aarch64/pmap_machdep.c:1.3	Sat Feb 25 00:40:22 2023
+++ src/sys/arch/aarch64/aarch64/pmap_machdep.c	Wed Apr 12 06:57:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_machdep.c,v 1.3 2023/02/25 00:40:22 riastradh Exp $	*/
+/*	$NetBSD: pmap_machdep.c,v 1.4 2023/04/12 06:57:28 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2022 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 #define __PMAP_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.3 2023/02/25 00:40:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.4 2023/04/12 06:57:28 skrll Exp $");
 
 #include 
 #include 
@@ -513,7 +513,8 @@ pmap_bootstrap(vaddr_t vstart, vaddr_t v
 #endif
 	IPL_NONE);
 
-	pmap_pvlist_lock_init(/*arm_dcache_align*/ 128);
+	// arm_dcache_align
+	pmap_pvlist_lock_init(CACHE_LINE_SIZE);
 
 	VPRINTF("done\n");
 }



CVS commit: src/sys/arch/aarch64/aarch64

2023-04-12 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Apr 12 06:57:28 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: pmap_machdep.c

Log Message:
Use CACHE_LINE_SIZE instead of magic number 128.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/aarch64/pmap_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-03-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar  1 08:17:24 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S

Log Message:
aarch64: Optimization: Omit needless membar when triggering softint.

When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/aarch64/aarch64/cpuswitch.S

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/cpuswitch.S
diff -u src/sys/arch/aarch64/aarch64/cpuswitch.S:1.40 src/sys/arch/aarch64/aarch64/cpuswitch.S:1.41
--- src/sys/arch/aarch64/aarch64/cpuswitch.S:1.40	Thu Feb 23 14:54:57 2023
+++ src/sys/arch/aarch64/aarch64/cpuswitch.S	Wed Mar  1 08:17:24 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuswitch.S,v 1.40 2023/02/23 14:54:57 riastradh Exp $ */
+/* $NetBSD: cpuswitch.S,v 1.41 2023/03/01 08:17:24 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include "opt_ddb.h"
 #include "opt_kasan.h"
 
-RCSID("$NetBSD: cpuswitch.S,v 1.40 2023/02/23 14:54:57 riastradh Exp $")
+RCSID("$NetBSD: cpuswitch.S,v 1.41 2023/03/01 08:17:24 riastradh Exp $")
 
 	ARMV8_DEFINE_OPTIONS
 
@@ -224,7 +224,13 @@ ENTRY_NP(cpu_switchto_softint)
 	msr	tpidr_el1, x0		/* curlwp = softlwp; */
 	dmb	ishst			/* for mutex_enter; see cpu_switchto */
 	str	x0, [x20, #CI_CURLWP]	/* curcpu()->ci_curlwp = softlwp; */
-	dmb	ish			/* for mutex_enter; see cpu_switchto */
+	/*
+	 * No need for barrier after ci->ci_curlwp = softlwp -- when we
+	 * enter a softint lwp, it can't be holding any mutexes, so it
+	 * can't release any until after it has acquired them, so we
+	 * need not participate in the protocol with mutex_vector_enter
+	 * barriers here.
+	 */
 
 	mov	x5, #CPACR_FPEN_NONE
 	msr	cpacr_el1, x5		/* cpacr_el1 = CPACR_FPEN_NONE */



CVS commit: src/sys/arch/aarch64/aarch64

2023-03-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar  1 08:17:24 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S

Log Message:
aarch64: Optimization: Omit needless membar when triggering softint.

When we are triggering a softint, it can't already hold any mutexes.
So any path to mutex_exit(mtx) must go via mutex_enter(mtx), which is
always done with atomic r/m/w, and we need not issue any explicit
barrier between ci->ci_curlwp = softlwp and a potential load of
mtx->mtx_owner in mutex_exit.

PR kern/57240

XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/aarch64/aarch64/cpuswitch.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Feb 25 08:00:35 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: vm_machdep.c

Log Message:
Add a KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/aarch64/vm_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/vm_machdep.c
diff -u src/sys/arch/aarch64/aarch64/vm_machdep.c:1.13 src/sys/arch/aarch64/aarch64/vm_machdep.c:1.14
--- src/sys/arch/aarch64/aarch64/vm_machdep.c:1.13	Sun May 29 16:13:41 2022
+++ src/sys/arch/aarch64/aarch64/vm_machdep.c	Sat Feb 25 08:00:35 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.13 2022/05/29 16:13:41 ryo Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.14 2023/02/25 08:00:35 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.13 2022/05/29 16:13:41 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.14 2023/02/25 08:00:35 skrll Exp $");
 
 #include 
 #include 
@@ -97,6 +97,7 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	 * FP state is valid.
 	 */
 	l2->l_md.md_cpacr = CPACR_FPEN_NONE;
+	KASSERT(l2->l_md.md_astpending == 0);
 
 #ifdef ARMV83_PAC
 	/*



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Feb 25 08:00:35 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: vm_machdep.c

Log Message:
Add a KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/aarch64/vm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:40:22 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch32_syscall.c cpu_machdep.c cpufunc.c
fault.c pmap_machdep.c syscall.c trap.c
src/sys/arch/aarch64/include: cpu.h

Log Message:
aarch64: curcpu() audit.

Sprinkle KASSERT (or KDASSERT in hot paths) for kpreempt_disabled()
when we use curcpu() and it's not immediately obvious that the caller
has preemption disabled but closer scrutiny suggests the caller has.

Note unsafe curcpu()s for syscall event counting.  Not sure this is
worth changing.

Possible bugs fixed:

- cpu_irq and cpu_fiq could be preempted while trying to run softints
  on this CPU.

- data_abort_handler might incorrectly think it was invoked in
  interrupt context when it was only preempted and migrated to
  another CPU.

- pmap_fault_fixup might report the wrong CPU logs.

(However, we don't currently run with kpreemption on aarch64, so
these are not yet real bugs fixed except if you patch it to build
with __HAVE_PREEMPTION.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/aarch64/aarch64/aarch32_syscall.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/aarch64/cpu_machdep.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/aarch64/aarch64/cpufunc.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/aarch64/aarch64/fault.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/aarch64/aarch64/pmap_machdep.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/aarch64/syscall.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/aarch64/include/cpu.h

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/aarch32_syscall.c
diff -u src/sys/arch/aarch64/aarch64/aarch32_syscall.c:1.6 src/sys/arch/aarch64/aarch64/aarch32_syscall.c:1.7
--- src/sys/arch/aarch64/aarch64/aarch32_syscall.c:1.6	Thu Nov 25 03:08:04 2021
+++ src/sys/arch/aarch64/aarch64/aarch32_syscall.c	Sat Feb 25 00:40:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: aarch32_syscall.c,v 1.6 2021/11/25 03:08:04 ryo Exp $	*/
+/*	$NetBSD: aarch32_syscall.c,v 1.7 2023/02/25 00:40:22 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2018 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aarch32_syscall.c,v 1.6 2021/11/25 03:08:04 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aarch32_syscall.c,v 1.7 2023/02/25 00:40:22 riastradh Exp $");
 
 #include 
 #include 
@@ -69,7 +69,7 @@ EMULNAME(syscall)(struct trapframe *tf)
 
 	LWP_CACHE_CREDS(l, p);
 
-	curcpu()->ci_data.cpu_nsyscall++;
+	curcpu()->ci_data.cpu_nsyscall++; /* XXX unsafe curcpu() */
 
 	thumbmode = (tf->tf_spsr & SPSR_A32_T) ? true : false;
 #ifdef SYSCALL_CODE_REG

Index: src/sys/arch/aarch64/aarch64/cpu_machdep.c
diff -u src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.13 src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.14
--- src/sys/arch/aarch64/aarch64/cpu_machdep.c:1.13	Thu Jul 28 09:14:12 2022
+++ src/sys/arch/aarch64/aarch64/cpu_machdep.c	Sat Feb 25 00:40:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_machdep.c,v 1.13 2022/07/28 09:14:12 riastradh Exp $ */
+/* $NetBSD: cpu_machdep.c,v 1.14 2023/02/25 00:40:22 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.13 2022/07/28 09:14:12 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.14 2023/02/25 00:40:22 riastradh Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -116,6 +116,8 @@ dosoftints(void)
 	const uint32_t softiplmask = SOFTIPLMASK(opl);
 	int s;
 
+	KDASSERT(kpreempt_disabled());
+
 	s = splhigh();
 	KASSERT(s == opl);
 	for (;;) {

Index: src/sys/arch/aarch64/aarch64/cpufunc.c
diff -u src/sys/arch/aarch64/aarch64/cpufunc.c:1.33 src/sys/arch/aarch64/aarch64/cpufunc.c:1.34
--- src/sys/arch/aarch64/aarch64/cpufunc.c:1.33	Mon Jan 31 09:16:09 2022
+++ src/sys/arch/aarch64/aarch64/cpufunc.c	Sat Feb 25 00:40:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.c,v 1.33 2022/01/31 09:16:09 ryo Exp $	*/
+/*	$NetBSD: cpufunc.c,v 1.34 2023/02/25 00:40:22 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -30,7 +30,7 @@
 #include "opt_multiprocessor.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.33 2022/01/31 09:16:09 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.34 2023/02/25 00:40:22 riastradh Exp $");
 
 #include 
 #include 
@@ -369,6 +369,8 @@ aarch64_dcache_wbinv_all(void)
 	struct aarch64_cache_info * const cinfo = ci->ci_cacheinfo;
 	int level;
 
+	KASSERT(kpreempt_disabled());
+
 	for (level = 0; level < MAX_CACHE_LEVEL; level++) {
 		if (cinfo[level].cacheable == CACHE_CACHEABLE_NONE)
 			break;
@@ -386,6 +388,8 @@ aarch64_dcache_inv_all(void)
 	struct aarch64_cache_info * const cinfo = ci->ci_cacheinfo;
 	int level;
 
+	KASSERT(kpreempt_disabled());
+
 	for (level = 0; level < MAX_CACHE_LEVEL; level++) {
 		if 

CVS commit: src/sys/arch/aarch64

2023-02-24 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Feb 25 00:40:22 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: aarch32_syscall.c cpu_machdep.c cpufunc.c
fault.c pmap_machdep.c syscall.c trap.c
src/sys/arch/aarch64/include: cpu.h

Log Message:
aarch64: curcpu() audit.

Sprinkle KASSERT (or KDASSERT in hot paths) for kpreempt_disabled()
when we use curcpu() and it's not immediately obvious that the caller
has preemption disabled but closer scrutiny suggests the caller has.

Note unsafe curcpu()s for syscall event counting.  Not sure this is
worth changing.

Possible bugs fixed:

- cpu_irq and cpu_fiq could be preempted while trying to run softints
  on this CPU.

- data_abort_handler might incorrectly think it was invoked in
  interrupt context when it was only preempted and migrated to
  another CPU.

- pmap_fault_fixup might report the wrong CPU logs.

(However, we don't currently run with kpreemption on aarch64, so
these are not yet real bugs fixed except if you patch it to build
with __HAVE_PREEMPTION.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/aarch64/aarch64/aarch32_syscall.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/aarch64/cpu_machdep.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/aarch64/aarch64/cpufunc.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/aarch64/aarch64/fault.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/aarch64/aarch64/pmap_machdep.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/aarch64/syscall.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/aarch64/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Feb 23 14:54:57 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S locore.S

Log Message:
aarch64: Add missing barriers in cpu_switchto.

Details in comments.

Note: This is a conservative change that inserts a barrier where
there was a comment saying none is needed, which is probably correct.
The goal of this change is to systematically add barriers to be
confident in correctness; subsequent changes may remove some bariers,
as an optimization, with an explanation of why each barrier is not
needed.

PR kern/57240

XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/aarch64/aarch64/locore.S

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/cpuswitch.S
diff -u src/sys/arch/aarch64/aarch64/cpuswitch.S:1.39 src/sys/arch/aarch64/aarch64/cpuswitch.S:1.40
--- src/sys/arch/aarch64/aarch64/cpuswitch.S:1.39	Mon Sep 19 17:23:14 2022
+++ src/sys/arch/aarch64/aarch64/cpuswitch.S	Thu Feb 23 14:54:57 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuswitch.S,v 1.39 2022/09/19 17:23:14 ryo Exp $ */
+/* $NetBSD: cpuswitch.S,v 1.40 2023/02/23 14:54:57 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include "opt_ddb.h"
 #include "opt_kasan.h"
 
-RCSID("$NetBSD: cpuswitch.S,v 1.39 2022/09/19 17:23:14 ryo Exp $")
+RCSID("$NetBSD: cpuswitch.S,v 1.40 2023/02/23 14:54:57 riastradh Exp $")
 
 	ARMV8_DEFINE_OPTIONS
 
@@ -125,8 +125,29 @@ ENTRY_NP(cpu_switchto)
 
 	msr	tpidr_el1, x1		/* switch curlwp to new lwp */
 	ldr	x3, [x1, #L_CPU]
+
+	/*
+	 * Issue barriers to coordinate mutex_exit on this CPU with
+	 * mutex_vector_enter on another CPU.
+	 *
+	 * 1. Any prior mutex_exit by oldlwp must be visible to other
+	 *CPUs before we set ci_curlwp := newlwp on this one,
+	 *requiring a store-before-store barrier.
+	 *
+	 * 2. ci_curlwp := newlwp must be visible on all other CPUs
+	 *before any subsequent mutex_exit by newlwp can even test
+	 *whether there might be waiters, requiring a
+	 *store-before-load barrier.
+	 *
+	 * See kern_mutex.c for details -- this is necessary for
+	 * adaptive mutexes to detect whether the lwp is on the CPU in
+	 * order to safely block without requiring atomic r/m/w in
+	 * mutex_exit.
+	 */
+	dmb	ishst			/* store-before-store */
 	str	x1, [x3, #CI_CURLWP]	/* switch curlwp to new lwp */
-	dmb	ishst			/* see comments in kern_mutex.c */
+	dmb	ish			/* store-before-load */
+
 	ENABLE_INTERRUPT
 
 	/*
@@ -201,8 +222,9 @@ ENTRY_NP(cpu_switchto_softint)
 	/* onto new stack */
 	sub	sp, x4, #TF_SIZE	/* new sp := softlwp->l_md_utf - 1 */
 	msr	tpidr_el1, x0		/* curlwp = softlwp; */
+	dmb	ishst			/* for mutex_enter; see cpu_switchto */
 	str	x0, [x20, #CI_CURLWP]	/* curcpu()->ci_curlwp = softlwp; */
-	/* no need for memory barrier here */
+	dmb	ish			/* for mutex_enter; see cpu_switchto */
 
 	mov	x5, #CPACR_FPEN_NONE
 	msr	cpacr_el1, x5		/* cpacr_el1 = CPACR_FPEN_NONE */
@@ -244,8 +266,9 @@ ENTRY_NP(cpu_switchto_softint)
 	DISABLE_INTERRUPT
 	msr	tpidr_el1, x19		/* curlwp = pinned_lwp */
 	ldr	x3, [x19, #L_CPU]	/* x3 = curlwp->l_cpu */
+	dmb	ishst			/* for mutex_enter; see cpu_switchto */
 	str	x19, [x3, #CI_CURLWP]	/* curlwp->l_cpu->ci_curlwp := x19 */
-	dmb	ishst			/* see comments in kern_mutex.c */
+	dmb	ish			/* for mutex_enter; see cpu_switchto */
 
 	mov	sp, x4			/* restore pinned_lwp sp */
 	msr	cpacr_el1, x5		/* restore pinned_lwp cpacr */

Index: src/sys/arch/aarch64/aarch64/locore.S
diff -u src/sys/arch/aarch64/aarch64/locore.S:1.90 src/sys/arch/aarch64/aarch64/locore.S:1.91
--- src/sys/arch/aarch64/aarch64/locore.S:1.90	Fri Feb 17 06:24:26 2023
+++ src/sys/arch/aarch64/aarch64/locore.S	Thu Feb 23 14:54:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.90 2023/02/17 06:24:26 skrll Exp $	*/
+/*	$NetBSD: locore.S,v 1.91 2023/02/23 14:54:57 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -38,7 +38,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: locore.S,v 1.90 2023/02/17 06:24:26 skrll Exp $")
+RCSID("$NetBSD: locore.S,v 1.91 2023/02/23 14:54:57 riastradh Exp $")
 
 #ifdef AARCH64_DEVICE_MEM_NONPOSTED
 #define	MAIR_DEVICE_MEM		MAIR_DEVICE_nGnRnE
@@ -529,6 +529,11 @@ mp_vstart:
 	 */
 	ldr	x1, [x0, #CI_IDLELWP]	/* x0 = curcpu()->ci_idlelwp */
 	msr	tpidr_el1, x1		/* tpidr_el1 = curlwp = x1 */
+	/*
+	 * No membar needed because we're not switching from a
+	 * previous lwp, and the idle lwp we're switching to can't be
+	 * holding locks already; see cpu_switchto.
+	 */
 	str	x1, [x0, #CI_CURLWP]	/* curlwp is idlelwp */
 
 	/* get my stack from lwp */



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Feb 23 14:54:57 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S locore.S

Log Message:
aarch64: Add missing barriers in cpu_switchto.

Details in comments.

Note: This is a conservative change that inserts a barrier where
there was a comment saying none is needed, which is probably correct.
The goal of this change is to systematically add barriers to be
confident in correctness; subsequent changes may remove some bariers,
as an optimization, with an explanation of why each barrier is not
needed.

PR kern/57240

XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/aarch64/aarch64/locore.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 17 06:24:26 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: locore.S

Log Message:
Improve an error message


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/aarch64/aarch64/locore.S

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/locore.S
diff -u src/sys/arch/aarch64/aarch64/locore.S:1.89 src/sys/arch/aarch64/aarch64/locore.S:1.90
--- src/sys/arch/aarch64/aarch64/locore.S:1.89	Sat Oct 29 07:32:54 2022
+++ src/sys/arch/aarch64/aarch64/locore.S	Fri Feb 17 06:24:26 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.89 2022/10/29 07:32:54 skrll Exp $	*/
+/*	$NetBSD: locore.S,v 1.90 2023/02/17 06:24:26 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -38,7 +38,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: locore.S,v 1.89 2022/10/29 07:32:54 skrll Exp $")
+RCSID("$NetBSD: locore.S,v 1.90 2023/02/17 06:24:26 skrll Exp $")
 
 #ifdef AARCH64_DEVICE_MEM_NONPOSTED
 #define	MAIR_DEVICE_MEM		MAIR_DEVICE_nGnRnE
@@ -564,7 +564,7 @@ mp_vstart:
 END(cpu_mpstart)
 
 toomanycpus:
-	CPU_DPRINT("too many cpus, or MPIDR not exists in cpu_mpidr[]\n")
+	CPU_DPRINT("too many cpus, or MPIDR does not exist in cpu_mpidr[]\n")
 1:	wfi
 	b	1b
 



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 17 06:24:26 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: locore.S

Log Message:
Improve an error message


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/arch/aarch64/aarch64/locore.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb  3 08:05:27 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c

Log Message:
Remove useless/harmful casts in debug messages. MPIDR AFF3 would not
be printed before.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/aarch64/aarch64/cpu.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/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.72 src/sys/arch/aarch64/aarch64/cpu.c:1.73
--- src/sys/arch/aarch64/aarch64/cpu.c:1.72	Thu Dec 22 06:58:47 2022
+++ src/sys/arch/aarch64/aarch64/cpu.c	Fri Feb  3 08:05:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.72 2022/12/22 06:58:47 ryo Exp $ */
+/* $NetBSD: cpu.c,v 1.73 2023/02/03 08:05:27 skrll Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.72 2022/12/22 06:58:47 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.73 2023/02/03 08:05:27 skrll Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -329,8 +329,8 @@ cpu_identify2(device_t self, struct cpu_
 {
 	struct aarch64_sysctl_cpu_id * const id = >ci_id;
 
-	aprint_debug_dev(self, "midr=0x%" PRIx32 " mpidr=0x%" PRIx32 "\n",
-	(uint32_t)id->ac_midr, (uint32_t)id->ac_mpidr);
+	aprint_debug_dev(self, "midr=0x%" PRIx64 " mpidr=0x%" PRIx64 "\n",
+	id->ac_midr, id->ac_mpidr);
 	aprint_verbose_dev(self, "revID=0x%" PRIx64, id->ac_revidr);
 
 	/* ID_AA64DFR0_EL1 */



CVS commit: src/sys/arch/aarch64/aarch64

2023-02-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb  3 08:05:27 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c

Log Message:
Remove useless/harmful casts in debug messages. MPIDR AFF3 would not
be printed before.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/aarch64/aarch64/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2023-01-12 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Jan 12 10:46:48 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: bus_space_asm_generic.S

Log Message:
fixed a bug that bus_space_read_region_{2,4,8}_swap() accesses wrong address.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/aarch64/bus_space_asm_generic.S

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/bus_space_asm_generic.S
diff -u src/sys/arch/aarch64/aarch64/bus_space_asm_generic.S:1.5 src/sys/arch/aarch64/aarch64/bus_space_asm_generic.S:1.6
--- src/sys/arch/aarch64/aarch64/bus_space_asm_generic.S:1.5	Thu Nov 12 11:28:39 2020
+++ src/sys/arch/aarch64/aarch64/bus_space_asm_generic.S	Thu Jan 12 10:46:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_space_asm_generic.S,v 1.5 2020/11/12 11:28:39 jmcneill Exp $	*/
+/*	$NetBSD: bus_space_asm_generic.S,v 1.6 2023/01/12 10:46:48 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -29,7 +29,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: bus_space_asm_generic.S,v 1.5 2020/11/12 11:28:39 jmcneill Exp $")
+RCSID("$NetBSD: bus_space_asm_generic.S,v 1.6 2023/01/12 10:46:48 ryo Exp $")
 
 .macro generate_bsfunc funcname, dsbop
 /* uint8_t {funcname}_bs_r_1(x0:tag, x1:addr, x2:offset) */
@@ -389,7 +389,7 @@ ENTRY_NP(\funcname\()_bs_rr_2_swap)
 0:
 	lsl	x2, x2, x8	/* offset <<= tag->bs_stride */
 1:
-	ldrh	w8, [x1, x9]	/* value = *src */
+	ldrh	w8, [x1, x2]	/* value = *src */
 	subs	x4, x4, #1	/* count-- */
 	add	x2, x2, x9	/* src += delta */
 	rev16	w8, w8
@@ -419,7 +419,7 @@ ENTRY_NP(\funcname\()_bs_rr_4_swap)
 0:
 	lsl	x2, x2, x8	/* offset <<= tag->bs_stride */
 1:
-	ldr	w8, [x1, x9]	/* value = *src */
+	ldr	w8, [x1, x2]	/* value = *src */
 	subs	x4, x4, #1	/* count-- */
 	add	x2, x2, x9	/* src += delta */
 	rev	w8, w8
@@ -449,7 +449,7 @@ ENTRY_NP(\funcname\()_bs_rr_8_swap)
 0:
 	lsl	x2, x2, x8	/* offset <<= tag->bs_stride */
 1:
-	ldr	x8, [x1, x9]	/* value = *src */
+	ldr	x8, [x1, x2]	/* value = *src */
 	subs	x4, x4, #1	/* count-- */
 	add	x2, x2, x9	/* src += delta */
 	rev	x8, x8



CVS commit: src/sys/arch/aarch64/aarch64

2023-01-12 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Jan 12 10:46:48 UTC 2023

Modified Files:
src/sys/arch/aarch64/aarch64: bus_space_asm_generic.S

Log Message:
fixed a bug that bus_space_read_region_{2,4,8}_swap() accesses wrong address.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/aarch64/bus_space_asm_generic.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-12-21 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec 22 06:58:47 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c

Log Message:
PMCR_EL0.LC should be set. ARM deprecates use of PMCR_EL0.LC=0


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/aarch64/aarch64/cpu.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/cpu.c
diff -u src/sys/arch/aarch64/aarch64/cpu.c:1.71 src/sys/arch/aarch64/aarch64/cpu.c:1.72
--- src/sys/arch/aarch64/aarch64/cpu.c:1.71	Thu Dec 22 06:58:07 2022
+++ src/sys/arch/aarch64/aarch64/cpu.c	Thu Dec 22 06:58:47 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.71 2022/12/22 06:58:07 ryo Exp $ */
+/* $NetBSD: cpu.c,v 1.72 2022/12/22 06:58:47 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.71 2022/12/22 06:58:07 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.72 2022/12/22 06:58:47 ryo Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -498,7 +498,7 @@ cpu_init_counter(struct cpu_info *ci)
 		return;
 	}
 
-	reg_pmcr_el0_write(PMCR_E | PMCR_C);
+	reg_pmcr_el0_write(PMCR_E | PMCR_C | PMCR_LC);
 	reg_pmintenclr_el1_write(PMINTEN_C | PMINTEN_P);
 	reg_pmcntenset_el0_write(PMCNTEN_C);
 



CVS commit: src/sys/arch/aarch64/aarch64

2022-12-21 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec 22 06:58:47 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: cpu.c

Log Message:
PMCR_EL0.LC should be set. ARM deprecates use of PMCR_EL0.LC=0


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/arch/aarch64/aarch64/cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/conf

2022-11-05 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Nov  5 08:29:17 UTC 2022

Modified Files:
src/sys/arch/aarch64/conf: files.aarch64

Log Message:
G/C


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/aarch64/conf/files.aarch64

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/conf

2022-11-05 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Nov  5 08:29:17 UTC 2022

Modified Files:
src/sys/arch/aarch64/conf: files.aarch64

Log Message:
G/C


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/aarch64/conf/files.aarch64

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/conf/files.aarch64
diff -u src/sys/arch/aarch64/conf/files.aarch64:1.41 src/sys/arch/aarch64/conf/files.aarch64:1.42
--- src/sys/arch/aarch64/conf/files.aarch64:1.41	Thu Nov  3 09:04:56 2022
+++ src/sys/arch/aarch64/conf/files.aarch64	Sat Nov  5 08:29:17 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: files.aarch64,v 1.41 2022/11/03 09:04:56 skrll Exp $
+#	$NetBSD: files.aarch64,v 1.42 2022/11/05 08:29:17 skrll Exp $
 
 defflag opt_cpuoptions.h	AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h	AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -72,8 +72,6 @@ file	arch/aarch64/aarch64/kgdb_machdep.c
 
 # mainbus files
 device	mainbus { [addr = -1], [size = 0], [intr = -1] }
-attach	mainbus at root
-file	arch/aarch64/dev/mainbus.c			mainbus
 
 device cpu { }
 file	arch/aarch64/aarch64/cpu.c			cpu



CVS commit: src/sys/arch/aarch64/aarch64

2022-11-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Nov  2 08:37:32 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_interface.c

Log Message:
Restore a '\n' I accidentally removed in 1.16


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/aarch64/aarch64/db_interface.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/db_interface.c
diff -u src/sys/arch/aarch64/aarch64/db_interface.c:1.21 src/sys/arch/aarch64/aarch64/db_interface.c:1.22
--- src/sys/arch/aarch64/aarch64/db_interface.c:1.21	Sun Oct 23 07:14:12 2022
+++ src/sys/arch/aarch64/aarch64/db_interface.c	Wed Nov  2 08:37:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_interface.c,v 1.21 2022/10/23 07:14:12 skrll Exp $ */
+/* $NetBSD: db_interface.c,v 1.22 2022/11/02 08:37:32 skrll Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.21 2022/10/23 07:14:12 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.22 2022/11/02 08:37:32 skrll Exp $");
 
 #include 
 #include 
@@ -566,7 +566,7 @@ dump_ln_table(bool countmode, pd_entry_t
 	if (pg == NULL) {
 		pr("%sL%d: pa=%lx pg=NULL\n", spc, level, pa);
 	} else {
-		pr("%sL%d: pa=%lx pg=%p", spc, level, pa, pg);
+		pr("%sL%d: pa=%lx pg=%p\n", spc, level, pa, pg);
 	}
 
 	for (i = n = 0; i < Ln_ENTRIES; i++) {



CVS commit: src/sys/arch/aarch64/aarch64

2022-11-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Nov  2 08:37:32 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_interface.c

Log Message:
Restore a '\n' I accidentally removed in 1.16


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/aarch64/aarch64/db_interface.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 30 14:08:09 UTC 2022

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

Log Message:
aarch64/pmap: Fix criterion in previous.

Use the pte bit that says whether this is a PMAP_WIRED page, not the
bit that says whether this is a non-global page.

(Forgot to git commit --amend before exporting to CVS, sorry!)


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 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.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 30 14:08:09 UTC 2022

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

Log Message:
aarch64/pmap: Fix criterion in previous.

Use the pte bit that says whether this is a PMAP_WIRED page, not the
bit that says whether this is a non-global page.

(Forgot to git commit --amend before exporting to CVS, sorry!)


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 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.146 src/sys/arch/aarch64/aarch64/pmap.c:1.147
--- src/sys/arch/aarch64/aarch64/pmap.c:1.146	Sun Oct 30 10:26:48 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sun Oct 30 14:08:09 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.146 2022/10/30 10:26:48 riastradh Exp $	*/
+/*	$NetBSD: pmap.c,v 1.147 2022/10/30 14:08:09 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.146 2022/10/30 10:26:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.147 2022/10/30 14:08:09 riastradh Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1426,7 +1426,7 @@ pmap_protect(struct pmap *pm, vaddr_t sv
 			continue;
 		}
 
-		if (pte & LX_BLKPAG_NG) {
+		if ((pte & LX_BLKPAG_OS_WIRED) == 0) {
 			const paddr_t pa = lxpde_pa(pte);
 			struct vm_page *const pg = PHYS_TO_VM_PAGE(pa);
 



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 30 10:26:48 UTC 2022

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

Log Message:
aarch64/pmap(9): Teach pmap_protect about pmap_kenter_pa mappings.

Pages mapped with pmap_kenter_pa are necessarily unmanaged, so there
are no P->V records, and pmap_kenter_pa leaves pp->pp_pv.pv_va zero
with no modified/referenced state.

However, pmap_protect erroneously examined pp->pp_pv.pv_va to
ascertain the modified/referenced state -- and if the page was not
marked referenced, pmap_protect would clear the LX_BLKPAG_AF bit
(Access Flag), with the effect that subsequent uses of the page fault
and require a detour through pmap_fault_fixup.

This caused problems for the kernel module loader:

- When loading the text section, kobj_load first allocates kva with
  uvm_km_alloc(UVM_KMF_WIRED|UVM_KMF_EXEC), which creates ptes with
  pmap_kenter_pa.  These ptes are writable, so we can copy the text
  section into them, and have LX_BLKPAG_AF set so there will be no
  fault when they are used by the kernel.

- But then kobj_affix makes the text section read/execute-only (and
  nonwritable) with uvm_km_protect(VM_PROT_READ|VM_PROT_EXECUTE),
  which updates the ptes with pmap_protect.  This _should_ leave
  LX_BLKPAG_AF set, but by inadvertently treating the page as managed
  when it should be unmanaged, pmap_protect cleared it instead.

- Most of the time, clearing LX_BLKPAG_AF caused no problem, because
  pmap_fault_fixup would silently resolve it.  But if a hard
  interrupt handler tried to use any page in the module's text (or
  rodata, I suspect) that was not yet fixed up, the CPU would fault
  and enter pmap_fault_fixup -- which would promptly crash (or hang)
  by trying to take the pmap lock in interrupt context, which is
  forbidden.

  I observed this by loading dtrace.kmod early at boot and trying to
  dtrace hard interrupt handlers.

With this change, pmap_protect now recognizes wired mappings (as
created by pmap_kenter_pa) before consulting pp->pp_pv.pv_va, and
preserves then LX_BLKPAG_AF bit in that case.

ok skrll


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 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.145 src/sys/arch/aarch64/aarch64/pmap.c:1.146
--- src/sys/arch/aarch64/aarch64/pmap.c:1.145	Sat Oct 29 07:21:41 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sun Oct 30 10:26:48 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.145 2022/10/29 07:21:41 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.146 2022/10/30 10:26:48 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.145 2022/10/29 07:21:41 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.146 2022/10/30 10:26:48 riastradh Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1410,9 +1410,7 @@ pmap_protect(struct pmap *pm, vaddr_t sv
 #ifdef UVMHIST
 		pt_entry_t opte;
 #endif
-		struct vm_page *pg;
 		struct pmap_page *pp;
-		paddr_t pa;
 		uint32_t mdattr;
 		bool executable;
 
@@ -1428,24 +1426,30 @@ pmap_protect(struct pmap *pm, vaddr_t sv
 			continue;
 		}
 
-		pa = lxpde_pa(pte);
-		pg = PHYS_TO_VM_PAGE(pa);
-		if (pg != NULL) {
-			pp = VM_PAGE_TO_PP(pg);
-			PMAP_COUNT(protect_managed);
-		} else {
+		if (pte & LX_BLKPAG_NG) {
+			const paddr_t pa = lxpde_pa(pte);
+			struct vm_page *const pg = PHYS_TO_VM_PAGE(pa);
+
+			if (pg != NULL) {
+pp = VM_PAGE_TO_PP(pg);
+PMAP_COUNT(protect_managed);
+			} else {
 #ifdef __HAVE_PMAP_PV_TRACK
-			pp = pmap_pv_tracked(pa);
+pp = pmap_pv_tracked(pa);
 #ifdef PMAPCOUNTERS
-			if (pp != NULL)
-PMAP_COUNT(protect_pvmanaged);
-			else
-PMAP_COUNT(protect_unmanaged);
+if (pp != NULL)
+	PMAP_COUNT(protect_pvmanaged);
+else
+	PMAP_COUNT(protect_unmanaged);
 #endif
 #else
+pp = NULL;
+PMAP_COUNT(protect_unmanaged);
+#endif /* __HAVE_PMAP_PV_TRACK */
+			}
+		} else {	/* kenter */
 			pp = NULL;
 			PMAP_COUNT(protect_unmanaged);
-#endif /* __HAVE_PMAP_PV_TRACK */
 		}
 
 		if (pp != NULL) {



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Oct 30 10:26:48 UTC 2022

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

Log Message:
aarch64/pmap(9): Teach pmap_protect about pmap_kenter_pa mappings.

Pages mapped with pmap_kenter_pa are necessarily unmanaged, so there
are no P->V records, and pmap_kenter_pa leaves pp->pp_pv.pv_va zero
with no modified/referenced state.

However, pmap_protect erroneously examined pp->pp_pv.pv_va to
ascertain the modified/referenced state -- and if the page was not
marked referenced, pmap_protect would clear the LX_BLKPAG_AF bit
(Access Flag), with the effect that subsequent uses of the page fault
and require a detour through pmap_fault_fixup.

This caused problems for the kernel module loader:

- When loading the text section, kobj_load first allocates kva with
  uvm_km_alloc(UVM_KMF_WIRED|UVM_KMF_EXEC), which creates ptes with
  pmap_kenter_pa.  These ptes are writable, so we can copy the text
  section into them, and have LX_BLKPAG_AF set so there will be no
  fault when they are used by the kernel.

- But then kobj_affix makes the text section read/execute-only (and
  nonwritable) with uvm_km_protect(VM_PROT_READ|VM_PROT_EXECUTE),
  which updates the ptes with pmap_protect.  This _should_ leave
  LX_BLKPAG_AF set, but by inadvertently treating the page as managed
  when it should be unmanaged, pmap_protect cleared it instead.

- Most of the time, clearing LX_BLKPAG_AF caused no problem, because
  pmap_fault_fixup would silently resolve it.  But if a hard
  interrupt handler tried to use any page in the module's text (or
  rodata, I suspect) that was not yet fixed up, the CPU would fault
  and enter pmap_fault_fixup -- which would promptly crash (or hang)
  by trying to take the pmap lock in interrupt context, which is
  forbidden.

  I observed this by loading dtrace.kmod early at boot and trying to
  dtrace hard interrupt handlers.

With this change, pmap_protect now recognizes wired mappings (as
created by pmap_kenter_pa) before consulting pp->pp_pv.pv_va, and
preserves then LX_BLKPAG_AF bit in that case.

ok skrll


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 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.



CVS commit: src/sys/arch/aarch64/include

2022-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 29 08:29:28 UTC 2022

Modified Files:
src/sys/arch/aarch64/include: pmap.h

Log Message:
KNF + remove unnecessary brackets


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/aarch64/include/pmap.h

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/include/pmap.h
diff -u src/sys/arch/aarch64/include/pmap.h:1.55 src/sys/arch/aarch64/include/pmap.h:1.56
--- src/sys/arch/aarch64/include/pmap.h:1.55	Sun Oct 23 07:13:07 2022
+++ src/sys/arch/aarch64/include/pmap.h	Sat Oct 29 08:29:28 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.55 2022/10/23 07:13:07 skrll Exp $ */
+/* $NetBSD: pmap.h,v 1.56 2022/10/29 08:29:28 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -256,11 +256,11 @@ pmap_kvattr(pt_entry_t *ptep, vm_prot_t 
 	case 0:
 		break;
 	case VM_PROT_READ:
-		pte |= (LX_BLKPAG_AF | LX_BLKPAG_AP_RO);
+		pte |= LX_BLKPAG_AF | LX_BLKPAG_AP_RO;
 		break;
 	case VM_PROT_WRITE:
-	case VM_PROT_READ|VM_PROT_WRITE:
-		pte |= (LX_BLKPAG_AF | LX_BLKPAG_AP_RW);
+	case VM_PROT_READ | VM_PROT_WRITE:
+		pte |= LX_BLKPAG_AF | LX_BLKPAG_AP_RW;
 		break;
 	}
 



CVS commit: src/sys/arch/aarch64/include

2022-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 29 08:29:28 UTC 2022

Modified Files:
src/sys/arch/aarch64/include: pmap.h

Log Message:
KNF + remove unnecessary brackets


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/aarch64/include/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 29 07:32:54 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: locore.S

Log Message:
Slightly better English in a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/aarch64/aarch64/locore.S

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/locore.S
diff -u src/sys/arch/aarch64/aarch64/locore.S:1.88 src/sys/arch/aarch64/aarch64/locore.S:1.89
--- src/sys/arch/aarch64/aarch64/locore.S:1.88	Sat Oct 15 11:07:38 2022
+++ src/sys/arch/aarch64/aarch64/locore.S	Sat Oct 29 07:32:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.88 2022/10/15 11:07:38 jmcneill Exp $	*/
+/*	$NetBSD: locore.S,v 1.89 2022/10/29 07:32:54 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -38,7 +38,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: locore.S,v 1.88 2022/10/15 11:07:38 jmcneill Exp $")
+RCSID("$NetBSD: locore.S,v 1.89 2022/10/29 07:32:54 skrll Exp $")
 
 #ifdef AARCH64_DEVICE_MEM_NONPOSTED
 #define	MAIR_DEVICE_MEM		MAIR_DEVICE_nGnRnE
@@ -52,7 +52,7 @@ RCSID("$NetBSD: locore.S,v 1.88 2022/10/
 
 #define LOCORE_EL2
 
-#define BOOT_AP_STACKSIZE	256	/* size of temporally stack for APs */
+#define BOOT_AP_STACKSIZE	256	/* size of temporary stack for APs */
 #define PMAPBOOT_PAGEALLOCMAX	(1024 * 1024)	/* reserved size from _end[] */
 
 #if (defined(VERBOSE_INIT_ARM) || defined(DEBUG_LOCORE)) && defined(EARLYCONS)



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 29 07:32:54 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: locore.S

Log Message:
Slightly better English in a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/arch/aarch64/aarch64/locore.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 29 07:21:42 UTC 2022

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

Log Message:
fix a spello in a comment


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 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.144 src/sys/arch/aarch64/aarch64/pmap.c:1.145
--- src/sys/arch/aarch64/aarch64/pmap.c:1.144	Fri Oct 28 06:22:26 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sat Oct 29 07:21:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.144 2022/10/28 06:22:26 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.145 2022/10/29 07:21:41 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.144 2022/10/28 06:22:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.145 2022/10/29 07:21:41 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1012,7 +1012,7 @@ pmap_icache_sync_range(pmap_t pm, vaddr_
 			cpu_icache_sync_range(va, len);
 		} else {
 			/*
-			 * change to accessible temporally
+			 * change to accessible temporarily
 			 * to do cpu_icache_sync_range()
 			 */
 			struct pmap_asid_info * const pai = PMAP_PAI(pm,



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 29 07:21:42 UTC 2022

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

Log Message:
fix a spello in a comment


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 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.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-28 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Oct 28 06:22:26 UTC 2022

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

Log Message:
Remove some empty lines


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 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.143 src/sys/arch/aarch64/aarch64/pmap.c:1.144
--- src/sys/arch/aarch64/aarch64/pmap.c:1.143	Sun Oct 23 07:04:44 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Fri Oct 28 06:22:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.143 2022/10/23 07:04:44 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.144 2022/10/28 06:22:26 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.143 2022/10/23 07:04:44 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.144 2022/10/28 06:22:26 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -199,7 +199,6 @@ static int _pmap_get_pdp(struct pmap *, 
 struct vm_page **);
 
 static struct pmap kernel_pmap __cacheline_aligned;
-
 struct pmap * const kernel_pmap_ptr = _pmap;
 
 #if defined(EFI_RUNTIME)
@@ -2873,7 +2872,6 @@ kvtopte(vaddr_t va)
 }
 
 #ifdef DDB
-
 void
 pmap_db_pmap_print(struct pmap *pm,
 void (*pr)(const char *, ...) __printflike(1, 2))
@@ -2886,4 +2884,3 @@ pmap_db_pmap_print(struct pmap *pm,
 	pr(" pm_activated  = %d\n\n", pm->pm_activated);
 }
 #endif /* DDB */
-



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-28 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Oct 28 06:22:26 UTC 2022

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

Log Message:
Remove some empty lines


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 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.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:14:12 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_interface.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/db_interface.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/db_interface.c
diff -u src/sys/arch/aarch64/aarch64/db_interface.c:1.20 src/sys/arch/aarch64/aarch64/db_interface.c:1.21
--- src/sys/arch/aarch64/aarch64/db_interface.c:1.20	Sat Oct 15 11:07:38 2022
+++ src/sys/arch/aarch64/aarch64/db_interface.c	Sun Oct 23 07:14:12 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_interface.c,v 1.20 2022/10/15 11:07:38 jmcneill Exp $ */
+/* $NetBSD: db_interface.c,v 1.21 2022/10/23 07:14:12 skrll Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.20 2022/10/15 11:07:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.21 2022/10/23 07:14:12 skrll Exp $");
 
 #include 
 #include 
@@ -170,7 +170,7 @@ db_write_text(vaddr_t addr, size_t size,
 		 * will stop...
 		 */
 		/* old pte is returned by pmap_kvattr */
-		pte = pmap_kvattr(ptep, VM_PROT_EXECUTE|VM_PROT_READ|VM_PROT_WRITE);
+		pte = pmap_kvattr(ptep, VM_PROT_EXECUTE | VM_PROT_READ | VM_PROT_WRITE);
 		aarch64_tlbi_all();
 
 		s = size;



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:14:12 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_interface.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/db_interface.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:13:07 UTC 2022

Modified Files:
src/sys/arch/aarch64/include: pmap.h

Log Message:
KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/aarch64/include/pmap.h

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/include/pmap.h
diff -u src/sys/arch/aarch64/include/pmap.h:1.54 src/sys/arch/aarch64/include/pmap.h:1.55
--- src/sys/arch/aarch64/include/pmap.h:1.54	Sun Oct 23 07:11:26 2022
+++ src/sys/arch/aarch64/include/pmap.h	Sun Oct 23 07:13:07 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.54 2022/10/23 07:11:26 skrll Exp $ */
+/* $NetBSD: pmap.h,v 1.55 2022/10/23 07:13:07 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -176,7 +176,7 @@ struct vm_page_md {
 #define LX_BLKPAG_OS_WRITE		LX_BLKPAG_OS_1
 #define LX_BLKPAG_OS_WIRED		LX_BLKPAG_OS_2
 #define LX_BLKPAG_OS_BOOT		LX_BLKPAG_OS_3
-#define LX_BLKPAG_OS_RWMASK		(LX_BLKPAG_OS_WRITE|LX_BLKPAG_OS_READ)
+#define LX_BLKPAG_OS_RWMASK		(LX_BLKPAG_OS_WRITE | LX_BLKPAG_OS_READ)
 
 #define PMAP_PTE_OS0	"read"
 #define PMAP_PTE_OS1	"write"
@@ -215,7 +215,7 @@ struct vm_page_md {
 (((pde) & ((user) ? LX_BLKPAG_UXN : LX_BLKPAG_PXN)) == 0)
 #define l3pte_readable(pde)	((pde) & LX_BLKPAG_AF)
 #define l3pte_writable(pde)	\
-(((pde) & (LX_BLKPAG_AF|LX_BLKPAG_AP)) == (LX_BLKPAG_AF|LX_BLKPAG_AP_RW))
+(((pde) & (LX_BLKPAG_AF | LX_BLKPAG_AP)) == (LX_BLKPAG_AF | LX_BLKPAG_AP_RW))
 #define l3pte_index(v)		(((vaddr_t)(v) & L3_ADDR_BITS) >> L3_SHIFT)
 #define l3pte_valid(pde)	lxpde_valid(pde)
 #define l3pte_is_page(pde)	(((pde) & LX_TYPE) == L3_TYPE_PAG)
@@ -251,16 +251,16 @@ pmap_kvattr(pt_entry_t *ptep, vm_prot_t 
 	pt_entry_t pte = *ptep;
 	const pt_entry_t opte = pte;
 
-	pte &= ~(LX_BLKPAG_AF|LX_BLKPAG_AP);
-	switch (prot & (VM_PROT_READ|VM_PROT_WRITE)) {
+	pte &= ~(LX_BLKPAG_AF | LX_BLKPAG_AP);
+	switch (prot & (VM_PROT_READ | VM_PROT_WRITE)) {
 	case 0:
 		break;
 	case VM_PROT_READ:
-		pte |= (LX_BLKPAG_AF|LX_BLKPAG_AP_RO);
+		pte |= (LX_BLKPAG_AF | LX_BLKPAG_AP_RO);
 		break;
 	case VM_PROT_WRITE:
 	case VM_PROT_READ|VM_PROT_WRITE:
-		pte |= (LX_BLKPAG_AF|LX_BLKPAG_AP_RW);
+		pte |= (LX_BLKPAG_AF | LX_BLKPAG_AP_RW);
 		break;
 	}
 
@@ -320,7 +320,7 @@ paddr_t pmap_devmap_vtophys(paddr_t);
 		.pd_va = DEVMAP_ALIGN(va),			\
 		.pd_pa = DEVMAP_ALIGN(pa),			\
 		.pd_size = DEVMAP_SIZE(sz),			\
-		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,		\
+		.pd_prot = VM_PROT_READ | VM_PROT_WRITE,	\
 		.pd_flags = PMAP_DEV\
 	}
 #define	DEVMAP_ENTRY_END	{ 0 }



CVS commit: src/sys/arch/aarch64/include

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:13:07 UTC 2022

Modified Files:
src/sys/arch/aarch64/include: pmap.h

Log Message:
KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/aarch64/include/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/include

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:11:27 UTC 2022

Modified Files:
src/sys/arch/aarch64/include: pmap.h

Log Message:
Line continuation alignment whitespace. NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/aarch64/include/pmap.h

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/include/pmap.h
diff -u src/sys/arch/aarch64/include/pmap.h:1.53 src/sys/arch/aarch64/include/pmap.h:1.54
--- src/sys/arch/aarch64/include/pmap.h:1.53	Sat Oct 15 11:07:38 2022
+++ src/sys/arch/aarch64/include/pmap.h	Sun Oct 23 07:11:26 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.53 2022/10/15 11:07:38 jmcneill Exp $ */
+/* $NetBSD: pmap.h,v 1.54 2022/10/23 07:11:26 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -315,13 +315,13 @@ paddr_t pmap_devmap_vtophys(paddr_t);
 #define DEVMAP_ALIGN(x)		L3_TRUNC_BLOCK((x))
 #define DEVMAP_SIZE(x)		L3_ROUND_BLOCK((x))
 
-#define	DEVMAP_ENTRY(va, pa, sz)			\
-	{		\
-		.pd_va = DEVMAP_ALIGN(va),		\
-		.pd_pa = DEVMAP_ALIGN(pa),		\
+#define	DEVMAP_ENTRY(va, pa, sz)\
+	{			\
+		.pd_va = DEVMAP_ALIGN(va),			\
+		.pd_pa = DEVMAP_ALIGN(pa),			\
 		.pd_size = DEVMAP_SIZE(sz),			\
-		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,	\
-		.pd_flags = PMAP_DEV			\
+		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,		\
+		.pd_flags = PMAP_DEV\
 	}
 #define	DEVMAP_ENTRY_END	{ 0 }
 



CVS commit: src/sys/arch/aarch64/include

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:11:27 UTC 2022

Modified Files:
src/sys/arch/aarch64/include: pmap.h

Log Message:
Line continuation alignment whitespace. NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/aarch64/include/pmap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:04:44 UTC 2022

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

Log Message:
Use UVMHIST_CALLARGS in pmap_bootstrap


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 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.142 src/sys/arch/aarch64/aarch64/pmap.c:1.143
--- src/sys/arch/aarch64/aarch64/pmap.c:1.142	Sun Oct 23 07:02:26 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sun Oct 23 07:04:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.142 2022/10/23 07:02:26 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.143 2022/10/23 07:04:44 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.142 2022/10/23 07:02:26 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.143 2022/10/23 07:04:44 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -472,7 +472,8 @@ pmap_bootstrap(vaddr_t vstart, vaddr_t v
 	PMAP_HIST_INIT();	/* init once */
 
 	UVMHIST_FUNC(__func__);
-	UVMHIST_CALLED(pmaphist);
+	UVMHIST_CALLARGS(pmaphist, "vstart=%#jx vend=%#jx", (uintptr_t)vstart,
+	(uintptr_t)vend, 0, 0);
 
 	uvmexp.ncolors = aarch64_cache_vindexsize / PAGE_SIZE;
 



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:04:44 UTC 2022

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

Log Message:
Use UVMHIST_CALLARGS in pmap_bootstrap


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 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.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:02:27 UTC 2022

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

Log Message:
Only define the EFI variable if EFI_RUNTIME


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 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.141 src/sys/arch/aarch64/aarch64/pmap.c:1.142
--- src/sys/arch/aarch64/aarch64/pmap.c:1.141	Thu Oct 20 06:47:29 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Sun Oct 23 07:02:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.141 2022/10/20 06:47:29 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.142 2022/10/23 07:02:26 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.141 2022/10/20 06:47:29 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.142 2022/10/23 07:02:26 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -199,15 +199,18 @@ static int _pmap_get_pdp(struct pmap *, 
 struct vm_page **);
 
 static struct pmap kernel_pmap __cacheline_aligned;
-static struct pmap efirt_pmap __cacheline_aligned;
 
 struct pmap * const kernel_pmap_ptr = _pmap;
 
+#if defined(EFI_RUNTIME)
+static struct pmap efirt_pmap __cacheline_aligned;
+
 pmap_t
 pmap_efirt(void)
 {
 	return _pmap;
 }
+#endif
 
 static vaddr_t pmap_maxkvaddr;
 



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Oct 23 07:02:27 UTC 2022

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

Log Message:
Only define the EFI variable if EFI_RUNTIME


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 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.



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 20 06:47:29 UTC 2022

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

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 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.140 src/sys/arch/aarch64/aarch64/pmap.c:1.141
--- src/sys/arch/aarch64/aarch64/pmap.c:1.140	Sat Oct 15 11:07:38 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Thu Oct 20 06:47:29 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.140 2022/10/15 11:07:38 jmcneill Exp $	*/
+/*	$NetBSD: pmap.c,v 1.141 2022/10/20 06:47:29 skrll Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.140 2022/10/15 11:07:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.141 2022/10/20 06:47:29 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -844,7 +844,7 @@ pmap_extract_coherency(struct pmap *pm, 
 			 * have no physical memory haven't been mapped.
 			 * fast lookup by using the S1E1R/PAR_EL1 registers.
 			 */
-			register_t s = daif_disable(DAIF_I|DAIF_F);
+			register_t s = daif_disable(DAIF_I | DAIF_F);
 			reg_s1e1r_write(va);
 			isb();
 			uint64_t par = reg_par_el1_read();
@@ -1064,7 +1064,7 @@ _pmap_pte_adjust_prot(pt_entry_t pte, vm
 	pt_entry_t xn;
 
 	masked = prot & refmod;
-	pte &= ~(LX_BLKPAG_OS_RWMASK|LX_BLKPAG_AF|LX_BLKPAG_DBM|LX_BLKPAG_AP);
+	pte &= ~(LX_BLKPAG_OS_RWMASK | LX_BLKPAG_AF | LX_BLKPAG_DBM | LX_BLKPAG_AP);
 
 	/*
 	 * keep actual prot in the pte as OS_{READ|WRITE} for ref/mod emulation,
@@ -1072,9 +1072,9 @@ _pmap_pte_adjust_prot(pt_entry_t pte, vm
 	 */
 	pte |= LX_BLKPAG_OS_READ;	/* a valid pte can always be readable */
 	if (prot & VM_PROT_WRITE)
-		pte |= LX_BLKPAG_OS_WRITE|LX_BLKPAG_DBM;
+		pte |= LX_BLKPAG_OS_WRITE | LX_BLKPAG_DBM;
 
-	switch (masked & (VM_PROT_READ|VM_PROT_WRITE)) {
+	switch (masked & (VM_PROT_READ | VM_PROT_WRITE)) {
 	case 0:
 	default:
 		/*
@@ -1092,7 +1092,7 @@ _pmap_pte_adjust_prot(pt_entry_t pte, vm
 		pte |= LX_BLKPAG_AP_RO;
 		break;
 	case VM_PROT_WRITE:
-	case VM_PROT_READ|VM_PROT_WRITE:
+	case VM_PROT_READ | VM_PROT_WRITE:
 		/* fully readable and writable */
 		pte |= LX_BLKPAG_AF;
 		pte |= LX_BLKPAG_AP_RW;
@@ -1100,7 +1100,7 @@ _pmap_pte_adjust_prot(pt_entry_t pte, vm
 	}
 
 	/* executable for kernel or user? first set never exec both */
-	pte |= (LX_BLKPAG_UXN|LX_BLKPAG_PXN);
+	pte |= (LX_BLKPAG_UXN | LX_BLKPAG_PXN);
 	/* and either to executable */
 	xn = user ? LX_BLKPAG_UXN : LX_BLKPAG_PXN;
 	if (prot & VM_PROT_EXECUTE)
@@ -1115,7 +1115,7 @@ _pmap_pte_adjust_cacheflags(pt_entry_t p
 
 	pte &= ~LX_BLKPAG_ATTR_MASK;
 
-	switch (flags & (PMAP_CACHE_MASK|PMAP_DEV_MASK)) {
+	switch (flags & (PMAP_CACHE_MASK | PMAP_DEV_MASK)) {
 	case PMAP_DEV_NP ... PMAP_DEV_NP | PMAP_CACHE_MASK:
 		pte |= LX_BLKPAG_ATTR_DEVICE_MEM_NP;	/* Device-nGnRnE */
 		break;
@@ -1348,7 +1348,7 @@ _pmap_protect_pv(struct pmap_page *pp, s
 
 	/* get prot mask from pte */
 	pteprot = VM_PROT_READ;	/* a valid pte can always be readable */
-	if ((pte & (LX_BLKPAG_OS_WRITE|LX_BLKPAG_DBM)) != 0)
+	if ((pte & (LX_BLKPAG_OS_WRITE | LX_BLKPAG_DBM)) != 0)
 		pteprot |= VM_PROT_WRITE;
 	if (l3pte_executable(pte, user))
 		pteprot |= VM_PROT_EXECUTE;
@@ -2071,9 +2071,9 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 	 * read permission is treated as an access permission internally.
 	 * require to add PROT_READ even if only PROT_WRITE or PROT_EXEC
 	 */
-	if (prot & (VM_PROT_WRITE|VM_PROT_EXECUTE))
+	if (prot & (VM_PROT_WRITE | VM_PROT_EXECUTE))
 		prot |= VM_PROT_READ;
-	if (flags & (VM_PROT_WRITE|VM_PROT_EXECUTE))
+	if (flags & (VM_PROT_WRITE | VM_PROT_EXECUTE))
 		flags |= VM_PROT_READ;
 
 	mdattr = VM_PROT_READ | VM_PROT_WRITE;
@@ -2434,7 +2434,7 @@ pmap_page_protect(struct vm_page *pg, vm
 		return;
 	}
 
-	if ((prot & (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)) ==
+	if ((prot & (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE)) ==
 	VM_PROT_NONE) {
 		pmap_page_remove(pp, prot);
 	} else {
@@ -2549,7 +2549,7 @@ pmap_fault_fixup(struct pmap *pm, vaddr_
 	 * If DBM is 1, it is considered a writable page.
 	 */
 	pmap_prot = VM_PROT_READ;
-	if ((pte & (LX_BLKPAG_OS_WRITE|LX_BLKPAG_DBM)) != 0)
+	if ((pte & (LX_BLKPAG_OS_WRITE | LX_BLKPAG_DBM)) != 0)
 		pmap_prot |= VM_PROT_WRITE;
 
 	if (l3pte_executable(pte, pm != pmap_kernel()))
@@ -2559,7 +2559,7 @@ pmap_fault_fixup(struct pmap *pm, vaddr_
 	va, pmap_prot, accessprot, 0);
 
 	/* ignore except read/write */
-	accessprot &= (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
+	accessprot &= (VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
 
 	/* PROT_EXEC requires implicit PROT_READ */
 	if (accessprot & VM_PROT_EXECUTE)



CVS commit: src/sys/arch/aarch64/aarch64

2022-10-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct 20 06:47:29 UTC 2022

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

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 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.



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 22 21:48:19 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
oops, my previous commit is bad. revert previous.
 is a frame pointer, not a trapframe, and it worked correctly. 
(e.g., trace $x29)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/aarch64/aarch64/db_trace.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/db_trace.c
diff -u src/sys/arch/aarch64/aarch64/db_trace.c:1.22 src/sys/arch/aarch64/aarch64/db_trace.c:1.23
--- src/sys/arch/aarch64/aarch64/db_trace.c:1.22	Thu Sep 22 21:00:46 2022
+++ src/sys/arch/aarch64/aarch64/db_trace.c	Thu Sep 22 21:48:18 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.22 2022/09/22 21:00:46 ryo Exp $ */
+/* $NetBSD: db_trace.c,v 1.23 2022/09/22 21:48:18 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.22 2022/09/22 21:00:46 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.23 2022/09/22 21:48:18 ryo Exp $");
 
 #include 
 #include 
@@ -497,6 +497,15 @@ db_sp_trace(struct trapframe *tf, db_add
 	db_addr_t pc, sp, lr0;
 	bool allow_leaf_function = false;
 
+	if (tf == NULL) {
+		/*
+		 * In the case of "trace/s ",
+		 * the specified frame pointer address is considered
+		 * a trapframe (or a switchframe) address.
+		 */
+		tf = (struct trapframe *)fp;
+	}
+
 	pr_frame(tf, pr);
 
 	db_read_bytes((db_addr_t)tf, sizeof(tf_buf), (char *)_buf);
@@ -801,15 +810,6 @@ db_stack_trace_print(db_expr_t addr, boo
 	if (count > MAXBACKTRACE)
 		count = MAXBACKTRACE;
 
-	if (tf == NULL) {
-		/*
-		 * In the case of "trace ",
-		 * the specified frame pointer address is considered
-		 * a trapframe (or a switchframe) address.
-		 */
-		tf = (struct trapframe *)fp;
-	}
-
 	if (trace_sp) {
 		/* trace $lr pushed to sp */
 		db_sp_trace(tf, fp, count, flags, pr);



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 22 21:48:19 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
oops, my previous commit is bad. revert previous.
 is a frame pointer, not a trapframe, and it worked correctly. 
(e.g., trace $x29)


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/aarch64/aarch64/db_trace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 22 21:00:46 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
Specifying the frame address "trace " was not working.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/aarch64/aarch64/db_trace.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/db_trace.c
diff -u src/sys/arch/aarch64/aarch64/db_trace.c:1.21 src/sys/arch/aarch64/aarch64/db_trace.c:1.22
--- src/sys/arch/aarch64/aarch64/db_trace.c:1.21	Thu Sep 22 19:33:00 2022
+++ src/sys/arch/aarch64/aarch64/db_trace.c	Thu Sep 22 21:00:46 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.21 2022/09/22 19:33:00 ryo Exp $ */
+/* $NetBSD: db_trace.c,v 1.22 2022/09/22 21:00:46 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.21 2022/09/22 19:33:00 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.22 2022/09/22 21:00:46 ryo Exp $");
 
 #include 
 #include 
@@ -497,15 +497,6 @@ db_sp_trace(struct trapframe *tf, db_add
 	db_addr_t pc, sp, lr0;
 	bool allow_leaf_function = false;
 
-	if (tf == NULL) {
-		/*
-		 * In the case of "trace/s ",
-		 * the specified frame pointer address is considered
-		 * a trapframe (or a switchframe) address.
-		 */
-		tf = (struct trapframe *)fp;
-	}
-
 	pr_frame(tf, pr);
 
 	db_read_bytes((db_addr_t)tf, sizeof(tf_buf), (char *)_buf);
@@ -810,6 +801,15 @@ db_stack_trace_print(db_expr_t addr, boo
 	if (count > MAXBACKTRACE)
 		count = MAXBACKTRACE;
 
+	if (tf == NULL) {
+		/*
+		 * In the case of "trace ",
+		 * the specified frame pointer address is considered
+		 * a trapframe (or a switchframe) address.
+		 */
+		tf = (struct trapframe *)fp;
+	}
+
 	if (trace_sp) {
 		/* trace $lr pushed to sp */
 		db_sp_trace(tf, fp, count, flags, pr);



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 22 21:00:46 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
Specifying the frame address "trace " was not working.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/aarch64/aarch64/db_trace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 22 19:33:00 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
If there was a "bl " instruction at the end of a function block,
the stack analysis backtrace (bt/s) would fail because $lr would point
to the beginning of the next function.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/db_trace.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/db_trace.c
diff -u src/sys/arch/aarch64/aarch64/db_trace.c:1.20 src/sys/arch/aarch64/aarch64/db_trace.c:1.21
--- src/sys/arch/aarch64/aarch64/db_trace.c:1.20	Mon Sep 19 17:24:23 2022
+++ src/sys/arch/aarch64/aarch64/db_trace.c	Thu Sep 22 19:33:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.20 2022/09/19 17:24:23 ryo Exp $ */
+/* $NetBSD: db_trace.c,v 1.21 2022/09/22 19:33:00 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.20 2022/09/19 17:24:23 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.21 2022/09/22 19:33:00 ryo Exp $");
 
 #include 
 #include 
@@ -512,7 +512,7 @@ db_sp_trace(struct trapframe *tf, db_add
 	if (tf_buf.tf_sp == 0) {
 		/* switchframe */
 		lr0 = 0;
-		pc = aarch64_strip_pac(tf_buf.tf_lr);
+		pc = aarch64_strip_pac(tf_buf.tf_lr) - 4;
 		sp = (uint64_t)(tf + 1);
 	} else {
 		/* trapframe */
@@ -527,10 +527,10 @@ db_sp_trace(struct trapframe *tf, db_add
 	TRACE_DEBUG("lr0=%016lx\n", lr0);
 
 	for (; (count > 0) && (sp != 0); count--) {
-		if (((pc - 4) == (db_addr_t)el0_trap) ||
-		((pc - 4) == (db_addr_t)el1_trap)) {
+		if ((pc == (db_addr_t)el0_trap) ||
+		(pc == (db_addr_t)el1_trap)) {
 
-			pr_traceaddr("tf", sp, pc - 4, flags, pr);
+			pr_traceaddr("tf", sp, pc, flags, pr);
 
 			db_read_bytes((db_addr_t)sp, sizeof(tf_buf),
 			(char *)_buf);
@@ -541,7 +541,7 @@ db_sp_trace(struct trapframe *tf, db_add
 			sp = tf_buf.tf_sp;
 			pc = tf_buf.tf_pc;
 			if (pc == 0)
-pc = aarch64_strip_pac(tf_buf.tf_lr);
+pc = aarch64_strip_pac(tf_buf.tf_lr) - 4;
 			if (pc == 0)
 break;
 			lr0 = aarch64_strip_pac(tf_buf.tf_lr);
@@ -593,7 +593,7 @@ db_sp_trace(struct trapframe *tf, db_add
 			}
 
 			sp += stacksize;
-			pc = lr;
+			pc = lr - 4;
 		}
 	}
 }



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 22 19:33:00 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
If there was a "bl " instruction at the end of a function block,
the stack analysis backtrace (bt/s) would fail because $lr would point
to the beginning of the next function.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/db_trace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Sep 19 17:24:23 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
Fixed stack analyzing backtrace (bt/s) correctly for nested trapframes.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/aarch64/aarch64/db_trace.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/db_trace.c
diff -u src/sys/arch/aarch64/aarch64/db_trace.c:1.19 src/sys/arch/aarch64/aarch64/db_trace.c:1.20
--- src/sys/arch/aarch64/aarch64/db_trace.c:1.19	Tue Jun  7 23:55:25 2022
+++ src/sys/arch/aarch64/aarch64/db_trace.c	Mon Sep 19 17:24:23 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.19 2022/06/07 23:55:25 ryo Exp $ */
+/* $NetBSD: db_trace.c,v 1.20 2022/09/19 17:24:23 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -28,7 +28,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.19 2022/06/07 23:55:25 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.20 2022/09/19 17:24:23 ryo Exp $");
 
 #include 
 #include 
@@ -544,8 +544,8 @@ db_sp_trace(struct trapframe *tf, db_add
 pc = aarch64_strip_pac(tf_buf.tf_lr);
 			if (pc == 0)
 break;
-
-			pr_traceaddr("sp", sp, pc, flags, pr);
+			lr0 = aarch64_strip_pac(tf_buf.tf_lr);
+			allow_leaf_function = true;
 
 		} else {
 			db_sym_t sym;



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Sep 19 17:24:23 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: db_trace.c

Log Message:
Fixed stack analyzing backtrace (bt/s) correctly for nested trapframes.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/aarch64/aarch64/db_trace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Sep 19 17:23:14 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S db_interface.c

Log Message:
Move cpu_Debugger() into a more suitable file, from cpuswitch.S to 
db_interface.c.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/aarch64/aarch64/db_interface.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/cpuswitch.S
diff -u src/sys/arch/aarch64/aarch64/cpuswitch.S:1.38 src/sys/arch/aarch64/aarch64/cpuswitch.S:1.39
--- src/sys/arch/aarch64/aarch64/cpuswitch.S:1.38	Tue Jun  7 08:08:31 2022
+++ src/sys/arch/aarch64/aarch64/cpuswitch.S	Mon Sep 19 17:23:14 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuswitch.S,v 1.38 2022/06/07 08:08:31 ryo Exp $ */
+/* $NetBSD: cpuswitch.S,v 1.39 2022/09/19 17:23:14 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include "opt_ddb.h"
 #include "opt_kasan.h"
 
-RCSID("$NetBSD: cpuswitch.S,v 1.38 2022/06/07 08:08:31 ryo Exp $")
+RCSID("$NetBSD: cpuswitch.S,v 1.39 2022/09/19 17:23:14 ryo Exp $")
 
 	ARMV8_DEFINE_OPTIONS
 
@@ -334,16 +334,6 @@ ENTRY_NP(lwp_trampoline)
 END(lwp_trampoline)
 
 
-#ifdef DDB
-ENTRY_NP(cpu_Debugger)
-	stp	fp, lr, [sp, #-16]!
-	mov	fp, sp
-	brk	#0x
-	ldp	fp, lr, [sp], #16
-	ret
-END(cpu_Debugger)
-#endif /* DDB */
-
 /*
  * int cpu_set_onfault(struct faultbuf *fb)
  */

Index: src/sys/arch/aarch64/aarch64/db_interface.c
diff -u src/sys/arch/aarch64/aarch64/db_interface.c:1.18 src/sys/arch/aarch64/aarch64/db_interface.c:1.19
--- src/sys/arch/aarch64/aarch64/db_interface.c:1.18	Sun May 29 16:39:22 2022
+++ src/sys/arch/aarch64/aarch64/db_interface.c	Mon Sep 19 17:23:14 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: db_interface.c,v 1.18 2022/05/29 16:39:22 ryo Exp $ */
+/* $NetBSD: db_interface.c,v 1.19 2022/09/19 17:23:14 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.18 2022/05/29 16:39:22 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.19 2022/09/19 17:23:14 ryo Exp $");
 
 #include 
 #include 
@@ -639,3 +639,9 @@ db_ttbrdump(bool countmode, vaddr_t va,
 	db_dump_l0table(countmode, pmap_l0table(pm),
 	(pm == pmap_kernel()) ? 0xUL : 0, pr);
 }
+
+void
+cpu_Debugger(void)
+{
+	__asm __volatile ("brk #0x");
+}



CVS commit: src/sys/arch/aarch64/aarch64

2022-09-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Sep 19 17:23:14 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S db_interface.c

Log Message:
Move cpu_Debugger() into a more suitable file, from cpuswitch.S to 
db_interface.c.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/aarch64/aarch64/db_interface.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-08-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Aug 23 05:31:13 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: locore.S start.S

Log Message:
Bss clearing is now done at the beginning of start.S.

Some `__attribute__((__section__(".data")))' hack will no longer be needed.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/aarch64/aarch64/locore.S
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/aarch64/start.S

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/locore.S
diff -u src/sys/arch/aarch64/aarch64/locore.S:1.86 src/sys/arch/aarch64/aarch64/locore.S:1.87
--- src/sys/arch/aarch64/aarch64/locore.S:1.86	Fri May  6 06:09:50 2022
+++ src/sys/arch/aarch64/aarch64/locore.S	Tue Aug 23 05:31:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.86 2022/05/06 06:09:50 ryo Exp $	*/
+/*	$NetBSD: locore.S,v 1.87 2022/08/23 05:31:12 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -38,7 +38,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: locore.S,v 1.86 2022/05/06 06:09:50 ryo Exp $")
+RCSID("$NetBSD: locore.S,v 1.87 2022/08/23 05:31:12 ryo Exp $")
 
 #ifdef AARCH64_DEVICE_MEM_STRONGLY_ORDERED
 #define	MAIR_DEVICE_MEM		MAIR_DEVICE_nGnRnE
@@ -93,8 +93,6 @@ ASENTRY_NP(aarch64_start)
 	adrl	x0, bootstk
 	mov	sp, x0
 
-	bl	clear_bss
-
 	PRINT("boot NetBSD/aarch64\n")
 
 	bl	1f
@@ -238,18 +236,6 @@ ASEND(aarch64_start)
 	.align 2
 
 
-ASENTRY_NP(clear_bss)
-	/* Zero the BSS. The size must be aligned 16, usually it should be. */
-	adrl	x14, __bss_start__
-	adrl	x15, __bss_end__
-	b	2f
-1:	stp	xzr, xzr, [x14], #16
-2:	cmp	x14, x15
-	b.lo	1b
-	ret
-ASEND(clear_bss)
-
-
 init_sysregs:
 	stp	x0, lr, [sp, #-16]!
 

Index: src/sys/arch/aarch64/aarch64/start.S
diff -u src/sys/arch/aarch64/aarch64/start.S:1.12 src/sys/arch/aarch64/aarch64/start.S:1.13
--- src/sys/arch/aarch64/aarch64/start.S:1.12	Tue Aug 23 05:29:44 2022
+++ src/sys/arch/aarch64/aarch64/start.S	Tue Aug 23 05:31:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: start.S,v 1.12 2022/08/23 05:29:44 ryo Exp $	*/
+/*	$NetBSD: start.S,v 1.13 2022/08/23 05:31:12 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -33,7 +33,7 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: start.S,v 1.12 2022/08/23 05:29:44 ryo Exp $")
+RCSID("$NetBSD: start.S,v 1.13 2022/08/23 05:31:12 ryo Exp $")
 
 /*
  * Padding at start of kernel image to make room for 64-byte header
@@ -81,6 +81,19 @@ start:
 	br	x9
 9:
 
+
+	/*
+	 * Zero the BSS
+	 */
+	adrl	x8, __bss_start__
+	adrl	x9, __bss_end__
+	/* while (x8 < x9) *(uint128_t *)x8++ = 0; */
+	b	2f
+1:	stp	xzr, xzr, [x8], #16
+2:	cmp	x8, x9
+	b.lo	1b
+
+
 	mrs	x8, CurrentEL
 	lsr	x8, x8, #2
 	cmp	x8, #0x2



CVS commit: src/sys/arch/aarch64/aarch64

2022-08-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Aug 23 05:31:13 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: locore.S start.S

Log Message:
Bss clearing is now done at the beginning of start.S.

Some `__attribute__((__section__(".data")))' hack will no longer be needed.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/aarch64/aarch64/locore.S
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/aarch64/start.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2022-08-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Aug 23 05:29:44 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: start.S

Log Message:
Align the loaded kernel image to 2Mbytes, if necessary.

It appears that there are bootloaders that cannot specify the load address or 
ignore it.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/aarch64/start.S

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/start.S
diff -u src/sys/arch/aarch64/aarch64/start.S:1.11 src/sys/arch/aarch64/aarch64/start.S:1.12
--- src/sys/arch/aarch64/aarch64/start.S:1.11	Tue Sep 15 09:28:20 2020
+++ src/sys/arch/aarch64/aarch64/start.S	Tue Aug 23 05:29:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: start.S,v 1.11 2020/09/15 09:28:20 ryo Exp $	*/
+/*	$NetBSD: start.S,v 1.12 2022/08/23 05:29:44 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -33,12 +33,13 @@
 #include 
 #include "assym.h"
 
-RCSID("$NetBSD: start.S,v 1.11 2020/09/15 09:28:20 ryo Exp $")
+RCSID("$NetBSD: start.S,v 1.12 2022/08/23 05:29:44 ryo Exp $")
 
 /*
  * Padding at start of kernel image to make room for 64-byte header
  * (non-ELF booting)
  */
+.header:
 	.space	64, 0x0
 
 /*
@@ -46,6 +47,40 @@ RCSID("$NetBSD: start.S,v 1.11 2020/09/1
  */
 	.global start
 start:
+	/* DON'T CLOBBER X0-X3 REGISTERS. THEY ARE UBOOT ARGUMENTS */
+
+	/*
+	 * Relocate to L2_SIZE(2Mbyte) align if necessary
+	 *
+	 * x8 = currently loaded address
+	 * x9 = (x8 + L2_SIZE - 1) & -L2_SIZE = new (aligned) loaded address
+	 */
+	adrl	x8, .header
+	mov	x9, #(L2_SIZE-1)
+	add	x9, x9, x8
+	and	x9, x9, #-L2_SIZE
+	cmp	x8, x9
+	b.eq	9f
+
+	/* x10 = size = (_edata - __kernel_text) */
+	adrl	x10, _edata
+	adrl	x11, __kernel_text
+	sub	x10, x10, x11
+
+	/* do memmove(x9, x8, x10) */
+	add	x8, x8, x10
+	add	x13, x9, x10
+1:
+	ldp	x11, x12, [x8, #-16]!
+	stp	x11, x12, [x13, #-16]!
+	cmp	x13, x9
+	b.hi	1b
+
+	/* jump to new (aligned) loaded address */
+	add	x9, x9, #(start - .header)	/* skip header */
+	br	x9
+9:
+
 	mrs	x8, CurrentEL
 	lsr	x8, x8, #2
 	cmp	x8, #0x2



CVS commit: src/sys/arch/aarch64/aarch64

2022-08-22 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Aug 23 05:29:44 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: start.S

Log Message:
Align the loaded kernel image to 2Mbytes, if necessary.

It appears that there are bootloaders that cannot specify the load address or 
ignore it.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/aarch64/aarch64/start.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64

2022-08-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Aug 19 08:17:32 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c pmap.c
src/sys/arch/aarch64/include: pte.h

Log Message:
Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 
0x0001 in /dev/mem with mmap().


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/include/pte.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64

2022-08-19 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Fri Aug 19 08:17:32 UTC 2022

Modified Files:
src/sys/arch/aarch64/aarch64: aarch64_machdep.c pmap.c
src/sys/arch/aarch64/include: pte.h

Log Message:
Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 
0x0001 in /dev/mem with mmap().


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/aarch64/aarch64/aarch64_machdep.c
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/aarch64/aarch64/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/aarch64/include/pte.h

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.65 src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.66
--- src/sys/arch/aarch64/aarch64/aarch64_machdep.c:1.65	Sat Mar 12 09:16:05 2022
+++ src/sys/arch/aarch64/aarch64/aarch64_machdep.c	Fri Aug 19 08:17:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.65 2022/03/12 09:16:05 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.66 2022/08/19 08:17:32 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.65 2022/03/12 09:16:05 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.66 2022/08/19 08:17:32 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -619,6 +619,9 @@ mm_md_physacc(paddr_t pa, vm_prot_t prot
 	if (in_dram_p(pa, 0))
 		return 0;
 
+	if (pa >= AARCH64_MAX_PA)
+		return EFAULT;
+
 	return kauth_authorize_machdep(kauth_cred_get(),
 	KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL);
 }

Index: src/sys/arch/aarch64/aarch64/pmap.c
diff -u src/sys/arch/aarch64/aarch64/pmap.c:1.138 src/sys/arch/aarch64/aarch64/pmap.c:1.139
--- src/sys/arch/aarch64/aarch64/pmap.c:1.138	Fri Aug 19 07:45:50 2022
+++ src/sys/arch/aarch64/aarch64/pmap.c	Fri Aug 19 08:17:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.138 2022/08/19 07:45:50 ryo Exp $	*/
+/*	$NetBSD: pmap.c,v 1.139 2022/08/19 08:17:32 ryo Exp $	*/
 
 /*
  * Copyright (c) 2017 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.138 2022/08/19 07:45:50 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.139 2022/08/19 08:17:32 ryo Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -1915,6 +1915,7 @@ _pmap_enter(struct pmap *pm, vaddr_t va,
 	KASSERT_PM_ADDR(pm, va);
 	KASSERT(!IN_DIRECTMAP_ADDR(va));
 	KASSERT((prot & VM_PROT_ALL) != VM_PROT_NONE);
+	KASSERT(pa < AARCH64_MAX_PA);
 
 #ifdef PMAPCOUNTERS
 	PMAP_COUNT(mappings);

Index: src/sys/arch/aarch64/include/pte.h
diff -u src/sys/arch/aarch64/include/pte.h:1.13 src/sys/arch/aarch64/include/pte.h:1.14
--- src/sys/arch/aarch64/include/pte.h:1.13	Sun Oct 10 07:15:25 2021
+++ src/sys/arch/aarch64/include/pte.h	Fri Aug 19 08:17:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pte.h,v 1.13 2021/10/10 07:15:25 skrll Exp $ */
+/* $NetBSD: pte.h,v 1.14 2022/08/19 08:17:32 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -93,6 +93,7 @@ typedef uint64_t pt_entry_t;	/* L3(4k) t
 #define L1_BLK_OA		__BITS(47, 30)	/* 1GB */
 #define L2_BLK_OA		__BITS(47, 21)	/* 2MB */
 #define L3_PAG_OA		__BITS(47, 12)	/* 4KB */
+#define AARCH64_MAX_PA		__BIT(48)
 
 
 /* L0 table, 512GB/entry * 512 */



  1   2   3   4   5   >