CVS commit: src/sys/arch/amd64/amd64

2023-07-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 31 02:38:16 UTC 2023

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

Log Message:
when cpus are paused (spinning) in DDB, call x86_pause() in the loop,
hopefully this can reduce power usage while doing nothing.

ok chs@

XXX: pullup-*
XXX: apply to i386


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/amd64/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/amd64/amd64/db_interface.c
diff -u src/sys/arch/amd64/amd64/db_interface.c:1.41 src/sys/arch/amd64/amd64/db_interface.c:1.42
--- src/sys/arch/amd64/amd64/db_interface.c:1.41	Wed Oct 26 23:38:06 2022
+++ src/sys/arch/amd64/amd64/db_interface.c	Mon Jul 31 02:38:16 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.41 2022/10/26 23:38:06 riastradh Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.42 2023/07/31 02:38:16 mrg Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.41 2022/10/26 23:38:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.42 2023/07/31 02:38:16 mrg Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -303,7 +303,7 @@ ddb_suspend(struct trapframe *frame)
 	atomic_or_32(>ci_flags, CPUF_PAUSE);
 
 	while (ci->ci_flags & CPUF_PAUSE)
-		;
+		x86_pause();
 	ci->ci_ddb_regs = 0;
 	tlbflushg();
 }



CVS commit: src/sys/arch/amd64/amd64

2023-07-30 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 31 02:38:16 UTC 2023

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

Log Message:
when cpus are paused (spinning) in DDB, call x86_pause() in the loop,
hopefully this can reduce power usage while doing nothing.

ok chs@

XXX: pullup-*
XXX: apply to i386


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/amd64/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/amd64/amd64

2023-02-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 27 16:24:28 UTC 2023

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S

Log Message:
amd64_trap.S: Annotate trap vectors with their mnemonics.

Derived from Intel and AMD manuals.

Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3
(3A, 3B, 3C, & 3D: System Programming Guide, Order Number:
325384-077US, April 2022.
https://cdrdv2.intel.com/v1/dl/getContent/671447

AMD64 Technology: AMD64 Architecture Programmers' Manual, Volume 2:
System Programming, Publication No. 24953, Revision 3.40, January 2023.
https://www.amd.com/system/files/TechDocs/24593.pdf

No functional change intended.

XXX Should apply the same treatment to i386_trap.S.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/amd64/amd64/amd64_trap.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/amd64/amd64/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.54 src/sys/arch/amd64/amd64/amd64_trap.S:1.55
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.54	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Mon Feb 27 16:24:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.54 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.55 2023/02/27 16:24:28 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2017 The NetBSD Foundation, Inc.
@@ -159,7 +159,7 @@
 
 	TEXT_USER_BEGIN
 
-IDTVEC(trap00)
+IDTVEC(trap00)		/* #DE - Divide-by-zero error */
 	ZTRAP(T_DIVIDE)
 IDTVEC_END(trap00)
 
@@ -178,7 +178,7 @@ IDTVEC_END(trap00)
  * not a problem, because in this particular case, the frame is known not
  * to contain secrets.
  */
-IDTVEC(trap01)
+IDTVEC(trap01)		/* #DB - Debug */
 #ifndef XENPV
 	subq	$(TF_REGSIZE+16),%rsp
 
@@ -247,7 +247,7 @@ IDTVEC_END(trap01)
  * We need to be careful about %gs too, because it is possible that we were
  * running in kernel mode with a userland %gs.
  */
-IDTVEC(trap02)
+IDTVEC(trap02)		/* NMI - Non-maskable interrupt */
 #if defined(XENPV)
 	ZTRAP(T_NMI)
 #else /* XENPV */
@@ -302,7 +302,7 @@ IDTVEC(trap02)
 #endif /* XENPV */
 IDTVEC_END(trap02)
 
-IDTVEC(trap03)
+IDTVEC(trap03)		/* #BP - Breakpoint */
 #ifndef KDTRACE_HOOKS
 	ZTRAP(T_BPTFLT)
 #else
@@ -331,19 +331,19 @@ IDTVEC(trap03)
 #endif
 IDTVEC_END(trap03)
 
-IDTVEC(trap04)
+IDTVEC(trap04)		/* #OF - Overflow */
 	ZTRAP(T_OFLOW)
 IDTVEC_END(trap04)
 
-IDTVEC(trap05)
+IDTVEC(trap05)		/* #BR - BOUND range exceeded */
 	ZTRAP(T_BOUND)
 IDTVEC_END(trap05)
 
-IDTVEC(trap06)
+IDTVEC(trap06)		/* #UD - Invalid opcode */
 	ZTRAP(T_PRIVINFLT)
 IDTVEC_END(trap06)
 
-IDTVEC(trap07)
+IDTVEC(trap07)		/* #NM - Device not available (x87) */
 	ZTRAP_NJ(T_DNA)
 	INTRENTRY
 #ifdef DIAGNOSTIC
@@ -358,7 +358,7 @@ IDTVEC_END(trap07)
  * Double faults execute on a particular stack, and we must not jump out
  * of it. So don't enable interrupts.
  */
-IDTVEC(trap08)
+IDTVEC(trap08)		/* #DF - Double fault */
 #if defined(XENPV)
 	TRAP(T_DOUBLEFLT)
 #else /* XENPV */
@@ -399,11 +399,11 @@ IDTVEC(trap08)
 #endif /* XENPV */
 IDTVEC_END(trap08)
 
-IDTVEC(trap09)
+IDTVEC(trap09)		/* Coprocessor segment overrun (legacy x87) */
 	ZTRAP(T_FPOPFLT)
 IDTVEC_END(trap09)
 
-IDTVEC(trap10)
+IDTVEC(trap10)		/* #TS - Invalid TSS */
 	TRAP(T_TSSFLT)
 IDTVEC_END(trap10)
 
@@ -416,26 +416,26 @@ IDTVEC_END(trap10)
 #define kernuser_reenter alltraps
 #endif /* XENPV */
 
-IDTVEC(trap11)		/* #NP() Segment not present */
+IDTVEC(trap11)		/* #NP - Segment not present */
 	TRAP_NJ(T_SEGNPFLT)
 	jmp	kernuser_reenter
 IDTVEC_END(trap11)
 
-IDTVEC(trap12)		/* #SS() Stack exception */
+IDTVEC(trap12)		/* #SS - Stack fault */
 	TRAP_NJ(T_STKFLT)
 	jmp	kernuser_reenter
 IDTVEC_END(trap12)
 
-IDTVEC(trap13)		/* #GP() General protection */
+IDTVEC(trap13)		/* #GP - General protection */
 	TRAP_NJ(T_PROTFLT)
 	jmp	kernuser_reenter
 IDTVEC_END(trap13)
 
-IDTVEC(trap14)
+IDTVEC(trap14)		/* #PF - Page fault */
 	TRAP(T_PAGEFLT)
 IDTVEC_END(trap14)
 
-IDTVEC(trap15)
+IDTVEC(trap15)		/* XXX ??? */
 	ZTRAP_NJ(T_ASTFLT)
 	INTRENTRY
 #ifdef DIAGNOSTIC
@@ -444,7 +444,7 @@ IDTVEC(trap15)
 	jmp	.Lalltraps_checkusr
 IDTVEC_END(trap15)
 
-IDTVEC(trap16)
+IDTVEC(trap16)		/* #MF - x87 floating-point exception */
 	ZTRAP_NJ(T_ARITHTRAP)
 .Ldo_fputrap:
 	INTRENTRY
@@ -464,30 +464,30 @@ IDTVEC(trap16)
 	jmp	.Lalltraps_checkusr
 IDTVEC_END(trap16)
 
-IDTVEC(trap17)
+IDTVEC(trap17)		/* #AC - Alignment check */
 	TRAP(T_ALIGNFLT)
 IDTVEC_END(trap17)
 
-IDTVEC(trap18)
+IDTVEC(trap18)		/* #MC - Machine check */
 	ZTRAP(T_MCA)
 IDTVEC_END(trap18)
 
-IDTVEC(trap19)
+IDTVEC(trap19)		/* #XM - SIMD floating-point exception */
 	ZTRAP_NJ(T_XMM)
 	jmp	.Ldo_fputrap
 IDTVEC_END(trap19)
 
-IDTVEC(trap20)
-IDTVEC(trap21)
+IDTVEC(trap20)		/* #VE - Virtualization (Intel) */
+IDTVEC(trap21)		/* #CP - Control protection */
 IDTVEC(trap22)
 IDTVEC(trap23)
 IDTVEC(trap24)
 

CVS commit: src/sys/arch/amd64/amd64

2023-02-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Feb 27 16:24:28 UTC 2023

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S

Log Message:
amd64_trap.S: Annotate trap vectors with their mnemonics.

Derived from Intel and AMD manuals.

Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3
(3A, 3B, 3C, & 3D: System Programming Guide, Order Number:
325384-077US, April 2022.
https://cdrdv2.intel.com/v1/dl/getContent/671447

AMD64 Technology: AMD64 Architecture Programmers' Manual, Volume 2:
System Programming, Publication No. 24953, Revision 3.40, January 2023.
https://www.amd.com/system/files/TechDocs/24593.pdf

No functional change intended.

XXX Should apply the same treatment to i386_trap.S.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/amd64/amd64/amd64_trap.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/amd64/amd64

2022-12-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 26 17:46:00 UTC 2022

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

Log Message:
sysret -> sysretl for new binutils


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/sys/arch/amd64/amd64/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/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.214 src/sys/arch/amd64/amd64/locore.S:1.215
--- src/sys/arch/amd64/amd64/locore.S:1.214	Tue Sep  6 20:40:18 2022
+++ src/sys/arch/amd64/amd64/locore.S	Mon Dec 26 12:46:00 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.214 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: locore.S,v 1.215 2022/12/26 17:46:00 christos Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1527,7 +1527,7 @@ SYSCALL_ENTRY	syscall_svs,is_svs=1
 #endif
 
 IDTVEC(syscall32)
-	sysret		/* go away please */
+	sysretl		/* go away please */
 IDTVEC_END(syscall32)
 
 	TEXT_USER_END



CVS commit: src/sys/arch/amd64/amd64

2022-12-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 26 17:46:00 UTC 2022

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

Log Message:
sysret -> sysretl for new binutils


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/sys/arch/amd64/amd64/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/amd64/amd64

2022-12-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 18 07:53:31 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: copy.S

Log Message:
Typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/copy.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/amd64/amd64

2022-12-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 18 07:53:31 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: copy.S

Log Message:
Typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/copy.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/amd64/amd64/copy.S
diff -u src/sys/arch/amd64/amd64/copy.S:1.34 src/sys/arch/amd64/amd64/copy.S:1.35
--- src/sys/arch/amd64/amd64/copy.S:1.34	Tue Jun 30 16:20:00 2020
+++ src/sys/arch/amd64/amd64/copy.S	Sun Dec 18 07:53:30 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.34 2020/06/30 16:20:00 maxv Exp $	*/
+/*	$NetBSD: copy.S,v 1.35 2022/12/18 07:53:30 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -120,7 +120,7 @@ END(do_pmap_load)
  * However the use of 'rep movsb' for the final bytes should be killed.
  *
  * Newer Intel cpus have a much lower setup time, and may (someday)
- * be ably to do cache-line size copies
+ * be able to do cache-line size copies
  */
 
 /*



CVS commit: src/sys/arch/amd64/amd64

2022-09-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 13 05:36:29 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Fix PR kern/57007.  I missed applying a part of the original patch.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/amd64/lock_stubs.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/amd64/amd64/lock_stubs.S
diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.37 src/sys/arch/amd64/amd64/lock_stubs.S:1.38
--- src/sys/arch/amd64/amd64/lock_stubs.S:1.37	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/amd64/amd64/lock_stubs.S	Tue Sep 13 05:36:29 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.S,v 1.37 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.38 2022/09/13 05:36:29 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -124,13 +124,13 @@ ENTRY(mutex_spin_exit)
 	movl	CPU_INFO_MTX_OLDSPL(%r8), %edi
 	incl	CPU_INFO_MTX_COUNT(%r8)
 	jnz	1f
-	cmpl	CPU_INFO_ILEVEL(%r8), %edi
+	cmpb	CPU_INFO_ILEVEL(%r8), %dil
 	jae	1f
-	movl	CPU_INFO_IUNMASK(%r8,%rdi,4), %esi
+	movq	CPU_INFO_IUNMASK(%r8,%rdi,8), %rsi
 	CLI(ax)
-	testl	CPU_INFO_IPENDING(%r8), %esi
+	testq	CPU_INFO_IPENDING(%r8), %rsi
 	jnz	_C_LABEL(Xspllower)
-	movl	%edi, CPU_INFO_ILEVEL(%r8)
+	movb	%dil, CPU_INFO_ILEVEL(%r8)
 	STI(ax)
 1:	rep	/* double byte ret as branch */
 	ret	/* target: see AMD docs */
@@ -141,23 +141,27 @@ ENTRY(mutex_spin_exit)
 	movb	$0x00, MTX_LOCK(%rdi)
 	movl	CPU_INFO_MTX_OLDSPL(%rsi), %ecx
 	incl	CPU_INFO_MTX_COUNT(%rsi)
-	movl	CPU_INFO_ILEVEL(%rsi),%edx
+	movzbl	CPU_INFO_ILEVEL(%rsi),%edx
 	cmovnzl	%edx,%ecx
-	pushq	%rbx
 	cmpl	%edx,%ecx			/* new level is lower? */
 	jae	2f
+	xorq	%rdi,%rdi			/* rdi: ci_ipending mask */
+	notq	%rdi
+	shrq	$8,%rdi
+	movq	%rcx,%r9			/* r9: shifted new level */
+	shlq	$56,%r9
 1:
-	movl	CPU_INFO_IPENDING(%rsi),%eax
-	testl	%eax,CPU_INFO_IUNMASK(%rsi,%rcx,4)/* deferred interrupts? */
+	movq	CPU_INFO_IPENDING(%rsi),%rax
+	testq	%rax,CPU_INFO_IUNMASK(%rsi,%rcx,8)/* deferred interrupts? */
 	jnz	3f
-	movl	%eax,%ebx
-	cmpxchg8b CPU_INFO_ISTATE(%rsi)		/* swap in new ilevel */
+	movq	%rax,%r8
+	andq	%rdi,%r8
+	orq	%r9,%r8
+	cmpxchgq %r8,CPU_INFO_ISTATE(%rsi)	/* swap in new ilevel */
 	jnz	4f
 2:
-	popq	%rbx
 	ret
 3:
-	popq	%rbx
 	movl	%ecx, %edi
 	jmp	_C_LABEL(Xspllower)
 4:



CVS commit: src/sys/arch/amd64/amd64

2022-09-12 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Tue Sep 13 05:36:29 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Fix PR kern/57007.  I missed applying a part of the original patch.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/amd64/lock_stubs.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/amd64/amd64

2022-09-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 12 02:21:11 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Update register name at fault.  Pointed out by hgutch@n.o, thanks.

In vetor.S:r1.78

IDTVEC(handle_hypervisor_callback)
  movlCPUVAR(ILEVEL),%edi
  pushq   %rdi /* for Xdoreti */

So, use %edi as before.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/amd64/amd64/vector.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/amd64/amd64

2022-09-11 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Mon Sep 12 02:21:11 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Update register name at fault.  Pointed out by hgutch@n.o, thanks.

In vetor.S:r1.78

IDTVEC(handle_hypervisor_callback)
  movlCPUVAR(ILEVEL),%edi
  pushq   %rdi /* for Xdoreti */

So, use %edi as before.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/amd64/amd64/vector.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/amd64/amd64/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.79 src/sys/arch/amd64/amd64/vector.S:1.80
--- src/sys/arch/amd64/amd64/vector.S:1.79	Wed Sep  7 00:40:18 2022
+++ src/sys/arch/amd64/amd64/vector.S	Mon Sep 12 02:21:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.79 2022/09/07 00:40:18 knakahara Exp $	*/
+/*	$NetBSD: vector.S,v 1.80 2022/09/12 02:21:11 knakahara Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -728,7 +728,7 @@ ENTRY(hypervisor_callback)
 	pushq	$T_ASTFLT
 	INTRENTRY
 IDTVEC(handle_hypervisor_callback)
-	movzbl	CPUVAR(ILEVEL),%rdi
+	movzbl	CPUVAR(ILEVEL),%edi
 	pushq   %rdi /* for Xdoreti */
 	incl	CPUVAR(IDEPTH)
 	movq	%rsp,%rdi



CVS commit: src/sys/arch/amd64/amd64

2022-06-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jun 27 23:36:48 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
amd64: Handle __syscall trap frames specially too.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/amd64/db_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/amd64/amd64/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.12 src/sys/arch/amd64/amd64/db_machdep.c:1.13
--- src/sys/arch/amd64/amd64/db_machdep.c:1.12	Sun Jun 26 22:31:12 2022
+++ src/sys/arch/amd64/amd64/db_machdep.c	Mon Jun 27 23:36:48 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.12 2022/06/26 22:31:12 riastradh Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.13 2022/06/27 23:36:48 riastradh Exp $	*/
 
 /*
  * Mach Operating System
@@ -26,7 +26,7 @@
  * rights to redistribute these changes.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.12 2022/06/26 22:31:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.13 2022/06/27 23:36:48 riastradh Exp $");
 
 #include 
 #include 
@@ -130,7 +130,7 @@ db_nextframe(long **nextframe, long **re
 	case SYSCALL:
 		tf = (struct trapframe *)argp;
 		syscallno = db_get_value((long)>tf_rax, 8, false);
-		if (syscallno == SYS_syscall) {
+		if (syscallno == SYS_syscall || syscallno == SYS___syscall) {
 			syscallno = db_get_value((long)>tf_rdi, 8, false);
 			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u"
 			" via SYS_syscall) ---\n",



CVS commit: src/sys/arch/amd64/amd64

2022-06-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jun 27 23:36:48 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
amd64: Handle __syscall trap frames specially too.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/amd64/db_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/amd64/amd64

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 22:31:12 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
amd64: Print effective syscall number for SYS_syscall stack traces.

This time with compile-testing, at least.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/amd64/amd64/db_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/amd64/amd64/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.11 src/sys/arch/amd64/amd64/db_machdep.c:1.12
--- src/sys/arch/amd64/amd64/db_machdep.c:1.11	Sun Jun 26 22:29:28 2022
+++ src/sys/arch/amd64/amd64/db_machdep.c	Sun Jun 26 22:31:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.11 2022/06/26 22:29:28 riastradh Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.12 2022/06/26 22:31:12 riastradh Exp $	*/
 
 /*
  * Mach Operating System
@@ -26,11 +26,12 @@
  * rights to redistribute these changes.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.11 2022/06/26 22:29:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.12 2022/06/26 22:31:12 riastradh Exp $");
 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -111,6 +112,7 @@ db_nextframe(long **nextframe, long **re
 	struct x86_64_frame *fp;
 	struct intrframe *ifp;
 	int traptype, trapno, err, i;
+	db_expr_t syscallno;
 
 	switch (is_trap) {
 	case NONE:
@@ -127,8 +129,16 @@ db_nextframe(long **nextframe, long **re
 
 	case SYSCALL:
 		tf = (struct trapframe *)argp;
-		(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
-		db_get_value((long)>tf_rax, 8, false));
+		syscallno = db_get_value((long)>tf_rax, 8, false);
+		if (syscallno == SYS_syscall) {
+			syscallno = db_get_value((long)>tf_rdi, 8, false);
+			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u"
+			" via SYS_syscall) ---\n",
+			syscallno);
+		} else {
+			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
+			syscallno);
+		}
 		return 0;
 
 	case TRAP:



CVS commit: src/sys/arch/amd64/amd64

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 22:31:12 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
amd64: Print effective syscall number for SYS_syscall stack traces.

This time with compile-testing, at least.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/amd64/amd64/db_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/amd64/amd64

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 22:29:28 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
Revert "amd64: Print effective syscall number for SYS_syscall stack traces."

Built the wrong kernel (arm64 is not amd64), oops.  Will redo.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/amd64/db_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/amd64/amd64/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.10 src/sys/arch/amd64/amd64/db_machdep.c:1.11
--- src/sys/arch/amd64/amd64/db_machdep.c:1.10	Sun Jun 26 22:18:30 2022
+++ src/sys/arch/amd64/amd64/db_machdep.c	Sun Jun 26 22:29:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.10 2022/06/26 22:18:30 riastradh Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.11 2022/06/26 22:29:28 riastradh Exp $	*/
 
 /*
  * Mach Operating System
@@ -26,7 +26,7 @@
  * rights to redistribute these changes.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.10 2022/06/26 22:18:30 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.11 2022/06/26 22:29:28 riastradh Exp $");
 
 #include 
 #include 
@@ -111,7 +111,6 @@ db_nextframe(long **nextframe, long **re
 	struct x86_64_frame *fp;
 	struct intrframe *ifp;
 	int traptype, trapno, err, i;
-	db_expr_t syscallno;
 
 	switch (is_trap) {
 	case NONE:
@@ -128,16 +127,8 @@ db_nextframe(long **nextframe, long **re
 
 	case SYSCALL:
 		tf = (struct trapframe *)argp;
-		syscallno = db_get_value((long)>tf_rax, 8, false);
-		if (syscallno == SYS_syscall) {
-			syscallno = db_get_value((long)>tf_rdi, 8, false);
-			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u"
-			" via SYS_syscall) ---\n",
-			syscallno);
-		} else {
-			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
-			syscallno);
-		}
+		(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
+		db_get_value((long)>tf_rax, 8, false));
 		return 0;
 
 	case TRAP:



CVS commit: src/sys/arch/amd64/amd64

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 22:29:28 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
Revert "amd64: Print effective syscall number for SYS_syscall stack traces."

Built the wrong kernel (arm64 is not amd64), oops.  Will redo.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/amd64/db_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/amd64/amd64

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 22:18:30 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
amd64: Print effective syscall number for SYS_syscall stack traces.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/amd64/db_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/amd64/amd64/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.9 src/sys/arch/amd64/amd64/db_machdep.c:1.10
--- src/sys/arch/amd64/amd64/db_machdep.c:1.9	Mon Dec 13 01:25:29 2021
+++ src/sys/arch/amd64/amd64/db_machdep.c	Sun Jun 26 22:18:30 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.9 2021/12/13 01:25:29 chs Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.10 2022/06/26 22:18:30 riastradh Exp $	*/
 
 /*
  * Mach Operating System
@@ -26,7 +26,7 @@
  * rights to redistribute these changes.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.9 2021/12/13 01:25:29 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.10 2022/06/26 22:18:30 riastradh Exp $");
 
 #include 
 #include 
@@ -111,6 +111,7 @@ db_nextframe(long **nextframe, long **re
 	struct x86_64_frame *fp;
 	struct intrframe *ifp;
 	int traptype, trapno, err, i;
+	db_expr_t syscallno;
 
 	switch (is_trap) {
 	case NONE:
@@ -127,8 +128,16 @@ db_nextframe(long **nextframe, long **re
 
 	case SYSCALL:
 		tf = (struct trapframe *)argp;
-		(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
-		db_get_value((long)>tf_rax, 8, false));
+		syscallno = db_get_value((long)>tf_rax, 8, false);
+		if (syscallno == SYS_syscall) {
+			syscallno = db_get_value((long)>tf_rdi, 8, false);
+			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u"
+			" via SYS_syscall) ---\n",
+			syscallno);
+		} else {
+			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
+			syscallno);
+		}
 		return 0;
 
 	case TRAP:



CVS commit: src/sys/arch/amd64/amd64

2022-06-26 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun 26 22:18:30 UTC 2022

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
amd64: Print effective syscall number for SYS_syscall stack traces.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/amd64/db_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/amd64/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:02:00 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Use bool for "write" in ptrace_machdep_dorequest() for clarity.
No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/process_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/amd64/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:02:00 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Use bool for "write" in ptrace_machdep_dorequest() for clarity.
No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/process_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/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.44 src/sys/arch/amd64/amd64/process_machdep.c:1.45
--- src/sys/arch/amd64/amd64/process_machdep.c:1.44	Tue Aug  6 01:34:29 2019
+++ src/sys/arch/amd64/amd64/process_machdep.c	Wed Nov 27 09:01:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.44 2019/08/06 01:34:29 kamil Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.45 2019/11/27 09:01:59 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.44 2019/08/06 01:34:29 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.45 2019/11/27 09:01:59 rin Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -315,15 +315,15 @@ ptrace_machdep_dorequest(
 	struct iovec iov;
 	struct vmspace *vm;
 	int error;
-	int write = 0;
+	bool write = false;
 
 	switch (req) {
 	case PT_SETXSTATE:
-		write = 1;
+		write = true;
 
 		/* FALLTHROUGH */
 	case PT_GETXSTATE:
-		/* write = 0 done above. */
+		/* write = false done above. */
 		if (!process_machdep_validxstate(lt->l_proc))
 			return EINVAL;
 		if (__predict_false(l->l_proc->p_flag & PK_32)) {



CVS commit: src/sys/arch/amd64/amd64

2019-11-20 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 20 10:57:08 UTC 2019

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

Log Message:
Fix netbsd32_process_write_dbregs() for amd64:

- Zero-clear regs64 so that random values are not written into the
  preserved registers.
- Cast 32-bit registers (int) to u_int, in order to avoid undesired
  sign extension when filled into 64-bit registers (long).

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-11-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Nov 15 09:50:01 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: cpu_in_cksum.S

Log Message:
Since cpu_in_cksum.S can be built outside of the kernel, add an ugly #ifdef
_KERNEL for kMSan.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/amd64/cpu_in_cksum.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/amd64/amd64/cpu_in_cksum.S
diff -u src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.4 src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.5
--- src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.4	Thu Nov 14 16:23:52 2019
+++ src/sys/arch/amd64/amd64/cpu_in_cksum.S	Fri Nov 15 09:50:01 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_in_cksum.S,v 1.4 2019/11/14 16:23:52 maxv Exp $ */
+/* $NetBSD: cpu_in_cksum.S,v 1.5 2019/11/15 09:50:01 maxv Exp $ */
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger .
@@ -30,7 +30,11 @@
  */
 
 #include 
+#ifdef _KERNEL
 #include 
+#else
+#define KMSAN_INIT_RET(sz)	/* nothing */
+#endif
 #include "assym.h"
 
 ENTRY(cpu_in_cksum)



CVS commit: src/sys/arch/amd64/amd64

2019-11-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Nov 15 09:50:01 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: cpu_in_cksum.S

Log Message:
Since cpu_in_cksum.S can be built outside of the kernel, add an ugly #ifdef
_KERNEL for kMSan.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/amd64/cpu_in_cksum.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/amd64/amd64

2019-09-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 26 01:39:22 UTC 2019

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

Log Message:
- promote regs from int to u_int in comparisons with unsigned constants
- cast -1 to __greg32_t which is unsigned and the LHS.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-09-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep 26 01:39:22 UTC 2019

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

Log Message:
- promote regs from int to u_int in comparisons with unsigned constants
- cast -1 to __greg32_t which is unsigned and the LHS.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/amd64/amd64/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/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.127 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.128
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.127	Wed Aug 21 08:46:56 2019
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Sep 25 21:39:22 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.127 2019/08/21 12:46:56 maxv Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.128 2019/09/26 01:39:22 christos Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.127 2019/08/21 12:46:56 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.128 2019/09/26 01:39:22 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -437,7 +437,7 @@ netbsd32_process_write_regs(struct lwp *
 	if (!VALID_USER_DSEL32(regs->r_ds) ||
 	!VALID_USER_DSEL32(regs->r_ss))
 		return EINVAL;
-	if (regs->r_eip >= VM_MAXUSER_ADDRESS32)
+	if ((u_int)regs->r_eip >= VM_MAXUSER_ADDRESS32)
 		return EINVAL;
 
 	tf->tf_rax = regs->r_eax;
@@ -479,7 +479,7 @@ netbsd32_process_write_dbregs(struct lwp
 
 	/* Check that DR0-DR3 contain user-space address */
 	for (i = 0; i < X86_DBREGS; i++) {
-		if (regs->dr[i] >= VM_MAXUSER_ADDRESS32)
+		if ((u_int)regs->dr[i] >= VM_MAXUSER_ADDRESS32)
 			return EINVAL;
 	}
 
@@ -811,7 +811,7 @@ cpu_getmcontext32(struct lwp *l, mcontex
 	gr[_REG32_ERR]= tf->tf_err;
 
 	if ((ras_eip = (__greg32_t)(uintptr_t)ras_lookup(l->l_proc,
-	(void *) (uintptr_t)gr[_REG32_EIP])) != -1)
+	(void *) (uintptr_t)gr[_REG32_EIP])) != (__greg32_t)-1)
 		gr[_REG32_EIP] = ras_eip;
 
 	*flags |= _UC_CPU;



CVS commit: src/sys/arch/amd64/amd64

2019-09-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Sep 18 20:18:27 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Avoid VLA to appease stack-protector

This has been reproduced with -O0 and -fsanitize=undefined.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-09-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Sep 18 20:18:27 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Avoid VLA to appease stack-protector

This has been reproduced with -O0 and -fsanitize=undefined.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/sys/arch/amd64/amd64/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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.123 src/sys/arch/amd64/amd64/trap.c:1.124
--- src/sys/arch/amd64/amd64/trap.c:1.123	Wed Aug 21 17:14:05 2019
+++ src/sys/arch/amd64/amd64/trap.c	Wed Sep 18 20:18:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.123 2019/08/21 17:14:05 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.124 2019/09/18 20:18:27 kamil Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.123 2019/08/21 17:14:05 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.124 2019/09/18 20:18:27 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -351,7 +351,7 @@ trap(struct trapframe *frame)
 	{
 		static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 };
 		const size_t sz = sizeof(lcall);
-		char tmp[sz];
+		char tmp[sizeof(lcall) /* Avoids VLA */];
 
 		/* Check for the oosyscall lcall instruction. */
 		if (p->p_emul == _netbsd32 &&



Re: CVS commit: src/sys/arch/amd64/amd64

2019-09-05 Thread Kamil Rytarowski
On 05.09.2019 14:57, Maxime Villard wrote:
> Module Name:  src
> Committed By: maxv
> Date: Thu Sep  5 12:57:30 UTC 2019
> 
> Modified Files:
>   src/sys/arch/amd64/amd64: lock_stubs.S
> 
> Log Message:
> Remove unused, and style.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/lock_stubs.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/amd64/amd64/lock_stubs.S
> diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.31 
> src/sys/arch/amd64/amd64/lock_stubs.S:1.32
> --- src/sys/arch/amd64/amd64/lock_stubs.S:1.31Mon Feb 11 14:59:32 2019
> +++ src/sys/arch/amd64/amd64/lock_stubs.S Thu Sep  5 12:57:30 2019
> @@ -1,6 +1,6 @@
> -/*   $NetBSD: lock_stubs.S,v 1.31 2019/02/11 14:59:32 cherry Exp $   */
> +/*   $NetBSD: lock_stubs.S,v 1.32 2019/09/05 12:57:30 maxv Exp $ */
>  
> -/*-
> +/*
>   * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
>   * All rights reserved.
>   *

This is our style use /*- for comments that shall not be reformatted
(originally indent(1) specific).



signature.asc
Description: OpenPGP digital signature


CVS commit: src/sys/arch/amd64/amd64

2019-09-05 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Sep  5 12:57:30 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Remove unused, and style.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/lock_stubs.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/amd64/amd64

2019-09-05 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Sep  5 12:57:30 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Remove unused, and style.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/lock_stubs.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/amd64/amd64/lock_stubs.S
diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.31 src/sys/arch/amd64/amd64/lock_stubs.S:1.32
--- src/sys/arch/amd64/amd64/lock_stubs.S:1.31	Mon Feb 11 14:59:32 2019
+++ src/sys/arch/amd64/amd64/lock_stubs.S	Thu Sep  5 12:57:30 2019
@@ -1,6 +1,6 @@
-/*	$NetBSD: lock_stubs.S,v 1.31 2019/02/11 14:59:32 cherry Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.32 2019/09/05 12:57:30 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -15,7 +15,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *notice, this list of conditions and the following disclaimer in the
  *documentation and/or other materials provided with the distribution.
- *  
+ *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -29,15 +29,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * AMD64 lock stubs.  Calling convention:
- *
- * %rdi		arg 1
- * %rsi		arg 2
- * %rdx		arg 3
- * %rax		return value
- */
-
 #include "opt_multiprocessor.h"
 #include "opt_lockdebug.h"
 
@@ -46,31 +37,30 @@
 
 #include "assym.h"
 
-#define	ENDLABEL(name,a) .align	a; LABEL(name)
-#define	LOCK(num)	\
+#define LOCK	\
 	HOTPATCH(HP_NAME_NOLOCK, 1)	; \
 	lock
-#define	RET(num)	\
+#define RET	\
 	HOTPATCH(HP_NAME_RETFENCE, 3)	; \
 	ret; nop; nop			; \
 	ret
 
 #ifndef LOCKDEBUG
 
+	.align	64
+
 /*
  * void mutex_enter(kmutex_t *mtx);
  *
  * Acquire a mutex and post a load fence.
  */
-	.align	64
-
 ENTRY(mutex_enter)
 	movq	CPUVAR(CURLWP), %rcx
 	xorq	%rax, %rax
-	LOCK(1)
+	LOCK
 	cmpxchgq %rcx, (%rdi)
 	jnz	1f
-	RET(1)
+	RET
 1:
 	jmp	_C_LABEL(mutex_vector_enter)
 END(mutex_enter)
@@ -114,7 +104,7 @@ ENTRY(mutex_spin_enter)
 	testb	%al, %al
 	jnz	1f
 #endif
-	RET(2)
+	RET
 1:
 	jmp	_C_LABEL(mutex_spin_retry)	/* failed; hard case */
 END(mutex_spin_enter)
@@ -211,11 +201,11 @@ ENTRY(rw_enter)
 0:
 	testb	$(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
 	jnz	3f
-	leaq	RW_READ_INCR(%rax), %rdx 
-	LOCK(2)
+	leaq	RW_READ_INCR(%rax), %rdx
+	LOCK
 	cmpxchgq %rdx, (%rdi)
 	jnz	1f
-	RET(3)
+	RET
 1:
 	jmp	0b
 
@@ -225,10 +215,10 @@ ENTRY(rw_enter)
 2:	movq	CPUVAR(CURLWP), %rcx
 	xorq	%rax, %rax
 	orq	$RW_WRITE_LOCKED, %rcx
-	LOCK(3)
+	LOCK
 	cmpxchgq %rcx, (%rdi)
 	jnz	3f
-	RET(4)
+	RET
 3:
 	jmp	_C_LABEL(rw_vector_enter)
 END(rw_enter)
@@ -251,7 +241,7 @@ ENTRY(rw_exit)
 	cmpq	$RW_READ_INCR, %rax
 	jb	3f
 	leaq	-RW_READ_INCR(%rax), %rdx
-	LOCK(4)
+	LOCK
 	cmpxchgq %rdx, (%rdi)
 	jnz	1f
 	ret
@@ -264,7 +254,7 @@ ENTRY(rw_exit)
 2:	leaq	-RW_WRITE_LOCKED(%rax), %rdx
 	subq	CPUVAR(CURLWP), %rdx
 	jnz	3f
-	LOCK(5)
+	LOCK
 	cmpxchgq %rdx, (%rdi)
 	jnz	3f
 	ret
@@ -288,12 +278,12 @@ ENTRY(rw_tryenter)
 0:
 	testb	$(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al
 	jnz	4f
-	leaq	RW_READ_INCR(%rax), %rdx 
-	LOCK(8)
+	leaq	RW_READ_INCR(%rax), %rdx
+	LOCK
 	cmpxchgq %rdx, (%rdi)
 	jnz	1f
 	movl	%edx, %eax			/* nonzero */
-	RET(5)
+	RET
 1:
 	jmp	0b
 
@@ -303,12 +293,12 @@ ENTRY(rw_tryenter)
 2:	movq	CPUVAR(CURLWP), %rcx
 	xorq	%rax, %rax
 	orq	$RW_WRITE_LOCKED, %rcx
-	LOCK(9)
+	LOCK
 	cmpxchgq %rcx, (%rdi)
 	movl	$0, %eax
 	setz	%al
 3:
-	RET(6)
+	RET
 	ret
 4:
 	xorl	%eax, %eax
@@ -328,10 +318,10 @@ END(__cpu_simple_lock_init)
 ENTRY(__cpu_simple_lock)
 	movl	$0x0100, %eax
 1:
-	LOCK(6)
+	LOCK
 	cmpxchgb %ah, (%rdi)
 	jnz	2f
-	RET(7)
+	RET
 2:
 	movl	$0x0100, %eax
 	pause
@@ -349,10 +339,10 @@ END(__cpu_simple_unlock)
 
 ENTRY(__cpu_simple_lock_try)
 	movl	$0x0100, %eax
-	LOCK(7)
+	LOCK
 	cmpxchgb %ah, (%rdi)
 	movl	$0, %eax
 	setz	%al
-	RET(8)
+	RET
 END(__cpu_simple_lock_try)
 



Re: CVS commit: src/sys/arch/amd64/amd64

2019-08-24 Thread Maxime Villard

Le 21/08/2019 à 23:47, matthew green a écrit :

"Maxime Villard" writes:

Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 16:35:10 UTC 2019

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

Log Message:
Switch from printf to panic. These messages were notorious for being
unreadable, and at least a clean panic allows the user to inspect the
system via DDB. Also simplify the output, EAX gets overwritten with
the error code so it indicates nothing meaningful.


thanks for this.  i'd been working on the same myself.

do you have a reliable way to trigger this issue?  i thought that
returning to userland with a lock held would do it, but i wasn't
able to get that to work reliably.  there's more work related to
crash dumps i'd like to work on but i got distracted by testing a
change similar to this one and didn't get back to it yet.


if you hard-code a splhigh() in a syscall and invoke it, you can see
the message; to get the unreadable/garbage output you likely need to
have two threads that invoke the syscall at the same time


re: CVS commit: src/sys/arch/amd64/amd64

2019-08-21 Thread matthew green
"Maxime Villard" writes:
> Module Name:  src
> Committed By: maxv
> Date: Wed Aug 21 16:35:10 UTC 2019
> 
> Modified Files:
>   src/sys/arch/amd64/amd64: locore.S
> 
> Log Message:
> Switch from printf to panic. These messages were notorious for being
> unreadable, and at least a clean panic allows the user to inspect the
> system via DDB. Also simplify the output, EAX gets overwritten with
> the error code so it indicates nothing meaningful.

thanks for this.  i'd been working on the same myself.

do you have a reliable way to trigger this issue?  i thought that
returning to userland with a lock held would do it, but i wasn't
able to get that to work reliably.  there's more work related to
crash dumps i'd like to work on but i got distracted by testing a
change similar to this one and didn't get back to it yet.


.mrg.


CVS commit: src/sys/arch/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 17:14:05 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Style and cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/amd64/amd64/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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.122 src/sys/arch/amd64/amd64/trap.c:1.123
--- src/sys/arch/amd64/amd64/trap.c:1.122	Wed Aug 21 17:06:36 2019
+++ src/sys/arch/amd64/amd64/trap.c	Wed Aug 21 17:14:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.122 2019/08/21 17:06:36 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.123 2019/08/21 17:14:05 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.122 2019/08/21 17:06:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.123 2019/08/21 17:14:05 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -110,21 +110,17 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.1
 
 #ifdef KDTRACE_HOOKS
 #include 
-
 /*
- * This is a hook which is initialized by the dtrace module
- * to handle traps which might occur during DTrace probe
- * execution.
+ * This is a hook which is initialized by the dtrace module to handle traps
+ * which might occur during DTrace probe execution.
  */
-dtrace_trap_func_t	dtrace_trap_func = NULL;
-
-dtrace_doubletrap_func_t	dtrace_doubletrap_func = NULL;
+dtrace_trap_func_t dtrace_trap_func = NULL;
+dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL;
 #endif
 
 void nmitrap(struct trapframe *);
 void doubletrap(struct trapframe *);
 void trap(struct trapframe *);
-void trap_return_fault_return(struct trapframe *) __dead;
 
 const char * const trap_type[] = {
 	"privileged instruction fault",		/*  0 T_PRIVINFLT */
@@ -149,7 +145,7 @@ const char * const trap_type[] = {
 	"SSE FP exception",			/* 19 T_XMM */
 	"reserved trap",			/* 20 T_RESERVED */
 };
-int	trap_types = __arraycount(trap_type);
+int trap_types = __arraycount(trap_type);
 
 #ifdef TRAP_SIGDEBUG
 static void sigdebug(const struct trapframe *, const ksiginfo_t *, int);
@@ -274,7 +270,7 @@ trap(struct trapframe *frame)
 		p = l->l_proc;
 	} else {
 		/*
-		 * this can happen eg. on break points in early on boot.
+		 * This can happen eg on break points in early on boot.
 		 */
 		pcb = NULL;
 		p = NULL;
@@ -454,9 +450,7 @@ trap(struct trapframe *frame)
 			ksi.ksi_code = FPE_INTDIV;
 			break;
 		default:
-#ifdef DIAGNOSTIC
-			panic("unhandled type %x\n", type);
-#endif
+			KASSERT(0);
 			break;
 		}
 		goto trapsignal;
@@ -493,7 +487,7 @@ trap(struct trapframe *frame)
 			}
 		}
 
-		goto faultcommon;
+		goto pagefltcommon;
 
 	case T_PAGEFLT|T_USER: {
 		register vaddr_t va;
@@ -506,7 +500,7 @@ trap(struct trapframe *frame)
 		if (p->p_emul->e_usertrap != NULL &&
 		(*p->p_emul->e_usertrap)(l, cr2, frame) != 0)
 			return;
-faultcommon:
+pagefltcommon:
 		vm = p->p_vmspace;
 		if (__predict_false(vm == NULL)) {
 			goto we_re_toast;



CVS commit: src/sys/arch/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 17:14:05 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Style and cleanup.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 17:06:36 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Remove the single-step check, it is wrong. There is no way we could
single-step on these entry points. If there were, we would be running
with the wrong GS.base, and we would have died long before.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 17:06:36 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Remove the single-step check, it is wrong. There is no way we could
single-step on these entry points. If there were, we would be running
with the wrong GS.base, and we would have died long before.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/amd64/amd64/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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.121 src/sys/arch/amd64/amd64/trap.c:1.122
--- src/sys/arch/amd64/amd64/trap.c:1.121	Sat Jul 13 17:03:01 2019
+++ src/sys/arch/amd64/amd64/trap.c	Wed Aug 21 17:06:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.121 2019/07/13 17:03:01 mlelstv Exp $	*/
+/*	$NetBSD: trap.c,v 1.122 2019/08/21 17:06:36 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.121 2019/07/13 17:03:01 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.122 2019/08/21 17:06:36 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -151,8 +151,6 @@ const char * const trap_type[] = {
 };
 int	trap_types = __arraycount(trap_type);
 
-#define	IDTVEC(name)	__CONCAT(X, name)
-
 #ifdef TRAP_SIGDEBUG
 static void sigdebug(const struct trapframe *, const ksiginfo_t *, int);
 #define SIGDEBUG(a, b, c) sigdebug(a, b, c)
@@ -265,8 +263,6 @@ trap(struct trapframe *frame)
 	struct proc *p;
 	struct pcb *pcb;
 	extern char kcopy_fault[];
-	extern char IDTVEC(osyscall)[];
-	extern char IDTVEC(syscall32)[];
 	ksiginfo_t ksi;
 	void *onfault;
 	int type, error;
@@ -657,12 +653,6 @@ faultcommon:
 		if (x86_dbregs_user_trap())
 			break;
 
-		/* Check whether they single-stepped into a lcall. */
-		if (frame->tf_rip == (uint64_t)IDTVEC(osyscall) ||
-		frame->tf_rip == (uint64_t)IDTVEC(syscall32)) {
-			frame->tf_rflags &= ~PSL_T;
-			return;
-		}
 		goto we_re_toast;
 
 	case T_BPTFLT|T_USER:		/* bpt instruction fault */



CVS commit: src/sys/arch/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 16:35:10 UTC 2019

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

Log Message:
Switch from printf to panic. These messages were notorious for being
unreadable, and at least a clean panic allows the user to inspect the
system via DDB. Also simplify the output, EAX gets overwritten with
the error code so it indicates nothing meaningful.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 16:35:10 UTC 2019

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

Log Message:
Switch from printf to panic. These messages were notorious for being
unreadable, and at least a clean panic allows the user to inspect the
system via DDB. Also simplify the output, EAX gets overwritten with
the error code so it indicates nothing meaningful.


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/arch/amd64/amd64/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/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.185 src/sys/arch/amd64/amd64/locore.S:1.186
--- src/sys/arch/amd64/amd64/locore.S:1.185	Sat May 18 13:32:12 2019
+++ src/sys/arch/amd64/amd64/locore.S	Wed Aug 21 16:35:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.185 2019/05/18 13:32:12 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.186 2019/08/21 16:35:10 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1322,19 +1322,11 @@ ENTRY(handle_syscall)
 	jmp	syscall_sysret
 
 #ifdef DIAGNOSTIC
-	/* Report SPL error */
 .Lspl_error:
 	movabsq	$4f,%rdi
-	movl	TF_RAX(%rsp),%esi
-	movl	TF_RDI(%rsp),%edx
-	movl	%ebx,%ecx
-	movl	CPUVAR(ILEVEL),%r8d
-	xorq	%rax,%rax
-	call	_C_LABEL(printf)
-	movl	$IPL_NONE,%edi
-	call	_C_LABEL(spllower)
-	jmp	.Lsyscall_checkast
-4:	.asciz	"WARNING: SPL NOT LOWERED ON SYSCALL %d %d EXIT %x %x\n"
+	movl	CPUVAR(ILEVEL),%esi
+	call	_C_LABEL(panic)
+4:	.asciz	"spl not lowered on syscall, ilevel=%x"
 #endif
 
 /* AST pending or pmap load needed */



CVS commit: src/sys/arch/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 12:46:56 UTC 2019

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

Log Message:
Style and remove dead stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/amd64/amd64/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/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.126 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.127
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.126	Wed Aug 21 12:33:12 2019
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Aug 21 12:46:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.126 2019/08/21 12:33:12 maxv Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.127 2019/08/21 12:46:56 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.126 2019/08/21 12:33:12 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.127 2019/08/21 12:46:56 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -84,8 +84,8 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mac
 #include 
 
 /* Provide a the name of the architecture we're emulating */
-const char	machine32[] = "i386";
-const char	machine_arch32[] = "i386";	
+const char machine32[] = "i386";
+const char machine_arch32[] = "i386";
 
 #ifdef USER_LDT
 static int x86_64_get_ldt32(struct lwp *, void *, register_t *);
@@ -104,10 +104,8 @@ static int x86_64_set_mtrr32(struct lwp 
 #endif
 
 int check_sigcontext32(struct lwp *, const struct netbsd32_sigcontext *);
-
-void  netbsd32_buildcontext(struct lwp *l, struct trapframe *tf, void *fp,
-sig_t catcher, int onstack);
-
+void netbsd32_buildcontext(struct lwp *, struct trapframe *, void *,
+sig_t, int);
 int netbsd32_sendsig_siginfo(const ksiginfo_t *, const sigset_t *);
 
 #ifdef EXEC_AOUT
@@ -288,7 +286,7 @@ netbsd32_sendsig(const ksiginfo_t *ksi, 
 #ifdef COREDUMP
 /*
  * Dump the machine specific segment at the start of a core dump.
- */ 
+ */
 struct md_core32 {
 	struct reg32 intreg;
 	struct fpreg32 freg;
@@ -389,7 +387,7 @@ int
 netbsd32_process_read_fpregs(struct lwp *l, struct fpreg32 *regs, size_t *sz)
 {
 
-	__CTASSERT(sizeof *regs == sizeof (struct save87));
+	__CTASSERT(sizeof(*regs) == sizeof(struct save87));
 	process_read_fpregs_s87(l, (struct save87 *)regs);
 	return 0;
 }
@@ -467,7 +465,7 @@ netbsd32_process_write_fpregs(struct lwp
 size_t sz)
 {
 
-	__CTASSERT(sizeof *regs == sizeof (struct save87));
+	__CTASSERT(sizeof(*regs) == sizeof(struct save87));
 	process_write_fpregs_s87(l, (const struct save87 *)regs);
 	return 0;
 }
@@ -515,11 +513,11 @@ netbsd32_sysarch(struct lwp *l, const st
 		error = x86_iopl(l,
 		NETBSD32PTR64(SCARG(uap, parms)), retval);
 		break;
-	case X86_GET_LDT: 
+	case X86_GET_LDT:
 		error = x86_64_get_ldt32(l,
 		NETBSD32PTR64(SCARG(uap, parms)), retval);
 		break;
-	case X86_SET_LDT: 
+	case X86_SET_LDT:
 		error = x86_64_set_ldt32(l,
 		NETBSD32PTR64(SCARG(uap, parms)), retval);
 		break;
@@ -548,7 +546,7 @@ x86_64_set_ldt32(struct lwp *l, void *ar
 	int error;
 
 	if ((error = copyin(args, , sizeof(ua32))) != 0)
-		return (error);
+		return error;
 
 	ua.start = ua32.start;
 	ua.num = ua32.num;
@@ -621,18 +619,18 @@ x86_64_get_mtrr32(struct lwp *l, void *a
 	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_MTRR_GET,
 	NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
-	error = copyin(args, , sizeof args32);
+	error = copyin(args, , sizeof(args32));
 	if (error != 0)
 		return error;
 
 	if (args32.mtrrp == 0) {
 		n = (MTRR_I686_NFIXED_SOFT + MTRR_I686_NVAR_MAX);
-		return copyout(, (void *)(uintptr_t)args32.n, sizeof n);
+		return copyout(, (void *)(uintptr_t)args32.n, sizeof(n));
 	}
 
-	error = copyin((void *)(uintptr_t)args32.n, , sizeof n);
+	error = copyin((void *)(uintptr_t)args32.n, , sizeof(n));
 	if (error != 0)
 		return error;
 
@@ -652,7 +650,7 @@ x86_64_get_mtrr32(struct lwp *l, void *a
 		m32.type = mp->type;
 		m32.flags = mp->flags;
 		m32.owner = mp->owner;
-		error = copyout(, m32p, sizeof m32);
+		error = copyout(, m32p, sizeof(m32));
 		if (error != 0)
 			break;
 		mp++;
@@ -663,7 +661,7 @@ fail:
 		kmem_free(m64p, size);
 	if (error != 0)
 		n = 0;
-	copyout(, (void *)(uintptr_t)args32.n, sizeof n);
+	copyout(, (void *)(uintptr_t)args32.n, sizeof(n));
 	return error;
 }
 
@@ -685,13 +683,13 @@ x86_64_set_mtrr32(struct lwp *l, void *a
 	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_MTRR_SET,
 	NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
-	error = copyin(args, , sizeof args32);
+	error = copyin(args, , sizeof(args32));
 	if (error != 0)
 		return error;
 
-	error = copyin((void *)(uintptr_t)args32.n, , sizeof n);
+	error 

CVS commit: src/sys/arch/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 12:46:56 UTC 2019

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

Log Message:
Style and remove dead stuff.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 12:33:12 UTC 2019

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

Log Message:
Don't depend on #ifdef USER_LDT in cpu_mcontext32_validate(), but rather on
whether the proc uses a user-set LDT. Same as check_sigcontext32().


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-08-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 21 12:33:12 UTC 2019

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

Log Message:
Don't depend on #ifdef USER_LDT in cpu_mcontext32_validate(), but rather on
whether the proc uses a user-set LDT. Same as check_sigcontext32().


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/sys/arch/amd64/amd64/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/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.125 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.126
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.125	Sat Jul 20 18:25:11 2019
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Aug 21 12:33:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.125 2019/07/20 18:25:11 christos Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.126 2019/08/21 12:33:12 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.125 2019/07/20 18:25:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.126 2019/08/21 12:33:12 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -903,12 +903,6 @@ startlwp32(void *arg)
 	userret(l);
 }
 
-/*
- * For various reasons, the amd64 port can't do what the i386 port does,
- * and relies on catching invalid user contexts on exit from the kernel.
- * These functions perform the needed checks.
- */
-
 int
 check_sigcontext32(struct lwp *l, const struct netbsd32_sigcontext *scp)
 {
@@ -923,21 +917,22 @@ check_sigcontext32(struct lwp *l, const 
 		return EINVAL;
 
 	if (__predict_false(pmap->pm_ldt != NULL)) {
-		/* Only when the LDT is user-set (with USER_LDT) */
+		/* Allow unfamiliar segment register values (USER_LDT). */
 		if (!USERMODE(scp->sc_cs))
 			return EINVAL;
 	} else {
 		if (!VALID_USER_CSEL32(scp->sc_cs))
 			return EINVAL;
 		if (scp->sc_fs != 0 && !VALID_USER_DSEL32(scp->sc_fs) &&
-			!(VALID_USER_FSEL32(scp->sc_fs) && pcb->pcb_fs != 0))
+		!(VALID_USER_FSEL32(scp->sc_fs) && pcb->pcb_fs != 0))
 			return EINVAL;
 		if (scp->sc_gs != 0 && !VALID_USER_DSEL32(scp->sc_gs) &&
-			!(VALID_USER_GSEL32(scp->sc_gs) && pcb->pcb_gs != 0))
+		!(VALID_USER_GSEL32(scp->sc_gs) && pcb->pcb_gs != 0))
 			return EINVAL;
 		if (scp->sc_es != 0 && !VALID_USER_DSEL32(scp->sc_es))
 			return EINVAL;
-		if (!VALID_USER_DSEL32(scp->sc_ds) || !VALID_USER_DSEL32(scp->sc_ss))
+		if (!VALID_USER_DSEL32(scp->sc_ds) ||
+		!VALID_USER_DSEL32(scp->sc_ss))
 			return EINVAL;
 	}
 
@@ -950,36 +945,37 @@ check_sigcontext32(struct lwp *l, const 
 int
 cpu_mcontext32_validate(struct lwp *l, const mcontext32_t *mcp)
 {
+	struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap;
 	const __greg32_t *gr;
 	struct trapframe *tf;
+	struct pcb *pcb;
 
 	gr = mcp->__gregs;
 	tf = l->l_md.md_regs;
+	pcb = lwp_getpcb(l);
 
 	if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0)
 		return EINVAL;
 
-#ifdef USER_LDT
-	/* Userland is allowed to have unfamiliar segment register values */
-	if (!USERMODE(gr[_REG32_CS]))
-		return EINVAL;
-#else
-	struct pcb *pcb = lwp_getpcb(l);
-
-	if (!VALID_USER_CSEL32(gr[_REG32_CS]))
-		return EINVAL;
-	if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) &&
-	!(VALID_USER_FSEL32(gr[_REG32_FS]) && pcb->pcb_fs != 0))
-		return EINVAL;
-	if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) &&
-	!(VALID_USER_GSEL32(gr[_REG32_GS]) && pcb->pcb_gs != 0))
-		return EINVAL;
-	if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES]))
-		return EINVAL;
-	if (!VALID_USER_DSEL32(gr[_REG32_DS]) ||
-	!VALID_USER_DSEL32(gr[_REG32_SS]))
-		return EINVAL;
-#endif
+	if (__predict_false(pmap->pm_ldt != NULL)) {
+		/* Allow unfamiliar segment register values (USER_LDT). */
+		if (!USERMODE(gr[_REG32_CS]))
+			return EINVAL;
+	} else {
+		if (!VALID_USER_CSEL32(gr[_REG32_CS]))
+			return EINVAL;
+		if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) &&
+		!(VALID_USER_FSEL32(gr[_REG32_FS]) && pcb->pcb_fs != 0))
+			return EINVAL;
+		if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) &&
+		!(VALID_USER_GSEL32(gr[_REG32_GS]) && pcb->pcb_gs != 0))
+			return EINVAL;
+		if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES]))
+			return EINVAL;
+		if (!VALID_USER_DSEL32(gr[_REG32_DS]) ||
+		!VALID_USER_DSEL32(gr[_REG32_SS]))
+			return EINVAL;
+	}
 
 	if (gr[_REG32_EIP] >= VM_MAXUSER_ADDRESS32)
 		return EINVAL;



CVS commit: src/sys/arch/amd64/amd64

2019-08-05 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Aug  6 01:34:29 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Do not dereference user pointer in ptrace_machdep_dorequest()/amd64

Always use copyin(9) for reading user memory.

This fixes SMAP crash on some amd64 machines.

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/amd64/amd64/process_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/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.43 src/sys/arch/amd64/amd64/process_machdep.c:1.44
--- src/sys/arch/amd64/amd64/process_machdep.c:1.43	Wed Jul 24 16:36:47 2019
+++ src/sys/arch/amd64/amd64/process_machdep.c	Tue Aug  6 01:34:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.43 2019/07/24 16:36:47 bouyer Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.44 2019/08/06 01:34:29 kamil Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.43 2019/07/24 16:36:47 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.44 2019/08/06 01:34:29 kamil Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -327,14 +327,21 @@ ptrace_machdep_dorequest(
 		if (!process_machdep_validxstate(lt->l_proc))
 			return EINVAL;
 		if (__predict_false(l->l_proc->p_flag & PK_32)) {
-			struct netbsd32_iovec *user_iov = addr;
-			iov.iov_base = NETBSD32PTR64(user_iov->iov_base);
-			iov.iov_len = user_iov->iov_len;
+			struct netbsd32_iovec user_iov;
+			if ((error = copyin(addr, _iov, sizeof(user_iov)))
+			!= 0)
+return error;
+
+			iov.iov_base = NETBSD32PTR64(user_iov.iov_base);
+			iov.iov_len = user_iov.iov_len;
 		} else {
-			struct iovec *user_iov;
-			user_iov = (struct iovec*)addr;
-			iov.iov_base = user_iov->iov_base;
-			iov.iov_len = user_iov->iov_len;
+			struct iovec user_iov;
+			if ((error = copyin(addr, _iov, sizeof(user_iov)))
+			!= 0)
+return error;
+
+			iov.iov_base = user_iov.iov_base;
+			iov.iov_len = user_iov.iov_len;
 		}
 
 		error = proc_vmspace_getref(l->l_proc, );



CVS commit: src/sys/arch/amd64/amd64

2019-08-05 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Aug  6 01:34:29 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Do not dereference user pointer in ptrace_machdep_dorequest()/amd64

Always use copyin(9) for reading user memory.

This fixes SMAP crash on some amd64 machines.

Reported by 


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/amd64/amd64/process_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/amd64/amd64

2019-07-24 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Jul 24 16:36:48 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c process_machdep.c

Log Message:
Remove XENPV-specific %ss/%cs handling, it doens't seem to be needed with
newer hypervisors (tested with 4.6 and 4.11)


To generate a diff of this commit:
cvs rdiff -u -r1.334 -r1.335 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/amd64/amd64/process_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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.334 src/sys/arch/amd64/amd64/machdep.c:1.335
--- src/sys/arch/amd64/amd64/machdep.c:1.334	Thu Jun 27 02:00:30 2019
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Jul 24 16:36:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.334 2019/06/27 02:00:30 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.335 2019/07/24 16:36:47 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.334 2019/06/27 02:00:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.335 2019/07/24 16:36:47 bouyer Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -2064,15 +2064,6 @@ cpu_setmcontext(struct lwp *l, const mco
 		tf->tf_rsp  = gr[_REG_RSP];
 		tf->tf_ss   = LSEL(LUDATA_SEL, SEL_UPL);
 
-#ifdef XENPV
-		/*
-		 * Xen has its own way of dealing with %cs and %ss,
-		 * reset them to proper values.
-		 */
-		tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL);
-		tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL);
-#endif
-
 		l->l_md.md_flags |= MDL_IRET;
 	}
 

Index: src/sys/arch/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.42 src/sys/arch/amd64/amd64/process_machdep.c:1.43
--- src/sys/arch/amd64/amd64/process_machdep.c:1.42	Sat Jul 20 18:25:11 2019
+++ src/sys/arch/amd64/amd64/process_machdep.c	Wed Jul 24 16:36:47 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.42 2019/07/20 18:25:11 christos Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.43 2019/07/24 16:36:47 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.42 2019/07/20 18:25:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.43 2019/07/24 16:36:47 bouyer Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -225,12 +225,6 @@ process_write_regs(struct lwp *l, const 
 	tf->tf_rflags = regs[_REG_RFLAGS];
 	tf->tf_rsp  = regs[_REG_RSP];
 
-#ifdef XENPV
-	/* see comment in cpu_setmcontext */
-	tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL);
-	tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL);
-#endif
-
 	return 0;
 }
 



CVS commit: src/sys/arch/amd64/amd64

2019-07-24 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Jul 24 16:36:48 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c process_machdep.c

Log Message:
Remove XENPV-specific %ss/%cs handling, it doens't seem to be needed with
newer hypervisors (tested with 4.6 and 4.11)


To generate a diff of this commit:
cvs rdiff -u -r1.334 -r1.335 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/amd64/amd64/process_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/amd64/amd64

2019-07-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jul 20 18:25:11 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c process_machdep.c

Log Message:
Restore the ability to debug a 32 bit process from a 64 bit debugger:
- add a function to validate a 64 bit context in 32 bit mode to write registers
- remove 32 bit checks from read and write register functions
- check for pc to fit in 32 bits.
proposed in tech-kern, ok maxv.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/amd64/process_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/amd64/amd64

2019-07-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jul 20 18:25:11 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c process_machdep.c

Log Message:
Restore the ability to debug a 32 bit process from a 64 bit debugger:
- add a function to validate a 64 bit context in 32 bit mode to write registers
- remove 32 bit checks from read and write register functions
- check for pc to fit in 32 bits.
proposed in tech-kern, ok maxv.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/amd64/process_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/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.124 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.125
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.124	Wed Jun 26 08:30:12 2019
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Sat Jul 20 14:25:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.124 2019/06/26 12:30:12 mgorny Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.125 2019/07/20 18:25:11 christos Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.124 2019/06/26 12:30:12 mgorny Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.125 2019/07/20 18:25:11 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -382,7 +382,7 @@ netbsd32_process_read_regs(struct lwp *l
 	regs->r_esp = tf->tf_rsp & 0x;
 	regs->r_ss = tf->tf_ss & 0x;
 
-	return (0);
+	return 0;
 }
 
 int
@@ -987,6 +987,25 @@ cpu_mcontext32_validate(struct lwp *l, c
 	return 0;
 }
 
+static int
+cpu_mcontext32from64_validate(struct lwp *l, const struct reg *regp)
+{
+	mcontext32_t mc;
+	__greg32_t *gr32 = mc.__gregs;
+	const __greg_t *gr = regp->regs;
+
+	memset(, 0, sizeof(mc));
+	gr32[_REG32_EFL] = gr[_REG_RFLAGS];
+	gr32[_REG32_EIP] = gr[_REG_RIP];
+	gr32[_REG32_CS] = gr[_REG_CS];
+	gr32[_REG32_DS] = gr[_REG_DS];
+	gr32[_REG32_ES] = gr[_REG_ES];
+	gr32[_REG32_FS] = gr[_REG_FS];
+	gr32[_REG32_GS] = gr[_REG_GS];
+	gr32[_REG32_SS] = gr[_REG_SS];
+	return cpu_mcontext32_validate(l, );
+}
+
 vaddr_t
 netbsd32_vm_default_addr(struct proc *p, vaddr_t base, vsize_t sz,
 int topdown)
@@ -1009,6 +1028,8 @@ netbsd32_machdep_md_init(void)
 {
 
 	MODULE_HOOK_SET(netbsd32_machine32_hook, "mach32", netbsd32_machine32);
+	MODULE_HOOK_SET(netbsd32_reg_validate_hook,
+	"mcontext32from64_validate", cpu_mcontext32from64_validate);
 }
 
 void
@@ -1016,4 +1037,5 @@ netbsd32_machdep_md_fini(void)
 {
 
 	MODULE_HOOK_UNSET(netbsd32_machine32_hook);
+	MODULE_HOOK_UNSET(netbsd32_reg_validate_hook);
 }

Index: src/sys/arch/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.41 src/sys/arch/amd64/amd64/process_machdep.c:1.42
--- src/sys/arch/amd64/amd64/process_machdep.c:1.41	Wed Jun 26 21:59:30 2019
+++ src/sys/arch/amd64/amd64/process_machdep.c	Sat Jul 20 14:25:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.41 2019/06/27 01:59:30 christos Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.42 2019/07/20 18:25:11 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.41 2019/06/27 01:59:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.42 2019/07/20 18:25:11 christos Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -83,6 +83,7 @@ __KERNEL_RCSID(0, "$NetBSD: process_mach
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -103,42 +104,48 @@ process_frame(struct lwp *l)
 }
 
 int
-process_read_regs(struct lwp *l, struct reg *regs)
+process_read_regs(struct lwp *l, struct reg *regp)
 {
 	struct trapframe *tf = process_frame(l);
-	struct proc *p = l->l_proc;
+	long *regs = regp->regs;
+	const bool pk32 = (l->l_proc->p_flag & PK_32) != 0;
 
-	if (p->p_flag & PK_32) {
-		return EINVAL;
-	}
-
-	regs->regs[_REG_RDI] = tf->tf_rdi;
-	regs->regs[_REG_RSI] = tf->tf_rsi;
-	regs->regs[_REG_RDX] = tf->tf_rdx;
-	regs->regs[_REG_R10] = tf->tf_r10;
-	regs->regs[_REG_R8]  = tf->tf_r8;
-	regs->regs[_REG_R9]  = tf->tf_r9;
+	regs[_REG_RDI] = tf->tf_rdi;
+	regs[_REG_RSI] = tf->tf_rsi;
+	regs[_REG_RDX] = tf->tf_rdx;
+	regs[_REG_R10] = tf->tf_r10;
+	regs[_REG_R8]  = tf->tf_r8;
+	regs[_REG_R9]  = tf->tf_r9;
 	/* argX not touched */
-	regs->regs[_REG_RCX] = tf->tf_rcx;
-	regs->regs[_REG_R11] = tf->tf_r11;
-	regs->regs[_REG_R12] = tf->tf_r12;
-	regs->regs[_REG_R13] = tf->tf_r13;
-	regs->regs[_REG_R14] = tf->tf_r14;
-	regs->regs[_REG_R15] = tf->tf_r15;
-	regs->regs[_REG_RBP] = tf->tf_rbp;
-	regs->regs[_REG_RBX] = tf->tf_rbx;
-	regs->regs[_REG_RAX] = tf->tf_rax;
-	regs->regs[_REG_GS]  = 0;
-	regs->regs[_REG_FS]  = 0;
-	regs->regs[_REG_ES]  = 

CVS commit: src/sys/arch/amd64/amd64

2019-07-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jul 13 17:03:01 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Use common code for SMEP/SMAP panic to print more information and
allow debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/amd64/amd64/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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.120 src/sys/arch/amd64/amd64/trap.c:1.121
--- src/sys/arch/amd64/amd64/trap.c:1.120	Wed May 15 13:49:10 2019
+++ src/sys/arch/amd64/amd64/trap.c	Sat Jul 13 17:03:01 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.120 2019/05/15 13:49:10 christos Exp $	*/
+/*	$NetBSD: trap.c,v 1.121 2019/07/13 17:03:01 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.120 2019/05/15 13:49:10 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.121 2019/07/13 17:03:01 mlelstv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -481,13 +481,9 @@ trap(struct trapframe *frame)
 		if (frame->tf_err & PGEX_X) {
 			/* SMEP might have brought us here */
 			if (cr2 < VM_MAXUSER_ADDRESS) {
-if (cr2 == 0)
-	panic("prevented jump to null"
-	" instruction pointer (SMEP)");
-else
-	panic("prevented execution of"
-	" user address %p (SMEP)",
-	(void *)cr2);
+printf("prevented execution of %p (SMEP)\n",
+(void *)cr2);
+goto we_re_toast;
 			}
 		}
 
@@ -495,8 +491,9 @@ trap(struct trapframe *frame)
 		cr2 < VM_MAXUSER_ADDRESS) {
 			/* SMAP might have brought us here */
 			if (onfault_handler(pcb, frame) == NULL) {
-panic("prevented access to %p (SMAP)",
+printf("prevented access to %p (SMAP)\n",
 (void *)cr2);
+goto we_re_toast;
 			}
 		}
 



CVS commit: src/sys/arch/amd64/amd64

2019-07-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jul 13 17:03:01 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Use common code for SMEP/SMAP panic to print more information and
allow debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/amd64/amd64/trap.c

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



Re: CVS commit: src/sys/arch/amd64/amd64

2019-06-28 Thread Christos Zoulas
In article ,
Maxime Villard   wrote:
>
>This isn't correct, with USER_LDT the 32bit LWPs may have non-default segregs,
>besides it is really dumb to mix 32 and 64bit code, part of the reasons why
>I dropped the thing

Yes, it is still missing the check that the compat_netbsd32 function had.

Before you disabled the code it was possible to debug a 32 bit process
with a 64 bit debugger. This is still useful because trying to debug a
32 bit process with a 32 bit debugger on a 64 system is extremely difficult
to get it right because the 32 bit debugger needs to know somehow that it
is running on a 64 bit system in order to mangle the paths properly and
load the appropriate shared libraries.

I think that the choice if we are going to let this work or not does not
belong to the opinion of a single person, but to the developer base of
NetBSD or the core group.

christos



Re: CVS commit: src/sys/arch/amd64/amd64

2019-06-27 Thread Maxime Villard

Le 27/06/2019 à 04:00, Christos Zoulas a écrit :

Module Name:src
Committed By:   christos
Date:   Thu Jun 27 02:00:31 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Although this is correct, I will let maxv commit it. Still waiting.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/arch/amd64/amd64/machdep.c

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


This isn't correct, with USER_LDT the 32bit LWPs may have non-default segregs,
besides it is really dumb to mix 32 and 64bit code, part of the reasons why
I dropped the thing


CVS commit: src/sys/arch/amd64/amd64

2019-06-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 27 02:00:31 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Although this is correct, I will let maxv commit it. Still waiting.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-06-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 27 02:00:31 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Although this is correct, I will let maxv commit it. Still waiting.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/arch/amd64/amd64/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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.333 src/sys/arch/amd64/amd64/machdep.c:1.334
--- src/sys/arch/amd64/amd64/machdep.c:1.333	Wed Jun 26 21:59:30 2019
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Jun 26 22:00:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.333 2019/06/27 01:59:30 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.334 2019/06/27 02:00:30 christos Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.333 2019/06/27 01:59:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.334 2019/06/27 02:00:30 christos Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -2095,50 +2095,44 @@ cpu_setmcontext(struct lwp *l, const mco
 int
 cpu_mcontext_validate(struct lwp *l, const mcontext_t *mcp)
 {
-	struct proc *p = l->l_proc;
+	struct proc *p __diagused = l->l_proc;
 	struct trapframe *tf = l->l_md.md_regs;
 	const __greg_t *gr;
 	uint16_t sel;
-	const bool pk32 = (p->p_flag & PK_32) != 0;
 
+	KASSERT((p->p_flag & PK_32) == 0);
 	gr = mcp->__gregs;
 
 	if (((gr[_REG_RFLAGS] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0)
 		return EINVAL;
-#define VUD(sel) (pk32 ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel))
-#define VUF(sel) (pk32 ? (VALID_USER_DSEL32(sel) || VALID_USER_FSEL32(sel)) \
-: VALID_USER_DSEL(sel))
-#define VUG(sel) (pk32 ? (VALID_USER_DSEL32(sel) || VALID_USER_GSEL32(sel)) \
-: VALID_USER_DSEL(sel))
-#define VUC(sel) (pk32 ? VALID_USER_CSEL32(sel) : VALID_USER_CSEL(sel))
 
 	sel = gr[_REG_ES] & 0x;
-	if (sel != 0 && !VUD(sel))
+	if (sel != 0 && !VALID_USER_DSEL(sel))
 		return EINVAL;
 
 	sel = gr[_REG_FS] & 0x;
-	if (sel != 0 && !VUF(sel))
+	if (sel != 0 && !VALID_USER_DSEL(sel))
 		return EINVAL;
 
 	sel = gr[_REG_GS] & 0x;
-	if (sel != 0 && !VUG(sel))
+	if (sel != 0 && !VALID_USER_DSEL(sel))
 		return EINVAL;
 
 	sel = gr[_REG_DS] & 0x;
-	if (!VUD(sel))
+	if (!VALID_USER_DSEL(sel))
 		return EINVAL;
 
 #ifndef XENPV
 	sel = gr[_REG_SS] & 0x;
-	if (!VUD(sel))
+	if (!VALID_USER_DSEL(sel))
 		return EINVAL;
 
 	sel = gr[_REG_CS] & 0x;
-	if (!VUC(sel))
+	if (!VALID_USER_CSEL(sel))
 		return EINVAL;
 #endif
 
-	if (gr[_REG_RIP] >= (pk32 ? VM_MAXUSER_ADDRESS32 : VM_MAXUSER_ADDRESS))
+	if (gr[_REG_RIP] >= VM_MAXUSER_ADDRESS)
 		return EINVAL;
 
 	return 0;



CVS commit: src/sys/arch/amd64/amd64

2019-06-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 27 01:59:30 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c process_machdep.c

Log Message:
don't cast void *


To generate a diff of this commit:
cvs rdiff -u -r1.332 -r1.333 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/amd64/amd64/process_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/amd64/amd64

2019-06-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun 12 14:28:38 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Add missing address check. This broke things like:

crash -w
w /l ipsec_debug 1

with an invalid address, because it found the first readonly segment and
returned EFAULT. I guess this never worked properly, but this got exposed
when maxv made text and rodata actually R/O?


To generate a diff of this commit:
cvs rdiff -u -r1.331 -r1.332 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-06-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun 12 14:28:38 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Add missing address check. This broke things like:

crash -w
w /l ipsec_debug 1

with an invalid address, because it found the first readonly segment and
returned EFAULT. I guess this never worked properly, but this got exposed
when maxv made text and rodata actually R/O?


To generate a diff of this commit:
cvs rdiff -u -r1.331 -r1.332 src/sys/arch/amd64/amd64/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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.331 src/sys/arch/amd64/amd64/machdep.c:1.332
--- src/sys/arch/amd64/amd64/machdep.c:1.331	Sun May 19 04:46:15 2019
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Jun 12 10:28:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.331 2019/05/19 08:46:15 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.332 2019/06/12 14:28:38 christos Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.331 2019/05/19 08:46:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.332 2019/06/12 14:28:38 christos Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -2161,6 +2161,8 @@ mm_md_kernacc(void *ptr, vm_prot_t prot,
 	for (i = 0; i < BTSPACE_NSEGS; i++) {
 		kva = bootspace.segs[i].va;
 		kva_end = kva + bootspace.segs[i].sz;
+		if (v < kva || v >= kva_end)
+			continue;
 		*handled = true;
 		if (bootspace.segs[i].type == BTSEG_TEXT ||
 		bootspace.segs[i].type == BTSEG_RODATA) {
@@ -2180,8 +2182,9 @@ mm_md_kernacc(void *ptr, vm_prot_t prot,
 
 	if (v >= bootspace.smodule && v < bootspace.emodule) {
 		*handled = true;
-		if (!uvm_map_checkprot(module_map, v, v + 1, prot))
+		if (!uvm_map_checkprot(module_map, v, v + 1, prot)) {
 			return EFAULT;
+		}
 	} else {
 		*handled = false;
 	}



CVS commit: src/sys/arch/amd64/amd64

2019-06-04 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Tue Jun  4 16:30:19 UTC 2019

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

Log Message:
compat32: Implement PT_GETDBREGS and PT_SETDBREGS

Uncomment and improve the implementation of compat32 support for
PT_GETDBREGS and PT_SETDBREGS requests.

The new implementation uses x86_dbregs_read() and x86_dbregs_write()
function instead of accessing pcb directly.  While this might be
a little slower, it guarantees that the needed pcb field is allocated
correctly.

Furthermore, the code introduces necessary sanity checks
for PT_SETDBREGS arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/amd64/amd64/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/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.122 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.123
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.122	Tue Jun  4 16:29:53 2019
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Tue Jun  4 16:30:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.122 2019/06/04 16:29:53 mgorny Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.123 2019/06/04 16:30:19 mgorny Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.122 2019/06/04 16:29:53 mgorny Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.123 2019/06/04 16:30:19 mgorny Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -395,23 +395,19 @@ netbsd32_process_read_fpregs(struct lwp 
 int
 netbsd32_process_read_dbregs(struct lwp *l, struct dbreg32 *regs, size_t *sz)
 {
-#if notyet
-	struct pcb *pcb;
-
-	pcb = lwp_getpcb(l);
+	struct dbreg regs64;
 
-	regs->dr[0] = pcb->pcb_dbregs->dr[0] & 0x;
-	regs->dr[1] = pcb->pcb_dbregs->dr[1] & 0x;
-	regs->dr[2] = pcb->pcb_dbregs->dr[2] & 0x;
-	regs->dr[3] = pcb->pcb_dbregs->dr[3] & 0x;
+	x86_dbregs_read(l, );
+	memset(regs, 0, sizeof(*regs));
+	regs->dr[0] = regs64.dr[0] & 0x;
+	regs->dr[1] = regs64.dr[1] & 0x;
+	regs->dr[2] = regs64.dr[2] & 0x;
+	regs->dr[3] = regs64.dr[3] & 0x;
 
-	regs->dr[6] = pcb->pcb_dbregs->dr[6] & 0x;
-	regs->dr[7] = pcb->pcb_dbregs->dr[7] & 0x;
+	regs->dr[6] = regs64.dr[6] & 0x;
+	regs->dr[7] = regs64.dr[7] & 0x;
 
 	return 0;
-#else
-	return ENOTSUP;
-#endif
 }
 
 int
@@ -478,23 +474,29 @@ int
 netbsd32_process_write_dbregs(struct lwp *l, const struct dbreg32 *regs,
 size_t sz)
 {
-#if notyet
-	struct pcb *pcb;
+	size_t i;
+	struct dbreg regs64;
 
-	pcb = lwp_getpcb(l);
+	/* Check that DR0-DR3 contain user-space address */
+	for (i = 0; i < X86_DBREGS; i++) {
+		if (regs->dr[i] >= VM_MAXUSER_ADDRESS32)
+			return EINVAL;
+	}
 
-	pcb->pcb_dbregs->dr[0] = regs->dr[0];
-	pcb->pcb_dbregs->dr[1] = regs->dr[1];
-	pcb->pcb_dbregs->dr[2] = regs->dr[2];
-	pcb->pcb_dbregs->dr[3] = regs->dr[3];
+	if (regs->dr[7] & X86_DR7_GENERAL_DETECT_ENABLE) {
+		return EINVAL;
+	}
 
-	pcb->pcb_dbregs->dr[6] = regs->dr[6];
-	pcb->pcb_dbregs->dr[7] = regs->dr[7];
+	regs64.dr[0] = regs->dr[0];
+	regs64.dr[1] = regs->dr[1];
+	regs64.dr[2] = regs->dr[2];
+	regs64.dr[3] = regs->dr[3];
 
+	regs64.dr[6] = regs->dr[6];
+	regs64.dr[7] = regs->dr[7];
+
+	x86_dbregs_write(l, );
 	return 0;
-#else
-	return ENOTSUP;
-#endif
 }
 
 int



CVS commit: src/sys/arch/amd64/amd64

2019-06-04 Thread Michał Górny
Module Name:src
Committed By:   mgorny
Date:   Tue Jun  4 16:30:19 UTC 2019

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

Log Message:
compat32: Implement PT_GETDBREGS and PT_SETDBREGS

Uncomment and improve the implementation of compat32 support for
PT_GETDBREGS and PT_SETDBREGS requests.

The new implementation uses x86_dbregs_read() and x86_dbregs_write()
function instead of accessing pcb directly.  While this might be
a little slower, it guarantees that the needed pcb field is allocated
correctly.

Furthermore, the code introduces necessary sanity checks
for PT_SETDBREGS arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-05-27 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May 28 03:52:09 UTC 2019

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

Log Message:
Replace misaligned operations with memcpy() calls in kobj_machdep.c

Detected with kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/amd64/amd64/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/amd64/amd64/kobj_machdep.c
diff -u src/sys/arch/amd64/amd64/kobj_machdep.c:1.7 src/sys/arch/amd64/amd64/kobj_machdep.c:1.8
--- src/sys/arch/amd64/amd64/kobj_machdep.c:1.7	Mon Dec 24 21:48:52 2018
+++ src/sys/arch/amd64/amd64/kobj_machdep.c	Tue May 28 03:52:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kobj_machdep.c,v 1.7 2018/12/24 21:48:52 christos Exp $	*/
+/*	$NetBSD: kobj_machdep.c,v 1.8 2019/05/28 03:52:08 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.7 2018/12/24 21:48:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.8 2019/05/28 03:52:08 kamil Exp $");
 
 #define	ELFSIZE		ARCH_ELFSIZE
 
@@ -115,7 +115,7 @@ kobj_reloc(kobj_t ko, uintptr_t relocbas
 		if (error)
 			return -1;
 		val = addr + addend;
-		*where = val;
+		memcpy(where, , sizeof(val));
 		break;
 
 	case R_X86_64_PC32:	/* S + A - P */
@@ -125,7 +125,7 @@ kobj_reloc(kobj_t ko, uintptr_t relocbas
 			return -1;
 		where32 = (Elf32_Addr *)where;
 		val32 = (Elf32_Addr)(addr + addend - (Elf64_Addr)where);
-		*where32 = val32;
+		memcpy(where32, , sizeof(val32));
 		break;
 
 	case R_X86_64_32:	/* S + A */
@@ -135,7 +135,7 @@ kobj_reloc(kobj_t ko, uintptr_t relocbas
 			return -1;
 		val32 = (Elf32_Addr)(addr + addend);
 		where32 = (Elf32_Addr *)where;
-		*where32 = val32;
+		memcpy(where32, , sizeof(val32));
 		break;
 
 	case R_X86_64_GLOB_DAT:	/* S */
@@ -143,13 +143,13 @@ kobj_reloc(kobj_t ko, uintptr_t relocbas
 		error = kobj_sym_lookup(ko, symidx, );
 		if (error)
 			return -1;
-		*where = addr;
+		memcpy(where, , sizeof(addr));
 		break;
 
 	case R_X86_64_RELATIVE:	/* B + A */
 		addr = relocbase + addend;
 		val = addr;
-		*where = val;
+		memcpy(where, , sizeof(val));
 		break;
 
 	default:



CVS commit: src/sys/arch/amd64/amd64

2019-05-27 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue May 28 03:52:09 UTC 2019

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

Log Message:
Replace misaligned operations with memcpy() calls in kobj_machdep.c

Detected with kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/amd64/amd64/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/amd64/amd64

2019-05-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 18 07:58:58 UTC 2019

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

Log Message:
Set the symbol type for intrfastexit, so that tools like tprof can find
the symbol name.


To generate a diff of this commit:
cvs rdiff -u -r1.183 -r1.184 src/sys/arch/amd64/amd64/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/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.183 src/sys/arch/amd64/amd64/locore.S:1.184
--- src/sys/arch/amd64/amd64/locore.S:1.183	Wed May 15 18:27:51 2019
+++ src/sys/arch/amd64/amd64/locore.S	Sat May 18 07:58:58 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.183 2019/05/15 18:27:51 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.184 2019/05/18 07:58:58 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1571,6 +1571,7 @@ END(pagezero)
 #define TF_BACKW(val, reg)	(val - (TF_REGSIZE+16))(reg)
 
 	_ALIGN_TEXT
+	.type intrfastexit,@function
 LABEL(intrfastexit)
 	NOT_XEN(cli;)
 	MDS_LEAVE



CVS commit: src/sys/arch/amd64/amd64

2019-05-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 15 13:49:10 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
print also ksi_code.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/amd64/amd64/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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.119 src/sys/arch/amd64/amd64/trap.c:1.120
--- src/sys/arch/amd64/amd64/trap.c:1.119	Fri Apr  5 23:06:24 2019
+++ src/sys/arch/amd64/amd64/trap.c	Wed May 15 09:49:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.119 2019/04/06 03:06:24 thorpej Exp $	*/
+/*	$NetBSD: trap.c,v 1.120 2019/05/15 13:49:10 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.119 2019/04/06 03:06:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.120 2019/05/15 13:49:10 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -751,10 +751,10 @@ sigdebug(const struct trapframe *tf, con
 	struct lwp *l = curlwp;
 	struct proc *p = l->l_proc;
 
-	printf("pid %d.%d (%s): signal %d (trap %#lx) "
+	printf("pid %d.%d (%s): signal %d code=%d (trap %#lx) "
 	"@rip %#lx addr %#lx error=%d\n",
-	p->p_pid, l->l_lid, p->p_comm, ksi->ksi_signo, tf->tf_trapno,
-	tf->tf_rip, rcr2(), e);
+	p->p_pid, l->l_lid, p->p_comm, ksi->ksi_signo, ksi->ksi_code,
+	tf->tf_trapno, tf->tf_rip, rcr2(), e);
 	frame_dump(tf, lwp_getpcb(l));
 }
 #endif



CVS commit: src/sys/arch/amd64/amd64

2019-05-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 15 13:49:10 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
print also ksi_code.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/amd64/amd64/trap.c

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



Re: CVS commit: src/sys/arch/amd64/amd64

2018-04-23 Thread Joerg Sonnenberger
On Sun, Apr 22, 2018 at 09:09:40PM +0200, Maxime Villard wrote:
> I recently told membership-exec that I would be less outspoken, and more
> convivial, so here's a try:
> 
> Le 22/04/2018 à 20:51, Joerg Sonnenberger a écrit :
> > On Sun, Apr 22, 2018 at 12:36:36PM +0200, Maxime Villard wrote:
> > > Where are they? I haven't been made aware of any issue related to 
> > > SVS+clang.
> > 
> > Yes, I did make you aware that SVS killed VirtualBox.
> 
> You are being dishonest. You did tell me that SVS didn't work with your
> VirtualBox. At no point in time did you tell me that it was related to clang
> or anything close to being a compiler issue, and not an implementation
> issue.

I didn't claim that now either. All I said is that SVS was known to be
broken in my environment. Understanding the issue took a while as
reproduction was annoying given that people continued to break the LLVM
build every other day, so it was hard to use official images for testing. 

> In fact, if you want my point of view, you reported your "problem" in a way
> that made me just unable to understand what it was about. I had to ask you
> repeatedly, question after question, what is your virtualbox, what is your
> cpu, is it hw-assisted, and so on.

Shockingly, I would have included more data if I know whether any of the
parameters are relevant. I originally ruled out LLVM since I thought it
worked on a different (physical) machine. No longer sure I did, given
that the machine is not supposed to use SVS for the obvious performance
implications.

Joerg


Re: CVS commit: src/sys/arch/amd64/amd64

2018-04-22 Thread Maxime Villard

I recently told membership-exec that I would be less outspoken, and more
convivial, so here's a try:

Le 22/04/2018 à 20:51, Joerg Sonnenberger a écrit :

On Sun, Apr 22, 2018 at 12:36:36PM +0200, Maxime Villard wrote:

Where are they? I haven't been made aware of any issue related to SVS+clang.


Yes, I did make you aware that SVS killed VirtualBox.


You are being dishonest. You did tell me that SVS didn't work with your
VirtualBox. At no point in time did you tell me that it was related to clang
or anything close to being a compiler issue, and not an implementation
issue.

In fact, if you want my point of view, you reported your "problem" in a way
that made me just unable to understand what it was about. I had to ask you
repeatedly, question after question, what is your virtualbox, what is your
cpu, is it hw-assisted, and so on.

In PR reports, we ask users to provide a minimal amount of information.

If you can't provide a full answer at once, and if I always have to ask one
more question all the time, you're just putting all the work on my side,
and I'm not going to use my crystal ball to try to guess what your exact
configuration or use-case is.

Having said that, I did review SVS when you reported your problem, I found
and fixed one issue, but it wasn't related to your problem.

Maxime


Re: CVS commit: src/sys/arch/amd64/amd64

2018-04-22 Thread Joerg Sonnenberger
On Sun, Apr 22, 2018 at 12:36:36PM +0200, Maxime Villard wrote:
> Where are they? I haven't been made aware of any issue related to SVS+clang.

Yes, I did make you aware that SVS killed VirtualBox.

Joerg


Re: CVS commit: src/sys/arch/amd64/amd64

2018-04-22 Thread Kamil Rytarowski
On 22.04.2018 12:36, Maxime Villard wrote:
> Le 22/04/2018 à 12:32, Kamil Rytarowski a écrit :
>> On 22.04.2018 07:46, Maxime Villard wrote:
>>> Le 22/04/2018 à 01:25, Joerg Sonnenberger a écrit :
 Module Name:    src
 Committed By:    joerg
 Date:    Sat Apr 21 23:25:01 UTC 2018

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

 Log Message:
 Do not use movq for loading arbitrary 64bit immediates. The ISA
 restricts it to 32bit immediates.


 To generate a diff of this commit:
 cvs rdiff -u -r1.163 -r1.164 src/sys/arch/amd64/amd64/locore.S

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
>>>
>>> Mmh. Is there a compiler where this makes a difference? On NetBSD/GGG it
>>> doesn't (because if it did, SVS would never have worked), but I see that
>>> on MacOS the instruction indeed makes a difference, the encoding
>>> becomes:
>>>
>>>  movq    0x0, %rax
>>>
>>> Which is obviously not what we expect.
>>>
>>> Is this the problem you were having a few weeks ago? That is to say, the
>>> kernel that was crashing at boot time, did you compile it on another
>>> system/compiler that generated a "movq 0x0,%rax"?
>>>
>>> Anyway your change seems correct.
>>>
>>> Thanks,
>>> Maxime
>>
>> There are reports that the SVS kernel built by Clang doesn't work.
> 
> Where are they? I haven't been made aware of any issue related to
> SVS+clang.
> 
> (By the way, I sent [pullup-8 #786] this morning.)

I'm only aware about notification about the problem from users on IRC.



signature.asc
Description: OpenPGP digital signature


Re: CVS commit: src/sys/arch/amd64/amd64

2018-04-22 Thread Maxime Villard

Le 22/04/2018 à 12:32, Kamil Rytarowski a écrit :

On 22.04.2018 07:46, Maxime Villard wrote:

Le 22/04/2018 à 01:25, Joerg Sonnenberger a écrit :

Module Name:src
Committed By:joerg
Date:Sat Apr 21 23:25:01 UTC 2018

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

Log Message:
Do not use movq for loading arbitrary 64bit immediates. The ISA
restricts it to 32bit immediates.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/amd64/amd64/locore.S

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


Mmh. Is there a compiler where this makes a difference? On NetBSD/GGG it
doesn't (because if it did, SVS would never have worked), but I see that
on MacOS the instruction indeed makes a difference, the encoding becomes:

 movq0x0, %rax

Which is obviously not what we expect.

Is this the problem you were having a few weeks ago? That is to say, the
kernel that was crashing at boot time, did you compile it on another
system/compiler that generated a "movq 0x0,%rax"?

Anyway your change seems correct.

Thanks,
Maxime


There are reports that the SVS kernel built by Clang doesn't work.


Where are they? I haven't been made aware of any issue related to SVS+clang.

(By the way, I sent [pullup-8 #786] this morning.)


Re: CVS commit: src/sys/arch/amd64/amd64

2018-04-21 Thread Maxime Villard

Le 22/04/2018 à 01:25, Joerg Sonnenberger a écrit :

Module Name:src
Committed By:   joerg
Date:   Sat Apr 21 23:25:01 UTC 2018

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

Log Message:
Do not use movq for loading arbitrary 64bit immediates. The ISA
restricts it to 32bit immediates.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/arch/amd64/amd64/locore.S

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


Mmh. Is there a compiler where this makes a difference? On NetBSD/GGG it
doesn't (because if it did, SVS would never have worked), but I see that
on MacOS the instruction indeed makes a difference, the encoding becomes:

movq0x0, %rax

Which is obviously not what we expect.

Is this the problem you were having a few weeks ago? That is to say, the
kernel that was crashing at boot time, did you compile it on another
system/compiler that generated a "movq 0x0,%rax"?

Anyway your change seems correct.

Thanks,
Maxime


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Maxime Villard

Le 24/02/2018 à 17:30, Christos Zoulas a écrit :

In article <18bc2a5a-f82d-91ba-5e52-b262c907b...@m00nbsd.net>,
Maxime Villard   wrote:

Le 24/02/2018 à 11:54, Martin Husemann a écrit :

On Sat, Feb 24, 2018 at 11:37:11AM +0100, Maxime Villard wrote:

If the macro was defined as #if, you would need to do something like:

SYSCALL_ENTRY(syscall)
#define SYSCALL_ENTRY_SVS
SYSCALL_ENTRY(syscall_svs)
#undef SYSCALL_ENTRY_SVS

Where SYSCALL_ENTRY would contain another macro that depends on whether
SYSCALL_ENTRY_SVS is defined.


Not sure I follow here.

I would do something like:

SYSCALL_ENTRY_PLAIN(syscall)
SYSCALL_ENTRY_SVS(syscall_svs)

and have the SYSCALL_ENTRY_SVS be defined empty ifndef SVS.


But then you are duplicating the code that is shared between the two.


Yes, I can see why you prefer macros here, but you are also duplicating
the stack frame formation code just because in one branch you are using
r15 and in the other rax. Why not simplify it? or use a macro for it?


Actually I was unhappy about having two different branches too. But thinking
about this, now that we have a dynamic detection for SVS, we can use %rax in
both branches. I've fixed that in rev1.155, now there is no duplication.

Maxime


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Christos Zoulas
In article <18bc2a5a-f82d-91ba-5e52-b262c907b...@m00nbsd.net>,
Maxime Villard   wrote:
>Le 24/02/2018 à 11:54, Martin Husemann a écrit :
>> On Sat, Feb 24, 2018 at 11:37:11AM +0100, Maxime Villard wrote:
>>> If the macro was defined as #if, you would need to do something like:
>>>
>>> SYSCALL_ENTRY(syscall)
>>> #define SYSCALL_ENTRY_SVS
>>> SYSCALL_ENTRY(syscall_svs)
>>> #undef SYSCALL_ENTRY_SVS
>>>
>>> Where SYSCALL_ENTRY would contain another macro that depends on whether
>>> SYSCALL_ENTRY_SVS is defined.
>> 
>> Not sure I follow here.
>> 
>> I would do something like:
>> 
>> SYSCALL_ENTRY_PLAIN(syscall)
>> SYSCALL_ENTRY_SVS(syscall_svs)
>> 
>> and have the SYSCALL_ENTRY_SVS be defined empty ifndef SVS.
>
>But then you are duplicating the code that is shared between the two.

Yes, I can see why you prefer macros here, but you are also duplicating
the stack frame formation code just because in one branch you are using
r15 and in the other rax. Why not simplify it? or use a macro for it?

christos



Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Maxime Villard

Le 24/02/2018 à 11:54, Martin Husemann a écrit :

On Sat, Feb 24, 2018 at 11:37:11AM +0100, Maxime Villard wrote:

If the macro was defined as #if, you would need to do something like:

SYSCALL_ENTRY(syscall)
#define SYSCALL_ENTRY_SVS
SYSCALL_ENTRY(syscall_svs)
#undef SYSCALL_ENTRY_SVS

Where SYSCALL_ENTRY would contain another macro that depends on whether
SYSCALL_ENTRY_SVS is defined.


Not sure I follow here.

I would do something like:

SYSCALL_ENTRY_PLAIN(syscall)
SYSCALL_ENTRY_SVS(syscall_svs)

and have the SYSCALL_ENTRY_SVS be defined empty ifndef SVS.


But then you are duplicating the code that is shared between the two.


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Martin Husemann
On Sat, Feb 24, 2018 at 11:37:11AM +0100, Maxime Villard wrote:
> If the macro was defined as #if, you would need to do something like:
> 
>   SYSCALL_ENTRY(syscall)
>   #define SYSCALL_ENTRY_SVS
>   SYSCALL_ENTRY(syscall_svs)
>   #undef SYSCALL_ENTRY_SVS
> 
> Where SYSCALL_ENTRY would contain another macro that depends on whether
> SYSCALL_ENTRY_SVS is defined.

Not sure I follow here.

I would do something like:

SYSCALL_ENTRY_PLAIN(syscall)
SYSCALL_ENTRY_SVS(syscall_svs)

and have the SYSCALL_ENTRY_SVS be defined empty ifndef SVS.

Martin


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Maxime Villard

Le 24/02/2018 à 11:14, Martin Husemann a écrit :

On Fri, Feb 23, 2018 at 08:09:09AM +0100, Maxime Villard wrote:

... And? There is only one place where we use .if instead of #if, because there
is a good reason for doing so.


Which reason is that?


Well, look at the code. We want to control what gets compiled in the macro
with an argument.

SYSCALL_ENTRY   syscall,is_svs=0
SYSCALL_ENTRY   syscall_svs,is_svs=1

If the macro was defined as #if, you would need to do something like:

SYSCALL_ENTRY(syscall)
#define SYSCALL_ENTRY_SVS
SYSCALL_ENTRY(syscall_svs)
#undef SYSCALL_ENTRY_SVS

Where SYSCALL_ENTRY would contain another macro that depends on whether
SYSCALL_ENTRY_SVS is defined.

The second approach is the one that complexifies the code.

Maxime


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Martin Husemann
On Fri, Feb 23, 2018 at 08:09:09AM +0100, Maxime Villard wrote:
> ... And? There is only one place where we use .if instead of #if, because 
> there
> is a good reason for doing so.

Which reason is that?

Martin


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-24 Thread Maxime Villard

Le 22/02/2018 à 17:31, Christos Zoulas a écrit :

In article <7f4de63c-e782-14e6-5554-9b9d23471...@m00nbsd.net>,
Maxime Villard   wrote:

Le 22/02/2018 à 15:54, Christos Zoulas a écrit :

In article <20180222140848.70e95f...@cvs.netbsd.org>,
Martin Husemann  wrote:

-=-=-=-=-=-

Module Name:src
Committed By:   martin
Date:   Thu Feb 22 14:08:48 UTC 2018

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

Log Message:
Protect the SVS part of SYSCALL_ENTRY by #ifdef SVS to make non-SVS
kernels compile again.


The combination of "#ifdef" and ".if" makes the code more horrific.
Can we use one and not the other? Preferrably "#ifdef" since we already
use it extensively?


In this case the ifdef just had to be put around the declaration.

You can't replace .if by #ifdef, there are two SYSCALL_ENTRY declarations,
and we give a different argument depending on whether we want the SVS code
to be in the macro or not.


The question is do we want to keep using both cpp and assembly macros.


Why wouldn't we? I don't see the problem.


The use of assembly macros is recent, the cpp one has always been there.
I.e. until recently we were not using .macro or .if, now we are.


... And? There is only one place where we use .if instead of #if, because there
is a good reason for doing so. It doesn't occur to me we need to replace all
the other #ifs by .ifs as a result.

Maxime


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-23 Thread Christos Zoulas
On Feb 23,  8:09am, m...@m00nbsd.net (Maxime Villard) wrote:
-- Subject: Re: CVS commit: src/sys/arch/amd64/amd64

| > The question is do we want to keep using both cpp and assembly macros.
| 
| Why wouldn't we? I don't see the problem.

Because it adds complexity.

| ... And? There is only one place where we use .if instead of #if, because
| there is a good reason for doing so. It doesn't occur to me we need to
| replace all the other #ifs by .ifs as a result.

Requiring macro support ties us more tightly to binutils and gas, since
the syntax and implementation is typically assembler specific. For example
does it work with the llvm assembler?

The bottom line is I would not use it unless it simplified the code a lot
and made it more readable (and easier to debug).

christos


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-22 Thread Christos Zoulas
In article <7f4de63c-e782-14e6-5554-9b9d23471...@m00nbsd.net>,
Maxime Villard   wrote:
>Le 22/02/2018 à 15:54, Christos Zoulas a écrit :
>> In article <20180222140848.70e95f...@cvs.netbsd.org>,
>> Martin Husemann  wrote:
>>> -=-=-=-=-=-
>>>
>>> Module Name:src
>>> Committed By:   martin
>>> Date:   Thu Feb 22 14:08:48 UTC 2018
>>>
>>> Modified Files:
>>> src/sys/arch/amd64/amd64: locore.S
>>>
>>> Log Message:
>>> Protect the SVS part of SYSCALL_ENTRY by #ifdef SVS to make non-SVS
>>> kernels compile again.
>> 
>> The combination of "#ifdef" and ".if" makes the code more horrific.
>> Can we use one and not the other? Preferrably "#ifdef" since we already
>> use it extensively?
>
>In this case the ifdef just had to be put around the declaration.
>
>You can't replace .if by #ifdef, there are two SYSCALL_ENTRY declarations,
>and we give a different argument depending on whether we want the SVS code
>to be in the macro or not.

The question is do we want to keep using both cpp and assembly macros.
The use of assembly macros is recent, the cpp one has always been there.
I.e. until recently we were not using .macro or .if, now we are.

christos



Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-22 Thread Maxime Villard

Le 22/02/2018 à 15:54, Christos Zoulas a écrit :

In article <20180222140848.70e95f...@cvs.netbsd.org>,
Martin Husemann  wrote:

-=-=-=-=-=-

Module Name:src
Committed By:   martin
Date:   Thu Feb 22 14:08:48 UTC 2018

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

Log Message:
Protect the SVS part of SYSCALL_ENTRY by #ifdef SVS to make non-SVS
kernels compile again.


The combination of "#ifdef" and ".if" makes the code more horrific.
Can we use one and not the other? Preferrably "#ifdef" since we already
use it extensively?


In this case the ifdef just had to be put around the declaration.

You can't replace .if by #ifdef, there are two SYSCALL_ENTRY declarations,
and we give a different argument depending on whether we want the SVS code
to be in the macro or not.

Maxime


Re: CVS commit: src/sys/arch/amd64/amd64

2018-02-22 Thread Christos Zoulas
In article <20180222140848.70e95f...@cvs.netbsd.org>,
Martin Husemann  wrote:
>-=-=-=-=-=-
>
>Module Name:   src
>Committed By:  martin
>Date:  Thu Feb 22 14:08:48 UTC 2018
>
>Modified Files:
>   src/sys/arch/amd64/amd64: locore.S
>
>Log Message:
>Protect the SVS part of SYSCALL_ENTRY by #ifdef SVS to make non-SVS
>kernels compile again.

The combination of "#ifdef" and ".if" makes the code more horrific.
Can we use one and not the other? Preferrably "#ifdef" since we already
use it extensively?

christos



Re: CVS commit: src/sys/arch/amd64/amd64

2017-03-25 Thread Maxime Villard

e 24/03/2017 à 21:32, co...@sdf.org a écrit :

cool!

I see in arch/i386/i386/locore.S that there is another call gate and
there's:

1246 IDTVEC(osyscall)
1247 #ifndef XEN
1248 /* XXX we are in trouble! interrupts be off here. */
1249 cli /* must be first instruction */
1250 #endif
1251 pushfl  /* set eflags in trap frame */

Is 'cli' as first instruction what should've been done here, if it
wasn't been otherwise useless? can xen not do it?


Yes, I saw that too. In fact, I didn't understand how putting 'cli' fixed
the issue, since an interrupt can still happen before this instruction.
Given that it was committed by ad@, he probably must have thought about
this too; so it perhaps means that call gates on i386 disable interrupt for
the first instruction or something like that, but I was unable to find any
reference to this in the SDMs.

For Xen, there is no documentation, so if you want to find out what happens
you need to dig into the Xen source code. As far as I can test, it seems
that Xen disables interrupts on call gates.

There is still at least one bug here: now that pushfl is the second
instruction, the first two single-steps should be ignored, and this [1]
branch should be 'osyscall + 2', otherwise we may unintentionnally disable
single-stepping when returing to userland.

[1] https://nxr.netbsd.org/xref/src/sys/arch/i386/i386/trap.c#716


Re: CVS commit: src/sys/arch/amd64/amd64

2017-03-24 Thread coypu
On Thu, Mar 23, 2017 at 05:25:51PM +, Maxime Villard wrote:
> Module Name:  src
> Committed By: maxv
> Date: Thu Mar 23 17:25:51 UTC 2017
> 
> Modified Files:
>   src/sys/arch/amd64/amd64: locore.S machdep.c trap.c
> 
> Log Message:
> Remove this call gate on amd64, it is useless and vulnerable.
> 
> Call gates do not modify %rflags, so interrupts are not disabled when
> entering the gate. There is a small window where we are in kernel mode and
> with a userland %gs, and if an interrupt happens here we will rejump into
> the kernel but not switch to the kernel TLS.
> 
> Userland can simply perform a gate call in a loop, and hope that at some
> point an interrupt will be received in this window - which necessarily will
> be the case. With a specially-crafted %gs it is certainly enough to
> escalate privileges.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.121 -r1.122 src/sys/arch/amd64/amd64/locore.S
> cvs rdiff -u -r1.253 -r1.254 src/sys/arch/amd64/amd64/machdep.c
> cvs rdiff -u -r1.94 -r1.95 src/sys/arch/amd64/amd64/trap.c
> 

cool!

I see in arch/i386/i386/locore.S that there is another call gate and
there's:

1246 IDTVEC(osyscall)
1247 #ifndef XEN
1248 /* XXX we are in trouble! interrupts be off here. */
1249 cli /* must be first instruction */
1250 #endif
1251 pushfl  /* set eflags in trap frame */

Is 'cli' as first instruction what should've been done here, if it
wasn't been otherwise useless? can xen not do it?

thanks.


Re: CVS commit: src/sys/arch/amd64/amd64

2016-05-29 Thread Maxime Villard

Le 29/05/2016 à 11:04, Maxime Villard a écrit :

Module Name:src
Committed By:   maxv
Date:   Sun May 29 09:04:20 UTC 2016

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

Log Message:
Revert rev1.94. It apparently raises a page fault from SMEP. I need to
investigate the whole kernel mappings anyway, so I'll recommit this
patch later.




I obviously meant rev1.95




To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/amd64/amd64/locore.S

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






Re: CVS commit: src/sys/arch/amd64/amd64

2016-05-08 Thread Maxime Villard

Le 07/05/2016 23:13, matthew green a écrit :

Joerg Sonnenberger writes:

On Sat, May 07, 2016 at 11:49:21AM +, Maxime Villard wrote:

Module Name:src
Committed By:   maxv
Date:   Sat May  7 11:49:21 UTC 2016

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

Log Message:
clarify


WTH. Can you please not mix arbitrary stylistic changes with refactoring
and whatever else you have hidden in this?!


I don't like the "arbitrary". I wrote this months ago, and the patch I have
for this file entails many more actual functional changes. I just committed
the stylistic and idiotic parts yesterday, because I was busy doing something
else. The other real changes will come separately soon.



agreed.  there is at least one functional change here:  PROC0_STK_OFF
has changed definition.  could you please explain this part?


It's rather simple:

-#define PROC0_STK_OFF  (PROC0_PML4_OFF + PAGE_SIZE)
+#define PROC0_STK_OFF  (PROC0_PML4_OFF + 1 * PAGE_SIZE)
  #define PROC0_PTP3_OFF(PROC0_STK_OFF + UPAGES * PAGE_SIZE)
  #define PROC0_PTP2_OFF(PROC0_PTP3_OFF + NKL4_KIMG_ENTRIES * PAGE_SIZE)
  #define PROC0_PTP1_OFF(PROC0_PTP2_OFF + TABLE_L3_ENTRIES * PAGE_SIZE)

All the macros are in the format NUMBER_OF_PAGES * PAGE_SIZE, so I put 1*
to make clear we are allocating one page.



additionally, please revert killkpt macro -- it makes it harder to
understand the assembly as it moves the 1: target into a macro so
that people will mis-reaad branch/jumps thinking they'll go to the
following 1:.


No. You can see above that there is the fillkpt macro, that is in charge
of setting up a set of pages. We now have a pair fillkpt/killkpt, which
is way clearer than hard-coded loops.

fillkpt too uses 1: loop 1b as well, and there is no problem with it.

I see by the way that I could have used killkpt for the PML4 entries as
well; I'll commit that right now.



thanks.


.mrg.





re: CVS commit: src/sys/arch/amd64/amd64

2016-05-07 Thread matthew green
Joerg Sonnenberger writes:
> On Sat, May 07, 2016 at 11:49:21AM +, Maxime Villard wrote:
> > Module Name:src
> > Committed By:   maxv
> > Date:   Sat May  7 11:49:21 UTC 2016
> > 
> > Modified Files:
> > src/sys/arch/amd64/amd64: locore.S
> > 
> > Log Message:
> > clarify
> 
> WTH. Can you please not mix arbitrary stylistic changes with refactoring
> and whatever else you have hidden in this?!

agreed.  there is at least one functional change here:  PROC0_STK_OFF
has changed definition.  could you please explain this part?

additionally, please revert killkpt macro -- it makes it harder to
understand the assembly as it moves the 1: target into a macro so
that people will mis-reaad branch/jumps thinking they'll go to the
following 1:.

thanks.


.mrg.


Re: CVS commit: src/sys/arch/amd64/amd64

2015-07-07 Thread David Laight
On Wed, Jul 01, 2015 at 02:04:43AM +, Christos Zoulas wrote:
 In article 20150630233112.ga8...@britannica.bec.de,
 Joerg Sonnenberger  jo...@britannica.bec.de wrote:
 On Tue, Jun 30, 2015 at 05:08:24PM -0400, Christos Zoulas wrote:
  Module Name:   src
  Committed By:  christos
  Date:  Tue Jun 30 21:08:24 UTC 2015
  
  Modified Files:
 src/sys/arch/amd64/amd64: cpu_in_cksum.S
  
  Log Message:
  handle PIC compilation (if we are building a PIE system; this is used
 by tests)
 
 Isn't the leaq generally preferable as smaller?
 
 I believe leaq is 7 bytes, and movq is 5. But I am not sure which takes
 more cycles.

'leaq' with %rip will have to be a long encoding since rip relative
isn't a 386 addressing mode.

My guess is that both take the same number of cycles on current cpus.
Some old brain cells recall 'lea' using different hardware from the ALU
(for adds) so happening at a different stage in the pipeline and having
different result delay and/or concurrency rules - but I can't remember
which particular cpu that applied to.

David

-- 
David Laight: da...@l8s.co.uk


Re: CVS commit: src/sys/arch/amd64/amd64

2015-06-30 Thread Christos Zoulas
In article 20150630233112.ga8...@britannica.bec.de,
Joerg Sonnenberger  jo...@britannica.bec.de wrote:
On Tue, Jun 30, 2015 at 05:08:24PM -0400, Christos Zoulas wrote:
 Module Name: src
 Committed By:christos
 Date:Tue Jun 30 21:08:24 UTC 2015
 
 Modified Files:
  src/sys/arch/amd64/amd64: cpu_in_cksum.S
 
 Log Message:
 handle PIC compilation (if we are building a PIE system; this is used
by tests)

Isn't the leaq generally preferable as smaller?

I believe leaq is 7 bytes, and movq is 5. But I am not sure which takes
more cycles.

christos



Re: CVS commit: src/sys/arch/amd64/amd64

2015-06-30 Thread Joerg Sonnenberger
On Tue, Jun 30, 2015 at 05:08:24PM -0400, Christos Zoulas wrote:
 Module Name:  src
 Committed By: christos
 Date: Tue Jun 30 21:08:24 UTC 2015
 
 Modified Files:
   src/sys/arch/amd64/amd64: cpu_in_cksum.S
 
 Log Message:
 handle PIC compilation (if we are building a PIE system; this is used by 
 tests)

Isn't the leaq generally preferable as smaller?

Joerg


Re: CVS commit: src/sys/arch/amd64/amd64

2014-05-12 Thread Joerg Sonnenberger
On Mon, May 12, 2014 at 01:49:24PM +, Masao Uebayashi wrote:
 Module Name:  src
 Committed By: uebayasi
 Date: Mon May 12 13:49:24 UTC 2014
 
 Modified Files:
   src/sys/arch/amd64/amd64: machdep.c
 
 Log Message:
 Don't reserve space (128) on signal stack for unknown reasons; the actual
 space for struct sigframe_siginfo (+ alignment) is allocated just below.

AMD64 uses a redzone, so the compiler can put up to 128 Bytes on the
stack without having to adjust RSP. Please revert immediately.

Joerg


Re: CVS commit: src/sys/arch/amd64/amd64

2014-05-12 Thread Jonathan A. Kollasch
On Mon, May 12, 2014 at 07:05:29PM +0200, Joerg Sonnenberger wrote:
 On Mon, May 12, 2014 at 01:49:24PM +, Masao Uebayashi wrote:
  Module Name:src
  Committed By:   uebayasi
  Date:   Mon May 12 13:49:24 UTC 2014
  
  Modified Files:
  src/sys/arch/amd64/amd64: machdep.c
  
  Log Message:
  Don't reserve space (128) on signal stack for unknown reasons; the actual
  space for struct sigframe_siginfo (+ alignment) is allocated just below.
 
 AMD64 uses a redzone, so the compiler can put up to 128 Bytes on the
 stack without having to adjust RSP. Please revert immediately.

Done.


Re: CVS commit: src/sys/arch/amd64/amd64

2014-05-12 Thread Masao Uebayashi
On Tue, May 13, 2014 at 2:28 AM, Jonathan A. Kollasch
jakll...@kollasch.net wrote:
 On Mon, May 12, 2014 at 07:05:29PM +0200, Joerg Sonnenberger wrote:
 On Mon, May 12, 2014 at 01:49:24PM +, Masao Uebayashi wrote:
  Module Name:src
  Committed By:   uebayasi
  Date:   Mon May 12 13:49:24 UTC 2014
 
  Modified Files:
  src/sys/arch/amd64/amd64: machdep.c
 
  Log Message:
  Don't reserve space (128) on signal stack for unknown reasons; the actual
  space for struct sigframe_siginfo (+ alignment) is allocated just below.

 AMD64 uses a redzone, so the compiler can put up to 128 Bytes on the
 stack without having to adjust RSP. Please revert immediately.

 Done.

Thanks.  I left a comment there.


Re: CVS commit: src/sys/arch/amd64/amd64

2012-04-21 Thread Paul Goyette

I just tested with a new updated kernel.

It no longer crashes.  Instead, it reports an expected failure:

x86 architecture does not correctly report the
address where the unaligned access occurred:
/build/netbsd-local/src/tests/lib/libc/gen/t_siginfo.c:427:
info-si_addr != (void *)addr

Much better!



On Sat, 21 Apr 2012, Jean-Yves Migeon wrote:


Le 21/04/12 20:52, Christos Zoulas a écrit :

Module Name:src
Committed By:   christos
Date:   Sat Apr 21 18:52:37 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Alignment fault traps push the error code automatically, so don't use 

ZTRAP!

Meh, the fix was awaiting Paul testing... Alright, so I guess this one is 
right.


Do you want me to ask for a pull-up?

--
jym@

!DSPAM:4f930ab01981554950846!





-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-

Re: CVS commit: src/sys/arch/amd64/amd64

2012-04-21 Thread Jean-Yves Migeon

Le 21/04/12 23:25, Christos Zoulas a écrit :

In article4f930a8c.6040...@free.fr,
Jean-Yves Migeonjeanyves.mig...@free.fr  wrote:

Le 21/04/12 20:52, Christos Zoulas a écrit :

Module Name:src
Committed By:   christos
Date:   Sat Apr 21 18:52:37 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Alignment fault traps push the error code automatically, so don't use

ZTRAP!

Meh, the fix was awaiting Paul testing... Alright, so I guess this one
is right.


Even if Paul's testing discovered that the fix did not work for the emulator,
wouldn't you commit it so that at least things work on real hardware?


It's the other way around; the bug was rather harmless in VMs (kills the 
process with a SIGILL), while it force-reboot the host on a native platform.


I could not know that the fix works on real hardware, that's why I was 
waiting for Paul's response.



Do you want me to ask for a pull-up?


Sure, thanks.


Will do.

--
jym@


Re: CVS commit: src/sys/arch/amd64/amd64

2012-04-21 Thread Christos Zoulas
On Apr 22, 12:00am, jeanyves.mig...@free.fr (Jean-Yves Migeon) wrote:
-- Subject: Re: CVS commit: src/sys/arch/amd64/amd64

| It's the other way around; the bug was rather harmless in VMs (kills the 
| process with a SIGILL), while it force-reboot the host on a native platform.

I had the real host so I was experiencing the crash, so I wanted to fix
it quickly.

| I could not know that the fix works on real hardware, that's why I was 
| waiting for Paul's response.

Ok.

christos


CVS commit: src/sys/arch/amd64/amd64

2010-02-22 Thread Christoph Egger
Module Name:src
Committed By:   cegger
Date:   Tue Feb 23 00:23:36 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
include opt_xen.h


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/vector.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/amd64/amd64/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.31 src/sys/arch/amd64/amd64/vector.S:1.32
--- src/sys/arch/amd64/amd64/vector.S:1.31	Thu Jul  9 21:43:16 2009
+++ src/sys/arch/amd64/amd64/vector.S	Tue Feb 23 00:23:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.31 2009/07/09 21:43:16 rmind Exp $	*/
+/*	$NetBSD: vector.S,v 1.32 2010/02/23 00:23:36 cegger Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,6 +68,7 @@
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
+#include opt_xen.h
 
 #define ALIGN_TEXT	.align 16,0x90
 



CVS commit: src/sys/arch/amd64/amd64

2010-02-22 Thread Christoph Egger
Module Name:src
Committed By:   cegger
Date:   Tue Feb 23 00:23:36 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
include opt_xen.h


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/vector.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/amd64/amd64

2010-01-18 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Mon Jan 18 21:55:40 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: procfs_machdep.c

Log Message:
Do not check more than 32 bits against ci_feature_flags, to avoid printing
bogus data on /proc/cpuinfo flags line.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/amd64/amd64/procfs_machdep.c

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



  1   2   >