Blame SOURCES/0001-xf86-logind-Fix-drm_drop_master-before-vt_reldisp.patch

3f8e74
From dafe5f6358edd557d89bb63265d6df2e1249f106 Mon Sep 17 00:00:00 2001
3f8e74
From: Jocelyn Falempe <jfalempe@redhat.com>
3f8e74
Date: Thu, 18 Nov 2021 14:45:42 +0100
3f8e74
Subject: [PATCH] xf86/logind: fix call systemd_logind_vtenter after receiving
3f8e74
 drm device resume
3f8e74
3f8e74
logind send the resume event for input devices and drm device,
3f8e74
in any order. if we call vt_enter before logind resume the drm device,
3f8e74
it leads to a driver error, because logind has not done the
3f8e74
DRM_IOCTL_SET_MASTER on it.
3f8e74
3f8e74
Keep the old workaround to make sure we call systemd_logind_vtenter at
3f8e74
least once if there are no platform device
3f8e74
3f8e74
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
3f8e74
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
3f8e74
3f8e74
xf86/logind: Fix drm_drop_master before vt_reldisp
3f8e74
3f8e74
When switching to VT, the ioctl DRM_DROP_MASTER must be done before
3f8e74
the ioctl VT_RELDISP. Otherwise the kernel can't change the modesetting
3f8e74
reliably, and this leads to the console not showing up in some cases, like
3f8e74
after unplugging a docking station with a DP or HDMI monitor.
3f8e74
3f8e74
Before doing the VT_RELDISP, send a dbus message to logind, to
3f8e74
pause the drm device, so logind will do the ioctl DRM_DROP_MASTER.
3f8e74
3f8e74
With this patch, it changes the order logind will send the resume
3f8e74
event, and drm will be sent last instead of first.
3f8e74
so there is a also fix to call systemd_logind_vtenter() at the right time.
3f8e74
3f8e74
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
3f8e74
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
3f8e74
3f8e74
xf86/logind: Fix compilation error when built without logind/platform bus
3f8e74
3f8e74
This was introduced by commit 8eb1396d
3f8e74
3f8e74
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1269
3f8e74
Fixes: da9d012a9 - xf86/logind: Fix drm_drop_master before vt_reldisp
3f8e74
3f8e74
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
3f8e74
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
3f8e74
3f8e74
xf86/logind: fix missing call to vtenter if the platform device is not paused
3f8e74
3f8e74
If there is one platform device, which is not paused nor resumed,
3f8e74
systemd_logind_vtenter() will never get called.
3f8e74
This break suspend/resume, and switching to VT on system with Nvidia
3f8e74
proprietary driver.
3f8e74
This is a regression introduced by f5bd039633fa83
3f8e74
3f8e74
So now call systemd_logind_vtenter() if there are no paused
3f8e74
platform devices.
3f8e74
3f8e74
Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1271
3f8e74
Fixes: f5bd0396 - xf86/logind: fix call systemd_logind_vtenter after receiving drm device resume
3f8e74
3f8e74
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
3f8e74
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
3f8e74
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
3f8e74
---
3f8e74
 hw/xfree86/common/xf86Events.c               |  4 ++
3f8e74
 hw/xfree86/os-support/linux/systemd-logind.c | 41 +++++++++++++++++---
3f8e74
 include/systemd-logind.h                     |  2 +
3f8e74
 3 files changed, 42 insertions(+), 5 deletions(-)
3f8e74
3f8e74
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
3f8e74
index 8a800bd8f..b683d233b 100644
3f8e74
--- a/hw/xfree86/common/xf86Events.c
3f8e74
+++ b/hw/xfree86/common/xf86Events.c
3f8e74
@@ -393,6 +393,10 @@ xf86VTLeave(void)
3f8e74
     for (i = 0; i < xf86NumGPUScreens; i++)
3f8e74
         xf86GPUScreens[i]->LeaveVT(xf86GPUScreens[i]);
3f8e74
 
3f8e74
+    if (systemd_logind_controls_session()) {
3f8e74
+        systemd_logind_drop_master();
3f8e74
+    }
3f8e74
+
3f8e74
     if (!xf86VTSwitchAway())
3f8e74
         goto switch_failed;
3f8e74
 
3f8e74
diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c
3f8e74
index 13784d15c..bd7a341f0 100644
3f8e74
--- a/hw/xfree86/os-support/linux/systemd-logind.c
3f8e74
+++ b/hw/xfree86/os-support/linux/systemd-logind.c
3f8e74
@@ -302,6 +302,37 @@ cleanup:
3f8e74
     dbus_error_free(&error);
3f8e74
 }
3f8e74
 
3f8e74
+/*
3f8e74
+ * Send a message to logind, to pause the drm device
3f8e74
+ * and ensure the drm_drop_master is done before
3f8e74
+ * VT_RELDISP when switching VT
3f8e74
+ */
3f8e74
+void systemd_logind_drop_master(void)
3f8e74
+{
3f8e74
+    int i;
3f8e74
+    for (i = 0; i < xf86_num_platform_devices; i++) {
3f8e74
+        if (xf86_platform_devices[i].flags & XF86_PDEV_SERVER_FD) {
3f8e74
+            dbus_int32_t major, minor;
3f8e74
+            struct systemd_logind_info *info = &logind_info;
3f8e74
+
3f8e74
+            xf86_platform_devices[i].flags |= XF86_PDEV_PAUSED;
3f8e74
+            major = xf86_platform_odev_attributes(i)->major;
3f8e74
+            minor = xf86_platform_odev_attributes(i)->minor;
3f8e74
+            systemd_logind_ack_pause(info, minor, major);
3f8e74
+        }
3f8e74
+    }
3f8e74
+}
3f8e74
+
3f8e74
+static Bool are_platform_devices_resumed(void) {
3f8e74
+    int i;
3f8e74
+    for (i = 0; i < xf86_num_platform_devices; i++) {
3f8e74
+        if (xf86_platform_devices[i].flags & XF86_PDEV_PAUSED) {
3f8e74
+            return FALSE;
3f8e74
+        }
3f8e74
+    }
3f8e74
+    return TRUE;
3f8e74
+}
3f8e74
+
3f8e74
 static DBusHandlerResult
3f8e74
 message_filter(DBusConnection * connection, DBusMessage * message, void *data)
3f8e74
 {
3f8e74
@@ -417,14 +448,14 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data)
3f8e74
         /* info->vt_active gets set by systemd_logind_vtenter() */
3f8e74
         info->active = TRUE;
3f8e74
 
3f8e74
-        if (pdev)
3f8e74
+        if (pdev) {
3f8e74
             pdev->flags &= ~XF86_PDEV_PAUSED;
3f8e74
-        else
3f8e74
+        } else
3f8e74
             systemd_logind_set_input_fd_for_all_devs(major, minor, fd,
3f8e74
                                                      info->vt_active);
3f8e74
-
3f8e74
-        /* Always call vtenter(), in case there are only legacy video devs */
3f8e74
-        systemd_logind_vtenter();
3f8e74
+        /* Call vtenter if all platform devices are resumed, or if there are no platform device */
3f8e74
+        if (are_platform_devices_resumed())
3f8e74
+            systemd_logind_vtenter();
3f8e74
     }
3f8e74
     return DBUS_HANDLER_RESULT_HANDLED;
3f8e74
 }
3f8e74
diff --git a/include/systemd-logind.h b/include/systemd-logind.h
3f8e74
index a4067d097..5c04d0130 100644
3f8e74
--- a/include/systemd-logind.h
3f8e74
+++ b/include/systemd-logind.h
3f8e74
@@ -33,6 +33,7 @@ int systemd_logind_take_fd(int major, int minor, const char *path, Bool *paus);
3f8e74
 void systemd_logind_release_fd(int major, int minor, int fd);
3f8e74
 int systemd_logind_controls_session(void);
3f8e74
 void systemd_logind_vtenter(void);
3f8e74
+void systemd_logind_drop_master(void);
3f8e74
 #else
3f8e74
 #define systemd_logind_init()
3f8e74
 #define systemd_logind_fini()
3f8e74
@@ -40,6 +41,7 @@ void systemd_logind_vtenter(void);
3f8e74
 #define systemd_logind_release_fd(major, minor, fd) close(fd)
3f8e74
 #define systemd_logind_controls_session() 0
3f8e74
 #define systemd_logind_vtenter()
3f8e74
+#define systemd_logind_drop_master()
3f8e74
 #endif
3f8e74
 
3f8e74
 #endif
3f8e74
-- 
3f8e74
2.33.1
3f8e74