drm/log: Introduce a new boot logger to draw the kmsg on the screen
Subsystems (3)
Jocelyn Falempe
maintainerv2 cover drm/log: Introduce a new boot logger to draw the kmsg on the screen
drm_log is a simple logger that uses the drm_client API to print the kmsg boot log on the screen. This is not a full replacement to fbcon, as it will only print the kmsg.
It will never handle user input, or a terminal because this is better done in userspace.
If you're curious on how it looks like, I've put a small demo here:
https://people.redhat.com/jfalempe/drm_log/drm_log_draft_boot_v2.mp4
Design decisions:
* It uses the drm_client API, so it should work on all drm drivers from the start.
* It doesn't scroll the message, that way it doesn't need to redraw the whole screen for each new message. It also means it doesn't have to keep drawn messages in memory, to redraw them when scrolling.
* It uses a circular buffer so the console->write() callback is very quick, and will never stall.
* Drawing is done asynchronously using a workqueue.
* drm_log can only be built-in (and drm must be built-in too).
The reason is that, if you build it as a module, then a userspace application will be more appropriate than this module.
* When nbcon will be ready, I will use it. It should simplify this a lot, but I prefer not to depend on it yet.
The first patch is not for review/merge, it's a squash of my pending drm_panic series:
https://patchwork.freedesktop.org/series/135944/
The second patch, moves the drawing function from drm_panic.c, to drm_draw.c, so they can be re-used by drm_log. The next patches are the actual drm_log implementation.
v2:
* Use vmap_local() api, with that change, I've tested it successfully on simpledrm, virtio-gpu, amdgpu, and nouveau.
* Stop drawing when the drm_master is taken. This avoid wasting CPU cycle if the buffer is not visible.
* Use deferred probe. Only do the probe the first time there is a log to draw. With this, if you boot with quiet, drm_log won't do any modeset.
* Add color support for the timestamp prefix, like what dmesg does.
* Add build dependency on disabling the fbdev emulation, as they are both drm_client, and there is no way to choose which one gets the focus.
Thanks and best regards,
Signature · 31 lines
Jocelyn Jocelyn Falempe (5): [NOT FOR REVIEW] drm/panic: Squash of pending series drm/panic: Move drawing functions to drm_draw drm/log: Introduce a new boot logger to draw the kmsg on the screen drm/log: Do not draw if drm_master is taken drm/log: Color the timestamp, to improve readability drivers/gpu/drm/Kconfig | 50 ++ drivers/gpu/drm/Makefile | 4 + drivers/gpu/drm/drm_crtc_internal.h | 4 + drivers/gpu/drm/drm_draw.c | 216 ++++++ drivers/gpu/drm/drm_draw.h | 56 ++ drivers/gpu/drm/drm_drv.c | 5 + drivers/gpu/drm/drm_log.c | 515 ++++++++++++++ drivers/gpu/drm/drm_log.h | 11 + drivers/gpu/drm/drm_panic.c | 569 ++++++++------- drivers/gpu/drm/drm_panic_qr.rs | 1003 +++++++++++++++++++++++++++ include/drm/drm_rect.h | 15 + 11 files changed, 2193 insertions(+), 255 deletions(-) create mode 100644 drivers/gpu/drm/drm_draw.c create mode 100644 drivers/gpu/drm/drm_draw.h create mode 100644 drivers/gpu/drm/drm_log.c create mode 100644 drivers/gpu/drm/drm_log.h create mode 100644 drivers/gpu/drm/drm_panic_qr.rs base-commit: 8befe8fa5a4e4b30787b17e078d9d7b5cb92ea19 -- 2.46.0
Jocelyn Falempe
maintainerPATCH v2 1/5 drm/panic: Squash of pending series
squash of the drm/panic QR code series
https://patchwork.freedesktop.org/series/135944/
--- drivers/gpu/drm/Kconfig | 31 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_crtc_internal.h | 4 + drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_panic.c | 340 +++++++-- drivers/gpu/drm/drm_panic_qr.rs | 1003 +++++++++++++++++++++++++++ include/drm/drm_rect.h | 15 + 7 files changed, 1357 insertions(+), 40 deletions(-) create mode 100644 drivers/gpu/drm/drm_panic_qr.rs
drivers/gpu/drm/Kconfig +31 -0
@@ -149,6 +149,37 @@ config DRM_PANIC_SCREEN or by writing to /sys/module/drm/parameters/panic_screen sysfs entry Default is "user" +config DRM_PANIC_SCREEN_QR_CODE + bool "Add a panic screen with a QR code" + depends on DRM_PANIC && RUST + help + This option adds a QR code generator, and a panic screen with a QR + code. The QR code will contain the last lines of kmsg and other debug + information. This should be easier for the user to report a kernel + panic, with all debug information available. + To use this panic screen, also set DRM_PANIC_SCREEN to "qr_code" + +config DRM_PANIC_SCREEN_QR_CODE_URL + string "Base URL of the QR code in the panic screen" + depends on DRM_PANIC_SCREEN_QR_CODE + help + This option sets the base URL to report the kernel panic. If it's set + the QR code will contain the URL and the kmsg compressed with zlib as + a URL parameter. If it's empty, the QR code will contain the kmsg as + uncompressed text only. + There is a demo code in javascript, to decode and uncompress the kmsg + data from the URL parameter at https://github.com/kdj0c/panic_report + +config DRM_PANIC_SCREEN_QR_VERSION + int "Maximum version (size) of the QR code." + depends on DRM_PANIC_SCREEN_QR_CODE + default 40 + help + This option limits the version (or size) of the QR code. QR code + version ranges from Version 1 (21x21) to Version 40 (177x177). + Smaller QR code are easier to read, but will contain less debugging + data. Default is 40. + 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
@@ -89,6 +89,7 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ drm_privacy_screen_x86.o drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o drm-$(CONFIG_DRM_PANIC) += drm_panic.o +drm-$(CONFIG_DRM_PANIC_SCREEN_QR_CODE) += drm_panic_qr.o obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
drivers/gpu/drm/drm_crtc_internal.h +4 -0
@@ -320,10 +320,14 @@ drm_edid_load_firmware(struct drm_connector *connector)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); +void drm_panic_init (void ); +void drm_panic_exit (void );#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) {} +static inline void drm_panic_init (void ) {} +static inline void drm_panic_exit (void ) {}#endif #endif /* __DRM_CRTC_INTERNAL_H__ */
drivers/gpu/drm/drm_drv.c +3 -0
@@ -1067,6 +1067,7 @@ static const struct file_operations drm_stub_fops = {static void drm_core_exit (void ) {drm_privacy_screen_lookup_exit (); +drm_panic_exit ();accel_core_exit ();unregister_chrdev (DRM_MAJOR ,"drm" );debugfs_remove (drm_debugfs_root);
@@ -1099,6 +1100,8 @@ static int __init drm_core_init(void)if (ret <0 ) goto error; +drm_panic_init (); +drm_privacy_screen_lookup_init (); drm_core_init_complete = true;
drivers/gpu/drm/drm_panic.c +300 -40
492 lines not on this page · raw message
drivers/gpu/drm/drm_panic_qr.rs new file +1003 -0
1,003 lines not on this page · raw message
include/drm/drm_rect.h +15 -0
@@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct drm_rect *dst, drm_rect_height(src) >> 16); } +/** +* drm_rect_overlap - Check if two rectangles overlap +* @r1: first rectangle +* @r2: second rectangle +* +* RETURNS: +* %true if the rectangles overlap, %false otherwise. +*/ +static inline bool drm_rect_overlap (const struct drm_rect *r1, +const struct drm_rect *r2) +{ +return (r1->x2 > r2->x1 && r2->x2 > r1->x1 && + r1->y2 > r2->y1 && r2->y2 > r1->y1); +} +bool drm_rect_intersect (struct drm_rect *r,const struct drm_rect *clip);bool drm_rect_clip_scaled (struct drm_rect *src,struct drm_rect *dst,const struct drm_rect *clip);
Signature · 1 line
2.46.0
Jocelyn Falempe
maintainerPATCH v2 2/5 drm/panic: Move drawing functions to drm_draw
In reply to Jocelyn FalempeMove the color conversions, blit and fill functions to drm_draw.c, so that they can be re-used by drm_log.drm_draw is internal to the drm subsystem, and shouldn't be used by gpu drivers.
--- drivers/gpu/drm/Kconfig | 5 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_draw.c | 216 +++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_draw.h | 56 ++++++++ drivers/gpu/drm/drm_panic.c | 247 ++++-------------------------------- 5 files changed, 301 insertions(+), 224 deletions(-) create mode 100644 drivers/gpu/drm/drm_draw.c create mode 100644 drivers/gpu/drm/drm_draw.h
drivers/gpu/drm/Kconfig +5 -0
@@ -105,10 +105,15 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_DRAW + bool + depends on DRM + config DRM_PANIC bool "Display a user-friendly message when a kernel panic occurs" depends on DRM select FONT_SUPPORT + select DRM_DRAW 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
drivers/gpu/drm/Makefile +1 -0
@@ -89,6 +89,7 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ drm_privacy_screen_x86.o drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o drm-$(CONFIG_DRM_PANIC) += drm_panic.o +drm-$(CONFIG_DRM_DRAW) += drm_draw.o drm-$(CONFIG_DRM_PANIC_SCREEN_QR_CODE) += drm_panic_qr.o obj-$(CONFIG_DRM) += drm.o
drivers/gpu/drm/drm_draw.c new file +216 -0
216 lines not on this page · raw message
drivers/gpu/drm/drm_draw.h new file +56 -0
56 lines not on this page · raw message
drivers/gpu/drm/drm_panic.c +23 -224
332 lines not on this page · raw message
Signature · 1 line
2.46.0
Jocelyn Falempe
maintainerPATCH v2 3/5 drm/log: Introduce a new boot logger to draw the kmsg on the screen
In reply to Jocelyn Falempedrm_log is a simple logger that uses the drm_client API to print the kmsg boot log on the screen. This is not a full replacement to fbcon, as it will only print the kmsg. It will never handle user input, or a terminal because this is better done in userspace.
Design decisions:
* It uses the drm_client API, so it should work on all drm drivers from the start.
* It doesn't scroll the message, that way it doesn't need to redraw the whole screen for each new message.
It also means it doesn't have to keep drawn messages in memory, to redraw them when scrolling.
* It uses a circular buffer so the console->write() callback is very quick, and will never stall.
* Drawing is done asynchronously using a workqueue.
* drm_log can only be built-in (and drm must be built-in too). The reason is that, if you build it as a module, then a userspace application will be more appropriate than this module.
---
v2:
* Use vmap_local() api, with that change, I've tested it successfully on simpledrm, virtio-gpu, amdgpu, and nouveau.
* Use deferred probe. Only do the probe the first time there is a log to draw. With this, if you boot with quiet, drm_log won't do any modeset.
* Add build dependency on disabling the fbdev emulation, as they are both drm_client, and there is no way to choose which one gets the focus.
drivers/gpu/drm/Kconfig | 14 ++ drivers/gpu/drm/Makefile | 2 + drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_log.c | 495 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_log.h | 11 + 5 files changed, 524 insertions(+) create mode 100644 drivers/gpu/drm/drm_log.c create mode 100644 drivers/gpu/drm/drm_log.h
drivers/gpu/drm/Kconfig +14 -0
@@ -185,6 +185,20 @@ config DRM_PANIC_SCREEN_QR_VERSION Smaller QR code are easier to read, but will contain less debugging data. Default is 40. +config DRM_LOG + bool "Print the kernel boot message on the screen" + depends on DRM=y + depends on !DRM_FBDEV_EMULATION + select DRM_DRAW + help + This enable a drm logger, that will print the kernel messages to the + screen until the userspace is ready to take over. + It only makes sense to have it built-in, because otherwise it would + be loaded after userspace. + + If you only need logs, but no terminal, or if you prefer userspace + terminal, say "Y". + 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 +2 -0
@@ -149,6 +149,8 @@ drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o +obj-$(CONFIG_DRM_LOG) += drm_log.o + # # Drivers and the rest #
drivers/gpu/drm/drm_drv.c +2 -0
@@ -48,6 +48,7 @@#include <drm/drm_privacy_screen_machine.h> #include "drm_crtc_internal.h" +#include "drm_log.h" #include "drm_internal.h" MODULE_AUTHOR ("Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl" );
@@ -946,6 +947,7 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) goto err_unload; }drm_panic_register (dev); +drm_log_register (dev); DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n", driver->name, driver->major, driver->minor,
drivers/gpu/drm/drm_log.c new file +495 -0
495 lines not on this page · raw message
drivers/gpu/drm/drm_log.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 or MIT */ +#ifndef __DRM_LOG_H__ +#define __DRM_LOG_H__ + +#ifdef CONFIG_DRM_LOG +void drm_log_register (struct drm_device *dev); +#else +static inline void drm_log_register (struct drm_device *dev) {} +#endif + +#endif
Signature · 1 line
2.46.0
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Jocelyn,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 8befe8fa5a4e4b30787b17e078d9d7b5cb92ea19]
url: https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-panic-Squash-of-pending-series/20240816-205859 base: 8befe8fa5a4e4b30787b17e078d9d7b5cb92ea19 patch link: https://lore.kernel.org/r/20240816125612.1003295-4-jfalempe%40redhat.com patch subject: [PATCH v2 3/5] drm/log: Introduce a new boot logger to draw the kmsg on the screen config: arm-randconfig-r121-20240818 (https://download.01.org/0day-ci/archive/20240818/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 14.1.0 reproduce: (https://download.01.org/0day-ci/archive/20240818/[email protected]/reproduce)
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]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/drm_log.c:66:17: sparse: sparse: symbol 'drm_log_buf' was not declared. Should it be static? >> drivers/gpu/drm/drm_log.c:384:1: sparse: sparse: symbol 'drm_log_work' was not declared. Should it be static?
drivers/gpu/drm/drm_log.c: note: in included file (through include/linux/rculist.h, include/linux/console.h):
include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
vim +/drm_log_buf +66 drivers/gpu/drm/drm_log.c
59
60 /*
61 * A circular buffer, with the last kmsg logs to print.
62 * 8K is more than what can be drawn on most monitors.
63 */
64 #define CIRC_BUF_SIZE (1 << 13)
65 #define CIRC_BUF_MASK (CIRC_BUF_SIZE - 1)
> 66 struct circ_buf drm_log_buf;
67 static DEFINE_SPINLOCK(drm_log_writer_lock);
68 static DEFINE_SPINLOCK(drm_log_reader_lock);
69 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jocelyn Falempe
maintainerPATCH v2 4/5 drm/log: Do not draw if drm_master is taken
In reply to Jocelyn FalempeWhen userspace takes drm_master, the drm_client buffer is no more visible, so drm_log shouldn't waste CPU cycle to draw on it.
--- drivers/gpu/drm/drm_log.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_log.c +10 -4
@@ -22,6 +22,7 @@#include "drm_draw.h" #include "drm_log.h" +#include "drm_internal.h" MODULE_AUTHOR ("Jocelyn Falempe" );MODULE_DESCRIPTION ("DRM boot logger" );
@@ -361,10 +362,15 @@ static bool drm_log_active_output(void)bool active = false;mutex_lock (&drm_log_lock); -list_for_each_entry (dclient, &drm_log_clients, head) -if (dclient->n_scanout || !dclient->probed) - active = true; - +list_for_each_entry (dclient, &drm_log_clients, head) { +if (dclient->n_scanout || !dclient->probed) { +/* Also check that we are still the master */ +if (drm_master_internal_acquire (dclient->client.dev)) { +drm_master_internal_release (dclient->client.dev); + active = true; + } + } + }mutex_unlock (&drm_log_lock);return active; }
Signature · 1 line
2.46.0
Jocelyn Falempe
maintainerPATCH v2 5/5 drm/log: Color the timestamp, to improve readability
In reply to Jocelyn FalempeColor the timesamp prefix, similar to dmesg.
--- drivers/gpu/drm/drm_log.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_log.c +20 -6
@@ -45,6 +45,7 @@ struct drm_log_scanout {u32 format;u32 px_width;u32 front_color; +u32 prefix_color; };struct drm_log_client {
@@ -186,7 +187,7 @@ static void drm_log_clear_line(struct drm_log_scanout *scanout, u32 line) }static void drm_log_draw_line (struct drm_log_scanout *scanout,const char *s, -unsigned int len) +unsigned int len,unsigned int prefix_len) {struct drm_framebuffer *fb = scanout->buffer->fb;struct iosys_map map;
@@ -203,9 +204,10 @@ static void drm_log_draw_line(struct drm_log_scanout *scanout, const char *s,iosys_map_incr (&map, r.y1 * fb->pitches[0 ]);for (i =0 ; i < len && i < scanout->columns; i++) { +u32 color = (i < prefix_len) ? scanout->prefix_color : scanout->front_color; src =drm_draw_get_char_bitmap (font, s[i], font_pitch);drm_log_blit (&map, fb->pitches[0 ], src, font_pitch, font->height, font->width, -1 , px_width, scanout->front_color); +1 , px_width, color);iosys_map_incr (&map, font->width * px_width); }
@@ -217,7 +219,7 @@ static void drm_log_draw_line(struct drm_log_scanout *scanout, const char *s, }static void drm_log_draw_new_line (struct drm_log_scanout *scanout, -const char *s,unsigned int len) +const char *s,unsigned int len,unsigned int prefix_len) {if (scanout->line ==0 ) {drm_log_clear_line (scanout,0 );
@@ -226,20 +228,31 @@ static void drm_log_draw_new_line(struct drm_log_scanout *scanout, }else if (scanout->line +2 < scanout->rows)drm_log_clear_line (scanout, scanout->line +2 ); -drm_log_draw_line (scanout, s, len); +drm_log_draw_line (scanout, s, len, prefix_len); } +/* +* Depends on print_time() in printk.c +* Timestamp is written with "[%5lu.%06lu]" +*/ +#define TS_PREFIX_LEN 13 +static void drm_log_draw_kmsg_record (struct drm_log_scanout *scanout,const char *s,unsigned int len) { +u32 prefix_len =0 ; + +if (len >TS_PREFIX_LEN && s[0 ] =='[' && s[6 ] =='.' && s[TS_PREFIX_LEN ] ==']' ) + prefix_len =TS_PREFIX_LEN +1 ;while (len > scanout->columns) { -drm_log_draw_new_line (scanout, s, scanout->columns); +drm_log_draw_new_line (scanout, s, scanout->columns, prefix_len); s += scanout->columns; len -= scanout->columns; + prefix_len =0 ; }if (len) -drm_log_draw_new_line (scanout, s, len); +drm_log_draw_new_line (scanout, s, len, prefix_len); }static u32 drm_log_find_usable_format (struct drm_plane *plane)
@@ -279,6 +292,7 @@ static int drm_log_setup_modeset(struct drm_client_dev *client, scanout->rows = height / scanout->font->height; scanout->columns = width / scanout->font->width; scanout->front_color =drm_draw_color_from_xrgb8888 (0xffffff , format); + scanout->prefix_color =drm_draw_color_from_xrgb8888 (0x4e9a06 , format);return 0 ; }
Signature · 1 line
2.46.0
Quoted 23 lines · EDT Jocelyn Falempe
drm_logis a simple logger that uses thedrm_clientAPI to print the kmsg boot log on the screen. This is not a full replacement to fbcon, as it will only print the kmsg.
It will never handle user input, or a terminal because this is better done in userspace.If you're curious on how it looks like, I've put a small demo here:
https://people.redhat.com/jfalempe/drm_log/drm_log_draft_boot_v2.mp4Design decisions:
* It uses thedrm_clientAPI, so it should work on all drm drivers from the start.
* It doesn't scroll the message, that way it doesn't need to redraw the whole screen for each new message. It also means it doesn't have to keep drawn messages in memory, to redraw them when scrolling.
* It uses a circular buffer so theconsole->write()callback is very quick, and will never stall.
* Drawing is done asynchronously using a workqueue.
*drm_logcan only be built-in (and drm must be built-in too).
The reason is that, if you build it as a module, then a userspace application will be more appropriate than this module.
* When nbcon will be ready, I will use it. It should simplify this a lot, but I prefer not to depend on it yet.The first patch is not for review/merge, it's a squash of my pending
drm_panicseries:
https://patchwork.freedesktop.org/series/135944/The second patch, moves the drawing function from
drm_panic.c, todrm_draw.c, so they can be re-used bydrm_log. The next patches are the actualdrm_logimplementation.
Quoted 10 lines
v2:
* Usevmap_local()api, with that change, I've tested it successfully on simpledrm, virtio-gpu, amdgpu, and nouveau.
* Stop drawing when thedrm_masteris taken. This avoid wasting CPU cycle if the buffer is not visible.
* Use deferred probe. Only do the probe the first time there is a log to draw. With this, if you boot with quiet,drm_logwon't do any modeset.
* Add color support for the timestamp prefix, like what dmesg does.
* Add build dependency on disabling the fbdev emulation, as they are bothdrm_client, and there is no way to choose which one gets the focus.Thanks and best regards,
I tested it, and it seems pretty cool. And fast, it seems to keep up when I echo 100,000 lines to /dev/kmsg with seq