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

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