CVS commit: src/external/cddl/osnet/dev/dtrace/aarch64

2021-04-06 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Apr  6 12:48:36 UTC 2021

Modified Files:
src/external/cddl/osnet/dev/dtrace/aarch64: dtrace_subr.c

Log Message:
sizeof(*var) instead of sizeof(type)
Call kmem_free() with size of data being freed.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 \
src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c

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

Modified files:

Index: src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c
diff -u src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.4 src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.5
--- src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.4	Thu Nov 12 02:15:56 2020
+++ src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c	Tue Apr  6 12:48:36 2021
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dtrace_subr.c,v 1.4 2020/11/12 02:15:56 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtrace_subr.c,v 1.5 2021/04/06 12:48:36 simonb Exp $");
 
 #include 
 #include 
@@ -87,7 +87,7 @@ dtrace_invop_add(int (*func)(uintptr_t, 
 {
 	dtrace_invop_hdlr_t *hdlr;
 
-	hdlr = kmem_alloc(sizeof (dtrace_invop_hdlr_t), KM_SLEEP);
+	hdlr = kmem_alloc(sizeof(*hdlr), KM_SLEEP);
 	hdlr->dtih_func = func;
 	hdlr->dtih_next = dtrace_invop_hdlr;
 	dtrace_invop_hdlr = hdlr;
@@ -120,7 +120,7 @@ dtrace_invop_remove(int (*func)(uintptr_
 		prev->dtih_next = hdlr->dtih_next;
 	}
 
-	kmem_free(hdlr, 0);
+	kmem_free(hdlr, sizeof(*hdlr));
 }
 
 /*ARGSUSED*/



CVS commit: src/external/cddl/osnet/dev/dtrace/aarch64

2020-11-11 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Nov 12 02:15:56 UTC 2020

Modified Files:
src/external/cddl/osnet/dev/dtrace/aarch64: dtrace_subr.c

Log Message:
One more catch up with ``aarch64 is not mips'' change.
Fix evbarm-aarch64 build.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c

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

Modified files:

Index: src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c
diff -u src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.3 src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.4
--- src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.3	Wed Feb 12 06:05:23 2020
+++ src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c	Thu Nov 12 02:15:56 2020
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dtrace_subr.c,v 1.3 2020/02/12 06:05:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtrace_subr.c,v 1.4 2020/11/12 02:15:56 rin Exp $");
 
 #include 
 #include 
@@ -128,7 +128,7 @@ void
 dtrace_toxic_ranges(void (*func)(uintptr_t base, uintptr_t limit))
 {
 
-	(*func)(0, (uintptr_t)AARCH64_KSEG_START);
+	(*func)(0, (uintptr_t)AARCH64_DIRECTMAP_START);
 	(*func)((uintptr_t)VM_KERNEL_IO_ADDRESS, ~(uintptr_t)0);
 }
 



CVS commit: src/external/cddl/osnet/dev/dtrace/aarch64

2020-02-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Feb 12 06:05:23 UTC 2020

Modified Files:
src/external/cddl/osnet/dev/dtrace/aarch64: dtrace_subr.c

Log Message:
Change the address ranges that aarch64 considers toxic for dtrace.

`Toxic' means dtrace forbids D scripts from even attempting to read
or write at them.

Previously we considered [0, VM_MIN_KERNEL_ADDRESS) toxic, but
VM_MIN_KERNEL_ADDRESS is only the minimum address of the kernel map;
the direct-mapped region lies below it, and with PMAP_MAP_POOLPAGE we
allocate virtual pages for pool backing directly from physical pages
through the direct-mapped region.  Also, this did not consider I/O
mappings to be toxic, which they probably should be.

Instead, treat:

[0, AARCH64_KSEG_START)
and
[VM_KERNEL_IO_ADDRESS, 0xfff...ff)

as toxic.  (The upper bound for 0xfff...ff ought to be inclusive, not
exclusive, but I think we'll need another mechanism for expressing
that to dtrace!)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c

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

Modified files:

Index: src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c
diff -u src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.2 src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.3
--- src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c:1.2	Wed Feb 12 01:09:38 2020
+++ src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_subr.c	Wed Feb 12 06:05:23 2020
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dtrace_subr.c,v 1.2 2020/02/12 01:09:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtrace_subr.c,v 1.3 2020/02/12 06:05:23 riastradh Exp $");
 
 #include 
 #include 
@@ -128,7 +128,8 @@ void
 dtrace_toxic_ranges(void (*func)(uintptr_t base, uintptr_t limit))
 {
 
-	(*func)(0, (uintptr_t)VM_MIN_KERNEL_ADDRESS);
+	(*func)(0, (uintptr_t)AARCH64_KSEG_START);
+	(*func)((uintptr_t)VM_KERNEL_IO_ADDRESS, ~(uintptr_t)0);
 }
 
 static void



CVS commit: src/external/cddl/osnet/dev/dtrace/aarch64

2020-02-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Feb 12 01:10:16 UTC 2020

Modified Files:
src/external/cddl/osnet/dev/dtrace/aarch64: dtrace_isa.c

Log Message:
Teach dtrace about el1_trap_exit frames on aarch64.

Implement dtrace_getarg and dtrace_getreg while here.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 \
src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_isa.c

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

Modified files:

Index: src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_isa.c
diff -u src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_isa.c:1.1 src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_isa.c:1.2
--- src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_isa.c:1.1	Tue Dec  3 22:10:56 2019
+++ src/external/cddl/osnet/dev/dtrace/aarch64/dtrace_isa.c	Wed Feb 12 01:10:16 2020
@@ -89,52 +89,60 @@ void
 dtrace_getpcstack(pc_t *pcstack, int pcstack_limit, int aframes,
 uint32_t *intrpc)
 {
-	struct unwind_state state;
-	int scp_offset;
-	register_t sp, fp;
-	int depth;
-
-	depth = 0;
-
-	if (intrpc != 0) {
-		pcstack[depth++] = (pc_t) intrpc;
+	extern const char el1_trap_exit[];
+	const register_t *fp;
+	int i = 0;
+
+	if (intrpc) {
+		if (i < pcstack_limit)
+			pcstack[i++] = (pc_t)intrpc;
 	}
 
-	aframes++;
-
-	__asm __volatile("mov %0, sp" : "=" (sp));
-
-	state.fp = (uint64_t)__builtin_frame_address(0);
-	state.sp = sp;
-	state.pc = (uint64_t)dtrace_getpcstack;
-
-	while (depth < pcstack_limit) {
-		if (!INKERNEL(state.pc) || !INKERNEL(state.fp))
-			break;
-
-		fp = state.fp;
-		state.sp = fp + 0x10;
-		/* FP to previous frame (X29) */
-		state.fp = *(register_t *)(fp);
-		/* LR (X30) */
-		state.pc = *(register_t *)(fp + 8) - 4;
-
-		/*
-		 * NB: Unlike some other architectures, we don't need to
-		 * explicitly insert cpu_dtrace_caller as it appears in the
-		 * normal kernel stack trace rather than a special trap frame.
-		 */
-		if (aframes > 0) {
+	/*
+	 * fp[0] = x29 (saved frame pointer)
+	 * fp[1] = x30 (saved link register == return address)
+	 */
+	fp = __builtin_frame_address(0);
+	while (i < pcstack_limit && INKERNEL(fp[0]) && INKERNEL(fp[1])) {
+		/* Skip the specified number of artificial frames.  */
+		if (aframes > 0)
 			aframes--;
+		else
+			pcstack[i++] = fp[1];
+
+		/* Check whether this frame is handling a trap.  */
+		if (fp[1] == (register_t)el1_trap_exit) {
+			/*
+			 * Trap from kernel.  The trapframe is the
+			 * saved frame pointer of the call to the trap
+			 * handler whose return address is
+			 * el1_trap_exit.  The frame pointer of the
+			 * interrupted code is in x29 stashed in the
+			 * trapframe, alongside its pc.
+			 */
+			const struct trapframe *tf = (const void *)fp[0];
+			/* x29 = frame pointer */
+			fp = (const void *)tf->tf_regs.r_reg[29];
+			if (INKERNEL(tf->tf_pc)) {
+if (i >= pcstack_limit)
+	break;
+if (aframes > 0)
+	aframes--;
+else
+	pcstack[i++] = tf->tf_pc;
+			}
 		} else {
-			pcstack[depth++] = state.pc;
+			/*
+			 * Not a trap.  Keep going with fp[0] as the
+			 * parent frame pointer.
+			 */
+			fp = (const void *)fp[0];
 		}
-
 	}
 
-	for (; depth < pcstack_limit; depth++) {
-		pcstack[depth] = 0;
-	}
+	/* Zero the rest of the return address stack.  (Paranoia?)  */
+	while (i < pcstack_limit)
+		pcstack[i++] = 0;
 }
 
 static int
@@ -282,48 +290,78 @@ dtrace_getufpstack(uint64_t *pcstack, ui
 uint64_t
 dtrace_getarg(int arg, int aframes)
 {
+	extern const char el1_trap_exit[];
+	const register_t *fp;
+	const struct trapframe *tf = NULL;
+	int i = 0;
 
-	printf("IMPLEMENT ME: %s\n", __func__);
+	/*
+	 * The first arguments are passed in x0,...,x7.  The rest are
+	 * on the stack, too much trouble to figure out.
+	 *
+	 * XXX Shouldn't we ask ctf or dwarf or something to figure
+	 * this stuff out for us?
+	 */
+	KASSERT(arg >= 0);
+	if (arg >= 8)
+		return 0;
+
+	fp = __builtin_frame_address(0);
+	while (i < 1000 && INKERNEL(fp[0]) && INKERNEL(fp[1])) {
+		if (aframes > 0)
+			aframes--;
+		else
+			i++;
+		if (fp[1] == (register_t)el1_trap_exit) {
+			tf = (const void *)fp[0];
+			break;
+		} else {
+			fp = (const void *)fp[0];
+		}
+	}
 
-	return (0);
+	/* If we didn't find a trap frame, give up.  */
+	if (tf == NULL)
+		return 0;
+
+	/* Arg0, arg1, ..., arg7 are in registers x0, x1, ..., x7.  */
+	return tf->tf_regs.r_reg[arg];
 }
 
 int
 dtrace_getstackdepth(int aframes)
 {
-	struct unwind_state state;
-	int scp_offset;
-	register_t sp;
-	int depth;
-	int done;
-
-	depth = 1;
-	done = 0;
-
-	__asm __volatile("mov %0, sp" : "=" (sp));
-
-	state.fp = (uint64_t)__builtin_frame_address(0);
-	state.sp = sp;
-	state.pc = (uint64_t)dtrace_getstackdepth;
-
-	do {
-		done = unwind_frame();
-		if (!INKERNEL(state.pc) || !INKERNEL(state.fp))
-			break;
-		depth++;
-	} while (!done);
+	extern const char el1_trap_exit[];
+	const register_t *fp;
+	int i = 0;
+
+	fp = __builtin_frame_address(0);