]> Pileus Git - ~andy/linux/commitdiff
virtio_ring: change host notification API
authorHeinz Graalfs <graalfs@linux.vnet.ibm.com>
Mon, 28 Oct 2013 23:08:50 +0000 (09:38 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 29 Oct 2013 00:58:11 +0000 (11:28 +1030)
Currently a host kick error is silently ignored and not reflected in
the virtqueue of a particular virtio device.

Changing the notify API for guest->host notification seems to be one
prerequisite in order to be able to handle such errors in the context
where the kick is triggered.

This patch changes the notify API. The notify function must return a
bool return value. It returns false if the host notification failed.

Signed-off-by: Heinz Graalfs <graalfs@linux.vnet.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/lguest/lguest_device.c
drivers/remoteproc/remoteproc_virtio.c
drivers/s390/kvm/kvm_virtio.c
drivers/s390/kvm/virtio_ccw.c
drivers/virtio/virtio_mmio.c
drivers/virtio/virtio_pci.c
drivers/virtio/virtio_ring.c
include/linux/virtio_ring.h
tools/virtio/virtio_test.c
tools/virtio/vringh_test.c

index b3256ff0d426a2598c6e17c9e3d38cbb7e7b6036..d0a1d8a45c815e347e249beaff4855455e1e708c 100644 (file)
@@ -229,7 +229,7 @@ struct lguest_vq_info {
  * make a hypercall.  We hand the physical address of the virtqueue so the Host
  * knows which virtqueue we're talking about.
  */
-static void lg_notify(struct virtqueue *vq)
+static bool lg_notify(struct virtqueue *vq)
 {
        /*
         * We store our virtqueue information in the "priv" pointer of the
@@ -238,6 +238,7 @@ static void lg_notify(struct virtqueue *vq)
        struct lguest_vq_info *lvq = vq->priv;
 
        hcall(LHCALL_NOTIFY, lvq->config.pfn << PAGE_SHIFT, 0, 0, 0);
+       return true;
 }
 
 /* An extern declaration inside a C file is bad form.  Don't do it. */
index b09c75c21b609c51569e4088d8aba51769bec8a4..a34b50690b4efd28a3616d98f304185b723233b8 100644 (file)
@@ -30,7 +30,7 @@
 #include "remoteproc_internal.h"
 
 /* kick the remote processor, and let it know which virtqueue to poke at */
-static void rproc_virtio_notify(struct virtqueue *vq)
+static bool rproc_virtio_notify(struct virtqueue *vq)
 {
        struct rproc_vring *rvring = vq->priv;
        struct rproc *rproc = rvring->rvdev->rproc;
@@ -39,6 +39,7 @@ static void rproc_virtio_notify(struct virtqueue *vq)
        dev_dbg(&rproc->dev, "kicking vq index: %d\n", notifyid);
 
        rproc->ops->kick(rproc, notifyid);
+       return true;
 }
 
 /**
index af2166fa515953ff8beaf57226182095c67f9654..1abd0db29915bf69b8618b7c267dad552573a74d 100644 (file)
@@ -166,11 +166,15 @@ static void kvm_reset(struct virtio_device *vdev)
  * make a hypercall.  We hand the address  of the virtqueue so the Host
  * knows which virtqueue we're talking about.
  */
-static void kvm_notify(struct virtqueue *vq)
+static bool kvm_notify(struct virtqueue *vq)
 {
+       long rc;
        struct kvm_vqconfig *config = vq->priv;
 
-       kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, config->address);
+       rc = kvm_hypercall1(KVM_S390_VIRTIO_NOTIFY, config->address);
+       if (rc < 0)
+               return false;
+       return true;
 }
 
 /*
index 779dc5136291610f28361b7386151cc1bb4b9372..d6297176ab85b8b306eb69be685dfba811ae35ba 100644 (file)
@@ -162,7 +162,7 @@ static inline long do_kvm_notify(struct subchannel_id schid,
        return __rc;
 }
 
-static void virtio_ccw_kvm_notify(struct virtqueue *vq)
+static bool virtio_ccw_kvm_notify(struct virtqueue *vq)
 {
        struct virtio_ccw_vq_info *info = vq->priv;
        struct virtio_ccw_device *vcdev;
@@ -171,6 +171,9 @@ static void virtio_ccw_kvm_notify(struct virtqueue *vq)
        vcdev = to_vc_device(info->vq->vdev);
        ccw_device_get_schid(vcdev->cdev, &schid);
        info->cookie = do_kvm_notify(schid, vq->index, info->cookie);
+       if (info->cookie < 0)
+               return false;
+       return true;
 }
 
 static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev,
index 1ba0d683101525b1615cc03beea3524f42318694..e9fdeb8619922303bbedff5747c563b5cd16423b 100644 (file)
@@ -219,13 +219,14 @@ static void vm_reset(struct virtio_device *vdev)
 /* Transport interface */
 
 /* the notify function used when creating a virt queue */
-static void vm_notify(struct virtqueue *vq)
+static bool vm_notify(struct virtqueue *vq)
 {
        struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
 
        /* We write the queue's selector into the notification register to
         * signal the other end */
        writel(vq->index, vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY);
+       return true;
 }
 
 /* Notify all virtqueues on an interrupt. */
index 98917fc872a429a1ab3aee94cd7d499bc1dafa25..a37c69941d30920649f6f25726ce72b038b752fd 100644 (file)
@@ -197,13 +197,14 @@ static void vp_reset(struct virtio_device *vdev)
 }
 
 /* the notify function used when creating a virt queue */
-static void vp_notify(struct virtqueue *vq)
+static bool vp_notify(struct virtqueue *vq)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
 
        /* we write the queue's selector into the notification register to
         * signal the other end */
        iowrite16(vq->index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
+       return true;
 }
 
 /* Handle a configuration change: Tell driver if it wants to know. */
index 6547d46171b3814b3a14d381b41ca60812a0a629..97dd51619b554f1902bd4018bf1fbaf68ba6b917 100644 (file)
@@ -81,7 +81,7 @@ struct vring_virtqueue
        u16 last_used_idx;
 
        /* How to notify other side. FIXME: commonalize hcalls! */
-       void (*notify)(struct virtqueue *vq);
+       bool (*notify)(struct virtqueue *vq);
 
 #ifdef DEBUG
        /* They're supposed to lock for us. */
@@ -744,7 +744,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
                                      struct virtio_device *vdev,
                                      bool weak_barriers,
                                      void *pages,
-                                     void (*notify)(struct virtqueue *),
+                                     bool (*notify)(struct virtqueue *),
                                      void (*callback)(struct virtqueue *),
                                      const char *name)
 {
index b300787af8e089b05e4038d71fef277fba9f85e4..67e06fe18c03b6814e217f05134cdb68a5df13bc 100644 (file)
@@ -71,7 +71,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
                                      struct virtio_device *vdev,
                                      bool weak_barriers,
                                      void *pages,
-                                     void (*notify)(struct virtqueue *vq),
+                                     bool (*notify)(struct virtqueue *vq),
                                      void (*callback)(struct virtqueue *vq),
                                      const char *name);
 void vring_del_virtqueue(struct virtqueue *vq);
index da7a19558281637789bd932614861cc10c15d692..059cb723f6a7757d31377bd1dd040e5f2a457326 100644 (file)
@@ -41,13 +41,14 @@ struct vdev_info {
        struct vhost_memory *mem;
 };
 
-void vq_notify(struct virtqueue *vq)
+bool vq_notify(struct virtqueue *vq)
 {
        struct vq_info *info = vq->priv;
        unsigned long long v = 1;
        int r;
        r = write(info->kick, &v, sizeof v);
        assert(r == sizeof v);
+       return true;
 }
 
 void vq_callback(struct virtqueue *vq)
index d053ea40c001ff8ecfba849560d819c9886c212a..14a4f4cab5b97a1070abc656bca1bc72c60b5aa1 100644 (file)
@@ -22,7 +22,7 @@ static u64 user_addr_offset;
 #define RINGSIZE 256
 #define ALIGN 4096
 
-static void never_notify_host(struct virtqueue *vq)
+static bool never_notify_host(struct virtqueue *vq)
 {
        abort();
 }
@@ -65,17 +65,22 @@ struct guest_virtio_device {
        unsigned long notifies;
 };
 
-static void parallel_notify_host(struct virtqueue *vq)
+static bool parallel_notify_host(struct virtqueue *vq)
 {
+       int rc;
        struct guest_virtio_device *gvdev;
 
        gvdev = container_of(vq->vdev, struct guest_virtio_device, vdev);
-       write(gvdev->to_host_fd, "", 1);
+       rc = write(gvdev->to_host_fd, "", 1);
+       if (rc < 0)
+               return false;
        gvdev->notifies++;
+       return true;
 }
 
-static void no_notify_host(struct virtqueue *vq)
+static bool no_notify_host(struct virtqueue *vq)
 {
+       return true;
 }
 
 #define NUM_XFERS (10000000)