Skip to contentSkip to conversation

drm/panic: Allows to run with fbcon

PATCH New Jocelyn Falempe 1 participant 3 messages Apr 22, 2024

Subsystems (3)
lore
Share & tools
lore

Jocelyn Falempe

author maintainer
#0 lore raw

cover drm/panic: Allows to run with fbcon

fbcon and drm_panic cannot be built together because they both write to the screen when a panic occurs, leading to a corrupted panic image. With this 2 patches, drm_panic will disable the fbdev output before writing the panic screen, so only drm_panic screen will be shown.

Jocelyn Falempe (2):
drm/fb-helper: Add drm_fb_helper_emergency_disable drm/panic: Allows to run with fbcon

 drivers/gpu/drm/Kconfig         |  2 +-
 drivers/gpu/drm/drm_fb_helper.c | 17 +++++++++++++++++
 drivers/gpu/drm/drm_panic.c     |  4 ++++
 include/drm/drm_fb_helper.h     |  5 +++++
 4 files changed, 27 insertions(+), 1 deletion(-)

base-commit: 105aa4c65b76c3a344ca89a2d2dc96c84cca557f

Signature · 1 line
2.44.0
author maintainer
#1 lore raw

PATCH 1/2 drm/fb-helper: Add drm_fb_helper_emergency_disable

This is needed for drm_panic, to disable fbcon output that will otherwise mix with drm_panic output.

---
 drivers/gpu/drm/drm_fb_helper.c | 17 +++++++++++++++++
 include/drm/drm_fb_helper.h     |  5 +++++
 2 files changed, 22 insertions(+)
drivers/gpu/drm/drm_fb_helper.c +17 -0
index d612133e2cf7e..e2e681e252e73 100644
@@ -798,6 +798,23 @@ void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper,
 }
 EXPORT_SYMBOL(drm_fb_helper_set_suspend_unlocked);
 
+/**
+ * drm_fb_helper_emergency_disable - disable fb output in panic situation
+ * @fb_helper: driver-allocated fbdev helper, can be NULL
+ *
+ * A wrapper around fb_set_suspend, to disable fb emulation when a panic occurs.
+ */
+void drm_fb_helper_emergency_disable(struct drm_fb_helper *fb_helper)
+{
+	if (fb_helper && fb_helper->info && fb_helper->info->state == FBINFO_STATE_RUNNING) {
+		if (console_trylock()) {
+			fb_set_suspend(fb_helper->info, FBINFO_STATE_SUSPENDED);
+			console_unlock();
+		}
+	}
+}
+EXPORT_SYMBOL(drm_fb_helper_emergency_disable);
+
 static int setcmap_pseudo_palette(struct fb_cmap *cmap, struct fb_info *info)
 {
 	u32 *palette = (u32 *)info->pseudo_palette;
include/drm/drm_fb_helper.h +5 -0
index 375737fd6c36e..8c61c4fe93e3b 100644
@@ -261,6 +261,7 @@ void drm_fb_helper_deferred_io(struct fb_info *info, struct list_head *pagerefli
 void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, bool suspend);
 void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper,
 					bool suspend);
+void drm_fb_helper_emergency_disable(struct drm_fb_helper *fb_helper);
 
 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
 
@@ -378,6 +379,10 @@ drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper, bool suspend
 {
 }
 
+static inline void drm_fb_helper_emergency_disable(struct drm_fb_helper *fb_helper)
+{
+}
+
 static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
 {
 	return 0;
Signature · 1 line
2.44.0
author maintainer
#2 lore raw

PATCH 2/2 drm/panic: Allows to run with fbcon

In reply to Jocelyn Falempe

Disable the framebuffer emulation when a panic occurs, to avoid fbcon to overwrite the panic screen.
So it's now safe to enable DRM_PANIC and FRAMEBUFFER_CONSOLE.

---
 drivers/gpu/drm/Kconfig     | 2 +-
 drivers/gpu/drm/drm_panic.c | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +1 -1
index 959b19a041018..7a8b1ef4c6bcf 100644
@@ -106,7 +106,7 @@ config DRM_KMS_HELPER
 
 config DRM_PANIC
 	bool "Display a user-friendly message when a kernel panic occurs"
-	depends on DRM && !FRAMEBUFFER_CONSOLE
+	depends on DRM
 	select DRM_KMS_HELPER
 	select FONT_SUPPORT
 	help
drivers/gpu/drm/drm_panic.c +4 -0
index 7ece67086cecb..c46a2b878e759 100644
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 
 #include <drm/drm_drv.h>
+#include <drm/drm_fb_helper.h>
 #include <drm/drm_format_helper.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
@@ -470,6 +471,9 @@ static void draw_panic_plane(struct drm_plane *plane)
 	int ret;
 	unsigned long flags;
 
+	/* Prevent fbcon from overwriting the panic screen */
+	drm_fb_helper_emergency_disable(plane->dev->fb_helper);
+
 	if (!drm_panic_trylock(plane->dev, flags))
 		return;
 
Signature · 1 line
2.44.0