drm/panic: Split into core and helpers
Subsystems (26)
Thomas Zimmermann
maintainerPATCH 7/12 drm/panic: Retry in dispatch function if panic output fails
In reply to Thomas ZimmermannOn failed output of QR codes and kmsg buffers, fall back to a user message. QR-code output already did this internally, but now formally support it in drm_panic_dispatch(). Streamlines the existing logic.
Also pass module parameter drm_panic_type as a parameter to drm_panic_dispatch(). This simpifies the implementation. It will later allow for moving the function into a helper library.
--- drivers/gpu/drm/drm_panic.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/gpu/drm/drm_panic.c +12 -12
@@ -746,9 +746,9 @@ static int drm_panic_get_qr_code(u8 **qr_image, unsigned int qr_version)/* * Draw the panic message at the center of the screen, with a QR Code */ -static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color, +unsigned int qr_version) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg, r_qr, r_qr_canvas;
@@ -816,15 +816,6 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,drm_panic_blit (sb, &r_qr, qr_image, qr_pitch, scale, fg_color); return 0; } - -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) -{ -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version)) -draw_panic_screen_user (sb, fg_color, bg_color); -return 0 ; -}#else static void drm_panic_qr_init (void ) {};static void drm_panic_qr_exit (void ) {};
@@ -899,13 +890,22 @@ static int draw_panic_dispatch(struct drm_scanout_buffer *sb, enum drm_panic_typ {int ret; +retry:switch (panic_type) {case DRM_PANIC_TYPE_KMSG : ret =draw_panic_screen_kmsg (sb, fg_color, bg_color); +if (ret) { + panic_type =DRM_PANIC_TYPE_USER ; + goto retry; + }break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : ret =draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version); +if (ret) { + panic_type =DRM_PANIC_TYPE_USER ; + goto retry; + }break ;#endif case DRM_PANIC_TYPE_USER :
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 11/12 drm/panic: Move panic display code into helper library
In reply to Thomas ZimmermannMove drm_plane_helper_display_panic_screen() and the existing panic- display code into drm_panic_helper.c. Rename symbols accordingly. Also update the QR-related code and the bindings accordingly.
Link the rsp. object file into drm_kms_helper.ko. Eventually the code will become a DRM drawing library, together with DRM's format and draw helpers. This requires more preparation. until then, KMS helpers serve as a module. All DRM drivers link it anyway.
Add a new section about drawing helpers to the documentation of the KMS helpers. List format and panic helpers there.
---
Documentation/gpu/drm-kms-helpers.rst | 11 +-
MAINTAINERS | 5 +-
drivers/gpu/drm/Kconfig | 5 +
drivers/gpu/drm/Makefile | 3 +-
drivers/gpu/drm/drm_crtc_internal.h | 2 -
drivers/gpu/drm/drm_drv.c | 1 -
drivers/gpu/drm/drm_kms_helper_common.c | 14 +
drivers/gpu/drm/drm_panic.c | 891 -----------------
drivers/gpu/drm/drm_panic_helper.c | 913 ++++++++++++++++++
...drm_panic_qr.rs => drm_panic_helper_qr.rs} | 4 +-
drivers/gpu/drm/drm_panic_internal.h | 4 +
...m_panic_test.c => drm_panic_helper_test.c} | 24 +-
include/drm/drm_panic.h | 7 -
include/drm/drm_panic_helper.h | 5 +
rust/bindings/bindings_helper.h | 4 +-
15 files changed, 972 insertions(+), 921 deletions(-)
create mode 100644 drivers/gpu/drm/drm_panic_helper.c
rename drivers/gpu/drm/{drm_panic_qr.rs => drm_panic_helper_qr.rs} (99%)
rename drivers/gpu/drm/tests/{drm_panic_test.c => drm_panic_helper_test.c} (88%)Documentation/gpu/drm-kms-helpers.rst +10 -1
@@ -118,12 +118,21 @@ fbdev Helper Functions Reference .. kernel-doc:: drivers/gpu/drm/drm_fb_helper.c :export: -format Helper Functions Reference +Draw Helper Functions Reference ================================= +Format-Conversion Helper Reference +---------------------------------- + .. kernel-doc:: drivers/gpu/drm/drm_format_helper.c :export: +Panic Helper Reference +---------------------- + +.. kernel-doc:: drivers/gpu/drm/drm_panic_helper.c + :export: + Framebuffer DMA Helper Functions Reference ==========================================
MAINTAINERS +3 -2
@@ -9019,8 +9019,9 @@ T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: drivers/gpu/drm/drm_draw.c F: drivers/gpu/drm/drm_draw_internal.h F: drivers/gpu/drm/drm_panic.c +F: drivers/gpu/drm/drm_panic_helper.c F: drivers/gpu/drm/drm_panic_internal.h -F: drivers/gpu/drm/tests/drm_panic_test.c +F: drivers/gpu/drm/tests/drm_panic_helper_test.c F: include/drm/drm_panic.h F: include/drm/drm_panic_helper.h
@@ -9031,7 +9032,7 @@ L: [email protected] L: [email protected] S: Supported T: git https://gitlab.freedesktop.org/drm/misc/kernel.git -F: drivers/gpu/drm/drm_panic_qr.rs +F: drivers/gpu/drm/drm_panic_helper_qr.rs DRM PRIVACY-SCREEN CLASS M: Hans de Goede <[email protected]>
drivers/gpu/drm/Kconfig +5 -0
@@ -45,6 +45,7 @@ config DRM_MIPI_DSI config DRM_KMS_HELPER tristate depends on DRM + select DRM_PANIC_HELPER if DRM_PANIC select FB_CORE if DRM_FBDEV_EMULATION help CRTC helpers for KMS drivers.
@@ -130,6 +131,10 @@ config DRM_PANIC_SCREEN_QR_VERSION Smaller QR code are easier to read, but will contain less debugging data. Default is 40. +config DRM_PANIC_HELPER + bool + depends on DRM_TTM + config DRM_RAS bool "DRM RAS support" depends on DRM
drivers/gpu/drm/Makefile +2 -1
@@ -92,7 +92,6 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ 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 drm-$(CONFIG_DRM_RAS) += drm_ras.o drm_ras_nl.o drm_ras_genl_family.o obj-$(CONFIG_DRM) += drm.o
@@ -157,6 +156,8 @@ drm_kms_helper-y := \ drm_simple_kms_helper.o \ drm_vblank_helper.o drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o +drm_kms_helper-$(CONFIG_DRM_PANIC_HELPER) += drm_panic_helper.o +drm_kms_helper-$(CONFIG_DRM_PANIC_SCREEN_QR_CODE) += drm_panic_helper_qr.o drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
drivers/gpu/drm/drm_crtc_internal.h +0 -2
@@ -322,13 +322,11 @@ 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 +0 -1
@@ -1248,7 +1248,6 @@ static void drm_core_exit(void) {drm_ras_genl_family_unregister ();drm_privacy_screen_lookup_exit (); -drm_panic_exit ();accel_core_exit ();unregister_chrdev (DRM_MAJOR ,"drm" );drm_debugfs_remove_root ();
drivers/gpu/drm/drm_kms_helper_common.c +14 -0
@@ -27,6 +27,20 @@#include <linux/module.h> +#include "drm_panic_internal.h" + +static int __init drm_kms_helper_init (void ) +{ +return drm_panic_helper_init (); +} +module_init (drm_kms_helper_init); + +static void __exit drm_kms_helper_exit(void) +{ +drm_panic_helper_exit (); +} +module_exit (drm_kms_helper_exit); +MODULE_AUTHOR ("David Airlie, Jesse Barnes" );MODULE_DESCRIPTION ("DRM KMS helper" );MODULE_LICENSE ("GPL and additional rights" );
drivers/gpu/drm/drm_panic.c +0 -891
933 lines not on this page · raw message
drivers/gpu/drm/drm_panic_helper.c new file +913 -0
913 lines not on this page · raw message
drivers/gpu/drm/drm_panic_helper_qr.rs renamed from drivers/gpu/drm/drm_panic_qr.rs +2 -2
@@ -938,7 +938,7 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {/// /// They must remain valid for the duration of the function call. #[export] -pub unsafe extern "C" fn drm_panic_qr_generate ( +pub unsafe extern "C" fn drm_panic_helper_qr_generate ( url: *const kernel::ffi::c_char , data: *mut u8 , data_len: usize,
@@ -994,7 +994,7 @@ fn draw_all(&mut self, data: impl Iterator<Item = u8>) {/// Always safe to call. // Required to be unsafe due to the `#[export]` annotation. #[export] -pub unsafe extern "C" fn drm_panic_qr_max_data_size (version:u8 , url_len:usize ) ->usize { +pub unsafe extern "C" fn drm_panic_helper_qr_max_data_size (version:u8 , url_len:usize ) ->usize {#[expect(clippy::manual_range_contains)] if version <1 || version >40 {return 0 ;
drivers/gpu/drm/drm_panic_internal.h +4 -0
@@ -52,4 +52,8 @@ static inline void drm_panic_lock(struct drm_device *dev, unsigned long flags) {static inline void drm_panic_unlock (struct drm_device *dev,unsigned long flags) {}#endif +/* drm_panic_helper.c */ +int drm_panic_helper_init (void ); +void drm_panic_helper_exit (void ); +#endif /* __DRM_PANIC_INTERNAL_H__ */
drivers/gpu/drm/tests/drm_panic_helper_test.c renamed from drivers/gpu/drm/tests/drm_panic_test.c +12 -12
@@ -3,7 +3,7 @@* Copyright (c) 2025 Red Hat. * Author: Jocelyn Falempe <[email protected]> * -* KUNIT tests for drm panic +* KUNIT tests for DRM panic helpers */ #include <drm/drm_fourcc.h>
@@ -41,24 +41,24 @@ struct drm_test_mode { .width = w, \ .height = h, \ .format = f, \ - .draw_screen = draw_panic_screen_ ## name ## _default, \ + .draw_screen = drm_panic_helper_draw_screen_ ## name ## _default, \ .fname = #name, \ }, \ -static int draw_panic_screen_user_default (struct drm_scanout_buffer *sb) +static int drm_panic_helper_draw_screen_user_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_user (sb,0x00ffffff ,0x00000000 ); +return drm_panic_helper_draw_screen_user (sb,0x00ffffff ,0x00000000 ); } -static int draw_panic_screen_kmsg_default (struct drm_scanout_buffer *sb) +static int drm_panic_helper_draw_screen_kmsg_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_kmsg (sb,0x00ffffff ,0x00000000 ); +return drm_panic_helper_draw_screen_kmsg (sb,0x00ffffff ,0x00000000 ); }#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) -static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) +static int drm_panic_helper_draw_screen_qr_code_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ,40 ); +return drm_panic_helper_draw_screen_qr_code (sb,0x00ffffff ,0x00000000 ,40 ); }#endif
@@ -81,7 +81,7 @@ static int drm_test_panic_init(struct kunit *test) test->priv = priv; -drm_panic_set_description ("Kunit testing" ); +drm_panic_helper_set_description ("Kunit testing" );return 0 ; }
@@ -226,10 +226,10 @@ static struct kunit_case drm_panic_screen_user_test[] = { { } }; -static struct kunit_suite drm_panic_suite = { - .name ="drm_panic" , +static struct kunit_suite drm_panic_helper_suite = { + .name ="drm_panic_helper" , .init = drm_test_panic_init, .test_cases = drm_panic_screen_user_test, }; -kunit_test_suite (drm_panic_suite); +kunit_test_suite (drm_panic_helper_suite);
include/drm/drm_panic.h +0 -7
@@ -85,11 +85,4 @@ struct drm_scanout_buffer { void *private; }; -#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE ) -size_t drm_panic_qr_max_data_size (u8 version,size_t url_len); - -u8 drm_panic_qr_generate (const char *url,u8 *data,size_t data_len,size_t data_size, -u8 *tmp,size_t tmp_size); -#endif -#endif /* __DRM_PANIC_H__ */
include/drm/drm_panic_helper.h +5 -0
@@ -16,6 +16,11 @@ void drm_plane_helper_display_panic_screen(struct drm_plane *plane, u32 fg_color, u32 bg_color, unsigned int qr_version); +/* drm_panic_helper_qr.rs */ +size_t drm_panic_helper_qr_max_data_size (u8 version,size_t url_len); +u8 drm_panic_helper_qr_generate (const char *url,u8 *data,size_t data_len,size_t data_size, +u8 *tmp,size_t tmp_size); +#if IS_ENABLED (CONFIG_DRM_PANIC )#define DRM_PANIC_PLANE_FUNCS \ .display_panic_screen = drm_plane_helper_display_panic_screen
rust/bindings/bindings_helper.h +2 -2
@@ -102,8 +102,8 @@#include <../../drivers/base/base.h> #if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE ) -// Used by `#[export]` in `drivers/gpu/drm/drm_panic_qr.rs`. -#include <drm/drm_panic.h> +// Used by `#[export]` in `drivers/gpu/drm/drm_panic_helper_qr.rs`. +#include <drm/drm_panic_helper.h> #endif /* `bindgen` gets confused at certain things. */
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 12/12 drm/panic: Compile KUnit tests as module
In reply to Thomas ZimmermannFix dependency of the panic-helper KUnit tests on CONFIG_DRM_KUNIT_TEST=y and make them build as a module. Export the necessary interfaces from the panic helpers iff the KUnit framework has been enabled.
Select DRM_PANIC_HELPER from DRM_KUNIT_TEST to meet the dependencies of the panic-helper tests.
It is now possible to run the tests by modprobing drm_panic_helper_test.ko at runtime.
--- drivers/gpu/drm/Kconfig.debug | 1 + drivers/gpu/drm/drm_panic_helper.c | 26 ++++++++++--------- drivers/gpu/drm/tests/Makefile | 1 + drivers/gpu/drm/tests/drm_panic_helper_test.c | 15 ++++++++--- include/drm/drm_panic_helper.h | 8 ++++++ 5 files changed, 35 insertions(+), 16 deletions(-)
drivers/gpu/drm/Kconfig.debug +1 -0
@@ -69,6 +69,7 @@ config DRM_KUNIT_TEST select DRM_EXPORT_FOR_TESTS if m select DRM_GEM_SHMEM_HELPER select DRM_KUNIT_TEST_HELPERS + select DRM_PANIC_HELPER select DRM_SYSFB_HELPER select PRIME_NUMBERS default KUNIT_ALL_TESTS
drivers/gpu/drm/drm_panic_helper.c +14 -12
@@ -8,6 +8,8 @@#include <linux/utsname.h> #include <linux/zlib.h> +#include <kunit/visibility.h> +#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_modeset_helper_vtables.h>
@@ -431,8 +433,8 @@ static void drm_panic_helper_logo_draw(struct drm_scanout_buffer *sb, struct drm fg_color); } -static int drm_panic_helper_draw_screen_user (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color) +VISIBLE_IF_KUNIT int drm_panic_helper_draw_screen_user(struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg;
@@ -464,6 +466,7 @@ static int drm_panic_helper_draw_screen_user(struct drm_scanout_buffer *sb,return 0 ; } +EXPORT_SYMBOL_IF_KUNIT (drm_panic_helper_draw_screen_user);/* * Draw one line of kmsg, and handle wrapping if it won't fit in the screen width.
@@ -502,8 +505,8 @@ static int draw_line_with_wrap(struct drm_scanout_buffer *sb, const struct font_* Draw the kmsg buffer to the screen, starting from the youngest message at the bottom, * and going up until reaching the top of the screen. */ -static int drm_panic_helper_draw_screen_kmsg (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color) +VISIBLE_IF_KUNIT int drm_panic_helper_draw_screen_kmsg(struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);
@@ -547,6 +550,7 @@ static int drm_panic_helper_draw_screen_kmsg(struct drm_scanout_buffer *sb,return 0 ; } +EXPORT_SYMBOL_IF_KUNIT (drm_panic_helper_draw_screen_kmsg);#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE )/*
@@ -697,9 +701,9 @@ static int drm_panic_helper_get_qr_code(u8 **qr_image, unsigned int qr_version)/* * Draw the panic message at the center of the screen, with a QR Code */ -static int drm_panic_helper_draw_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) +VISIBLE_IF_KUNIT int drm_panic_helper_draw_screen_qr_code(struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color, +unsigned int qr_version) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg, r_qr, r_qr_canvas;
@@ -767,6 +771,7 @@ static int drm_panic_helper_draw_screen_qr_code(struct drm_scanout_buffer *sb,drm_panic_helper_blit (sb, &r_qr, qr_image, qr_pitch, scale, fg_color);return 0 ; } +EXPORT_SYMBOL_IF_KUNIT (drm_panic_helper_draw_screen_qr_code);#else static void __init drm_panic_helper_qr_init (void ) {}; static void __exit drm_panic_helper_qr_exit(void) {};
@@ -819,7 +824,7 @@ static int draw_panic_helper_dispatch(struct drm_scanout_buffer *sb,return ret; } -static void drm_panic_helper_set_description (const char *description) +VISIBLE_IF_KUNIT void drm_panic_helper_set_description(const char *description) {u32 len;
@@ -834,6 +839,7 @@ static void drm_panic_helper_set_description(const char *description) desc_line->len = len; } } +EXPORT_SYMBOL_IF_KUNIT (drm_panic_helper_set_description);static void drm_panic_helper_clear_description (void ) {
@@ -907,7 +913,3 @@ void __exit drm_panic_helper_exit(void) {drm_panic_helper_qr_exit (); } - -#ifdef CONFIG_DRM_KUNIT_TEST -#include "tests/drm_panic_helper_test.c" -#endif
drivers/gpu/drm/tests/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \ drm_managed_test.o \ drm_mm_test.o \ drm_modes_test.o \ + drm_panic_helper_test.o \ drm_plane_helper_test.o \ drm_probe_helper_test.o \ drm_rect_test.o \
drivers/gpu/drm/tests/drm_panic_helper_test.c +11 -4
@@ -6,13 +6,17 @@* KUNIT tests for DRM panic helpers */ -#include <drm/drm_fourcc.h> -#include <drm/drm_panic.h> +#include <linux/highmem.h> +#include <linux/units.h> +#include <linux/vmalloc.h> #include <kunit/test.h> -#include <linux/units.h> -#include <linux/vmalloc.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> + +MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" );static void drm_panic_check_color_byte (struct kunit *test,u8 b) {
@@ -233,3 +237,6 @@ static struct kunit_suite drm_panic_helper_suite = { };kunit_test_suite (drm_panic_helper_suite); + +MODULE_DESCRIPTION ("KUnit test suite for DRM panic handling" ); +MODULE_LICENSE ("GPL" );
include/drm/drm_panic_helper.h +8 -0
@@ -8,6 +8,7 @@enum drm_panic_type ;struct drm_plane ; +struct drm_scanout_buffer ;/* drm_panic_helper.c */ void drm_plane_helper_display_panic_screen(struct drm_plane *plane,
@@ -15,6 +16,13 @@ void drm_plane_helper_display_panic_screen(struct drm_plane *plane,enum drm_panic_type panic_type, u32 fg_color, u32 bg_color, unsigned int qr_version); +#if IS_ENABLED (CONFIG_KUNIT ) +int drm_panic_helper_draw_screen_user (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color); +int drm_panic_helper_draw_screen_kmsg (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color); +int drm_panic_helper_draw_screen_qr_code (struct drm_scanout_buffer *sb,unsigned int qr_version, +u32 fg_color,u32 bg_color); +void drm_panic_helper_set_description (const char *description); +#endif /* drm_panic_helper_qr.rs */ size_t drm_panic_helper_qr_max_data_size (u8 version,size_t url_len);
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainercover drm/panic: Split into core and helpers
Split DRM's current panic handling into a core and a helper module. The core is still part of DRM's core library. The panic helpers are part of DRM's KMS helper module (for now).
The motivation behind this series is to get panic handling's drawing code out of the DRM core. At some point it should share a single module with DRM's other drawing and format conversion.
With the series applied, panic hanlding follows DRM's established design pattern of having a DRM core interface with an dedicated implementation in each driver. Drivers share common code in helper modules. For panic handling, the DRM core still contains the panic entry points, the parameters and the debugfs interface. All drawing is now located in the panic helpers.
Patches 1 to 4 improve several issues in the current panic code. It makes sense to fix them before moving the core around.
Patches 5 to 8 put handling of all panic state and locking into a single place, drm_panic_display_panic_screen(). It is maintained by panic handling's DRM core code. This also enables the test cases to work more independently from the kernel's configuration.
Patches 9 to 11 split the panic-handling code into the core and panic helpers. The former maintain all state, locking and public interfaces. The latter handles drawing and details of the involved framebuffers.
DRM devices that offer panic handling provide a single callback, struct drm_plane_funcs.display_panic_screen. A new initializer macro makes it point to the existing panic-drawing implementation. Hence there's no change in features or functionality. If panic handling is configured off, it all clears out to NULL.
Patch 12 reworks the test cases slighly, so that they can be build as a separate module. Do 'modprobe drm_panic_helper_test' to run them.
Tested under bochs with debugfs and test cases.
Future directions:
- Panic handling shares some drawing code with format conversion and clients. There's even more drawing code in vkms. Later series' can attempt to unify and harmonize all these implementations in a single draw module.
- The drawing helper drm_plane_helper_display_panic_screen() still implements various access schemes (map, set_pixel, memcpy) in a single function. It could be split up into specifialized helpers.
- If we ever need a driver-specific helper, it is now possible to implement a custom version of display_panic_screen.
Thomas Zimmermann (12):
drm/panic: Allocate QR-code buffers statically drm/panic: Make allocation of zlib workspace more robust drm/panic: Return -EINVAL if font is not available drm/panic: Return errno codes if panic output fails drm/panic: Pass colors to draw_panic_dispatch() drm/panic: Pass global module parameters to drm_panic_dispatch() drm/panic: Retry in dispatch function if panic output fails drm/panic: Split draw_panic_plane()
drm/panic: Display panic screen via per-plane callback drm/panic: Internalize panic locking in DRM core and helpers drm/panic: Move panic display code into helper library drm/panic: Compile KUnit tests as module
Documentation/gpu/drm-kms-helpers.rst | 11 +-
Documentation/gpu/drm-kms.rst | 3 +
MAINTAINERS | 11 +-
drivers/gpu/drm/Kconfig | 5 +
drivers/gpu/drm/Kconfig.debug | 1 +
drivers/gpu/drm/Makefile | 3 +-
.../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 2 +
drivers/gpu/drm/ast/ast_mode.c | 2 +
drivers/gpu/drm/drm_atomic_helper.c | 2 +-
drivers/gpu/drm/drm_crtc_internal.h | 2 -
drivers/gpu/drm/drm_drv.c | 3 +-
drivers/gpu/drm/drm_kms_helper_common.c | 14 +
drivers/gpu/drm/drm_panic.c | 914 +----------------
drivers/gpu/drm/drm_panic_helper.c | 915 ++++++++++++++++++
...drm_panic_qr.rs => drm_panic_helper_qr.rs} | 4 +-
drivers/gpu/drm/drm_panic_internal.h | 59 ++
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 2 +
drivers/gpu/drm/i915/display/i9xx_plane.c | 3 +
.../drm/i915/display/skl_universal_plane.c | 4 +
drivers/gpu/drm/imx/ipuv3/ipuv3-plane.c | 2 +
drivers/gpu/drm/mgag200/mgag200_drv.h | 4 +-
drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 +
.../gpu/drm/renesas/rcar-du/rcar_du_plane.c | 2 +
.../drm/renesas/shmobile/shmob_drm_plane.c | 2 +
drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 4 +-
drivers/gpu/drm/sysfb/vesadrm.c | 1 +
drivers/gpu/drm/tests/Makefile | 1 +
...m_panic_test.c => drm_panic_helper_test.c} | 65 +-
drivers/gpu/drm/tidss/tidss_plane.c | 2 +
drivers/gpu/drm/tiny/bochs.c | 4 +-
drivers/gpu/drm/virtio/virtgpu_plane.c | 2 +
include/drm/drm_mode_config.h | 4 +-
include/drm/drm_modeset_helper_vtables.h | 11 +-
include/drm/drm_panic.h | 117 +--
include/drm/drm_panic_helper.h | 40 +
include/drm/drm_plane.h | 57 ++
rust/bindings/bindings_helper.h | 4 +-
37 files changed, 1253 insertions(+), 1031 deletions(-)
create mode 100644 drivers/gpu/drm/drm_panic_helper.c
rename drivers/gpu/drm/{drm_panic_qr.rs => drm_panic_helper_qr.rs} (99%)
create mode 100644 drivers/gpu/drm/drm_panic_internal.h
rename drivers/gpu/drm/tests/{drm_panic_test.c => drm_panic_helper_test.c} (80%)
create mode 100644 include/drm/drm_panic_helper.hbase-commit: dc462ab791b686c48545c160ecc81be64f77a846
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24
prerequisite-patch-id: a5a973e527c88a5b47053d7a72aefe0b550197cb
prerequisite-patch-id: b9adc9622920a3e70168e672c2c92795b3e3a106
prerequisite-patch-id: 5030de433a01c2e99056cadb676a8e2ba35f055a
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 5/12 drm/panic: Pass colors to draw_panic_dispatch()
Set the panic-screen colors in draw_panic_plane() as a single point of truth. Pass the values into the individual drawing functions.
In the test cases, replace the Kconfig-defined colors with white and black. Allows for removal of the tests' limitations and dependency on the exact values. All tests now always verify the generated output.
Hardcoding the test colors will later also allow for building the test case without having DRM panic handling enabled.
--- drivers/gpu/drm/drm_panic.c | 54 +++++++++++++++----------- drivers/gpu/drm/tests/drm_panic_test.c | 26 +++++++++---- 2 files changed, 49 insertions(+), 31 deletions(-)
drivers/gpu/drm/drm_panic.c +31 -23
@@ -478,12 +478,8 @@ static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct drm_rect * fg_color); } -static int draw_panic_screen_user (struct drm_scanout_buffer *sb) +static int draw_panic_screen_user (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) { -u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , - sb->format->format); -u32 bg_color =drm_draw_color_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 msg_width, msg_height;
@@ -491,6 +487,9 @@ static int draw_panic_screen_user(struct drm_scanout_buffer *sb)if (!font)return -EINVAL ; + fg_color =drm_draw_color_from_xrgb8888 (fg_color, sb->format->format); + bg_color =drm_draw_color_from_xrgb8888 (bg_color, sb->format->format); + r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);drm_panic_logo_rect (&r_logo, font);
@@ -549,12 +548,8 @@ static int draw_line_with_wrap(struct drm_scanout_buffer *sb, const struct font_* Draw the kmsg buffer to the screen, starting from the youngest message at the bottom, * and going up until reaching the top of the screen. */ -static int draw_panic_screen_kmsg (struct drm_scanout_buffer *sb) +static int draw_panic_screen_kmsg (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) { -u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , - sb->format->format); -u32 bg_color =drm_draw_color_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 =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);struct kmsg_dump_iter iter;
@@ -566,6 +561,9 @@ static int draw_panic_screen_kmsg(struct drm_scanout_buffer *sb)if (!font || font->width > sb->width)return -EINVAL ; + fg_color =drm_draw_color_from_xrgb8888 (fg_color, sb->format->format); + bg_color =drm_draw_color_from_xrgb8888 (bg_color, sb->format->format); + yoffset = sb->height - font->height - (sb->height % font->height) /2 ;/* Fill with the background color, and draw text on top */
@@ -748,12 +746,9 @@ static int drm_panic_get_qr_code(u8 **qr_image)/* * Draw the panic message at the center of the screen, with a QR Code */ -static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color) { -u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , - sb->format->format); -u32 bg_color =drm_draw_color_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, r_qr, r_qr_canvas;unsigned int max_qr_size, scale;
@@ -766,6 +761,9 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb)if (!font)return -EINVAL ; + fg_color =drm_draw_color_from_xrgb8888 (fg_color, sb->format->format); + bg_color =drm_draw_color_from_xrgb8888 (bg_color, sb->format->format); + r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);drm_panic_logo_rect (&r_logo, font);
@@ -818,10 +816,10 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb) return 0; } -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) { -if (_draw_panic_screen_qr_code (sb)) -draw_panic_screen_user (sb); +if (_draw_panic_screen_qr_code (sb, fg_color, bg_color)) +draw_panic_screen_user (sb, fg_color, bg_color);return 0 ; }#else
@@ -893,22 +891,22 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format)return drm_draw_can_convert_from_xrgb8888 (format->format); } -static int draw_panic_dispatch (struct drm_scanout_buffer *sb) +static int draw_panic_dispatch (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) {int ret;switch (drm_panic_type) {case DRM_PANIC_TYPE_KMSG : - ret =draw_panic_screen_kmsg (sb); + ret =draw_panic_screen_kmsg (sb, fg_color, bg_color);break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : - ret =draw_panic_screen_qr_code (sb); + ret =draw_panic_screen_qr_code (sb, fg_color, bg_color);break ;#endif case DRM_PANIC_TYPE_USER :default : - ret =draw_panic_screen_user (sb); + ret =draw_panic_screen_user (sb, fg_color, bg_color); }return ret;
@@ -943,6 +941,16 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)struct drm_scanout_buffer sb = { };int ret;unsigned long flags; +#if defined(CONFIG_DRM_PANIC_FOREGROUND_COLOR ) +u32 fg_color =CONFIG_DRM_PANIC_FOREGROUND_COLOR ; +#else +u32 fg_color =0x00ffffff ; +#endif +#if defined(CONFIG_DRM_PANIC_BACKGROUND_COLOR ) +u32 bg_color =CONFIG_DRM_PANIC_BACKGROUND_COLOR ; +#else +u32 bg_color =0x00000000 ; +#endif if (!drm_panic_trylock (plane->dev, flags))return ;
@@ -958,7 +966,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); - ret =draw_panic_dispatch (&sb); + ret =draw_panic_dispatch (&sb, fg_color, bg_color);if (!ret) {/* * Only flush if we have a panic screen to display. Otherwise
drivers/gpu/drm/tests/drm_panic_test.c +18 -8
@@ -14,17 +14,10 @@#include <linux/units.h> #include <linux/vmalloc.h> -/* Check the framebuffer color only if the panic colors are the default */ -#if (CONFIG_DRM_PANIC_BACKGROUND_COLOR ==0 && \ -CONFIG_DRM_PANIC_FOREGROUND_COLOR ==0xffffff ) -static void drm_panic_check_color_byte (struct kunit *test,u8 b) {KUNIT_EXPECT_TRUE (test, (b ==0 || b ==0xff )); } -#else -static void drm_panic_check_color_byte (struct kunit *test,u8 b) {} -#endif struct drm_test_mode {const int width;
@@ -48,10 +41,27 @@ struct drm_test_mode { .width = w, \ .height = h, \ .format = f, \ - .draw_screen = draw_panic_screen_##name, \ + .draw_screen = draw_panic_screen_ ## name ## _default, \ .fname = #name, \ }, \ +static int draw_panic_screen_user_default (struct drm_scanout_buffer *sb) +{ +return draw_panic_screen_user (sb,0x00ffffff ,0x00000000 ); +} + +static int draw_panic_screen_kmsg_default (struct drm_scanout_buffer *sb) +{ +return draw_panic_screen_kmsg (sb,0x00ffffff ,0x00000000 ); +} + +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) +{ +return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ); +} +#endif +static const struct drm_test_mode drm_test_modes_cases[] = { DRM_TEST_MODE_LIST(user)DRM_TEST_MODE_LIST (kmsg)
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 9/12 drm/panic: Display panic screen via per-plane callback
In reply to Thomas ZimmermannAdd display_panic_screen to struct drm_plane_funcs. If set on a plane, register a panic handler for the plane from the DRM core's panic handling. Invoke this helper from the core to display a panic screen.
The new callback replaces get_scanout_buffer as signal for panic support in a plane. Using get_scanout_buffer is now merely a detail of the implementation. This will also free struct drm_scanout_buffer for use cases besides panic handling.
With display_panic_screen in place, rename draw_panic_plane() to drm_plane_helper_display_panic_screen() and make it available to DRM drivers via drm_panic_helper.h. Do not change the implementation or functionality of this code. drm_plane_helper_display_panic_screen() still supports kernel messages, user messages and QR codes on various color formats.
Then update all drivers that implement panic support. Provide the initializer macro DRM_PANIC_PLANE_FUNCS that sets display_panic_screen to drm_plane_helper_display_panic_screen(). If panic handling has been disabled, it instead clears the callback. There's again no change in functionality.
This logically splits panic handling into a set of entry points in the DRM code and a set of helper functions provided by drivers. The core invokes the driver's helper via callback, while the driver can tailor the implementation to its needs. Panic handling now works like most other interfaces in the DRM framework.
Locking and state-handling happens in the DRM core or helpers. Drivers that receive a call to display_panic_screen can assume that no concurrent modeset takes place on the plane or its CRTC.
Also update the documentation. Move information about locking and state guarantees from drm_panic_trylock() to display_panic_screen, where drivers authors can find it easily. Move information about the features of the current implementation to drm_panic_helper_display_panic_screen().
--- MAINTAINERS | 3 +- .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 2 + drivers/gpu/drm/ast/ast_mode.c | 2 + drivers/gpu/drm/drm_panic.c | 78 ++++++++++--------- drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 2 + drivers/gpu/drm/i915/display/i9xx_plane.c | 3 + .../drm/i915/display/skl_universal_plane.c | 4 + drivers/gpu/drm/imx/ipuv3/ipuv3-plane.c | 2 + drivers/gpu/drm/mgag200/mgag200_drv.h | 4 +- drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 + .../gpu/drm/renesas/rcar-du/rcar_du_plane.c | 2 + .../drm/renesas/shmobile/shmob_drm_plane.c | 2 + drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 4 +- drivers/gpu/drm/sysfb/vesadrm.c | 1 + drivers/gpu/drm/tidss/tidss_plane.c | 2 + drivers/gpu/drm/tiny/bochs.c | 4 +- drivers/gpu/drm/virtio/virtgpu_plane.c | 2 + include/drm/drm_mode_config.h | 4 +- include/drm/drm_modeset_helper_vtables.h | 11 ++- include/drm/drm_panic.h | 49 +++--------- include/drm/drm_panic_helper.h | 27 +++++++ include/drm/drm_plane.h | 57 ++++++++++++++ 22 files changed, 180 insertions(+), 87 deletions(-) create mode 100644 include/drm/drm_panic_helper.h
MAINTAINERS +2 -1
@@ -9020,7 +9020,8 @@ F: drivers/gpu/drm/drm_draw.c F: drivers/gpu/drm/drm_draw_internal.h F: drivers/gpu/drm/drm_panic*.c F: drivers/gpu/drm/tests/drm_panic_test.c -F: include/drm/drm_panic* +F: include/drm/drm_panic.h +F: include/drm/drm_panic_helper.h DRM PANIC QR CODE M: Jocelyn Falempe <[email protected]>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +2 -0
@@ -28,6 +28,7 @@#include <drm/drm_blend.h> #include "drm/drm_framebuffer.h" #include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_fourcc.h>
@@ -2177,6 +2178,7 @@ static const struct drm_plane_funcs dm_plane_funcs = { .atomic_set_property = dm_atomic_plane_set_property, .atomic_get_property = dm_atomic_plane_get_property,#endif + DRM_PANIC_PLANE_FUNCS, }; int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
drivers/gpu/drm/ast/ast_mode.c +2 -0
@@ -43,6 +43,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_managed.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h>
@@ -652,6 +653,7 @@ static const struct drm_plane_funcs ast_primary_plane_funcs = { .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup,DRM_GEM_SHADOW_PLANE_FUNCS , + DRM_PANIC_PLANE_FUNCS, };static int ast_primary_plane_init (struct ast_device *ast)
drivers/gpu/drm/drm_panic.c +40 -38
134 lines not on this page · raw message
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +2 -0
@@ -18,6 +18,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_probe_helper.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane.h> #include <drm/drm_print.h> #include <drm/drm_vblank.h>
@@ -237,6 +238,7 @@ static const struct drm_plane_funcs hv_drm_plane_funcs = { .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup,DRM_GEM_SHADOW_PLANE_FUNCS , + DRM_PANIC_PLANE_FUNCS, }; static const struct drm_encoder_funcs hv_drm_simple_encoder_funcs_cleanup = {
drivers/gpu/drm/i915/display/i9xx_plane.c +3 -0
@@ -8,6 +8,7 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_blend.h> #include <drm/drm_fourcc.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include "i9xx_plane.h"
@@ -887,6 +888,7 @@ static const struct drm_plane_funcs i965_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = i965_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static const struct drm_plane_funcs i8xx_plane_funcs = {
@@ -897,6 +899,7 @@ static const struct drm_plane_funcs i8xx_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = i8xx_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static void i9xx_disable_tiling (struct intel_plane *plane)
drivers/gpu/drm/i915/display/skl_universal_plane.c +4 -0
@@ -7,6 +7,7 @@#include <drm/drm_blend.h> #include <drm/drm_damage_helper.h> #include <drm/drm_fourcc.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <drm/intel/step.h>
@@ -2707,6 +2708,7 @@ static const struct drm_plane_funcs skl_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = skl_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static const struct drm_plane_funcs icl_plane_funcs = {
@@ -2717,6 +2719,7 @@ static const struct drm_plane_funcs icl_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = icl_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static const struct drm_plane_funcs tgl_plane_funcs = {
@@ -2727,6 +2730,7 @@ static const struct drm_plane_funcs tgl_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = tgl_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, }; static void
drivers/gpu/drm/imx/ipuv3/ipuv3-plane.c +2 -0
@@ -14,6 +14,7 @@#include <drm/drm_gem_atomic_helper.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <video/imx-ipu-v3.h>
@@ -362,6 +363,7 @@ static const struct drm_plane_funcs ipu_plane_funcs = { .atomic_duplicate_state = ipu_plane_duplicate_state, .atomic_destroy_state = ipu_plane_destroy_state, .format_mod_supported = ipu_plane_format_mod_supported, + DRM_PANIC_PLANE_FUNCS, }; static int ipu_plane_atomic_check(struct drm_plane *plane,
drivers/gpu/drm/mgag200/mgag200_drv.h +3 -1
@@ -17,6 +17,7 @@#include <drm/drm_encoder.h> #include <drm/drm_gem.h> #include <drm/drm_gem_shmem_helper.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane.h> #include "mgag200_reg.h"
@@ -386,7 +387,8 @@ int mgag200_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane, .update_plane = drm_atomic_helper_update_plane, \ .disable_plane = drm_atomic_helper_disable_plane, \ .destroy = drm_plane_cleanup, \ - DRM_GEM_SHADOW_PLANE_FUNCS +DRM_GEM_SHADOW_PLANE_FUNCS , \ + DRM_PANIC_PLANE_FUNCSvoid mgag200_crtc_fill_gamma (struct mga_device *mdev,const struct drm_format_info *format); void mgag200_crtc_load_gamma(struct mga_device *mdev,
drivers/gpu/drm/nouveau/dispnv50/wndw.c +2 -0
@@ -39,6 +39,7 @@#include <drm/drm_framebuffer.h> #include <drm/drm_gem_atomic_helper.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/ttm/ttm_bo.h> #include "nouveau_bo.h"
@@ -841,6 +842,7 @@ nv50_wndw = { .atomic_duplicate_state = nv50_wndw_atomic_duplicate_state, .atomic_destroy_state = nv50_wndw_atomic_destroy_state, .format_mod_supported = nv50_plane_format_mod_supported, + DRM_PANIC_PLANE_FUNCS, };static const u64 nv50_cursor_format_modifiers[] = {
drivers/gpu/drm/renesas/rcar-du/rcar_du_plane.c +2 -0
@@ -16,6 +16,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> +#include <drm/drm_panic_helper.h> #include "rcar_du_drv.h" #include "rcar_du_group.h"
@@ -773,6 +774,7 @@ static const struct drm_plane_funcs rcar_du_plane_funcs = { .atomic_destroy_state = rcar_du_plane_atomic_destroy_state, .atomic_set_property = rcar_du_plane_atomic_set_property, .atomic_get_property = rcar_du_plane_atomic_get_property, + DRM_PANIC_PLANE_FUNCS, };static const uint32_t formats[] = {
drivers/gpu/drm/renesas/shmobile/shmob_drm_plane.c +2 -0
@@ -14,6 +14,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> +#include <drm/drm_panic_helper.h> #include "shmob_drm_drv.h" #include "shmob_drm_kms.h"
@@ -286,6 +287,7 @@ static const struct drm_plane_funcs shmob_drm_plane_funcs = { .reset = shmob_drm_plane_reset, .atomic_duplicate_state = shmob_drm_plane_atomic_duplicate_state, .atomic_destroy_state = shmob_drm_plane_atomic_destroy_state, + DRM_PANIC_PLANE_FUNCS, };static const uint32_t formats[] = {
drivers/gpu/drm/sysfb/drm_sysfb_helper.h +3 -1
@@ -12,6 +12,7 @@#include <drm/drm_device.h> #include <drm/drm_gem_atomic_helper.h> #include <drm/drm_modes.h> +#include <drm/drm_panic_helper.h> struct drm_format_info ;struct drm_scanout_buffer ;
@@ -144,7 +145,8 @@ void drm_sysfb_plane_atomic_destroy_state(struct drm_plane *plane, .update_plane = drm_atomic_helper_update_plane, \ .disable_plane = drm_atomic_helper_disable_plane, \ .atomic_duplicate_state = drm_sysfb_plane_atomic_duplicate_state, \ - .atomic_destroy_state = drm_sysfb_plane_atomic_destroy_state + .atomic_destroy_state = drm_sysfb_plane_atomic_destroy_state, \ +DRM_PANIC_PLANE_FUNCS /* * CRTC
drivers/gpu/drm/sysfb/vesadrm.c +1 -0
@@ -24,6 +24,7 @@#include <drm/drm_managed.h> #include <drm/drm_modeset_helper.h> #include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h>
drivers/gpu/drm/tidss/tidss_plane.c +2 -0
@@ -12,6 +12,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_panic_helper.h> #include "tidss_crtc.h" #include "tidss_dispc.h"
@@ -182,6 +183,7 @@ static const struct drm_plane_funcs tidss_plane_funcs = { .atomic_create_state = drm_atomic_helper_plane_create_state, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + DRM_PANIC_PLANE_FUNCS, }; struct tidss_plane *tidss_plane_create(struct tidss_device *tidss,
drivers/gpu/drm/tiny/bochs.c +3 -1
@@ -20,6 +20,7 @@#include <drm/drm_managed.h> #include <drm/drm_module.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h>
@@ -501,7 +502,8 @@ static const struct drm_plane_funcs bochs_primary_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup, - DRM_GEM_SHADOW_PLANE_FUNCS +DRM_GEM_SHADOW_PLANE_FUNCS , + DRM_PANIC_PLANE_FUNCS, };static void bochs_crtc_helper_mode_set_nofb (struct drm_crtc *crtc)
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -0
@@ -30,6 +30,7 @@#include <linux/virtio_dma_buf.h> #include <drm/drm_managed.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include "virtgpu_drv.h"
@@ -94,6 +95,7 @@ static const struct drm_plane_funcs virtio_gpu_plane_funcs = { .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = virtio_gpu_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + DRM_PANIC_PLANE_FUNCS, }; static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
include/drm/drm_mode_config.h +2 -2
@@ -495,8 +495,8 @@ struct drm_mode_config {* * Raw spinlock used to protect critical sections of code that access * the display hardware or modeset software state, which the panic -* printing code must be protected against. See drm_panic_trylock(), -* drm_panic_lock() and drm_panic_unlock(). +* printing code must be protected against. See the documentation on +* DRM panic handling for more information. */ struct raw_spinlock panic_lock;
include/drm/drm_modeset_helper_vtables.h +7 -4
@@ -1442,17 +1442,20 @@ struct drm_plane_helper_funcs {/** * @get_scanout_buffer: * -* Get the current scanout buffer, to display a message with drm_panic. +* Get the current scanout buffer to display a message with drm_panic. * The driver should do the minimum changes to provide a buffer, * that can be used to display the panic screen. Currently only linear * buffers are supported. Non-linear buffer support is on the TODO list. * The device &dev.mode_config.panic_lock is taken before calling this * function, so you can safely access the &plane.state * It is called from a panic callback, and must follow its restrictions. -* Please look the documentation at drm_panic_trylock() for an in-depth +* Please look the documentation on DRM panic handling for an in-depth * discussions of what's safe and what is not allowed. +* * It's a best effort mode, so it's expected that in some complex cases -* the panic screen won't be displayed. +* the panic screen won't be displayed. Drivers must not make any +* assumptions about the actual state of the hardware. +* * The returned &drm_scanout_buffer.map must be valid if no error code is * returned. *
@@ -1472,7 +1475,7 @@ struct drm_plane_helper_funcs {* It is only called if get_scanout_buffer() returned successfully, and * the &dev.mode_config.panic_lock is held during the entire sequence. * It is called from a panic callback, and must follow its restrictions. -* Please look the documentation at drm_panic_trylock() for an in-depth +* Please look the documentation on DRM panic handling for an in-depth * discussions of what's safe and what is not allowed. */ void (*panic_flush)(struct drm_plane *plane);
include/drm/drm_panic.h +10 -39
61 lines not on this page · raw message
include/drm/drm_panic_helper.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 or MIT */ + +#ifndef __DRM_DRM_PANIC_HELPER_H_ +#define __DRM_DRM_PANIC_HELPER_H_ + +#include <linux/types.h> + +enum drm_panic_type ; + +struct drm_plane ; + +/* drm_panic_helper.c */ +void drm_plane_helper_display_panic_screen (struct drm_plane *plane, +const char *description, +enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color, +unsigned int qr_version); + +#if IS_ENABLED (CONFIG_DRM_PANIC ) +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = drm_plane_helper_display_panic_screen +#else +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = NULL +#endif + +#endif
include/drm/drm_plane.h +57 -0
69 lines not on this page · raw message
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 2/12 drm/panic: Make allocation of zlib workspace more robust
In reply to Thomas ZimmermannTest the zlib workspace size to not have a negative value. This would be a driver bug. Also touch allocated memory so that the pages are available upon a panic.
--- drivers/gpu/drm/drm_panic.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic.c +8 -2
@@ -634,13 +634,19 @@ static struct z_stream_s stream;static void __init drm_panic_qr_init (void ) { +int wssize; + + wssize =zlib_deflate_workspacesize (WINDOW_BITS ,MEM_LEVEL ); +if (WARN_ON_ONCE (wssize <0 )) +return ;/* best-effort allocation; can be NULL */ - stream.workspace =kmalloc (zlib_deflate_workspacesize (WINDOW_BITS ,MEM_LEVEL ), -GFP_KERNEL ); + stream.workspace =kmalloc (wssize,GFP_KERNEL );/* touch memory so that pages are there in the case of a panic */ memset (qrbuf1,0 ,sizeof (qrbuf1));memset (qrbuf2,0 ,sizeof (qrbuf2)); +if (stream.workspace) +memset (stream.workspace,0 , wssize); }static void drm_panic_qr_exit (void )
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 3/12 drm/panic: Return -EINVAL if font is not available
In reply to Thomas ZimmermannFont lookup does not allocate memory. Hence reporting ENOMEM on failed lookups is misleading. Report EINVAL instead.
--- drivers/gpu/drm/drm_panic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_panic.c +3 -1
@@ -757,8 +757,10 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb)int qr_width, qr_canvas_width, qr_pitch, v_margin;u8 *qr_image; -if (!font || !stream.workspace) +if (!stream.workspace)return -ENOMEM ; +if (!font) +return -EINVAL ; r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 10/12 drm/panic: Internalize panic locking in DRM core and helpers
In reply to Thomas ZimmermannNone of the DRM drivers handles panic locking. Declare the interfaces in an internal header file. Move the trylock required during the panic into the DRM core's sources.
--- Documentation/gpu/drm-kms.rst | 3 ++ MAINTAINERS | 3 +- drivers/gpu/drm/drm_atomic_helper.c | 2 +- drivers/gpu/drm/drm_drv.c | 2 +- drivers/gpu/drm/drm_panic.c | 4 ++ drivers/gpu/drm/drm_panic_internal.h | 55 +++++++++++++++++++++++ include/drm/drm_panic.h | 65 ---------------------------- 7 files changed, 66 insertions(+), 68 deletions(-) create mode 100644 drivers/gpu/drm/drm_panic_internal.h
Documentation/gpu/drm-kms.rst +3 -0
@@ -421,6 +421,9 @@ Plane Panic Functions Reference .. kernel-doc:: include/drm/drm_panic.h :internal: +.. kernel-doc:: drivers/gpu/drm/drm_panic_internal.h + :internal: + .. kernel-doc:: drivers/gpu/drm/drm_panic.c :export:
MAINTAINERS +2 -1
@@ -9018,7 +9018,8 @@ S: Supported T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: drivers/gpu/drm/drm_draw.c F: drivers/gpu/drm/drm_draw_internal.h -F: drivers/gpu/drm/drm_panic*.c +F: drivers/gpu/drm/drm_panic.c +F: drivers/gpu/drm/drm_panic_internal.h F: drivers/gpu/drm/tests/drm_panic_test.c F: include/drm/drm_panic.h F: include/drm/drm_panic_helper.h
drivers/gpu/drm/drm_atomic_helper.c +1 -1
@@ -41,7 +41,6 @@#include <drm/drm_drv.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_atomic_helper.h> -#include <drm/drm_panic.h> #include <drm/drm_print.h> #include <drm/drm_self_refresh_helper.h> #include <drm/drm_vblank.h>
@@ -49,6 +48,7 @@#include "drm_crtc_helper_internal.h" #include "drm_crtc_internal.h" +#include "drm_panic_internal.h" /** * DOC: overview
drivers/gpu/drm/drm_drv.c +1 -1
@@ -50,13 +50,13 @@#include <drm/drm_file.h> #include <drm/drm_managed.h> #include <drm/drm_mode_object.h> -#include <drm/drm_panic.h> #include <drm/drm_print.h> #include <drm/drm_privacy_screen_machine.h> #include <drm/drm_ras_genl_family.h> #include "drm_crtc_internal.h" #include "drm_internal.h" +#include "drm_panic_internal.h" MODULE_AUTHOR ("Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl" );MODULE_DESCRIPTION ("DRM shared core routines" );
drivers/gpu/drm/drm_panic.c +4 -0
@@ -35,6 +35,7 @@#include "drm_crtc_internal.h" #include "drm_draw_internal.h" +#include "drm_panic_internal.h" MODULE_AUTHOR ("Jocelyn Falempe" );MODULE_DESCRIPTION ("DRM panic handler" );
@@ -973,6 +974,9 @@ void drm_plane_helper_display_panic_screen(struct drm_plane *plane, const char * }EXPORT_SYMBOL (drm_plane_helper_display_panic_screen); +#define drm_panic_trylock (dev, flags) \ + raw_spin_trylock_irqsave(&(dev)->mode_config.panic_lock, flags) +static void drm_panic_display_panic_screen (struct drm_plane *plane,const char *description) {#if defined(CONFIG_DRM_PANIC_FOREGROUND_COLOR )
drivers/gpu/drm/drm_panic_internal.h new file +55 -0
55 lines not on this page · raw message
include/drm/drm_panic.h +0 -65
82 lines not on this page · raw message
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 1/12 drm/panic: Allocate QR-code buffers statically
In reply to Thomas ZimmermannDeclare qrbuf1 and qrbuf2 as static arrays so that the module loader allocates them for us. Avoids the kmalloc later on. Also allows for using sizeof() to get the number of bytes in each array. Access the arrays once with memset, so that the physical pages are available on a panic.
--- drivers/gpu/drm/drm_panic.c | 41 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 19 deletions(-)
drivers/gpu/drm/drm_panic.c +22 -19
@@ -628,24 +628,23 @@ MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code");#define WINDOW_BITS 12#define MEM_LEVEL 4 -static char *qrbuf1; -static char *qrbuf2; +static u8 qrbuf1[QR_BUFFER1_SIZE ]; +static u8 qrbuf2[QR_BUFFER2_SIZE ];static struct z_stream_s stream;static void __init drm_panic_qr_init (void ) { - qrbuf1 =kmalloc (QR_BUFFER1_SIZE ,GFP_KERNEL ); - qrbuf2 =kmalloc (QR_BUFFER2_SIZE ,GFP_KERNEL ); +/* best-effort allocation; can be NULL */ stream.workspace =kmalloc (zlib_deflate_workspacesize (WINDOW_BITS ,MEM_LEVEL ),GFP_KERNEL ); + +/* touch memory so that pages are there in the case of a panic */ +memset (qrbuf1,0 ,sizeof (qrbuf1)); +memset (qrbuf2,0 ,sizeof (qrbuf2)); }static void drm_panic_qr_exit (void ) { -kfree (qrbuf1); - qrbuf1 =NULL ; -kfree (qrbuf2); - qrbuf2 =NULL ;kfree (stream.workspace); stream.workspace =NULL ; }
@@ -656,13 +655,17 @@ static int drm_panic_get_qr_code_url(u8 **qr_image)char url[256 ];size_t kmsg_len, max_kmsg_size;char *kmsg; -int max_qr_data_size, url_len; +int ret; +size_t max_qr_data_size, url_len; - url_len =snprintf (url,sizeof (url),CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL "?a=%s&v=%s&z=" , -utsname ()->machine,utsname ()->release); + ret =snprintf (url,sizeof (url),CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL "?a=%s&v=%s&z=" , +utsname ()->machine,utsname ()->release); +if (ret >=sizeof (url)) +return -EINVAL ; + url_len = ret; max_qr_data_size =drm_panic_qr_max_data_size (panic_qr_version, url_len); - max_kmsg_size =min (MAX_ZLIB_RATIO * max_qr_data_size,QR_BUFFER1_SIZE ); + max_kmsg_size =min (MAX_ZLIB_RATIO * max_qr_data_size,sizeof (qrbuf1));/* get kmsg to buffer 1 */ kmsg_dump_rewind (&iter);
@@ -681,7 +684,7 @@ static int drm_panic_get_qr_code_url(u8 **qr_image) stream.avail_in = kmsg_len; stream.total_in =0 ; stream.next_out = qrbuf2; - stream.avail_out =QR_BUFFER2_SIZE ; + stream.avail_out =sizeof (qrbuf2); stream.total_out =0 ;if (zlib_deflate (&stream,Z_FINISH ) !=Z_STREAM_END )
@@ -703,8 +706,8 @@ static int drm_panic_get_qr_code_url(u8 **qr_image) *qr_image = qrbuf2;/* generate qr code image in buffer2 */ -return drm_panic_qr_generate (url, qrbuf2, stream.total_out,QR_BUFFER2_SIZE , - qrbuf1,QR_BUFFER1_SIZE ); +return drm_panic_qr_generate (url, qrbuf2, stream.total_out,sizeof (qrbuf2), + qrbuf1,sizeof (qrbuf1)); }static int drm_panic_get_qr_code_raw (u8 **qr_image)
@@ -712,7 +715,7 @@ static int drm_panic_get_qr_code_raw(u8 **qr_image)struct kmsg_dump_iter iter;size_t kmsg_len;size_t max_kmsg_size =min (drm_panic_qr_max_data_size (panic_qr_version,0 ), -QR_BUFFER1_SIZE ); +sizeof (qrbuf1));kmsg_dump_rewind (&iter);kmsg_dump_get_buffer (&iter, false, qrbuf1, max_kmsg_size, &kmsg_len);
@@ -720,8 +723,8 @@ static int drm_panic_get_qr_code_raw(u8 **qr_image)return -ENODATA ; *qr_image = qrbuf1; -return drm_panic_qr_generate (NULL , qrbuf1, kmsg_len,QR_BUFFER1_SIZE , - qrbuf2,QR_BUFFER2_SIZE ); +return drm_panic_qr_generate (NULL , qrbuf1, kmsg_len,sizeof (qrbuf1), + qrbuf2,sizeof (qrbuf2)); }static int drm_panic_get_qr_code (u8 **qr_image)
@@ -748,7 +751,7 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb)int qr_width, qr_canvas_width, qr_pitch, v_margin;u8 *qr_image; -if (!font || !qrbuf1 || !qrbuf2 || !stream.workspace) +if (!font || !stream.workspace)return -ENOMEM ; r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 4/12 drm/panic: Return errno codes if panic output fails
In reply to Thomas ZimmermannReturn errno codes from the panic output helpers to detect invalid panic handling. Avoid flushing the display if an error ocured. The unflushed display output might be helpful in debugging.
For now, test the result values in the panic test cases. A later patch will add support for retrying failed panic output.
--- drivers/gpu/drm/drm_panic.c | 41 +++++++++++++++++--------- drivers/gpu/drm/tests/drm_panic_test.c | 16 ++++++---- 2 files changed, 37 insertions(+), 20 deletions(-)
drivers/gpu/drm/drm_panic.c +27 -14
@@ -478,7 +478,7 @@ static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct drm_rect * fg_color); } -static void draw_panic_screen_user (struct drm_scanout_buffer *sb) +static int draw_panic_screen_user (struct drm_scanout_buffer *sb) {u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);
@@ -489,7 +489,7 @@ static void draw_panic_screen_user(struct drm_scanout_buffer *sb)unsigned int msg_width, msg_height;if (!font) -return ; +return -EINVAL ; r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);drm_panic_logo_rect (&r_logo, font);
@@ -508,6 +508,8 @@ static void draw_panic_screen_user(struct drm_scanout_buffer *sb)drm_panic_logo_draw (sb, &r_logo, font, fg_color);draw_txt_rectangle (sb, font, panic_msg, panic_msg_lines, true, &r_msg, fg_color); + +return 0 ; }/*
@@ -547,7 +549,7 @@ static int draw_line_with_wrap(struct drm_scanout_buffer *sb, const struct font_* Draw the kmsg buffer to the screen, starting from the youngest message at the bottom, * and going up until reaching the top of the screen. */ -static void draw_panic_screen_kmsg (struct drm_scanout_buffer *sb) +static int draw_panic_screen_kmsg (struct drm_scanout_buffer *sb) {u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);
@@ -562,7 +564,7 @@ static void draw_panic_screen_kmsg(struct drm_scanout_buffer *sb)int yoffset;if (!font || font->width > sb->width) -return ; +return -EINVAL ; yoffset = sb->height - font->height - (sb->height % font->height) /2 ;
@@ -589,6 +591,8 @@ static void draw_panic_screen_kmsg(struct drm_scanout_buffer *sb) start--; } } + +return 0 ; }#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE )
@@ -814,10 +818,11 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb) return 0; } -static void draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) {if (_draw_panic_screen_qr_code (sb))draw_panic_screen_user (sb); +return 0 ; }#else static void drm_panic_qr_init (void ) {};
@@ -888,23 +893,25 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format)return drm_draw_can_convert_from_xrgb8888 (format->format); } -static void draw_panic_dispatch (struct drm_scanout_buffer *sb) +static int draw_panic_dispatch (struct drm_scanout_buffer *sb) { +int ret; +switch (drm_panic_type) {case DRM_PANIC_TYPE_KMSG : -draw_panic_screen_kmsg (sb); + ret =draw_panic_screen_kmsg (sb);break ; -#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : -draw_panic_screen_qr_code (sb); + ret =draw_panic_screen_qr_code (sb);break ;#endif -case DRM_PANIC_TYPE_USER :default : -draw_panic_screen_user (sb); + ret =draw_panic_screen_user (sb); } + +return ret; }static void drm_panic_set_description (const char *description)
@@ -951,9 +958,15 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); -draw_panic_dispatch (&sb); -if (plane->helper_private->panic_flush) - plane->helper_private->panic_flush (plane); + ret =draw_panic_dispatch (&sb); +if (!ret) { +/* +* Only flush if we have a panic screen to display. Otherwise +* it's probably better to leave the display output as-is. +*/ +if (plane->helper_private->panic_flush) + plane->helper_private->panic_flush (plane); + }drm_panic_clear_description ();
drivers/gpu/drm/tests/drm_panic_test.c +10 -6
@@ -30,7 +30,7 @@ struct drm_test_mode {const int width;const int height;const u32 format; -void (*draw_screen)(struct drm_scanout_buffer *sb); +int (*draw_screen)(struct drm_scanout_buffer *sb);const char *fname; };
@@ -87,7 +87,7 @@ static void drm_test_panic_screen_user_map(struct kunit *test)const struct drm_test_mode *params = test->param_value;char *fb;int fb_size; -int i; +int i, ret; sb->format =drm_format_info (params->format); fb_size = params->width * params->height * sb->format->cpp[0 ];
@@ -102,7 +102,8 @@ static void drm_test_panic_screen_user_map(struct kunit *test) sb->height = params->height; sb->pitch[0 ] = params->width * sb->format->cpp[0 ]; - params->draw_screen (sb); + ret = params->draw_screen (sb); +KUNIT_ASSERT_EQ (test, ret,0 );for (i =0 ; i < fb_size; i++)drm_panic_check_color_byte (test, fb[i]);
@@ -119,7 +120,7 @@ static void drm_test_panic_screen_user_page(struct kunit *test) {struct drm_scanout_buffer *sb = test->priv;const struct drm_test_mode *params = test->param_value; -int fb_size, p, i, npages; +int fb_size, p, i, npages, ret;struct page **pages;u8 *vaddr;
@@ -146,7 +147,8 @@ static void drm_test_panic_screen_user_page(struct kunit *test) sb->height = params->height; sb->pitch[0 ] = params->width * sb->format->cpp[0 ]; - params->draw_screen (sb); + ret = params->draw_screen (sb); +KUNIT_ASSERT_EQ (test, ret,0 );for (p =0 ; p < npages; p++) {int bytes_in_page = (p == npages -1 ) ? fb_size - p *PAGE_SIZE :PAGE_SIZE ;
@@ -182,6 +184,7 @@ static void drm_test_panic_screen_user_set_pixel(struct kunit *test) {struct drm_scanout_buffer *sb = test->priv;const struct drm_test_mode *params = test->param_value; +int ret; sb->format =drm_format_info (params->format); sb->set_pixel = drm_test_panic_set_pixel;
@@ -189,7 +192,8 @@ static void drm_test_panic_screen_user_set_pixel(struct kunit *test) sb->height = params->height; sb->private = test; - params->draw_screen (sb); + ret = params->draw_screen (sb); +KUNIT_ASSERT_EQ (test, ret,0 ); }static void drm_test_panic_desc (const struct drm_test_mode *t,char *desc)
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 6/12 drm/panic: Pass global module parameters to drm_panic_dispatch()
In reply to Thomas ZimmermannSet the panic type and QR version in draw_panic_plane() as a single point of truth. Pass the values into the individual drawing functions.
In the test case, always create a QR code with version 40 (i.e., the highest supported version).
--- drivers/gpu/drm/drm_panic.c | 39 ++++++++++++++++---------- drivers/gpu/drm/tests/drm_panic_test.c | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_panic.c +24 -15
@@ -657,7 +657,7 @@ static void drm_panic_qr_exit(void) stream.workspace =NULL ; } -static int drm_panic_get_qr_code_url (u8 **qr_image) +static int drm_panic_get_qr_code_url (u8 **qr_image,unsigned int qr_version) {struct kmsg_dump_iter iter;char url[256 ];
@@ -672,7 +672,7 @@ static int drm_panic_get_qr_code_url(u8 **qr_image)return -EINVAL ; url_len = ret; - max_qr_data_size =drm_panic_qr_max_data_size (panic_qr_version, url_len); + max_qr_data_size =drm_panic_qr_max_data_size (qr_version, url_len); max_kmsg_size =min (MAX_ZLIB_RATIO * max_qr_data_size,sizeof (qrbuf1));/* get kmsg to buffer 1 */
@@ -718,11 +718,11 @@ static int drm_panic_get_qr_code_url(u8 **qr_image) qrbuf1, sizeof(qrbuf1)); } -static int drm_panic_get_qr_code_raw (u8 **qr_image) +static int drm_panic_get_qr_code_raw (u8 **qr_image,unsigned int qr_version) {struct kmsg_dump_iter iter;size_t kmsg_len; -size_t max_kmsg_size =min (drm_panic_qr_max_data_size (panic_qr_version,0 ), +size_t max_kmsg_size =min (drm_panic_qr_max_data_size (qr_version,0 ),sizeof (qrbuf1));kmsg_dump_rewind (&iter);
@@ -735,19 +735,20 @@ static int drm_panic_get_qr_code_raw(u8 **qr_image) qrbuf2, sizeof(qrbuf2)); } -static int drm_panic_get_qr_code (u8 **qr_image) +static int drm_panic_get_qr_code (u8 **qr_image,unsigned int qr_version) {if (strlen (CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL ) >0 ) -return drm_panic_get_qr_code_url (qr_image); +return drm_panic_get_qr_code_url (qr_image, qr_version);else -return drm_panic_get_qr_code_raw (qr_image); +return drm_panic_get_qr_code_raw (qr_image, qr_version); }/* * Draw the panic message at the center of the screen, with a QR Code */ static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color) +u32 fg_color,u32 bg_color, +unsigned int qr_version) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg, r_qr, r_qr_canvas;
@@ -774,7 +775,7 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb, max_qr_size =min (3 * sb->width /4 ,3 * sb->height /4 ); - qr_width =drm_panic_get_qr_code (&qr_image); + qr_width =drm_panic_get_qr_code (&qr_image, qr_version);if (qr_width <=0 )return -ENOSPC ;
@@ -816,9 +817,11 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,return 0 ; } -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color, +unsigned int qr_version) { -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color)) +if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version))draw_panic_screen_user (sb, fg_color, bg_color);return 0 ; }
@@ -891,17 +894,18 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format)return drm_draw_can_convert_from_xrgb8888 (format->format); } -static int draw_panic_dispatch (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) +static int draw_panic_dispatch (struct drm_scanout_buffer *sb,enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color,unsigned int qr_version) {int ret; -switch (drm_panic_type) { +switch (panic_type) {case DRM_PANIC_TYPE_KMSG : ret =draw_panic_screen_kmsg (sb, fg_color, bg_color);break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : - ret =draw_panic_screen_qr_code (sb, fg_color, bg_color); + ret =draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version);break ;#endif case DRM_PANIC_TYPE_USER :
@@ -951,6 +955,11 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)#else u32 bg_color =0x00000000 ;#endif +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +unsigned int qr_version = panic_qr_version; +#else +unsigned int qr_version =0 ; +#endif if (!drm_panic_trylock (plane->dev, flags))return ;
@@ -966,7 +975,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); - ret =draw_panic_dispatch (&sb, fg_color, bg_color); + ret =draw_panic_dispatch (&sb, drm_panic_type, fg_color, bg_color, qr_version);if (!ret) {/* * Only flush if we have a panic screen to display. Otherwise
drivers/gpu/drm/tests/drm_panic_test.c +1 -1
@@ -58,7 +58,7 @@ static int draw_panic_screen_kmsg_default(struct drm_scanout_buffer *sb)#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ); +return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ,40 ); }#endif
Signature · 1 line
2.55.0
Thomas Zimmermann
maintainerPATCH 8/12 drm/panic: Split draw_panic_plane()
In reply to Thomas ZimmermannMove locking and parameters from draw_panic_plane() into the new helper drm_panic_display_panic_screen(). Call draw_panic_plane() from there.
The new helper drm_panic_display_panic_screen() is now the DRM core's interface for displaying a panic screen. The code remaining in draw_panic_plane() still does all the heavy lifting. It will become a plane helper for DRM drivers.
--- drivers/gpu/drm/drm_panic.c | 60 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-)
drivers/gpu/drm/drm_panic.c +33 -27
@@ -940,38 +940,21 @@ static void drm_panic_clear_description(void) desc_line->txt =NULL ; } -static void draw_panic_plane (struct drm_plane *plane,const char *description) +static void draw_panic_plane (struct drm_plane *plane,const char *description, +enum drm_panic_type panic_type,u32 fg_color,u32 bg_color, +unsigned int qr_version) {struct drm_scanout_buffer sb = { };int ret; -unsigned long flags; -#if defined(CONFIG_DRM_PANIC_FOREGROUND_COLOR ) -u32 fg_color =CONFIG_DRM_PANIC_FOREGROUND_COLOR ; -#else -u32 fg_color =0x00ffffff ; -#endif -#if defined(CONFIG_DRM_PANIC_BACKGROUND_COLOR ) -u32 bg_color =CONFIG_DRM_PANIC_BACKGROUND_COLOR ; -#else -u32 bg_color =0x00000000 ; -#endif -#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) -unsigned int qr_version = panic_qr_version; -#else -unsigned int qr_version =0 ; -#endif - -if (!drm_panic_trylock (plane->dev, flags)) -return ; ret = plane->helper_private->get_scanout_buffer (plane, &sb);if (ret || !drm_panic_is_format_supported (sb.format)) - goto unlock; +return ;/* One of these should be set, or it can't draw pixels */ if (!sb.set_pixel && !sb.pages &&iosys_map_is_null (&sb.map[0 ])) - goto unlock; +return ;drm_panic_set_description (description);
@@ -986,9 +969,33 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description) }drm_panic_clear_description (); +} -unlock: -drm_panic_unlock (plane->dev, flags); +static void drm_panic_display_panic_screen (struct drm_plane *plane,const char *description) +{ +#if defined(CONFIG_DRM_PANIC_FOREGROUND_COLOR ) +u32 fg_color =CONFIG_DRM_PANIC_FOREGROUND_COLOR ; +#else +u32 fg_color =0x00ffffff ; +#endif +#if defined(CONFIG_DRM_PANIC_BACKGROUND_COLOR ) +u32 bg_color =CONFIG_DRM_PANIC_BACKGROUND_COLOR ; +#else +u32 bg_color =0x00000000 ; +#endif +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +unsigned int qr_version = panic_qr_version; +#else +unsigned int qr_version =0 ; +#endif +struct drm_device *dev = plane->dev; +unsigned long flags; + +if (drm_panic_trylock (dev, flags)) { +draw_panic_plane (plane, description, drm_panic_type, + fg_color, bg_color, qr_version); +drm_panic_unlock (dev, flags); + } }static struct drm_plane *to_drm_plane (struct kmsg_dumper *kd)
@@ -1001,10 +1008,9 @@ 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, detail->description); +drm_panic_display_panic_screen (plane, detail->description); } -/* * DEBUG FS, This is currently unsafe. * Create one file per plane, so it's possible to debug one plane at a time.
@@ -1021,7 +1027,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,"Test from debugfs" ); +drm_panic_display_panic_screen (plane,"Test from debugfs" ); }return count; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 04/12] drm/panic: Return errno codes if panic output fails
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] draw_panic_screen_qr_code() ignores the return value of its fallback function…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] draw_panic_screen_qr_code() ignores the return value of its fallback function draw_panic_screen_user() and unconditionally returns 0. --
--- Patch [4]: [PATCH 04/12] drm/panic: Return errno codes if panic output fails --- commit 8764682ca919f839ac40d09290f5a67bb03da8dc
Author: Thomas Zimmermann <[email protected]>
drm/panic: Return errno codes if panic output fails
This commit updates the panic output helpers to return errno codes on failure. This allows the driver to avoid flushing the display if an error occurs, preserving the unflushed display output for debugging.
Quoted 3 lines
drivers/gpu/drm/drm_panic.c +0
-0
[ ... ]
drivers/gpu/drm/drm_panic.c static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb) · line 825
Quoted 10 lines
drivers/gpu/drm/drm_panic.c +2
-1@@ -814,10 +818,11 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb)return 0 ; } -static void draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) {if (_draw_panic_screen_qr_code (sb))draw_panic_screen_user (sb); +return 0 ;
[Severity: Medium]
Should this return the error code from draw_panic_screen_user() if the fallback also fails?
Because this unconditionally returns 0, draw_panic_dispatch() will report success even if both _draw_panic_screen_qr_code() and the fallback fail. This causes draw_panic_plane() to still flush the display buffer, which might overwrite the unflushed output this patch aims to preserve.
Quoted 3 lines
drivers/gpu/drm/drm_panic.c +0
-0}#else static void drm_panic_qr_init (void ) {};
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH 03/12] drm/panic: Return -EINVAL if font is not available
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing NULL check for the result of kmap_local_page_try_from_panic() in drm_panic_write_pixel24_xpage() leads to a NULL pointer dereference. --
--- Patch [3]: [PATCH 03/12] drm/panic: Return -EINVAL if font is not available --- commit 5ad93562bf6ffaf36ef771a5c8eebc2aa43f5621
Author: Thomas Zimmermann <[email protected]>
drm/panic: Return -EINVAL if font is not available
Font lookup does not allocate memory. Hence reporting ENOMEM on failed lookups is misleading. Report EINVAL instead.
Quoted 4 lines
drivers/gpu/drm/drm_panic.c +0
-0
[ ... ]
Quoted 15 lines
static void drm_panic_write_pixel24_xpage(void *vaddr, struct page
*next_page,
unsigned int offset, u32 color){ u8 *vaddr2; u8 *p = vaddr + offset; vaddr2 = kmap_local_page_try_from_panic(next_page); *p++ = color & 0xff; color >>= 8; if (offset == PAGE_SIZE - 1) p = vaddr2; *p++ = color & 0xff;
[Severity: High]
This isn't a bug introduced by this patch, but does drm_panic_write_pixel24_xpage() lack a NULL check for vaddr2?
If the next page is located in HighMem, kmap_local_page_try_from_panic() returns NULL since it is unsafe to map HighMem during a panic.
When vaddr2 is NULL and the offset crosses the page boundary (PAGE_SIZE - 1 or PAGE_SIZE - 2), the write pointer p is set to vaddr2. Would the subsequent write operation then dereference NULL, causing a recursive panic that aborts the DRM panic handler?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH 07/12] drm/panic: Retry in dispatch function if panic output fails
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Removing the internal fallback from `draw_panic_screen_qr_code` breaks the `drm_panic` KUnit…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removing the internal fallback from draw_panic_screen_qr_code breaks the drm_panic KUnit tests. --
--- Patch [7]: [PATCH 07/12] drm/panic: Retry in dispatch function if panic output fails --- commit 23392eb57457ad383d9c4741f6fc2f3c107aabb3
Author: Thomas Zimmermann <[email protected]>
drm/panic: Retry in dispatch function if panic output fails
On failed output of QR codes and kmsg buffers, fall back to a user message. QR-code output already did this internally, but now formally support it in drm_panic_dispatch(). Streamlines the existing logic.
Quoted 2 lines
drivers/gpu/drm/drm_panic.c +0
-0
[ ... ]
drivers/gpu/drm/drm_panic.c static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb, · line 827
Quoted 13 lines
drivers/gpu/drm/drm_panic.c +0
-9@@ -816,15 +816,6 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,drm_panic_blit (sb, &r_qr, qr_image, qr_pitch, scale, fg_color);return 0 ; } - -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) -{ -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version)) -draw_panic_screen_user (sb, fg_color, bg_color); -return 0 ; -}
[Severity: Medium]
Does removing this fallback cause the drm_panic KUnit tests to fail?
Looking at the test suite in drivers/gpu/drm/tests/drm_panic_test.c, it calls this function directly without going through the new dispatch logic:
static int draw_panic_screen_qr_code_default(struct drm_scanout_buffer *sb)
{
return draw_panic_screen_qr_code(sb, 0x00ffffff, 0x00000000, 40);
}When tested with a small resolution like 300x200, the scale evaluates to 0 and returns -ENOSPC. Previously, this wrapper caught the error, fell back to draw_panic_screen_user, and safely returned 0, satisfying the KUnit check.
Since the fallback was moved to draw_panic_dispatch and the test calls the lower-level function directly, will this now propagate the -ENOSPC error and spuriously fail the test?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH 01/12] drm/panic: Allocate QR-code buffers statically
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but using the CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL Kconfig macro directly as part of the format string in snprintf creates a format string vulnerability. If the configured URL contains URL-encoded characters that form valid format specifiers (e.g., ?reason=kernel%20panic, where %20p is a format specifier for a padded pointer), snprintf will consume unintended arguments. This shifts the argument mapping for the explicit %s specifiers, causing them to read and dereference uninitialized stack memory, leading to a nested kernel oops during a panic. --
--- Patch [1]: [PATCH 01/12] drm/panic: Allocate QR-code buffers statically --- commit 8f4057e44664878e84dd3de301552d418b19254c
Author: Thomas Zimmermann <[email protected]>
drm/panic: Allocate QR-code buffers statically
Declare qrbuf1 and qrbuf2 as static arrays so that the module loader allocates them for us. Avoids the kmalloc later on. Access the arrays once with memset, so that the physical pages are available on a panic.
Quoted 3 lines
drivers/gpu/drm/drm_panic.c +0
-0
[ ... ]
drivers/gpu/drm/drm_panic.c static int drm_panic_get_qr_code_url(u8 **qr_image) · line 662
Quoted 12 lines
drivers/gpu/drm/drm_panic.c +4
-3@@ -656,13 +655,17 @@ static int drm_panic_get_qr_code_url(u8 **qr_image)char url[256 ];size_t kmsg_len, max_kmsg_size;char *kmsg; -int max_qr_data_size, url_len; +int ret; +size_t max_qr_data_size, url_len; - url_len =snprintf (url,sizeof (url),CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL "?a=%s&v=%s&z=" , -utsname ()->machine,utsname ()->release); + ret =snprintf (url,sizeof (url),CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL "?a=%s&v=%s&z=" , +utsname ()->machine,utsname ()->release);
[Severity: High]
This isn't a bug introduced by this patch, but does constructing the format string directly from CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL create a format string vulnerability in drm_panic_get_qr_code_url()?
If a system builder configures the url string with standard url-encoded characters that happen to match valid format specifiers (such as %20p or %20d), snprintf() will try to consume unintended arguments.
Could this shift the argument mapping for the explicit %s specifiers, causing them to dereference uninitialized stack memory and trigger a nested oops that prevents the panic screen from displaying?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH 06/12] drm/panic: Pass global module parameters to drm_panic_dispatch()
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent debugfs writes or KUnit tests across multiple DRM devices race on global static buffers without adequate synchronization. --
--- Patch [6]: [PATCH 06/12] drm/panic: Pass global module parameters to drm_panic_dispatch() --- commit 9f2a1b5158feac614c09a17c83f387591642e034
Author: Thomas Zimmermann <[email protected]>
drm/panic: Pass global module parameters to drm_panic_dispatch()
This patch sets the panic type and QR version in draw_panic_plane() as a single point of truth, passing these values into the individual drawing functions. In the test case, it always creates a QR code with version 40.
Quoted 4 lines
drivers/gpu/drm/drm_panic.c +0
-0
[ ... ]
Quoted 13 lines
drivers/gpu/drm/drm_panic.c +5
-0@@ -951,6 +955,11 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)#else u32 bg_color =0x00000000 ;#endif +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +unsigned int qr_version = panic_qr_version; +#else +unsigned int qr_version =0 ; +#endif if (!drm_panic_trylock (plane->dev, flags))return ;
drivers/gpu/drm/drm_panic.c static void draw_panic_plane(struct drm_plane *plane, const char *description) · line 978
Quoted 5 lines
drivers/gpu/drm/drm_panic.c +1
-1@@ -966,7 +975,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); - ret =draw_panic_dispatch (&sb, fg_color, bg_color); + ret =draw_panic_dispatch (&sb, drm_panic_type, fg_color, bg_color, qr_version);
[Severity: High]
This is a pre-existing issue, but does the per-device locking in drm_panic_trylock() adequately protect the global buffers?
Since the lock is per-device (plane->dev->mode_config.panic_lock), concurrent debugfs writes across multiple DRM devices can still race and mutate global static variables, such as the zlib stream workspace (struct z_stream_s stream) or qrbuf1 and qrbuf2.
If a real kernel panic occurs while a debugfs write is concurrently using these buffers, the true panic handler could inherit a corrupted zlib workspace state, which might lead to a recursive fault and failure to display the panic screen.
Could this be protected by a global lock for non-panic paths?
[ ... ]
drivers/gpu/drm/tests/drm_panic_test.c static int draw_panic_screen_kmsg_default(struct drm_scanout_buffer *sb) · line 63
Quoted 12 lines
drivers/gpu/drm/tests/drm_panic_test.c +1
-1@@ -58,7 +58,7 @@ static int draw_panic_screen_kmsg_default(struct drm_scanout_buffer *sb)#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ); +return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ,40 ); }#endif
[Severity: High]
This isn't a bug introduced by this patch, but do the KUnit tests safely access the global drawing state?
It appears the KUnit tests bypass draw_panic_plane() entirely and directly call drawing functions like draw_panic_screen_qr_code() without acquiring any locks. Could running the tests race on the global buffers and corrupt the zlib workspace?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH 11/12] drm/panic: Move panic display code into helper library
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Missing fallback stubs for `drm_panic_helper_init` and `drm_panic_helper_exit` cause link failure…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Missing fallback stubs for drm_panic_helper_init and drm_panic_helper_exit cause link failure when CONFIG_DRM_PANIC_HELPER is disabled.
- [Low] DRM_KMS_HELPER selects DRM_PANIC_HELPER without satisfying its DRM_TTM dependency.
--
--- Patch [11]: [PATCH 11/12] drm/panic: Move panic display code into helper library --- commit 3d718c4f09d4c3ad0b378e7ca17f9b9b1d4d1627
Author: Thomas Zimmermann <[email protected]>
drm/panic: Move panic display code into helper library
This commit extracts panic display functionality from drm_panic.c into a new drm_panic_helper.c file. The KMS helper module is updated to link this new helper object, and relevant Kconfig and Makefile entries are added.
Quoted 11 lines
drivers/gpu/drm/Kconfig +1
-0@@ -45,6 +45,7 @@ config DRM_MIPI_DSI config DRM_KMS_HELPER tristate depends on DRM + select DRM_PANIC_HELPER if DRM_PANIC select FB_CORE if DRM_FBDEV_EMULATION help
[ ... ]
drivers/gpu/drm/Kconfig config DRM_PANIC_SCREEN_QR_VERSION · line 136
Quoted 7 lines
drivers/gpu/drm/Kconfig +3
-0@@ -130,6 +131,10 @@ config DRM_PANIC_SCREEN_QR_VERSION Smaller QR code are easier to read, but will contain less debugging data. Default is 40. +config DRM_PANIC_HELPER + bool + depends on DRM_TTM
[Severity: Low]
Will this cause an unmet direct dependency warning in Kconfig?
DRM_KMS_HELPER selects DRM_PANIC_HELPER, but it doesn't inherit or ensure the DRM_TTM dependency is met. If a kernel is configured with DRM_KMS_HELPER and DRM_PANIC enabled, but without DRM_TTM, it might lead to Kconfig warnings or a build failure.
Quoted 15 lines
drivers/gpu/drm/drm_kms_helper_common.c +7
-0@@ -27,6 +27,20 @@#include <linux/module.h> +#include "drm_panic_internal.h" + +static int __init drm_kms_helper_init (void ) +{ +return drm_panic_helper_init (); +} +module_init (drm_kms_helper_init);
[ ... ]
drivers/gpu/drm/drm_panic_internal.h static inline void drm_panic_lock(struct drm_device *dev, unsigned long flags) { · line 58
Quoted 12 lines
drivers/gpu/drm/drm_panic_internal.h +4
-0@@ -52,4 +52,8 @@ static inline void drm_panic_lock(struct drm_device *dev, unsigned long flags) {static inline void drm_panic_unlock (struct drm_device *dev,unsigned long flags) {}#endif +/* drm_panic_helper.c */ +int drm_panic_helper_init (void ); +void drm_panic_helper_exit (void ); +
[Severity: Low]
Does this cause a link failure when CONFIG_DRM_PANIC_HELPER is disabled?
The calls to drm_panic_helper_init() and drm_panic_helper_exit() in drm_kms_helper_common.c are unconditional. Without fallback static inline stubs in drm_panic_internal.h when the feature is disabled, it seems this will lead to unresolved external references during the linking phase.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
[email protected]
AI reviewRe: [PATCH 08/12] drm/panic: Split draw_panic_plane()
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] The panic_type parameter in draw_panic_plane() is ignored and shadowed by the global drm_panic_type variable.
Pre-existing issues:
- [High] Data race on global variables (panic_msg, qrbuf1, qrbuf2, stream) when triggering panic debugfs interface concurrently across multiple DRM devices. --
--- Patch [8]: [PATCH 08/12] drm/panic: Split draw_panic_plane() --- commit 87af97baf7c5108af8275ef63007ab9f483466ca
Author: Thomas Zimmermann <[email protected]>
drm/panic: Split draw_panic_plane()
Move locking and parameters from draw_panic_plane() into the new helper drm_panic_display_panic_screen(). Call draw_panic_plane() from there. The new helper is now the DRM core's interface for displaying a panic screen.
drivers/gpu/drm/drm_panic.c static void drm_panic_clear_description(void) · line 946
Quoted 13 lines
drivers/gpu/drm/drm_panic.c +3
-1@@ -940,38 +940,21 @@ static void drm_panic_clear_description(void) desc_line->txt =NULL ; } -static void draw_panic_plane (struct drm_plane *plane,const char *description) +static void draw_panic_plane (struct drm_plane *plane,const char *description, +enum drm_panic_type panic_type,u32 fg_color,u32 bg_color, +unsigned int qr_version) {
[Severity: Medium]
Does this function ignore the new panic_type parameter?
The parameter is passed to draw_panic_plane(), but if the code still uses the global drm_panic_type variable internally when calling draw_panic_dispatch():
ret = draw_panic_dispatch(&sb, drm_panic_type, fg_color, bg_color, qr_version);
Any caller passing a specific panic_type will have its request overridden by the global module parameter, which seems to break the intent of making this a generic helper.
[ ... ]
drivers/gpu/drm/drm_panic.c static ssize_t debugfs_trigger_write(struct file *file, const char __user *user_ · line 1030
Quoted 6 lines
drivers/gpu/drm/drm_panic.c +1
-1@@ -1021,7 +1027,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,"Test from debugfs" ); +drm_panic_display_panic_screen (plane,"Test from debugfs" );
[Severity: High]
This is a pre-existing issue, but does this debugfs entry point allow a data race on global variables across different DRM devices?
When a user writes concurrently to the debugfs files of two or more distinct DRM devices, the debugfs_trigger_write() handler acquires a per-device lock via drm_panic_trylock().
However, these concurrent writes can proceed to mutate the unprotected global panic_msg array in drm_panic_set_description():
struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines - 1]; desc_line->txt = description;
This could also affect other globals like qrbuf1, qrbuf2, and the zlib stream workspace.
Could this concurrent execution across different DRM devices corrupt memory and lead to an inconsistent state?
Quoted 3 lines
drivers/gpu/drm/drm_panic.c +0
-0}return count; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH 12/12] drm/panic: Compile KUnit tests as module
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] Mismatched parameter order between declaration and definition for…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Mismatched parameter order between declaration and definition for drm_panic_helper_draw_screen_qr_code.
- [Low] Unmet direct dependency warning when DRM_PANIC_HELPER is selected without DRM_TTM.
- [Low] Missing indirect dependencies on DRM_DRAW and FONT_SUPPORT leading to linker errors.
--
--- Patch [12]: [PATCH 12/12] drm/panic: Compile KUnit tests as module --- commit a56a5f0ffd0c185768aecc54426d672e40b1b0ae
Author: Thomas Zimmermann <[email protected]>
drm/panic: Compile KUnit tests as module
Fix dependency of the panic-helper KUnit tests on CONFIG_DRM_KUNIT_TEST=y and make them build as a module. Export the necessary interfaces from the panic helpers iff the KUnit framework has been enabled.
drivers/gpu/drm/Kconfig.debug config DRM_KUNIT_TEST · line 72
Quoted 9 lines
drivers/gpu/drm/Kconfig.debug +1
-0@@ -69,6 +69,7 @@ config DRM_KUNIT_TEST select DRM_EXPORT_FOR_TESTS if m select DRM_GEM_SHMEM_HELPER select DRM_KUNIT_TEST_HELPERS + select DRM_PANIC_HELPER
[Severity: Low]
When DRM_KUNIT_TEST is enabled on a configuration where DRM_TTM is disabled, does this cause an unmet direct dependency warning? DRM_PANIC_HELPER has a depends on DRM_TTM requirement in drivers/gpu/drm/Kconfig.
Also, does selecting DRM_PANIC_HELPER without ensuring DRM_DRAW and FONT_SUPPORT are available cause linker errors?
The drm_panic_helper.c file unconditionally calls functions from the DRM draw library (drm_draw_color_from_xrgb8888) and the font library (get_default_font). Normally, DRM_PANIC selects DRM_DRAW and FONT_SUPPORT, ensuring these symbols are available, but selecting DRM_PANIC_HELPER directly bypasses these.
[ ... ]
Quoted 4 lines
include/drm/drm_panic_helper.h +0
-0
[ ... ]
include/drm/drm_panic_helper.h void drm_plane_helper_display_panic_screen(struct drm_plane *plane, · line 23
Quoted 9 lines
include/drm/drm_panic_helper.h +5
-0@@ -15,6 +16,13 @@ void drm_plane_helper_display_panic_screen(struct drm_plane *plane,enum drm_panic_type panic_type, u32 fg_color, u32 bg_color, unsigned int qr_version); +#if IS_ENABLED (CONFIG_KUNIT ) +int drm_panic_helper_draw_screen_user (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color); +int drm_panic_helper_draw_screen_kmsg (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color); +int drm_panic_helper_draw_screen_qr_code (struct drm_scanout_buffer *sb,unsigned int qr_version, +u32 fg_color,u32 bg_color);
[Severity: Medium]
Does this prototype match the definition indrivers/gpu/drm/drm_panic_helper.c?
Here it is declared as:
int drm_panic_helper_draw_screen_qr_code(struct drm_scanout_buffer *sb,
unsigned int qr_version,
u32 fg_color,
u32 bg_color);But the implementation is defined as:VISIBLE_IF_KUNIT int drm_panic_helper_draw_screen_qr_code(
struct drm_scanout_buffer *sb, u32 fg_color,
u32 bg_color, unsigned int qr_version)
Because u32 and unsigned int are functionally equivalent types, the compiler silently accepts this mismatch without any warnings. Will any caller relying on the header's parameter order inadvertently swap the qr_version and fg_color arguments, causing the function to fail with -ENOSPC or render with corrupted colors?
Quoted 2 lines
include/drm/drm_panic_helper.h +2
-0+void drm_panic_helper_set_description (const char *description); +#endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
[email protected]
AI reviewRe: [PATCH 09/12] drm/panic: Display panic screen via per-plane callback
In reply to Thomas ZimmermannThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The `drm_plane_helper_display_panic_screen` helper unconditionally dereferences…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The drm_plane_helper_display_panic_screen helper unconditionally dereferences plane->helper_private and plane->helper_private->get_scanout_buffer. However, by adding DRM_PANIC_PLANE_FUNCS to shared plane function tables (like skl_plane_funcs in i915 and dm_plane_funcs in amdgpu), the display_panic_screen callback is now applied to all planes (including cursors and overlays). These non-primary planes use different helper functions (e.g., intel_plane_helper_funcs or dm_plane_helper_funcs) that do not implement get_scanout_buffer. This causes drm_panic_register to mistakenly register panic dumpers for these planes, and upon a panic, the handler executes a NULL pointer dereference, triggering a nested panic.
- [Medium] The patch replaces get_scanout_buffer with display_panic_screen as the signal for panic support. However, it fails to add DRM_PANIC_PLANE_FUNCS to the legacy fallback primary_plane_funcs in drm_modeset_helper.c. Older AMDGPU DCE drivers (e.g., DCE 6.0, 8.0, 10.0) use drm_crtc_init() which implicitly relies on this legacy structure for their primary planes. Although these drivers implement get_scanout_buffer in their helper functions (dce_v10_0_drm_primary_plane_helper_funcs), their planes now lack the display_panic_screen callback. Consequently, drm_panic_is_enabled() returns false and their panic dumpers are never registered, silently breaking panic screen support on these hardware generations.
- [Low] drm_plane_helper_display_panic_screen accepts a panic_type parameter (an enum drm_panic_type). However, when it calls draw_panic_dispatch(), it passes the global module parameter drm_panic_type instead of the passed-in panic_type. This logic bug prevents drivers from tailoring the panic screen implementation via the helper as intended.
--
--- Patch [9]: [PATCH 09/12] drm/panic: Display panic screen via per-plane callback --- commit 69fa8c39afc844867e193df3659c6f6f1fb762f3
Author: Thomas Zimmermann <[email protected]>
drm/panic: Display panic screen via per-plane callback
This commit adds display_panic_screen to struct drm_plane_funcs to replace get_scanout_buffer as the signal for panic support. It provides the helper drm_plane_helper_display_panic_screen() and the DRM_PANIC_PLANE_FUNCS macro to update drivers that implement panic support.
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +0
-0
[ ... ]
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c static const struct drm_plane_funcs dm_plane_funcs = { · line 2182
Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +1
-0@@ -2177,6 +2178,7 @@ static const struct drm_plane_funcs dm_plane_funcs = { .atomic_set_property = dm_atomic_plane_set_property, .atomic_get_property = dm_atomic_plane_get_property,#endif + DRM_PANIC_PLANE_FUNCS, };
[Severity: High]
Does adding this macro to shared plane function tables (like dm_plane_funcs or skl_plane_funcs) apply the panic screen callback to all planes, including cursors and overlays?
Non-primary planes use different helper functions that do not implement get_scanout_buffer. Since drm_plane_helper_display_panic_screen() unconditionally dereferences plane->helper_private->get_scanout_buffer, could this cause a NULL pointer dereference in the panic handler for these planes and trigger a nested panic?
Quoted 4 lines
drivers/gpu/drm/drm_panic.c +0
-0
[ ... ]
drivers/gpu/drm/drm_panic.c static void drm_panic_clear_description(void) · line 949
Quoted 6 lines
drivers/gpu/drm/drm_panic.c +3
-0+void drm_plane_helper_display_panic_screen (struct drm_plane *plane,const char *description, +enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color,unsigned int qr_version) {struct drm_scanout_buffer sb = { };int ret;
[Severity: Low]
Is the panic_type parameter correctly passed to the dispatch function?
The function accepts a panic_type argument, but the implementation appears to pass the global module parameter drm_panic_type to draw_panic_dispatch() instead of the passed-in argument. Does this discard the caller's requested panic type?
Quoted 5 lines
include/drm/drm_panic_helper.h new file +0
-0
[ ... ]
include/drm/drm_panic_helper.h line 25
Quoted 7 lines
include/drm/drm_panic_helper.h new file +7
-0+#if IS_ENABLED (CONFIG_DRM_PANIC ) +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = drm_plane_helper_display_panic_screen +#else +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = NULL +#endif
[Severity: Medium]
Does the legacy fallback primary_plane_funcs in drm_modeset_helper.c also need to be updated with DRM_PANIC_PLANE_FUNCS?
Older AMDGPU DCE drivers use drm_crtc_init(), which implicitly relies on this legacy structure for their primary planes. Although these drivers implement get_scanout_buffer() in their helper functions, lacking this macro in the fallback could cause drm_panic_is_enabled() to return false and silently drop panic screen support on these hardware generations.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Patchwork
CI✗ Fi.CI.BUILD: failure for drm/panic: Split into core and helpers
In reply to Thomas Zimmermann== Series Details ==
== Series Details ==
Series: drm/panic: Split into core and helpers
URL : https://patchwork.freedesktop.org/series/172395/
State : failure
== Summary ==
Error: make failed
DESCEND objtool
HDRTEST drivers/gpu/drm/xe/generated/xe_wa_oob.h HDRTEST drivers/gpu/drm/xe/generated/xe_device_wa_oob.h
UPD include/generated/utsversion.h CC init/version-timestamp.o KSYMS .tmp_vmlinux0.kallsyms.S AS .tmp_vmlinux0.kallsyms.o LD .tmp_vmlinux1
ld: vmlinux.o: in function `drm_panic_helper_fill':
/home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:347:(.text+0xf7d499): undefined reference to `drm_draw_fill16'
ld: /home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:355:(.text+0xf7d561): undefined reference to `drm_draw_fill32'
ld: /home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:351:(.text+0xf7d582): undefined reference to `drm_draw_fill24'
ld: vmlinux.o: in function `drm_panic_helper_blit':
/home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:258:(.text+0xf7da6c): undefined reference to `drm_draw_blit16'
ld: /home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:266:(.text+0xf7dae6): undefined reference to `drm_draw_blit32'
ld: /home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:262:(.text+0xf7db0a): undefined reference to `drm_draw_blit24'
ld: vmlinux.o: in function `drm_panic_helper_draw_screen_user':
/home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:446:(.text+0xf7dbc1): undefined reference to `drm_draw_color_from_xrgb8888'
ld: /home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:447:(.text+0xf7dbd3): undefined reference to `drm_draw_color_from_xrgb8888'
ld: vmlinux.o: in function `drm_panic_helper_draw_screen_kmsg':
/home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:522:(.text+0xf7de3e): undefined reference to `drm_draw_color_from_xrgb8888'
ld: /home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:523:(.text+0xf7de50): undefined reference to `drm_draw_color_from_xrgb8888'
ld: vmlinux.o: in function `drm_panic_helper_format_is_supported':
/home/kbuild/kernel/drivers/gpu/drm/drm_panic_helper.c:791:(.text+0xf7e1d2): undefined reference to `drm_draw_can_convert_from_xrgb8888' make[2]: *** [scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1
make[1]: *** [/home/kbuild/kernel/Makefile:1370: vmlinux] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Build failed, no error log produced
Patchwork
CI✗ CI.checkpatch: warning for drm/panic: Split into core and helpers
In reply to Thomas Zimmermann== Series Details ==
== Series Details ==
Series: drm/panic: Split into core and helpers
URL : https://patchwork.freedesktop.org/series/172394/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 061140b9bc586ae7f40abc1249c97e1cc72d1b9d
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 1abd75770638641c3934cecbbe974de5a0342e04
Author: Thomas Zimmermann <[email protected]> Date: Tue Aug 18 14:28:10 2026 +0200
drm/panic: Compile KUnit tests as module
Fix dependency of the panic-helper KUnit tests on CONFIG_DRM_KUNIT_TEST=y and make them build as a module. Export the necessary interfaces from the panic helpers iff the KUnit framework has been enabled.
Select DRM_PANIC_HELPER from DRM_KUNIT_TEST to meet the dependencies of the panic-helper tests.
It is now possible to run the tests by modprobing drm_panic_helper_test.ko at runtime.
+ /mt/dim checkpatch 275df33dcf4c5d018717867a0b29ed1d3b62c1ef drm-intel 1a5e1e270ee6 drm/panic: Allocate QR-code buffers statically455a770fad55 drm/panic: Make allocation of zlib workspace more robust5e90d001a6de drm/panic: Return -EINVAL if font is not available1fc4cd4247e5 drm/panic: Return errno codes if panic output failsefe17365dd1c drm/panic: Pass colors to draw_panic_dispatch()1660f0b4aea5 drm/panic: Pass global module parameters to drm_panic_dispatch() d404222f3e11 drm/panic: Retry in dispatch function if panic output fails ddb8a7df8aa2 drm/panic: Split draw_panic_plane()a4343a106029 drm/panic: Display panic screen via per-plane callback
-:648: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #648:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 571 lines checkedb1c510458752 drm/panic: Internalize panic locking in DRM core and helpers
-:102: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #102:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 199 lines checked79335fa4360b drm/panic: Move panic display code into helper library
-:1112: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #1112:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 2070 lines checked 1abd75770638 drm/panic: Compile KUnit tests as module
Patchwork
CI✗ CI.KUnit: failure for drm/panic: Split into core and helpers
In reply to Thomas Zimmermann== Series Details ==
== Series Details ==
Series: drm/panic: Split into core and helpers
URL : https://patchwork.freedesktop.org/series/172394/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:/usr/bin/ld: drivers/gpu/drm/drm_kms_helper_common.o: in function `drm_kms_helper_init':
drm_kms_helper_common.c:(.init.text+0x6): undefined reference to drm_panic_helper_init' /usr/bin/ld: drivers/gpu/drm/drm_kms_helper_common.o: in function drm_kms_helper_exit':
drm_kms_helper_common.c:(.exit.text+0x6): undefined reference to `drm_panic_helper_exit'
collect2: error: ld returned 1 exit status
make[3]: *** [../scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1
make[2]: *** [/kernel/Makefile:1370: vmlinux] Error 2
make[1]: *** [/kernel/Makefile:248: __sub-make] Error 2
make: *** [Makefile:248: __sub-make] Error 2
[14:23:39] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [14:23:44] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel
Randy Dunlap
reviewerRe: [PATCH 11/12] drm/panic: Move panic display code into helper library
In reply to Thomas ZimmermannHi,
drivers/gpu/drm/Kconfig config DRM_MIPI_DSI · line 48
Quoted 10 lines · Thomas Zimmermann
M: Hans de Goede <[email protected]>
drivers/gpu/drm/Kconfig +1
-0@@ -45,6 +45,7 @@ config DRM_MIPI_DSI config DRM_KMS_HELPER tristate depends on DRM + select DRM_PANIC_HELPER if DRM_PANIC
but DRM_PANIC_HELPER depends on DRM_TTM so DRM_KMS_HELPER should also depend on DRM_TTM. Otherwise:
WARNING: unmet direct dependencies detected for DRM_PANIC_HELPER
Depends on [n]: HAS_IOMEM [=y] && DRM [=y] && DRM_TTM [=n] Selected by [y]:
- DRM_KMS_HELPER [=y] && HAS_IOMEM [=y] && DRM [=y] && DRM_PANIC [=y]
Quoted 14 lines
drivers/gpu/drm/Kconfig +4
-0select FB_CORE if DRM_FBDEV_EMULATION help CRTC helpers for KMS drivers.@@ -130,6 +131,10 @@ config DRM_PANIC_SCREEN_QR_VERSION Smaller QR code are easier to read, but will contain less debugging data. Default is 40. +config DRM_PANIC_HELPER + bool + depends on DRM_TTM + config DRM_RAS bool "DRM RAS support" depends on DRM
Signature · 1 line
~Randy
Thomas Zimmermann
maintainerRe: [PATCH 11/12] drm/panic: Move panic display code into helper library
Hi
Am 18.08.26 um 17:55 schrieb Randy Dunlap:
Quoted 15 lines
Hi,
drivers/gpu/drm/Kconfig config DRM_MIPI_DSI · line 48
Quoted 10 lines · Thomas Zimmermann
M: Hans de Goede <[email protected]>
drivers/gpu/drm/Kconfig +1
-0@@ -45,6 +45,7 @@ config DRM_MIPI_DSI config DRM_KMS_HELPER tristate depends on DRM + select DRM_PANIC_HELPER if DRM_PANICbut
DRM_PANIC_HELPERdepends onDRM_TTMsoDRM_KMS_HELPERshould also depend onDRM_TTM. Otherwise:
Oops, how did that creep in? There's no TTM dependency. This Kconfig change appears to be a copy-paste accident. Thanks for noting.
Best regards
Thomas
Quoted 21 lines
WARNING: unmet direct dependencies detected for
DRM_PANIC_HELPER
Depends on [n]:HAS_IOMEM[=y] && DRM [=y] &&DRM_TTM[=n] Selected by [y]:
-DRM_KMS_HELPER[=y] &&HAS_IOMEM[=y] && DRM [=y] &&DRM_PANIC[=y]Quoted 14 lines
drivers/gpu/drm/Kconfig +4
-0select FB_CORE if DRM_FBDEV_EMULATION help CRTC helpers for KMS drivers.@@ -130,6 +131,10 @@ config DRM_PANIC_SCREEN_QR_VERSION Smaller QR code are easier to read, but will contain less debugging data. Default is 40. +config DRM_PANIC_HELPER + bool + depends on DRM_TTM + config DRM_RAS bool "DRM RAS support" depends on DRM
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
Thomas Zimmermann
maintainerRe: [PATCH 06/12] drm/panic: Pass global module parameters to drm_panic_dispatch()
In reply to [email protected]Am 18.08.26 um 15:09 schrieb [email protected]:
Quoted 4 lines
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent debugfs writes or KUnit tests across multiple DRM devices race on global static buffers without adequate synchronization.
A fix would be nice, but is beyond this series. As it affects debugfs and kunit test there's no urgency.
Quoted 72 lines
--
--- Patch [6]: [PATCH 06/12] drm/panic: Pass global module parameters to
drm_panic_dispatch()--- commit9f2a1b5158feac614c09a17c83f387591642e034
Author: Thomas Zimmermann <[email protected]>drm/panic: Pass global module parameters to
drm_panic_dispatch()This patch sets the panic type and QR version in
draw_panic_plane()as a single point of truth, passing these values into the individual drawing functions. In the test case, it always creates a QR code with version 40.Quoted 4 lines
drivers/gpu/drm/drm_panic.c +0
-0[ ... ]
Quoted 13 lines
drivers/gpu/drm/drm_panic.c +5
-0@@ -951,6 +955,11 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)#else u32 bg_color =0x00000000 ;#endif +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +unsigned int qr_version = panic_qr_version; +#else +unsigned int qr_version =0 ; +#endif if (!drm_panic_trylock (plane->dev, flags))return ;drivers/gpu/drm/drm_panic.c static void draw_panic_plane(struct drm_plane *plane, const char *description) · line 978
Quoted 5 lines
drivers/gpu/drm/drm_panic.c +1
-1@@ -966,7 +975,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); - ret =draw_panic_dispatch (&sb, fg_color, bg_color); + ret =draw_panic_dispatch (&sb, drm_panic_type, fg_color, bg_color, qr_version);[Severity: High]
This is a pre-existing issue, but does the per-device locking indrm_panic_trylock()adequately protect the global buffers?Since the lock is per-device (
plane->dev->mode_config.panic_lock), concurrent debugfs writes across multiple DRM devices can still race and mutate global static variables, such as the zlib stream workspace (structz_stream_sstream) or qrbuf1 and qrbuf2.If a real kernel panic occurs while a debugfs write is concurrently using these buffers, the true panic handler could inherit a corrupted zlib workspace state, which might lead to a recursive fault and failure to display the panic screen.
Could this be protected by a global lock for non-panic paths?
[ ... ]
drivers/gpu/drm/tests/drm_panic_test.c static int draw_panic_screen_kmsg_default(struct drm_scanout_buffer *sb) · line 63
Quoted 12 lines
drivers/gpu/drm/tests/drm_panic_test.c +1
-1@@ -58,7 +58,7 @@ static int draw_panic_screen_kmsg_default(struct drm_scanout_buffer *sb)#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ); +return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ,40 ); }#endif [Severity: High]
This isn't a bug introduced by this patch, but do the KUnit tests safely access the global drawing state?It appears the KUnit tests bypass
draw_panic_plane()entirely and directly call drawing functions likedraw_panic_screen_qr_code()without acquiring any locks. Could running the tests race on the global buffers and corrupt the zlib workspace?
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
Thomas Zimmermann
maintainerRe: [PATCH 07/12] drm/panic: Retry in dispatch function if panic output fails
In reply to [email protected]Am 18.08.26 um 15:05 schrieb [email protected]:
Quoted 2 lines
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removing the internal fallback fromdraw_panic_screen_qr_codebreaks thedrm_panicKUnit tests.
I think that's exactly the right thing to do. When we unit-test draw_panic_screen_qr_code() , we better not fallback silently to something that works; thus masking the error.
Quoted 48 lines
--
--- Patch [7]: [PATCH 07/12] drm/panic: Retry in dispatch function if panic output fails --- commit
23392eb57457ad383d9c4741f6fc2f3c107aabb3
Author: Thomas Zimmermann <[email protected]>drm/panic: Retry in dispatch function if panic output fails
On failed output of QR codes and kmsg buffers, fall back to a user message. QR-code output already did this internally, but now formally support it in
drm_panic_dispatch(). Streamlines the existing logic.Quoted 2 lines
drivers/gpu/drm/drm_panic.c +0
-0[ ... ]
drivers/gpu/drm/drm_panic.c static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb, · line 827
Quoted 13 lines
drivers/gpu/drm/drm_panic.c +0
-9@@ -816,15 +816,6 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,drm_panic_blit (sb, &r_qr, qr_image, qr_pitch, scale, fg_color);return 0 ; } - -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) -{ -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version)) -draw_panic_screen_user (sb, fg_color, bg_color); -return 0 ; -}[Severity: Medium]
Does removing this fallback cause thedrm_panicKUnit tests to fail?Looking at the test suite in
drivers/gpu/drm/tests/drm_panic_test.c, it calls this function directly without going through the new dispatch logic:static int
draw_panic_screen_qr_code_default(struct drm_scanout_buffer *sb){ return draw_panic_screen_qr_code(sb, 0x00ffffff, 0x00000000, 40); }When tested with a small resolution like 300x200, the scale evaluates to 0 and returns
-ENOSPC. Previously, this wrapper caught the error, fell back todraw_panic_screen_user, and safely returned 0, satisfying the KUnit check.Since the fallback was moved to
draw_panic_dispatchand the test calls the lower-level function directly, will this now propagate the-ENOSPCerror and spuriously fail the test?
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
Thomas Zimmermann
maintainerRe: [PATCH 09/12] drm/panic: Display panic screen via per-plane callback
In reply to [email protected]Am 18.08.26 um 15:19 schrieb [email protected]:
Quoted 2 lines
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Thedrm_plane_helper_display_panic_screenhelper unconditionally dereferencesplane->helper_privateandplane->helper_private->get_scanout_buffer. However, by addingDRM_PANIC_PLANE_FUNCSto shared plane function tables (likeskl_plane_funcsin i915 anddm_plane_funcsin amdgpu), thedisplay_panic_screencallback is now applied to all planes (including cursors and overlays). These non-primary planes use different helper functions (e.g.,intel_plane_helper_funcsordm_plane_helper_funcs) that do not implementget_scanout_buffer. This causesdrm_panic_registerto mistakenly register panic dumpers for these planes, and upon a panic, the handler executes a NULL pointer dereference, triggering a nested panic.
Will be fixed by testing for get_scanout_buffer from drm_plane_helper_display_panic_screen(). I'll also add a check to only register panic screens for primary planes.
Quoted 1 line
- [Medium] The patch replaces
get_scanout_bufferwithdisplay_panic_screenas the signal for panic support. However, it fails to addDRM_PANIC_PLANE_FUNCSto the legacy fallbackprimary_plane_funcsindrm_modeset_helper.c. Older AMDGPU DCE drivers (e.g., DCE 6.0, 8.0, 10.0) usedrm_crtc_init()which implicitly relies on this legacy structure for their primary planes. Although these drivers implementget_scanout_bufferin their helper functions (dce_v10_0_drm_primary_plane_helper_funcs), their planes now lack thedisplay_panic_screencallback. Consequently,drm_panic_is_enabled()returns false and their panic dumpers are never registered, silently breaking panic screen support on these hardware generations.
Will be added.
Quoted 1 line
- [Low]
drm_plane_helper_display_panic_screenaccepts apanic_typeparameter (anenum drm_panic_type). However, when it callsdraw_panic_dispatch(), it passes the global module parameterdrm_panic_typeinstead of the passed-inpanic_type. This logic bug prevents drivers from tailoring the panic screen implementation via the helper as intended.
Fixed in an earlier patch.
Quoted 77 lines
--
--- Patch [9]: [PATCH 09/12] drm/panic: Display panic screen via per-plane callback --- commit
69fa8c39afc844867e193df3659c6f6f1fb762f3
Author: Thomas Zimmermann <[email protected]>drm/panic: Display panic screen via per-plane callback
This commit adds
display_panic_screento structdrm_plane_funcsto replaceget_scanout_bufferas the signal for panic support. It provides the helperdrm_plane_helper_display_panic_screen()and theDRM_PANIC_PLANE_FUNCSmacro to update drivers that implement panic support.Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +0
-0[ ... ]
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c static const struct drm_plane_funcs dm_plane_funcs = { · line 2182
Quoted 6 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +1
-0@@ -2177,6 +2178,7 @@ static const struct drm_plane_funcs dm_plane_funcs = { .atomic_set_property = dm_atomic_plane_set_property, .atomic_get_property = dm_atomic_plane_get_property,#endif + DRM_PANIC_PLANE_FUNCS, };[Severity: High]
Does adding this macro to shared plane function tables (likedm_plane_funcsorskl_plane_funcs) apply the panic screen callback to all planes, including cursors and overlays?Non-primary planes use different helper functions that do not implement
get_scanout_buffer. Sincedrm_plane_helper_display_panic_screen()unconditionally dereferencesplane->helper_private->get_scanout_buffer, could this cause a NULL pointer dereference in the panic handler for these planes and trigger a nested panic?Quoted 4 lines
drivers/gpu/drm/drm_panic.c +0
-0[ ... ]
drivers/gpu/drm/drm_panic.c static void drm_panic_clear_description(void) · line 949
Quoted 6 lines
drivers/gpu/drm/drm_panic.c +3
-0+void drm_plane_helper_display_panic_screen (struct drm_plane *plane,const char *description, +enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color,unsigned int qr_version) {struct drm_scanout_buffer sb = { };int ret;[Severity: Low]
Is thepanic_typeparameter correctly passed to the dispatch function?The function accepts a
panic_typeargument, but the implementation appears to pass the global module parameterdrm_panic_typetodraw_panic_dispatch()instead of the passed-in argument. Does this discard the caller's requested panic type?Quoted 5 lines
include/drm/drm_panic_helper.h new file +0
-0[ ... ]
include/drm/drm_panic_helper.h line 25
Quoted 7 lines
include/drm/drm_panic_helper.h new file +7
-0+#if IS_ENABLED (CONFIG_DRM_PANIC ) +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = drm_plane_helper_display_panic_screen +#else +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = NULL +#endif [Severity: Medium]
Does the legacy fallbackprimary_plane_funcsindrm_modeset_helper.calso need to be updated withDRM_PANIC_PLANE_FUNCS?Older AMDGPU DCE drivers use
drm_crtc_init(), which implicitly relies on this legacy structure for their primary planes. Although these drivers implementget_scanout_buffer()in their helper functions, lacking this macro in the fallback could causedrm_panic_is_enabled()to return false and silently drop panic screen support on these hardware generations.
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
Re: [PATCH 01/12] drm/panic: Allocate QR-code buffers statically
In reply to Thomas ZimmermannHi Thomas,
Quoted 7 lines · Thomas Zimmermann
Declare qrbuf1 and qrbuf2 as static arrays so that the module loader allocates them for us. Avoids the kmalloc later on. Also allows for using
sizeof()to get the number of bytes in each array. Access the arrays once with memset, so that the physical pages are available on a panic.Signed-off-by Thomas Zimmermann <[email protected]>
Thanks for your patch!
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 632
Quoted 10 lines
drivers/gpu/drm/drm_panic.c +2
-2@@ -628,24 +628,23 @@ MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code");#define WINDOW_BITS 12#define MEM_LEVEL 4 -static char *qrbuf1; -static char *qrbuf2; +static u8 qrbuf1[QR_BUFFER1_SIZE ]; +static u8 qrbuf2[QR_BUFFER2_SIZE ];
I am not a big fan of increasing kernel size like this. You may run (faster) into boot loader limitations.
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 639
Quoted 9 lines
drivers/gpu/drm/drm_panic.c +1
-2static struct z_stream_s stream;static void __init drm_panic_qr_init (void ) { - qrbuf1 =kmalloc (QR_BUFFER1_SIZE ,GFP_KERNEL ); - qrbuf2 =kmalloc (QR_BUFFER2_SIZE ,GFP_KERNEL ); +/* best-effort allocation; can be NULL */ stream.workspace =kmalloc (zlib_deflate_workspacesize (WINDOW_BITS ,MEM_LEVEL ),GFP_KERNEL );
<ironic>Why not use a static array for this, too?</ironic>
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 643
Quoted 4 lines
drivers/gpu/drm/drm_panic.c +4
-0+ +/* touch memory so that pages are there in the case of a panic */ +memset (qrbuf1,0 ,sizeof (qrbuf1)); +memset (qrbuf2,0 ,sizeof (qrbuf2));
Please clarify "there"?
In cache? Not all systems have sufficient data cache, so it may be evicted at any time.
In RAM? AFAIK kernel and module memory is not demand-paged. In TLB? Like cache, it may be evicted at any time.
So IMHO this is futile.
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 644
Quoted 1 line
drivers/gpu/drm/drm_panic.c +0
-0}
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Thomas Zimmermann
maintainerRe: [PATCH 01/12] drm/panic: Allocate QR-code buffers statically
Hi
Am 19.08.26 um 11:38 schrieb Geert Uytterhoeven:
Quoted 18 lines
Hi Thomas,
Quoted 7 lines · Thomas Zimmermann
Declare qrbuf1 and qrbuf2 as static arrays so that the module loader allocates them for us. Avoids the kmalloc later on. Also allows for using
sizeof()to get the number of bytes in each array. Access the arrays once with memset, so that the physical pages are available on a panic.Signed-off-by Thomas Zimmermann <[email protected]>Thanks for your patch!
Quoted 6 lines
drivers/gpu/drm/drm_panic.c +0
-0@@ -628,24 +628,23 @@ MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code");#define WINDOW_BITS 12#define MEM_LEVEL 4
Quoted 6 lines
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 632
Quoted 4 lines
drivers/gpu/drm/drm_panic.c +2
-2-static char *qrbuf1; -static char *qrbuf2; +static u8 qrbuf1[QR_BUFFER1_SIZE ]; +static u8 qrbuf2[QR_BUFFER2_SIZE ];I am not a big fan of increasing kernel size like this. You may run (faster) into boot loader limitations.
Which limitation would this be?
Quoted 11 lines
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 639
Quoted 10 lines
drivers/gpu/drm/drm_panic.c +1
-2static struct z_stream_s stream;static void __init drm_panic_qr_init (void ) { - qrbuf1 =kmalloc (QR_BUFFER1_SIZE ,GFP_KERNEL ); - qrbuf2 =kmalloc (QR_BUFFER2_SIZE ,GFP_KERNEL ); +/* best-effort allocation; can be NULL */ stream.workspace =kmalloc (zlib_deflate_workspacesize (WINDOW_BITS ,MEM_LEVEL ),GFP_KERNEL );<ironic>Why not use a static array for this, too?</ironic>
I tried, by the size is calculated at runtime.
Quoted 10 lines
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 643
Quoted 5 lines
drivers/gpu/drm/drm_panic.c +4
-0+ +/* touch memory so that pages are there in the case of a panic */ +memset (qrbuf1,0 ,sizeof (qrbuf1)); +memset (qrbuf2,0 ,sizeof (qrbuf2));Please clarify "there"?
In cache? Not all systems have sufficient data cache, so it may be evicted at any time.
In RAM? AFAIK kernel and module memory is not demand-paged. In TLB? Like cache, it may be evicted at any time.
I'd like to avoid looking for a page after a panic has already occurred. But I guess it might not make a difference, given all the DRM that is involved.
The motivation here was that I did not like that panic handling depends on a number of dynamic kmallocs, with which we don't even detect alloc failures until a panic has occurred.
Quoted 2 lines
So IMHO this is futile.
Noted.
Best regards
Thomas
Quoted 6 lines
drivers/gpu/drm/drm_panic.c MODULE_PARM_DESC(panic_qr_version, "maximum version (size) of the QR code"); · line 644
Quoted 2 lines
drivers/gpu/drm/drm_panic.c +0
-0}Gr{oetje,eeting}s,
Geert
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
Re: [PATCH 03/12] drm/panic: Return -EINVAL if font is not available
In reply to Thomas ZimmermannQuoted 2 lines · Thomas Zimmermann
Font lookup does not allocate memory. Hence reporting ENOMEM on failed lookups is misleading. Report EINVAL instead.
Thanks, it looks good to me.
Quoted 22 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_panic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_panic.c +3
-1@@ -757,8 +757,10 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb)int qr_width, qr_canvas_width, qr_pitch, v_margin;u8 *qr_image; -if (!font || !stream.workspace) +if (!stream.workspace)return -ENOMEM ; +if (!font) +return -EINVAL ; r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);
Re: [PATCH 04/12] drm/panic: Return errno codes if panic output fails
In reply to Thomas ZimmermannQuoted 6 lines · Thomas Zimmermann
Return errno codes from the panic output helpers to detect invalid panic handling. Avoid flushing the display if an error ocured. The unflushed display output might be helpful in debugging.
For now, test the result values in the panic test cases. A later patch will add support for retrying failed panic output.
Thanks, it looks good to me.
Quoted 198 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_panic.c | 41 +++++++++++++++++--------- drivers/gpu/drm/tests/drm_panic_test.c | 16 ++++++---- 2 files changed, 37 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_panic.c +27
-14@@ -478,7 +478,7 @@ static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct drm_rect * fg_color); } -static void draw_panic_screen_user (struct drm_scanout_buffer *sb) +static int draw_panic_screen_user (struct drm_scanout_buffer *sb) {u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);@@ -489,7 +489,7 @@ static void draw_panic_screen_user(struct drm_scanout_buffer *sb)unsigned int msg_width, msg_height;if (!font) -return ; +return -EINVAL ; r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);drm_panic_logo_rect (&r_logo, font);@@ -508,6 +508,8 @@ static void draw_panic_screen_user(struct drm_scanout_buffer *sb)drm_panic_logo_draw (sb, &r_logo, font, fg_color);draw_txt_rectangle (sb, font, panic_msg, panic_msg_lines, true, &r_msg, fg_color); + +return 0 ; }/* @@ -547,7 +549,7 @@ static int draw_line_with_wrap(struct drm_scanout_buffer *sb, const struct font_* Draw the kmsg buffer to the screen, starting from the youngest message at the bottom, * and going up until reaching the top of the screen. */ -static void draw_panic_screen_kmsg (struct drm_scanout_buffer *sb) +static int draw_panic_screen_kmsg (struct drm_scanout_buffer *sb) {u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , sb->format->format);@@ -562,7 +564,7 @@ static void draw_panic_screen_kmsg(struct drm_scanout_buffer *sb)int yoffset;if (!font || font->width > sb->width) -return ; +return -EINVAL ; yoffset = sb->height - font->height - (sb->height % font->height) /2 ;@@ -589,6 +591,8 @@ static void draw_panic_screen_kmsg(struct drm_scanout_buffer *sb) start--; } } + +return 0 ; }#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE )@@ -814,10 +818,11 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb) return 0; } -static void draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) {if (_draw_panic_screen_qr_code (sb))draw_panic_screen_user (sb); +return 0 ; }#else static void drm_panic_qr_init (void ) {};@@ -888,23 +893,25 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format)return drm_draw_can_convert_from_xrgb8888 (format->format); } -static void draw_panic_dispatch (struct drm_scanout_buffer *sb) +static int draw_panic_dispatch (struct drm_scanout_buffer *sb) { +int ret; +switch (drm_panic_type) {case DRM_PANIC_TYPE_KMSG : -draw_panic_screen_kmsg (sb); + ret =draw_panic_screen_kmsg (sb);break ; -#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : -draw_panic_screen_qr_code (sb); + ret =draw_panic_screen_qr_code (sb);break ;#endif -case DRM_PANIC_TYPE_USER :default : -draw_panic_screen_user (sb); + ret =draw_panic_screen_user (sb); } + +return ret; }static void drm_panic_set_description (const char *description)@@ -951,9 +958,15 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); -draw_panic_dispatch (&sb); -if (plane->helper_private->panic_flush) - plane->helper_private->panic_flush (plane); + ret =draw_panic_dispatch (&sb); +if (!ret) { +/* +* Only flush if we have a panic screen to display. Otherwise +* it's probably better to leave the display output as-is. +*/ +if (plane->helper_private->panic_flush) + plane->helper_private->panic_flush (plane); + }drm_panic_clear_description ();drivers/gpu/drm/tests/drm_panic_test.c +10
-6@@ -30,7 +30,7 @@ struct drm_test_mode {const int width;const int height;const u32 format; -void (*draw_screen)(struct drm_scanout_buffer *sb); +int (*draw_screen)(struct drm_scanout_buffer *sb);const char *fname; };@@ -87,7 +87,7 @@ static void drm_test_panic_screen_user_map(struct kunit *test)const struct drm_test_mode *params = test->param_value;char *fb;int fb_size; -int i; +int i, ret; sb->format =drm_format_info (params->format); fb_size = params->width * params->height * sb->format->cpp[0 ];@@ -102,7 +102,8 @@ static void drm_test_panic_screen_user_map(struct kunit *test) sb->height = params->height; sb->pitch[0 ] = params->width * sb->format->cpp[0 ]; - params->draw_screen (sb); + ret = params->draw_screen (sb); +KUNIT_ASSERT_EQ (test, ret,0 );for (i =0 ; i < fb_size; i++)drm_panic_check_color_byte (test, fb[i]);@@ -119,7 +120,7 @@ static void drm_test_panic_screen_user_page(struct kunit *test) {struct drm_scanout_buffer *sb = test->priv;const struct drm_test_mode *params = test->param_value; -int fb_size, p, i, npages; +int fb_size, p, i, npages, ret;struct page **pages;u8 *vaddr;@@ -146,7 +147,8 @@ static void drm_test_panic_screen_user_page(struct kunit *test) sb->height = params->height; sb->pitch[0 ] = params->width * sb->format->cpp[0 ]; - params->draw_screen (sb); + ret = params->draw_screen (sb); +KUNIT_ASSERT_EQ (test, ret,0 );for (p =0 ; p < npages; p++) {int bytes_in_page = (p == npages -1 ) ? fb_size - p *PAGE_SIZE :PAGE_SIZE ;@@ -182,6 +184,7 @@ static void drm_test_panic_screen_user_set_pixel(struct kunit *test) {struct drm_scanout_buffer *sb = test->priv;const struct drm_test_mode *params = test->param_value; +int ret; sb->format =drm_format_info (params->format); sb->set_pixel = drm_test_panic_set_pixel;@@ -189,7 +192,8 @@ static void drm_test_panic_screen_user_set_pixel(struct kunit *test) sb->height = params->height; sb->private = test; - params->draw_screen (sb); + ret = params->draw_screen (sb); +KUNIT_ASSERT_EQ (test, ret,0 ); }static void drm_test_panic_desc (const struct drm_test_mode *t,char *desc)
Re: [PATCH 05/12] drm/panic: Pass colors to draw_panic_dispatch()
In reply to Thomas ZimmermannQuoted 9 lines · Thomas Zimmermann
Set the panic-screen colors in
draw_panic_plane()as a single point of truth. Pass the values into the individual drawing functions.In the test cases, replace the Kconfig-defined colors with white and black. Allows for removal of the tests' limitations and dependency on the exact values. All tests now always verify the generated output.
Hardcoding the test colors will later also allow for building the test case without having DRM panic handling enabled.
Thanks, that makes sense, I should've think about it, as this colors was a bit painful when writing the KUnit tests.
Quoted 202 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_panic.c | 54 +++++++++++++++----------- drivers/gpu/drm/tests/drm_panic_test.c | 26 +++++++++---- 2 files changed, 49 insertions(+), 31 deletions(-)drivers/gpu/drm/drm_panic.c +31
-23@@ -478,12 +478,8 @@ static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct drm_rect * fg_color); } -static int draw_panic_screen_user (struct drm_scanout_buffer *sb) +static int draw_panic_screen_user (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) { -u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , - sb->format->format); -u32 bg_color =drm_draw_color_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 msg_width, msg_height;@@ -491,6 +487,9 @@ static int draw_panic_screen_user(struct drm_scanout_buffer *sb)if (!font)return -EINVAL ; + fg_color =drm_draw_color_from_xrgb8888 (fg_color, sb->format->format); + bg_color =drm_draw_color_from_xrgb8888 (bg_color, sb->format->format); + r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);drm_panic_logo_rect (&r_logo, font);@@ -549,12 +548,8 @@ static int draw_line_with_wrap(struct drm_scanout_buffer *sb, const struct font_* Draw the kmsg buffer to the screen, starting from the youngest message at the bottom, * and going up until reaching the top of the screen. */ -static int draw_panic_screen_kmsg (struct drm_scanout_buffer *sb) +static int draw_panic_screen_kmsg (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) { -u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , - sb->format->format); -u32 bg_color =drm_draw_color_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 =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);struct kmsg_dump_iter iter;@@ -566,6 +561,9 @@ static int draw_panic_screen_kmsg(struct drm_scanout_buffer *sb)if (!font || font->width > sb->width)return -EINVAL ; + fg_color =drm_draw_color_from_xrgb8888 (fg_color, sb->format->format); + bg_color =drm_draw_color_from_xrgb8888 (bg_color, sb->format->format); + yoffset = sb->height - font->height - (sb->height % font->height) /2 ;/* Fill with the background color, and draw text on top */ @@ -748,12 +746,9 @@ static int drm_panic_get_qr_code(u8 **qr_image)/* * Draw the panic message at the center of the screen, with a QR Code */ -static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color) { -u32 fg_color =drm_draw_color_from_xrgb8888 (CONFIG_DRM_PANIC_FOREGROUND_COLOR , - sb->format->format); -u32 bg_color =drm_draw_color_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, r_qr, r_qr_canvas;unsigned int max_qr_size, scale;@@ -766,6 +761,9 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb)if (!font)return -EINVAL ; + fg_color =drm_draw_color_from_xrgb8888 (fg_color, sb->format->format); + bg_color =drm_draw_color_from_xrgb8888 (bg_color, sb->format->format); + r_screen =DRM_RECT_INIT (0 ,0 , sb->width, sb->height);drm_panic_logo_rect (&r_logo, font);@@ -818,10 +816,10 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb) return 0; } -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) { -if (_draw_panic_screen_qr_code (sb)) -draw_panic_screen_user (sb); +if (_draw_panic_screen_qr_code (sb, fg_color, bg_color)) +draw_panic_screen_user (sb, fg_color, bg_color);return 0 ; }#else @@ -893,22 +891,22 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format)return drm_draw_can_convert_from_xrgb8888 (format->format); } -static int draw_panic_dispatch (struct drm_scanout_buffer *sb) +static int draw_panic_dispatch (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) {int ret;switch (drm_panic_type) {case DRM_PANIC_TYPE_KMSG : - ret =draw_panic_screen_kmsg (sb); + ret =draw_panic_screen_kmsg (sb, fg_color, bg_color);break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : - ret =draw_panic_screen_qr_code (sb); + ret =draw_panic_screen_qr_code (sb, fg_color, bg_color);break ;#endif case DRM_PANIC_TYPE_USER :default : - ret =draw_panic_screen_user (sb); + ret =draw_panic_screen_user (sb, fg_color, bg_color); }return ret;@@ -943,6 +941,16 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)struct drm_scanout_buffer sb = { };int ret;unsigned long flags; +#if defined(CONFIG_DRM_PANIC_FOREGROUND_COLOR ) +u32 fg_color =CONFIG_DRM_PANIC_FOREGROUND_COLOR ; +#else +u32 fg_color =0x00ffffff ; +#endif +#if defined(CONFIG_DRM_PANIC_BACKGROUND_COLOR ) +u32 bg_color =CONFIG_DRM_PANIC_BACKGROUND_COLOR ; +#else +u32 bg_color =0x00000000 ; +#endif if (!drm_panic_trylock (plane->dev, flags))return ;@@ -958,7 +966,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); - ret =draw_panic_dispatch (&sb); + ret =draw_panic_dispatch (&sb, fg_color, bg_color);if (!ret) {/* * Only flush if we have a panic screen to display. Otherwise drivers/gpu/drm/tests/drm_panic_test.c +18
-8@@ -14,17 +14,10 @@#include <linux/units.h> #include <linux/vmalloc.h> -/* Check the framebuffer color only if the panic colors are the default */ -#if (CONFIG_DRM_PANIC_BACKGROUND_COLOR ==0 && \ -CONFIG_DRM_PANIC_FOREGROUND_COLOR ==0xffffff ) -static void drm_panic_check_color_byte (struct kunit *test,u8 b) {KUNIT_EXPECT_TRUE (test, (b ==0 || b ==0xff )); } -#else -static void drm_panic_check_color_byte (struct kunit *test,u8 b) {} -#endif struct drm_test_mode {const int width;@@ -48,10 +41,27 @@ struct drm_test_mode { .width = w, \ .height = h, \ .format = f, \ - .draw_screen = draw_panic_screen_##name, \ + .draw_screen = draw_panic_screen_ ## name ## _default, \ .fname = #name, \ }, \ +static int draw_panic_screen_user_default (struct drm_scanout_buffer *sb) +{ +return draw_panic_screen_user (sb,0x00ffffff ,0x00000000 ); +} + +static int draw_panic_screen_kmsg_default (struct drm_scanout_buffer *sb) +{ +return draw_panic_screen_kmsg (sb,0x00ffffff ,0x00000000 ); +} + +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) +{ +return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ); +} +#endif +static const struct drm_test_mode drm_test_modes_cases[] = { DRM_TEST_MODE_LIST(user)DRM_TEST_MODE_LIST (kmsg)
Re: [PATCH 06/12] drm/panic: Pass global module parameters to drm_panic_dispatch()
In reply to Thomas ZimmermannQuoted 5 lines · Thomas Zimmermann
Set the panic type and QR version in
draw_panic_plane()as a single point of truth. Pass the values into the individual drawing functions.In the test case, always create a QR code with version 40 (i.e., the highest supported version).
Thanks, it looks good to me.
Quoted 147 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_panic.c | 39 ++++++++++++++++---------- drivers/gpu/drm/tests/drm_panic_test.c | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-)drivers/gpu/drm/drm_panic.c +24
-15@@ -657,7 +657,7 @@ static void drm_panic_qr_exit(void) stream.workspace =NULL ; } -static int drm_panic_get_qr_code_url (u8 **qr_image) +static int drm_panic_get_qr_code_url (u8 **qr_image,unsigned int qr_version) {struct kmsg_dump_iter iter;char url[256 ];@@ -672,7 +672,7 @@ static int drm_panic_get_qr_code_url(u8 **qr_image)return -EINVAL ; url_len = ret; - max_qr_data_size =drm_panic_qr_max_data_size (panic_qr_version, url_len); + max_qr_data_size =drm_panic_qr_max_data_size (qr_version, url_len); max_kmsg_size =min (MAX_ZLIB_RATIO * max_qr_data_size,sizeof (qrbuf1));/* get kmsg to buffer 1 */ @@ -718,11 +718,11 @@ static int drm_panic_get_qr_code_url(u8 **qr_image) qrbuf1, sizeof(qrbuf1)); } -static int drm_panic_get_qr_code_raw (u8 **qr_image) +static int drm_panic_get_qr_code_raw (u8 **qr_image,unsigned int qr_version) {struct kmsg_dump_iter iter;size_t kmsg_len; -size_t max_kmsg_size =min (drm_panic_qr_max_data_size (panic_qr_version,0 ), +size_t max_kmsg_size =min (drm_panic_qr_max_data_size (qr_version,0 ),sizeof (qrbuf1));kmsg_dump_rewind (&iter);@@ -735,19 +735,20 @@ static int drm_panic_get_qr_code_raw(u8 **qr_image) qrbuf2, sizeof(qrbuf2)); } -static int drm_panic_get_qr_code (u8 **qr_image) +static int drm_panic_get_qr_code (u8 **qr_image,unsigned int qr_version) {if (strlen (CONFIG_DRM_PANIC_SCREEN_QR_CODE_URL ) >0 ) -return drm_panic_get_qr_code_url (qr_image); +return drm_panic_get_qr_code_url (qr_image, qr_version);else -return drm_panic_get_qr_code_raw (qr_image); +return drm_panic_get_qr_code_raw (qr_image, qr_version); }/* * Draw the panic message at the center of the screen, with a QR Code */ static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color) +u32 fg_color,u32 bg_color, +unsigned int qr_version) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg, r_qr, r_qr_canvas;@@ -774,7 +775,7 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb, max_qr_size =min (3 * sb->width /4 ,3 * sb->height /4 ); - qr_width =drm_panic_get_qr_code (&qr_image); + qr_width =drm_panic_get_qr_code (&qr_image, qr_version);if (qr_width <=0 )return -ENOSPC ;@@ -816,9 +817,11 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,return 0 ; } -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color, +unsigned int qr_version) { -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color)) +if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version))draw_panic_screen_user (sb, fg_color, bg_color);return 0 ; }@@ -891,17 +894,18 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format)return drm_draw_can_convert_from_xrgb8888 (format->format); } -static int draw_panic_dispatch (struct drm_scanout_buffer *sb,u32 fg_color,u32 bg_color) +static int draw_panic_dispatch (struct drm_scanout_buffer *sb,enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color,unsigned int qr_version) {int ret; -switch (drm_panic_type) { +switch (panic_type) {case DRM_PANIC_TYPE_KMSG : ret =draw_panic_screen_kmsg (sb, fg_color, bg_color);break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : - ret =draw_panic_screen_qr_code (sb, fg_color, bg_color); + ret =draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version);break ;#endif case DRM_PANIC_TYPE_USER :@@ -951,6 +955,11 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)#else u32 bg_color =0x00000000 ;#endif +#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE ) +unsigned int qr_version = panic_qr_version; +#else +unsigned int qr_version =0 ; +#endif if (!drm_panic_trylock (plane->dev, flags))return ;@@ -966,7 +975,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)drm_panic_set_description (description); - ret =draw_panic_dispatch (&sb, fg_color, bg_color); + ret =draw_panic_dispatch (&sb, drm_panic_type, fg_color, bg_color, qr_version);if (!ret) {/* * Only flush if we have a panic screen to display. Otherwise drivers/gpu/drm/tests/drm_panic_test.c +1
-1@@ -58,7 +58,7 @@ static int draw_panic_screen_kmsg_default(struct drm_scanout_buffer *sb)#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )static int draw_panic_screen_qr_code_default (struct drm_scanout_buffer *sb) { -return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ); +return draw_panic_screen_qr_code (sb,0x00ffffff ,0x00000000 ,40 ); }#endif
Re: [PATCH 07/12] drm/panic: Retry in dispatch function if panic output fails
In reply to Thomas ZimmermannQuoted 7 lines · Thomas Zimmermann
On failed output of QR codes and kmsg buffers, fall back to a user message. QR-code output already did this internally, but now formally support it in
drm_panic_dispatch(). Streamlines the existing logic.Also pass module parameter
drm_panic_typeas a parameter todrm_panic_dispatch(). This simpifies the implementation. It will later allow for moving the function into a helper library.
Thanks, it looks good to me.
Quoted 62 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_panic.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/gpu/drm/drm_panic.c +12
-12@@ -746,9 +746,9 @@ static int drm_panic_get_qr_code(u8 **qr_image, unsigned int qr_version)/* * Draw the panic message at the center of the screen, with a QR Code */ -static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color, +unsigned int qr_version) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg, r_qr, r_qr_canvas;@@ -816,15 +816,6 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,drm_panic_blit (sb, &r_qr, qr_image, qr_pitch, scale, fg_color); return 0; } - -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) -{ -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version)) -draw_panic_screen_user (sb, fg_color, bg_color); -return 0 ; -}#else static void drm_panic_qr_init (void ) {};static void drm_panic_qr_exit (void ) {};@@ -899,13 +890,22 @@ static int draw_panic_dispatch(struct drm_scanout_buffer *sb, enum drm_panic_typ {int ret; +retry:switch (panic_type) {case DRM_PANIC_TYPE_KMSG : ret =draw_panic_screen_kmsg (sb, fg_color, bg_color); +if (ret) { + panic_type =DRM_PANIC_TYPE_USER ; + goto retry; + }break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : ret =draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version); +if (ret) { + panic_type =DRM_PANIC_TYPE_USER ; + goto retry; + }break ;#endif case DRM_PANIC_TYPE_USER :
Re: [PATCH 07/12] drm/panic: Retry in dispatch function if panic output fails
In reply to Thomas ZimmermannQuoted 7 lines · Thomas Zimmermann
On failed output of QR codes and kmsg buffers, fall back to a user message. QR-code output already did this internally, but now formally support it in
drm_panic_dispatch(). Streamlines the existing logic.Also pass module parameter
drm_panic_typeas a parameter todrm_panic_dispatch(). This simpifies the implementation. It will later allow for moving the function into a helper library.
Thanks, it looks good to me.
Quoted 62 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_panic.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/gpu/drm/drm_panic.c +12
-12@@ -746,9 +746,9 @@ static int drm_panic_get_qr_code(u8 **qr_image, unsigned int qr_version)/* * Draw the panic message at the center of the screen, with a QR Code */ -static int _draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) +static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, +u32 fg_color,u32 bg_color, +unsigned int qr_version) {const struct font_desc *font =get_default_font (sb->width, sb->height,NULL ,NULL );struct drm_rect r_screen, r_logo, r_msg, r_qr, r_qr_canvas;@@ -816,15 +816,6 @@ static int _draw_panic_screen_qr_code(struct drm_scanout_buffer *sb,drm_panic_blit (sb, &r_qr, qr_image, qr_pitch, scale, fg_color); return 0; } - -static int draw_panic_screen_qr_code (struct drm_scanout_buffer *sb, -u32 fg_color,u32 bg_color, -unsigned int qr_version) -{ -if (_draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version)) -draw_panic_screen_user (sb, fg_color, bg_color); -return 0 ; -}#else static void drm_panic_qr_init (void ) {};static void drm_panic_qr_exit (void ) {};@@ -899,13 +890,22 @@ static int draw_panic_dispatch(struct drm_scanout_buffer *sb, enum drm_panic_typ {int ret; +retry:switch (panic_type) {case DRM_PANIC_TYPE_KMSG : ret =draw_panic_screen_kmsg (sb, fg_color, bg_color); +if (ret) { + panic_type =DRM_PANIC_TYPE_USER ; + goto retry; + }break ;#if IS_ENABLED (CONFIG_DRM_PANIC_SCREEN_QR_CODE )case DRM_PANIC_TYPE_QR : ret =draw_panic_screen_qr_code (sb, fg_color, bg_color, qr_version); +if (ret) { + panic_type =DRM_PANIC_TYPE_USER ; + goto retry; + }break ;#endif case DRM_PANIC_TYPE_USER :
Re: [PATCH 09/12] drm/panic: Display panic screen via per-plane callback
In reply to Thomas ZimmermannQuoted 28 lines · Thomas Zimmermann
Add
display_panic_screento structdrm_plane_funcs. If set on a plane, register a panic handler for the plane from the DRM core's panic handling. Invoke this helper from the core to display a panic screen.The new callback replaces
get_scanout_bufferas signal for panic support in a plane. Usingget_scanout_bufferis now merely a detail of the implementation. This will also free structdrm_scanout_bufferfor use cases besides panic handling.With
display_panic_screenin place, renamedraw_panic_plane()todrm_plane_helper_display_panic_screen()and make it available to DRM drivers viadrm_panic_helper.h. Do not change the implementation or functionality of this code.drm_plane_helper_display_panic_screen()still supports kernel messages, user messages and QR codes on various color formats.Then update all drivers that implement panic support. Provide the initializer macro
DRM_PANIC_PLANE_FUNCSthat setsdisplay_panic_screentodrm_plane_helper_display_panic_screen(). If panic handling has been disabled, it instead clears the callback. There's again no change in functionality.This logically splits panic handling into a set of entry points in the DRM code and a set of helper functions provided by drivers. The core invokes the driver's helper via callback, while the driver can tailor the implementation to its needs. Panic handling now works like most other interfaces in the DRM framework.
Quoted 9 lines
Locking and state-handling happens in the DRM core or helpers. Drivers that receive a call to
display_panic_screencan assume that no concurrent modeset takes place on the plane or its CRTC.Also update the documentation. Move information about locking and state guarantees from
drm_panic_trylock()todisplay_panic_screen, where drivers authors can find it easily. Move information about the features of the current implementation todrm_panic_helper_display_panic_screen().
Thanks, it looks good to me.
Quoted 737 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- MAINTAINERS | 3 +- .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 2 + drivers/gpu/drm/ast/ast_mode.c | 2 + drivers/gpu/drm/drm_panic.c | 78 ++++++++++--------- drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 2 + drivers/gpu/drm/i915/display/i9xx_plane.c | 3 + .../drm/i915/display/skl_universal_plane.c | 4 + drivers/gpu/drm/imx/ipuv3/ipuv3-plane.c | 2 + drivers/gpu/drm/mgag200/mgag200_drv.h | 4 +- drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 + .../gpu/drm/renesas/rcar-du/rcar_du_plane.c | 2 + .../drm/renesas/shmobile/shmob_drm_plane.c | 2 + drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 4 +- drivers/gpu/drm/sysfb/vesadrm.c | 1 + drivers/gpu/drm/tidss/tidss_plane.c | 2 + drivers/gpu/drm/tiny/bochs.c | 4 +- drivers/gpu/drm/virtio/virtgpu_plane.c | 2 + include/drm/drm_mode_config.h | 4 +- include/drm/drm_modeset_helper_vtables.h | 11 ++- include/drm/drm_panic.h | 49 +++--------- include/drm/drm_panic_helper.h | 27 +++++++ include/drm/drm_plane.h | 57 ++++++++++++++ 22 files changed, 180 insertions(+), 87 deletions(-)create mode 100644
include/drm/drm_panic_helper.hMAINTAINERS +2
-1@@ -9020,7 +9020,8 @@ F: drivers/gpu/drm/drm_draw.c F: drivers/gpu/drm/drm_draw_internal.h F: drivers/gpu/drm/drm_panic*.c F: drivers/gpu/drm/tests/drm_panic_test.c -F: include/drm/drm_panic* +F: include/drm/drm_panic.h +F: include/drm/drm_panic_helper.h DRM PANIC QR CODE M: Jocelyn Falempe <[email protected]>drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +2
-0@@ -28,6 +28,7 @@#include <drm/drm_blend.h> #include "drm/drm_framebuffer.h" #include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_fourcc.h> @@ -2177,6 +2178,7 @@ static const struct drm_plane_funcs dm_plane_funcs = { .atomic_set_property = dm_atomic_plane_set_property, .atomic_get_property = dm_atomic_plane_get_property,#endif + DRM_PANIC_PLANE_FUNCS, }; int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,drivers/gpu/drm/ast/ast_mode.c +2
-0@@ -43,6 +43,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_managed.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h> @@ -652,6 +653,7 @@ static const struct drm_plane_funcs ast_primary_plane_funcs = { .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup,DRM_GEM_SHADOW_PLANE_FUNCS , + DRM_PANIC_PLANE_FUNCS, };static int ast_primary_plane_init (struct ast_device *ast)drivers/gpu/drm/drm_panic.c +40
-38@@ -28,6 +28,7 @@#include <drm/drm_framebuffer.h> #include <drm/drm_modeset_helper_vtables.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> @@ -42,32 +43,18 @@ MODULE_LICENSE("GPL");/** * DOC: overview * -* To enable DRM panic for a driver, the primary plane must implement a -* &drm_plane_helper_funcs.get_scanout_buffer helper function. It is then -* automatically registered to the drm panic handler. -* When a panic occurs, the &drm_plane_helper_funcs.get_scanout_buffer will be -* called, and the driver can provide a framebuffer so the panic handler can -* draw the panic screen on it. Currently only linear buffer and a few color -* formats are supported. -* Optionally the driver can also provide a &drm_plane_helper_funcs.panic_flush -* callback, that will be called after that, to send additional commands to the -* hardware to make the scanout buffer visible. -*/ - -/* -* This module displays a user friendly message on screen when a kernel panic -* occurs. This is conflicting with fbcon, so you can only enable it when fbcon -* is disabled. -* It's intended for end-user, so have minimal technical/debug information. +* This module displays a user friendly message on screen when a kernel +* panic occurs. This is conflicting with fbcon, so you can only enable +* it when fbcon is disabled. It's intended for end users and therefore +* have minimal technical/debug information. * -* Implementation details: +* To enable DRM panic for a driver, the at least one primary plane must +* implement struct &drm_plane_funcs.display_panic_screen. The plane is +* then automatically registered to the drm panic handler. * -* It is a panic handler, so it can't take lock, allocate memory, run tasks/irq, -* or attempt to sleep. It's a best effort, and it may not be able to display -* the message in all situations (like if the panic occurs in the middle of a -* modesetting). -* It will display only one static frame, so performance optimizations are low -* priority as the machine is already in an unusable state. +* When a panic occurs, the DRM panic handler calls struct +* &drm_plane_funcs.display_panic_screen. See +* drm_plane_helper_display_panic_screen() for a generic implementation. */ struct drm_panic_line {@@ -821,12 +808,6 @@ static void drm_panic_qr_init(void) {};static void drm_panic_qr_exit (void ) {};#endif -enum drm_panic_type { -DRM_PANIC_TYPE_KMSG , -DRM_PANIC_TYPE_USER , -DRM_PANIC_TYPE_QR , -}; -static enum drm_panic_type drm_panic_type =-1 ;static const char *drm_panic_type_map[] = {@@ -940,9 +921,29 @@ static void drm_panic_clear_description(void) desc_line->txt =NULL ; } -static void draw_panic_plane (struct drm_plane *plane,const char *description, -enum drm_panic_type panic_type,u32 fg_color,u32 bg_color, -unsigned int qr_version) +/** +* drm_plane_helper_display_panic_screen - Displays a panic screen according to the given settings +* @plane: the DRM plane to display to +* @description: error message to display +* @panic_type: type of panic screen +* @fg_color: text foreground color +* @bg_color: text background color +* @qr_version: version of the QR code, if any +* +* This helper display a panic screen on common primary planes. The panic +* screen can either display a kernel message, a user message or a QR code. +* +* The helper uses struct drm_plane_helper_funcs.get_scanout_buffer, where +* the plane can provide a scanout buffer that the panic handler can draw to. +* Currently only linear buffer and a few color formats are supported. +* +* Optionally the plane can also provide a &drm_plane_helper_funcs.panic_flush +* callback, which the DRM panic handler calls after drawing to send additional +* commands to the hardware to make the scanout buffer visible. +*/ +void drm_plane_helper_display_panic_screen (struct drm_plane *plane,const char *description, +enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color,unsigned int qr_version) {struct drm_scanout_buffer sb = { };int ret;@@ -970,6 +971,7 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description,drm_panic_clear_description (); } +EXPORT_SYMBOL (drm_plane_helper_display_panic_screen);static void drm_panic_display_panic_screen (struct drm_plane *plane,const char *description) {@@ -992,8 +994,8 @@ static void drm_panic_display_panic_screen(struct drm_plane *plane, const char *unsigned long flags;if (drm_panic_trylock (dev, flags)) { -draw_panic_plane (plane, description, drm_panic_type, - fg_color, bg_color, qr_version); + plane->funcs->display_panic_screen (plane, description, drm_panic_type, + fg_color, bg_color, qr_version);drm_panic_unlock (dev, flags); } }@@ -1064,7 +1066,7 @@ bool drm_panic_is_enabled(struct drm_device *dev)return false;drm_for_each_plane (plane, dev) -if (plane->helper_private && plane->helper_private->get_scanout_buffer) +if (plane->funcs && plane->funcs->display_panic_screen)return true;return false; }@@ -1083,7 +1085,7 @@ void drm_panic_register(struct drm_device *dev)return ;drm_for_each_plane (plane, dev) { -if (!plane->helper_private || !plane->helper_private->get_scanout_buffer) +if (!plane->funcs || !plane->funcs->display_panic_screen)continue ; plane->kmsg_panic.dump = drm_panic; plane->kmsg_panic.max_reason =KMSG_DUMP_PANIC ;@@ -1110,7 +1112,7 @@ void drm_panic_unregister(struct drm_device *dev)return ;drm_for_each_plane (plane, dev) { -if (!plane->helper_private || !plane->helper_private->get_scanout_buffer) +if (!plane->funcs || !plane->funcs->display_panic_screen)continue ;kmsg_dump_unregister (&plane->kmsg_panic); }drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +2
-0@@ -18,6 +18,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_probe_helper.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane.h> #include <drm/drm_print.h> #include <drm/drm_vblank.h> @@ -237,6 +238,7 @@ static const struct drm_plane_funcs hv_drm_plane_funcs = { .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup,DRM_GEM_SHADOW_PLANE_FUNCS , + DRM_PANIC_PLANE_FUNCS, }; static const struct drm_encoder_funcs hv_drm_simple_encoder_funcs_cleanup = {drivers/gpu/drm/i915/display/i9xx_plane.c +3
-0@@ -8,6 +8,7 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_blend.h> #include <drm/drm_fourcc.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include "i9xx_plane.h" @@ -887,6 +888,7 @@ static const struct drm_plane_funcs i965_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = i965_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static const struct drm_plane_funcs i8xx_plane_funcs = {@@ -897,6 +899,7 @@ static const struct drm_plane_funcs i8xx_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = i8xx_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static void i9xx_disable_tiling (struct intel_plane *plane)drivers/gpu/drm/i915/display/skl_universal_plane.c +4
-0@@ -7,6 +7,7 @@#include <drm/drm_blend.h> #include <drm/drm_damage_helper.h> #include <drm/drm_fourcc.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <drm/intel/step.h> @@ -2707,6 +2708,7 @@ static const struct drm_plane_funcs skl_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = skl_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static const struct drm_plane_funcs icl_plane_funcs = {@@ -2717,6 +2719,7 @@ static const struct drm_plane_funcs icl_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = icl_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, };static const struct drm_plane_funcs tgl_plane_funcs = {@@ -2727,6 +2730,7 @@ static const struct drm_plane_funcs tgl_plane_funcs = { .atomic_destroy_state = intel_plane_destroy_state, .format_mod_supported = tgl_plane_format_mod_supported, .format_mod_supported_async = intel_plane_format_mod_supported_async, + DRM_PANIC_PLANE_FUNCS, }; static voiddrivers/gpu/drm/imx/ipuv3/ipuv3-plane.c +2
-0@@ -14,6 +14,7 @@#include <drm/drm_gem_atomic_helper.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <video/imx-ipu-v3.h> @@ -362,6 +363,7 @@ static const struct drm_plane_funcs ipu_plane_funcs = { .atomic_duplicate_state = ipu_plane_duplicate_state, .atomic_destroy_state = ipu_plane_destroy_state, .format_mod_supported = ipu_plane_format_mod_supported, + DRM_PANIC_PLANE_FUNCS, }; static int ipu_plane_atomic_check(struct drm_plane *plane,drivers/gpu/drm/mgag200/mgag200_drv.h +3
-1@@ -17,6 +17,7 @@#include <drm/drm_encoder.h> #include <drm/drm_gem.h> #include <drm/drm_gem_shmem_helper.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane.h> #include "mgag200_reg.h" @@ -386,7 +387,8 @@ int mgag200_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane, .update_plane = drm_atomic_helper_update_plane, \ .disable_plane = drm_atomic_helper_disable_plane, \ .destroy = drm_plane_cleanup, \ - DRM_GEM_SHADOW_PLANE_FUNCS +DRM_GEM_SHADOW_PLANE_FUNCS , \ + DRM_PANIC_PLANE_FUNCSvoid mgag200_crtc_fill_gamma (struct mga_device *mdev,const struct drm_format_info *format); void mgag200_crtc_load_gamma(struct mga_device *mdev,drivers/gpu/drm/nouveau/dispnv50/wndw.c +2
-0@@ -39,6 +39,7 @@#include <drm/drm_framebuffer.h> #include <drm/drm_gem_atomic_helper.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/ttm/ttm_bo.h> #include "nouveau_bo.h" @@ -841,6 +842,7 @@ nv50_wndw = { .atomic_duplicate_state = nv50_wndw_atomic_duplicate_state, .atomic_destroy_state = nv50_wndw_atomic_destroy_state, .format_mod_supported = nv50_plane_format_mod_supported, + DRM_PANIC_PLANE_FUNCS, };static const u64 nv50_cursor_format_modifiers[] = {drivers/gpu/drm/renesas/rcar-du/rcar_du_plane.c +2
-0@@ -16,6 +16,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> +#include <drm/drm_panic_helper.h> #include "rcar_du_drv.h" #include "rcar_du_group.h" @@ -773,6 +774,7 @@ static const struct drm_plane_funcs rcar_du_plane_funcs = { .atomic_destroy_state = rcar_du_plane_atomic_destroy_state, .atomic_set_property = rcar_du_plane_atomic_set_property, .atomic_get_property = rcar_du_plane_atomic_get_property, + DRM_PANIC_PLANE_FUNCS, };static const uint32_t formats[] = {drivers/gpu/drm/renesas/shmobile/shmob_drm_plane.c +2
-0@@ -14,6 +14,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> +#include <drm/drm_panic_helper.h> #include "shmob_drm_drv.h" #include "shmob_drm_kms.h" @@ -286,6 +287,7 @@ static const struct drm_plane_funcs shmob_drm_plane_funcs = { .reset = shmob_drm_plane_reset, .atomic_duplicate_state = shmob_drm_plane_atomic_duplicate_state, .atomic_destroy_state = shmob_drm_plane_atomic_destroy_state, + DRM_PANIC_PLANE_FUNCS, };static const uint32_t formats[] = {drivers/gpu/drm/sysfb/drm_sysfb_helper.h +3
-1@@ -12,6 +12,7 @@#include <drm/drm_device.h> #include <drm/drm_gem_atomic_helper.h> #include <drm/drm_modes.h> +#include <drm/drm_panic_helper.h> struct drm_format_info ;struct drm_scanout_buffer ;@@ -144,7 +145,8 @@ void drm_sysfb_plane_atomic_destroy_state(struct drm_plane *plane, .update_plane = drm_atomic_helper_update_plane, \ .disable_plane = drm_atomic_helper_disable_plane, \ .atomic_duplicate_state = drm_sysfb_plane_atomic_duplicate_state, \ - .atomic_destroy_state = drm_sysfb_plane_atomic_destroy_state + .atomic_destroy_state = drm_sysfb_plane_atomic_destroy_state, \ +DRM_PANIC_PLANE_FUNCS /* * CRTC drivers/gpu/drm/sysfb/vesadrm.c +1
-0@@ -24,6 +24,7 @@#include <drm/drm_managed.h> #include <drm/drm_modeset_helper.h> #include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h> drivers/gpu/drm/tidss/tidss_plane.c +2
-0@@ -12,6 +12,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> #include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_panic_helper.h> #include "tidss_crtc.h" #include "tidss_dispc.h" @@ -182,6 +183,7 @@ static const struct drm_plane_funcs tidss_plane_funcs = { .atomic_create_state = drm_atomic_helper_plane_create_state, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + DRM_PANIC_PLANE_FUNCS, }; struct tidss_plane *tidss_plane_create(struct tidss_device *tidss,drivers/gpu/drm/tiny/bochs.c +3
-1@@ -20,6 +20,7 @@#include <drm/drm_managed.h> #include <drm/drm_module.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_plane_helper.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h> @@ -501,7 +502,8 @@ static const struct drm_plane_funcs bochs_primary_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup, - DRM_GEM_SHADOW_PLANE_FUNCS +DRM_GEM_SHADOW_PLANE_FUNCS , + DRM_PANIC_PLANE_FUNCS, };static void bochs_crtc_helper_mode_set_nofb (struct drm_crtc *crtc)drivers/gpu/drm/virtio/virtgpu_plane.c +2
-0@@ -30,6 +30,7 @@#include <linux/virtio_dma_buf.h> #include <drm/drm_managed.h> #include <drm/drm_panic.h> +#include <drm/drm_panic_helper.h> #include <drm/drm_print.h> #include "virtgpu_drv.h" @@ -94,6 +95,7 @@ static const struct drm_plane_funcs virtio_gpu_plane_funcs = { .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = virtio_gpu_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + DRM_PANIC_PLANE_FUNCS, }; static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,include/drm/drm_mode_config.h +2
-2@@ -495,8 +495,8 @@ struct drm_mode_config {* * Raw spinlock used to protect critical sections of code that access * the display hardware or modeset software state, which the panic -* printing code must be protected against. See drm_panic_trylock(), -* drm_panic_lock() and drm_panic_unlock(). +* printing code must be protected against. See the documentation on +* DRM panic handling for more information. */ struct raw_spinlock panic_lock;include/drm/drm_modeset_helper_vtables.h +7
-4@@ -1442,17 +1442,20 @@ struct drm_plane_helper_funcs {/** * @get_scanout_buffer: * -* Get the current scanout buffer, to display a message with drm_panic. +* Get the current scanout buffer to display a message with drm_panic. * The driver should do the minimum changes to provide a buffer, * that can be used to display the panic screen. Currently only linear * buffers are supported. Non-linear buffer support is on the TODO list. * The device &dev.mode_config.panic_lock is taken before calling this * function, so you can safely access the &plane.state * It is called from a panic callback, and must follow its restrictions. -* Please look the documentation at drm_panic_trylock() for an in-depth +* Please look the documentation on DRM panic handling for an in-depth * discussions of what's safe and what is not allowed. +* * It's a best effort mode, so it's expected that in some complex cases -* the panic screen won't be displayed. +* the panic screen won't be displayed. Drivers must not make any +* assumptions about the actual state of the hardware. +* * The returned &drm_scanout_buffer.map must be valid if no error code is * returned. * @@ -1472,7 +1475,7 @@ struct drm_plane_helper_funcs {* It is only called if get_scanout_buffer() returned successfully, and * the &dev.mode_config.panic_lock is held during the entire sequence. * It is called from a panic callback, and must follow its restrictions. -* Please look the documentation at drm_panic_trylock() for an in-depth +* Please look the documentation on DRM panic handling for an in-depth * discussions of what's safe and what is not allowed. */ void (*panic_flush)(struct drm_plane *plane);include/drm/drm_panic.h +10
-39@@ -15,6 +15,14 @@#include <drm/drm_device.h> #include <drm/drm_fourcc.h> +struct page ; + +enum drm_panic_type { +DRM_PANIC_TYPE_KMSG , +DRM_PANIC_TYPE_USER , +DRM_PANIC_TYPE_QR , +}; +/** * struct drm_scanout_buffer - DRM scanout buffer * @@ -87,45 +95,8 @@ struct drm_scanout_buffer {* @dev: struct drm_device * @flags: unsigned long irq flags you need to pass to the unlock() counterpart * -* This function must be called by any panic printing code. The panic printing -* attempt must be aborted if the trylock fails. -* -* Panic printing code can make the following assumptions while holding the -* panic lock: -* -* - Anything protected by drm_panic_lock() and drm_panic_unlock() pairs is safe -* to access. -* -* - Furthermore the panic printing code only registers in drm_dev_unregister() -* and gets removed in drm_dev_unregister(). This allows the panic code to -* safely access any state which is invariant in between these two function -* calls, like the list of planes &drm_mode_config.plane_list or most of the -* struct drm_plane structure. -* -* Specifically thanks to the protection around plane updates in -* drm_atomic_helper_swap_state() the following additional guarantees hold: -* -* - It is safe to deference the drm_plane.state pointer. -* -* - Anything in struct drm_plane_state or the driver's subclass thereof which -* stays invariant after the atomic check code has finished is safe to access. -* Specifically this includes the reference counted pointers to framebuffer -* and buffer objects. -* -* - Anything set up by &drm_plane_helper_funcs.fb_prepare and cleaned up -* &drm_plane_helper_funcs.fb_cleanup is safe to access, as long as it stays -* invariant between these two calls. This also means that for drivers using -* dynamic buffer management the framebuffer is pinned, and therefer all -* relevant datastructures can be accessed without taking any further locks -* (which would be impossible in panic context anyway). -* -* - Importantly, software and hardware state set up by -* &drm_plane_helper_funcs.begin_fb_access and -* &drm_plane_helper_funcs.end_fb_access is not safe to access. -* -* Drivers must not make any assumptions about the actual state of the hardware, -* unless they explicitly protected these hardware access with drm_panic_lock() -* and drm_panic_unlock(). +* The panic-printing code calls this function. The panic printing attempt must +* be aborted if the trylock fails. * * Return: * %0 when failing to acquire the raw spinlock, nonzero on success. include/drm/drm_panic_helper.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 or MIT */ + +#ifndef __DRM_DRM_PANIC_HELPER_H_ +#define __DRM_DRM_PANIC_HELPER_H_ + +#include <linux/types.h> + +enum drm_panic_type ; + +struct drm_plane ; + +/* drm_panic_helper.c */ +void drm_plane_helper_display_panic_screen (struct drm_plane *plane, +const char *description, +enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color, +unsigned int qr_version); + +#if IS_ENABLED (CONFIG_DRM_PANIC ) +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = drm_plane_helper_display_panic_screen +#else +#define DRM_PANIC_PLANE_FUNCS \ + .display_panic_screen = NULL +#endif + +#endif include/drm/drm_plane.h +57
-0@@ -32,6 +32,8 @@#include <drm/drm_modeset_lock.h> #include <drm/drm_util.h> +enum drm_panic_type ; +struct drm_crtc ;struct drm_plane_size_hint ;struct drm_printer ;@@ -590,6 +592,61 @@ struct drm_plane_funcs {bool (*format_mod_supported_async)(struct drm_plane *plane,u32 format,u64 modifier); +/** +* @display_panic_screen: +* +* DRM panic handling invokes this callback on panics. +* +* It is a panic handler, so it can't take locks, allocate memory, run tasks/irq, +* or attempt to sleep. It's a best effort, and it may not be able to display +* the message in all situations (like if the panic occurs in the middle of a +* modesetting). +* +* Panic-printing code must acquire the panic lock before interacting with the +* scanout buffer. Such helpers can make the following assumptions while holding +* the panic lock: +* +* - Anything protected by drm_panic_lock() and drm_panic_unlock() pairs is safe +* to access. +* +* - Furthermore the panic printing code only registers in drm_dev_unregister() +* and gets removed in drm_dev_unregister(). This allows the panic code to +* safely access any state which is invariant in between these two function +* calls, like the list of planes &drm_mode_config.plane_list or most of the +* struct drm_plane structure. +* +* Specifically thanks to the protection around plane updates in +* drm_atomic_helper_swap_state() the following additional guarantees hold: +* +* - It is safe to deference the drm_plane.state pointer. +* +* - Anything in struct drm_plane_state or the driver's subclass thereof which +* stays invariant after the atomic check code has finished is safe to access. +* Specifically this includes the reference counted pointers to framebuffer +* and buffer objects. +* +* - Anything set up by &drm_plane_helper_funcs.fb_prepare and cleaned up +* &drm_plane_helper_funcs.fb_cleanup is safe to access, as long as it stays +* invariant between these two calls. This also means that for drivers using +* dynamic buffer management the framebuffer is pinned, and therefer all +* relevant datastructures can be accessed without taking any further locks +* (which would be impossible in panic context anyway). +* +* - Importantly, software and hardware state set up by +* &drm_plane_helper_funcs.begin_fb_access and +* &drm_plane_helper_funcs.end_fb_access is not safe to access. +* +* It will display only one static frame, so performance optimizations are +* low priority as the machine is already in an unusable state. +* +* This callback is optional. Planes without will not be considered +* for panic output. +*/ +void (*display_panic_screen)(struct drm_plane *plane, +const char *description, +enum drm_panic_type panic_type, +u32 fg_color,u32 bg_color, +unsigned int qr_version); };/**
Jocelyn Falempe
maintainerQuoted 33 lines · Thomas Zimmermann
Split DRM's current panic handling into a core and a helper module. The core is still part of DRM's core library. The panic helpers are part of DRM's KMS helper module (for now).
The motivation behind this series is to get panic handling's drawing code out of the DRM core. At some point it should share a single module with DRM's other drawing and format conversion.
With the series applied, panic hanlding follows DRM's established design pattern of having a DRM core interface with an dedicated implementation in each driver. Drivers share common code in helper modules. For panic handling, the DRM core still contains the panic entry points, the parameters and the debugfs interface. All drawing is now located in the panic helpers.
Patches 1 to 4 improve several issues in the current panic code. It makes sense to fix them before moving the core around.
Patches 5 to 8 put handling of all panic state and locking into a single place,
drm_panic_display_panic_screen(). It is maintained by panic handling's DRM core code. This also enables the test cases to work more independently from the kernel's configuration.Patches 9 to 11 split the panic-handling code into the core and panic helpers. The former maintain all state, locking and public interfaces. The latter handles drawing and details of the involved framebuffers.
DRM devices that offer panic handling provide a single callback, struct drm_plane_funcs.display_panic_screen. A new initializer macro makes it point to the existing panic-drawing implementation. Hence there's no change in features or functionality. If panic handling is configured off, it all clears out to NULL.
Quoted 4 lines
Patch 12 reworks the test cases slighly, so that they can be build as a separate module. Do 'modprobe
drm_panic_helper_test' to run them.Tested under bochs with debugfs and test cases.
Overall the series looks good to me, and I like the split between the helper and the core.
I would just drop the first two patches, as I don't see much difference between static allocation or kmalloc() at init, and I think that memset() the buffers to 0 is not useful in this case.
Best regards,
Signature · 1 line
Jocelyn
Quoted 79 lines
Future directions:
- Panic handling shares some drawing code with format conversion and clients. There's even more drawing code in vkms. Later series' can attempt to unify and harmonize all these implementations in a single draw module.
- The drawing helper
drm_plane_helper_display_panic_screen()still implements various access schemes (map,set_pixel, memcpy) in a single function. It could be split up into specifialized helpers.- If we ever need a driver-specific helper, it is now possible to implement a custom version of
display_panic_screen.Thomas Zimmermann (12):
drm/panic: Allocate QR-code buffers statically drm/panic: Make allocation of zlib workspace more robust drm/panic: Return-EINVALif font is not available drm/panic: Return errno codes if panic output fails drm/panic: Pass colors todraw_panic_dispatch()drm/panic: Pass global module parameters todrm_panic_dispatch()drm/panic: Retry in dispatch function if panic output fails drm/panic: Splitdraw_panic_plane()
drm/panic: Display panic screen via per-plane callback drm/panic: Internalize panic locking in DRM core and helpers drm/panic: Move panic display code into helper library drm/panic: Compile KUnit tests as moduleDocumentation/gpu/drm-kms-helpers.rst | 11 +- Documentation/gpu/drm-kms.rst | 3 + MAINTAINERS | 11 +- drivers/gpu/drm/Kconfig | 5 + drivers/gpu/drm/Kconfig.debug | 1 + drivers/gpu/drm/Makefile | 3 +- .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 2 + drivers/gpu/drm/ast/ast_mode.c | 2 + drivers/gpu/drm/drm_atomic_helper.c | 2 +- drivers/gpu/drm/drm_crtc_internal.h | 2 - drivers/gpu/drm/drm_drv.c | 3 +- drivers/gpu/drm/drm_kms_helper_common.c | 14 + drivers/gpu/drm/drm_panic.c | 914 +---------------- drivers/gpu/drm/drm_panic_helper.c | 915 ++++++++++++++++++ ...drm_panic_qr.rs => drm_panic_helper_qr.rs} | 4 +- drivers/gpu/drm/drm_panic_internal.h | 59 ++ drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 2 + drivers/gpu/drm/i915/display/i9xx_plane.c | 3 + .../drm/i915/display/skl_universal_plane.c | 4 + drivers/gpu/drm/imx/ipuv3/ipuv3-plane.c | 2 + drivers/gpu/drm/mgag200/mgag200_drv.h | 4 +- drivers/gpu/drm/nouveau/dispnv50/wndw.c | 2 + .../gpu/drm/renesas/rcar-du/rcar_du_plane.c | 2 + .../drm/renesas/shmobile/shmob_drm_plane.c | 2 + drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 4 +- drivers/gpu/drm/sysfb/vesadrm.c | 1 + drivers/gpu/drm/tests/Makefile | 1 + ...m_panic_test.c => drm_panic_helper_test.c} | 65 +- drivers/gpu/drm/tidss/tidss_plane.c | 2 + drivers/gpu/drm/tiny/bochs.c | 4 +- drivers/gpu/drm/virtio/virtgpu_plane.c | 2 + include/drm/drm_mode_config.h | 4 +- include/drm/drm_modeset_helper_vtables.h | 11 +- include/drm/drm_panic.h | 117 +-- include/drm/drm_panic_helper.h | 40 + include/drm/drm_plane.h | 57 ++ rust/bindings/bindings_helper.h | 4 +- 37 files changed, 1253 insertions(+), 1031 deletions(-)create mode 100644
drivers/gpu/drm/drm_panic_helper.c
renamedrivers/gpu/drm/{drm_panic_qr.rs=>drm_panic_helper_qr.rs} (99%) create mode 100644drivers/gpu/drm/drm_panic_internal.h
renamedrivers/gpu/drm/tests/{drm_panic_test.c=>drm_panic_helper_test.c} (80%) create mode 100644include/drm/drm_panic_helper.hbase-commit:
dc462ab791b686c48545c160ecc81be64f77a846
prerequisite-patch-id:c67e5d886a47b7d0266d81100837557fda34cb24
prerequisite-patch-id:a5a973e527c88a5b47053d7a72aefe0b550197cb
prerequisite-patch-id:b9adc9622920a3e70168e672c2c92795b3e3a106
prerequisite-patch-id:5030de433a01c2e99056cadb676a8e2ba35f055a
Thomas Zimmermann
maintainerHi Jocelyn
Am 20.08.26 um 19:49 schrieb Jocelyn Falempe:
Quoted 34 lines · Thomas Zimmermann
Quoted 33 lines
Split DRM's current panic handling into a core and a helper module. The core is still part of DRM's core library. The panic helpers are part of DRM's KMS helper module (for now).
The motivation behind this series is to get panic handling's drawing code out of the DRM core. At some point it should share a single module with DRM's other drawing and format conversion.
With the series applied, panic hanlding follows DRM's established design pattern of having a DRM core interface with an dedicated implementation in each driver. Drivers share common code in helper modules. For panic handling, the DRM core still contains the panic entry points, the parameters and the debugfs interface. All drawing is now located in the panic helpers.
Patches 1 to 4 improve several issues in the current panic code. It makes sense to fix them before moving the core around.
Patches 5 to 8 put handling of all panic state and locking into a single place,
drm_panic_display_panic_screen(). It is maintained by panic handling's DRM core code. This also enables the test cases to work more independently from the kernel's configuration.Patches 9 to 11 split the panic-handling code into the core and panic helpers. The former maintain all state, locking and public interfaces. The latter handles drawing and details of the involved framebuffers.
DRM devices that offer panic handling provide a single callback, struct drm_plane_funcs.display_panic_screen. A new initializer macro makes it point to the existing panic-drawing implementation. Hence there's no change in features or functionality. If panic handling is configured off, it all clears out to NULL.
Quoted 7 lines
Quoted 4 lines
Patch 12 reworks the test cases slighly, so that they can be build as a separate module. Do 'modprobe
drm_panic_helper_test' to run them.Tested under bochs with debugfs and test cases.
Overall the series looks good to me, and I like the split between the helper and the core.
I would just drop the first two patches, as I don't see much difference between static allocation orkmalloc()at init, and I think thatmemset()the buffers to 0 is not useful in this case.
Ok. Geert also expressed a dislike for these changes.
I have a number of changes done from the Sashiko review and will post an update to the series early next week.
Thanks for reviewing.
Best regards
Thomas
Quoted 3 lines
Best regards,
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)