Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jun 2018 03:58:02 +0000 (UTC)
From:      Marcelo Araujo <araujo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r335688 - stable/11/usr.sbin/bhyve
Message-ID:  <201806270358.w5R3w2LB073213@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: araujo
Date: Wed Jun 27 03:58:02 2018
New Revision: 335688
URL: https://svnweb.freebsd.org/changeset/base/335688

Log:
  MFC r333622, r334019, r334084
  
  r333622:
  vq_getchain() can return -1 if some descriptor(s) are invalid and prints
  a diagnostic message. So we do a sanity checking on the return value
  of vq_getchain().
  
  Spotted by:	gcc49
  Reviewed by:	avg
  Sponsored by:	iXsystems Inc.
  Differential Revision:	https://reviews.freebsd.org/D15388
  
  r334019:
  Include atkbdc header where there are declared the prototype functions
  atkbdc_event and atkbdc_init.
  
  Sponsored by:	iXsystems Inc.
  
  r334084:
  pthread_rwlock_unlock(3) returns 0 if successful, otherwise an error number
  will be returned to indicate the error, so I'm applying an assert(3) to do
  a sanity check of the return value.
  
  Reported by:	Coverity CID: 1391235, 1193654 and 1193651
  Reviewed by:	grehan
  Sponsored by:	iXsystems Inc.
  Differential Revision:	https://reviews.freebsd.org/D15533

Modified:
  stable/11/usr.sbin/bhyve/atkbdc.c
  stable/11/usr.sbin/bhyve/mem.c
  stable/11/usr.sbin/bhyve/pci_virtio_console.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/atkbdc.c
==============================================================================
--- stable/11/usr.sbin/bhyve/atkbdc.c	Wed Jun 27 03:50:11 2018	(r335687)
+++ stable/11/usr.sbin/bhyve/atkbdc.c	Wed Jun 27 03:58:02 2018	(r335688)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <pthread_np.h>
 
 #include "acpi.h"
+#include "atkbdc.h"
 #include "inout.h"
 #include "pci_emul.h"
 #include "pci_irq.h"

Modified: stable/11/usr.sbin/bhyve/mem.c
==============================================================================
--- stable/11/usr.sbin/bhyve/mem.c	Wed Jun 27 03:50:11 2018	(r335687)
+++ stable/11/usr.sbin/bhyve/mem.c	Wed Jun 27 03:58:02 2018	(r335688)
@@ -123,6 +123,7 @@ mmio_rb_add(struct mmio_rb_tree *rbt, struct mmio_rb_r
 static void
 mmio_rb_dump(struct mmio_rb_tree *rbt)
 {
+	int perror;
 	struct mmio_rb_range *np;
 
 	pthread_rwlock_rdlock(&mmio_rwlock);
@@ -130,7 +131,8 @@ mmio_rb_dump(struct mmio_rb_tree *rbt)
 		printf(" %lx:%lx, %s\n", np->mr_base, np->mr_end,
 		       np->mr_param.name);
 	}
-	pthread_rwlock_unlock(&mmio_rwlock);
+	perror = pthread_rwlock_unlock(&mmio_rwlock);
+	assert(perror == 0);
 }
 #endif
 
@@ -164,7 +166,7 @@ emulate_mem(struct vmctx *ctx, int vcpu, uint64_t padd
 
 {
 	struct mmio_rb_range *entry;
-	int err, immutable;
+	int err, perror, immutable;
 	
 	pthread_rwlock_rdlock(&mmio_rwlock);
 	/*
@@ -182,7 +184,8 @@ emulate_mem(struct vmctx *ctx, int vcpu, uint64_t padd
 			/* Update the per-vCPU cache */
 			mmio_hint[vcpu] = entry;			
 		} else if (mmio_rb_lookup(&mmio_rb_fallback, paddr, &entry)) {
-			pthread_rwlock_unlock(&mmio_rwlock);
+			perror = pthread_rwlock_unlock(&mmio_rwlock);
+			assert(perror == 0);
 			return (ESRCH);
 		}
 	}
@@ -201,15 +204,20 @@ emulate_mem(struct vmctx *ctx, int vcpu, uint64_t padd
 	 * config space window as 'immutable' the deadlock can be avoided.
 	 */
 	immutable = (entry->mr_param.flags & MEM_F_IMMUTABLE);
-	if (immutable)
-		pthread_rwlock_unlock(&mmio_rwlock);
+	if (immutable) {
+		perror = pthread_rwlock_unlock(&mmio_rwlock);
+		assert(perror == 0);
+	}
 
 	err = vmm_emulate_instruction(ctx, vcpu, paddr, vie, paging,
 				      mem_read, mem_write, &entry->mr_param);
 
-	if (!immutable)
-		pthread_rwlock_unlock(&mmio_rwlock);
+	if (!immutable) {
+		perror = pthread_rwlock_unlock(&mmio_rwlock);
+		assert(perror == 0);
+	}
 
+
 	return (err);
 }
 
@@ -217,7 +225,7 @@ static int
 register_mem_int(struct mmio_rb_tree *rbt, struct mem_range *memp)
 {
 	struct mmio_rb_range *entry, *mrp;
-	int		err;
+	int err, perror;
 
 	err = 0;
 
@@ -230,7 +238,8 @@ register_mem_int(struct mmio_rb_tree *rbt, struct mem_
 		pthread_rwlock_wrlock(&mmio_rwlock);
 		if (mmio_rb_lookup(rbt, memp->base, &entry) != 0)
 			err = mmio_rb_add(rbt, mrp);
-		pthread_rwlock_unlock(&mmio_rwlock);
+		perror = pthread_rwlock_unlock(&mmio_rwlock);
+		assert(perror == 0);
 		if (err)
 			free(mrp);
 	} else
@@ -258,7 +267,7 @@ unregister_mem(struct mem_range *memp)
 {
 	struct mem_range *mr;
 	struct mmio_rb_range *entry = NULL;
-	int err, i;
+	int err, perror, i;
 	
 	pthread_rwlock_wrlock(&mmio_rwlock);
 	err = mmio_rb_lookup(&mmio_rb_root, memp->base, &entry);
@@ -275,7 +284,8 @@ unregister_mem(struct mem_range *memp)
 				mmio_hint[i] = NULL;
 		}
 	}
-	pthread_rwlock_unlock(&mmio_rwlock);
+	perror = pthread_rwlock_unlock(&mmio_rwlock);
+	assert(perror == 0);
 
 	if (entry)
 		free(entry);

Modified: stable/11/usr.sbin/bhyve/pci_virtio_console.c
==============================================================================
--- stable/11/usr.sbin/bhyve/pci_virtio_console.c	Wed Jun 27 03:50:11 2018	(r335687)
+++ stable/11/usr.sbin/bhyve/pci_virtio_console.c	Wed Jun 27 03:58:02 2018	(r335688)
@@ -556,6 +556,7 @@ pci_vtcon_notify_tx(void *vsc, struct vqueue_info *vq)
 
 	while (vq_has_descs(vq)) {
 		n = vq_getchain(vq, &idx, iov, 1, flags);
+		assert(n >= 1);
 		if (port != NULL)
 			port->vsp_cb(port, port->vsp_arg, iov, 1);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806270358.w5R3w2LB073213>