thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 6d8b03e0e91a58a0b276e76363e0c836827c9a49 Mon Sep 17 00:00:00 2001
9ae3a8
From: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Date: Fri, 19 Jul 2013 13:05:23 +0200
9ae3a8
Subject: monitor: maintain at most one G_IO_OUT watch
9ae3a8
9ae3a8
RH-Author: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Message-id: <1374239123-4841-3-git-send-email-lersek@redhat.com>
9ae3a8
Patchwork-id: 52616
9ae3a8
O-Subject: [RHEL-7 qemu-kvm PATCH 2/2] monitor: maintain at most one G_IO_OUT watch
9ae3a8
Bugzilla: 970047
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
9ae3a8
When monitor_flush() is invoked repeatedly outside the monitor_unblocked()
9ae3a8
callback, for example from tlb_info() -> ... -> print_pte(), several
9ae3a8
watches may be added for the same event.
9ae3a8
9ae3a8
This is no problem per se because the extra monitor_unblocked() callbacks
9ae3a8
are harmless if mon->outbuf is empty, the watches will be removed
9ae3a8
gradually. However a big number of watches can grow "gpollfds" without
9ae3a8
limit in glib_pollfds_fill(), triggering a -1/EINVAL condition in
9ae3a8
g_poll().
9ae3a8
9ae3a8
Keep at most one such watch, by following the pattern observable in eg.
9ae3a8
commits c874ea97 and c3d6b96e. The change has no effect when
9ae3a8
monitor_unblocked() calls monitor_flush() (when the watch can either be
9ae3a8
removed or renewed 1-for-1), but non-callback contexts won't create an
9ae3a8
additional watch when the monitor already has one.
9ae3a8
9ae3a8
Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=970047
9ae3a8
9ae3a8
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Reviewed-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
Message-id: 1373998781-29561-3-git-send-email-lersek@redhat.com
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
(cherry picked from commit 293d2a0014a0e849477413f55aaa05f2743b2e04)
9ae3a8
9ae3a8
diff --git a/monitor.c b/monitor.c
9ae3a8
index dee980c..deb0dc8 100644
9ae3a8
--- a/monitor.c
9ae3a8
+++ b/monitor.c
9ae3a8
@@ -190,6 +190,7 @@ struct Monitor {
9ae3a8
     int suspend_cnt;
9ae3a8
     bool skip_flush;
9ae3a8
     QString *outbuf;
9ae3a8
+    guint watch;
9ae3a8
     ReadLineState *rs;
9ae3a8
     MonitorControl *mc;
9ae3a8
     CPUArchState *mon_cpu;
9ae3a8
@@ -264,7 +265,10 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func,
9ae3a8
 static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
9ae3a8
                                   void *opaque)
9ae3a8
 {
9ae3a8
-    monitor_flush(opaque);
9ae3a8
+    Monitor *mon = opaque;
9ae3a8
+
9ae3a8
+    mon->watch = 0;
9ae3a8
+    monitor_flush(mon);
9ae3a8
     return FALSE;
9ae3a8
 }
9ae3a8
 
9ae3a8
@@ -295,7 +299,10 @@ void monitor_flush(Monitor *mon)
9ae3a8
             QDECREF(mon->outbuf);
9ae3a8
             mon->outbuf = tmp;
9ae3a8
         }
9ae3a8
-        qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon);
9ae3a8
+        if (mon->watch == 0) {
9ae3a8
+            mon->watch = qemu_chr_fe_add_watch(mon->chr, G_IO_OUT,
9ae3a8
+                                               monitor_unblocked, mon);
9ae3a8
+        }
9ae3a8
     }
9ae3a8
 }
9ae3a8