CVS commit: src/tests/bin/sh

2016-05-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat May 14 00:33:02 UTC 2016

Modified Files:
src/tests/bin/sh: t_redir.sh

Log Message:
Add another test for the 48875 fix fallout...


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/bin/sh/t_redir.sh

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

Modified files:

Index: src/tests/bin/sh/t_redir.sh
diff -u src/tests/bin/sh/t_redir.sh:1.8 src/tests/bin/sh/t_redir.sh:1.9
--- src/tests/bin/sh/t_redir.sh:1.8	Wed May 11 17:43:17 2016
+++ src/tests/bin/sh/t_redir.sh	Sat May 14 00:33:02 2016
@@ -1,4 +1,4 @@
-# $NetBSD: t_redir.sh,v 1.8 2016/05/11 17:43:17 kre Exp $
+# $NetBSD: t_redir.sh,v 1.9 2016/05/14 00:33:02 kre Exp $
 #
 # Copyright (c) 2016 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -800,6 +800,21 @@ validate_fn_redirects_body()
 f "$B" <&3 >&4
 			done >&2'
 
+	# And this tests a similar condition with that same fix
+	cat  <<- 'DONE' >Script
+		f() {
+			printf '%s' " hello $1"
+		}
+		exec 3>&1
+		echo $( for i in a b c
+			do printf '%s' @$i; f $i >&3; done >foo
+		)
+		printf '%s\n' foo=$(cat foo)
+	DONE
+	atf_check -s exit:0 -e empty \
+	-o inline:' hello a hello b hello c\nfoo=@a@b@c\n' \
+	${TEST_SH} Script
+
 	# Tests with sh reading stdin, which is not quite the same internal
 	# mechanism.
 	echo ". ./f-def || echo >&2 FAIL



CVS commit: src/sys/arch/sparc64/sparc64

2016-05-13 Thread Palle Lyckegaard
Module Name:src
Committed By:   palle
Date:   Fri May 13 21:48:15 UTC 2016

Modified Files:
src/sys/arch/sparc64/sparc64: locore.s

Log Message:
sun4v: add missing implementation of sun4v_datatrap_tl0 so data_access_fault() 
is called - mostly from OpenBSD


To generate a diff of this commit:
cvs rdiff -u -r1.392 -r1.393 src/sys/arch/sparc64/sparc64/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/sparc64/sparc64/locore.s
diff -u src/sys/arch/sparc64/sparc64/locore.s:1.392 src/sys/arch/sparc64/sparc64/locore.s:1.393
--- src/sys/arch/sparc64/sparc64/locore.s:1.392	Fri May 13 21:21:25 2016
+++ src/sys/arch/sparc64/sparc64/locore.s	Fri May 13 21:48:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.392 2016/05/13 21:21:25 nakayama Exp $	*/
+/*	$NetBSD: locore.s,v 1.393 2016/05/13 21:48:15 palle Exp $	*/
 
 /*
  * Copyright (c) 2006-2010 Matthew R. Green
@@ -2829,9 +2829,66 @@ sun4v_datatrap:			! branch further based
 	 nop
 	ba	sun4v_datatrap_tl1
 	 nop
+
 sun4v_datatrap_tl0:
-	/* XXX missing implementaion */
-	sir
+	GET_MMFSA %g3! MMU Fault status area
+	add	%g3, 0x48, %g1
+	LDPTRA	[%g1] ASI_PHYS_CACHED, %g1	! Data fault address
+	add	%g3, 0x50, %g2
+	LDPTRA	[%g2] ASI_PHYS_CACHED, %g2	! Data fault context
+
+	TRAP_SETUP(-CC64FSZ-TF_SIZE)
+	or	%g1, %g2, %o3
+	mov	%g1, %o4
+
+	rdpr	%tt, %g4
+	rdpr	%tstate, %g1
+	rdpr	%tpc, %g2
+	rdpr	%tnpc, %g3
+
+	stx	%g1, [%sp + CC64FSZ + BIAS + TF_TSTATE]
+	mov	%g4, %o1		! (type)
+	stx	%g2, [%sp + CC64FSZ + BIAS + TF_PC]
+	rd	%y, %g5
+	stx	%g3, [%sp + CC64FSZ + BIAS + TF_NPC]
+	st	%g5, [%sp + CC64FSZ + BIAS + TF_Y]
+	mov	%g2, %o2		! (pc)
+	sth	%o1, [%sp + CC64FSZ + BIAS + TF_TT]! debug
+
+	cmp	%o1, T_FDMMU_PROT
+	bne,pn	%icc, 1f
+	 mov	SFSR_FV, %o5
+	or	%o5, SFSR_W, %o5
+
+1:
+	NORMAL_GLOBALS_SUN4V
+
+	stx	%g1, [%sp + CC64FSZ + BIAS + TF_G + (1*8)]
+	stx	%g2, [%sp + CC64FSZ + BIAS + TF_G + (2*8)]
+	add	%sp, CC64FSZ + BIAS, %o0		! ()
+	stx	%g3, [%sp + CC64FSZ + BIAS + TF_G + (3*8)]
+	stx	%g4, [%sp + CC64FSZ + BIAS + TF_G + (4*8)]
+	stx	%g5, [%sp + CC64FSZ + BIAS + TF_G + (5*8)]
+	rdpr	%pil, %g5
+	stx	%g6, [%sp + CC64FSZ + BIAS + TF_G + (6*8)]
+	stx	%g7, [%sp + CC64FSZ + BIAS + TF_G + (7*8)]
+	stb	%g5, [%sp + CC64FSZ + BIAS + TF_PIL]
+	stb	%g5, [%sp + CC64FSZ + BIAS + TF_OLDPIL]
+
+	/*
+	 * Phew, ready to enable traps and call C code.
+	 */
+	wrpr	%g0, 0, %tl
+
+	wr	%g0, ASI_PRIMARY_NOFAULT, %asi	! Restore default ASI
+	wrpr	%g0, PSTATE_INTR, %pstate	! traps on again
+	call	_C_LABEL(data_access_fault)	! data_acces_fault(tf, type, ...)
+	 nop
+
+	ba,a,pt	%icc, return_from_trap
+	 nop
+	NOTREACHED
+	
 sun4v_datatrap_tl1:
 	/* XXX missing implementaion */
 	sir



CVS commit: src/sys/arch/sparc64/sparc64

2016-05-13 Thread Takeshi Nakayama
Module Name:src
Committed By:   nakayama
Date:   Fri May 13 21:24:11 UTC 2016

Modified Files:
src/sys/arch/sparc64/sparc64: intr.c

Log Message:
Interrupt handlers are now allocated by kmem_zalloc(9), so free
them by kmem_free(9).


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/sparc64/sparc64/intr.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/sparc64/sparc64/intr.c
diff -u src/sys/arch/sparc64/sparc64/intr.c:1.68 src/sys/arch/sparc64/sparc64/intr.c:1.69
--- src/sys/arch/sparc64/sparc64/intr.c:1.68	Tue May 10 19:24:00 2016
+++ src/sys/arch/sparc64/sparc64/intr.c	Fri May 13 21:24:11 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.68 2016/05/10 19:24:00 palle Exp $ */
+/*	$NetBSD: intr.c,v 1.69 2016/05/13 21:24:11 nakayama Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.68 2016/05/10 19:24:00 palle Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.69 2016/05/13 21:24:11 nakayama Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -50,7 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.6
 #include 
 #include 
 #include 
-#include 
 
 #include 
 
@@ -309,7 +308,7 @@ void
 sparc_softintr_disestablish(void *cookie)
 {
 
-	free(cookie, M_DEVBUF);
+	kmem_free(cookie, sizeof(struct intrhand));
 }
 
 void



CVS commit: src/sys/arch/sparc64

2016-05-13 Thread Takeshi Nakayama
Module Name:src
Committed By:   nakayama
Date:   Fri May 13 21:22:47 UTC 2016

Modified Files:
src/sys/arch/sparc64/dev: ebus_mainbus.c
src/sys/arch/sparc64/sparc64: machdep.c

Log Message:
Use newly introduced intrhand_alloc().


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/sparc64/dev/ebus_mainbus.c
cvs rdiff -u -r1.283 -r1.284 src/sys/arch/sparc64/sparc64/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/sparc64/dev/ebus_mainbus.c
diff -u src/sys/arch/sparc64/dev/ebus_mainbus.c:1.15 src/sys/arch/sparc64/dev/ebus_mainbus.c:1.16
--- src/sys/arch/sparc64/dev/ebus_mainbus.c:1.15	Tue Nov  4 18:11:42 2014
+++ src/sys/arch/sparc64/dev/ebus_mainbus.c	Fri May 13 21:22:47 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ebus_mainbus.c,v 1.15 2014/11/04 18:11:42 palle Exp $	*/
+/*	$NetBSD: ebus_mainbus.c,v 1.16 2016/05/13 21:22:47 nakayama Exp $	*/
 /*	$OpenBSD: ebus_mainbus.c,v 1.7 2010/11/11 17:58:23 miod Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ebus_mainbus.c,v 1.15 2014/11/04 18:11:42 palle Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ebus_mainbus.c,v 1.16 2016/05/13 21:22:47 nakayama Exp $");
 
 #ifdef DEBUG
 #define	EDB_PROM	0x01
@@ -350,9 +350,7 @@ XXX
 	intrclrptr = [ino];
 	ino |= INTVEC(ihandle);
 
-	ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT);
-	if (ih == NULL)
-		return (NULL);
+	ih = intrhand_alloc();
 
 	/* Register the map and clear intr registers */
 	ih->ih_map = intrmapptr;

Index: src/sys/arch/sparc64/sparc64/machdep.c
diff -u src/sys/arch/sparc64/sparc64/machdep.c:1.283 src/sys/arch/sparc64/sparc64/machdep.c:1.284
--- src/sys/arch/sparc64/sparc64/machdep.c:1.283	Sun Nov 22 09:32:34 2015
+++ src/sys/arch/sparc64/sparc64/machdep.c	Fri May 13 21:22:47 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.283 2015/11/22 09:32:34 martin Exp $ */
+/*	$NetBSD: machdep.c,v 1.284 2016/05/13 21:22:47 nakayama Exp $ */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.283 2015/11/22 09:32:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.284 2016/05/13 21:22:47 nakayama Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -2368,11 +2368,7 @@ sparc_mainbus_intr_establish(bus_space_t
 {
 	struct intrhand *ih;
 
-	ih = (struct intrhand *)
-		malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
-	if (ih == NULL)
-		return (NULL);
-
+	ih = intrhand_alloc();
 	ih->ih_fun = handler;
 	ih->ih_arg = arg;
 	intr_establish(pil, level != IPL_VM, ih);



CVS commit: src/sys/arch/sparc64/sparc64

2016-05-13 Thread Takeshi Nakayama
Module Name:src
Committed By:   nakayama
Date:   Fri May 13 21:23:30 UTC 2016

Modified Files:
src/sys/arch/sparc64/sparc64: clock.c

Log Message:
Allocate interrupt handlers for clockintr and statintr dynamically.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/sparc64/sparc64/clock.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/sparc64/sparc64/clock.c
diff -u src/sys/arch/sparc64/sparc64/clock.c:1.118 src/sys/arch/sparc64/sparc64/clock.c:1.119
--- src/sys/arch/sparc64/sparc64/clock.c:1.118	Sun Dec 13 18:41:09 2015
+++ src/sys/arch/sparc64/sparc64/clock.c	Fri May 13 21:23:30 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.118 2015/12/13 18:41:09 christos Exp $ */
+/*	$NetBSD: clock.c,v 1.119 2016/05/13 21:23:30 nakayama Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -55,7 +55,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.118 2015/12/13 18:41:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.119 2016/05/13 21:23:30 nakayama Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -72,7 +72,6 @@ __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #ifdef GPROF
@@ -129,11 +128,6 @@ int statmin;			/* statclock interval - 1
 int timerok;
 #ifndef MULTIPROCESSOR
 static int statscheddiv;
-#endif
-
-static struct intrhand level10 = { .ih_fun = clockintr, .ih_pil = PIL_CLOCK };
-#ifndef MULTIPROCESSOR
-static struct intrhand level14 = { .ih_fun = statintr, .ih_pil = PIL_STATCLOCK };
 static struct intrhand *schedint;
 #endif
 
@@ -293,18 +287,24 @@ timerattach(device_t parent, device_t se
 	 (CPU_UPAID << INTMAP_TID_SHIFT));
 
 	/* Install the appropriate interrupt vector here */
-	level10.ih_number = INTVEC(ma->ma_interrupts[0]);
-	level10.ih_clr = _4u.t_clrintr[0];
-	intr_establish(PIL_CLOCK, true, );
-	printf(" irq vectors %lx", (u_long)level10.ih_number);
+	struct intrhand *level10 = intrhand_alloc();
+	level10->ih_fun = clockintr;
+	level10->ih_pil = PIL_CLOCK;
+	level10->ih_number = INTVEC(ma->ma_interrupts[0]);
+	level10->ih_clr = _4u.t_clrintr[0];
+	intr_establish(PIL_CLOCK, true, level10);
+	printf(" irq vectors %lx", (u_long)level10->ih_number);
 #ifndef MULTIPROCESSOR
 	/*
 	 * On SMP kernel, don't establish interrupt to use it as timecounter.
 	 */
-	level14.ih_number = INTVEC(ma->ma_interrupts[1]);
-	level14.ih_clr = _4u.t_clrintr[1];
-	intr_establish(PIL_STATCLOCK, true, );
-	printf(" and %lx", (u_long)level14.ih_number);
+	struct intrhand *level14 = intrhand_alloc();
+	level14->ih_fun = statintr;
+	level14->ih_pil = PIL_STATCLOCK;
+	level14->ih_number = INTVEC(ma->ma_interrupts[1]);
+	level14->ih_clr = _4u.t_clrintr[1];
+	intr_establish(PIL_STATCLOCK, true, level14);
+	printf(" and %lx", (u_long)level14->ih_number);
 #endif
 
 #if 0



CVS commit: src/sys/arch/sparc64/sparc64

2016-05-13 Thread Palle Lyckegaard
Module Name:src
Committed By:   palle
Date:   Fri May 13 21:21:43 UTC 2016

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

Log Message:
Fixed typo in comment + reorder parameters for trap debug output to match 
function prototype for data_access_fault()


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/arch/sparc64/sparc64/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/sparc64/sparc64/trap.c
diff -u src/sys/arch/sparc64/sparc64/trap.c:1.182 src/sys/arch/sparc64/sparc64/trap.c:1.183
--- src/sys/arch/sparc64/sparc64/trap.c:1.182	Sun May  1 19:57:55 2016
+++ src/sys/arch/sparc64/sparc64/trap.c	Fri May 13 21:21:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.182 2016/05/01 19:57:55 palle Exp $ */
+/*	$NetBSD: trap.c,v 1.183 2016/05/13 21:21:43 palle Exp $ */
 
 /*
  * Copyright (c) 1996-2002 Eduardo Horvath.  All rights reserved.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.182 2016/05/01 19:57:55 palle Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.183 2016/05/13 21:21:43 palle Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -438,7 +438,7 @@ print_trapframe(struct trapframe64 *tf)
 
 /*
  * Called from locore.s trap handling, for non-MMU-related traps.
- * (MMU-related traps go through mem_access_fault, below.)
+ * (MMU-related traps go through data_access_fault, below.)
  */
 void
 trap(struct trapframe64 *tf, unsigned int type, vaddr_t pc, long tstate)
@@ -1053,7 +1053,7 @@ data_access_fault(struct trapframe64 *tf
 		printf("%ld: data_access_fault(%p, %x, %p, %p, %lx, %lx) "
 			"nsaved=%d\n",
 			(long)(curproc?curproc->p_pid:-1), tf, type,
-			(void *)addr, (void *)pc,
+			(void *)pc, (void *)addr, 
 			sfva, sfsr, (int)curpcb->pcb_nsaved);
 #ifdef DDB
 		if ((trapdebug & TDB_NSAVED && curpcb->pcb_nsaved))



CVS commit: src/sys/arch/sparc64/sparc64

2016-05-13 Thread Takeshi Nakayama
Module Name:src
Committed By:   nakayama
Date:   Fri May 13 21:21:25 UTC 2016

Modified Files:
src/sys/arch/sparc64/sparc64: locore.s

Log Message:
- ci_paddr is always 64-bit.
- intrlev is array of pointer.
- ih_ack is pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.391 -r1.392 src/sys/arch/sparc64/sparc64/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/sparc64/sparc64/locore.s
diff -u src/sys/arch/sparc64/sparc64/locore.s:1.391 src/sys/arch/sparc64/sparc64/locore.s:1.392
--- src/sys/arch/sparc64/sparc64/locore.s:1.391	Tue May 10 19:24:00 2016
+++ src/sys/arch/sparc64/sparc64/locore.s	Fri May 13 21:21:25 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.s,v 1.391 2016/05/10 19:24:00 palle Exp $	*/
+/*	$NetBSD: locore.s,v 1.392 2016/05/13 21:21:25 nakayama Exp $	*/
 
 /*
  * Copyright (c) 2006-2010 Matthew R. Green
@@ -3598,7 +3598,7 @@ sun4v_cpu_mondo:
 	mov	0x3c0, %g1			 ! CPU Mondo Queue Head
 	ldxa	[%g1] ASI_QUEUE, %g2		 ! fetch index value for head
 	set	CPUINFO_VA, %g3
-	LDPTR	[%g3 + CI_PADDR], %g3
+	ldx	[%g3 + CI_PADDR], %g3
 	add	%g3, CI_CPUMQ, %g3	
 	ldxa	[%g3] ASI_PHYS_CACHED, %g3	 ! fetch head element
 	ldxa	[%g3 + %g2] ASI_PHYS_CACHED, %g4 ! fetch func 
@@ -3630,7 +3630,7 @@ sun4v_dev_mondo:
 	retry	! unlikely, ingnore interrupt
 2:	
 	set	CPUINFO_VA, %g3			 ! fetch cpuinfo pa
-	LDPTR	[%g3 + CI_PADDR], %g3		 ! fetch intstack pa
+	ldx	[%g3 + CI_PADDR], %g3		 ! fetch intstack pa
 	set	CPUINFO_VA-INTSTACK, %g4	 ! offset to cpuinfo
 	add	%g4, %g3, %g3			 ! %g3 is now cpuifo
 	add	%g3, CI_DEVMQ, %g3		 ! calc offset to devmq
@@ -3647,9 +3647,9 @@ sun4v_dev_mondo:
 	 nop	! no just continue
 
 	sethi	%hi(_C_LABEL(intrlev)), %g3
+	sllx	%g5, PTRSHFT, %g5	! Calculate entry number
 	or	%g3, %lo(_C_LABEL(intrlev)), %g3
-	sllx	%g5, 3, %g5		! Calculate entry number
-	ldx	[%g3 + %g5], %g5	! We have a pointer to the handler
+	LDPTR	[%g3 + %g5], %g5	! We have a pointer to the handler
 1:
 	brnz,pt	%g5, setup_sparcintr	! branch if valid handle
 	 nop
@@ -3951,7 +3951,7 @@ sparc_intr_retry:
 	stx	%g0, [%l1]		! Clear intr source
 	membar	#Sync			! Should not be needed
 0:
-	ldx	[%l2 + IH_ACK], %l1	! ih->ih_ack
+	LDPTR	[%l2 + IH_ACK], %l1	! ih->ih_ack
 	brz,pn	%l1, 1f
 	 nop
 	jmpl	%l1, %o7		! (*ih->ih_ack)(ih)



CVS commit: src/sys/kern

2016-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 13 17:33:43 UTC 2016

Modified Files:
src/sys/kern: exec_subr.c kern_pax.c

Log Message:
- make pax aslr stack eat up to 1/8 of the max stack space insted of 1/4
  and reduce the length of the randomization bits since this is unused.
- call the pax aslr stack function sooner so we don't need to re-adjust the
  stack size.
- adjust the stack max resource limit to account for the maximum space that
  can be lost by aslr
- tidy up debugging printfs


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/kern/exec_subr.c
cvs rdiff -u -r1.43 -r1.44 src/sys/kern/kern_pax.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/kern/exec_subr.c
diff -u src/sys/kern/exec_subr.c:1.74 src/sys/kern/exec_subr.c:1.75
--- src/sys/kern/exec_subr.c:1.74	Thu Apr  7 08:06:50 2016
+++ src/sys/kern/exec_subr.c	Fri May 13 13:33:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec_subr.c,v 1.74 2016/04/07 12:06:50 christos Exp $	*/
+/*	$NetBSD: exec_subr.c,v 1.75 2016/05/13 17:33:43 christos Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.74 2016/04/07 12:06:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.75 2016/05/13 17:33:43 christos Exp $");
 
 #include "opt_pax.h"
 
@@ -391,25 +391,27 @@ exec_setup_stack(struct lwp *l, struct e
 		max_stack_size = MAXSSIZ;
 	}
 
-	DPRINTF(("ep_minsaddr=%llx max_stack_size=%llx\n",
-	(unsigned long long)epp->ep_minsaddr,
-	(unsigned long long)max_stack_size));
-
-	epp->ep_ssize = MIN(l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur,
-	max_stack_size);
+	DPRINTF(("ep_minsaddr=%#jx max_stack_size=%#jx\n",
+	(uintmax_t)epp->ep_minsaddr, (uintmax_t)max_stack_size));
 
 #ifdef PAX_ASLR
 	pax_aslr_stack(epp, _stack_size);
 #endif /* PAX_ASLR */
 
+	DPRINTF(("[RLIMIT_STACK].lim_cur=%#jx max_stack_size=%#jx\n",
+	(uintmax_t)l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur,
+	(uintmax_t)max_stack_size));
+	epp->ep_ssize = MIN(l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur,
+	max_stack_size);
+
 	l->l_proc->p_stackbase = epp->ep_minsaddr;
 	
 	epp->ep_maxsaddr = (vaddr_t)STACK_GROW(epp->ep_minsaddr,
-		max_stack_size);
+	max_stack_size);
 
-	DPRINTF(("ep_ssize=%llx ep_maxsaddr=%llx\n",
-	(unsigned long long)epp->ep_ssize,
-	(unsigned long long)epp->ep_maxsaddr));
+	DPRINTF(("ep_ssize=%#jx ep_minsaddr=%#jx ep_maxsaddr=%#jx\n",
+	(uintmax_t)epp->ep_ssize, (uintmax_t)epp->ep_minsaddr,
+	(uintmax_t)epp->ep_maxsaddr));
 
 	/*
 	 * set up commands for stack.  note that this takes *two*, one to
@@ -425,12 +427,10 @@ exec_setup_stack(struct lwp *l, struct e
 	noaccess_linear_min = (vaddr_t)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
 	access_size), noaccess_size);
 
-	DPRINTF(("access_size=%llx, access_linear_min=%llx, "
-	"noaccess_size=%llx, noaccess_linear_min=%llx\n",
-	(unsigned long long)access_size,
-	(unsigned long long)access_linear_min,
-	(unsigned long long)noaccess_size,
-	(unsigned long long)noaccess_linear_min));
+	DPRINTF(("access_size=%#jx, access_linear_min=%#jx, "
+	"noaccess_size=%#jx, noaccess_linear_min=%#jx\n",
+	(uintmax_t)access_size, (uintmax_t)access_linear_min,
+	(uintmax_t)noaccess_size, (uintmax_t)noaccess_linear_min));
 
 	if (noaccess_size > 0 && noaccess_size <= MAXSSIZ) {
 		NEW_VMCMD2(>ep_vmcmds, vmcmd_map_zero, noaccess_size,

Index: src/sys/kern/kern_pax.c
diff -u src/sys/kern/kern_pax.c:1.43 src/sys/kern/kern_pax.c:1.44
--- src/sys/kern/kern_pax.c:1.43	Sun May  8 16:01:56 2016
+++ src/sys/kern/kern_pax.c	Fri May 13 13:33:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_pax.c,v 1.43 2016/05/08 20:01:56 christos Exp $	*/
+/*	$NetBSD: kern_pax.c,v 1.44 2016/05/13 17:33:43 christos Exp $	*/
 
 /*
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.43 2016/05/08 20:01:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.44 2016/05/13 17:33:43 christos Exp $");
 
 #include "opt_pax.h"
 
@@ -104,11 +104,12 @@ int pax_aslr_global = PAX_ASLR;
 #define PAX_ASLR_DELTA_STACK_LSB	PGSHIFT
 #endif
 #ifndef PAX_ASLR_DELTA_STACK_LEN
-#define PAX_ASLR_DELTA_STACK_LEN 	PAX_ASLR_DELTA_MMAP_LEN
+#define PAX_ASLR_DELTA_STACK_LEN 	((sizeof(void *) * NBBY) / 4)
 #endif
 #ifndef PAX_ASLR_DELTA_STACK_LEN32
-#define PAX_ASLR_DELTA_STACK_LEN32 	PAX_ASLR_DELTA_MMAP_LEN32
+#define PAX_ASLR_DELTA_STACK_LEN32 	((sizeof(uint32_t) * NBBY) / 4)
 #endif
+#define PAX_ASLR_MAX_STACK_WASTE	8
 
 static bool pax_aslr_elf_flags_active(uint32_t);
 #endif /* PAX_ASLR */
@@ -335,6 +336,12 @@ pax_init(void)
 		panic("pax_init: segvguard_id: error=%d\n", error);
 	}
 #endif /* PAX_SEGVGUARD */
+#ifdef PAX_ASLR
+	/* Adjust maximum stack by the size we can consume for ASLR */
+	

CVS commit: src/sys/compat/netbsd32

2016-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 13 16:54:36 UTC 2016

Modified Files:
src/sys/compat/netbsd32: netbsd32_netbsd.c

Log Message:
clamp getrlimit the same way we clamp setrlimit


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 src/sys/compat/netbsd32/netbsd32_netbsd.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/compat/netbsd32/netbsd32_netbsd.c
diff -u src/sys/compat/netbsd32/netbsd32_netbsd.c:1.199 src/sys/compat/netbsd32/netbsd32_netbsd.c:1.200
--- src/sys/compat/netbsd32/netbsd32_netbsd.c:1.199	Sun Feb 28 18:24:35 2016
+++ src/sys/compat/netbsd32/netbsd32_netbsd.c	Fri May 13 12:54:36 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_netbsd.c,v 1.199 2016/02/28 23:24:35 khorben Exp $	*/
+/*	$NetBSD: netbsd32_netbsd.c,v 1.200 2016/05/13 16:54:36 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.199 2016/02/28 23:24:35 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.200 2016/05/13 16:54:36 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -1448,23 +1448,51 @@ netbsd32_fpathconf(struct lwp *l, const 
 	return sys_fpathconf(l, , retval);
 }
 
+static void
+fixlimit(int which, struct rlimit *alim)
+{
+	switch (which) {
+	case RLIMIT_DATA:
+		if (LIMITCHECK(alim->rlim_cur, MAXDSIZ32))
+			alim->rlim_cur = MAXDSIZ32;
+		if (LIMITCHECK(alim->rlim_max, MAXDSIZ32))
+			alim->rlim_max = MAXDSIZ32;
+		return;	
+	case RLIMIT_STACK:
+		if (LIMITCHECK(alim->rlim_cur, MAXSSIZ32))
+			alim->rlim_cur = MAXSSIZ32;
+		if (LIMITCHECK(alim->rlim_max, MAXSSIZ32))
+			alim->rlim_max = MAXSSIZ32;
+		return;
+	default:
+		return;
+	}
+}
+
 int
-netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap, register_t *retval)
+netbsd32_getrlimit(struct lwp *l, const struct netbsd32_getrlimit_args *uap,
+register_t *retval)
 {
 	/* {
 		syscallarg(int) which;
 		syscallarg(netbsd32_rlimitp_t) rlp;
 	} */
 	int which = SCARG(uap, which);
+	struct rlimit alim;
 
 	if ((u_int)which >= RLIM_NLIMITS)
-		return (EINVAL);
-	return (copyout(>l_proc->p_rlimit[which],
-	SCARG_P32(uap, rlp), sizeof(struct rlimit)));
+		return EINVAL;
+
+	alim = l->l_proc->p_rlimit[which];
+
+	fixlimit(which, );
+
+	return copyout(, SCARG_P32(uap, rlp), sizeof(alim));
 }
 
 int
-netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap, register_t *retval)
+netbsd32_setrlimit(struct lwp *l, const struct netbsd32_setrlimit_args *uap,
+register_t *retval)
 {
 	/* {
 		syscallarg(int) which;
@@ -1474,28 +1502,16 @@ netbsd32_setrlimit(struct lwp *l, const 
 	struct rlimit alim;
 	int error;
 
+	if ((u_int)which >= RLIM_NLIMITS)
+		return EINVAL;
+
 	error = copyin(SCARG_P32(uap, rlp), , sizeof(struct rlimit));
 	if (error)
 		return (error);
 
-	switch (which) {
-	case RLIMIT_DATA:
-		if (LIMITCHECK(alim.rlim_cur, MAXDSIZ32))
-			alim.rlim_cur = MAXDSIZ32;
-		if (LIMITCHECK(alim.rlim_max, MAXDSIZ32))
-			alim.rlim_max = MAXDSIZ32;
-		break;
-
-	case RLIMIT_STACK:
-		if (LIMITCHECK(alim.rlim_cur, MAXSSIZ32))
-			alim.rlim_cur = MAXSSIZ32;
-		if (LIMITCHECK(alim.rlim_max, MAXSSIZ32))
-			alim.rlim_max = MAXSSIZ32;
-	default:
-		break;
-	}
+	fixlimit(which, );
 
-	return (dosetrlimit(l, l->l_proc, which, ));
+	return dosetrlimit(l, l->l_proc, which, );
 }
 
 int



CVS commit: src/lib/libedit

2016-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 13 15:55:59 UTC 2016

Modified Files:
src/lib/libedit: readline.c

Log Message:
>From Bastian Maerkisch, via Igno Schwarze:

Even though section "2.3.3 Information About the History List"
of the history(3) info(1) manual only says

  -- Function: int where_history (void)
 Returns the offset of the current history element.

which maybe isn't completely clear, a plausible implementation
is that the offset returned is the same offset that can be used
for history_set_pos(), i.e. that it is 0 for the oldest entry
and increases with time, and that's how the GNU implementation
behaves indeed.

The libedit implementation, on the other hand, returns 1 for the
newest entry and increases going back in time.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/lib/libedit/readline.c

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

Modified files:

Index: src/lib/libedit/readline.c
diff -u src/lib/libedit/readline.c:1.132 src/lib/libedit/readline.c:1.133
--- src/lib/libedit/readline.c:1.132	Mon May  9 17:27:55 2016
+++ src/lib/libedit/readline.c	Fri May 13 11:55:59 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: readline.c,v 1.132 2016/05/09 21:27:55 christos Exp $	*/
+/*	$NetBSD: readline.c,v 1.133 2016/05/13 15:55:59 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.132 2016/05/09 21:27:55 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.133 2016/05/13 15:55:59 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include 
@@ -1571,9 +1571,12 @@ where_history(void)
 		return 0;
 	curr_num = ev.num;
 
-	(void)history(h, , H_FIRST);
-	off = 1;
-	while (ev.num != curr_num && history(h, , H_NEXT) == 0)
+	/* start from the oldest */
+	(void)history(h, , H_LAST);
+
+	/* position is zero-based */
+	off = 0;
+	while (ev.num != curr_num && history(h, , H_PREV) == 0)
 		off++;
 
 	return off;



CVS commit: src/sys/external/bsd/drm2/include/drm

2016-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 13 15:25:57 UTC 2016

Modified Files:
src/sys/external/bsd/drm2/include/drm: drm_wait_netbsd.h

Log Message:
We now use cpu_intr_p() all the time.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 \
src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h

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

Modified files:

Index: src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h
diff -u src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h:1.13 src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h:1.14
--- src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h:1.13	Sun Apr 12 16:55:02 2015
+++ src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h	Fri May 13 11:25:57 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: drm_wait_netbsd.h,v 1.13 2015/04/12 20:55:02 riastradh Exp $	*/
+/*	$NetBSD: drm_wait_netbsd.h,v 1.14 2016/05/13 15:25:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -34,9 +34,7 @@
 
 #include 
 #include 
-#if DIAGNOSTIC
 #include 		/* cpu_intr_p */
-#endif
 #include 
 #include 
 #include 



CVS commit: src/sys/arch/i386/i386

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 14:03:00 UTC 2016

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

Log Message:
Bring some amd64 swag. No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.116 src/sys/arch/i386/i386/locore.S:1.117
--- src/sys/arch/i386/i386/locore.S:1.116	Thu May 12 06:45:16 2016
+++ src/sys/arch/i386/i386/locore.S	Fri May 13 14:03:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.116 2016/05/12 06:45:16 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.117 2016/05/13 14:03:00 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.116 2016/05/12 06:45:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.117 2016/05/13 14:03:00 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -340,10 +340,13 @@ _C_LABEL(Multiboot_Header):
 1:
 	/*
 	 * At this point, we know that a NetBSD-specific boot loader
-	 * booted this kernel.  The stack carries the following parameters:
-	 * (boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem),
-	 * 4 bytes each.
+	 * booted this kernel.
+	 *
+	 * Load parameters from the stack (32 bits):
+	 * boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem
+	 * We are not interested in 'bootdev'.
 	 */
+
 	addl	$4,%esp		/* Discard return address to boot loader */
 	call	_C_LABEL(native_loader)
 	addl	$24,%esp
@@ -537,22 +540,43 @@ try586:	/* Use the `cpuid' instruction. 
 	movl	$_RELOC(tmpstk),%esp
 
 /*
- * Virtual address space of kernel, without PAE. The page dir is 1 page long.
+ * There are two different layouts possible, depending on whether PAE is
+ * enabled or not.
  *
- * text | data | bss | [syms] | [blobs] | page dir | proc0 kstack | L1 ptp
- *			0  1   2  3
+ * If PAE is not enabled, there are two levels of pages: PD -> PT. They will
+ * be referred to as: L2 -> L1. L2 is 1 page long. The BOOTSTRAP TABLES have
+ * the following layout:
+ * 	+-+++
+ * 	| L2 -> PROC0 STK -> L1 |
+ * 	+-+++
+ *
+ * If PAE is enabled, there are three levels of pages: PDP -> PD -> PT. They
+ * will be referred to as: L3 -> L2 -> L1. L3 is 1 page long, L2 is 4 page
+ * long. The BOOTSTRAP TABLES have the following layout:
+ * 	+-+-+++
+ * 	| L3 -> L2 -> PROC0 STK -> L1 |
+ * 	+-+-+++
+ *
+ * Virtual address space of the kernel in both cases:
+ * +--++--+-++-+---
+ * | TEXT | RODATA | DATA | BSS | [SYMS] | [PRELOADED MODULES] | BOOTSTRAP
+ * +--++--+-++-+---
+ * (1)  (2)   (3)
+ *
+ * ---++
+ * TABLES | ISA IO MEM |
+ * ---++
+ *   (4)
  *
- * Virtual address space of kernel, with PAE. We need 4 pages for the page dir
- * and 1 page for the L3.
- * text | data | bss | [syms] | [blobs] | L3 | page dir | proc0 kstack | L1 ptp
- * 	01  5   6  7
+ * PROC0 STK is obviously not linked as a page level. It just happens to be
+ * caught between L2 and L1.
  */
 
-	/* Find end of kernel image. */
+	/* Find end of kernel image; brings us on (1). */
 	movl	$RELOC(end),%edi
 
 #if (NKSYMS || defined(DDB) || defined(MODULAR)) && !defined(makeoptions_COPY_SYMTAB)
-	/* Save the symbols (if loaded). */
+	/* Save the symbols (if loaded); brinds us on (2). */
 	movl	RELOC(esym),%eax
 	testl	%eax,%eax
 	jz	1f
@@ -561,14 +585,15 @@ try586:	/* Use the `cpuid' instruction. 
 1:
 #endif
 
-	/* Skip over any modules/blobs. */
+	/* Skip over any modules/blobs; brings us on (3). */
 	movl	RELOC(eblob),%eax
 	testl	%eax,%eax
 	jz	1f
 	subl	$KERNBASE,%eax
 	movl	%eax,%edi
 1:
-	/* Compute sizes */
+
+	/* We are on (3). Align up for BOOTSTRAP TABLES. */
 	movl	%edi,%esi
 	addl	$PGOFSET,%esi
 	andl	$~PGOFSET,%esi
@@ -577,20 +602,20 @@ try586:	/* Use the `cpuid' instruction. 
 	movl	%esi,%eax
 	addl	$~L2_FRAME,%eax
 	shrl	$L2_SHIFT,%eax
-	incl	%eax		/* one more ptp for VAs stolen by bootstrap */
+	incl	%eax		/* one more PTP for VAs stolen by bootstrap */
 1:	movl	%eax,RELOC(nkptp)+1*4
 
 	/* tablesize = (PDP_SIZE + UPAGES + nkptp) << PGSHIFT; */
 	addl	$(PDP_SIZE+UPAGES),%eax
 #ifdef PAE
-	incl	%eax 		/* one more page for the L3 PD */
+	incl	%eax 		/* one more page for L3 */
 	shll	$PGSHIFT+1,%eax	/* PTP tables are twice larger with PAE */
 #else
 	shll	$PGSHIFT,%eax
 #endif
 	movl	%eax,RELOC(tablesize)
 
-	/* ensure that nkptp covers bootstrap tables */
+	/* Ensure that nkptp covers BOOTSTRAP TABLES. */
 	addl	%esi,%eax
 	addl	$~L2_FRAME,%eax
 	

CVS commit: src/doc

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 14:09:38 UTC 2016

Modified Files:
src/doc: CHANGES

Log Message:
Mention SMEP.


To generate a diff of this commit:
cvs rdiff -u -r1.2159 -r1.2160 src/doc/CHANGES

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

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.2159 src/doc/CHANGES:1.2160
--- src/doc/CHANGES:1.2159	Mon May  9 10:21:42 2016
+++ src/doc/CHANGES	Fri May 13 14:09:38 2016
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2159 $>
+# LIST OF CHANGES FROM LAST RELEASE:			<$Revision: 1.2160 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -233,6 +233,7 @@ Changes from NetBSD 7.0 to NetBSD 8.0:
 	bind: Import version 9.10.3-P2. [christos 20151216]
 	mdocml: Import 1.13.3. [christos 20151217]
 	sortinfo(1): Add utility to sort texinfo dir files [christos 20151218]
+	x86: Add support for SMEP on amd64 and i386. [maxv 20151219]
 	raidframe: Now built as a kernel module; it can be built-in at
 		kernel build time, or (for MODULAR kernels) loaded as
 		needed. [pgoyette 20151226]



CVS commit: src/sys/arch/ia64/ia64

2016-05-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri May 13 13:40:56 UTC 2016

Modified Files:
src/sys/arch/ia64/ia64: ssc.c

Log Message:
>From scole_mail:
So here is a patch to get basic ski console output working.  The ski
simulator was decoding the wrong registers in ssccnputc() due to
automagically inlined ssc() which contains a "break" simulated system
call.

The ski loader "skiload" has almost exactly the same inline assembly
call for ssc(), but for whatever reason, (maybe ssc() and
ski_cons_putchar() are in different files?), the ssc() function didn't
get inlined and I/O worked fine.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/ia64/ia64/ssc.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/ia64/ia64/ssc.c
diff -u src/sys/arch/ia64/ia64/ssc.c:1.4 src/sys/arch/ia64/ia64/ssc.c:1.5
--- src/sys/arch/ia64/ia64/ssc.c:1.4	Sat Oct 27 13:17:57 2012
+++ src/sys/arch/ia64/ia64/ssc.c	Fri May 13 09:40:55 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ssc.c,v 1.4 2012/10/27 17:17:57 chs Exp $	*/
+/*	$NetBSD: ssc.c,v 1.5 2016/05/13 13:40:55 christos Exp $	*/
 
 /*-
  * Copyright (c) 2000 Doug Rabson
@@ -46,6 +46,7 @@ int ssccngetc(dev_t);
 void ssccnpollc(dev_t, int);
 
 
+__attribute__((__noinline__))
 uint64_t
 ssc(uint64_t in0, uint64_t in1, uint64_t in2, uint64_t in3, int which)
 {



CVS commit: src/sys/arch/i386/i386

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 13:24:01 UTC 2016

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

Log Message:
KNF a little, use C-style comments, and remove susword/fusword. No
functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/i386/i386/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/i386/i386/copy.S
diff -u src/sys/arch/i386/i386/copy.S:1.23 src/sys/arch/i386/i386/copy.S:1.24
--- src/sys/arch/i386/i386/copy.S:1.23	Fri Jan 10 16:47:07 2014
+++ src/sys/arch/i386/i386/copy.S	Fri May 13 13:24:01 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.23 2014/01/10 16:47:07 pedro Exp $	*/
+/*	$NetBSD: copy.S,v 1.24 2016/05/13 13:24:01 maxv Exp $	*/
 /*	NetBSD: locore.S,v 1.34 2005/04/01 11:59:31 yamt Exp $	*/
 
 /*-
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.23 2014/01/10 16:47:07 pedro Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.24 2016/05/13 13:24:01 maxv Exp $");
 
 #include "assym.h"
 
@@ -86,10 +86,10 @@ __KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.2
 #define DEFERRED_SWITCH_CHECK \
 	CHECK_DEFERRED_SWITCH			; \
 	jnz	99f; \
-98:
+	98:
 
 #define DEFERRED_SWITCH_CALL \
-99:		; \
+	99:		; \
 	call	_C_LABEL(do_pmap_load)		; \
 	jmp	98b
 
@@ -136,7 +136,7 @@ NENTRY(do_pmap_load)
  * `level' levels down the stack if level > 0.
  */
 ENTRY(return_address)
-	movl	%ebp,%eax	/* frame pointer -> %eax */ 
+	movl	%ebp,%eax	/* frame pointer -> %eax */
 	movl	4(%esp),%ecx	/* level -> %ecx */
 	movl	CPUVAR(CURLWP),%edx
 	movl	L_PCB(%edx),%edx
@@ -166,15 +166,15 @@ ENTRY(kcopy)
 .Lkcopy_start:
 	movl	%edi,%eax
 	subl	%esi,%eax
-	cmpl	%ecx,%eax		# overlapping?
+	cmpl	%ecx,%eax		/* overlapping? */
 	movl	%ecx,%edx
 	jb	1f
-	# nope, copy forward
-	shrl	$2,%ecx			# copy by 32-bit words
+	/* nope, copy forward */
+	shrl	$2,%ecx			/* copy by 32-bit words */
 	rep
 	movsl
 	movl	%edx,%ecx
-	andl	$3,%ecx			# any bytes left?
+	andl	$3,%ecx			/* any bytes left? */
 	jz	0f
 	rep
 	movsb
@@ -185,15 +185,15 @@ ENTRY(kcopy)
 	ret
 
 	ALIGN_TEXT
-1:	addl	%ecx,%edi		# copy backward
+1:	addl	%ecx,%edi		/* copy backward */
 	addl	%ecx,%esi
 	std
-	andl	$3,%ecx			# any fractional bytes?
+	andl	$3,%ecx			/* any fractional bytes? */
 	decl	%edi
 	decl	%esi
 	rep
 	movsb
-	movl	%edx,%ecx		# copy remainder by 32-bit words
+	movl	%edx,%ecx		/* copy remainder by 32-bit words */
 	shrl	$2,%ecx
 	subl	$3,%esi
 	subl	$3,%edi
@@ -337,11 +337,11 @@ ENTRY(copyoutstr)
 	DEFERRED_SWITCH_CHECK
 	pushl	%esi
 	pushl	%edi
-	movl	12(%esp),%esi		# esi = from
-	movl	16(%esp),%edi		# edi = to
-	movl	20(%esp),%edx		# edx = maxlen
+	movl	12(%esp),%esi		/* esi = from */
+	movl	16(%esp),%edi		/* edi = to */
+	movl	20(%esp),%edx		/* edx = maxlen */
 .Lcopyoutstr_start:
-5:	
+5:
 	/*
 	 * Get min(%edx, VM_MAXUSER_ADDRESS-%edi).
 	 */
@@ -388,9 +388,9 @@ ENTRY(copyinstr)
 	DEFERRED_SWITCH_CHECK
 	pushl	%esi
 	pushl	%edi
-	movl	12(%esp),%esi		# %esi = from
-	movl	16(%esp),%edi		# %edi = to
-	movl	20(%esp),%edx		# %edx = maxlen
+	movl	12(%esp),%esi		/* %esi = from */
+	movl	16(%esp),%edi		/* %edi = to */
+	movl	20(%esp),%edx		/* %edx = maxlen */
 
 	/*
 	 * Get min(%edx, VM_MAXUSER_ADDRESS-%esi).
@@ -457,9 +457,9 @@ ENTRY(copystr)
 	pushl	%esi
 	pushl	%edi
 
-	movl	12(%esp),%esi		# esi = from
-	movl	16(%esp),%edi		# edi = to
-	movl	20(%esp),%edx		# edx = maxlen
+	movl	12(%esp),%esi		/* esi = from */
+	movl	16(%esp),%edi		/* edi = to */
+	movl	20(%esp),%edx		/* edx = maxlen */
 	incl	%edx
 
 1:	decl	%edx
@@ -508,24 +508,6 @@ ENTRY(fuword)
 	DEFERRED_SWITCH_CALL
 
 /*
- * int fusword(const void *uaddr);
- * Fetch a short from the user's address space.
- * see fusword(9)
- */
-/* LINTSTUB: Func: int fusword(const void *base) */
-ENTRY(fusword)
-	DEFERRED_SWITCH_CHECK
-	movl	4(%esp),%edx
-	cmpl	$VM_MAXUSER_ADDRESS-2,%edx
-	ja	_C_LABEL(fusuaddrfault)
-	GET_CURPCB(%ecx)
-	movl	$_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
-	movzwl	(%edx),%eax
-	movl	$0,PCB_ONFAULT(%ecx)
-	ret
-	DEFERRED_SWITCH_CALL
-
-/*
  * int fuswintr(const void *uaddr);
  * Fetch a short from the user's address space.  Can be called during an
  * interrupt.
@@ -612,26 +594,6 @@ ENTRY(suword)
 	DEFERRED_SWITCH_CALL
 
 /*
- * int susword(void *uaddr, short x);
- * Store a short in the user's address space.
- * see susword(9)
- */
-/* LINTSTUB: Func: int susword(void *base, short c) */
-ENTRY(susword)
-	DEFERRED_SWITCH_CHECK
-	movl	4(%esp),%edx
-	cmpl	$VM_MAXUSER_ADDRESS-2,%edx
-	ja	_C_LABEL(fusuaddrfault)
-	GET_CURPCB(%ecx)
-	movl	$_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
-	movl	8(%esp),%eax
-	movw	%ax,(%edx)
-	xorl	%eax,%eax
-	movl	%eax,PCB_ONFAULT(%ecx)
-	ret
-	DEFERRED_SWITCH_CALL
-
-/*
  * int suswintr(void *uaddr, short x);
  * Store a short in the user's address space.  Can be called during an
  * interrupt.
@@ -736,7 +698,7 @@ ENTRY(x86_copyargs)
 	cmpl	

CVS commit: src/tests/kernel

2016-05-13 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri May 13 13:22:29 UTC 2016

Modified Files:
src/tests/kernel: t_rnd.c

Log Message:
mark read_random xfail kern/51135


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/kernel/t_rnd.c

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

Modified files:

Index: src/tests/kernel/t_rnd.c
diff -u src/tests/kernel/t_rnd.c:1.7 src/tests/kernel/t_rnd.c:1.8
--- src/tests/kernel/t_rnd.c:1.7	Thu May 12 11:41:43 2016
+++ src/tests/kernel/t_rnd.c	Fri May 13 13:22:28 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_rnd.c,v 1.7 2016/05/12 11:41:43 pooka Exp $	*/
+/*	$NetBSD: t_rnd.c,v 1.8 2016/05/13 13:22:28 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: t_rnd.c,v 1.7 2016/05/12 11:41:43 pooka Exp $");
+__RCSID("$NetBSD: t_rnd.c,v 1.8 2016/05/13 13:22:28 pooka Exp $");
 
 #include 
 #include 
@@ -99,6 +99,8 @@ ATF_TC_BODY(read_random, tc)
 	char buf[128];
 	int fd;
 
+	atf_tc_expect_fail("PR kern/51135");
+
 	rump_init();
 	RL(fd = rump_sys_open("/dev/random", O_RDONLY));
 	RL(rump_sys_read(fd, buf, sizeof(buf)));



CVS commit: src/sys/arch/x86/x86

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 11:47:02 UTC 2016

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

Log Message:
Actually, make the NOX part amd64-specific. The secondary CPUs bug is not
yet fixed on i386.


To generate a diff of this commit:
cvs rdiff -u -r1.192 -r1.193 src/sys/arch/x86/x86/pmap.c

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

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.192 src/sys/arch/x86/x86/pmap.c:1.193
--- src/sys/arch/x86/x86/pmap.c:1.192	Fri May 13 10:24:42 2016
+++ src/sys/arch/x86/x86/pmap.c	Fri May 13 11:47:02 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.192 2016/05/13 10:24:42 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.193 2016/05/13 11:47:02 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.192 2016/05/13 10:24:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.193 2016/05/13 11:47:02 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1343,7 +1343,12 @@ pmap_bootstrap(vaddr_t kva_start)
 		for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2,
 		pa += NBPD_L2) {
 			pde = _BASE[pl2_i(kva)];
+#ifdef __x86_64__
 			*pde = pa | pmap_pg_g | PG_PS | pg_nx | PG_KR | PG_V;
+#else
+			*pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V;
+#endif
+
 			tlbflushg();
 		}
 
@@ -1354,7 +1359,11 @@ pmap_bootstrap(vaddr_t kva_start)
 		for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2,
 		pa += NBPD_L2) {
 			pde = _BASE[pl2_i(kva)];
+#ifdef __x86_64__
 			*pde = pa | pmap_pg_g | PG_PS | pg_nx | PG_KW | PG_V;
+#else
+			*pde = pa | pmap_pg_g | PG_PS | PG_KW | PG_V;
+#endif
 			tlbflushg();
 		}
 	}



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

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 11:17:20 UTC 2016

Modified Files:
src/sys/arch/amd64/include: pte.h

Log Message:
KNF, so it appears aligned on NXR.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/include/pte.h

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

Modified files:

Index: src/sys/arch/amd64/include/pte.h
diff -u src/sys/arch/amd64/include/pte.h:1.8 src/sys/arch/amd64/include/pte.h:1.9
--- src/sys/arch/amd64/include/pte.h:1.8	Sat Jul 24 17:43:47 2010
+++ src/sys/arch/amd64/include/pte.h	Fri May 13 11:17:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pte.h,v 1.8 2010/07/24 17:43:47 njoly Exp $	*/
+/*	$NetBSD: pte.h,v 1.9 2016/05/13 11:17:20 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -44,7 +44,7 @@
  * amd64 MMU hardware structure:
  *
  * the (first generation) amd64 MMU is a 4-level MMU which maps 2^48 bytes
- * of  virtual memory. The  pagesize we use is 4K (4096 [0x1000] bytes), 
+ * of virtual memory. The pagesize we use is 4K (4096 [0x1000] bytes),
  * although 2M and 4M can be used as well. The indexes in the levels
  * are 9 bits wide (512 64bit entries per level), dividing the bits
  * 9-9-9-9-12.
@@ -65,28 +65,24 @@
  */
 
 #if !defined(_LOCORE)
-
 /*
- * here we define the data types for PDEs and PTEs
+ * Here we define the data types for PDEs and PTEs.
  */
-
 typedef uint64_t pd_entry_t;		/* PDE */
 typedef uint64_t pt_entry_t;		/* PTE */
-
 #endif
 
 /*
- * now we define various for playing with virtual addresses
+ * Now we define various constants for playing with virtual addresses.
  */
-
 #define L1_SHIFT	12
-#define	L2_SHIFT	21
-#define	L3_SHIFT	30
-#define	L4_SHIFT	39
-#define	NBPD_L1		(1UL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
-#define	NBPD_L2		(1UL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
-#define	NBPD_L3		(1UL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */
-#define	NBPD_L4		(1UL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */
+#define L2_SHIFT	21
+#define L3_SHIFT	30
+#define L4_SHIFT	39
+#define NBPD_L1		(1UL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
+#define NBPD_L2		(1UL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
+#define NBPD_L3		(1UL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */
+#define NBPD_L4		(1UL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */
 
 #define L4_MASK		0xff80
 #define L3_MASK		0x007fc000
@@ -101,16 +97,15 @@ typedef uint64_t pt_entry_t;		/* PTE */
 /*
  * PDE/PTE bits. These are no different from their i386 counterparts.
  */
-
-#define	PG_V		0x0001	/* valid */
-#define	PG_RO		0x	/* read-only */
-#define	PG_RW		0x0002	/* read-write */
-#define	PG_u		0x0004	/* user accessible */
-#define	PG_PROT		0x0006
+#define PG_V		0x0001	/* valid */
+#define PG_RO		0x	/* read-only */
+#define PG_RW		0x0002	/* read-write */
+#define PG_u		0x0004	/* user accessible */
+#define PG_PROT		0x0006
 #define PG_WT		0x0008	/* write-through */
-#define	PG_N		0x0010	/* non-cacheable */
-#define	PG_U		0x0020	/* used */
-#define	PG_M		0x0040	/* modified */
+#define PG_N		0x0010	/* non-cacheable */
+#define PG_U		0x0020	/* used */
+#define PG_M		0x0040	/* modified */
 #define PG_PAT		0x0080	/* PAT (on pte) */
 #define PG_PS		0x0080	/* 2MB page size (on pde) */
 #define PG_G		0x0100	/* not flushed */
@@ -118,19 +113,18 @@ typedef uint64_t pt_entry_t;		/* PTE */
 #define PG_AVAIL2	0x0400
 #define PG_AVAIL3	0x0800
 #define PG_LGPAT	0x1000	/* PAT on large pages */
-#define	PG_FRAME	0x000ff000
-#define	PG_NX		0x8000
+#define PG_FRAME	0x000ff000
+#define PG_NX		0x8000
 
 #define PG_2MFRAME	0x000fffe0	/* large (2M) page frame mask */
 #define PG_1GFRAME	0x000fc000	/* large (1G) page frame mask */
-#define	PG_LGFRAME	PG_2MFRAME
+#define PG_LGFRAME	PG_2MFRAME
 
 /*
- * short forms of protection codes
+ * Short forms of protection codes.
  */
-
-#define	PG_KR		0x	/* kernel read-only */
-#define	PG_KW		0x0002	/* kernel read-write */
+#define PG_KR		0x	/* kernel read-only */
+#define PG_KW		0x0002	/* kernel read-write */
 
 #include 
 



CVS commit: src/bin/sh

2016-05-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri May 13 10:32:52 UTC 2016

Modified Files:
src/bin/sh: eval.c

Log Message:
More fallout from the fix for PR bin/48875 - this one found just by
code reading, rather than any actual real use case failing.

With this script
f()
{
echo hello $1
}

exec 3>&1
echo $(
for i in a b c
do
echo @$i
f >&3
done >/tmp/foo
)
echo foo= $(cat /tmp/foo)

what should be output is

hello
hello
hello

foo= @a @b @c

but since the (my) 48875 fix the other day, we've been getting

hello
@b
hello
@c
hello

foo= @a

This fixes that.   I think (hope) this is the last of these fixes...


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/bin/sh/eval.c

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

Modified files:

Index: src/bin/sh/eval.c
diff -u src/bin/sh/eval.c:1.126 src/bin/sh/eval.c:1.127
--- src/bin/sh/eval.c:1.126	Tue May 10 15:14:30 2016
+++ src/bin/sh/eval.c	Fri May 13 10:32:52 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: eval.c,v 1.126 2016/05/10 15:14:30 kre Exp $	*/
+/*	$NetBSD: eval.c,v 1.127 2016/05/13 10:32:52 kre Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c	8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.126 2016/05/10 15:14:30 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.127 2016/05/13 10:32:52 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -413,8 +413,13 @@ evalfor(union node *n, int flags)
 
 	loopnest++;
 	for (sp = arglist.list ; sp ; sp = sp->next) {
+		int f = flags & (EV_TESTED | EV_MORE);
+
+		if (sp->next)
+			f |= EV_MORE;
+
 		setvar(n->nfor.var, sp->text, 0);
-		evaltree(n->nfor.body, flags & (EV_TESTED | EV_MORE));
+		evaltree(n->nfor.body, f);
 		status = exitstatus;
 		if (nflag)
 			break;



CVS commit: src/sys/arch/x86/x86

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 10:24:42 UTC 2016

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

Log Message:
Remap the rodata and data+bss segments with large pages on x86. There still
is a bug in the way the text segment is mapped, but I'll see later.


To generate a diff of this commit:
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/x86/x86/pmap.c

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

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.191 src/sys/arch/x86/x86/pmap.c:1.192
--- src/sys/arch/x86/x86/pmap.c:1.191	Thu May 12 06:45:16 2016
+++ src/sys/arch/x86/x86/pmap.c	Fri May 13 10:24:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.191 2016/05/12 06:45:16 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.192 2016/05/13 10:24:42 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.191 2016/05/12 06:45:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.192 2016/05/13 10:24:42 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1272,7 +1272,6 @@ pmap_bootstrap(vaddr_t kva_start)
 	 * which happens in cpu_init(), which is run on each cpu
 	 * (and happens later)
 	 */
-
 	if (cpu_feature[0] & CPUID_PGE) {
 		pmap_pg_g = PG_G;		/* enable software */
 
@@ -1296,18 +1295,19 @@ pmap_bootstrap(vaddr_t kva_start)
 	}
 
 	/*
-	 * enable large pages if they are supported.
+	 * Enable large pages if they are supported.
 	 */
-
 	if (cpu_feature[0] & CPUID_PSE) {
 		paddr_t pa;
 		extern char __rodata_start;
+		extern char __data_start;
+		extern char __kernel_end;
 
 		lcr4(rcr4() | CR4_PSE);	/* enable hardware (via %cr4) */
 		pmap_largepages = 1;	/* enable software */
 
 		/*
-		 * the TLB must be flushed after enabling large pages
+		 * The TLB must be flushed after enabling large pages
 		 * on Pentium CPUs, according to section 3.6.2.2 of
 		 * "Intel Architecture Software Developer's Manual,
 		 * Volume 3: System Programming".
@@ -1315,16 +1315,18 @@ pmap_bootstrap(vaddr_t kva_start)
 		tlbflushg();
 
 		/*
-		 * now, remap the kernel text using large pages.  we
-		 * assume that the linker has properly aligned the
-		 * .rodata segment to a NBPD_L2 boundary.
+		 * Now, we remap several kernel segments with large pages. We
+		 * cover as many pages as we can.
 		 */
+
+		/* Remap the kernel text using large pages. */
+		kva = KERNBASE;
 		kva_end = rounddown((vaddr_t)&__rodata_start, NBPD_L1);
-		for (pa = 0, kva = KERNBASE; kva + NBPD_L2 <= kva_end;
-		 kva += NBPD_L2, pa += NBPD_L2) {
+		pa = kva - KERNBASE;
+		for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2,
+		pa += NBPD_L2) {
 			pde = _BASE[pl2_i(kva)];
-			*pde = pa | pmap_pg_g | PG_PS |
-			PG_KR | PG_V;	/* zap! */
+			*pde = pa | pmap_pg_g | PG_PS | PG_KR | PG_V;
 			tlbflushg();
 		}
 #if defined(DEBUG)
@@ -1333,6 +1335,28 @@ pmap_bootstrap(vaddr_t kva_start)
 		howmany(kva - KERNBASE, NBPD_L2),
 		howmany((vaddr_t)&__rodata_start - kva, NBPD_L1));
 #endif /* defined(DEBUG) */
+
+		/* Remap the kernel rodata using large pages. */
+		kva = roundup((vaddr_t)&__rodata_start, NBPD_L2);
+		kva_end = rounddown((vaddr_t)&__data_start, NBPD_L1);
+		pa = kva - KERNBASE;
+		for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2,
+		pa += NBPD_L2) {
+			pde = _BASE[pl2_i(kva)];
+			*pde = pa | pmap_pg_g | PG_PS | pg_nx | PG_KR | PG_V;
+			tlbflushg();
+		}
+
+		/* Remap the kernel data+bss using large pages. */
+		kva = roundup((vaddr_t)&__data_start, NBPD_L2);
+		kva_end = rounddown((vaddr_t)&__kernel_end, NBPD_L1);
+		pa = kva - KERNBASE;
+		for (/* */; kva + NBPD_L2 <= kva_end; kva += NBPD_L2,
+		pa += NBPD_L2) {
+			pde = _BASE[pl2_i(kva)];
+			*pde = pa | pmap_pg_g | PG_PS | pg_nx | PG_KW | PG_V;
+			tlbflushg();
+		}
 	}
 #endif /* !XEN */
 



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

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 10:18:02 UTC 2016

Modified Files:
src/sys/arch/i386/conf: kern.ldscript

Log Message:
Define __kernel_end.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/i386/conf/kern.ldscript

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/i386/conf/kern.ldscript
diff -u src/sys/arch/i386/conf/kern.ldscript:1.17 src/sys/arch/i386/conf/kern.ldscript:1.18
--- src/sys/arch/i386/conf/kern.ldscript:1.17	Thu May 12 06:45:16 2016
+++ src/sys/arch/i386/conf/kern.ldscript	Fri May 13 10:18:01 2016
@@ -1,11 +1,12 @@
-/*	$NetBSD: kern.ldscript,v 1.17 2016/05/12 06:45:16 maxv Exp $	*/
+/*	$NetBSD: kern.ldscript,v 1.18 2016/05/13 10:18:01 maxv Exp $	*/
 
 #include "assym.h"
 
+__PAGE_SIZE = 0x1000 ;
+
 ENTRY(_start)
 SECTIONS
 {
-	/* Read-only sections, merged into text segment: */
 	.text :
 	{
 		*(.text)
@@ -45,6 +46,7 @@ SECTIONS
 		*(.data.read_mostly)
 	}
 	. = ALIGN(COHERENCY_UNIT);
+
 	_edata = . ;
 	PROVIDE (edata = .) ;
 	__bss_start = . ;
@@ -55,7 +57,12 @@ SECTIONS
 		*(COMMON)
 	. = ALIGN(32 / 8);
 	}
-	. = ALIGN(32 / 8);
+
+	. = ALIGN(__PAGE_SIZE);
+
+	/* End of the kernel image */
+	__kernel_end = . ;
+
 	_end = . ;
 	PROVIDE (end = .) ;
 	.note.netbsd.ident :



CVS commit: src/sys/conf

2016-05-13 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri May 13 07:41:47 UTC 2016

Modified Files:
src/sys/conf: majors

Log Message:
Clarify the intention here after discussing it with soda@


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/conf/majors

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

Modified files:

Index: src/sys/conf/majors
diff -u src/sys/conf/majors:1.72 src/sys/conf/majors:1.73
--- src/sys/conf/majors:1.72	Fri May 13 02:00:36 2016
+++ src/sys/conf/majors	Fri May 13 07:41:47 2016
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.72 2016/05/13 02:00:36 soda Exp $
+# $NetBSD: majors,v 1.73 2016/05/13 07:41:47 skrll Exp $
 #
 # Device majors for Machine-Independent drivers.
 #
@@ -56,11 +56,19 @@ device-major dtracechar 207		   dtra
 device-major spiflash  char 208 block 208  spiflash
 device-major lua   char 209lua
 
+# NOTE:
+# The following ranges are reserved for devices that have historical MD
+# definition, but are for "partially" MI use.
+# 
+# Any new port should use these "previously not" MI definitions instead of
+# separate MD values.
+# 
+# New MI devices should go to this file instead of majors.*
+#
 # 210-219 reserved for previously not MI ws devices
 # 220-239 reserved for previously not MI usb devices
 # 240-259 reserved for previously not MI "std" devices
 # 260-269 reserved for previously not MI tty devices
 # 310-339 reserved for previously not MI storage devices
-# NOTE: new MI devices should go to this file instead of above
 
 device-major hdmicec   char 340hdmicec