From 9728d6b054e3e497d080b0469a70c2422e3f8914 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Fri, 30 Mar 2018 19:10:00 +0200 Subject: [PATCH] virtio: check if setting status bits succeeded This is required by the Virtio spec. (3.1 Device Init.) It will also help us with vhost-user error handling. set_status() doesn't have a way to return an error, so its internal failures were silenced until now. When we exceeded max memory region count (8) we only printed an error message without failing any SPDK initialization. This patch fixes that. It also removes not-particularly- useful comments in virtio_dev_reset(). Change-Id: Ibe0010c493ef4e12e1fdd0a1679bf706f298d97e Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/405915 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Daniel Verkamp --- lib/virtio/virtio.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/virtio/virtio.c b/lib/virtio/virtio.c index fdabfc769..fa8d8d819 100644 --- a/lib/virtio/virtio.c +++ b/lib/virtio/virtio.c @@ -304,14 +304,19 @@ virtio_dev_reset(struct virtio_dev *dev, uint64_t req_features) { req_features |= (1ULL << VIRTIO_F_VERSION_1); - /* Reset the device although not necessary at startup */ virtio_dev_stop(dev); - /* Tell the host we've noticed this device. */ virtio_dev_set_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE); + if (!(virtio_dev_get_status(dev) & VIRTIO_CONFIG_S_ACKNOWLEDGE)) { + SPDK_ERRLOG("Failed to set VIRTIO_CONFIG_S_ACKNOWLEDGE status.\n"); + return -1; + } - /* Tell the host we've known how to drive the device. */ virtio_dev_set_status(dev, VIRTIO_CONFIG_S_DRIVER); + if (!(virtio_dev_get_status(dev) & VIRTIO_CONFIG_S_DRIVER)) { + SPDK_ERRLOG("Failed to set VIRTIO_CONFIG_S_DRIVER status.\n"); + return -1; + } return virtio_negotiate_features(dev, req_features); } @@ -327,6 +332,11 @@ virtio_dev_start(struct virtio_dev *vdev, uint16_t max_queues, uint16_t fixed_qu } virtio_dev_set_status(vdev, VIRTIO_CONFIG_S_DRIVER_OK); + if (!(virtio_dev_get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK)) { + SPDK_ERRLOG("Failed to set VIRTIO_CONFIG_S_DRIVER_OK status.\n"); + return -1; + } + return 0; }