[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[[UNIKRAFT PATCH] v4 3/4] plat/drivers/virtio: Made virtio irq handler interrupt-context-safe



From: Cristian Vijelie <cristianvijelie@xxxxxxxxx>

Added a new sourcefile, virtio-isr.c, where I placed the interrupt handler
'virtqueue_ring_interrupt', and made it to be build with the isr flag.

Signed-off-by: Cristian Vijelie <cristianvijelie@xxxxxxxxx>
---
 plat/drivers/virtio/internal/internal.h | 63 ++++++++++++++++++++++++
 plat/drivers/virtio/virtio_isr.c        | 64 +++++++++++++++++++++++++
 plat/drivers/virtio/virtio_ring.c       | 61 ++++++++---------------
 plat/kvm/Makefile.uk                    |  2 +
 4 files changed, 148 insertions(+), 42 deletions(-)
 create mode 100644 plat/drivers/virtio/internal/internal.h
 create mode 100644 plat/drivers/virtio/virtio_isr.c

diff --git a/plat/drivers/virtio/internal/internal.h 
b/plat/drivers/virtio/internal/internal.h
new file mode 100644
index 0000000..7f71653
--- /dev/null
+++ b/plat/drivers/virtio/internal/internal.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+/**
+ * Inspired from the FreeBSD.
+ * Commit-id: a89e7a10d501
+ */
+
+#include <virtio/virtqueue.h>
+
+struct virtqueue_desc_info {
+       void *cookie;
+       __u16 desc_count;
+};
+
+struct virtqueue_vring {
+       struct virtqueue vq;
+       /* Descriptor Ring */
+       struct vring vring;
+       /* Reference to the vring */
+       void   *vring_mem;
+       /* Keep track of available descriptors */
+       __u16 desc_avail;
+       /* Index of the next available slot */
+       __u16 head_free_desc;
+       /* Index of the last used descriptor by the host */
+       __u16 last_used_desc_idx;
+       /* Cookie to identify driver buffer */
+       struct virtqueue_desc_info vq_info[];
+};
+
+#define to_virtqueue_vring(vq)                 \
+       __containerof(vq, struct virtqueue_vring, vq)
diff --git a/plat/drivers/virtio/virtio_isr.c b/plat/drivers/virtio/virtio_isr.c
new file mode 100644
index 0000000..d338be0
--- /dev/null
+++ b/plat/drivers/virtio/virtio_isr.c
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+/**
+ * Inspired from the FreeBSD.
+ * Commit-id: a89e7a10d501
+ */
+
+#include "internal/internal.h"
+
+int virtqueue_hasdata(struct virtqueue *vq)
+{
+       struct virtqueue_vring *vring;
+
+       UK_ASSERT(vq);
+
+       vring = to_virtqueue_vring(vq);
+       return (vring->last_used_desc_idx != vring->vring.used->idx);
+}
+
+int virtqueue_ring_interrupt(void *obj)
+{
+       struct virtqueue *vq = (struct virtqueue *)obj;
+       int rc = 0;
+
+       UK_ASSERT(vq);
+
+       if (!virtqueue_hasdata(vq))
+               return rc;
+
+       if (likely(vq->vq_callback))
+               rc = vq->vq_callback(vq, vq->priv);
+       return rc;
+}
diff --git a/plat/drivers/virtio/virtio_ring.c 
b/plat/drivers/virtio/virtio_ring.c
index 0a5c3f3..5a05bef 100644
--- a/plat/drivers/virtio/virtio_ring.c
+++ b/plat/drivers/virtio/virtio_ring.c
@@ -44,32 +44,9 @@
 #include <uk/arch/atomic.h>
 #include <uk/plat/io.h>
 #include <virtio/virtio_ring.h>
-#include <virtio/virtqueue.h>
+#include "internal/internal.h"
 
 #define VIRTQUEUE_MAX_SIZE  32768
-#define to_virtqueue_vring(vq)                 \
-       __containerof(vq, struct virtqueue_vring, vq)
-
-struct virtqueue_desc_info {
-       void *cookie;
-       __u16 desc_count;
-};
-
-struct virtqueue_vring {
-       struct virtqueue vq;
-       /* Descriptor Ring */
-       struct vring vring;
-       /* Reference to the vring */
-       void   *vring_mem;
-       /* Keep track of available descriptors */
-       __u16 desc_avail;
-       /* Index of the next available slot */
-       __u16 head_free_desc;
-       /* Index of the last used descriptor by the host */
-       __u16 last_used_desc_idx;
-       /* Cookie to identify driver buffer */
-       struct virtqueue_desc_info vq_info[];
-};
 
 /**
  * Static function Declaration(s).
@@ -215,15 +192,15 @@ static inline int virtqueue_buffer_enqueue_segments(
        return idx;
 }
 
-int virtqueue_hasdata(struct virtqueue *vq)
-{
-       struct virtqueue_vring *vring;
+// int virtqueue_hasdata(struct virtqueue *vq)
+// {
+//     struct virtqueue_vring *vring;
 
-       UK_ASSERT(vq);
+//     UK_ASSERT(vq);
 
-       vring = to_virtqueue_vring(vq);
-       return (vring->last_used_desc_idx != vring->vring.used->idx);
-}
+       // vring = to_virtqueue_vring(vq);
+//     return (vring->last_used_desc_idx != vring->vring.used->idx);
+// }
 
 __u64 virtqueue_feature_negotiate(__u64 feature_set)
 {
@@ -237,20 +214,20 @@ __u64 virtqueue_feature_negotiate(__u64 feature_set)
        return feature;
 }
 
-int virtqueue_ring_interrupt(void *obj)
-{
-       struct virtqueue *vq = (struct virtqueue *)obj;
-       int rc = 0;
+// int virtqueue_ring_interrupt(void *obj)
+// {
+//     struct virtqueue *vq = (struct virtqueue *)obj;
+//     int rc = 0;
 
-       UK_ASSERT(vq);
+//     UK_ASSERT(vq);
 
-       if (!virtqueue_hasdata(vq))
-               return rc;
+//     if (!virtqueue_hasdata(vq))
+//             return rc;
 
-       if (likely(vq->vq_callback))
-               rc = vq->vq_callback(vq, vq->priv);
-       return rc;
-}
+//     if (likely(vq->vq_callback))
+//             rc = vq->vq_callback(vq, vq->priv);
+//     return rc;
+// }
 
 __phys_addr virtqueue_physaddr(struct virtqueue *vq)
 {
diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index ec079dd..5a3a741 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -128,6 +128,8 @@ LIBKVMVIRTIO_SRCS-$(CONFIG_VIRTIO_BUS) +=\
                        $(UK_PLAT_DRIVERS_BASE)/virtio/virtio_bus.c
 LIBKVMVIRTIO_SRCS-$(CONFIG_VIRTIO_BUS) +=\
                        $(UK_PLAT_DRIVERS_BASE)/virtio/virtio_ring.c
+                       LIBKVMVIRTIO_SRCS-$(CONFIG_VIRTIO_BUS) +=\
+                       $(UK_PLAT_DRIVERS_BASE)/virtio/virtio_isr.c|isr
 LIBKVMVIRTIO_SRCS-$(CONFIG_VIRTIO_PCI) +=\
                        $(UK_PLAT_DRIVERS_BASE)/virtio/virtio_pci.c
 ##
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.