drm/panic: Add a kmsg dump screen
Subsystems (3)
Jocelyn Falempe
maintainerv2 cover drm/panic: Add a kmsg dump screen
Add a kmsg option, which will display the last lines of kmsg, and should be similar to fbcon.
Add a drm.panic_screen module parameter, so you can choose between the different panic screens available.
Two options currently, but more will be added later:
* "user": a short message telling the user to reboot the machine.
* "kmsg": fill the screen with the last lines of kmsg.
You can even change it at runtime by writing to/sys/module/drm/parameters/panic_screen
Patch 1-2 are the same as https://patchwork.freedesktop.org/series/133963/
and are here to avoid conflicts.
v2:
* use module parameter instead of Kconfig choice, so it can be changed at runtime. (Javier Martinez Canillas)
* keep fg16/fg24/fg32 as variable name for the blit functions (Javier Martinez Canillas)
* Add drm_panic_is_pixel_fg() to avoid code duplication. (Javier Martinez Canillas)
Jocelyn Falempe (3):
drm/panic: only draw the foreground color in drm_panic_blit() drm/panic: Add a set_pixel() callback to drm_scanout_buffer drm/panic: Add a kmsg panic screen
drivers/gpu/drm/Kconfig | 11 ++ drivers/gpu/drm/drm_panic.c | 283 +++++++++++++++++++++++++----------- include/drm/drm_panic.h | 9 ++ 3 files changed, 219 insertions(+), 84 deletions(-)
base-commit: 86266829ea755f737762ebda614c59b136c8feac
Signature · 1 line
2.45.1
Jocelyn Falempe
maintainerPATCH v2 1/3 drm/panic: only draw the foreground color in drm_panic_blit()
The whole framebuffer is cleared, so it's useless to rewrite the background colored pixels. It allows to simplify the drawing functions, and prepare the work for the set_pixel() callback.
v2:
* keep fg16/fg24/fg32 as variable name for the blit function.
* add drm_panic_is_pixel_fg() to avoid code duplication. both suggested by Javier Martinez Canillas
--- drivers/gpu/drm/drm_panic.c | 67 +++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 36 deletions(-)
drivers/gpu/drm/drm_panic.c +31 -36
@@ -194,40 +194,42 @@ static u32 convert_from_xrgb8888(u32 color, u32 format)/* * Blit & Fill */ +/* check if the pixel at coord x,y is 1 (foreground) or 0 (background) */ +static bool drm_panic_is_pixel_fg (const u8 *sbuf8,unsigned int spitch,int x,int y) +{ +return (sbuf8[(y * spitch) + x /8 ] & (0x80 >> (x %8 ))) !=0 ; +} +static void drm_panic_blit16 (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u16 fg16,u16 bg16) +u16 fg16) {unsigned int y, x; -u16 val16; -for (y =0 ; y < height; y++) { -for (x =0 ; x < width; x++) { - val16 = (sbuf8[(y * spitch) + x /8 ] & (0x80 >> (x %8 ))) ? fg16 : bg16; -iosys_map_wr (dmap, y * dpitch + x *sizeof (u16), u16, val16); - } - } +for (y =0 ; y < height; y++) +for (x =0 ; x < width; x++) +if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) +iosys_map_wr (dmap, y * dpitch + x *sizeof (u16), u16, fg16); }static void drm_panic_blit24 (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u32 fg32,u32 bg32) +u32 fg32) {unsigned int y, x; -u32 val32;for (y =0 ; y < height; y++) {for (x =0 ; x < width; x++) {u32 off = y * dpitch + x *3 ; - val32 = (sbuf8[(y * spitch) + x /8 ] & (0x80 >> (x %8 ))) ? fg32 : bg32; - -/* write blue-green-red to output in little endianness */ -iosys_map_wr (dmap, off, u8, (val32 &0x000000FF ) >>0 ); -iosys_map_wr (dmap, off +1 , u8, (val32 &0x0000FF00 ) >>8 ); -iosys_map_wr (dmap, off +2 , u8, (val32 &0x00FF0000 ) >>16 ); +if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) { +/* write blue-green-red to output in little endianness */ +iosys_map_wr (dmap, off, u8, (fg32 &0x000000FF ) >>0 ); +iosys_map_wr (dmap, off +1 , u8, (fg32 &0x0000FF00 ) >>8 ); +iosys_map_wr (dmap, off +2 , u8, (fg32 &0x00FF0000 ) >>16 ); + } } } }
@@ -235,17 +237,14 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,static void drm_panic_blit32 (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u32 fg32,u32 bg32) +u32 fg32) {unsigned int y, x; -u32 val32; -for (y =0 ; y < height; y++) { -for (x =0 ; x < width; x++) { - val32 = (sbuf8[(y * spitch) + x /8 ] & (0x80 >> (x %8 ))) ? fg32 : bg32; -iosys_map_wr (dmap, y * dpitch + x *sizeof (u32), u32, val32); - } - } +for (y =0 ; y < height; y++) +for (x =0 ; x < width; x++) +if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) +iosys_map_wr (dmap, y * dpitch + x *sizeof (u32), u32, fg32); }/*
@@ -257,7 +256,6 @@ static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch,* @height: height of the image to copy, in pixels * @width: width of the image to copy, in pixels * @fg_color: foreground color, in destination format -* @bg_color: background color, in destination format * @pixel_width: pixel width in bytes. * * This can be used to draw a font character, which is a monochrome image, to a
@@ -266,21 +264,20 @@ static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch,static void drm_panic_blit (struct iosys_map *dmap,unsigned int dpitch,const u8 *sbuf8,unsigned int spitch,unsigned int height,unsigned int width, -u32 fg_color,u32 bg_color, -unsigned int pixel_width) +u32 fg_color,unsigned int pixel_width) {switch (pixel_width) {case 2 :drm_panic_blit16 (dmap, dpitch, sbuf8, spitch, - height, width, fg_color, bg_color); + height, width, fg_color);break ;case 3 :drm_panic_blit24 (dmap, dpitch, sbuf8, spitch, - height, width, fg_color, bg_color); + height, width, fg_color);break ;case 4 :drm_panic_blit32 (dmap, dpitch, sbuf8, spitch, - height, width, fg_color, bg_color); + height, width, fg_color);break ;default :WARN_ONCE (1 ,"Can't blit with pixel width %d\n" , pixel_width);
@@ -381,8 +378,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,unsigned int msg_lines, bool centered, struct drm_rect *clip, - u32 fg_color, - u32 bg_color) + u32 color) { int i, j;const u8 *src;
@@ -404,8 +400,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,for (j =0 ; j < line_len; j++) { src =get_char_bitmap (font, msg[i].txt[j], font_pitch);drm_panic_blit (&dst, sb->pitch[0 ], src, font_pitch, - font->height, font->width, - fg_color, bg_color, px_width); + font->height, font->width, color, px_width);iosys_map_incr (&dst, font->width * px_width); } }
@@ -445,9 +440,9 @@ static void draw_panic_static(struct drm_scanout_buffer *sb)if ((r_msg.x1 >=drm_rect_width (&r_logo) || r_msg.y1 >=drm_rect_height (&r_logo)) &&drm_rect_width (&r_logo) < sb->width &&drm_rect_height (&r_logo) < sb->height) { -draw_txt_rectangle (sb, font, logo, logo_lines, false, &r_logo, fg_color, bg_color); +draw_txt_rectangle (sb, font, logo, logo_lines, false, &r_logo, fg_color); } -draw_txt_rectangle (sb, font, panic_msg, msg_lines, true, &r_msg, fg_color, bg_color); +draw_txt_rectangle (sb, font, panic_msg, msg_lines, true, &r_msg, fg_color); }/*
Signature · 1 line
2.45.1
Re: [PATCH v2 1/3] drm/panic: only draw the foreground color in drm_panic_blit()
Jocelyn Falempe <[email protected]> writes:
Hello Jocelyn,
Quoted 19 lines
The whole framebuffer is cleared, so it's useless to rewrite the background colored pixels. It allows to simplify the drawing functions, and prepare the work for the
set_pixel()callback.v2:
* keep fg16/fg24/fg32 as variable name for the blit function.
* adddrm_panic_is_pixel_fg()to avoid code duplication. both suggested by Javier Martinez CanillasSigned-off-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/drm_panic.c | 67 +++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 36 deletions(-)drivers/gpu/drm/drm_panic.c +0
-0
drivers/gpu/drm/drm_panic.c static u32 convert_from_xrgb8888(u32 color, u32 format) · line 201
Quoted 8 lines
drivers/gpu/drm/drm_panic.c +5
-0@@ -194,40 +194,42 @@ static u32 convert_from_xrgb8888(u32 color, u32 format)/* * Blit & Fill */ +/* check if the pixel at coord x,y is 1 (foreground) or 0 (background) */ +static bool drm_panic_is_pixel_fg (const u8 *sbuf8,unsigned int spitch,int x,int y) +{ +return (sbuf8[(y * spitch) + x /8 ] & (0x80 >> (x %8 ))) !=0 ; +}
Thanks for doing this! The code is much easier to follow now IMO.
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Jocelyn Falempe
maintainerPATCH v2 2/3 drm/panic: Add a set_pixel() callback to drm_scanout_buffer
In reply to Jocelyn FalempeThis allows drivers to draw the pixel, and handle tiling, or specific color formats.
v2:
* Use fg_color for blit() functions (Javier Martinez Canillas)
--- drivers/gpu/drm/drm_panic.c | 120 +++++++++++++++++++++++------------- include/drm/drm_panic.h | 9 +++ 2 files changed, 85 insertions(+), 44 deletions(-)
drivers/gpu/drm/drm_panic.c +76 -44
@@ -247,40 +247,54 @@ static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch,iosys_map_wr (dmap, y * dpitch + x *sizeof (u32), u32, fg32); } +static void drm_panic_blit_pixel (struct drm_scanout_buffer *sb,struct drm_rect *clip, +const u8 *sbuf8,unsigned int spitch,u32 fg_color) +{ +unsigned int y, x; + +for (y =0 ; y <drm_rect_height (clip); y++) +for (x =0 ; x <drm_rect_width (clip); x++) +if (drm_panic_is_pixel_fg (sbuf8, spitch, x, y)) + sb->set_pixel (sb, clip->x1 + x, clip->y1 + y, fg_color); +} +/* * drm_panic_blit - convert a monochrome image to a linear framebuffer -* @dmap: destination iosys_map -* @dpitch: destination pitch in bytes +* @sb: destination scanout buffer +* @clip: destination rectangle * @sbuf8: source buffer, in monochrome format, 8 pixels per byte. * @spitch: source pitch in bytes -* @height: height of the image to copy, in pixels -* @width: width of the image to copy, in pixels * @fg_color: foreground color, in destination format -* @pixel_width: pixel width in bytes. * * This can be used to draw a font character, which is a monochrome image, to a * framebuffer in other supported format. */ -static void drm_panic_blit (struct iosys_map *dmap,unsigned int dpitch, -const u8 *sbuf8,unsigned int spitch, -unsigned int height,unsigned int width, -u32 fg_color,unsigned int pixel_width) +static void drm_panic_blit (struct drm_scanout_buffer *sb,struct drm_rect *clip, +const u8 *sbuf8,unsigned int spitch,u32 fg_color) { -switch (pixel_width) { +struct iosys_map map; + +if (sb->set_pixel) +return drm_panic_blit_pixel (sb, clip, sbuf8, spitch, fg_color); + + map = sb->map[0 ]; +iosys_map_incr (&map, clip->y1 * sb->pitch[0 ] + clip->x1 * sb->format->cpp[0 ]); + +switch (sb->format->cpp[0 ]) {case 2 : -drm_panic_blit16 (dmap, dpitch, sbuf8, spitch, - height, width, fg_color); +drm_panic_blit16 (&map, sb->pitch[0 ], sbuf8, spitch, +drm_rect_height (clip),drm_rect_width (clip), fg_color);break ;case 3 : -drm_panic_blit24 (dmap, dpitch, sbuf8, spitch, - height, width, fg_color); +drm_panic_blit24 (&map, sb->pitch[0 ], sbuf8, spitch, +drm_rect_height (clip),drm_rect_width (clip), fg_color);break ;case 4 : -drm_panic_blit32 (dmap, dpitch, sbuf8, spitch, - height, width, fg_color); +drm_panic_blit32 (&map, sb->pitch[0 ], sbuf8, spitch, +drm_rect_height (clip),drm_rect_width (clip), fg_color);break ;default : -WARN_ONCE (1 ,"Can't blit with pixel width %d\n" , pixel_width); +WARN_ONCE (1 ,"Can't blit with pixel width %d\n" , sb->format->cpp[0 ]); } }
@@ -324,33 +338,51 @@ static void drm_panic_fill32(struct iosys_map *dmap, unsigned int dpitch,iosys_map_wr (dmap, y * dpitch + x *sizeof (u32), u32, color); } +static void drm_panic_fill_pixel (struct drm_scanout_buffer *sb, +struct drm_rect *clip, +u32 color) +{ +unsigned int y, x; + +for (y =0 ; y <drm_rect_height (clip); y++) +for (x =0 ; x <drm_rect_width (clip); x++) + sb->set_pixel (sb, clip->x1 + x, clip->y1 + y, color); +} +/* * drm_panic_fill - Fill a rectangle with a color -* @dmap: destination iosys_map, pointing to the top left corner of the rectangle -* @dpitch: destination pitch in bytes -* @height: height of the rectangle, in pixels -* @width: width of the rectangle, in pixels -* @color: color to fill the rectangle. -* @pixel_width: pixel width in bytes +* @sb: destination scanout buffer +* @clip: destination rectangle +* @color: foreground color, in destination format * * Fill a rectangle with a color, in a linear framebuffer. */ -static void drm_panic_fill (struct iosys_map *dmap,unsigned int dpitch, -unsigned int height,unsigned int width, -u32 color,unsigned int pixel_width) +static void drm_panic_fill (struct drm_scanout_buffer *sb,struct drm_rect *clip, +u32 color) { -switch (pixel_width) { +struct iosys_map map; + +if (sb->set_pixel) +return drm_panic_fill_pixel (sb, clip, color); + + map = sb->map[0 ]; +iosys_map_incr (&map, clip->y1 * sb->pitch[0 ] + clip->x1 * sb->format->cpp[0 ]); + +switch (sb->format->cpp[0 ]) {case 2 : -drm_panic_fill16 (dmap, dpitch, height, width, color); +drm_panic_fill16 (&map, sb->pitch[0 ],drm_rect_height (clip), +drm_rect_width (clip), color);break ;case 3 : -drm_panic_fill24 (dmap, dpitch, height, width, color); +drm_panic_fill24 (&map, sb->pitch[0 ],drm_rect_height (clip), +drm_rect_width (clip), color);break ;case 4 : -drm_panic_fill32 (dmap, dpitch, height, width, color); +drm_panic_fill32 (&map, sb->pitch[0 ],drm_rect_height (clip), +drm_rect_width (clip), color);break ;default : -WARN_ONCE (1 ,"Can't fill with pixel width %d\n" , pixel_width); +WARN_ONCE (1 ,"Can't fill with pixel width %d\n" , sb->format->cpp[0 ]); } }
@@ -383,25 +415,24 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,int i, j;const u8 *src;size_t font_pitch =DIV_ROUND_UP (font->width,8 ); -struct iosys_map dst; -unsigned int px_width = sb->format->cpp[0 ]; -int left =0 ; +struct drm_rect rec; msg_lines =min (msg_lines,drm_rect_height (clip) / font->height);for (i =0 ; i < msg_lines; i++) {size_t line_len =min (msg[i].len,drm_rect_width (clip) / font->width); + rec.y1 = clip->y1 + i * font->height; + rec.y2 = rec.y1 + font->height; + rec.x1 = clip->x1; +if (centered) - left = (drm_rect_width (clip) - (line_len * font->width)) /2 ; + rec.x1 += (drm_rect_width (clip) - (line_len * font->width)) /2 ; - dst = sb->map[0 ]; -iosys_map_incr (&dst, (clip->y1 + i * font->height) * sb->pitch[0 ] + - (clip->x1 + left) * px_width);for (j =0 ; j < line_len; j++) { src =get_char_bitmap (font, msg[i].txt[j], font_pitch); -drm_panic_blit (&dst, sb->pitch[0 ], src, font_pitch, - font->height, font->width, color, px_width); -iosys_map_incr (&dst, font->width * px_width); + rec.x2 = rec.x1 + font->width; +drm_panic_blit (sb, &rec, src, font_pitch, color); + rec.x1 += font->width; } } }
@@ -416,7 +447,7 @@ static void draw_panic_static(struct drm_scanout_buffer *sb)u32 fg_color =CONFIG_DRM_PANIC_FOREGROUND_COLOR ;u32 bg_color =CONFIG_DRM_PANIC_BACKGROUND_COLOR ;const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL ); -struct drm_rect r_logo, r_msg; +struct drm_rect r_screen, r_logo, r_msg;if (!font)return ;
@@ -424,6 +455,8 @@ static void draw_panic_static(struct drm_scanout_buffer *sb) fg_color =convert_from_xrgb8888 (fg_color, sb->format->format); bg_color =convert_from_xrgb8888 (bg_color, sb->format->format); + r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height); + r_logo =DRM_RECT_INIT (0 ,0 ,get_max_line_len (logo, logo_lines) * font->width, logo_lines * font->height);
@@ -435,8 +468,7 @@ static void draw_panic_static(struct drm_scanout_buffer *sb)drm_rect_translate (&r_msg, (sb->width - r_msg.x2) /2 , (sb->height - r_msg.y2) /2 );/* Fill with the background color, and draw text on top */ -drm_panic_fill (&sb->map[0 ], sb->pitch[0 ], sb->height, sb->width, - bg_color, sb->format->cpp[0 ]); +drm_panic_fill (sb, &r_screen, bg_color);if ((r_msg.x1 >=drm_rect_width (&r_logo) || r_msg.y1 >=drm_rect_height (&r_logo)) &&drm_rect_width (&r_logo) < sb->width &&drm_rect_height (&r_logo) < sb->height) {
include/drm/drm_panic.h +9 -0
@@ -50,6 +50,15 @@ struct drm_scanout_buffer {* @pitch: Length in bytes between the start of two consecutive lines. */ unsigned int pitch[DRM_FORMAT_MAX_PLANES ]; + +/** +* @set_pixel: Optional function, to set a pixel color on the +* framebuffer. It allows to handle special tiling format inside the +* driver. +*/ +void (*set_pixel)(struct drm_scanout_buffer *sb,unsigned int x, +unsigned int y,u32 color); + };/**
Signature · 1 line
2.45.1
Re: [PATCH v2 2/3] drm/panic: Add a set_pixel() callback to drm_scanout_buffer
Quoted 8 lines · Jocelyn Falempe
This allows drivers to draw the pixel, and handle tiling, or specific color formats.
v2:
* Usefg_colorforblit()functions (Javier Martinez Canillas)Signed-off-by Jocelyn Falempe <[email protected]>---
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Jocelyn Falempe
maintainerPATCH v2 3/3 drm/panic: Add a kmsg panic screen
In reply to Jocelyn FalempeAdd a kmsg option, which will display the last lines of kmsg, and should be similar to fbcon.
Add a drm.panic_screen module parameter, so you can choose between the different panic screens available.
two options currently, but more will be added later:
* "user": a short message telling the user to reboot the machine.
* "kmsg": fill the screen with the last lines of kmsg.
You can even change it at runtime by writing to/sys/module/drm/parameters/panic_screen
v2:
* use module parameter instead of Kconfig choice
(Javier Martinez Canillas)
--- drivers/gpu/drm/Kconfig | 11 ++++ drivers/gpu/drm/drm_panic.c | 108 ++++++++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 10 deletions(-)
drivers/gpu/drm/Kconfig +11 -0
@@ -137,6 +137,17 @@ config DRM_PANIC_DEBUG This is unsafe and should not be enabled on a production build. If in doubt, say "N". +config DRM_PANIC_SCREEN + string "Panic screen formater" + default "user" + depends on DRM_PANIC + help + This option enable to choose what will be displayed when a kernel + panic occurs. You can choose between "user", a short message telling + the user to reboot the system, or "kmsg" which will display the last + lines of kmsg. + Default is "user" + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT
drivers/gpu/drm/drm_panic.c +98 -10
153 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PATCH v2 3/3] drm/panic: Add a kmsg panic screen
Hi Jocelyn,
kernel test robot noticed the following build warnings:
url: https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-panic-only-draw-the-foreground-color-in-drm_panic_blit/20240603-181247 base: 86266829ea755f737762ebda614c59b136c8feac patch link: https://lore.kernel.org/r/20240603095343.39588-4-jfalempe%40redhat.com patch subject: [PATCH v2 3/3] drm/panic: Add a kmsg panic screen config: i386-randconfig-141-20240604 (https://download.01.org/0day-ci/archive/20240604/[email protected]/config) compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/gpu/drm/drm_panic.c:531 draw_panic_static_kmsg() warn: variable dereferenced before check 'font' (see line 529)
vim +/font +531 drivers/gpu/drm/drm_panic.c
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 519 static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 520 {
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 521 u32 fg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_FOREGROUND_COLOR, sb->format->format);
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 522 u32 bg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_BACKGROUND_COLOR, sb->format->format);
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 523 const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL);
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 524 struct drm_rect r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height);
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 525 struct kmsg_dump_iter iter;
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 526 char kmsg_buf[512];
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 527 size_t kmsg_len;
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 528 struct drm_panic_line line;
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 @529 int yoffset = sb->height - font->height - (sb->height % font->height) / 2;
^^^^^^^^^^^^ ^^^^^^^^^^^^Unchecked dereferences
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 530c259bba1e69ff2 Jocelyn Falempe 2024-06-03 @531 if (!font)
^^^^
Checked too late
c259bba1e69ff2 Jocelyn Falempe 2024-06-03 532 return;c259bba1e69ff2 Jocelyn Falempe 2024-06-03 533
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 3/3] drm/panic: Add a kmsg panic screen
In reply to Jocelyn FalempeQuoted 11 lines · Jocelyn Falempe
Add a kmsg option, which will display the last lines of kmsg, and should be similar to fbcon.
Add a drm.panic_screen module parameter, so you can choose between the different panic screens available.
two options currently, but more will be added later:
* "user": a short message telling the user to reboot the machine.
* "kmsg": fill the screen with the last lines of kmsg.You can even change it at runtime by writing to
/sys/module/drm/parameters/panic_screen
Great!
Quoted 17 lines
v2:
* use module parameter instead ofKconfigchoice
(Javier Martinez Canillas)Signed-off-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/Kconfig | 11 ++++ drivers/gpu/drm/drm_panic.c | 108 ++++++++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 10 deletions(-)drivers/gpu/drm/Kconfig +0
-0@@ -137,6 +137,17 @@ config DRM_PANIC_DEBUG This is unsafe and should not be enabled on a production build. If in doubt, say "N".
drivers/gpu/drm/Kconfig config DRM_PANIC_DEBUG · line 148
Quoted 10 lines
drivers/gpu/drm/Kconfig +9
-0+config DRM_PANIC_SCREEN + string "Panic screen formater" + default "user" + depends on DRM_PANIC + help + This option enable to choose what will be displayed when a kernel + panic occurs. You can choose between "user", a short message telling + the user to reboot the system, or "kmsg" which will display the last + lines of kmsg.
Maybe I would mention here that this is only about the default, but that can be changed using the "drm.panic_screen=" kernel cmdline parameter or writting to the /sys/module/drm/parameters/panic_screen sysfs entry.
[...]
drivers/gpu/drm/Kconfig config DRM_PANIC_DEBUG · line 153
Quoted 5 lines
drivers/gpu/drm/Kconfig +5
-0+static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb) +{ + 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);
Dan reported that get_default_font() can return NULL....
drivers/gpu/drm/Kconfig config DRM_PANIC_DEBUG
Quoted 10 lines
drivers/gpu/drm/Kconfig +10
-0+ struct drm_rect r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height); + struct kmsg_dump_iter iter; + char kmsg_buf[512]; + size_t kmsg_len; + struct drm_panic_line line; + int yoffset = sb->height - font->height - (sb->height % font->height) / 2; + + if (!font) + return; +
... so you have to calculate yoffset after checking if the font is not NULL.
with that fixed:
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Jocelyn Falempe
maintainerRe: [PATCH v2 3/3] drm/panic: Add a kmsg panic screen
Quoted 48 lines · Javier Martinez Canillas
Quoted 11 lines · Jocelyn Falempe
Add a kmsg option, which will display the last lines of kmsg, and should be similar to fbcon.
Add a drm.panic_screen module parameter, so you can choose between the different panic screens available.
two options currently, but more will be added later:
* "user": a short message telling the user to reboot the machine.
* "kmsg": fill the screen with the last lines of kmsg.You can even change it at runtime by writing to
/sys/module/drm/parameters/panic_screenGreat!
Quoted 17 lines
v2:
* use module parameter instead ofKconfigchoice (Javier Martinez Canillas)Signed-off-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/Kconfig | 11 ++++ drivers/gpu/drm/drm_panic.c | 108 ++++++++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 10 deletions(-)drivers/gpu/drm/Kconfig +0
-0@@ -137,6 +137,17 @@ config DRM_PANIC_DEBUG This is unsafe and should not be enabled on a production build. If in doubt, say "N".drivers/gpu/drm/Kconfig config DRM_PANIC_DEBUG · line 148
Quoted 10 lines
drivers/gpu/drm/Kconfig +9
-0+config DRM_PANIC_SCREEN + string "Panic screen formater" + default "user" + depends on DRM_PANIC + help + This option enable to choose what will be displayed when a kernel + panic occurs. You can choose between "user", a short message telling + the user to reboot the system, or "kmsg" which will display the last + lines of kmsg.Maybe I would mention here that this is only about the default, but that can be changed using the "drm.panic_screen=" kernel cmdline parameter or writting to the
/sys/module/drm/parameters/panic_screensysfs entry.
Quoted 1 line
[...]
Done
Quoted 10 lines
drivers/gpu/drm/Kconfig
Quoted 6 lines
drivers/gpu/drm/Kconfig +5
-0+static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb) +{ + 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);Dan reported that
get_default_font()can return NULL....
Quoted 12 lines
drivers/gpu/drm/Kconfig
Quoted 10 lines
drivers/gpu/drm/Kconfig +10
-0+ struct drm_rect r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height); + struct kmsg_dump_iter iter; + char kmsg_buf[512]; + size_t kmsg_len; + struct drm_panic_line line; + int yoffset = sb->height - font->height - (sb->height % font->height) / 2; + + if (!font) + return; +... so you have to calculate yoffset after checking if the font is not NULL.
Yes I fixed that too.
Quoted 5 lines
with that fixed:
Reviewed-by Javier Martinez Canillas <[email protected]>
Thanks a lot.
I just pushed this series to drm-misc-next.
Best regards,
Signature · 1 line
Jocelyn