drm/panic: Cleanup and add panic description
Subsystems (3)
Jocelyn Falempe
maintainerv2 cover drm/panic: Cleanup and add panic description
This small series removes unused export symbols, moves internal include to drm_crtc_internal.h, and adds the panic description, now that kmsg_dump provides this information.
v2:
* Use a macro PANIC_MSG_LINES, instead of directly using the indice in drm_panic_set_description() (Sima)
* Add drm_panic_clear_description() to make sure the stack allocated pointer won't be used. (Sima)
* use the macro PANIC_MSG_LINES also in draw_panic_static_user()
Jocelyn Falempe (5):
drm/panic: Remove space before "!" in panic message drm/panic: Remove useless export symbols
drm/panic: Move drm_panic_register prototype to drm_crtc_internal.h drm/panic: Move copyright notice to the top
drm/panic: Add panic description
drivers/gpu/drm/drm_crtc_internal.h | 4 ++ drivers/gpu/drm/drm_panic.c | 60 +++++++++++++++++++++-------- include/drm/drm_panic.h | 21 +++------- 3 files changed, 54 insertions(+), 31 deletions(-)
base-commit: f7f3ddb6e5c8dc7b621fd8c0903ea42190d67452
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 1/5 drm/panic: Remove space before "!" in panic message
There is no space between the last word, and the punctuation mark in English.
--- drivers/gpu/drm/drm_panic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_panic.c +1 -1
@@ -78,7 +78,7 @@ struct drm_panic_line {#define PANIC_LINE (s) {.len = sizeof(s) - 1, .txt = s}static struct drm_panic_line panic_msg[] = { -PANIC_LINE ("KERNEL PANIC !" ), +PANIC_LINE ("KERNEL PANIC!" ),PANIC_LINE ("" ),PANIC_LINE ("Please reboot your computer." ), };
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 2/5 drm/panic: Remove useless export symbols
In reply to Jocelyn Falempedrm_panic_[un]register() are called only from the core drm, so there is no need to export them.
--- drivers/gpu/drm/drm_panic.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_panic.c +0 -2
@@ -752,7 +752,6 @@ void drm_panic_register(struct drm_device *dev)if (registered_plane)drm_info (dev,"Registered %d planes with drm panic\n" , registered_plane); } -EXPORT_SYMBOL (drm_panic_register);/** * drm_panic_unregister()
@@ -771,4 +770,3 @@ void drm_panic_unregister(struct drm_device *dev)kmsg_dump_unregister (&plane->kmsg_panic); } } -EXPORT_SYMBOL (drm_panic_unregister);
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 3/5 drm/panic: Move drm_panic_register prototype to drm_crtc_internal.h
In reply to Jocelyn Falempedrm_panic_[un]register() are only used by the core drm, and are not intended to be called by other drm drivers, so move their prototypes to drm_crtc_internal.h.
--- drivers/gpu/drm/drm_crtc_internal.h | 4 ++++ include/drm/drm_panic.h | 12 ------------ 2 files changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/drm_crtc_internal.h +4 -0
@@ -318,8 +318,12 @@ drm_edid_load_firmware(struct drm_connector *connector)/* drm_panic.c */ #ifdef CONFIG_DRM_PANIC bool drm_panic_is_enabled (struct drm_device *dev); +void drm_panic_register (struct drm_device *dev); +void drm_panic_unregister (struct drm_device *dev);#else static inline bool drm_panic_is_enabled (struct drm_device *dev) {return false; } +static inline void drm_panic_register (struct drm_device *dev) {} +static inline void drm_panic_unregister (struct drm_device *dev) {}#endif #endif /* __DRM_CRTC_INTERNAL_H__ */
include/drm/drm_panic.h +0 -12
@@ -146,16 +146,4 @@ struct drm_scanout_buffer {#define drm_panic_unlock (dev, flags) \ raw_spin_unlock_irqrestore(&(dev)->mode_config.panic_lock, flags) -#ifdef CONFIG_DRM_PANIC - -void drm_panic_register (struct drm_device *dev); -void drm_panic_unregister (struct drm_device *dev); - -#else - -static inline void drm_panic_register (struct drm_device *dev) {} -static inline void drm_panic_unregister (struct drm_device *dev) {} - -#endif -#endif /* __DRM_PANIC_H__ */
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 4/5 drm/panic: Move copyright notice to the top
In reply to Jocelyn FalempeMove the copyright notice to the top of drm_panic.h, and add the missing Red Hat copyright notice.
--- include/drm/drm_panic.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
include/drm/drm_panic.h +6 -3
@@ -1,4 +1,10 @@/* SPDX-License-Identifier: GPL-2.0 or MIT */ + +/* +* Copyright (c) 2024 Intel +* Copyright (c) 2024 Red Hat +*/ +#ifndef __DRM_PANIC_H__#define __DRM_PANIC_H__
@@ -8,9 +14,6 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> -/* -* Copyright (c) 2024 Intel -*/ /** * struct drm_scanout_buffer - DRM scanout buffer
Signature · 1 line
2.45.2
Jocelyn Falempe
maintainerPATCH v2 5/5 drm/panic: Add panic description
In reply to Jocelyn FalempeNow that kmsg dump callback has the description parameter, use it in the user panic screen.
This is the string passed to panic(), like "VFS: Unable to mount root fs on xxx" or "Attempted to kill init! exitcode=0xxxx".
It gives a hint on why the panic occurred, without being too cryptic.
---
v2:
* Use a macro PANIC_MSG_LINES, instead of directly using the indice in drm_panic_set_description() (Sima)
* Add drm_panic_clear_description() to make sure the stack allocated pointer won't be used. (Sima)
* use the macro PANIC_MSG_LINES also in draw_panic_static_user()
drivers/gpu/drm/drm_panic.c | 56 ++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_panic.c +43 -13
@@ -81,7 +81,10 @@ static struct drm_panic_line panic_msg[] = {PANIC_LINE ("KERNEL PANIC!" ),PANIC_LINE ("" ),PANIC_LINE ("Please reboot your computer." ), +PANIC_LINE ("" ), + PANIC_LINE(""), /* will be replaced by the panic description */ }; +#define PANIC_MSG_LINES ARRAY_SIZE(panic_msg)static const struct drm_panic_line logo_ascii[] = { PANIC_LINE(" .--. _"),
@@ -92,6 +95,7 @@ static const struct drm_panic_line logo_ascii[] = {PANIC_LINE (" /'\\_ _/`\\ (_)" ), PANIC_LINE(" \\___)=(___/"), }; +#define PANIC_LOGO_LINES ARRAY_SIZE(logo_ascii)#if defined(CONFIG_LOGO ) && !defined(MODULE )static const struct linux_logo *logo_mono;
@@ -487,13 +491,12 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,static void draw_panic_static_user (struct drm_scanout_buffer *sb) { -size_t msg_lines =ARRAY_SIZE (panic_msg); -size_t logo_ascii_lines =ARRAY_SIZE (logo_ascii);u32 fg_color =convert_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);u32 bg_color =convert_from_xrgb8888 (CONFIG_DRM_PANIC_BACKGROUND_COLOR , sb->format->format);const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg;unsigned int logo_width, logo_height; +unsigned int msg_width, msg_height;if (!font)return ;
@@ -504,14 +507,14 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb) logo_width = logo_mono->width; logo_height = logo_mono->height; }else { - logo_width =get_max_line_len (logo_ascii, logo_ascii_lines) * font->width; - logo_height = logo_ascii_lines * font->height; + logo_width =get_max_line_len (logo_ascii,PANIC_LOGO_LINES ) * font->width; + logo_height =PANIC_LOGO_LINES * font->height; } - r_logo =DRM_RECT_INIT (0 ,0 , logo_width, logo_height); - r_msg =DRM_RECT_INIT (0 ,0 , -min (get_max_line_len (panic_msg, msg_lines) * font->width, sb->width), -min (msg_lines * font->height, sb->height)); + + msg_width =min (get_max_line_len (panic_msg,PANIC_MSG_LINES ) * font->width, sb->width); + msg_height =min (PANIC_MSG_LINES * font->height, sb->height); + r_msg =DRM_RECT_INIT (0 ,0 , msg_width, msg_height);/* Center the panic message */ drm_rect_translate (&r_msg, (sb->width - r_msg.x2) /2 , (sb->height - r_msg.y2) /2 );
@@ -525,10 +528,10 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)drm_panic_blit (sb, &r_logo, logo_mono->data,DIV_ROUND_UP (logo_width,8 ), fg_color); else - draw_txt_rectangle(sb, font, logo_ascii, logo_ascii_lines, false, &r_logo, + draw_txt_rectangle(sb, font, logo_ascii, PANIC_LOGO_LINES, false, &r_logo, fg_color); } -draw_txt_rectangle (sb, font, panic_msg, msg_lines, true, &r_msg, fg_color); +draw_txt_rectangle (sb, font, panic_msg,PANIC_MSG_LINES , true, &r_msg, fg_color); }/*
@@ -633,7 +636,31 @@ static void draw_panic_dispatch(struct drm_scanout_buffer *sb) } } -static void draw_panic_plane (struct drm_plane *plane) +static void drm_panic_set_description (const char *description) +{ +u32 len; + +if (description) { +struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES -1 ]; + + desc_line->txt = description; + len =strlen (description); +/* ignore the last newline character */ +if (len && description[len -1 ] =='\n' ) + len -=1 ; + desc_line->len = len; + } +} + +static void drm_panic_clear_description (void ) +{ +struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES -1 ]; + + desc_line->len =0 ; + desc_line->txt =NULL ; +} + +static void draw_panic_plane (struct drm_plane *plane,const char *description) {struct drm_scanout_buffer sb = { };int ret;
@@ -642,6 +669,8 @@ static void draw_panic_plane(struct drm_plane *plane)if (!drm_panic_trylock (plane->dev, flags))return ; +drm_panic_set_description (description); + ret = plane->helper_private->get_scanout_buffer (plane, &sb);if (!ret &&drm_panic_is_format_supported (sb.format)) {
@@ -649,6 +678,7 @@ static void draw_panic_plane(struct drm_plane *plane)if (plane->helper_private->panic_flush) plane->helper_private->panic_flush (plane); } +drm_panic_clear_description ();drm_panic_unlock (plane->dev, flags); }
@@ -662,7 +692,7 @@ static void drm_panic(struct kmsg_dumper *dumper, struct kmsg_dump_detail *detaistruct drm_plane *plane =to_drm_plane (dumper);if (detail->reason ==KMSG_DUMP_PANIC ) -draw_panic_plane (plane); +draw_panic_plane (plane, detail->description); }
@@ -682,7 +712,7 @@ static ssize_t debugfs_trigger_write(struct file *file, const char __user *user_if (kstrtobool_from_user (user_buf, count, &run) ==0 && run) {struct drm_plane *plane = file->private_data; -draw_panic_plane (plane); +draw_panic_plane (plane,"Test from debugfs" ); }return count; }
Signature · 1 line
2.45.2
Re: [PATCH v2 5/5] drm/panic: Add panic description
Quoted 6 lines · Jocelyn Falempe
Now that kmsg dump callback has the description parameter, use it in the user panic screen.
This is the string passed topanic(), like "VFS: Unable to mount root fs on xxx" or "Attempted to kill init! exitcode=0xxxx".
It gives a hint on why the panic occurred, without being too cryptic.
Quoted 8 lines
Signed-off-by Jocelyn Falempe <[email protected]>Reviewed-by Thomas Zimmermann <[email protected]>---
v2:
* Use a macroPANIC_MSG_LINES, instead of directly using the indice indrm_panic_set_description()(Sima)
* Adddrm_panic_clear_description()to make sure the stack allocated pointer won't be used. (Sima)
* use the macroPANIC_MSG_LINESalso indraw_panic_static_user()
Quoted 147 lines
drivers/gpu/drm/drm_panic.c | 56 ++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-)drivers/gpu/drm/drm_panic.c +43
-13@@ -81,7 +81,10 @@ static struct drm_panic_line panic_msg[] = {PANIC_LINE ("KERNEL PANIC!" ),PANIC_LINE ("" ),PANIC_LINE ("Please reboot your computer." ), +PANIC_LINE ("" ), + PANIC_LINE(""), /* will be replaced by the panic description */ }; +#define PANIC_MSG_LINES ARRAY_SIZE(panic_msg)static const struct drm_panic_line logo_ascii[] = { PANIC_LINE(" .--. _"),@@ -92,6 +95,7 @@ static const struct drm_panic_line logo_ascii[] = {PANIC_LINE (" /'\\_ _/`\\ (_)" ), PANIC_LINE(" \\___)=(___/"), }; +#define PANIC_LOGO_LINES ARRAY_SIZE(logo_ascii)#if defined(CONFIG_LOGO ) && !defined(MODULE )static const struct linux_logo *logo_mono;@@ -487,13 +491,12 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,static void draw_panic_static_user (struct drm_scanout_buffer *sb) { -size_t msg_lines =ARRAY_SIZE (panic_msg); -size_t logo_ascii_lines =ARRAY_SIZE (logo_ascii);u32 fg_color =convert_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);u32 bg_color =convert_from_xrgb8888 (CONFIG_DRM_PANIC_BACKGROUND_COLOR , sb->format->format);const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg;unsigned int logo_width, logo_height; +unsigned int msg_width, msg_height;if (!font)return ;@@ -504,14 +507,14 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb) logo_width = logo_mono->width; logo_height = logo_mono->height; }else { - logo_width =get_max_line_len (logo_ascii, logo_ascii_lines) * font->width; - logo_height = logo_ascii_lines * font->height; + logo_width =get_max_line_len (logo_ascii,PANIC_LOGO_LINES ) * font->width; + logo_height =PANIC_LOGO_LINES * font->height; } - r_logo =DRM_RECT_INIT (0 ,0 , logo_width, logo_height); - r_msg =DRM_RECT_INIT (0 ,0 , -min (get_max_line_len (panic_msg, msg_lines) * font->width, sb->width), -min (msg_lines * font->height, sb->height)); + + msg_width =min (get_max_line_len (panic_msg,PANIC_MSG_LINES ) * font->width, sb->width); + msg_height =min (PANIC_MSG_LINES * font->height, sb->height); + r_msg =DRM_RECT_INIT (0 ,0 , msg_width, msg_height);/* Center the panic message */ drm_rect_translate (&r_msg, (sb->width - r_msg.x2) /2 , (sb->height - r_msg.y2) /2 );@@ -525,10 +528,10 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)drm_panic_blit (sb, &r_logo, logo_mono->data,DIV_ROUND_UP (logo_width,8 ), fg_color); else - draw_txt_rectangle(sb, font, logo_ascii, logo_ascii_lines, false, &r_logo, + draw_txt_rectangle(sb, font, logo_ascii, PANIC_LOGO_LINES, false, &r_logo, fg_color); } -draw_txt_rectangle (sb, font, panic_msg, msg_lines, true, &r_msg, fg_color); +draw_txt_rectangle (sb, font, panic_msg,PANIC_MSG_LINES , true, &r_msg, fg_color); }/* @@ -633,7 +636,31 @@ static void draw_panic_dispatch(struct drm_scanout_buffer *sb) } } -static void draw_panic_plane (struct drm_plane *plane) +static void drm_panic_set_description (const char *description) +{ +u32 len; + +if (description) { +struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES -1 ]; + + desc_line->txt = description; + len =strlen (description); +/* ignore the last newline character */ +if (len && description[len -1 ] =='\n' ) + len -=1 ; + desc_line->len = len; + } +} + +static void drm_panic_clear_description (void ) +{ +struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES -1 ]; + + desc_line->len =0 ; + desc_line->txt =NULL ; +} + +static void draw_panic_plane (struct drm_plane *plane,const char *description) {struct drm_scanout_buffer sb = { };int ret;@@ -642,6 +669,8 @@ static void draw_panic_plane(struct drm_plane *plane)if (!drm_panic_trylock (plane->dev, flags))return ; +drm_panic_set_description (description); + ret = plane->helper_private->get_scanout_buffer (plane, &sb);if (!ret &&drm_panic_is_format_supported (sb.format)) {@@ -649,6 +678,7 @@ static void draw_panic_plane(struct drm_plane *plane)if (plane->helper_private->panic_flush) plane->helper_private->panic_flush (plane); } +drm_panic_clear_description ();drm_panic_unlock (plane->dev, flags); }@@ -662,7 +692,7 @@ static void drm_panic(struct kmsg_dumper *dumper, struct kmsg_dump_detail *detaistruct drm_plane *plane =to_drm_plane (dumper);if (detail->reason ==KMSG_DUMP_PANIC ) -draw_panic_plane (plane); +draw_panic_plane (plane, detail->description); }@@ -682,7 +712,7 @@ static ssize_t debugfs_trigger_write(struct file *file, const char __user *user_if (kstrtobool_from_user (user_buf, count, &run) ==0 && run) {struct drm_plane *plane = file->private_data; -draw_panic_plane (plane); +draw_panic_plane (plane,"Test from debugfs" ); }return count; }Signature · 1 line
2.45.2
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch