svn commit: r349693 - stable/11/sys/dev/virtio/scsi
Eric van Gyzen
vangyzen at FreeBSD.org
Wed Jul 3 19:54:57 UTC 2019
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
More information about the svn-src-all
mailing list