Blame SOURCES/kvm-monitor-maintain-at-most-one-G_IO_OUT-watch.patch

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