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

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