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

2018-01-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan 12 06:24:43 UTC 2018

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

Log Message:
Remove unused.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/x86/x86/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/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.117 src/sys/arch/x86/x86/intr.c:1.118
--- src/sys/arch/x86/x86/intr.c:1.117	Thu Jan 11 10:30:26 2018
+++ src/sys/arch/x86/x86/intr.c	Fri Jan 12 06:24:43 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.117 2018/01/11 10:30:26 maxv Exp $	*/
+/*	$NetBSD: intr.c,v 1.118 2018/01/12 06:24:43 maxv Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.117 2018/01/11 10:30:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.118 2018/01/12 06:24:43 maxv Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1500,7 +1500,6 @@ cpu_intr_init(struct cpu_info *ci)
 
 #else /* XEN */
 	int i; /* XXX: duplicate */
-	vaddr_t istack; /* XXX: duplicate */
 	ci->ci_iunmask[0] = 0xfffe;
 	for (i = 1; i < NIPL; i++)
 		ci->ci_iunmask[i] = ci->ci_iunmask[i - 1] & ~(1 << i);



CVS commit: src/sys/arch/sparc/sparc

2018-01-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Jan 12 06:01:34 UTC 2018

Modified Files:
src/sys/arch/sparc/sparc: timer.c timer_sun4m.c timerreg.h

Log Message:
fix time goes backwards problems on sparc.

there are a few things here:
- there's a race between reading the limit register (which clears
  the interrupt and the limit bit) and increasing the latest offset.
  this can happen easily if an interrupt comes between the read and
  the call to tickle_tc() that increases the offset (i obverved this
  actually happening.)
- in early boot, sometimes the counter can cycle twice before the
  tickle happens.

to handle these issues, add two workarounds:
- if the limit bit isn't set, but the counter value is less than
  the previous value, and the offset hasn't changed, use the same
  fixup as if the limit bit was set.  this handles the first case
  above.
- add a hard-workaround for never allowing returning a smaller
  value (except during 32 bit overflow): if the result is less than
  the last result, add fixups until it does (or until it would
  overflow.)

the first workaround fixes general run-time issues, and the second
fixes issues only seen during boot.

also expand some comments in timer_sun4m.c and re-enable the sun4m
sub-microsecond tmr_ustolim4m() support (but it's always called with
at least 'tick' microseconds, so the end result is the same.)


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/sparc/sparc/timer.c
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/sparc/sparc/timer_sun4m.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/sparc/sparc/timerreg.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/sparc/sparc/timer.c
diff -u src/sys/arch/sparc/sparc/timer.c:1.32 src/sys/arch/sparc/sparc/timer.c:1.33
--- src/sys/arch/sparc/sparc/timer.c:1.32	Sun Jan 19 00:22:33 2014
+++ src/sys/arch/sparc/sparc/timer.c	Fri Jan 12 06:01:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: timer.c,v 1.32 2014/01/19 00:22:33 mrg Exp $ */
+/*	$NetBSD: timer.c,v 1.33 2018/01/12 06:01:33 mrg Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.32 2014/01/19 00:22:33 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: timer.c,v 1.33 2018/01/12 06:01:33 mrg Exp $");
 
 #include 
 #include 
@@ -85,55 +85,98 @@ void *sched_cookie;
  * timecounter local state
  */
 static struct counter {
-	volatile u_int *cntreg;	/* counter register */
+	__cpu_simple_lock_t lock; /* protects access to offset, reg, last* */
+	volatile u_int *cntreg;	/* counter register to read */
 	u_int limit;		/* limit we count up to */
 	u_int offset;		/* accumulated offset due to wraps */
 	u_int shift;		/* scaling for valid bits */
 	u_int mask;		/* valid bit mask */
-} cntr;
+	u_int lastcnt;		/* the last* values are used to notice */
+	u_int lastres;		/* and fix up cases where it would appear */
+	u_int lastoffset;	/* time went backwards. */
+} cntr __aligned(CACHE_LINE_SIZE);
 
 /*
  * define timecounter
  */
 
 static struct timecounter counter_timecounter = {
-	timer_get_timecount,	/* get_timecount */
-	0,			/* no poll_pps */
-	~0u,			/* counter_mask */
-	0,  /* frequency - set at initialisation */
-	"timer-counter",	/* name */
-	100,			/* quality */
-/* private reference */
+	.tc_get_timecount =	timer_get_timecount,
+	.tc_poll_pps =		NULL,
+	.tc_counter_mask =	~0u,
+	.tc_frequency =		0,
+	.tc_name =		"timer-counter",
+	.tc_quality =		100,
+	.tc_priv =		,
 };
 
 /*
  * timer_get_timecount provide current counter value
  */
+__attribute__((__optimize__("Os")))
 static u_int
 timer_get_timecount(struct timecounter *tc)
 {
-	struct counter *ctr = (struct counter *)tc->tc_priv;
-
-	u_int c, res, r;
+	u_int cnt, res, fixup, offset;
 	int s;
 
+	/*
+	 * We use splhigh/__cpu_simple_lock here as we don't want
+	 * any mutex or lockdebug overhead.  The lock protects a
+	 * bunch of the members of cntr that are written here to
+	 * deal with the various minor races to be observed and
+	 * worked around.
+	 */
 	s = splhigh();
-
-	res = c = *ctr->cntreg;
+	__cpu_simple_lock();
+	res = cnt = *cntr.cntreg;
 
 	res &= ~TMR_LIMIT;
+	offset = cntr.offset;
 
-	if (c != res) {
-		r = ctr->limit;
+	/*
+	 * There are 3 cases here:
+	 * - limit reached, interrupt not yet processed.
+	 * - count reset but offset the same, race between handling
+	 *   the interrupt and tickle_tc() updating the offset.
+	 * - normal case.
+	 *
+	 * For the first two cases, add the limit so that we avoid
+	 * time going backwards.
+	 */
+	if (cnt != res) {
+		fixup = cntr.limit;
+	} else if (res < cntr.lastcnt && offset == cntr.lastoffset) {
+		fixup = cntr.limit;
 	} else {
-		r = 0;
+		fixup = 0;
 	}
+
+	cntr.lastcnt = res;
+	cntr.lastoffset = offset;
 	
-	res >>= ctr->shift;
-	res  &= ctr->mask;
+	res >>= cntr.shift;
+	res  &= cntr.mask;
+
+	res += fixup + offset;
 
-	res += r + 

CVS commit: src/sys/dev/sbus

2018-01-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Jan 12 05:59:20 UTC 2018

Modified Files:
src/sys/dev/sbus: dbri.c

Log Message:
fix several KASSERT()s and locking in a few places.
fixes DIAGNOSTIC kernels and still plays.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/sbus/dbri.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/dev/sbus/dbri.c
diff -u src/sys/dev/sbus/dbri.c:1.37 src/sys/dev/sbus/dbri.c:1.38
--- src/sys/dev/sbus/dbri.c:1.37	Thu Dec 21 21:56:29 2017
+++ src/sys/dev/sbus/dbri.c	Fri Jan 12 05:59:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dbri.c,v 1.37 2017/12/21 21:56:29 macallan Exp $	*/
+/*	$NetBSD: dbri.c,v 1.38 2018/01/12 05:59:20 mrg Exp $	*/
 
 /*
  * Copyright (C) 1997 Rudolf Koenig (rfkoe...@immd4.informatik.uni-erlangen.de)
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.37 2017/12/21 21:56:29 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbri.c,v 1.38 2018/01/12 05:59:20 mrg Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -461,15 +461,14 @@ dbri_config_interrupts(device_t dev)
 
 	dbri_init(sc);
 
-	mutex_spin_exit(>sc_intr_lock);
-
-
 	/* talking to the codec needs working interrupts */
 	if (mmcodec_init(sc) == -1) {
+		mutex_spin_exit(>sc_intr_lock);
 		printf("%s: no codec detected, aborting\n",
 		device_xname(dev));
 		return 0;
 	}
+	mutex_spin_exit(>sc_intr_lock);
 
 	/* Attach ourselves to the high level audio interface */
 	audio_attach_mi(_hw_if, sc, sc->sc_dev);
@@ -550,7 +549,7 @@ dbri_init(struct dbri_softc *sc)
 	bus_addr_t dmaaddr;
 	int n;
 
-	KASSERT(mutex_owned(sc->sc_intr_lock));
+	KASSERT(mutex_owned(>sc_intr_lock));
 
 	dbri_reset(sc);
 	sc->sc_mm.status = 0;
@@ -624,7 +623,7 @@ dbri_command_send(struct dbri_softc *sc,
 	bus_space_tag_t iot = sc->sc_iot;
 	int maxloops = 100;
 
-	KASSERT(mutex_owned(sc->sc_intr_lock));
+	KASSERT(mutex_owned(>sc_intr_lock));
 
 	sc->sc_locked--;
 
@@ -671,7 +670,7 @@ dbri_process_interrupt_buffer(struct dbr
 	int32_t i;
 	int orig_irqp = sc->sc_irqp;
 
-	KASSERT(mutex_owned(sc->sc_intr_lock));
+	KASSERT(mutex_owned(>sc_intr_lock));
 
 	while ((i = sc->sc_dma->intr[sc->sc_irqp]) != 0) {
 		sc->sc_dma->intr[sc->sc_irqp] = 0;
@@ -1003,6 +1002,8 @@ mmcodec_setcontrol(struct dbri_softc *sc
 	int error, bail = 0;
 #endif
 
+	KASSERT(mutex_owned(>sc_intr_lock));
+
 	/*
 	 * Temporarily mute outputs and wait 125 us to make sure that it
 	 * happens. This avoids clicking noises.
@@ -1068,7 +1069,6 @@ mmcodec_setcontrol(struct dbri_softc *sc
 		goto fail;
 	}
 #else
-	mutex_spin_enter(>sc_intr_lock);
 	while (((sc->sc_mm.status & 0xe4) != CS4215_ONE) && (bail < 10)) {
 		DPRINTF("%s: cv_wait_sig %p\n", device_xname(sc->sc_dev), sc);
 		error = cv_timedwait_sig(>sc_cv, >sc_intr_lock, hz);
@@ -1080,7 +1080,6 @@ mmcodec_setcontrol(struct dbri_softc *sc
 		}
 		bail++;
 	}
-	mutex_spin_exit(>sc_intr_lock);
 	if (bail >= 10) {
 		aprint_error("%s: switching to control mode timed out (%x %x)\n",
 		device_xname(sc->sc_dev), sc->sc_mm.status,
@@ -2025,6 +2024,7 @@ dbri_commit(void *hdl)
 	if (sc->sc_whack_codec == 0)
 		return 0;
 
+	mutex_spin_enter(>sc_intr_lock);
 	ret = mmcodec_setcontrol(sc);
 	if (ret) {
 		DPRINTF("%s: control mode failed. Mutex %s PIL %x\n", __func__,
@@ -2033,6 +2033,7 @@ dbri_commit(void *hdl)
 	} else
 		DPRINTF("%s: control mode ok\n", __func__);
 	mmcodec_init_data(sc);
+	mutex_spin_exit(>sc_intr_lock);
 	return 0;
 }
 
@@ -2225,8 +2226,9 @@ dbri_open(void *cookie, int flags)
 
 	DPRINTF("%s: %d\n", __func__, sc->sc_refcount);
 
-	if (sc->sc_refcount == 0)
+	if (sc->sc_refcount == 0) {
 		dbri_bring_up(sc);
+	}
 
 	sc->sc_refcount++;
 



CVS commit: src/sys/dev

2018-01-11 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Fri Jan 12 04:10:10 UTC 2018

Modified Files:
src/sys/dev: audio.c

Log Message:
Allow open of audioctl devices whilst audio is open with the mixer
disabled.

XXX pullup -8


To generate a diff of this commit:
cvs rdiff -u -r1.449 -r1.450 src/sys/dev/audio.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/dev/audio.c
diff -u src/sys/dev/audio.c:1.449 src/sys/dev/audio.c:1.450
--- src/sys/dev/audio.c:1.449	Tue Jan  9 04:14:21 2018
+++ src/sys/dev/audio.c	Fri Jan 12 04:10:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.449 2018/01/09 04:14:21 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.450 2018/01/12 04:10:10 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss 
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.449 2018/01/09 04:14:21 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.450 2018/01/12 04:10:10 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2175,6 +2175,9 @@ audio_open(dev_t dev, struct audio_softc
 		vc = sc->sc_hwvc;
 	chan->vc = vc;
 
+	if (!sc->sc_usemixer && AUDIODEV(dev) == AUDIOCTL_DEVICE)
+		goto audioctl_dev;
+
 	if (sc->sc_usemixer) {
 		vc->sc_open = 0;
 		vc->sc_mode = 0;
@@ -2292,9 +2295,12 @@ audio_open(dev_t dev, struct audio_softc
 	/* audio_close() decreases sc_mpr[n].usedlow, recalculate here */
 	audio_calcwater(sc, vc);
 
+audioctl_dev:
 	error = fd_allocfile(, );
 	if (error)
 		goto bad;
+	if (!sc->sc_usemixer && AUDIODEV(dev) == AUDIOCTL_DEVICE)
+		goto setup_chan;
 
 	DPRINTF(("audio_open: done sc_mode = 0x%x\n", vc->sc_mode));
 
@@ -2304,6 +2310,8 @@ audio_open(dev_t dev, struct audio_softc
 		sc->sc_recopens++;
 	if (flags & FWRITE)
 		sc->sc_opens++;
+
+setup_chan:
 	chan->dev = dev;
 	chan->chan = n;
 	chan->deschan = n;
@@ -2480,6 +2488,9 @@ audio_close(struct audio_softc *sc, int 
 
 	KASSERT(mutex_owned(sc->sc_lock));
 	
+	if (!sc->sc_usemixer && AUDIODEV(chan->dev) == AUDIOCTL_DEVICE)
+		return 0;
+
 	if (sc->sc_opens == 0 && sc->sc_recopens == 0)
 		return ENXIO;
 



CVS commit: src/usr.sbin/autofs

2018-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 11 13:44:26 UTC 2018

Modified Files:
src/usr.sbin/autofs: automountd.c

Log Message:
sprinkle __dead, use EXIT_{SUCCESS,FAILURE}


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/autofs/automountd.c

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

Modified files:

Index: src/usr.sbin/autofs/automountd.c
diff -u src/usr.sbin/autofs/automountd.c:1.1 src/usr.sbin/autofs/automountd.c:1.2
--- src/usr.sbin/autofs/automountd.c:1.1	Mon Jan  8 22:31:15 2018
+++ src/usr.sbin/autofs/automountd.c	Thu Jan 11 08:44:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: automountd.c,v 1.1 2018/01/09 03:31:15 christos Exp $	*/
+/*	$NetBSD: automountd.c,v 1.2 2018/01/11 13:44:26 christos Exp $	*/
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  *
  */
 #include 
-__RCSID("$NetBSD: automountd.c,v 1.1 2018/01/09 03:31:15 christos Exp $");
+__RCSID("$NetBSD: automountd.c,v 1.2 2018/01/11 13:44:26 christos Exp $");
 
 #include 
 #include 
@@ -163,7 +163,7 @@ exit_callback(void)
 	done(EIO, true);
 }
 
-static void
+__dead static void
 handle_request(const struct autofs_daemon_request *adr, char *cmdline_options,
 bool incomplete_hierarchy)
 {
@@ -262,7 +262,7 @@ handle_request(const struct autofs_daemo
 			/*
 			 * Exit without calling exit_callback().
 			 */
-			quick_exit(0);
+			quick_exit(EXIT_SUCCESS);
 		}
 
 		/*
@@ -288,7 +288,7 @@ handle_request(const struct autofs_daemo
 		/*
 		 * Exit without calling exit_callback().
 		 */
-		quick_exit(0);
+		quick_exit(EXIT_SUCCESS);
 	}
 
 	log_debugx("found node defined at %s:%d; it is a mountpoint",
@@ -362,7 +362,7 @@ handle_request(const struct autofs_daemo
 	/*
 	 * Exit without calling exit_callback().
 	 */
-	quick_exit(0);
+	quick_exit(EXIT_SUCCESS);
 }
 
 static void
@@ -424,13 +424,13 @@ wait_for_children(bool block)
 	return num;
 }
 
-static void
+__dead static void
 usage_automountd(void)
 {
 
-	fprintf(stderr, "usage: automountd [-D name=value][-m maxproc]"
-	"[-o opts][-Tidv]\n");
-	exit(1);
+	fprintf(stderr, "Usage: %s [-D name=value][-m maxproc]"
+	"[-o opts][-Tidv]\n", getprogname());
+	exit(EXIT_FAILURE);
 }
 
 static int
@@ -531,7 +531,7 @@ main_automountd(int argc, char **argv)
 		if (daemon(0, 0) == -1) {
 			log_warn("cannot daemonize");
 			pidfile_clean();
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 	} else {
 		lesser_daemon();
@@ -597,5 +597,5 @@ main_automountd(int argc, char **argv)
 
 	pidfile_clean();
 
-	return 0;
+	return EXIT_SUCCESS;
 }



CVS commit: src/sys/arch

2018-01-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 11 13:35:15 UTC 2018

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

Log Message:
Introduce a new svs_page_add function, which can be used to map in the user
space a VA from the kernel space.

Use it to replace the PDIR_SLOT_PCPU slot: at boot time each CPU creates
its own slot which maps only its own pcpu_entry plus the common area (IDT+
LDT).

This way, the pcpu areas of the remote CPUs are not mapped in userland.


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.145 -r1.146 src/sys/arch/x86/x86/cpu.c

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

Modified files:

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.288 src/sys/arch/amd64/amd64/machdep.c:1.289
--- src/sys/arch/amd64/amd64/machdep.c:1.288	Thu Jan 11 10:38:13 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan 11 13:35:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.288 2018/01/11 10:38:13 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.289 2018/01/11 13:35:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.288 2018/01/11 10:38:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.289 2018/01/11 13:35:15 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -2264,9 +2264,76 @@ mm_md_direct_mapped_phys(paddr_t paddr, 
  * TODO: for now, only PMAP_SLOT_PTE is unmapped.
  */
 
+static void
+svs_page_add(struct cpu_info *ci, vaddr_t va)
+{
+	extern pd_entry_t * const normal_pdes[];
+	extern const vaddr_t ptp_masks[];
+	extern const int ptp_shifts[];
+	extern const long nbpd[];
+	pd_entry_t *srcpde, *dstpde;
+	size_t i, idx, pidx, mod;
+	struct vm_page *pg;
+	paddr_t pa;
+
+	KASSERT(va % PAGE_SIZE == 0);
+
+	dstpde = ci->ci_svs_updir;
+	mod = (size_t)-1;
+
+	for (i = PTP_LEVELS; i > 1; i--) {
+		idx = pl_i(va, i);
+		srcpde = normal_pdes[i - 2];
+
+		if (!pmap_valid_entry(srcpde[idx])) {
+			panic("%s: page not mapped", __func__);
+		}
+		pidx = pl_i(va % mod, i);
+
+		if (!pmap_valid_entry(dstpde[pidx])) {
+			pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO);
+			if (pg == 0)
+panic("%s: failed to allocate PA for CPU %d\n",
+	__func__, cpu_index(ci));
+			pa = VM_PAGE_TO_PHYS(pg);
+
+			dstpde[pidx] = PG_V | PG_RW | pa;
+		}
+
+		pa = (paddr_t)(dstpde[pidx] & PG_FRAME);
+		dstpde = (pd_entry_t *)PMAP_DIRECT_MAP(pa);
+		mod = nbpd[i-1];
+	}
+
+	/* Do the last level manually */
+	idx = pl_i(va, 1);
+	srcpde = L1_BASE;
+	if (!pmap_valid_entry(srcpde[idx])) {
+		panic("%s: L1 page not mapped", __func__);
+	}
+	pidx = pl_i(va % mod, 1);
+	if (pmap_valid_entry(dstpde[pidx])) {
+		panic("%s: L1 page already mapped", __func__);
+	}
+	dstpde[pidx] = srcpde[idx];
+}
+
+static void
+svs_range_add(struct cpu_info *ci, vaddr_t va, size_t size)
+{
+	size_t i, n;
+
+	KASSERT(size % PAGE_SIZE == 0);
+	n = size / PAGE_SIZE;
+	for (i = 0; i < n; i++) {
+		svs_page_add(ci, va + i * PAGE_SIZE);
+	}
+}
+
 void
 cpu_svs_init(struct cpu_info *ci)
 {
+	const cpuid_t cid = cpu_index(ci);
 	struct vm_page *pg;
 
 	KASSERT(ci != NULL);
@@ -2291,6 +2358,11 @@ cpu_svs_init(struct cpu_info *ci)
 	ci->ci_svs_kpdirpa = pmap_pdirpa(pmap_kernel(), 0);
 
 	mutex_init(>ci_svs_mtx, MUTEX_DEFAULT, IPL_VM);
+
+	svs_page_add(ci, (vaddr_t)>idt);
+	svs_page_add(ci, (vaddr_t)>ldt);
+	svs_range_add(ci, (vaddr_t)>ent[cid],
+	sizeof(struct pcpu_entry));
 }
 
 void
@@ -2364,7 +2436,9 @@ svs_pdir_switch(struct pmap *pmap)
 		 * This is where we decide what to unmap from the user page
 		 * tables.
 		 */
-		if (pmap_direct_pdpe <= i &&
+		if (i == PDIR_SLOT_PCPU) {
+			/* keep the one created at boot time */
+		} else if (pmap_direct_pdpe <= i &&
 		i < pmap_direct_pdpe + pmap_direct_npdp) {
 			ci->ci_svs_updir[i] = 0;
 		} else if (i == PDIR_SLOT_PTE) {

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.145 src/sys/arch/x86/x86/cpu.c:1.146
--- src/sys/arch/x86/x86/cpu.c:1.145	Thu Jan 11 09:18:16 2018
+++ src/sys/arch/x86/x86/cpu.c	Thu Jan 11 13:35:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.145 2018/01/11 09:18:16 msaitoh Exp $	*/
+/*	$NetBSD: cpu.c,v 1.146 2018/01/11 13:35:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.145 2018/01/11 09:18:16 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.146 2018/01/11 13:35:15 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -380,10 +380,6 @@ cpu_attach(device_t parent, device_t sel
 	/* Must be before mi_cpu_attach(). */
 	cpu_vm_init(ci);
 
-#ifdef SVS
-	cpu_svs_init(ci);
-#endif
-
 	if (caa->cpu_role == CPU_ROLE_AP) {
 		int error;
 
@@ -401,6 +397,10 @@ cpu_attach(device_t 

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

2018-01-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 11 11:15:35 UTC 2018

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

Log Message:
The uarea must always be page-aligned.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/x86/x86/vm_machdep.c

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

Modified files:

Index: src/sys/arch/x86/x86/vm_machdep.c
diff -u src/sys/arch/x86/x86/vm_machdep.c:1.30 src/sys/arch/x86/x86/vm_machdep.c:1.31
--- src/sys/arch/x86/x86/vm_machdep.c:1.30	Sun Dec 31 08:29:38 2017
+++ src/sys/arch/x86/x86/vm_machdep.c	Thu Jan 11 11:15:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.30 2017/12/31 08:29:38 maxv Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.31 2018/01/11 11:15:34 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.30 2017/12/31 08:29:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.31 2018/01/11 11:15:34 maxv Exp $");
 
 #include "opt_mtrr.h"
 
@@ -178,9 +178,10 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	 * returns normally.
 	 */
 	uv = uvm_lwp_getuarea(l2);
+	KASSERT(uv % PAGE_SIZE == 0);
 
 #ifdef __x86_64__
-	pcb2->pcb_rsp0 = (uv + USPACE - 16) & ~0xf;
+	pcb2->pcb_rsp0 = (uv + USPACE - 16);
 	tf = (struct trapframe *)pcb2->pcb_rsp0 - 1;
 #else
 	pcb2->pcb_esp0 = (uv + USPACE - 16);



CVS commit: src/sys/arch

2018-01-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 11 10:38:13 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/x86/include: pmap.h

Log Message:
Add ist0 to pcpu_entry.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.73 -r1.74 src/sys/arch/x86/include/pmap.h

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

Modified files:

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.287 src/sys/arch/amd64/amd64/machdep.c:1.288
--- src/sys/arch/amd64/amd64/machdep.c:1.287	Thu Jan 11 10:30:26 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan 11 10:38:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.287 2018/01/11 10:30:26 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.288 2018/01/11 10:38:13 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.287 2018/01/11 10:30:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.288 2018/01/11 10:38:13 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -522,7 +522,11 @@ cpu_init_tss(struct cpu_info *ci)
 	cputss->tss.tss_iobase = IOMAP_INVALOFF << 16;
 
 	/* DDB stack */
+#ifdef __HAVE_PCPU_AREA
+	p = (vaddr_t)>ent[cid].ist0;
+#else
 	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
+#endif
 	cputss->tss.tss_ist[0] = p + PAGE_SIZE - 16;
 
 	/* double fault */

Index: src/sys/arch/x86/include/pmap.h
diff -u src/sys/arch/x86/include/pmap.h:1.73 src/sys/arch/x86/include/pmap.h:1.74
--- src/sys/arch/x86/include/pmap.h:1.73	Fri Jan  5 08:04:21 2018
+++ src/sys/arch/x86/include/pmap.h	Thu Jan 11 10:38:13 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.73 2018/01/05 08:04:21 maxv Exp $	*/
+/*	$NetBSD: pmap.h,v 1.74 2018/01/11 10:38:13 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -160,6 +160,7 @@ struct bootspace {
 struct pcpu_entry {
 	uint8_t gdt[MAXGDTSIZ];
 	uint8_t tss[PAGE_SIZE];
+	uint8_t ist0[PAGE_SIZE];
 	uint8_t ist1[PAGE_SIZE];
 	uint8_t ist2[PAGE_SIZE];
 } __packed;



CVS commit: src/sys/arch

2018-01-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 11 10:30:26 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/amd64/include: param.h
src/sys/arch/x86/x86: intr.c

Log Message:
Initialize ist0 in cpu_init_tss. On amd64 this is the DDB stack, and it has
nothing to do with ci_intrstack. While here, style, and don't forget to
pass UVM_KMF_ZERO in uvm_km_alloc.


To generate a diff of this commit:
cvs rdiff -u -r1.286 -r1.287 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/amd64/include/param.h
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/x86/x86/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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.286 src/sys/arch/amd64/amd64/machdep.c:1.287
--- src/sys/arch/amd64/amd64/machdep.c:1.286	Thu Jan 11 09:00:04 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan 11 10:30:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.286 2018/01/11 09:00:04 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.287 2018/01/11 10:30:26 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.286 2018/01/11 09:00:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.287 2018/01/11 10:30:26 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -520,13 +520,16 @@ cpu_init_tss(struct cpu_info *ci)
 #endif
 
 	cputss->tss.tss_iobase = IOMAP_INVALOFF << 16;
-	/* cputss->tss.tss_ist[0] is filled by cpu_intr_init */
+
+	/* DDB stack */
+	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
+	cputss->tss.tss_ist[0] = p + PAGE_SIZE - 16;
 
 	/* double fault */
 #ifdef __HAVE_PCPU_AREA
 	p = (vaddr_t)>ent[cid].ist1;
 #else
-	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
+	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
 #endif
 	cputss->tss.tss_ist[1] = p + PAGE_SIZE - 16;
 
@@ -534,7 +537,7 @@ cpu_init_tss(struct cpu_info *ci)
 #ifdef __HAVE_PCPU_AREA
 	p = (vaddr_t)>ent[cid].ist2;
 #else
-	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
+	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
 #endif
 	cputss->tss.tss_ist[2] = p + PAGE_SIZE - 16;
 

Index: src/sys/arch/amd64/include/param.h
diff -u src/sys/arch/amd64/include/param.h:1.22 src/sys/arch/amd64/include/param.h:1.23
--- src/sys/arch/amd64/include/param.h:1.22	Wed Jun 14 12:27:24 2017
+++ src/sys/arch/amd64/include/param.h	Thu Jan 11 10:30:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.22 2017/06/14 12:27:24 maxv Exp $	*/
+/*	$NetBSD: param.h,v 1.23 2018/01/11 10:30:26 maxv Exp $	*/
 
 #ifdef __x86_64__
 
@@ -63,7 +63,6 @@
 #define	UPAGES		3		/* pages of u-area */
 #endif
 #define	USPACE		(UPAGES * NBPG)	/* total size of u-area */
-#define	INTRSTACKSIZE	4096
 
 #ifndef MSGBUFSIZE
 #define MSGBUFSIZE	(8*NBPG)	/* default message buffer size */

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.116 src/sys/arch/x86/x86/intr.c:1.117
--- src/sys/arch/x86/x86/intr.c:1.116	Thu Jan  4 13:36:30 2018
+++ src/sys/arch/x86/x86/intr.c	Thu Jan 11 10:30:26 2018
@@ -1,6 +1,6 @@
-/*	$NetBSD: intr.c,v 1.116 2018/01/04 13:36:30 maxv Exp $	*/
+/*	$NetBSD: intr.c,v 1.117 2018/01/11 10:30:26 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -133,7 +133,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.116 2018/01/04 13:36:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.117 2018/01/11 10:30:26 maxv Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -168,7 +168,7 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.1
 #include "acpica.h"
 
 #if NIOAPIC > 0 || NACPICA > 0
-#include  
+#include 
 #include 
 #include 
 #endif
@@ -372,7 +372,7 @@ intr_calculatemasks(struct cpu_info *ci)
 
 /*
  * List to keep track of PCI buses that are probed but not known
- * to the firmware. Used to 
+ * to the firmware. Used to
  *
  * XXX should maintain one list, not an array and a linked list.
  */
@@ -791,7 +791,7 @@ intr_allocate_slot(struct pic *pic, int 
 	}
 	KASSERT(ci != NULL);
 
-	/* 
+	/*
 	 * Now allocate an IDT vector.
 	 * For the 8259 these are reserved up front.
 	 */
@@ -1034,7 +1034,7 @@ intr_establish_xname(int legacy_irq, str
 		/* NOTREACHED */
 	}
 
-/*
+	/*
 	 * If the establishing interrupt uses shared IRQ, the interrupt uses
 	 * "ci->ci_isources[slot]" instead of allocated by the establishing
 	 * device's pci_intr_alloc() or this function.
@@ -1149,7 +1149,7 @@ intr_disestablish_xcall(void *arg1, void
 	source = ci->ci_isources[ih->ih_slot];
 	idtvec = source->is_idtvec;
 
-	(*pic->pic_hwmask)(pic, ih->ih_pin);	
+	(*pic->pic_hwmask)(pic, ih->ih_pin);
 	atomic_and_32(>ci_ipending, ~(1 << ih->ih_slot));
 
 	/*
@@ -1457,9 

CVS commit: src/share/man/man7

2018-01-11 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Thu Jan 11 09:53:55 UTC 2018

Modified Files:
src/share/man/man7: sysctl.7

Log Message:
kern.module.verbose is a boolean, not an integer.  We had it right in the
text following the table, but the table itself was wrong.

Thanks to martin@ for pointing this out.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/share/man/man7/sysctl.7

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

Modified files:

Index: src/share/man/man7/sysctl.7
diff -u src/share/man/man7/sysctl.7:1.120 src/share/man/man7/sysctl.7:1.121
--- src/share/man/man7/sysctl.7:1.120	Thu Dec 28 23:16:57 2017
+++ src/share/man/man7/sysctl.7	Thu Jan 11 09:53:55 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sysctl.7,v 1.120 2017/12/28 23:16:57 wiz Exp $
+.\"	$NetBSD: sysctl.7,v 1.121 2018/01/11 09:53:55 pgoyette Exp $
 .\"
 .\" Copyright (c) 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -786,7 +786,7 @@ The third level names for the settings a
 .It Sy Third level name Ta Sy Type Ta Sy Changeable
 .It kern.module.autoload	integer	yes
 .It kern.module.autotime	integer	yes
-.It kern.module.verbose	integer	yes
+.It kern.module.verbose	boolean	yes
 .El
 .Pp
 The variables are as follows:



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

2018-01-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jan 11 09:18:16 UTC 2018

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

Log Message:
 Changing CR4 register may change cpuid values. For example, setting
CR4_OSXSAVE sets CPUID2_OSXSAVE. The CPUID2_OSXSAVE is in ci_feat_val[1],
so update it after changing CR4.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/x86/x86/cpu.c

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

Modified files:

Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.144 src/sys/arch/x86/x86/cpu.c:1.145
--- src/sys/arch/x86/x86/cpu.c:1.144	Sun Jan  7 16:10:16 2018
+++ src/sys/arch/x86/x86/cpu.c	Thu Jan 11 09:18:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.144 2018/01/07 16:10:16 maxv Exp $	*/
+/*	$NetBSD: cpu.c,v 1.145 2018/01/11 09:18:16 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.144 2018/01/07 16:10:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.145 2018/01/11 09:18:16 msaitoh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"		/* for MPDEBUG */
@@ -623,6 +623,19 @@ cpu_init(struct cpu_info *ci)
 		lcr4(cr4);
 	}
 
+	/*
+	 * Changing CR4 register may change cpuid values. For example, setting
+	 * CR4_OSXSAVE sets CPUID2_OSXSAVE. The CPUID2_OSXSAVE is in
+	 * ci_feat_val[1], so update it.
+	 * XXX Other than ci_feat_val[1] might be changed.
+	 */
+	if (cpuid_level >= 1) {
+		u_int descs[4];
+
+		x86_cpuid(1, descs);
+		ci->ci_feat_val[1] = descs[2];
+	}
+
 	if (x86_fpu_save >= FPU_SAVE_FXSAVE) {
 		fpuinit_mxcsr_mask();
 	}



CVS commit: src/sys/arch/amd64

2018-01-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan 11 09:00:04 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: locore.S machdep.c
src/sys/arch/amd64/include: frameasm.h types.h

Log Message:
Declare new SVS_* variants: SVS_ENTER_NOSTACK and SVS_LEAVE_NOSTACK. Use
SVS_ENTER_NOSTACK in the syscall entry point, and put it before the code
that touches curlwp. (curlwp is located in the direct map.)

Then, disable __HAVE_CPU_UAREA_ROUTINES (to be removed later). This moves
the kernel stack into pmap_kernel(), and not the direct map. That's a
change I've always wanted to make: because of the direct map we can't add
a redzone on the stack, and basically, a stack overflow can go very far
in memory without being detected (as far as erasing all of the system's
memory).

Finally, unmap the direct map from userland.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.285 -r1.286 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/amd64/include/frameasm.h
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/amd64/include/types.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/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.145 src/sys/arch/amd64/amd64/locore.S:1.146
--- src/sys/arch/amd64/amd64/locore.S:1.145	Sun Jan  7 16:10:16 2018
+++ src/sys/arch/amd64/amd64/locore.S	Thu Jan 11 09:00:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.145 2018/01/07 16:10:16 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.146 2018/01/11 09:00:04 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1268,6 +1268,7 @@ IDTVEC(syscall)
 	 * is ignored as well.
 	 */
 	swapgs
+	SVS_ENTER_NOSTACK
 	movq	%r15,CPUVAR(SCRATCH)
 	movq	CPUVAR(CURLWP),%r15
 	movq	L_PCB(%r15),%r15
@@ -1295,7 +1296,6 @@ IDTVEC(syscall)
 	subq	$TF_REGSIZE,%rsp
 	cld
 #endif
-	SVS_ENTER
 	INTR_SAVE_GPRS
 	movw	$GSEL(GUDATA_SEL, SEL_UPL),TF_DS(%rsp)
 	movw	$GSEL(GUDATA_SEL, SEL_UPL),TF_ES(%rsp)

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.285 src/sys/arch/amd64/amd64/machdep.c:1.286
--- src/sys/arch/amd64/amd64/machdep.c:1.285	Sun Jan  7 16:10:16 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan 11 09:00:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.285 2018/01/07 16:10:16 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.286 2018/01/11 09:00:04 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.285 2018/01/07 16:10:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.286 2018/01/11 09:00:04 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -2339,6 +2339,8 @@ svs_pte_atomic_read(struct pmap *pmap, s
 void
 svs_pdir_switch(struct pmap *pmap)
 {
+	extern size_t pmap_direct_pdpe;
+	extern size_t pmap_direct_npdp;
 	struct cpu_info *ci = curcpu();
 	pt_entry_t pte;
 	size_t i;
@@ -2351,8 +2353,14 @@ svs_pdir_switch(struct pmap *pmap)
 	mutex_enter(>ci_svs_mtx);
 
 	for (i = 0; i < 512; i++) {
-		if (i == PDIR_SLOT_PTE) {
-			/* We don't want to have this mapped. */
+		/*
+		 * This is where we decide what to unmap from the user page
+		 * tables.
+		 */
+		if (pmap_direct_pdpe <= i &&
+		i < pmap_direct_pdpe + pmap_direct_npdp) {
+			ci->ci_svs_updir[i] = 0;
+		} else if (i == PDIR_SLOT_PTE) {
 			ci->ci_svs_updir[i] = 0;
 		} else {
 			pte = svs_pte_atomic_read(pmap, i);

Index: src/sys/arch/amd64/include/frameasm.h
diff -u src/sys/arch/amd64/include/frameasm.h:1.27 src/sys/arch/amd64/include/frameasm.h:1.28
--- src/sys/arch/amd64/include/frameasm.h:1.27	Sun Jan  7 16:10:16 2018
+++ src/sys/arch/amd64/include/frameasm.h	Thu Jan 11 09:00:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: frameasm.h,v 1.27 2018/01/07 16:10:16 maxv Exp $	*/
+/*	$NetBSD: frameasm.h,v 1.28 2018/01/11 09:00:04 maxv Exp $	*/
 
 #ifndef _AMD64_MACHINE_FRAMEASM_H
 #define _AMD64_MACHINE_FRAMEASM_H
@@ -107,9 +107,21 @@
 	movq	CPUVAR(UPDIRPA),%rax	; \
 	movq	%rax,%cr3		; \
 	popq	%rax
+#define SVS_ENTER_NOSTACK \
+	movq	%rax,CPUVAR(SCRATCH)	; \
+	movq	CPUVAR(KPDIRPA),%rax	; \
+	movq	%rax,%cr3		; \
+	movq	CPUVAR(SCRATCH),%rax
+#define SVS_LEAVE_NOSTACK \
+	movq	%rax,CPUVAR(SCRATCH)	; \
+	movq	CPUVAR(UPDIRPA),%rax	; \
+	movq	%rax,%cr3		; \
+	movq	CPUVAR(SCRATCH),%rax
 #else
 #define SVS_ENTER	/* nothing */
 #define SVS_LEAVE	/* nothing */
+#define SVS_ENTER_NOSTACK	/* nothing */
+#define SVS_LEAVE_NOSTACK	/* nothing */
 #endif
 
 #define	INTRENTRY_L(kernel_trap, usertrap) \

Index: src/sys/arch/amd64/include/types.h
diff -u src/sys/arch/amd64/include/types.h:1.53 src/sys/arch/amd64/include/types.h:1.54
--- src/sys/arch/amd64/include/types.h:1.53	Fri Jan  5 08:04:21 2018
+++ src/sys/arch/amd64/include/types.h	Thu Jan 11 09:00:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: types.h,v 1.53 2018/01/05 08:04:21 maxv Exp $	*/
+/*	$NetBSD: types.h,v 1.54 

CVS commit: src/share/man/man4

2018-01-11 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Jan 11 08:59:27 UTC 2018

Modified Files:
src/share/man/man4: ipsecif.4

Log Message:
New sentence, new line. Remove empty macro.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/share/man/man4/ipsecif.4

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

Modified files:

Index: src/share/man/man4/ipsecif.4
diff -u src/share/man/man4/ipsecif.4:1.3 src/share/man/man4/ipsecif.4:1.4
--- src/share/man/man4/ipsecif.4:1.3	Thu Jan 11 06:38:05 2018
+++ src/share/man/man4/ipsecif.4	Thu Jan 11 08:59:27 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ipsecif.4,v 1.3 2018/01/11 06:38:05 knakahara Exp $
+.\"	$NetBSD: ipsecif.4,v 1.4 2018/01/11 08:59:27 wiz Exp $
 .\"
 .\" Copyright (C) 2017 Internet Initiative Japan Inc.
 .\" All rights reserved.
@@ -38,8 +38,9 @@
 .Sh DESCRIPTION
 The
 .Nm
-interface is targeted for route-based VPNs. It can tunnel IPv4 and
-IPv6 traffic over either IPv4 or IPv6 and secure it with ESP.
+interface is targeted for route-based VPNs.
+It can tunnel IPv4 and IPv6 traffic over either IPv4 or IPv6 and
+secure it with ESP.
 .Pp
 .Nm
 interfaces are dynamically created and destroyed with the
@@ -47,12 +48,12 @@ interfaces are dynamically created and d
 .Cm create
 and
 .Cm destroy
-subcommands. The administrator must configure
+subcommands.
+The administrator must configure
 .Nm
-.Cm
-tunnel
-endpoint addresses. These addresses will be used for the outer IP
-header of ESP packets. The administrator also configures the protocol
+tunnel endpoint addresses.
+These addresses will be used for the outer IP header of ESP packets.
+The administrator also configures the protocol
 and addresses for the inner IP header with
 .Xr ifconfig 8
 .Cm inet
@@ -72,7 +73,8 @@ transport mode, however their security p
 over
 .Xr ipsec 4
 transport mode expects for userland programs to managed its
-security policies. In contrast,
+security policies.
+In contrast,
 .Nm
 manages its security policies by itself, that is, when the administrator
 sets up a