Blame SOURCES/kvm-spice-set-device-address-and-device-display-ID-in-QX.patch

ae23c9
From 2d0261e575197b60fd17850f1079359375fb82a3 Mon Sep 17 00:00:00 2001
ae23c9
From: Danilo de Paula <ddepaula@redhat.com>
ae23c9
Date: Wed, 22 May 2019 20:24:33 +0100
ae23c9
Subject: [PATCH 11/12] spice: set device address and device display ID in QXL
ae23c9
 interface
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Danilo de Paula <ddepaula@redhat.com>
ae23c9
Message-id: <20190522202434.2529-2-ddepaula@redhat.com>
ae23c9
Patchwork-id: 88166
ae23c9
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 1/2] spice: set device address and device display ID in QXL interface
ae23c9
Bugzilla: 1712946
ae23c9
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
ae23c9
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
ae23c9
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
ae23c9
From: Lukáš Hrázký <lhrazky@redhat.com>
ae23c9
ae23c9
Calls the new SPICE QXL interface function spice_qxl_set_device_info to
ae23c9
set the hardware address of the graphics device represented by the QXL
ae23c9
interface (e.g. a PCI path) and the device display IDs (the IDs of the
ae23c9
device's monitors that belong to this QXL interface).
ae23c9
ae23c9
Also stops using the deprecated spice_qxl_set_max_monitors, the new
ae23c9
interface function replaces it.
ae23c9
ae23c9
Signed-off-by: Lukáš Hrázký <lhrazky@redhat.com>
ae23c9
Message-Id: <20190215150919.8263-1-lhrazky@redhat.com>
ae23c9
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ae23c9
(cherry picked from commit be812c0ab7d5ab741d0d87387a75a0e8bb6461e7)
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/display/qxl.c           | 14 ++++++++++++-
ae23c9
 include/ui/spice-display.h |  4 ++++
ae23c9
 ui/spice-core.c            | 51 ++++++++++++++++++++++++++++++++++++++++++++++
ae23c9
 ui/spice-display.c         | 11 ++++++++++
ae23c9
 4 files changed, 79 insertions(+), 1 deletion(-)
ae23c9
ae23c9
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
ae23c9
index e36ef32..b373c50 100644
ae23c9
--- a/hw/display/qxl.c
ae23c9
+++ b/hw/display/qxl.c
ae23c9
@@ -275,7 +275,8 @@ static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay)
ae23c9
                     QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
ae23c9
                     0));
ae23c9
     } else {
ae23c9
-#if SPICE_SERVER_VERSION >= 0x000c06 /* release 0.12.6 */
ae23c9
+/* >= release 0.12.6, < release 0.14.2 */
ae23c9
+#if SPICE_SERVER_VERSION >= 0x000c06 && SPICE_SERVER_VERSION < 0x000e02
ae23c9
         if (qxl->max_outputs) {
ae23c9
             spice_qxl_set_max_monitors(&qxl->ssd.qxl, qxl->max_outputs);
ae23c9
         }
ae23c9
@@ -2161,6 +2162,17 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp)
ae23c9
                    SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR);
ae23c9
         return;
ae23c9
     }
ae23c9
+
ae23c9
+#if SPICE_SERVER_VERSION >= 0x000e02 /* release 0.14.2 */
ae23c9
+    char device_address[256] = "";
ae23c9
+    if (qemu_spice_fill_device_address(qxl->vga.con, device_address, 256)) {
ae23c9
+        spice_qxl_set_device_info(&qxl->ssd.qxl,
ae23c9
+                                  device_address,
ae23c9
+                                  0,
ae23c9
+                                  qxl->max_outputs);
ae23c9
+    }
ae23c9
+#endif
ae23c9
+
ae23c9
     qemu_add_vm_change_state_handler(qxl_vm_change_state_handler, qxl);
ae23c9
 
ae23c9
     qxl->update_irq = qemu_bh_new(qxl_update_irq_bh, qxl);
ae23c9
diff --git a/include/ui/spice-display.h b/include/ui/spice-display.h
ae23c9
index 87a84a5..53c3612 100644
ae23c9
--- a/include/ui/spice-display.h
ae23c9
+++ b/include/ui/spice-display.h
ae23c9
@@ -179,3 +179,7 @@ void qemu_spice_wakeup(SimpleSpiceDisplay *ssd);
ae23c9
 void qemu_spice_display_start(void);
ae23c9
 void qemu_spice_display_stop(void);
ae23c9
 int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd);
ae23c9
+
ae23c9
+bool qemu_spice_fill_device_address(QemuConsole *con,
ae23c9
+                                    char *device_address,
ae23c9
+                                    size_t size);
ae23c9
diff --git a/ui/spice-core.c b/ui/spice-core.c
ae23c9
index ae8921a..ebc2f09 100644
ae23c9
--- a/ui/spice-core.c
ae23c9
+++ b/ui/spice-core.c
ae23c9
@@ -35,6 +35,7 @@
ae23c9
 #include "qemu/option.h"
ae23c9
 #include "migration/misc.h"
ae23c9
 #include "hw/hw.h"
ae23c9
+#include "hw/pci/pci_bus.h"
ae23c9
 #include "ui/spice-display.h"
ae23c9
 
ae23c9
 /* core bits */
ae23c9
@@ -872,6 +873,56 @@ bool qemu_spice_have_display_interface(QemuConsole *con)
ae23c9
     return false;
ae23c9
 }
ae23c9
 
ae23c9
+/*
ae23c9
+ * Recursively (in reverse order) appends addresses of PCI devices as it moves
ae23c9
+ * up in the PCI hierarchy.
ae23c9
+ *
ae23c9
+ * @returns true on success, false when the buffer wasn't large enough
ae23c9
+ */
ae23c9
+static bool append_pci_address(char *buf, size_t buf_size, const PCIDevice *pci)
ae23c9
+{
ae23c9
+    PCIBus *bus = pci_get_bus(pci);
ae23c9
+    /*
ae23c9
+     * equivalent to if (!pci_bus_is_root(bus)), but the function is not built
ae23c9
+     * with PCI_CONFIG=n, avoid using an #ifdef by checking directly
ae23c9
+     */
ae23c9
+    if (bus->parent_dev != NULL) {
ae23c9
+        append_pci_address(buf, buf_size, bus->parent_dev);
ae23c9
+    }
ae23c9
+
ae23c9
+    size_t len = strlen(buf);
ae23c9
+    ssize_t written = snprintf(buf + len, buf_size - len, "/%02x.%x",
ae23c9
+        PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn));
ae23c9
+
ae23c9
+    return written > 0 && written < buf_size - len;
ae23c9
+}
ae23c9
+
ae23c9
+bool qemu_spice_fill_device_address(QemuConsole *con,
ae23c9
+                                    char *device_address,
ae23c9
+                                    size_t size)
ae23c9
+{
ae23c9
+    DeviceState *dev = DEVICE(object_property_get_link(OBJECT(con),
ae23c9
+                                                       "device",
ae23c9
+                                                       &error_abort));
ae23c9
+    PCIDevice *pci = (PCIDevice *) object_dynamic_cast(OBJECT(dev),
ae23c9
+                                                       TYPE_PCI_DEVICE);
ae23c9
+
ae23c9
+    if (pci == NULL) {
ae23c9
+        warn_report("Setting device address of a display device to SPICE: "
ae23c9
+                    "Not a PCI device.");
ae23c9
+        return false;
ae23c9
+    }
ae23c9
+
ae23c9
+    strncpy(device_address, "pci/0000", size);
ae23c9
+    if (!append_pci_address(device_address, size, pci)) {
ae23c9
+        warn_report("Setting device address of a display device to SPICE: "
ae23c9
+            "Too many PCI devices in the chain.");
ae23c9
+        return false;
ae23c9
+    }
ae23c9
+
ae23c9
+    return true;
ae23c9
+}
ae23c9
+
ae23c9
 int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con)
ae23c9
 {
ae23c9
     if (g_slist_find(spice_consoles, con)) {
ae23c9
diff --git a/ui/spice-display.c b/ui/spice-display.c
ae23c9
index fe73482..22332f4 100644
ae23c9
--- a/ui/spice-display.c
ae23c9
+++ b/ui/spice-display.c
ae23c9
@@ -1115,6 +1115,17 @@ static void qemu_spice_display_init_one(QemuConsole *con)
ae23c9
 
ae23c9
     ssd->qxl.base.sif = &dpy_interface.base;
ae23c9
     qemu_spice_add_display_interface(&ssd->qxl, con);
ae23c9
+
ae23c9
+#if SPICE_SERVER_VERSION >= 0x000e02 /* release 0.14.2 */
ae23c9
+    char device_address[256] = "";
ae23c9
+    if (qemu_spice_fill_device_address(con, device_address, 256)) {
ae23c9
+        spice_qxl_set_device_info(&ssd->qxl,
ae23c9
+                                  device_address,
ae23c9
+                                  qemu_console_get_head(con),
ae23c9
+                                  1);
ae23c9
+    }
ae23c9
+#endif
ae23c9
+
ae23c9
     qemu_spice_create_host_memslot(ssd);
ae23c9
 
ae23c9
     register_displaychangelistener(&ssd->dcl);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9