CVS commit: src/sys/dev/pci/ixgbe

2019-02-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Feb 22 06:49:15 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h ixv.c

Log Message:
 Fix a bug that if_link_state_change(ifp, LINK_STATE_DOWN) isn't called unless
link goes up at least one time. Without this change, never linkup-ed media
keeps LINK_STATE_UNKNOWN instead of LINK_STATE_DOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.173 -r1.174 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.108 -r1.109 src/sys/dev/pci/ixgbe/ixv.c

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



CVS commit: src/sys/dev/pci/ixgbe

2019-02-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Feb 22 06:49:15 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h ixv.c

Log Message:
 Fix a bug that if_link_state_change(ifp, LINK_STATE_DOWN) isn't called unless
link goes up at least one time. Without this change, never linkup-ed media
keeps LINK_STATE_UNKNOWN instead of LINK_STATE_DOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.173 -r1.174 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.108 -r1.109 src/sys/dev/pci/ixgbe/ixv.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/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.51 src/sys/dev/pci/ixgbe/ix_txrx.c:1.52
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.51	Thu Dec 20 09:47:15 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Feb 22 06:49:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.51 2018/12/20 09:47:15 knakahara Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.52 2019/02/22 06:49:15 msaitoh Exp $ */
 
 /**
 
@@ -136,7 +136,7 @@ ixgbe_legacy_start_locked(struct ifnet *
 
 	IXGBE_TX_LOCK_ASSERT(txr);
 
-	if (!adapter->link_active) {
+	if (adapter->link_active != LINK_STATE_UP) {
 		/*
 		 * discard all packets buffered in IFQ to avoid
 		 * sending old packets at next link up timing.
@@ -282,7 +282,7 @@ ixgbe_mq_start_locked(struct ifnet *ifp,
 	struct mbuf*next;
 	intenqueued = 0, err = 0;
 
-	if (!txr->adapter->link_active) {
+	if (txr->adapter->link_active != LINK_STATE_UP) {
 		/*
 		 * discard all packets buffered in txr_interq to avoid
 		 * sending old packets at next link up timing.

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.173 src/sys/dev/pci/ixgbe/ixgbe.c:1.174
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.173	Wed Jan 23 09:47:52 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Feb 22 06:49:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.173 2019/01/23 09:47:52 msaitoh Exp $ */
+/* $NetBSD: ixgbe.c,v 1.174 2019/02/22 06:49:15 msaitoh Exp $ */
 
 /**
 
@@ -1628,7 +1628,7 @@ ixgbe_update_stats_counters(struct adapt
 	stats->mpctotal.ev_count += total_missed_rx;
 
 	/* Document says M[LR]FC are valid when link is up and 10Gbps */
-	if ((adapter->link_active == TRUE)
+	if ((adapter->link_active == LINK_STATE_UP)
 	&& (adapter->link_speed == IXGBE_LINK_SPEED_10GB_FULL)) {
 		stats->mlfc.ev_count += IXGBE_READ_REG(hw, IXGBE_MLFC);
 		stats->mrfc.ev_count += IXGBE_READ_REG(hw, IXGBE_MRFC);
@@ -2751,7 +2751,7 @@ ixgbe_media_status(struct ifnet *ifp, st
 	ifmr->ifm_status = IFM_AVALID;
 	ifmr->ifm_active = IFM_ETHER;
 
-	if (!adapter->link_active) {
+	if (adapter->link_active != LINK_STATE_UP) {
 		ifmr->ifm_active |= IFM_NONE;
 		IXGBE_CORE_UNLOCK(adapter);
 		return;
@@ -4759,7 +4759,7 @@ ixgbe_update_link_status(struct adapter 
 	KASSERT(mutex_owned(>core_mtx));
 
 	if (adapter->link_up) {
-		if (adapter->link_active == FALSE) {
+		if (adapter->link_active != LINK_STATE_UP) {
 			/*
 			 * To eliminate influence of the previous state
 			 * in the same way as ixgbe_init_locked().
@@ -4808,7 +4808,7 @@ ixgbe_update_link_status(struct adapter 
 device_printf(dev, "Link is up %s %s \n",
 bpsmsg, "Full Duplex");
 			}
-			adapter->link_active = TRUE;
+			adapter->link_active = LINK_STATE_UP;
 			/* Update any Flow Control changes */
 			ixgbe_fc_enable(>hw);
 			/* Update DMA coalescing config */
@@ -4818,12 +4818,17 @@ ixgbe_update_link_status(struct adapter 
 			if (adapter->feat_en & IXGBE_FEATURE_SRIOV)
 ixgbe_ping_all_vfs(adapter);
 		}
-	} else { /* Link down */
-		if (adapter->link_active == TRUE) {
+	} else {
+		/*
+		 * Do it when link active changes to DOWN. i.e.
+		 * a) LINK_STATE_UNKNOWN -> LINK_STATE_DOWN
+		 * b) LINK_STATE_UP  -> LINK_STATE_DOWN
+		 */
+		if (adapter->link_active != LINK_STATE_DOWN) {
 			if (bootverbose)
 device_printf(dev, "Link is Down\n");
 			if_link_state_change(ifp, LINK_STATE_DOWN);
-			adapter->link_active = FALSE;
+			adapter->link_active = LINK_STATE_DOWN;
 			if (adapter->feat_en & IXGBE_FEATURE_SRIOV)
 ixgbe_ping_all_vfs(adapter);
 			ixgbe_drain_all(adapter);

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.53 src/sys/dev/pci/ixgbe/ixgbe.h:1.54
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.53	Thu Dec  6 13:25:02 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Fri Feb 22 06:49:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.53 2018/12/06 13:25:02 msaitoh Exp $ */
+/* $NetBSD: ixgbe.h,v 1.54 2019/02/22 06:49:15 msaitoh Exp $ */
 
 /**
   SPDX-License-Identifier: BSD-3-Clause
@@ -492,7 

CVS commit: src/lib/librt

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:54:09 UTC 2019

Modified Files:
src/lib/librt: sem_init.3

Log Message:
Mention that ENOSPC can be returned if we exhausted the max number of
semaphores.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/librt/sem_init.3

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

Modified files:

Index: src/lib/librt/sem_init.3
diff -u src/lib/librt/sem_init.3:1.4 src/lib/librt/sem_init.3:1.5
--- src/lib/librt/sem_init.3:1.4	Fri Jul  6 21:39:59 2012
+++ src/lib/librt/sem_init.3	Thu Feb 21 16:54:09 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: sem_init.3,v 1.4 2012/07/07 01:39:59 joerg Exp $
+.\" $NetBSD: sem_init.3,v 1.5 2019/02/21 21:54:09 christos Exp $
 .\"
 .\" Copyright (C) 2000 Jason Evans .
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 7, 2012
+.Dd February 21, 2019
 .Dt SEM_INIT 3
 .Os
 .Sh NAME
@@ -73,7 +73,9 @@ will fail if:
 .Fa value
 exceeds SEM_VALUE_MAX.
 .It Bq Er ENOSPC
-Memory allocation error.
+There was memory allocation error, or the limit on available semaphores
+.Dv ( SEM_NSEMS_MAX )
+has been exceeded.
 .It Bq Er EPERM
 Unable to initialize a shared semaphore.
 .El



CVS commit: src/lib/librt

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:54:09 UTC 2019

Modified Files:
src/lib/librt: sem_init.3

Log Message:
Mention that ENOSPC can be returned if we exhausted the max number of
semaphores.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/librt/sem_init.3

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



CVS commit: src/sys/kern

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:49:23 UTC 2019

Modified Files:
src/sys/kern: uipc_sem.c

Log Message:
PR/53998: Joel Bertrand: Return ENOSPC when SEM_NSEMS_MAX is exceeded
instead of -1.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/uipc_sem.c

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



CVS commit: src/sys/kern

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:49:23 UTC 2019

Modified Files:
src/sys/kern: uipc_sem.c

Log Message:
PR/53998: Joel Bertrand: Return ENOSPC when SEM_NSEMS_MAX is exceeded
instead of -1.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/uipc_sem.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/uipc_sem.c
diff -u src/sys/kern/uipc_sem.c:1.53 src/sys/kern/uipc_sem.c:1.54
--- src/sys/kern/uipc_sem.c:1.53	Tue Feb  5 02:14:32 2019
+++ src/sys/kern/uipc_sem.c	Thu Feb 21 16:49:23 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_sem.c,v 1.53 2019/02/05 07:14:32 thorpej Exp $	*/
+/*	$NetBSD: uipc_sem.c,v 1.54 2019/02/21 21:49:23 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011, 2019 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.53 2019/02/05 07:14:32 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.54 2019/02/21 21:49:23 christos Exp $");
 
 #include 
 #include 
@@ -471,7 +471,7 @@ ksem_create(lwp_t *l, const char *name, 
 		atomic_dec_uint(>l_proc->p_nsems);
 		if (kname != NULL)
 			kmem_free(kname, len);
-		return -1;
+		return ENOSPC;
 	}
 
 	ks = kmem_zalloc(sizeof(ksem_t), KM_SLEEP);



CVS commit: src/sys/sys

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:34:05 UTC 2019

Modified Files:
src/sys/sys: cdefs.h

Log Message:
add a lint(1) comment to nothing.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/sys/cdefs.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/sys/cdefs.h
diff -u src/sys/sys/cdefs.h:1.140 src/sys/sys/cdefs.h:1.141
--- src/sys/sys/cdefs.h:1.140	Sat Jan 26 21:47:26 2019
+++ src/sys/sys/cdefs.h	Thu Feb 21 16:34:05 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.140 2019/01/27 02:47:26 christos Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.141 2019/02/21 21:34:05 christos Exp $	*/
 
 /* * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -327,7 +327,7 @@
  * We use ((void)0) instead of do {} while (0) so that it
  * works on , expressions.
  */
-#define __nothing	((void)0)
+#define __nothing	(/*LINTED*/(void)0)
 
 #if defined(__cplusplus)
 #define	__BEGIN_EXTERN_C	extern "C" {



CVS commit: src/lib/librt

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:33:34 UTC 2019

Modified Files:
src/lib/librt: sem.c

Log Message:
- KNF return
- be careful with errno, only set it when it is possibly set and not before
  a system call.
- factor out a common mask comparison.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/librt/sem.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/librt/sem.c
diff -u src/lib/librt/sem.c:1.8 src/lib/librt/sem.c:1.9
--- src/lib/librt/sem.c:1.8	Sat Feb  2 22:20:24 2019
+++ src/lib/librt/sem.c	Thu Feb 21 16:33:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sem.c,v 1.8 2019/02/03 03:20:24 thorpej Exp $	*/
+/*	$NetBSD: sem.c,v 1.9 2019/02/21 21:33:34 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2019 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: sem.c,v 1.8 2019/02/03 03:20:24 thorpej Exp $");
+__RCSID("$NetBSD: sem.c,v 1.9 2019/02/21 21:33:34 christos Exp $");
 
 #ifndef __LIBPTHREAD_SOURCE__
 /*
@@ -93,6 +93,7 @@ __RCSID("$NetBSD: sem.c,v 1.8 2019/02/03
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -104,8 +105,10 @@ __RCSID("$NetBSD: sem.c,v 1.8 2019/02/03
 #define	SEM_MAGIC		0x90af0421U
 #define	SEM_MAGIC_NAMED		(SEM_MAGIC ^ SEM_NAMED)
 
-#define	SEM_IS_KSEMID(k)	intptr_t)(k)) & KSEM_MARKER_MASK)	\
+#define	SEMID_IS_KSEMID(id)	(((uint32_t)(id) & KSEM_MARKER_MASK)	\
 		== KSEM_PSHARED_MARKER)
+#define	SEM_IS_KSEMID(k)	SEMID_IS_KSEMID((intptr_t)(k))	
+			
 
 #define	SEM_IS_UNNAMED(k)	(SEM_IS_KSEMID(k) ||			\
  (k)->ksem_magic == SEM_MAGIC)
@@ -177,16 +180,16 @@ sem_alloc(unsigned int value, intptr_t s
 	sem_t sem;
 
 	if (value > SEM_VALUE_MAX)
-		return (EINVAL);
+		return EINVAL;
 
 	if ((sem = malloc(sizeof(struct _sem_st))) == NULL)
-		return (ENOSPC);
+		return ENOSPC;
 
 	sem->ksem_magic = magic;
 	sem->ksem_semid = semid;
  
 	*semp = sem;
-	return (0);
+	return 0;
 }
 
 /* ARGSUSED */
@@ -197,7 +200,7 @@ sem_init(sem_t *sem, int pshared, unsign
 	int error;
 
 	if (_ksem_init(value, ) == -1)
-		return (-1);
+		return -1;
 
 	/*
 	 * pshared anonymous semaphores are treated a little differently.
@@ -213,22 +216,22 @@ sem_init(sem_t *sem, int pshared, unsign
 	 * non-pshared semaphores.
 	 */
 	if (pshared) {
-		if ((semid & KSEM_MARKER_MASK) != KSEM_PSHARED_MARKER) {
+		if (!SEMID_IS_KSEMID(semid)) {
 			_ksem_destroy(semid);
 			errno = ENOTSUP;
-			return (-1);
+			return -1;
 		}
 		*sem = (sem_t)semid;
-		return (0);
+		return 0;
 	}
 
 	if ((error = sem_alloc(value, semid, SEM_MAGIC, sem)) != 0) {
 		_ksem_destroy(semid);
 		errno = error;
-		return (-1);
+		return -1;
 	}
 
-	return (0);
+	return 0;
 }
 
 int
@@ -239,7 +242,7 @@ sem_destroy(sem_t *sem)
 #ifdef ERRORCHECK
 	if (sem == NULL || *sem == NULL || !SEM_MAGIC_OK(*sem)) {
 		errno = EINVAL;
-		return (-1);
+		return -1;
 	}
 #endif
 
@@ -248,13 +251,14 @@ sem_destroy(sem_t *sem)
 	} else {
 		if (SEM_IS_NAMED(*sem)) {
 			errno = EINVAL;
-			return (-1);
+			return -1;
 		}
 
 		error = _ksem_destroy((*sem)->ksem_semid);
 		save_errno = errno;
 		sem_free(*sem);
-		errno = save_errno;
+		if (error == -1)
+			errno = save_errno;
 	}
 
 	return error;
@@ -285,7 +289,7 @@ sem_open(const char *name, int oflag, ..
 	 * we'll just merge duplicate IDs into our list.
 	 */
 	if (_ksem_open(name, oflag, mode, value, ) == -1)
-		return (SEM_FAILED);
+		return SEM_FAILED;
 
 	/*
 	 * Search for a duplicate ID, we must return the same sem_t *
@@ -295,7 +299,7 @@ sem_open(const char *name, int oflag, ..
 	LIST_FOREACH(s, _sems, ksem_list) {
 		if (s->ksem_semid == semid) {
 			UNLOCK_NAMED_SEMS();
-			return (s->ksem_identity);
+			return s->ksem_identity;
 		}
 	}
 
@@ -310,7 +314,7 @@ sem_open(const char *name, int oflag, ..
 	UNLOCK_NAMED_SEMS();
 	(*sem)->ksem_identity = sem;
 
-	return (sem);
+	return sem;
 
  bad:
 	UNLOCK_NAMED_SEMS();
@@ -321,7 +325,7 @@ sem_open(const char *name, int oflag, ..
 		free(sem);
 	}
 	errno = error;
-	return (SEM_FAILED);
+	return SEM_FAILED;
 }
 
 int
@@ -332,13 +336,13 @@ sem_close(sem_t *sem)
 #ifdef ERRORCHECK
 	if (sem == NULL || *sem == NULL || !SEM_MAGIC_OK(*sem)) {
 		errno = EINVAL;
-		return (-1);
+		return -1;
 	}
 #endif
 
 	if (!SEM_IS_NAMED(*sem)) {
 		errno = EINVAL;
-		return (-1);
+		return -1;
 	}
 
 	LOCK_NAMED_SEMS();
@@ -348,7 +352,8 @@ sem_close(sem_t *sem)
 	UNLOCK_NAMED_SEMS();
 	sem_free(*sem);
 	free(sem);
-	errno = save_errno;
+	if (error == -1)
+		errno = save_errno;
 	return error;
 }
 
@@ -356,7 +361,7 @@ int
 sem_unlink(const char *name)
 {
 
-	return (_ksem_unlink(name));
+	return _ksem_unlink(name);
 }
 
 int
@@ -366,11 +371,11 @@ sem_wait(sem_t *sem)
 #ifdef ERRORCHECK
 	if (sem == NULL || *sem == NULL || !SEM_MAGIC_OK(*sem)) {
 		errno = EINVAL;
-		return (-1);
+		return -1;
 	}
 #endif
 
-	return (_ksem_wait(sem_to_semid(sem)));
+	return 

CVS commit: src/lib/librt

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:33:34 UTC 2019

Modified Files:
src/lib/librt: sem.c

Log Message:
- KNF return
- be careful with errno, only set it when it is possibly set and not before
  a system call.
- factor out a common mask comparison.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/librt/sem.c

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



CVS commit: src/sys/sys

2019-02-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Feb 21 21:34:05 UTC 2019

Modified Files:
src/sys/sys: cdefs.h

Log Message:
add a lint(1) comment to nothing.


To generate a diff of this commit:
cvs rdiff -u -r1.140 -r1.141 src/sys/sys/cdefs.h

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



CVS commit: src/sys/dev/mii

2019-02-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Feb 21 15:41:56 UTC 2019

Modified Files:
src/sys/dev/mii: rgephy.c

Log Message:
 Revision 2..5 == RTL8211B...F


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/mii/rgephy.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/mii/rgephy.c
diff -u src/sys/dev/mii/rgephy.c:1.46 src/sys/dev/mii/rgephy.c:1.47
--- src/sys/dev/mii/rgephy.c:1.46	Tue Jan 22 03:42:27 2019
+++ src/sys/dev/mii/rgephy.c	Thu Feb 21 15:41:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rgephy.c,v 1.46 2019/01/22 03:42:27 msaitoh Exp $	*/
+/*	$NetBSD: rgephy.c,v 1.47 2019/02/21 15:41:56 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2003
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.46 2019/01/22 03:42:27 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.47 2019/02/21 15:41:56 msaitoh Exp $");
 
 
 /*
@@ -125,7 +125,6 @@ rgephy_attach(device_t parent, device_t 
 	rev = MII_REV(ma->mii_id2);
 	mpd = mii_phy_match(ma, rgephys);
 	aprint_naive(": Media interface\n");
-	aprint_normal(": %s, rev. %d\n", mpd->mpd_name, rev);
 
 	sc->mii_dev = self;
 	sc->mii_inst = mii->mii_instance;
@@ -133,6 +132,15 @@ rgephy_attach(device_t parent, device_t 
 	sc->mii_mpd_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
 	sc->mii_mpd_model = MII_MODEL(ma->mii_id2);
 	sc->mii_mpd_rev = MII_REV(ma->mii_id2);
+
+	if (sc->mii_mpd_model == MII_MODEL_REALTEK_RTL8169S) {
+		aprint_normal(": RTL8211");
+		if (sc->mii_mpd_rev != 0)
+			aprint_normal("%c",'@' + sc->mii_mpd_rev);
+		aprint_normal(" 1000BASE-T media interface\n");
+	} else
+		aprint_normal(": %s, rev. %d\n", mpd->mpd_name, rev);
+
 	sc->mii_pdata = mii;
 	sc->mii_flags = ma->mii_flags;
 	sc->mii_anegticks = MII_ANEGTICKS_GIGE;



CVS commit: src/sys/dev/mii

2019-02-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Feb 21 15:41:56 UTC 2019

Modified Files:
src/sys/dev/mii: rgephy.c

Log Message:
 Revision 2..5 == RTL8211B...F


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/mii/rgephy.c

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



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

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 14:31:55 UTC 2019

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

Log Message:
Remove wrong KASSERT in EPT, and reorder the code to reduce duplication.


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 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.324 src/sys/arch/x86/x86/pmap.c:1.325
--- src/sys/arch/x86/x86/pmap.c:1.324	Mon Feb 18 19:03:12 2019
+++ src/sys/arch/x86/x86/pmap.c	Thu Feb 21 14:31:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.324 2019/02/18 19:03:12 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.325 2019/02/21 14:31:54 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.324 2019/02/18 19:03:12 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.325 2019/02/21 14:31:54 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -3643,25 +3643,25 @@ pmap_sync_pv(struct pv_pte *pvpte, paddr
 	pt_entry_t expect;
 	bool need_shootdown;
 
-	expect = pmap_pa2pte(pa) | PG_V;
 	ptp = pvpte->pte_ptp;
 	va = pvpte->pte_va;
 	KASSERT(ptp == NULL || ptp->uobject != NULL);
 	KASSERT(ptp == NULL || ptp_va2o(va, 1) == ptp->offset);
 	pmap = ptp_to_pmap(ptp);
+	KASSERT(kpreempt_disabled());
 
 	if (__predict_false(pmap->pm_sync_pv != NULL)) {
 		return (*pmap->pm_sync_pv)(ptp, va, pa, clearbits, oattrs,
 		optep);
 	}
 
+	expect = pmap_pa2pte(pa) | PG_V;
+
 	if (clearbits != ~0) {
 		KASSERT((clearbits & ~(PP_ATTRS_M|PP_ATTRS_U|PP_ATTRS_W)) == 0);
 		clearbits = pmap_pp_attrs_to_pte(clearbits);
 	}
 
-	KASSERT(kpreempt_disabled());
-
 	ptep = pmap_map_pte(pmap, ptp, va);
 	do {
 		opte = *ptep;
@@ -5487,13 +5487,8 @@ pmap_ept_sync_pv(struct vm_page *ptp, va
 	bool need_shootdown;
 
 	expect = pmap_pa2pte(pa) | EPT_R;
-	KASSERT(ptp == NULL || ptp->uobject != NULL);
-	KASSERT(ptp == NULL || ptp_va2o(va, 1) == ptp->offset);
 	pmap = ptp_to_pmap(ptp);
 
-	KASSERT(clearbits == ~0 || (clearbits & ~(EPT_D | EPT_A | EPT_W)) == 0);
-	KASSERT(kpreempt_disabled());
-
 	if (clearbits != ~0) {
 		KASSERT((clearbits & ~(PP_ATTRS_M|PP_ATTRS_U|PP_ATTRS_W)) == 0);
 		clearbits = pmap_pp_attrs_to_ept(clearbits);



CVS commit: src/doc

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 14:56:23 UTC 2019

Added Files:
src/doc: TODO.nvmm

Log Message:
Add a TODO list for NVMM, just to list some known issues.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/doc/TODO.nvmm

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



CVS commit: src/doc

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 14:56:23 UTC 2019

Added Files:
src/doc: TODO.nvmm

Log Message:
Add a TODO list for NVMM, just to list some known issues.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/doc/TODO.nvmm

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

Added files:

Index: src/doc/TODO.nvmm
diff -u /dev/null src/doc/TODO.nvmm:1.1
--- /dev/null	Thu Feb 21 14:56:23 2019
+++ src/doc/TODO.nvmm	Thu Feb 21 14:56:23 2019
@@ -0,0 +1,27 @@
+Known issues in NVMM, low priority in most cases.
+
+== KERNEL NVMM DRIVER ==
+
+ * Currently you can't modunload NVMM while a VM is running, otherwise you hit
+   a panic. See TODO in nvmm_fini().
+
+ * Maybe we will want a way to return to userland when the guest TPR changes.
+   On Intel that's not complicated, but on old AMD CPUs, we need to disassemble
+   the instruction, and I don't like that.
+
+ * Maybe we shouldn't modify the INT/NMI windows during event injection. The
+   virtualizer is supposed to inject the event only when these windows allow
+   it. (Eg Qemu does.)
+
+ * We need a cleaner way to handle CPUID exits. It is not complicated to solve,
+   but I'm still not sure which design is the cleanest.
+
+ * Same for the MSRs.
+
+== LIBNVMM ==
+
+ * There are still a few twisted corner cases we don't handle in the instruction
+   emulator. For example if the guest makes an MMIO access relative to RSP, we
+   must base the GVA on %SS and not %DS. This is tiring, and in practice, no
+   guest is dumb enough to perform such accesses.
+



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

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 14:31:55 UTC 2019

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

Log Message:
Remove wrong KASSERT in EPT, and reorder the code to reduce duplication.


To generate a diff of this commit:
cvs rdiff -u -r1.324 -r1.325 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.



CVS commit: src/sys/dev/nvmm/x86

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 13:25:44 UTC 2019

Modified Files:
src/sys/dev/nvmm/x86: nvmm_x86_vmx.c

Log Message:
Reorder the detection in vmx_ident(), to fix panic on old CPUs. We must
read MSR_IA32_VMX_EPT_VPID_CAP _after_ ensuring EPT is there, because if
it's not, the rdmsr faults.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c

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



CVS commit: src/sys/dev/nvmm/x86

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 13:25:44 UTC 2019

Modified Files:
src/sys/dev/nvmm/x86: nvmm_x86_vmx.c

Log Message:
Reorder the detection in vmx_ident(), to fix panic on old CPUs. We must
read MSR_IA32_VMX_EPT_VPID_CAP _after_ ensuring EPT is there, because if
it's not, the rdmsr faults.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/nvmm/x86/nvmm_x86_vmx.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/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.9 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.10
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.9	Thu Feb 21 12:17:52 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c	Thu Feb 21 13:25:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_vmx.c,v 1.9 2019/02/21 12:17:52 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86_vmx.c,v 1.10 2019/02/21 13:25:44 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.9 2019/02/21 12:17:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.10 2019/02/21 13:25:44 maxv Exp $");
 
 #include 
 #include 
@@ -2655,23 +2655,6 @@ vmx_ident(void)
 		return false;
 	}
 
-	msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
-	if ((msr & IA32_VMX_EPT_VPID_WALKLENGTH_4) == 0) {
-		return false;
-	}
-	if ((msr & IA32_VMX_EPT_VPID_INVEPT) == 0) {
-		return false;
-	}
-	if ((msr & IA32_VMX_EPT_VPID_INVVPID) == 0) {
-		return false;
-	}
-	if ((msr & IA32_VMX_EPT_VPID_FLAGS_AD) == 0) {
-		return false;
-	}
-	if (!(msr & IA32_VMX_EPT_VPID_UC) && !(msr & IA32_VMX_EPT_VPID_WB)) {
-		return false;
-	}
-
 	/* PG and PE are reported, even if Unrestricted Guests is supported. */
 	vmx_cr0_fixed0 = rdmsr(MSR_IA32_VMX_CR0_FIXED0) & ~(CR0_PG|CR0_PE);
 	vmx_cr0_fixed1 = rdmsr(MSR_IA32_VMX_CR0_FIXED1) | (CR0_PG|CR0_PE);
@@ -2724,6 +2707,23 @@ vmx_ident(void)
 		return false;
 	}
 
+	msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
+	if ((msr & IA32_VMX_EPT_VPID_WALKLENGTH_4) == 0) {
+		return false;
+	}
+	if ((msr & IA32_VMX_EPT_VPID_INVEPT) == 0) {
+		return false;
+	}
+	if ((msr & IA32_VMX_EPT_VPID_INVVPID) == 0) {
+		return false;
+	}
+	if ((msr & IA32_VMX_EPT_VPID_FLAGS_AD) == 0) {
+		return false;
+	}
+	if (!(msr & IA32_VMX_EPT_VPID_UC) && !(msr & IA32_VMX_EPT_VPID_WB)) {
+		return false;
+	}
+
 	return true;
 }
 



CVS commit: src/sys

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 12:17:52 UTC 2019

Modified Files:
src/sys/arch/x86/x86: x86_tlb.c
src/sys/dev/nvmm/x86: nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Another locking issue in NVMM: the {svm,vmx}_tlb_flush functions take VCPU
mutexes which can sleep, but their context does not allow it.

Rewrite the TLB handling code to fix that. It becomes a bit complex. In
short, we use a per-VM generation number, which we increase on each TLB
flush, before sending a broadcast IPI to everybody. The IPIs cause a
#VMEXIT of each VCPU, and each VCPU Loop will synchronize the per-VM gen
with a per-VCPU copy, and apply the flushes as neededi lazily.

The behavior differs between AMD and Intel; in short, on Intel we don't
flush the hTLB (EPT cache) if a context switch of a VCPU occurs, so now,
we need to maintain a kcpuset to know which VCPU's hTLBs are active on
which hCPU. This creates some redundancy on Intel, ie there are cases
where we flush the hTLB several times unnecessarily; but hTLB flushes are
very rare, so there is no real performance regression.

The thing is lock-less and non-blocking, so it solves our problem.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/x86_tlb.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/nvmm/x86/nvmm_x86_vmx.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/x86_tlb.c
diff -u src/sys/arch/x86/x86/x86_tlb.c:1.5 src/sys/arch/x86/x86/x86_tlb.c:1.6
--- src/sys/arch/x86/x86/x86_tlb.c:1.5	Mon Feb 11 14:59:33 2019
+++ src/sys/arch/x86/x86/x86_tlb.c	Thu Feb 21 12:17:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_tlb.c,v 1.5 2019/02/11 14:59:33 cherry Exp $	*/
+/*	$NetBSD: x86_tlb.c,v 1.6 2019/02/21 12:17:52 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008-2012 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 1.5 2019/02/11 14:59:33 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_tlb.c,v 1.6 2019/02/21 12:17:52 maxv Exp $");
 
 #include 
 #include 
@@ -229,6 +229,7 @@ pmap_tlb_shootdown(struct pmap *pm, vadd
 
 	if (__predict_false(pm->pm_tlb_flush != NULL)) {
 		(*pm->pm_tlb_flush)(pm);
+		return;
 	}
 
 	/*

Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.28 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.29
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.28	Thu Feb 21 11:58:04 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Thu Feb 21 12:17:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.28 2019/02/21 11:58:04 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86_svm.c,v 1.29 2019/02/21 12:17:52 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.28 2019/02/21 11:58:04 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.29 2019/02/21 12:17:52 maxv Exp $");
 
 #include 
 #include 
@@ -493,6 +493,7 @@ static uint64_t svm_xcr0_mask __read_mos
 struct svm_machdata {
 	bool cpuidpresent[SVM_NCPUIDS];
 	struct nvmm_x86_conf_cpuid cpuid[SVM_NCPUIDS];
+	volatile uint64_t mach_htlb_gen;
 };
 
 static const size_t svm_conf_sizes[NVMM_X86_NCONF] = {
@@ -503,6 +504,7 @@ struct svm_cpudata {
 	/* General */
 	bool shared_asid;
 	bool gtlb_want_flush;
+	uint64_t vcpu_htlb_gen;
 
 	/* VMCB */
 	struct vmcb *vmcb;
@@ -1101,6 +1103,8 @@ error:
 	svm_inject_gp(mach, vcpu);
 }
 
+/* -- */
+
 static void
 svm_vcpu_guest_fpu_enter(struct nvmm_cpu *vcpu)
 {
@@ -1197,18 +1201,57 @@ svm_gtlb_catchup(struct nvmm_cpu *vcpu, 
 	}
 }
 
+static inline void
+svm_htlb_catchup(struct nvmm_cpu *vcpu, int hcpu)
+{
+	/*
+	 * Nothing to do. If an hTLB flush was needed, either the VCPU was
+	 * executing on this hCPU and the hTLB already got flushed, or it
+	 * was executing on another hCPU in which case the catchup is done
+	 * in svm_gtlb_catchup().
+	 */
+}
+
+static inline uint64_t
+svm_htlb_flush(struct svm_machdata *machdata, struct svm_cpudata *cpudata)
+{
+	struct vmcb *vmcb = cpudata->vmcb;
+	uint64_t machgen;
+
+	machgen = machdata->mach_htlb_gen;
+	if (__predict_true(machgen == cpudata->vcpu_htlb_gen)) {
+		return machgen;
+	}
+
+	vmcb->ctrl.tlb_ctrl = svm_ctrl_tlb_flush;
+	return machgen;
+}
+
+static inline void
+svm_htlb_flush_ack(struct svm_cpudata *cpudata, uint64_t machgen)
+{
+	struct vmcb *vmcb = cpudata->vmcb;
+
+	if (__predict_true(vmcb->ctrl.exitcode != VMCB_EXITCODE_INVALID)) {
+		cpudata->vcpu_htlb_gen = machgen;
+	}
+}
+
 static int
 svm_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu,
 struct nvmm_exit *exit)
 {
+	struct svm_machdata *machdata = mach->machdata;
 	struct svm_cpudata *cpudata = vcpu->cpudata;
 	struct vmcb *vmcb = cpudata->vmcb;
+	uint64_t machgen;
 	int hcpu, s;
 
 	

CVS commit: src/sys

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 12:17:52 UTC 2019

Modified Files:
src/sys/arch/x86/x86: x86_tlb.c
src/sys/dev/nvmm/x86: nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Another locking issue in NVMM: the {svm,vmx}_tlb_flush functions take VCPU
mutexes which can sleep, but their context does not allow it.

Rewrite the TLB handling code to fix that. It becomes a bit complex. In
short, we use a per-VM generation number, which we increase on each TLB
flush, before sending a broadcast IPI to everybody. The IPIs cause a
#VMEXIT of each VCPU, and each VCPU Loop will synchronize the per-VM gen
with a per-VCPU copy, and apply the flushes as neededi lazily.

The behavior differs between AMD and Intel; in short, on Intel we don't
flush the hTLB (EPT cache) if a context switch of a VCPU occurs, so now,
we need to maintain a kcpuset to know which VCPU's hTLBs are active on
which hCPU. This creates some redundancy on Intel, ie there are cases
where we flush the hTLB several times unnecessarily; but hTLB flushes are
very rare, so there is no real performance regression.

The thing is lock-less and non-blocking, so it solves our problem.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/x86_tlb.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c

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



CVS commit: src/sys/dev/nvmm/x86

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 11:58:04 UTC 2019

Modified Files:
src/sys/dev/nvmm/x86: nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Clarify the gTLB code a little.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nvmm/x86/nvmm_x86_vmx.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/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.27 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.28
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.27	Mon Feb 18 12:17:45 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c	Thu Feb 21 11:58:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_svm.c,v 1.27 2019/02/18 12:17:45 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86_svm.c,v 1.28 2019/02/21 11:58:04 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.27 2019/02/18 12:17:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.28 2019/02/21 11:58:04 maxv Exp $");
 
 #include 
 #include 
@@ -502,7 +502,7 @@ static const size_t svm_conf_sizes[NVMM_
 struct svm_cpudata {
 	/* General */
 	bool shared_asid;
-	bool tlb_want_flush;
+	bool gtlb_want_flush;
 
 	/* VMCB */
 	struct vmcb *vmcb;
@@ -977,7 +977,7 @@ svm_inkernel_handle_msr(struct nvmm_mach
 			}
 			if ((vmcb->state.efer ^ exit->u.msr.val) &
 			 EFER_TLB_FLUSH) {
-cpudata->tlb_want_flush = true;
+cpudata->gtlb_want_flush = true;
 			}
 			vmcb->state.efer = exit->u.msr.val | EFER_SVME;
 			svm_vmcb_cache_flush(vmcb, VMCB_CTRL_VMCB_CLEAN_CR);
@@ -1185,21 +1185,30 @@ svm_vcpu_guest_misc_leave(struct nvmm_cp
 	wrmsr(MSR_KERNELGSBASE, cpudata->kernelgsbase);
 }
 
+/* -- */
+
+static inline void
+svm_gtlb_catchup(struct nvmm_cpu *vcpu, int hcpu)
+{
+	struct svm_cpudata *cpudata = vcpu->cpudata;
+
+	if (vcpu->hcpu_last != hcpu || cpudata->shared_asid) {
+		cpudata->gtlb_want_flush = true;
+	}
+}
+
 static int
 svm_vcpu_run(struct nvmm_machine *mach, struct nvmm_cpu *vcpu,
 struct nvmm_exit *exit)
 {
 	struct svm_cpudata *cpudata = vcpu->cpudata;
 	struct vmcb *vmcb = cpudata->vmcb;
-	bool tlb_need_flush = false;
 	int hcpu, s;
 
 	kpreempt_disable();
 	hcpu = cpu_number();
 
-	if (vcpu->hcpu_last != hcpu || cpudata->shared_asid) {
-		tlb_need_flush = true;
-	}
+	svm_gtlb_catchup(vcpu, hcpu);
 
 	if (vcpu->hcpu_last != hcpu) {
 		vmcb->ctrl.tsc_offset = cpudata->tsc_offset +
@@ -1211,7 +1220,7 @@ svm_vcpu_run(struct nvmm_machine *mach, 
 	svm_vcpu_guest_misc_enter(vcpu);
 
 	while (1) {
-		if (cpudata->tlb_want_flush || tlb_need_flush) {
+		if (cpudata->gtlb_want_flush) {
 			vmcb->ctrl.tlb_ctrl = svm_ctrl_tlb_flush;
 		} else {
 			vmcb->ctrl.tlb_ctrl = 0;
@@ -1226,8 +1235,7 @@ svm_vcpu_run(struct nvmm_machine *mach, 
 		svm_vmcb_cache_default(vmcb);
 
 		if (vmcb->ctrl.exitcode != VMCB_EXITCODE_INVALID) {
-			cpudata->tlb_want_flush = false;
-			tlb_need_flush = false;
+			cpudata->gtlb_want_flush = false;
 			vcpu->hcpu_last = hcpu;
 		}
 
@@ -1751,7 +1759,7 @@ svm_vcpu_setstate(struct nvmm_cpu *vcpu,
 	struct fxsave *fpustate;
 
 	if (svm_state_tlb_flush(vmcb, state, flags)) {
-		cpudata->tlb_want_flush = true;
+		cpudata->gtlb_want_flush = true;
 	}
 
 	if (flags & NVMM_X64_STATE_SEGS) {
@@ -1985,7 +1993,7 @@ svm_tlb_flush(struct pmap *pm)
 		if (error)
 			continue;
 		cpudata = vcpu->cpudata;
-		cpudata->tlb_want_flush = true;
+		cpudata->gtlb_want_flush = true;
 		nvmm_vcpu_put(vcpu);
 	}
 }

Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.7 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.8
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.7	Mon Feb 18 12:17:45 2019
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c	Thu Feb 21 11:58:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm_x86_vmx.c,v 1.7 2019/02/18 12:17:45 maxv Exp $	*/
+/*	$NetBSD: nvmm_x86_vmx.c,v 1.8 2019/02/21 11:58:04 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.7 2019/02/18 12:17:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.8 2019/02/21 11:58:04 maxv Exp $");
 
 #include 
 #include 
@@ -637,7 +637,7 @@ static const size_t vmx_conf_sizes[NVMM_
 struct vmx_cpudata {
 	/* General */
 	uint64_t asid;
-	bool tlb_want_flush;
+	bool gtlb_want_flush;
 
 	/* VMCS */
 	struct vmcs *vmcs;
@@ -1601,6 +1601,8 @@ vmx_vcpu_guest_misc_leave(struct nvmm_cp
 	wrmsr(MSR_KERNELGSBASE, cpudata->kernelgsbase);
 }
 
+/* - */
+
 #define VMX_INVVPID_ADDRESS		0
 #define VMX_INVVPID_CONTEXT		1
 #define VMX_INVVPID_ALL			2
@@ -1609,13 +1611,22 @@ vmx_vcpu_guest_misc_leave(struct nvmm_cp
 #define VMX_INVEPT_CONTEXT		1
 

CVS commit: src/sys/dev/nvmm/x86

2019-02-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb 21 11:58:04 UTC 2019

Modified Files:
src/sys/dev/nvmm/x86: nvmm_x86_svm.c nvmm_x86_vmx.c

Log Message:
Clarify the gTLB code a little.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c

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



CVS commit: src/sys/kern

2019-02-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Feb 21 08:52:53 UTC 2019

Modified Files:
src/sys/kern: vfs_trans.c

Log Message:
Fix bad assertion: vfs_suspend(dead_rootmount) may happen and
must return EOPNOTSUPP.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/kern/vfs_trans.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/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.54 src/sys/kern/vfs_trans.c:1.55
--- src/sys/kern/vfs_trans.c:1.54	Wed Feb 20 10:09:45 2019
+++ src/sys/kern/vfs_trans.c	Thu Feb 21 08:52:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $	*/
+/*	$NetBSD: vfs_trans.c,v 1.55 2019/02/21 08:52:53 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.55 2019/02/21 08:52:53 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -677,7 +677,8 @@ vfs_suspend(struct mount *mp, int nowait
 	struct fstrans_lwp_info *fli;
 	int error;
 
-	KASSERT(mp != dead_rootmount);
+	if (mp == dead_rootmount)
+		return EOPNOTSUPP;
 
 	fli = fstrans_get_lwp_info(mp, true);
 	mp = fli->fli_mount;



CVS commit: src/sys/kern

2019-02-21 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Thu Feb 21 08:52:53 UTC 2019

Modified Files:
src/sys/kern: vfs_trans.c

Log Message:
Fix bad assertion: vfs_suspend(dead_rootmount) may happen and
must return EOPNOTSUPP.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/kern/vfs_trans.c

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



CVS commit: src/sys/compat/sys

2019-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Feb 21 08:25:00 UTC 2019

Modified Files:
src/sys/compat/sys: ipc.h

Log Message:
include libkern.h or strings.h.  should fix i386 build issues.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/compat/sys/ipc.h

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



CVS commit: src/sys/compat/sys

2019-02-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Feb 21 08:25:00 UTC 2019

Modified Files:
src/sys/compat/sys: ipc.h

Log Message:
include libkern.h or strings.h.  should fix i386 build issues.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/compat/sys/ipc.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/compat/sys/ipc.h
diff -u src/sys/compat/sys/ipc.h:1.6 src/sys/compat/sys/ipc.h:1.7
--- src/sys/compat/sys/ipc.h:1.6	Thu Feb 21 03:37:19 2019
+++ src/sys/compat/sys/ipc.h	Thu Feb 21 08:25:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipc.h,v 1.6 2019/02/21 03:37:19 mrg Exp $	*/
+/*	$NetBSD: ipc.h,v 1.7 2019/02/21 08:25:00 mrg Exp $	*/
 
 /*
  * Copyright (c) 1990, 1993
@@ -47,6 +47,12 @@
 #ifndef _COMPAT_SYS_IPC_H_
 #define _COMPAT_SYS_IPC_H_
 
+#ifdef _KERNEL
+#include 
+#else
+#include 
+#endif
+
 __BEGIN_DECLS
 /*
  * Old IPC permission structure used before NetBSD 1.5.



CVS commit: src/sys/dev/pci

2019-02-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Feb 21 08:10:22 UTC 2019

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix panic when wm(4) is reattached. ok by msaitoh@n.o.

This panic occured after kern_rndq.c:r1.90.


To generate a diff of this commit:
cvs rdiff -u -r1.626 -r1.627 src/sys/dev/pci/if_wm.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/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.626 src/sys/dev/pci/if_wm.c:1.627
--- src/sys/dev/pci/if_wm.c:1.626	Fri Feb  8 06:33:04 2019
+++ src/sys/dev/pci/if_wm.c	Thu Feb 21 08:10:22 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.626 2019/02/08 06:33:04 msaitoh Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.627 2019/02/21 08:10:22 knakahara Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.626 2019/02/08 06:33:04 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.627 2019/02/21 08:10:22 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -2995,6 +2995,8 @@ wm_detach(device_t self, int flags __unu
 	evcnt_detach(>sc_ev_rx_macctl);
 #endif /* WM_EVENT_COUNTERS */
 
+	rnd_detach_source(>rnd_source);
+
 	/* Tell the firmware about the release */
 	WM_CORE_LOCK(sc);
 	wm_release_manageability(sc);



CVS commit: src/sys/dev/pci

2019-02-21 Thread Kengo NAKAHARA
Module Name:src
Committed By:   knakahara
Date:   Thu Feb 21 08:10:22 UTC 2019

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
Fix panic when wm(4) is reattached. ok by msaitoh@n.o.

This panic occured after kern_rndq.c:r1.90.


To generate a diff of this commit:
cvs rdiff -u -r1.626 -r1.627 src/sys/dev/pci/if_wm.c

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