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

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