Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Jul 2019 19:54:56 +0000 (UTC)
From:      Eric van Gyzen <vangyzen@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: r349693 - stable/11/sys/dev/virtio/scsi
Message-ID:  <201907031954.x63Jsu3w080106@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Wed Jul  3 19:54:56 2019
New Revision: 349693
URL: https://svnweb.freebsd.org/changeset/base/349693

Log:
  MFC r349285
  
  VirtIO SCSI:  validate seg_max on attach
  
  Until head r349278 (stable/12 r349690), bhyve presented a seg_max
  to the guest that was too large.  Detect this case and clamp it to
  the virtqueue size.  Otherwise, we would fail the "too many segments
  to enqueue" assertion in virtqueue_enqueue().
  
  I hit this by running a guest with a MAXPHYS of 256 KB.
  
  Reviewed by:	bryanv cem
  Sponsored by:	Dell EMC Isilon
  Differential Revision:	https://reviews.freebsd.org/D20703

Modified:
  stable/11/sys/dev/virtio/scsi/virtio_scsi.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/virtio/scsi/virtio_scsi.c
==============================================================================
--- stable/11/sys/dev/virtio/scsi/virtio_scsi.c	Wed Jul  3 19:54:37 2019	(r349692)
+++ stable/11/sys/dev/virtio/scsi/virtio_scsi.c	Wed Jul  3 19:54:56 2019	(r349693)
@@ -79,6 +79,7 @@ static void	vtscsi_read_config(struct vtscsi_softc *,
 		    struct virtio_scsi_config *);
 static int	vtscsi_maximum_segments(struct vtscsi_softc *, int);
 static int	vtscsi_alloc_virtqueues(struct vtscsi_softc *);
+static void	vtscsi_check_sizes(struct vtscsi_softc *);
 static void	vtscsi_write_device_config(struct vtscsi_softc *);
 static int	vtscsi_reinit(struct vtscsi_softc *);
 
@@ -312,6 +313,8 @@ vtscsi_attach(device_t dev)
 		goto fail;
 	}
 
+	vtscsi_check_sizes(sc);
+
 	error = vtscsi_init_event_vq(sc);
 	if (error) {
 		device_printf(dev, "cannot populate the eventvq\n");
@@ -476,6 +479,26 @@ vtscsi_alloc_virtqueues(struct vtscsi_softc *sc)
 	    "%s request", device_get_nameunit(dev));
 
 	return (virtio_alloc_virtqueues(dev, 0, nvqs, vq_info));
+}
+
+static void
+vtscsi_check_sizes(struct vtscsi_softc *sc)
+{
+	int rqsize;
+
+	if ((sc->vtscsi_flags & VTSCSI_FLAG_INDIRECT) == 0) {
+		/*
+		 * Ensure the assertions in virtqueue_enqueue(),
+		 * even if the hypervisor reports a bad seg_max.
+		 */
+		rqsize = virtqueue_size(sc->vtscsi_request_vq);
+		if (sc->vtscsi_max_nsegs > rqsize) {
+			device_printf(sc->vtscsi_dev,
+			    "clamping seg_max (%d %d)\n", sc->vtscsi_max_nsegs,
+			    rqsize);
+			sc->vtscsi_max_nsegs = rqsize;
+		}
+	}
 }
 
 static void



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