drm/panic: Add a drm panic handler
Subsystems (3)
Jocelyn Falempe
maintainerv2 cover drm/panic: Add a drm panic handler
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.
This is a proof of concept, and works only with simpledrm, using a new get_scanout_buffer() api
To test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c > /proc/sysrq-trigger
v2
* Use get_scanout_buffer() instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)
I didn't reuse the fbdev functions yet, that would need some fbdev refactoring, because they rely on struct fb_info, and struct vc_data (for font/console). But I still plan to at least try it for v3.
A few more though:
1) what about gpu with multiple monitor connected ?
maybe get_scanout_buffer() could return a list of scanout buffers ?
2) I think for some GPU drivers, there might need a flush_scanout_buffer() function, that should be called after the scanout buffer has been filled ?
Best regards,
Jocelyn Falempe (2):
drm/panic: Add a drm panic handler
drm/simpledrm: Add drm_panic support
drivers/gpu/drm/Kconfig | 11 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 270 +++++++++++++++++++++++++++++++ drivers/gpu/drm/tiny/simpledrm.c | 17 ++ include/drm/drm_drv.h | 14 ++ include/drm/drm_panic.h | 41 +++++ 7 files changed, 357 insertions(+) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.h
base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
Signature · 1 line
2.41.0
Jocelyn Falempe
maintainerPATCH v2 1/2 drm/panic: Add a drm panic handler
This module displays a user friendly message when a kernel panic occurs. It currently doesn't contain any debug information, but that can be added later.
v2
* Use get_scanout_buffer() instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)
--- drivers/gpu/drm/Kconfig | 11 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 270 ++++++++++++++++++++++++++++++++++++ include/drm/drm_drv.h | 14 ++ include/drm/drm_panic.h | 41 ++++++ 6 files changed, 340 insertions(+) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.h
drivers/gpu/drm/Kconfig +11 -0
@@ -99,6 +99,17 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_PANIC + bool "Display a user-friendly message when a kernel panic occurs" + depends on DRM && !FRAMEBUFFER_CONSOLE + select FONT_SUPPORT + default y if DRM_SIMPLEDRM + help + Enable a drm panic handler, which will display a user-friendly message + when a kernel panic occurs. It's useful when using a user-space + console instead of fbcon. + It will only work if your graphic driver supports this feature. + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT
drivers/gpu/drm/Makefile +1 -0
@@ -72,6 +72,7 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ drm_privacy_screen_x86.o drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o obj-$(CONFIG_DRM) += drm.o +drm-$(CONFIG_DRM_PANIC) += drm_panic.o obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
drivers/gpu/drm/drm_drv.c +3 -0
@@ -45,6 +45,7 @@#include <drm/drm_mode_object.h> #include <drm/drm_print.h> #include <drm/drm_privacy_screen_machine.h> +#include <drm/drm_panic.h> #include "drm_crtc_internal.h" #include "drm_internal.h"
@@ -1067,6 +1068,7 @@ static void drm_core_exit(void)unregister_chrdev (DRM_MAJOR ,"drm" );debugfs_remove (drm_debugfs_root);drm_sysfs_destroy (); +drm_panic_exit ();idr_destroy (&drm_minors_idr);drm_connector_ida_destroy (); }
@@ -1078,6 +1080,7 @@ static int __init drm_core_init(void)drm_connector_ida_init ();idr_init (&drm_minors_idr);drm_memcpy_init_early (); +drm_panic_init (); ret =drm_sysfs_init ();if (ret <0 ) {
drivers/gpu/drm/drm_panic.c new file +270 -0
270 lines not on this page · raw message
include/drm/drm_drv.h +14 -0
@@ -43,6 +43,7 @@ struct dma_buf_attachment;struct drm_display_mode ;struct drm_mode_create_dumb ;struct drm_printer ; +struct drm_scanout_buffer ;struct sg_table ;/**
@@ -408,6 +409,19 @@ struct drm_driver {*/ void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** +* @get_scanout_buffer: +* +* Get the current scanout buffer, to display a panic message with drm_panic. +* It is called from a panic callback, and must follow its restrictions. +* +* Returns: +* +* Zero on success, negative errno on failure. +*/ +int (*get_scanout_buffer)(struct drm_device *dev, +struct drm_scanout_buffer *sb); +/** @major: driver major number */ int major;/** @minor: driver minor number */
include/drm/drm_panic.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.41.0
Jocelyn Falempe
maintainerPATCH v2 2/2 drm/simpledrm: Add drm_panic support
In reply to Jocelyn FalempeAdd support for the drm_panic module, which displays a user-friendly message to the screen when a kernel panic occurs.
--- drivers/gpu/drm/tiny/simpledrm.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +17 -0
@@ -23,6 +23,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_managed.h> #include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_panic.h> #include <drm/drm_plane_helper.h> #include <drm/drm_probe_helper.h>
@@ -838,10 +839,24 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,return ERR_PTR (ret);drm_mode_config_reset (dev); +drm_panic_register (dev);return sdev; } +static int simpledrm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct simpledrm_device *sdev =simpledrm_device_of_dev (dev); + + sb->width = sdev->mode.hdisplay; + sb->height = sdev->mode.vdisplay; + sb->pitch = sdev->pitch; + sb->format = sdev->format; + sb->map = sdev->screen_base; +return 0 ; +} +/* * DRM driver */
@@ -857,6 +872,7 @@ static struct drm_driver simpledrm_driver = { .minor = DRIVER_MINOR, .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, .fops = &simpledrm_fops, + .get_scanout_buffer = simpledrm_get_scanout_buffer, };/*
@@ -894,6 +910,7 @@ static int simpledrm_remove(struct platform_device *pdev)struct drm_device *dev = &sdev->dev;drm_dev_unplug (dev); +drm_panic_unregister (dev);return 0 ; }
Signature · 1 line
2.41.0
Quoted 12 lines · EDT Jocelyn Falempe
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.This is a proof of concept, and works only with simpledrm, using a new
get_scanout_buffer()apiTo test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c >/proc/sysrq-trigger
This seems to work pretty good! With this one, I don't need to have Weston (or another display server) running for it to work this time. The panic reason works, which is pretty sweet.
FYI: I do get a hunk that fails to apply in simpledrm_remove in drivers/gpu/drm/tiny/simpledrm.c Seems to be a change in a recentish commit
https://github.com/torvalds/linux/commit/84e6da7ad5537826343636b846530ec2167d4a19
Thanks!
Quoted 32 lines
v2
* Useget_scanout_buffer()instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)I didn't reuse the fbdev functions yet, that would need some fbdev refactoring, because they rely on struct
fb_info, and structvc_data(for font/console). But I still plan to at least try it for v3.A few more though:
1) what about gpu with multiple monitor connected ?
maybeget_scanout_buffer()could return a list of scanout buffers ?
2) I think for some GPU drivers, there might need aflush_scanout_buffer()function, that should be called after the scanout buffer has been filled ?Best regards,
Jocelyn Falempe (2):
drm/panic: Add a drm panic handler
drm/simpledrm: Adddrm_panicsupportdrivers/gpu/drm/Kconfig | 11 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 270 +++++++++++++++++++++++++++++++ drivers/gpu/drm/tiny/simpledrm.c | 17 ++ include/drm/drm_drv.h | 14 ++ include/drm/drm_panic.h | 41 +++++ 7 files changed, 357 insertions(+) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.hbase-commit:
2dde18cd1d8fac735875f2e4987f11817cc0bc2c
Jocelyn Falempe
maintainerQuoted 8 lines · nerdopolis
Quoted 7 lines · EDT Jocelyn Falempe
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.
Quoted 7 lines
Quoted 5 lines
This is a proof of concept, and works only with simpledrm, using a new
get_scanout_buffer()apiTo test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c >/proc/sysrq-triggerThis seems to work pretty good! With this one, I don't need to have Weston (or another display server) running for it to work this time. The panic reason works, which is pretty sweet.
Thanks for testing, that's really appreciated.
Quoted 4 lines
FYI: I do get a hunk that fails to apply in
simpledrm_removeindrivers/gpu/drm/tiny/simpledrm.cSeems to be a change in a recentish commit
https://github.com/torvalds/linux/commit/84e6da7ad5537826343636b846530ec2167d4a19
Thanks for the head-up, when doing this RFC, I'm based on latest released version v6.5, to avoid having to rebase too often. When it's closer to merging, I will rebase to drm-misc-next.
Best regards,
Signature · 1 line
Jocelyn
Hi,
Quoted 9 lines · Jocelyn Falempe
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.This is a proof of concept, and works only with simpledrm, using a new
get_scanout_buffer()api
There's a panic handling entry in Documentation/gpu/todo.rst pointing to some work done in this area.
Noralf.
Quoted 34 lines
To test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c >/proc/sysrq-triggerv2
* Useget_scanout_buffer()instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)I didn't reuse the fbdev functions yet, that would need some fbdev refactoring, because they rely on struct
fb_info, and structvc_data(for font/console). But I still plan to at least try it for v3.A few more though:
1) what about gpu with multiple monitor connected ?
maybeget_scanout_buffer()could return a list of scanout buffers ?
2) I think for some GPU drivers, there might need aflush_scanout_buffer()function, that should be called after the scanout buffer has been filled ?Best regards,
Jocelyn Falempe (2):
drm/panic: Add a drm panic handler
drm/simpledrm: Adddrm_panicsupportdrivers/gpu/drm/Kconfig | 11 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 270 +++++++++++++++++++++++++++++++ drivers/gpu/drm/tiny/simpledrm.c | 17 ++ include/drm/drm_drv.h | 14 ++ include/drm/drm_panic.h | 41 +++++ 7 files changed, 357 insertions(+) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.hbase-commit:
2dde18cd1d8fac735875f2e4987f11817cc0bc2c
Jocelyn Falempe
maintainerQuoted 10 lines · Noralf Trønnes
Hi,
Quoted 7 lines · Jocelyn Falempe
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.
Quoted 5 lines
Quoted 2 lines
This is a proof of concept, and works only with simpledrm, using a new
get_scanout_buffer()apiThere's a panic handling entry in
Documentation/gpu/todo.rstpointing to some work done in this area.
Thanks a lot for this pointer, I wasn't aware of this previous drm panic attempt. I hope this one will go a bit further ;) Also I wasn't sure about what is allowed or not in the panic handler, and this doc makes things really clear.
Regarding the fbcon interactions, I prevent this at build time, I rely on userspace consoles, and hope they will progressively replace fbcon.
My real question is how did I missed that ? My google-fu failed me this time.
Best regards,
Signature · 1 line
Jocelyn
Quoted 38 lines
Noralf.
Quoted 34 lines
To test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c >/proc/sysrq-triggerv2
* Useget_scanout_buffer()instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)I didn't reuse the fbdev functions yet, that would need some fbdev refactoring, because they rely on struct
fb_info, and structvc_data(for font/console). But I still plan to at least try it for v3.A few more though:
1) what about gpu with multiple monitor connected ?
maybeget_scanout_buffer()could return a list of scanout buffers ?
2) I think for some GPU drivers, there might need aflush_scanout_buffer()function, that should be called after the scanout buffer has been filled ?Best regards,
Jocelyn Falempe (2):
drm/panic: Add a drm panic handler
drm/simpledrm: Adddrm_panicsupportdrivers/gpu/drm/Kconfig | 11 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 270 +++++++++++++++++++++++++++++++ drivers/gpu/drm/tiny/simpledrm.c | 17 ++ include/drm/drm_drv.h | 14 ++ include/drm/drm_panic.h | 41 +++++ 7 files changed, 357 insertions(+)create mode 100644
drivers/gpu/drm/drm_panic.c
create mode 100644include/drm/drm_panic.hbase-commit:
2dde18cd1d8fac735875f2e4987f11817cc0bc2c