]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
virtio: fail adding buffer on broken queues.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 13 Mar 2014 00:53:40 +0000 (11:23 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 13 Mar 2014 00:57:57 +0000 (11:27 +1030)
Heinz points out that adding buffers to a broken virtqueue (which
should "never happen") still works.  Failing allows drivers to detect
and complain about broken devices.

Now drivers are robust, we can add this extra check.

Reported-by: Heinz Graalfs <graalfs@linux.vnet.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/virtio/virtio_ring.c

index 7ae3cba2f6247c49f810c9411a7785e514a4fc25..1e443629f76d725f7223e4d9234b0cf47e942b0e 100644 (file)
@@ -204,6 +204,11 @@ static inline int virtqueue_add(struct virtqueue *_vq,
 
        BUG_ON(data == NULL);
 
+       if (unlikely(vq->broken)) {
+               END_USE(vq);
+               return -EIO;
+       }
+
 #ifdef DEBUG
        {
                ktime_t now = ktime_get();
@@ -310,7 +315,7 @@ add_head:
  * Caller must ensure we don't call this with other virtqueue operations
  * at the same time (except where noted).
  *
- * Returns zero or a negative error (ie. ENOSPC, ENOMEM).
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
  */
 int virtqueue_add_sgs(struct virtqueue *_vq,
                      struct scatterlist *sgs[],
@@ -348,7 +353,7 @@ EXPORT_SYMBOL_GPL(virtqueue_add_sgs);
  * Caller must ensure we don't call this with other virtqueue operations
  * at the same time (except where noted).
  *
- * Returns zero or a negative error (ie. ENOSPC, ENOMEM).
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
  */
 int virtqueue_add_outbuf(struct virtqueue *vq,
                         struct scatterlist sg[], unsigned int num,
@@ -370,7 +375,7 @@ EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
  * Caller must ensure we don't call this with other virtqueue operations
  * at the same time (except where noted).
  *
- * Returns zero or a negative error (ie. ENOSPC, ENOMEM).
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
  */
 int virtqueue_add_inbuf(struct virtqueue *vq,
                        struct scatterlist sg[], unsigned int num,