Blame 0015-qxl-Only-emit-QXL_INTERRUPT_CLIENT_MONITORS_CONFIG-o.patch

cf8164
From: Christophe Fergeau <cfergeau@redhat.com>
cf8164
Date: Fri, 14 Oct 2016 14:22:36 +0200
cf8164
Subject: [PATCH] qxl: Only emit QXL_INTERRUPT_CLIENT_MONITORS_CONFIG on config
cf8164
 changes
cf8164
cf8164
Currently if the client keeps sending the same monitor config to
cf8164
QEMU/spice-server, QEMU will always raise
cf8164
a QXL_INTERRUPT_CLIENT_MONITORS_CONFIG regardless of whether there was a
cf8164
change or not.
cf8164
Guest-side (with fedora 25), the kernel QXL KMS driver will also forward the
cf8164
event to user-space without checking if there were actual changes.
cf8164
Next in line are gnome-shell/mutter (on a default f25 install), which
cf8164
will try to reconfigure everything without checking if there is anything
cf8164
to do.
cf8164
Where this gets ugly is that when applying the resolution changes,
cf8164
gnome-shell/mutter will call drmModeRmFB, drmModeAddFB, and
cf8164
drmModeSetCrtc, which will cause the primary surface to be destroyed and
cf8164
recreated by the QXL KMS driver. This in turn will cause the client to
cf8164
resend a client monitors config message, which will cause QEMU to reemit
cf8164
an interrupt with an unchanged monitors configuration, ...
cf8164
This causes https://bugzilla.redhat.com/show_bug.cgi?id=1266484
cf8164
cf8164
This commit makes sure that we only emit
cf8164
QXL_INTERRUPT_CLIENT_MONITORS_CONFIG when there are actual configuration
cf8164
changes the guest should act on.
cf8164
---
cf8164
 hw/display/qxl.c | 20 +++++++++++++++++++-
cf8164
 1 file changed, 19 insertions(+), 1 deletion(-)
cf8164
cf8164
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
cf8164
index 0e2682d..56759f8 100644
cf8164
--- a/hw/display/qxl.c
cf8164
+++ b/hw/display/qxl.c
cf8164
@@ -1000,6 +1000,7 @@ static int interface_client_monitors_config(QXLInstance *sin,
cf8164
     QXLRom *rom = memory_region_get_ram_ptr(&qxl->rom_bar);
cf8164
     int i;
cf8164
     unsigned max_outputs = ARRAY_SIZE(rom->client_monitors_config.heads);
cf8164
+    bool config_changed = false;
cf8164
 
cf8164
     if (qxl->revision < 4) {
cf8164
         trace_qxl_client_monitors_config_unsupported_by_device(qxl->id,
cf8164
@@ -1030,6 +1031,21 @@ static int interface_client_monitors_config(QXLInstance *sin,
cf8164
     }
cf8164
 #endif
cf8164
 
cf8164
+    if (rom->client_monitors_config.count != MIN(monitors_config->num_of_monitors, max_outputs)) {
cf8164
+        config_changed = true;
cf8164
+    }
cf8164
+    for (i = 0 ; i < rom->client_monitors_config.count ; ++i) {
cf8164
+        VDAgentMonConfig *monitor = &monitors_config->monitors[i];
cf8164
+        QXLURect *rect = &rom->client_monitors_config.heads[i];
cf8164
+        /* monitor->depth ignored */
cf8164
+        if ((rect->left != monitor->x) ||
cf8164
+            (rect->top != monitor->y)  ||
cf8164
+            (rect->right != monitor->x + monitor->width) ||
cf8164
+            (rect->bottom != monitor->y + monitor->height)) {
cf8164
+            config_changed = true;
cf8164
+        }
cf8164
+    }
cf8164
+
cf8164
     memset(&rom->client_monitors_config, 0,
cf8164
            sizeof(rom->client_monitors_config));
cf8164
     rom->client_monitors_config.count = monitors_config->num_of_monitors;
cf8164
@@ -1059,7 +1075,9 @@ static int interface_client_monitors_config(QXLInstance *sin,
cf8164
     trace_qxl_interrupt_client_monitors_config(qxl->id,
cf8164
                         rom->client_monitors_config.count,
cf8164
                         rom->client_monitors_config.heads);
cf8164
-    qxl_send_events(qxl, QXL_INTERRUPT_CLIENT_MONITORS_CONFIG);
cf8164
+    if (config_changed) {
cf8164
+        qxl_send_events(qxl, QXL_INTERRUPT_CLIENT_MONITORS_CONFIG);
cf8164
+    }
cf8164
     return 1;
cf8164
 }
cf8164