CVS commit: [pgoyette-localcount] src/sys/rump/dev/lib/libcgd

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jul 23 05:05:47 UTC 2016

Modified Files:
src/sys/rump/dev/lib/libcgd [pgoyette-localcount]: cgd_component.c

Log Message:
The rump_cgd component needs to do an early cdevsw_attact() to figure
out the device major numbers being used.  But we then need to detach
the [bc]devsw's to allow them to get attached normally during module
initialization.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.2.1 src/sys/rump/dev/lib/libcgd/cgd_component.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/rump/dev/lib/libcgd/cgd_component.c
diff -u src/sys/rump/dev/lib/libcgd/cgd_component.c:1.2 src/sys/rump/dev/lib/libcgd/cgd_component.c:1.2.2.1
--- src/sys/rump/dev/lib/libcgd/cgd_component.c:1.2	Tue Jan 26 23:12:15 2016
+++ src/sys/rump/dev/lib/libcgd/cgd_component.c	Sat Jul 23 05:05:47 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cgd_component.c,v 1.2 2016/01/26 23:12:15 pooka Exp $	*/
+/*	$NetBSD: cgd_component.c,v 1.2.2.1 2016/07/23 05:05:47 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd_component.c,v 1.2 2016/01/26 23:12:15 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd_component.c,v 1.2.2.1 2016/07/23 05:05:47 pgoyette Exp $");
 
 #include 
 #include 
@@ -56,4 +56,5 @@ RUMP_COMPONENT(RUMP_COMPONENT_DEV)
 	if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/rcgd0", 'a',
 	cmaj, 0, 7)) != 0)
 		panic("cannot create raw cgd dev nodes: %d", error);
+	cdevsw_detach(_bdevsw, _cdevsw);
 }



CVS commit: [pgoyette-localcount] src/sys/miscfs/specfs

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jul 23 05:01:09 UTC 2016

Modified Files:
src/sys/miscfs/specfs [pgoyette-localcount]: spec_vnops.c

Log Message:
Restore original handling of ioctl() returns.  If the underlying disk's
ioctl() returns success, we call uvm_vnp_setsize().  Regardless of any
error from the ioctl() call we should return success.


To generate a diff of this commit:
cvs rdiff -u -r1.162.2.3 -r1.162.2.4 src/sys/miscfs/specfs/spec_vnops.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/miscfs/specfs/spec_vnops.c
diff -u src/sys/miscfs/specfs/spec_vnops.c:1.162.2.3 src/sys/miscfs/specfs/spec_vnops.c:1.162.2.4
--- src/sys/miscfs/specfs/spec_vnops.c:1.162.2.3	Fri Jul 22 01:50:12 2016
+++ src/sys/miscfs/specfs/spec_vnops.c	Sat Jul 23 05:01:09 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: spec_vnops.c,v 1.162.2.3 2016/07/22 01:50:12 pgoyette Exp $	*/
+/*	$NetBSD: spec_vnops.c,v 1.162.2.4 2016/07/23 05:01:09 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.162.2.3 2016/07/22 01:50:12 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.162.2.4 2016/07/23 05:01:09 pgoyette Exp $");
 
 #include 
 #include 
@@ -661,6 +661,13 @@ spec_open(void *v)
 	if (error == 0)
 		uvm_vnp_setsize(vp, (voff_t)pi.pi_secsize * pi.pi_size);
 
+	if (cdev != NULL)
+		cdevsw_release(cdev);
+	if (bdev != NULL)
+		bdevsw_release(bdev);
+
+	return 0;
+
  out:
 	if (cdev != NULL)
 		cdevsw_release(cdev);



CVS commit: [pgoyette-localcount] src/sys/dev

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jul 23 03:20:37 UTC 2016

Modified Files:
src/sys/dev [pgoyette-localcount]: cgd.c

Log Message:
Remove debug printfs.

For MODULE builds, define cgd_cd via CFDRIVER_DECL


To generate a diff of this commit:
cvs rdiff -u -r1.108.2.10 -r1.108.2.11 src/sys/dev/cgd.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/cgd.c
diff -u src/sys/dev/cgd.c:1.108.2.10 src/sys/dev/cgd.c:1.108.2.11
--- src/sys/dev/cgd.c:1.108.2.10	Sat Jul 23 02:36:51 2016
+++ src/sys/dev/cgd.c	Sat Jul 23 03:20:37 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.108.2.10 2016/07/23 02:36:51 pgoyette Exp $ */
+/* $NetBSD: cgd.c,v 1.108.2.11 2016/07/23 03:20:37 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108.2.10 2016/07/23 02:36:51 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108.2.11 2016/07/23 03:20:37 pgoyette Exp $");
 
 #include 
 #include 
@@ -200,16 +200,13 @@ getcgd_softc(dev_t dev, device_t *self)
 
 	DPRINTF_FOLLOW(("getcgd_softc(0x%"PRIx64"): unit = %d\n", dev, unit));
 
-printf("%s: unit %d\n", __func__, unit);
 	*self = device_lookup_acquire(_cd, unit);
-printf("%s: *self %p\n", __func__, *self);
 
 	if (*self == NULL) {
 		sc = cgd_spawn(unit, self);
 	} else {
 		sc = device_private(*self);
 	}
-printf("%s: return, sc %p\n", __func__, sc);
 
 	return sc;
 }
@@ -286,13 +283,9 @@ cgd_spawn(int unit, device_t *self)
 	cf->cf_fstate = FSTATE_STAR;
 
 	if (config_attach_pseudo(cf) == NULL)
-{
-printf("%s: config_attach_pseudo() failed\n", __func__);
 		return NULL;
-}
 
 	*self = device_lookup_acquire(_cd, unit);
-printf("%s: pseudo added, *self %p\n", __func__, *self);
 	if (self == NULL)
 		return NULL;
 	else
@@ -674,7 +667,6 @@ cgdioctl(dev_t dev, u_long cmd, void *da
 	DPRINTF_FOLLOW(("cgdioctl(0x%"PRIx64", %ld, %p, %d, %p)\n",
 	dev, cmd, data, flag, l));
 
-printf("%s: dev %lx cmd %lx\n", __func__, (long unsigned int)dev, cmd);
 	switch (cmd) {
 	case CGDIOCGET:
 		return cgd_ioctl_get(dev, data, l);
@@ -688,25 +680,21 @@ printf("%s: dev %lx cmd %lx\n", __func__
 		dksc = >sc_dksc;
 		break;
 	}
-printf("%s: softc %p, self %p\n", __func__, cs, self);
 
 	switch (cmd) {
 	case CGDIOCSET:
-printf("%s: case CGDIOCSET\n", __func__);
 		if (DK_ATTACHED(dksc))
 			error = EBUSY;
 		else
 			error = cgd_ioctl_set(cs, data, l);
 		break;
 	case CGDIOCCLR:
-printf("%s: case CGDIOCCLR\n", __func__);
 		if (DK_BUSY(>sc_dksc, pmask))
 			error = EBUSY;
 		else
 			error = cgd_ioctl_clr(cs, l);
 		break;
 	case DIOCCACHESYNC:
-printf("%s: case CGDIOCCACHESYNC\n", __func__);
 		/*
 		 * XXX Do we really need to care about having a writable
 		 * file descriptor here?
@@ -723,24 +711,20 @@ printf("%s: case CGDIOCCACHESYNC\n", __f
 		break;
 	case DIOCGSTRATEGY:
 	case DIOCSSTRATEGY:
-printf("%s: case CGDIOCxSTRATEGY\n", __func__);
 		if (!DK_ATTACHED(dksc)) {
 			error = ENOENT;
 			break;
 		}
 		/*FALLTHROUGH*/
 	default:
-printf("%s: case default\n", __func__);
 		error = dk_ioctl(dksc, dev, cmd, data, flag, l);
 		break;
 	case CGDIOCGET:
-printf("%s: case CGDIOCGET\n", __func__);
 		KASSERT(0);
 		error = EINVAL;
 		break;
 	}
 	device_release(self);
-printf("%s: return value %d\n", __func__, error);
 	return error;
 }
 
@@ -1150,7 +1134,7 @@ hexprint(const char *start, void *buf, i
 MODULE(MODULE_CLASS_DRIVER, cgd, "dk_subr");
 
 #ifdef _MODULE
-#include "ioconf.c"
+CFDRIVER_DECL(cgd, DV_DISK, NULL);
 #endif
 
 static int
@@ -1172,7 +1156,7 @@ cgd_modcmd(modcmd_t cmd, void *arg)
 		error = config_cfattach_attach(cgd_cd.cd_name, _ca);
 	if (error) {
 			config_cfdriver_detach(_cd);
-			aprint_error("%s: unable to register cfattach for ",
+			aprint_error("%s: unable to register cfattach for "
 			"%s, error %d", __func__, cgd_cd.cd_name, error);
 			break;
 		}



CVS commit: [pgoyette-localcount] src/sys/dev

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jul 23 02:36:51 UTC 2016

Modified Files:
src/sys/dev [pgoyette-localcount]: cgd.c

Log Message:
Revert changes in revision 1.108.2.3

For pseudo-devices, config(1) doesn't provide a valid cfattach, so when
a modular driver calls config_pseudo_attach() it will fail.  This is not
an issue for built-in drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.108.2.9 -r1.108.2.10 src/sys/dev/cgd.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/cgd.c
diff -u src/sys/dev/cgd.c:1.108.2.9 src/sys/dev/cgd.c:1.108.2.10
--- src/sys/dev/cgd.c:1.108.2.9	Fri Jul 22 06:32:54 2016
+++ src/sys/dev/cgd.c	Sat Jul 23 02:36:51 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.108.2.9 2016/07/22 06:32:54 pgoyette Exp $ */
+/* $NetBSD: cgd.c,v 1.108.2.10 2016/07/23 02:36:51 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108.2.9 2016/07/22 06:32:54 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108.2.10 2016/07/23 02:36:51 pgoyette Exp $");
 
 #include 
 #include 
@@ -172,8 +172,12 @@ static void	hexprint(const char *, void 
 /* Utility Functions */
 
 #define CGDUNIT(x)		DISKUNIT(x)
-#define GETCGD_SOFTC(_cs, x, _dv)\
-	if (!((_cs) = getcgd_softc(x, &_dv))) return ENXIO;
+#define GETCGD_SOFTC(_cs, x, _dv)			\
+	printf("%s: GETCGD_SOFTC\n", __func__);		\
+	if (!((_cs) = getcgd_softc(x, &_dv))) {		\
+		printf("%s: cs NULL\n", __func__);	\
+		return ENXIO;\
+	}
 
 /* The code */
 
@@ -196,13 +200,16 @@ getcgd_softc(dev_t dev, device_t *self)
 
 	DPRINTF_FOLLOW(("getcgd_softc(0x%"PRIx64"): unit = %d\n", dev, unit));
 
+printf("%s: unit %d\n", __func__, unit);
 	*self = device_lookup_acquire(_cd, unit);
+printf("%s: *self %p\n", __func__, *self);
 
 	if (*self == NULL) {
 		sc = cgd_spawn(unit, self);
 	} else {
 		sc = device_private(*self);
 	}
+printf("%s: return, sc %p\n", __func__, sc);
 
 	return sc;
 }
@@ -253,12 +260,18 @@ cgd_detach(device_t self, int flags)
 void
 cgdattach(int num)
 {
+/*
+ * We don't need to do anything here - the config database is updated
+ * in module initialization code.
+
 	int error;
 
 	error = config_cfattach_attach(cgd_cd.cd_name, _ca);
 	if (error != 0)
 		aprint_error("%s: unable to register cfattach\n",
 		cgd_cd.cd_name);
+ *
+ */
 }
 
 static struct cgd_softc *
@@ -273,11 +286,13 @@ cgd_spawn(int unit, device_t *self)
 	cf->cf_fstate = FSTATE_STAR;
 
 	if (config_attach_pseudo(cf) == NULL)
-{ printf("%s: config_attach_pseudo() failed\n", __func__);
+{
+printf("%s: config_attach_pseudo() failed\n", __func__);
 		return NULL;
 }
 
 	*self = device_lookup_acquire(_cd, unit);
+printf("%s: pseudo added, *self %p\n", __func__, *self);
 	if (self == NULL)
 		return NULL;
 	else
@@ -659,6 +674,7 @@ cgdioctl(dev_t dev, u_long cmd, void *da
 	DPRINTF_FOLLOW(("cgdioctl(0x%"PRIx64", %ld, %p, %d, %p)\n",
 	dev, cmd, data, flag, l));
 
+printf("%s: dev %lx cmd %lx\n", __func__, (long unsigned int)dev, cmd);
 	switch (cmd) {
 	case CGDIOCGET:
 		return cgd_ioctl_get(dev, data, l);
@@ -672,21 +688,25 @@ cgdioctl(dev_t dev, u_long cmd, void *da
 		dksc = >sc_dksc;
 		break;
 	}
+printf("%s: softc %p, self %p\n", __func__, cs, self);
 
 	switch (cmd) {
 	case CGDIOCSET:
+printf("%s: case CGDIOCSET\n", __func__);
 		if (DK_ATTACHED(dksc))
 			error = EBUSY;
 		else
-			cgd_ioctl_set(cs, data, l);
+			error = cgd_ioctl_set(cs, data, l);
 		break;
 	case CGDIOCCLR:
+printf("%s: case CGDIOCCLR\n", __func__);
 		if (DK_BUSY(>sc_dksc, pmask))
 			error = EBUSY;
 		else
-			cgd_ioctl_clr(cs, l);
+			error = cgd_ioctl_clr(cs, l);
 		break;
 	case DIOCCACHESYNC:
+printf("%s: case CGDIOCCACHESYNC\n", __func__);
 		/*
 		 * XXX Do we really need to care about having a writable
 		 * file descriptor here?
@@ -703,18 +723,24 @@ cgdioctl(dev_t dev, u_long cmd, void *da
 		break;
 	case DIOCGSTRATEGY:
 	case DIOCSSTRATEGY:
-		if (!DK_ATTACHED(dksc))
+printf("%s: case CGDIOCxSTRATEGY\n", __func__);
+		if (!DK_ATTACHED(dksc)) {
 			error = ENOENT;
+			break;
+		}
 		/*FALLTHROUGH*/
 	default:
-		 if (error == 0)
-			error = dk_ioctl(dksc, dev, cmd, data, flag, l);
+printf("%s: case default\n", __func__);
+		error = dk_ioctl(dksc, dev, cmd, data, flag, l);
 		break;
 	case CGDIOCGET:
+printf("%s: case CGDIOCGET\n", __func__);
 		KASSERT(0);
 		error = EINVAL;
+		break;
 	}
 	device_release(self);
+printf("%s: return value %d\n", __func__, error);
 	return error;
 }
 
@@ -1139,14 +1165,15 @@ cgd_modcmd(modcmd_t cmd, void *arg)
 	switch (cmd) {
 	case MODULE_CMD_INIT:
 #ifdef _MODULE
-		/*
-		 * Insert the driver into the autoconf database
-		 */
-		error = config_init_component(cfdriver_ioconf_cgd,
-cfattach_ioconf_cgd, cfdata_ioconf_cgd);
-		if (error) {
-			aprint_error("%s: unable to init component"
-			 

CVS commit: src/etc/rc.d

2016-07-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jul 23 01:38:35 UTC 2016

Modified Files:
src/etc/rc.d: mountcritlocal

Log Message:
Cause rc to abort if mounting any of the critical local filesystems fails
rather than just ignoring the error.

Don't bother attempting to clear the contents of /var/run if /var/run
does not exist.

In that case the mkdir of /var/run/lvm would have failed - correct that
by using mkdir -p (which as a side effect will ensure /var/run exists
and is available for later scripts to use if for some reason it did not exist.)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/etc/rc.d/mountcritlocal

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

Modified files:

Index: src/etc/rc.d/mountcritlocal
diff -u src/etc/rc.d/mountcritlocal:1.14 src/etc/rc.d/mountcritlocal:1.15
--- src/etc/rc.d/mountcritlocal:1.14	Tue Jul 22 17:11:09 2014
+++ src/etc/rc.d/mountcritlocal	Sat Jul 23 01:38:35 2016
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: mountcritlocal,v 1.14 2014/07/22 17:11:09 wiz Exp $
+# $NetBSD: mountcritlocal,v 1.15 2016/07/23 01:38:35 kre Exp $
 #
 
 # PROVIDE: mountcritlocal
@@ -18,19 +18,21 @@ mountcritlocal_start()
 	#	(as specified in $critical_filesystems_local)
 	#	This usually includes /var.
 	#
-	mount_critical_filesystems local
+	mount_critical_filesystems local || return $?
 
 	#	clean up left-over files.
 	#	this could include the cleanup of lock files and /var/run, etc.
 	#
 	rm -f /etc/nologin /var/spool/lock/LCK.*
-	(cd /var/run && rm -rf -- *)
+	test -d /var/run && (cd /var/run && rm -rf -- *)
+
 	#   create LVM locking directory, it needs to be owned by operator
 	#	group and has parmissions to allow lock file creation.
 	#
-	mkdir /var/run/lvm
+	mkdir -p /var/run/lvm
 	chown root:operator /var/run/lvm
 	chmod 770 /var/run/lvm
+	return 0
 }
 
 load_rc_config $name



CVS commit: [pgoyette-localcount] src/sys/fs/cd9660

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Sat Jul 23 00:44:59 UTC 2016

Modified Files:
src/sys/fs/cd9660 [pgoyette-localcount]: cd9660_vfsops.c

Log Message:
Be consistent in the ordering of operations.


To generate a diff of this commit:
cvs rdiff -u -r1.90.2.1 -r1.90.2.2 src/sys/fs/cd9660/cd9660_vfsops.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/fs/cd9660/cd9660_vfsops.c
diff -u src/sys/fs/cd9660/cd9660_vfsops.c:1.90.2.1 src/sys/fs/cd9660/cd9660_vfsops.c:1.90.2.2
--- src/sys/fs/cd9660/cd9660_vfsops.c:1.90.2.1	Wed Jul 20 23:47:56 2016
+++ src/sys/fs/cd9660/cd9660_vfsops.c	Sat Jul 23 00:44:59 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd9660_vfsops.c,v 1.90.2.1 2016/07/20 23:47:56 pgoyette Exp $	*/
+/*	$NetBSD: cd9660_vfsops.c,v 1.90.2.2 2016/07/23 00:44:59 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.90.2.1 2016/07/20 23:47:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.90.2.2 2016/07/23 00:44:59 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -292,8 +292,8 @@ cd9660_mount(struct mount *mp, const cha
 
 fail:
 	VOP_UNLOCK(devvp);
-	bdevsw_release(bdev);
 	vrele(devvp);
+	bdevsw_release(bdev);
 	return (error);
 }
 



CVS commit: [pgoyette-localcount] src/sys/kern

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 22 23:16:36 UTC 2016

Modified Files:
src/sys/kern [pgoyette-localcount]: subr_devsw.c

Log Message:
Fix a comment


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.12 -r1.34.2.13 src/sys/kern/subr_devsw.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/subr_devsw.c
diff -u src/sys/kern/subr_devsw.c:1.34.2.12 src/sys/kern/subr_devsw.c:1.34.2.13
--- src/sys/kern/subr_devsw.c:1.34.2.12	Fri Jul 22 23:04:01 2016
+++ src/sys/kern/subr_devsw.c	Fri Jul 22 23:16:36 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_devsw.c,v 1.34.2.12 2016/07/22 23:04:01 pgoyette Exp $	*/
+/*	$NetBSD: subr_devsw.c,v 1.34.2.13 2016/07/22 23:16:36 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.12 2016/07/22 23:04:01 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.13 2016/07/22 23:16:36 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -353,7 +353,7 @@ cdevsw_attach(const struct cdevsw *devsw
 	if (cdevsw[*devmajor] != NULL)
 		return (EEXIST);
 
-	/* ensure visibility of the bdevsw */
+	/* ensure visibility of the cdevsw */
 	membar_producer();
 
 	cdevsw[*devmajor] = devsw;



CVS commit: [pgoyette-localcount] src/sys/kern

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 22 23:04:01 UTC 2016

Modified Files:
src/sys/kern [pgoyette-localcount]: subr_devsw.c

Log Message:
Continue previous - finish what we started


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.11 -r1.34.2.12 src/sys/kern/subr_devsw.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/subr_devsw.c
diff -u src/sys/kern/subr_devsw.c:1.34.2.11 src/sys/kern/subr_devsw.c:1.34.2.12
--- src/sys/kern/subr_devsw.c:1.34.2.11	Fri Jul 22 23:02:55 2016
+++ src/sys/kern/subr_devsw.c	Fri Jul 22 23:04:01 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_devsw.c,v 1.34.2.11 2016/07/22 23:02:55 pgoyette Exp $	*/
+/*	$NetBSD: subr_devsw.c,v 1.34.2.12 2016/07/22 23:04:01 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.11 2016/07/22 23:02:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.12 2016/07/22 23:04:01 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -479,7 +479,7 @@ bdevsw_lookup_acquire(dev_t dev)
 
 	/* If the devsw is not statically linked, acquire a reference */
 	if (bdev->d_localcount != NULL)
-		localcount_acquire(bdevsw[bmajor]->d_localcount);
+		localcount_acquire(bdev->d_localcount);
 
  out:	pserialize_read_exit(s);
 
@@ -540,7 +540,7 @@ cdevsw_lookup_acquire(dev_t dev)
 
 	/* If the devsw is not statically linked, acquire a reference */
 	if (cdev->d_localcount != NULL)
-		localcount_acquire(cdevsw[cmajor]->d_localcount);
+		localcount_acquire(cdev->d_localcount);
 
  out:	pserialize_read_exit(s);
 



CVS commit: [pgoyette-localcount] src/sys/kern

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 22 23:02:55 UTC 2016

Modified Files:
src/sys/kern [pgoyette-localcount]: subr_devsw.c

Log Message:
Only retrieve the bdev/cdev from the xdevsw[] array once.


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.10 -r1.34.2.11 src/sys/kern/subr_devsw.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/subr_devsw.c
diff -u src/sys/kern/subr_devsw.c:1.34.2.10 src/sys/kern/subr_devsw.c:1.34.2.11
--- src/sys/kern/subr_devsw.c:1.34.2.10	Fri Jul 22 11:59:51 2016
+++ src/sys/kern/subr_devsw.c	Fri Jul 22 23:02:55 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_devsw.c,v 1.34.2.10 2016/07/22 11:59:51 pgoyette Exp $	*/
+/*	$NetBSD: subr_devsw.c,v 1.34.2.11 2016/07/22 23:02:55 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.10 2016/07/22 11:59:51 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.11 2016/07/22 23:02:55 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -478,7 +478,7 @@ bdevsw_lookup_acquire(dev_t dev)
 	membar_datadep_consumer();
 
 	/* If the devsw is not statically linked, acquire a reference */
-	if (bdevsw[bmajor]->d_localcount != NULL)
+	if (bdev->d_localcount != NULL)
 		localcount_acquire(bdevsw[bmajor]->d_localcount);
 
  out:	pserialize_read_exit(s);
@@ -539,7 +539,7 @@ cdevsw_lookup_acquire(dev_t dev)
 	membar_datadep_consumer();
 
 	/* If the devsw is not statically linked, acquire a reference */
-	if (cdevsw[cmajor]->d_localcount != NULL)
+	if (cdev->d_localcount != NULL)
 		localcount_acquire(cdevsw[cmajor]->d_localcount);
 
  out:	pserialize_read_exit(s);



CVS commit: src/sys/arch/mips/mips

2016-07-22 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Fri Jul 22 19:50:45 UTC 2016

Modified Files:
src/sys/arch/mips/mips: bus_dma.c

Log Message:
When mapping a dmamem page, make sure to trunc_pae the starting address


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/mips/mips/bus_dma.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/mips/mips/bus_dma.c
diff -u src/sys/arch/mips/mips/bus_dma.c:1.35 src/sys/arch/mips/mips/bus_dma.c:1.36
--- src/sys/arch/mips/mips/bus_dma.c:1.35	Sat Jul 16 21:33:46 2016
+++ src/sys/arch/mips/mips/bus_dma.c	Fri Jul 22 19:50:44 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.35 2016/07/16 21:33:46 matt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.36 2016/07/22 19:50:44 matt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.35 2016/07/16 21:33:46 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.36 2016/07/22 19:50:44 matt Exp $");
 
 #define _MIPS_BUS_DMA_PRIVATE
 
@@ -1115,7 +1115,7 @@ _bus_dmamem_map(bus_dma_tag_t t, bus_dma
 	*kvap = (void *)va;
 
 	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
+		for (addr = trunc_page(segs[curseg].ds_addr);
 		addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
 		addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
 			if (size == 0)



CVS commit: src/sys/arch

2016-07-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jul 22 14:08:33 UTC 2016

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

Log Message:
Remove pmap_prealloc_lowmem_ptps on amd64. This function creates levels in
the page tree so that the first 2MB of virtual memory can be kentered in
L1.

Strictly speaking, the kernel should never kenter a virtual page below
VM_MIN_KERNEL_ADDRESS, because then it wouldn't be available in userland.
It used to need the first 2MB in order to map the CPU trampoline and the
initial VAs used by the bootstrap code. Now, the CPU trampoline VA is
allocated with uvm_km_alloc and the VAs used by the bootstrap code are
allocated with pmap_bootstrap_valloc, and in either case the resulting VA
is above VM_MIN_KERNEL_ADDRESS.

The low levels in the page tree are therefore unused. By removing this
function, we are making sure no one will be tempted to map an area below
VM_MIN_KERNEL_ADDRESS in kernel mode, and particularly, we are making sure
NULL cannot be kentered.

In short, there is no way to map NULL in kernel mode anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.215 -r1.216 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/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.225 src/sys/arch/amd64/amd64/machdep.c:1.226
--- src/sys/arch/amd64/amd64/machdep.c:1.225	Wed Jul 20 13:49:17 2016
+++ src/sys/arch/amd64/amd64/machdep.c	Fri Jul 22 14:08:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.225 2016/07/20 13:49:17 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.226 2016/07/22 14:08:33 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.225 2016/07/20 13:49:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.226 2016/07/22 14:08:33 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1605,9 +1605,6 @@ init_x86_64(paddr_t first_avail)
 	 */
 	pmap_bootstrap(VM_MIN_KERNEL_ADDRESS);
 
-	if (avail_start != PAGE_SIZE)
-		pmap_prealloc_lowmem_ptps();
-
 #ifndef XEN
 	/* Internalize the physical pages into the VM system. */
 	init_x86_vm(first_avail);

Index: src/sys/arch/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.37 src/sys/arch/amd64/include/pmap.h:1.38
--- src/sys/arch/amd64/include/pmap.h:1.37	Sat May 21 07:00:18 2016
+++ src/sys/arch/amd64/include/pmap.h	Fri Jul 22 14:08:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.37 2016/05/21 07:00:18 maxv Exp $	*/
+/*	$NetBSD: pmap.h,v 1.38 2016/07/22 14:08:33 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -323,7 +323,6 @@ pmap_pte_flush(void)
 }
 #endif
 
-void pmap_prealloc_lowmem_ptps(void);
 void pmap_changeprot_local(vaddr_t, vm_prot_t);
 
 #include 

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.215 src/sys/arch/x86/x86/pmap.c:1.216
--- src/sys/arch/x86/x86/pmap.c:1.215	Fri Jul 22 13:01:43 2016
+++ src/sys/arch/x86/x86/pmap.c	Fri Jul 22 14:08:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.216 2016/07/22 14:08:33 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.216 2016/07/22 14:08:33 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1616,72 +1616,6 @@ pmap_remap_largepages(void)
 }
 #endif /* !XEN */
 
-#if defined(__x86_64__)
-/*
- * Pre-allocate PTPs for low memory, so that 1:1 mappings for various
- * trampoline code can be entered.
- */
-void
-pmap_prealloc_lowmem_ptps(void)
-{
-	int level;
-	paddr_t newp;
-	pd_entry_t *pdes;
-
-	const pd_entry_t pteflags = PG_k | PG_V | PG_RW;
-
-	pdes = pmap_kernel()->pm_pdir;
-	level = PTP_LEVELS;
-	for (;;) {
-		newp = pmap_bootstrap_palloc(1);
-
-#ifdef __HAVE_DIRECT_MAP
-		memset((void *)PMAP_DIRECT_MAP(newp), 0, PAGE_SIZE);
-#else
-		pmap_pte_set(early_zero_pte, pmap_pa2pte(newp) | pteflags |
-		pmap_pg_nx);
-		pmap_pte_flush();
-		pmap_update_pg((vaddr_t)early_zerop);
-		memset(early_zerop, 0, PAGE_SIZE);
-#endif
-
-#ifdef XEN
-		/* Mark R/O before installing */
-		HYPERVISOR_update_va_mapping ((vaddr_t)early_zerop,
-		xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
-		if (newp < (NKL2_KIMG_ENTRIES * NBPD_L2))
-			HYPERVISOR_update_va_mapping (newp + KERNBASE,
-			xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
-
-		if (level == PTP_LEVELS) { /* Top level pde is per-cpu */
-			pd_entry_t *kpm_pdir;
-			/* Reach it 

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

2016-07-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jul 22 13:01:44 UTC 2016

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

Log Message:
Simplify pmap_alloc_level. It is designed to work only with normal_pdes and
PTP_LEVELS, so don't pass them as argument. While here, explain what we are
doing.


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 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.214 src/sys/arch/x86/x86/pmap.c:1.215
--- src/sys/arch/x86/x86/pmap.c:1.214	Fri Jul 22 12:36:03 2016
+++ src/sys/arch/x86/x86/pmap.c	Fri Jul 22 13:01:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -569,7 +569,7 @@ static void pmap_remove_ptes(struct pmap
 vaddr_t, struct pv_entry **);
 
 static paddr_t pmap_get_physpage(void);
-static void pmap_alloc_level(pd_entry_t * const *, vaddr_t, int, long *);
+static void pmap_alloc_level(vaddr_t, long *);
 
 static bool pmap_reactivate(struct pmap *);
 
@@ -4299,15 +4299,15 @@ pmap_get_physpage(void)
 }
 
 /*
- * Allocate the amount of specified ptps for a ptp level, and populate
- * all levels below accordingly, mapping virtual addresses starting at
- * kva.
+ * Expand the page tree with the specified amount of PTPs, mapping virtual
+ * addresses starting at kva. We populate all the levels but the last one
+ * (L1). The nodes of the tree are created as RWX, but the pages covered
+ * will be kentered in L1, with proper permissions.
  *
- * Used by pmap_growkernel.
+ * Used only by pmap_growkernel.
  */
 static void
-pmap_alloc_level(pd_entry_t * const *pdes, vaddr_t kva, int lvl,
-long *needed_ptps)
+pmap_alloc_level(vaddr_t kva, long *needed_ptps)
 {
 	unsigned long i;
 	paddr_t pa;
@@ -4318,11 +4318,11 @@ pmap_alloc_level(pd_entry_t * const *pde
 	int s = splvm(); /* protect xpq_* */
 #endif
 
-	for (level = lvl; level > 1; level--) {
+	for (level = PTP_LEVELS; level > 1; level--) {
 		if (level == PTP_LEVELS)
 			pdep = pmap_kernel()->pm_pdir;
 		else
-			pdep = pdes[level - 2];
+			pdep = normal_pdes[level - 2];
 		index = pl_i_roundup(kva, level);
 		endindex = index + needed_ptps[level - 1] - 1;
 
@@ -4370,10 +4370,10 @@ pmap_alloc_level(pd_entry_t * const *pde
 }
 
 /*
- * pmap_growkernel: increase usage of KVM space
+ * pmap_growkernel: increase usage of KVM space.
  *
  * => we allocate new PTPs for the kernel and install them in all
- *	the pmaps on the system.
+ *the pmaps on the system.
  */
 
 vaddr_t
@@ -4413,7 +4413,7 @@ pmap_growkernel(vaddr_t maxkvaddr)
 		needed_kptp[i] = target_nptp - nkptp[i];
 	}
 
-	pmap_alloc_level(normal_pdes, pmap_maxkvaddr, PTP_LEVELS, needed_kptp);
+	pmap_alloc_level(pmap_maxkvaddr, needed_kptp);
 
 	/*
 	 * If the number of top level entries changed, update all pmaps.



CVS commit: src/sys/dev/ata

2016-07-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Jul 22 12:55:34 UTC 2016

Modified Files:
src/sys/dev/ata: wd.c

Log Message:
Space before tab and trailing whitespace fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.424 -r1.425 src/sys/dev/ata/wd.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/ata/wd.c
diff -u src/sys/dev/ata/wd.c:1.424 src/sys/dev/ata/wd.c:1.425
--- src/sys/dev/ata/wd.c:1.424	Fri Jul 22 04:08:10 2016
+++ src/sys/dev/ata/wd.c	Fri Jul 22 12:55:34 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: wd.c,v 1.424 2016/07/22 04:08:10 jakllsch Exp $ */
+/*	$NetBSD: wd.c,v 1.425 2016/07/22 12:55:34 jakllsch Exp $ */
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.  All rights reserved.
@@ -54,7 +54,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.424 2016/07/22 04:08:10 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.425 2016/07/22 12:55:34 jakllsch Exp $");
 
 #include "opt_ata.h"
 
@@ -245,7 +245,7 @@ static const struct wd_quirk {
 	  WD_QUIRK_SPLIT_MOD15_WRITE },
 	{ "ST380023AS",
 	  WD_QUIRK_SPLIT_MOD15_WRITE },
-	{ "ST360015AS",	
+	{ "ST360015AS",
 	  WD_QUIRK_SPLIT_MOD15_WRITE },
 	{ NULL,
 	  0 }
@@ -847,7 +847,7 @@ retry2:
 		 */
 		if ((bp->b_flags & B_READ) &&
 		((wd->drvp->ata_vers >= 4 && wd->sc_wdc_bio.r_error & 64) ||
-	 	 (wd->drvp->ata_vers < 4 && wd->sc_wdc_bio.r_error & 192))) {
+		 (wd->drvp->ata_vers < 4 && wd->sc_wdc_bio.r_error & 192))) {
 			struct disk_badsectors *dbs;
 
 			dbs = malloc(sizeof *dbs, M_TEMP, M_WAITOK);
@@ -1029,7 +1029,7 @@ wdopen(dev_t dev, int flag, int fmt, str
 	return error;
 }
 
-/* 
+/*
  * Caller must hold wd->sc_dk.dk_openlock.
  */
 static int
@@ -1494,7 +1494,7 @@ wdioctl(dev_t dev, u_long xfer, void *ad
 
 		return 0;
 	}
-	
+
 	case DIOCSSTRATEGY:
 	{
 		struct disk_strategy *dks = (void *)addr;
@@ -1704,7 +1704,7 @@ wddump(dev_t dev, daddr_t blkno, void *v
 		err = 0;
 		break;
 	default:
-		panic("wddump: unknown error type %d", err); 
+		panic("wddump: unknown error type %d", err);
 	}
 	if (err != 0) {
 		printf("\n");



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

2016-07-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jul 22 12:36:04 UTC 2016

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

Log Message:
Unused.


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 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.213 src/sys/arch/x86/x86/pmap.c:1.214
--- src/sys/arch/x86/x86/pmap.c:1.213	Wed Jul 20 12:33:59 2016
+++ src/sys/arch/x86/x86/pmap.c	Fri Jul 22 12:36:03 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.213 2016/07/20 12:33:59 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.213 2016/07/20 12:33:59 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.214 2016/07/22 12:36:03 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -492,10 +492,7 @@ static struct pool_cache pmap_cache;
  */
 static struct pool_cache pmap_pv_cache;
 
-#ifdef __HAVE_DIRECT_MAP
-extern phys_ram_seg_t mem_clusters[];
-extern int mem_cluster_cnt;
-#else
+#ifndef __HAVE_DIRECT_MAP
 /*
  * MULTIPROCESSOR: special VAs and PTEs are actually allocated inside a
  * (maxcpus * NPTECL) array of PTE, to avoid cache line thrashing due to



CVS commit: [pgoyette-localcount] src/sys/kern

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 22 12:03:15 UTC 2016

Modified Files:
src/sys/kern [pgoyette-localcount]: subr_autoconf.c

Log Message:
Fix logic to avoid dereferencing NULL pointer


To generate a diff of this commit:
cvs rdiff -u -r1.246.2.4 -r1.246.2.5 src/sys/kern/subr_autoconf.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/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.246.2.4 src/sys/kern/subr_autoconf.c:1.246.2.5
--- src/sys/kern/subr_autoconf.c:1.246.2.4	Fri Jul 22 02:05:39 2016
+++ src/sys/kern/subr_autoconf.c	Fri Jul 22 12:03:15 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.246.2.4 2016/07/22 02:05:39 pgoyette Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.246.2.5 2016/07/22 12:03:15 pgoyette Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.246.2.4 2016/07/22 02:05:39 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.246.2.5 2016/07/22 12:03:15 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -2273,7 +2273,7 @@ device_lookup_acquire(cfdriver_t cd, int
 		dv = NULL;
 	else if ((dv = cd->cd_devs[unit]) != NULL && dv->dv_del_gen != 0)
 		dv = NULL;
-	else
+	if (dv != NULL)
 		localcount_acquire(dv->dv_localcnt);
 	mutex_exit(_mtx);
 



CVS commit: [pgoyette-localcount] src/sys/kern

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 22 11:59:51 UTC 2016

Modified Files:
src/sys/kern [pgoyette-localcount]: subr_devsw.c

Log Message:
Style: indent label 'out:' one space from the margin.


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.9 -r1.34.2.10 src/sys/kern/subr_devsw.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/subr_devsw.c
diff -u src/sys/kern/subr_devsw.c:1.34.2.9 src/sys/kern/subr_devsw.c:1.34.2.10
--- src/sys/kern/subr_devsw.c:1.34.2.9	Thu Jul 21 06:22:31 2016
+++ src/sys/kern/subr_devsw.c	Fri Jul 22 11:59:51 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_devsw.c,v 1.34.2.9 2016/07/21 06:22:31 pgoyette Exp $	*/
+/*	$NetBSD: subr_devsw.c,v 1.34.2.10 2016/07/22 11:59:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.9 2016/07/21 06:22:31 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.10 2016/07/22 11:59:51 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -481,7 +481,7 @@ bdevsw_lookup_acquire(dev_t dev)
 	if (bdevsw[bmajor]->d_localcount != NULL)
 		localcount_acquire(bdevsw[bmajor]->d_localcount);
 
-out:	pserialize_read_exit(s);
+ out:	pserialize_read_exit(s);
 
 	return bdev;
 }
@@ -542,7 +542,7 @@ cdevsw_lookup_acquire(dev_t dev)
 	if (cdevsw[cmajor]->d_localcount != NULL)
 		localcount_acquire(cdevsw[cmajor]->d_localcount);
 
-out:	pserialize_read_exit(s);
+ out:	pserialize_read_exit(s);
 
 	return cdev;
 }



CVS commit: src/sys/net

2016-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 22 07:13:56 UTC 2016

Modified Files:
src/sys/net: if.c

Log Message:
Reduce KERNEL_LOCK thereby ifq_lock is used by default.

if_snd is always excluded by ifq_lock now. So, the KERNEL_LOCK in if_transmit()
which serializes packet output processing is not needed now.


To generate a diff of this commit:
cvs rdiff -u -r1.355 -r1.356 src/sys/net/if.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/net/if.c
diff -u src/sys/net/if.c:1.355 src/sys/net/if.c:1.356
--- src/sys/net/if.c:1.355	Fri Jul 22 07:09:40 2016
+++ src/sys/net/if.c	Fri Jul 22 07:13:56 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.355 2016/07/22 07:09:40 knakahara Exp $	*/
+/*	$NetBSD: if.c,v 1.356 2016/07/22 07:13:56 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.355 2016/07/22 07:09:40 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.356 2016/07/22 07:13:56 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2874,17 +2874,7 @@ if_transmit(struct ifnet *ifp, struct mb
 
 	s = splnet();
 
-	/*
-	 * If NET_MPSAFE is not defined , IFQ_LOCK() is nop.
-	 * use KERNEL_LOCK instead of ifq_lock.
-	 */
-#ifndef NET_MPSAFE
-	KERNEL_LOCK(1, NULL);
-#endif
 	IFQ_ENQUEUE(>if_snd, m, error);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-#endif
 	if (error != 0) {
 		/* mbuf is already freed */
 		goto out;



CVS commit: src/sys/net

2016-07-22 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Fri Jul 22 07:09:40 UTC 2016

Modified Files:
src/sys/net: if.c if.h

Log Message:
Toward NET_MPSAFE-on in future, if_snd uses if_snd->ifq_lock by default.

That can reduce confusing difference between NET_MPSAFE on and off.


To generate a diff of this commit:
cvs rdiff -u -r1.354 -r1.355 src/sys/net/if.c
cvs rdiff -u -r1.221 -r1.222 src/sys/net/if.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/net/if.c
diff -u src/sys/net/if.c:1.354 src/sys/net/if.c:1.355
--- src/sys/net/if.c:1.354	Thu Jul  7 09:32:02 2016
+++ src/sys/net/if.c	Fri Jul 22 07:09:40 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.354 2016/07/07 09:32:02 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.355 2016/07/22 07:09:40 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.354 2016/07/07 09:32:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.355 2016/07/22 07:09:40 knakahara Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -637,11 +637,7 @@ if_initialize(ifnet_t *ifp)
 	ifp->if_snd.altq_ifp  = ifp;
 #endif
 
-#ifdef NET_MPSAFE
 	ifp->if_snd.ifq_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
-#else
-	ifp->if_snd.ifq_lock = NULL;
-#endif
 
 	ifp->if_pfil = pfil_head_create(PFIL_TYPE_IFNET, ifp);
 	(void)pfil_run_hooks(if_pfil,
@@ -1160,8 +1156,7 @@ if_detach(struct ifnet *ifp)
 		altq_detach(>if_snd);
 #endif
 
-	if (ifp->if_snd.ifq_lock)
-		mutex_obj_free(ifp->if_snd.ifq_lock);
+	mutex_obj_free(ifp->if_snd.ifq_lock);
 
 #if NCARP > 0
 	/* Remove the interface from any carp group it is a part of.  */

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.221 src/sys/net/if.h:1.222
--- src/sys/net/if.h:1.221	Mon Jul 11 02:14:27 2016
+++ src/sys/net/if.h	Fri Jul 22 07:09:40 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.221 2016/07/11 02:14:27 ozaki-r Exp $	*/
+/*	$NetBSD: if.h,v 1.222 2016/07/22 07:09:40 knakahara Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -511,9 +511,6 @@ if_is_link_state_changeable(struct ifnet
 #define	IF_AFDATA_UNLOCK_ASSERT(ifp)	\
 	KASSERT(!rw_lock_held((ifp)->if_afdata_lock))
 
-#define IFQ_LOCK(_ifq)		if ((_ifq)->ifq_lock) mutex_enter((_ifq)->ifq_lock)
-#define IFQ_UNLOCK(_ifq)	if ((_ifq)->ifq_lock) mutex_exit((_ifq)->ifq_lock)
-
 /*
  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  * input routines have queues of messages stored on ifqueue structures
@@ -804,7 +801,7 @@ struct if_addrprefreq {
 #ifdef ALTQ
 #define IFQ_ENQUEUE(ifq, m, err)	\
 do {	\
-	IFQ_LOCK((ifq));		\
+	mutex_enter((ifq)->ifq_lock);	\
 	if (ALTQ_IS_ENABLED((ifq)))	\
 		ALTQ_ENQUEUE((ifq), (m), (err));			\
 	else {\
@@ -818,41 +815,41 @@ do {	\
 	}\
 	if ((err))			\
 		(ifq)->ifq_drops++;	\
-	IFQ_UNLOCK((ifq));		\
+	mutex_exit((ifq)->ifq_lock);	\
 } while (/*CONSTCOND*/ 0)
 
 #define IFQ_DEQUEUE(ifq, m)		\
 do {	\
-	IFQ_LOCK((ifq));		\
+	mutex_enter((ifq)->ifq_lock);	\
 	if (TBR_IS_ENABLED((ifq)))	\
 		(m) = tbr_dequeue((ifq), ALTDQ_REMOVE);			\
 	else if (ALTQ_IS_ENABLED((ifq)))\
 		ALTQ_DEQUEUE((ifq), (m));\
 	else\
 		IF_DEQUEUE((ifq), (m));	\
-	IFQ_UNLOCK((ifq));		\
+	mutex_exit((ifq)->ifq_lock);	\
 } while (/*CONSTCOND*/ 0)
 
 #define	IFQ_POLL(ifq, m)		\
 do {	\
-	IFQ_LOCK((ifq));		\
+	mutex_enter((ifq)->ifq_lock);	\
 	if (TBR_IS_ENABLED((ifq)))	\
 		(m) = tbr_dequeue((ifq), ALTDQ_POLL);			\
 	else if (ALTQ_IS_ENABLED((ifq)))\
 		ALTQ_POLL((ifq), (m));	\
 	else\
 		IF_POLL((ifq), (m));	\
-	IFQ_UNLOCK((ifq));		\
+	mutex_exit((ifq)->ifq_lock);	\
 } while (/*CONSTCOND*/ 0)
 
 #define	IFQ_PURGE(ifq)			\
 do {	\
-	IFQ_LOCK((ifq));		\
+	mutex_enter((ifq)->ifq_lock);	\
 	if (ALTQ_IS_ENABLED((ifq)))	\
 		ALTQ_PURGE((ifq));	\
 	else\
 		IF_PURGE((ifq));	\
-	IFQ_UNLOCK((ifq));		\
+	mutex_exit((ifq)->ifq_lock);	\
 } while (/*CONSTCOND*/ 0)
 
 #define	IFQ_SET_READY(ifq)		\
@@ -862,7 +859,7 @@ do {	\
 
 #define	IFQ_CLASSIFY(ifq, m, af)	\
 do {	\
-	IFQ_LOCK((ifq));		\
+	mutex_enter((ifq)->ifq_lock);	\
 	if (ALTQ_IS_ENABLED((ifq))) {	\
 		if (ALTQ_NEEDS_CLASSIFY((ifq)))\
 			m->m_pkthdr.pattr_class = (*(ifq)->altq_classify) \
@@ -870,12 +867,12 @@ do {	\
 		m->m_pkthdr.pattr_af = (af);\
 		m->m_pkthdr.pattr_hdr = mtod((m), void *);		\
 	}\
-	IFQ_UNLOCK((ifq));		\
+	mutex_exit((ifq)->ifq_lock);	\
 } while (/*CONSTCOND*/ 0)
 #else /* ! ALTQ */
 #define	IFQ_ENQUEUE(ifq, m, err)	\
 do {	\
-	IFQ_LOCK((ifq));		\
+	mutex_enter((ifq)->ifq_lock);	\
 	if (IF_QFULL((ifq))) {		\
 		m_freem((m));		\
 		(err) = 

CVS commit: [pgoyette-localcount] src/sys/dev

2016-07-22 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jul 22 06:32:54 UTC 2016

Modified Files:
src/sys/dev [pgoyette-localcount]: cgd.c

Log Message:
Remove debug


To generate a diff of this commit:
cvs rdiff -u -r1.108.2.8 -r1.108.2.9 src/sys/dev/cgd.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/cgd.c
diff -u src/sys/dev/cgd.c:1.108.2.8 src/sys/dev/cgd.c:1.108.2.9
--- src/sys/dev/cgd.c:1.108.2.8	Fri Jul 22 05:49:53 2016
+++ src/sys/dev/cgd.c	Fri Jul 22 06:32:54 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.108.2.8 2016/07/22 05:49:53 pgoyette Exp $ */
+/* $NetBSD: cgd.c,v 1.108.2.9 2016/07/22 06:32:54 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108.2.8 2016/07/22 05:49:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.108.2.9 2016/07/22 06:32:54 pgoyette Exp $");
 
 #include 
 #include 
@@ -194,18 +194,15 @@ getcgd_softc(dev_t dev, device_t *self)
 	int	unit = CGDUNIT(dev);
 	struct cgd_softc *sc;
 
-printf("%s: unit %d\n", __func__, unit);
 	DPRINTF_FOLLOW(("getcgd_softc(0x%"PRIx64"): unit = %d\n", dev, unit));
 
 	*self = device_lookup_acquire(_cd, unit);
-printf("%s: *self %p\n", __func__, *self);
 
-	if (*self == NULL)
+	if (*self == NULL) {
 		sc = cgd_spawn(unit, self);
-printf("%s: return sc %p\n", __func__, sc);
-	else
+	} else {
 		sc = device_private(*self);
-printf("%s: sc %p\n", __func__, sc);
+	}
 
 	return sc;
 }
@@ -281,7 +278,6 @@ cgd_spawn(int unit, device_t *self)
 }
 
 	*self = device_lookup_acquire(_cd, unit);
-printf("%s: self %p\n", __func__, *self);
 	if (self == NULL)
 		return NULL;
 	else
@@ -314,12 +310,9 @@ cgdopen(dev_t dev, int flags, int fmt, s
 	struct	cgd_softc *cs;
 
 	DPRINTF_FOLLOW(("cgdopen(0x%"PRIx64", %d)\n", dev, flags));
-printf("%s: dev %lx\n", __func__, (long unsigned int)dev);
 	GETCGD_SOFTC(cs, dev, self);
-printf("%s: cs %p, self %p\n", __func__, cs, self);
 	error = dk_open(>sc_dksc, dev, flags, fmt, l);
 	device_release(self);
-printf("%s: return %d\n", __func__, error);
 	return error;
 }
 
@@ -1143,7 +1136,6 @@ cgd_modcmd(modcmd_t cmd, void *arg)
 	devmajor_t bmajor = -1, cmajor = -1;
 #endif
 
-printf("%s: cmd %d\n", __func__, cmd);
 	switch (cmd) {
 	case MODULE_CMD_INIT:
 #ifdef _MODULE
@@ -1208,7 +1200,6 @@ printf("%s: cmd %d\n", __func__, cmd);
 		error = ENOTTY;
 		break;
 	}
-printf("%s: return %d\n", __func__, error);
 
 	return error;
 }