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

151958
From d1fd2760ce6025f55b7c71ca303d49afbf17ad8e Mon Sep 17 00:00:00 2001
151958
Message-Id: <d1fd2760ce6025f55b7c71ca303d49afbf17ad8e.1480901031.git.crobinso@redhat.com>
cf8164
From: Christophe Fergeau <cfergeau@redhat.com>
151958
Date: Fri, 28 Oct 2016 16:48:40 +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.
151958
151958
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
151958
Signed-off-by: Cole Robinson <crobinso@redhat.com>
cf8164
---
151958
 hw/display/qxl.c | 37 ++++++++++++++++++++++++++++++++++++-
151958
 1 file changed, 36 insertions(+), 1 deletion(-)
cf8164
cf8164
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
151958
index 0e2682d..62d0c80 100644
cf8164
--- a/hw/display/qxl.c
cf8164
+++ b/hw/display/qxl.c
151958
@@ -992,6 +992,34 @@ static uint32_t qxl_crc32(const uint8_t *p, unsigned len)
151958
     return crc32(0xffffffff, p, len) ^ 0xffffffff;
151958
 }
cf8164
 
151958
+static bool qxl_rom_monitors_config_changed(QXLRom *rom,
151958
+        VDAgentMonitorsConfig *monitors_config,
151958
+        unsigned int max_outputs)
151958
+{
151958
+    int i;
151958
+    unsigned int monitors_count;
151958
+
151958
+    monitors_count = MIN(monitors_config->num_of_monitors, max_outputs);
151958
+
151958
+    if (rom->client_monitors_config.count != monitors_count) {
151958
+        return true;
cf8164
+    }
151958
+
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)) {
151958
+            return true;
cf8164
+        }
cf8164
+    }
cf8164
+
151958
+    return false;
151958
+}
151958
+
151958
 /* called from main context only */
151958
 static int interface_client_monitors_config(QXLInstance *sin,
151958
                                         VDAgentMonitorsConfig *monitors_config)
151958
@@ -1000,6 +1028,7 @@ static int interface_client_monitors_config(QXLInstance *sin,
151958
     QXLRom *rom = memory_region_get_ram_ptr(&qxl->rom_bar);
151958
     int i;
151958
     unsigned max_outputs = ARRAY_SIZE(rom->client_monitors_config.heads);
151958
+    bool config_changed = false;
151958
 
151958
     if (qxl->revision < 4) {
151958
         trace_qxl_client_monitors_config_unsupported_by_device(qxl->id,
151958
@@ -1030,6 +1059,10 @@ static int interface_client_monitors_config(QXLInstance *sin,
151958
     }
151958
 #endif
151958
 
151958
+    config_changed = qxl_rom_monitors_config_changed(rom,
151958
+                                                     monitors_config,
151958
+                                                     max_outputs);
151958
+
cf8164
     memset(&rom->client_monitors_config, 0,
cf8164
            sizeof(rom->client_monitors_config));
cf8164
     rom->client_monitors_config.count = monitors_config->num_of_monitors;
151958
@@ -1059,7 +1092,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
 
151958
-- 
151958
2.9.3
151958