qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	lprosek@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>,
	amit.shah@redhat.com
Subject: [Qemu-devel] [PATCH 3/3] virtio-serial: add missing virtio_detach_element() call
Date: Mon, 19 Sep 2016 14:28:05 +0100	[thread overview]
Message-ID: <1474291685-24226-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1474291685-24226-1-git-send-email-stefanha@redhat.com>

Ports enter a "throttled" state when writing to the chardev would block.
The current output VirtQueueElement is kept around until the chardev
becomes writable again.

There are several places in the virtio-serial lifecycle where the
VirtQueueElement should be thrown away.  For example, if the virtio
device is reset then virtqueue elements are no longer valid.

This patch adds the discard_throttle_data() function to unmap the
scatter-gather list and decrement vq->inuse.  This ensures that the
VirtQueueElement is freed properly.

Cc: amit.shah@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/char/virtio-serial-bus.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index db57a38..35aa3c7 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -132,6 +132,15 @@ static void discard_vq_data(VirtQueue *vq, VirtIODevice *vdev)
     virtio_notify(vdev, vq);
 }
 
+static void discard_throttle_data(VirtIOSerialPort *port)
+{
+    if (port->elem) {
+        virtqueue_detach_element(port->ovq, port->elem, 0);
+        g_free(port->elem);
+        port->elem = NULL;
+    }
+}
+
 static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
                                  VirtIODevice *vdev)
 {
@@ -254,6 +263,7 @@ int virtio_serial_close(VirtIOSerialPort *port)
      * consume, reset the throttling flag and discard the data.
      */
     port->throttled = false;
+    discard_throttle_data(port);
     discard_vq_data(port->ovq, VIRTIO_DEVICE(port->vser));
 
     send_control_event(port->vser, port->id, VIRTIO_CONSOLE_PORT_OPEN, 0);
@@ -554,6 +564,9 @@ static void guest_reset(VirtIOSerial *vser)
 
     QTAILQ_FOREACH(port, &vser->ports, next) {
         vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
+
+        discard_throttle_data(port);
+
         if (port->guest_connected) {
             port->guest_connected = false;
             if (vsc->set_guest_connected) {
@@ -864,6 +877,7 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id)
     assert(port);
 
     /* Flush out any unconsumed buffers first */
+    discard_throttle_data(port);
     discard_vq_data(port->ovq, VIRTIO_DEVICE(port->vser));
 
     send_control_event(vser, port->id, VIRTIO_CONSOLE_PORT_REMOVE, 1);
-- 
2.7.4

  parent reply	other threads:[~2016-09-19 13:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-19 13:28 [Qemu-devel] [PATCH 0/3] virtio: detach VirtQueueElements freed by reset Stefan Hajnoczi
2016-09-19 13:28 ` [Qemu-devel] [PATCH 1/3] virtio: add virtio_detach_element() Stefan Hajnoczi
2016-09-26  8:43   ` Greg Kurz
2016-09-27  7:32   ` Ladi Prosek
2016-09-27 10:08     ` Stefan Hajnoczi
2016-09-27 12:12       ` Ladi Prosek
2016-09-27 15:03         ` Stefan Hajnoczi
2016-09-27 15:24           ` Ladi Prosek
2016-09-19 13:28 ` [Qemu-devel] [PATCH 2/3] virtio-blk: add missing virtio_detach_element() call Stefan Hajnoczi
2016-09-27  7:49   ` Ladi Prosek
2016-09-27  8:07     ` Greg Kurz
2016-09-19 13:28 ` Stefan Hajnoczi [this message]
2016-09-30 10:08   ` [Qemu-devel] [PATCH 3/3] virtio-serial: " Ladi Prosek
2016-09-27 10:08 ` [Qemu-devel] [PATCH 0/3] virtio: detach VirtQueueElements freed by reset Stefan Hajnoczi
2016-10-05 13:12   ` Greg Kurz

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=1474291685-24226-4-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=lprosek@redhat.com \
    --cc=mst@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).