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

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