xserver: Branch 'server-1.20-branch' - 3 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 18 17:25:23 UTC 2020


 config/udev.c                              |   42 +++++++++++++++++++++++++----
 hw/xfree86/os-support/linux/lnx_platform.c |   20 +------------
 2 files changed, 39 insertions(+), 23 deletions(-)

New commits:
commit 249a12c54a9316b089bd22683c011519348496df
Author: Huacai Chen <chenhc at lemote.com>
Date:   Sun Jul 5 05:59:58 2020 -0400

    linux: Fix platform device probe for DT-based PCI
    
    On a DT-base PCI platform, the sysfs path of vga device is like this:
    /sys/devices/platform/bus at 10000000/1a000000.pci/pci0000:00/0000:00:11.0/0000:04:00.0.
    
    Then the ID_PATH from udev is platform-1a000000.pci-pci-0000:04:00.0 and
    the BusID will be pci-0000:04:00.0, which causes Xorg start fail. This
    is because config_udev_odev_setup_attribs() use strstr() to search the
    first "pci-" in ID_PATH. To fix this, we implement a strrstr() function
    and use it to search the last "pci-" in ID_PATH, which can get a correct
    BusID.
    
    (backported from commit 9fbd3e43dd9e13700df96b508c3d97f77e2b9f7e)
    
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Huacai Chen <chenhc at lemote.com>

diff --git a/config/udev.c b/config/udev.c
index 14409549b..b00d90237 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -464,6 +464,31 @@ config_udev_fini(void)
 
 #ifdef CONFIG_UDEV_KMS
 
+/* Find the last occurrence of the needle in haystack */
+static char *strrstr(const char *haystack, const char *needle)
+{
+    char *prev, *last, *tmp;
+
+    prev = strstr(haystack, needle);
+    if (!prev)
+        return NULL;
+
+    last = prev;
+    tmp = prev + 1;
+
+    while (tmp) {
+        last = strstr(tmp, needle);
+        if (!last)
+            return prev;
+        else {
+            prev = last;
+            tmp = prev + 1;
+        }
+    }
+
+    return last;
+}
+
 static void
 config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path, const char *syspath,
                                int major, int minor,
@@ -478,7 +503,7 @@ config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path
     attribs->minor = minor;
 
     value = udev_device_get_property_value(udev_device, "ID_PATH");
-    if (value && (str = strstr(value, "pci-"))) {
+    if (value && (str = strrstr(value, "pci-"))) {
         attribs->busid = XNFstrdup(str);
         attribs->busid[3] = ':';
     }
commit 5c96eb5f44e62a4cfe835023cde304eb5795b8fd
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Jun 19 14:23:56 2019 -0400

    linux: Fix platform device PCI detection for complex bus topologies
    
    Suppose you're in a Hyper-V guest and are trying to use PCI passthrough.
    The ID_PATH that udev will construct for that looks something like
    "acpi-VMBUS:00-pci-b8c8:00:00.0", and obviously looking for "pci-" in
    the first four characters of that is going to not work.
    
    Instead, strstr. I suppose it's possible you could have _multiple_ PCI
    buses in the path, in which case you'd want strrstr, if that were a
    thing.
    
    (backported from commit 9acff309434a8029bcce1b22530043459bb71791)
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Huacai Chen <chenhc at lemote.com>

diff --git a/config/udev.c b/config/udev.c
index 8c6c4b666..14409549b 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -470,7 +470,7 @@ config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path
                                config_odev_probe_proc_ptr probe_callback)
 {
     struct OdevAttributes *attribs = config_odev_allocate_attributes();
-    const char *value;
+    const char *value, *str;
 
     attribs->path = XNFstrdup(path);
     attribs->syspath = XNFstrdup(syspath);
@@ -478,8 +478,8 @@ config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path
     attribs->minor = minor;
 
     value = udev_device_get_property_value(udev_device, "ID_PATH");
-    if (value && !strncmp(value, "pci-", 4)) {
-        attribs->busid = XNFstrdup(value);
+    if (value && (str = strstr(value, "pci-"))) {
+        attribs->busid = XNFstrdup(str);
         attribs->busid[3] = ':';
     }
 
commit 74b7427c41b4e4104af7abf70a996c086d3d7628
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Sep 18 14:37:51 2018 -0400

    linux: Make platform device probe less fragile
    
    At the point where xf86BusProbe runs we haven't yet taken our own VT,
    which means we can't perform drm "master" operations on the device. This
    is tragic, because we need master to fish the bus id string out of the
    kernel, which we can only do after drmSetInterfaceVersion, which for
    some reason stores that string on the device not the file handle and
    thus needs master access.
    
    Fortunately we know the format of the busid string, and it happens to
    almost be the same as the ID_PATH variable from udev. Use that instead
    and stop calling drmSetInterfaceVersion.
    
    (backported from commit 0816e8fca6194dfb4cc94c3a7fcb2c7f2a921386)
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Huacai Chen <chenhc at lemote.com>

diff --git a/config/udev.c b/config/udev.c
index 3a73189e2..8c6c4b666 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -56,7 +56,7 @@ static struct udev_monitor *udev_monitor;
 
 #ifdef CONFIG_UDEV_KMS
 static void
-config_udev_odev_setup_attribs(const char *path, const char *syspath,
+config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path, const char *syspath,
                                int major, int minor,
                                config_odev_probe_proc_ptr probe_callback);
 #endif
@@ -128,7 +128,7 @@ device_added(struct udev_device *udev_device)
 
         LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
 
-        config_udev_odev_setup_attribs(path, syspath, major(devnum),
+        config_udev_odev_setup_attribs(udev_device, path, syspath, major(devnum),
                                        minor(devnum), NewGPUDeviceRequest);
         return;
     }
@@ -322,7 +322,7 @@ device_removed(struct udev_device *device)
 
         LogMessage(X_INFO, "config/udev: removing GPU device %s %s\n",
                    syspath, path);
-        config_udev_odev_setup_attribs(path, syspath, major(devnum),
+        config_udev_odev_setup_attribs(device, path, syspath, major(devnum),
                                        minor(devnum), DeleteGPUDeviceRequest);
         /* Retry vtenter after a drm node removal */
         systemd_logind_vtenter();
@@ -465,17 +465,24 @@ config_udev_fini(void)
 #ifdef CONFIG_UDEV_KMS
 
 static void
-config_udev_odev_setup_attribs(const char *path, const char *syspath,
+config_udev_odev_setup_attribs(struct udev_device *udev_device, const char *path, const char *syspath,
                                int major, int minor,
                                config_odev_probe_proc_ptr probe_callback)
 {
     struct OdevAttributes *attribs = config_odev_allocate_attributes();
+    const char *value;
 
     attribs->path = XNFstrdup(path);
     attribs->syspath = XNFstrdup(syspath);
     attribs->major = major;
     attribs->minor = minor;
 
+    value = udev_device_get_property_value(udev_device, "ID_PATH");
+    if (value && !strncmp(value, "pci-", 4)) {
+        attribs->busid = XNFstrdup(value);
+        attribs->busid[3] = ':';
+    }
+
     /* ownership of attribs is passed to probe layer */
     probe_callback(attribs);
 }
@@ -516,7 +523,7 @@ config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback)
         else if (!check_seat(udev_device))
             goto no_probe;
 
-        config_udev_odev_setup_attribs(path, syspath, major(devnum),
+        config_udev_odev_setup_attribs(udev_device, path, syspath, major(devnum),
                                        minor(devnum), probe_callback);
     no_probe:
         udev_device_unref(udev_device);
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
index 70374ace8..e62306219 100644
--- a/hw/xfree86/os-support/linux/lnx_platform.c
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -23,13 +23,13 @@
 static Bool
 get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
 {
-    drmSetVersion sv;
     drmVersionPtr v;
-    char *buf;
     int fd;
     int err = 0;
     Bool paused, server_fd = FALSE;
 
+    LogMessage(X_INFO, "Platform probe for %s\n", attribs->syspath);
+
     fd = systemd_logind_take_fd(attribs->major, attribs->minor, path, &paused);
     if (fd != -1) {
         if (paused) {
@@ -48,18 +48,6 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
     if (fd == -1)
         return FALSE;
 
-    sv.drm_di_major = 1;
-    sv.drm_di_minor = 4;
-    sv.drm_dd_major = -1;       /* Don't care */
-    sv.drm_dd_minor = -1;       /* Don't care */
-
-    err = drmSetInterfaceVersion(fd, &sv);
-    if (err) {
-        xf86Msg(X_ERROR, "%s: failed to set DRM interface version 1.4: %s\n",
-                path, strerror(-err));
-        goto out;
-    }
-
     /* for a delayed probe we've already added the device */
     if (delayed_index == -1) {
             xf86_add_platform_device(attribs, FALSE);
@@ -69,10 +57,6 @@ get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index)
     if (server_fd)
         xf86_platform_devices[delayed_index].flags |= XF86_PDEV_SERVER_FD;
 
-    buf = drmGetBusid(fd);
-    xf86_platform_odev_attributes(delayed_index)->busid = XNFstrdup(buf);
-    drmFreeBusid(buf);
-
     v = drmGetVersion(fd);
     if (!v) {
         xf86Msg(X_ERROR, "%s: failed to query DRM version\n", path);


More information about the xorg-commit mailing list