Skip to contentSkip to conversation

minor virtio 1.0 fixups

PATCH In review Michael S. Tsirkin 2 participants 5 messages Dec 11, 2014 virtio core

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover minor virtio 1.0 fixups

Here are some fixup patches on top of my latest pull request. Will include in the next pull request.

Michael S. Tsirkin (3):
virtio: set VIRTIO_CONFIG_S_FEATURES_OK on restore
virtio_config: fix virtio_cread_bytes virtio_pci_common.h: drop VIRTIO_PCI_NO_LEGACY

 drivers/virtio/virtio_pci_common.h |  1 -
 include/linux/virtio_config.h      |  5 ++++-
 drivers/virtio/virtio.c            | 37 +++++++++++++++++++++++--------------
 3 files changed, 27 insertions(+), 16 deletions(-)
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH 1/3 virtio: set VIRTIO_CONFIG_S_FEATURES_OK on restore

virtio 1.0 devices require that drivers set VIRTIO_CONFIG_S_FEATURES_OK after finalizing features.
virtio core missed doing this on restore, fix it up.

---
 drivers/virtio/virtio.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
drivers/virtio/virtio.c +23 -14
index f226658..b9f70df 100644
@@ -162,6 +162,27 @@ static void virtio_config_enable(struct virtio_device *dev)
 	spin_unlock_irq(&dev->config_lock);
 }
 
+static int virtio_finalize_features(struct virtio_device *dev)
+{
+	int ret = dev->config->finalize_features(dev);
+	unsigned status;
+
+	if (ret)
+		return ret;
+
+	if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
+		return 0;
+
+	add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
+	status = dev->config->get_status(dev);
+	if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
+		dev_err(&dev->dev, "virtio: device refuses features: %x\n",
+			status);
+		return -ENODEV;
+	}
+	return 0;
+}
+
 static int virtio_dev_probe(struct device *_d)
 {
 	int err, i;
@@ -170,7 +191,6 @@ static int virtio_dev_probe(struct device *_d)
 	u64 device_features;
 	u64 driver_features;
 	u64 driver_features_legacy;
-	unsigned status;
 
 	/* We have a driver! */
 	add_status(dev, VIRTIO_CONFIG_S_DRIVER);
@@ -208,21 +228,10 @@ static int virtio_dev_probe(struct device *_d)
 		if (device_features & (1ULL << i))
 			__virtio_set_bit(dev, i);
 
-	err = dev->config->finalize_features(dev);
+	err = virtio_finalize_features(dev);
 	if (err)
 		goto err;
 
-	if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
-		add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
-		status = dev->config->get_status(dev);
-		if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
-			dev_err(_d, "virtio: device refuses features: %x\n",
-			       status);
-			err = -ENODEV;
-			goto err;
-		}
-	}
-
 	err = drv->probe(dev);
 	if (err)
 		goto err;
@@ -372,7 +381,7 @@ int virtio_device_restore(struct virtio_device *dev)
 	/* We have a driver! */
 	add_status(dev, VIRTIO_CONFIG_S_DRIVER);
 
-	ret = dev->config->finalize_features(dev);
+	ret = virtio_finalize_features(dev);
 	if (ret)
 		goto err;
 
Signature · 1 line
MST
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] virtio: set VIRTIO_CONFIG_S_FEATURES_OK on restore

Quoted 8 lines · On Thu, 11 Dec 2014 19:01:31 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

virtio 1.0 devices require that drivers set VIRTIO_CONFIG_S_FEATURES_OK after finalizing features.
virtio core missed doing this on restore, fix it up.

---
 drivers/virtio/virtio.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
author maintainer
#3 lore raw

PATCH 2/3 virtio_config: fix virtio_cread_bytes

In reply to Michael S. Tsirkin

virtio_cread_bytes is implemented incorrectly in case length happens to be 2,4 or 8 bytes: transports and devices will assume it's an integer value that has to be converted to LE format.

Let's just do multiple 1-byte reads: this also makes life easier for transports who only need to implement 1,2,4 and 8 byte reads.

---
 include/linux/virtio_config.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/virtio_config.h +4 -1
index 7979f85..a61cd37 100644
@@ -305,7 +305,10 @@ static inline void virtio_cread_bytes(struct virtio_device *vdev,
 				      unsigned int offset,
 				      void *buf, size_t len)
 {
-	vdev->config->get(vdev, offset, buf, len);
+	int i;
+
+	for (i = 0; i < len; i++)
+		vdev->config->get(vdev, offset + i, buf + i, 1);
 }
 
 static inline void virtio_cwrite8(struct virtio_device *vdev,
Signature · 1 line
MST
author maintainer
#4 lore raw

PATCH 3/3 virtio_pci_common.h: drop VIRTIO_PCI_NO_LEGACY

In reply to Michael S. Tsirkin

Legacy drivers use virtio_pci_common.h too, we should not define VIRTIO_PCI_NO_LEGACY there.

---
 drivers/virtio/virtio_pci_common.h | 1 -
 1 file changed, 1 deletion(-)
drivers/virtio/virtio_pci_common.h +0 -1
index d840dad..38d99ad 100644
@@ -27,7 +27,6 @@
 #include <linux/virtio.h>
 #include <linux/virtio_config.h>
 #include <linux/virtio_ring.h>
-#define VIRTIO_PCI_NO_LEGACY
 #include <linux/virtio_pci.h>
 #include <linux/highmem.h>
 #include <linux/spinlock.h>
Signature · 1 line
MST