All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: borntraeger@de.ibm.com, Paolo Bonzini <pbonzini@redhat.com>,
	Karl Rister <krister@redhat.com>, Fam Zheng <famz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v3 08/10] virtio: turn vq->notification into a nested counter
Date: Tue, 22 Nov 2016 16:31:44 +0000	[thread overview]
Message-ID: <1479832306-26440-9-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1479832306-26440-1-git-send-email-stefanha@redhat.com>

Polling should disable virtqueue notifications but that requires nested
virtio_queue_set_notification() calls.  Turn vq->notification into a
counter so it is possible to do nesting.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/virtio/virtio.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index f0ed8fe..66dd968 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -87,8 +87,8 @@ struct VirtQueue
     /* Last used index value we have signalled on */
     bool signalled_used_valid;
 
-    /* Notification enabled? */
-    bool notification;
+    /* Nested host->guest notification disabled counter */
+    unsigned int notification_disabled;
 
     uint16_t queue_index;
 
@@ -201,7 +201,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
 static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
 {
     hwaddr pa;
-    if (!vq->notification) {
+    if (vq->notification_disabled) {
         return;
     }
     pa = vq->vring.used + offsetof(VRingUsed, ring[vq->vring.num]);
@@ -210,7 +210,13 @@ static inline void vring_set_avail_event(VirtQueue *vq, uint16_t val)
 
 void virtio_queue_set_notification(VirtQueue *vq, int enable)
 {
-    vq->notification = enable;
+    if (enable) {
+        assert(vq->notification_disabled > 0);
+        vq->notification_disabled--;
+    } else {
+        vq->notification_disabled++;
+    }
+
     if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) {
         vring_set_avail_event(vq, vring_avail_idx(vq));
     } else if (enable) {
@@ -959,7 +965,7 @@ void virtio_reset(void *opaque)
         virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR);
         vdev->vq[i].signalled_used = 0;
         vdev->vq[i].signalled_used_valid = false;
-        vdev->vq[i].notification = true;
+        vdev->vq[i].notification_disabled = 0;
         vdev->vq[i].vring.num = vdev->vq[i].vring.num_default;
         vdev->vq[i].inuse = 0;
     }
@@ -1774,7 +1780,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
         vdev->vq[i].vring.desc = qemu_get_be64(f);
         qemu_get_be16s(f, &vdev->vq[i].last_avail_idx);
         vdev->vq[i].signalled_used_valid = false;
-        vdev->vq[i].notification = true;
+        vdev->vq[i].notification_disabled = 0;
 
         if (vdev->vq[i].vring.desc) {
             /* XXX virtio-1 devices */
-- 
2.7.4

  parent reply	other threads:[~2016-11-22 16:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22 16:31 [Qemu-devel] [PATCH v3 00/10] aio: experimental virtio-blk polling mode Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 01/10] virtio: add missing vdev->broken check Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 02/10] virtio-blk: suppress virtqueue kick during processing Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 03/10] virtio-scsi: " Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 04/10] aio: add AioPollFn and io_poll() interface Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 05/10] aio: add polling mode to AioContext Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 06/10] virtio: poll virtqueues for new buffers Stefan Hajnoczi
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 07/10] linux-aio: poll ring for completions Stefan Hajnoczi
2016-11-22 16:31 ` Stefan Hajnoczi [this message]
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 09/10] aio: add .io_poll_begin/end() callbacks Stefan Hajnoczi
2016-11-22 17:21   ` Paolo Bonzini
2016-11-23  9:44     ` Stefan Hajnoczi
2016-11-23 10:59       ` Paolo Bonzini
2016-11-22 16:31 ` [Qemu-devel] [PATCH v3 10/10] virtio: disable virtqueue notifications during polling Stefan Hajnoczi
2016-11-22 16:57 ` [Qemu-devel] [PATCH v3 00/10] aio: experimental virtio-blk polling mode no-reply
2016-11-22 17:13 ` Paolo Bonzini
2016-11-22 19:21 ` Christian Borntraeger
2016-11-23  9:51   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479832306-26440-9-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=famz@redhat.com \
    --cc=krister@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.