Blame SOURCES/0001-linux-Make-platform-device-probe-less-fragile.patch

28d94e
From 0816e8fca6194dfb4cc94c3a7fcb2c7f2a921386 Mon Sep 17 00:00:00 2001
bd52eb
From: Adam Jackson <ajax@redhat.com>
bd52eb
Date: Tue, 18 Sep 2018 14:37:51 -0400
28d94e
Subject: [PATCH xserver] linux: Make platform device probe less fragile
bd52eb
28d94e
At the point where xf86BusProbe runs we haven't yet taken our own VT,
28d94e
which means we can't perform drm "master" operations on the device. This
28d94e
is tragic, because we need master to fish the bus id string out of the
28d94e
kernel, which we can only do after drmSetInterfaceVersion, which for
28d94e
some reason stores that string on the device not the file handle and
28d94e
thus needs master access.
bd52eb
28d94e
Fortunately we know the format of the busid string, and it happens to
28d94e
almost be the same as the ID_PATH variable from udev. Use that instead
28d94e
and stop calling drmSetInterfaceVersion.
bd52eb
28d94e
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
28d94e
Signed-off-by: Adam Jackson <ajax@redhat.com>
bd52eb
---
28d94e
 config/udev.c                              | 17 ++++++++++++-----
28d94e
 hw/xfree86/os-support/linux/lnx_platform.c | 20 ++------------------
28d94e
 2 files changed, 14 insertions(+), 23 deletions(-)
bd52eb
28d94e
diff --git a/config/udev.c b/config/udev.c
28d94e
index 3a73189e25..8c6c4b6665 100644
28d94e
--- a/config/udev.c
28d94e
+++ b/config/udev.c
28d94e
@@ -56,7 +56,7 @@ static struct udev_monitor *udev_monitor;
28d94e
 
28d94e
 #ifdef CONFIG_UDEV_KMS
28d94e
 static void
28d94e
-config_udev_odev_setup_attribs(const char *path, const char *syspath,
28d94e
+config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path, const char *syspath,
28d94e
                                int major, int minor,
28d94e
                                config_odev_probe_proc_ptr probe_callback);
28d94e
 #endif
28d94e
@@ -128,7 +128,7 @@ device_added(struct udev_device *udev_device)
28d94e
 
28d94e
         LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
28d94e
 
28d94e
-        config_udev_odev_setup_attribs(path, syspath, major(devnum),
28d94e
+        config_udev_odev_setup_attribs(udev_device, path, syspath, major(devnum),
28d94e
                                        minor(devnum), NewGPUDeviceRequest);
28d94e
         return;
28d94e
     }
28d94e
@@ -322,7 +322,7 @@ device_removed(struct udev_device *device)
28d94e
 
28d94e
         LogMessage(X_INFO, "config/udev: removing GPU device %s %s\n",
28d94e
                    syspath, path);
28d94e
-        config_udev_odev_setup_attribs(path, syspath, major(devnum),
28d94e
+        config_udev_odev_setup_attribs(device, path, syspath, major(devnum),
28d94e
                                        minor(devnum), DeleteGPUDeviceRequest);
28d94e
         /* Retry vtenter after a drm node removal */
28d94e
         systemd_logind_vtenter();
28d94e
@@ -465,17 +465,24 @@ config_udev_fini(void)
28d94e
 #ifdef CONFIG_UDEV_KMS
28d94e
 
28d94e
 static void
28d94e
-config_udev_odev_setup_attribs(const char *path, const char *syspath,
28d94e
+config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path, const char *syspath,
28d94e
                                int major, int minor,
28d94e
                                config_odev_probe_proc_ptr probe_callback)
28d94e
 {
28d94e
     struct OdevAttributes *attribs = config_odev_allocate_attributes();
28d94e
+    const char *value;
28d94e
 
28d94e
     attribs->path = XNFstrdup(path);
28d94e
     attribs->syspath = XNFstrdup(syspath);
28d94e
     attribs->major = major;
28d94e
     attribs->minor = minor;
28d94e
 
28d94e
+    value = udev_device_get_property_value(udev_device, "ID_PATH");
28d94e
+    if (value && !strncmp(value, "pci-", 4)) {
28d94e
+        attribs->busid = XNFstrdup(value);
28d94e
+        attribs->busid[3] = ':';
28d94e
+    }
28d94e
+
28d94e
     /* ownership of attribs is passed to probe layer */
28d94e
     probe_callback(attribs);
28d94e
 }
28d94e
@@ -516,7 +523,7 @@ config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback)
28d94e
         else if (!check_seat(udev_device))
28d94e
             goto no_probe;
28d94e
 
28d94e
-        config_udev_odev_setup_attribs(path, syspath, major(devnum),
28d94e
+        config_udev_odev_setup_attribs(udev_device, path, syspath, major(devnum),
28d94e
                                        minor(devnum), probe_callback);
28d94e
     no_probe:
28d94e
         udev_device_unref(udev_device);
bd52eb
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
28d94e
index 70374ace88..e623062192 100644
bd52eb
--- a/hw/xfree86/os-support/linux/lnx_platform.c
bd52eb
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
28d94e
@@ -23,13 +23,13 @@
28d94e
 static Bool
28d94e
 get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
28d94e
 {
28d94e
-    drmSetVersion sv;
28d94e
     drmVersionPtr v;
28d94e
-    char *buf;
bd52eb
     int fd;
bd52eb
     int err = 0;
bd52eb
     Bool paused, server_fd = FALSE;
bd52eb
 
28d94e
+    LogMessage(X_INFO, "Platform probe for %s\n", attribs->syspath);
28d94e
+
bd52eb
     fd = systemd_logind_take_fd(attribs->major, attribs->minor, path, &paused);
bd52eb
     if (fd != -1) {
28d94e
         if (paused) {
28d94e
@@ -48,18 +48,6 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
28d94e
     if (fd == -1)
28d94e
         return FALSE;
bd52eb
 
28d94e
-    sv.drm_di_major = 1;
28d94e
-    sv.drm_di_minor = 4;
28d94e
-    sv.drm_dd_major = -1;       /* Don't care */
28d94e
-    sv.drm_dd_minor = -1;       /* Don't care */
28d94e
-
bd52eb
-    err = drmSetInterfaceVersion(fd, &sv;;
bd52eb
-    if (err) {
bd52eb
-        xf86Msg(X_ERROR, "%s: failed to set DRM interface version 1.4: %s\n",
bd52eb
-                path, strerror(-err));
bd52eb
-        goto out;
bd52eb
-    }
bd52eb
-
bd52eb
     /* for a delayed probe we've already added the device */
bd52eb
     if (delayed_index == -1) {
bd52eb
             xf86_add_platform_device(attribs, FALSE);
28d94e
@@ -69,10 +57,6 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
bd52eb
     if (server_fd)
bd52eb
         xf86_platform_devices[delayed_index].flags |= XF86_PDEV_SERVER_FD;
bd52eb
 
bd52eb
-    buf = drmGetBusid(fd);
bd52eb
-    xf86_platform_odev_attributes(delayed_index)->busid = XNFstrdup(buf);
bd52eb
-    drmFreeBusid(buf);
28d94e
-
bd52eb
     v = drmGetVersion(fd);
bd52eb
     if (!v) {
28d94e
         xf86Msg(X_ERROR, "%s: failed to query DRM version\n", path);
bd52eb
-- 
28d94e
2.19.1
bd52eb