Commit 91bdec96 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

virtio/vhost_user: set NEEDS_RESET status bit if necessary



This protects against brute-force initialization that virtio
is not really prepared for. Most importantly, this behavior
makes us Virtio spec compliant (3.1 Device Init.).

Change-Id: I6d26f3d8b5cce488a71068777531b78538489662
Signed-off-by: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/405917


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 8ac08761
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -236,15 +236,24 @@ static void
virtio_user_set_status(struct virtio_dev *vdev, uint8_t status)
{
	struct virtio_user_dev *dev = vdev->ctx;
	int rc = 0;

	if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
		virtio_user_start_device(vdev);
	if ((dev->status & VIRTIO_CONFIG_S_NEEDS_RESET) &&
	    status != VIRTIO_CONFIG_S_RESET) {
		rc = -1;
	} else if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
		rc = virtio_user_start_device(vdev);
	} else if (status == VIRTIO_CONFIG_S_RESET &&
		   (dev->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
		virtio_user_stop_device(vdev);
		rc = virtio_user_stop_device(vdev);
	}

	if (rc != 0) {
		dev->status |= VIRTIO_CONFIG_S_NEEDS_RESET;
	} else {
		dev->status = status;
	}
}

static uint8_t
virtio_user_get_status(struct virtio_dev *vdev)