Skip to contentSkip to conversation

drm/panic: Add a QR code panic screen

PATCH In review Jocelyn Falempe 2 participants 11 messages Aug 22, 2024 – Aug 23, 2024

Subsystems (4)
lore
Share & tools
lore

Jocelyn Falempe

author maintainer
#0 lore raw

v7 cover drm/panic: Add a QR code panic screen

This series adds a new panic screen, with the kmsg data embedded in a QR code.

The main advantage of QR code, is that you can copy/paste the debug data to a bug report.

The QR code encoder is written in rust, and is very specific to drm panic.
The reason is that it is called in a panic handler, and thus can't allocate memory, or use locking. The rust code uses a few rust core API, and provides only two C entry points.
There is no particular reason to do it in rust, I just wanted to learn rust, and see if it can work in the kernel.

If you want to see what it looks like, I've put a few screenshots here:
https://github.com/kdj0c/panic_report/issues/1

v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Mark drm_panic_qr_generate() as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call to as_str_unchecked() (Alice Ryhl)
* Add a check for data_len <= data_size (Greg KH)

v3:
* Fix all rust comments (typo, punctuation) (Miguel Ojeda)
* Change the wording of safety comments (Alice Ryhl)
* Add a link to the javascript decoder in the Kconfig (Greg KH)
* Fix data_size and tmp_size check in drm_panic_qr_generate()

v4:
* Fix the logic to find next line and skip the '\n' (Alic Ryhl)
* Remove __LOG_PREFIX as it's not used (Alice Ryhl)

v5:
* Move drm_panic_[init|exit]() prototype to drm_crtc_internal.h (Daniel Vetter)

v6:
* rebase, and handle conflict with 5d45c01dea6f ("drm/panic: Add panic description")
* Fix qr_width should be a signed int, to handle error code.

v7:
* rename r1/r2 to a/b in drm_rect_overlap() (Jani Nikula)

Jocelyn Falempe (4):
drm/panic: Add integer scaling to blit()
drm/rect: Add drm_rect_overlap()
drm/panic: Simplify logo handling
drm/panic: Add a QR code panic screen

 drivers/gpu/drm/Kconfig             |   31 +
 drivers/gpu/drm/Makefile            |    1 +
 drivers/gpu/drm/drm_crtc_internal.h |    4 +
 drivers/gpu/drm/drm_drv.c           |    3 +
 drivers/gpu/drm/drm_panic.c         |  340 +++++++--
 drivers/gpu/drm/drm_panic_qr.rs     | 1003 +++++++++++++++++++++++++++
 include/drm/drm_rect.h              |   15 +
 7 files changed, 1357 insertions(+), 40 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_panic_qr.rs

base-commit: 04b5b362bc2a36f1dfe5cad52c83b1ea9d25b87c

Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH v7 1/4 drm/panic: Add integer scaling to blit()

Add a parameter to the blit function, to upscale the image. This is necessary to draw a QR code, otherwise, the pixels are usually too small to be readable by most QR code reader. It can also be used later for drawing fonts on high DPI display.

---
 drivers/gpu/drm/drm_panic.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_panic.c +19 -14
index eff4598e2fc73..0a047152f88b8 100644
@@ -257,20 +257,20 @@ static bool drm_panic_is_pixel_fg(const u8 *sbuf8, unsigned int spitch, int x, i
 static void drm_panic_blit16(struct iosys_map *dmap, unsigned int dpitch,
 			     const u8 *sbuf8, unsigned int spitch,
 			     unsigned int height, unsigned int width,
-			     u16 fg16)
+			     unsigned int scale, u16 fg16)
 {
 	unsigned int y, x;
 
 	for (y = 0; y < height; y++)
 		for (x = 0; x < width; x++)
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y))
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
 				iosys_map_wr(dmap, y * dpitch + x * sizeof(u16), u16, fg16);
 }
 
 static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,
 			     const u8 *sbuf8, unsigned int spitch,
 			     unsigned int height, unsigned int width,
-			     u32 fg32)
+			     unsigned int scale, u32 fg32)
 {
 	unsigned int y, x;
 
@@ -278,7 +278,7 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,
 		for (x = 0; x < width; x++) {
 			u32 off = y * dpitch + x * 3;
 
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y)) {
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale)) {
 				/* write blue-green-red to output in little endianness */
 				iosys_map_wr(dmap, off, u8, (fg32 & 0x000000FF) >> 0);
 				iosys_map_wr(dmap, off + 1, u8, (fg32 & 0x0000FF00) >> 8);
@@ -291,24 +291,25 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,
 static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch,
 			     const u8 *sbuf8, unsigned int spitch,
 			     unsigned int height, unsigned int width,
-			     u32 fg32)
+			     unsigned int scale, u32 fg32)
 {
 	unsigned int y, x;
 
 	for (y = 0; y < height; y++)
 		for (x = 0; x < width; x++)
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y))
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
 				iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, fg32);
 }
 
 static void drm_panic_blit_pixel(struct drm_scanout_buffer *sb, struct drm_rect *clip,
-				 const u8 *sbuf8, unsigned int spitch, u32 fg_color)
+				 const u8 *sbuf8, unsigned int spitch, unsigned int scale,
+				 u32 fg_color)
 {
 	unsigned int y, x;
 
 	for (y = 0; y < drm_rect_height(clip); y++)
 		for (x = 0; x < drm_rect_width(clip); x++)
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y))
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
 				sb->set_pixel(sb, clip->x1 + x, clip->y1 + y, fg_color);
 }
 
@@ -318,18 +319,22 @@ static void drm_panic_blit_pixel(struct drm_scanout_buffer *sb, struct drm_rect
  * @clip: destination rectangle
  * @sbuf8: source buffer, in monochrome format, 8 pixels per byte.
  * @spitch: source pitch in bytes
+ * @scale: integer scale, source buffer is scale time smaller than destination
+ *         rectangle
  * @fg_color: foreground color, in destination format
  *
  * This can be used to draw a font character, which is a monochrome image, to a
  * framebuffer in other supported format.
  */
 static void drm_panic_blit(struct drm_scanout_buffer *sb, struct drm_rect *clip,
-			   const u8 *sbuf8, unsigned int spitch, u32 fg_color)
+			   const u8 *sbuf8, unsigned int spitch,
+			   unsigned int scale, u32 fg_color)
+
 {
 	struct iosys_map map;
 
 	if (sb->set_pixel)
-		return drm_panic_blit_pixel(sb, clip, sbuf8, spitch, fg_color);
+		return drm_panic_blit_pixel(sb, clip, sbuf8, spitch, scale, fg_color);
 
 	map = sb->map[0];
 	iosys_map_incr(&map, clip->y1 * sb->pitch[0] + clip->x1 * sb->format->cpp[0]);
@@ -337,15 +342,15 @@ static void drm_panic_blit(struct drm_scanout_buffer *sb, struct drm_rect *clip,
 	switch (sb->format->cpp[0]) {
 	case 2:
 		drm_panic_blit16(&map, sb->pitch[0], sbuf8, spitch,
-				 drm_rect_height(clip), drm_rect_width(clip), fg_color);
+				 drm_rect_height(clip), drm_rect_width(clip), scale, fg_color);
 	break;
 	case 3:
 		drm_panic_blit24(&map, sb->pitch[0], sbuf8, spitch,
-				 drm_rect_height(clip), drm_rect_width(clip), fg_color);
+				 drm_rect_height(clip), drm_rect_width(clip), scale, fg_color);
 	break;
 	case 4:
 		drm_panic_blit32(&map, sb->pitch[0], sbuf8, spitch,
-				 drm_rect_height(clip), drm_rect_width(clip), fg_color);
+				 drm_rect_height(clip), drm_rect_width(clip), scale, fg_color);
 	break;
 	default:
 		WARN_ONCE(1, "Can't blit with pixel width %d\n", sb->format->cpp[0]);
@@ -485,7 +490,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,
 		for (j = 0; j < line_len; j++) {
 			src = get_char_bitmap(font, msg[i].txt[j], font_pitch);
 			rec.x2 = rec.x1 + font->width;
-			drm_panic_blit(sb, &rec, src, font_pitch, color);
+			drm_panic_blit(sb, &rec, src, font_pitch, 1, color);
 			rec.x1 += font->width;
 		}
 	}
Signature · 1 line
2.46.0
maintainer Reviewed-by on v7 1/4
#2 lore raw

Re: [PATCH v7 1/4] drm/panic: Add integer scaling to blit()

Am 22.08.24 um 09:33 schrieb Jocelyn Falempe:

Quoted 6 lines

Add a parameter to the blit function, to upscale the image. This is necessary to draw a QR code, otherwise, the pixels are usually too small to be readable by most QR code reader. It can also be used later for drawing fonts on high DPI display.

Quoted 124 lines
---
  drivers/gpu/drm/drm_panic.c | 33 +++++++++++++++++++--------------
  1 file changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_panic.c +19 -14
index eff4598e2fc73..0a047152f88b8 100644
@@ -257,20 +257,20 @@ static bool drm_panic_is_pixel_fg(const u8 *sbuf8, unsigned int spitch, int x, i
  static void drm_panic_blit16(struct iosys_map *dmap, unsigned int dpitch,
  			     const u8 *sbuf8, unsigned int spitch,
  			     unsigned int height, unsigned int width,
-			     u16 fg16)
+			     unsigned int scale, u16 fg16)
  {
  	unsigned int y, x;
 
  	for (y = 0; y < height; y++)
  		for (x = 0; x < width; x++)
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y))
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
  				iosys_map_wr(dmap, y * dpitch + x * sizeof(u16), u16, fg16);
  }
 
  static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,
  			     const u8 *sbuf8, unsigned int spitch,
  			     unsigned int height, unsigned int width,
-			     u32 fg32)
+			     unsigned int scale, u32 fg32)
  {
  	unsigned int y, x;
 
@@ -278,7 +278,7 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,
  		for (x = 0; x < width; x++) {
  			u32 off = y * dpitch + x * 3;
 
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y)) {
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale)) {
  				/* write blue-green-red to output in little endianness */
  				iosys_map_wr(dmap, off, u8, (fg32 & 0x000000FF) >> 0);
  				iosys_map_wr(dmap, off + 1, u8, (fg32 & 0x0000FF00) >> 8);
@@ -291,24 +291,25 @@ static void drm_panic_blit24(struct iosys_map *dmap, unsigned int dpitch,
  static void drm_panic_blit32(struct iosys_map *dmap, unsigned int dpitch,
  			     const u8 *sbuf8, unsigned int spitch,
  			     unsigned int height, unsigned int width,
-			     u32 fg32)
+			     unsigned int scale, u32 fg32)
  {
  	unsigned int y, x;
 
  	for (y = 0; y < height; y++)
  		for (x = 0; x < width; x++)
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y))
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
  				iosys_map_wr(dmap, y * dpitch + x * sizeof(u32), u32, fg32);
  }
 
  static void drm_panic_blit_pixel(struct drm_scanout_buffer *sb, struct drm_rect *clip,
-				 const u8 *sbuf8, unsigned int spitch, u32 fg_color)
+				 const u8 *sbuf8, unsigned int spitch, unsigned int scale,
+				 u32 fg_color)
  {
  	unsigned int y, x;
 
  	for (y = 0; y < drm_rect_height(clip); y++)
  		for (x = 0; x < drm_rect_width(clip); x++)
-			if (drm_panic_is_pixel_fg(sbuf8, spitch, x, y))
+			if (drm_panic_is_pixel_fg(sbuf8, spitch, x / scale, y / scale))
  				sb->set_pixel(sb, clip->x1 + x, clip->y1 + y, fg_color);
  }
 
@@ -318,18 +319,22 @@ static void drm_panic_blit_pixel(struct drm_scanout_buffer *sb, struct drm_rect
   * @clip: destination rectangle
   * @sbuf8: source buffer, in monochrome format, 8 pixels per byte.
   * @spitch: source pitch in bytes
+ * @scale: integer scale, source buffer is scale time smaller than destination
+ *         rectangle
   * @fg_color: foreground color, in destination format
   *
   * This can be used to draw a font character, which is a monochrome image, to a
   * framebuffer in other supported format.
   */
  static void drm_panic_blit(struct drm_scanout_buffer *sb, struct drm_rect *clip,
-			   const u8 *sbuf8, unsigned int spitch, u32 fg_color)
+			   const u8 *sbuf8, unsigned int spitch,
+			   unsigned int scale, u32 fg_color)
+
  {
  	struct iosys_map map;
 
  	if (sb->set_pixel)
-		return drm_panic_blit_pixel(sb, clip, sbuf8, spitch, fg_color);
+		return drm_panic_blit_pixel(sb, clip, sbuf8, spitch, scale, fg_color);
 
  	map = sb->map[0];
  	iosys_map_incr(&map, clip->y1 * sb->pitch[0] + clip->x1 * sb->format->cpp[0]);
@@ -337,15 +342,15 @@ static void drm_panic_blit(struct drm_scanout_buffer *sb, struct drm_rect *clip,
  	switch (sb->format->cpp[0]) {
  	case 2:
  		drm_panic_blit16(&map, sb->pitch[0], sbuf8, spitch,
-				 drm_rect_height(clip), drm_rect_width(clip), fg_color);
+				 drm_rect_height(clip), drm_rect_width(clip), scale, fg_color);
  	break;
  	case 3:
  		drm_panic_blit24(&map, sb->pitch[0], sbuf8, spitch,
-				 drm_rect_height(clip), drm_rect_width(clip), fg_color);
+				 drm_rect_height(clip), drm_rect_width(clip), scale, fg_color);
  	break;
  	case 4:
  		drm_panic_blit32(&map, sb->pitch[0], sbuf8, spitch,
-				 drm_rect_height(clip), drm_rect_width(clip), fg_color);
+				 drm_rect_height(clip), drm_rect_width(clip), scale, fg_color);
  	break;
  	default:
  		WARN_ONCE(1, "Can't blit with pixel width %d\n", sb->format->cpp[0]);
@@ -485,7 +490,7 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,
  		for (j = 0; j < line_len; j++) {
  			src = get_char_bitmap(font, msg[i].txt[j], font_pitch);
  			rec.x2 = rec.x1 + font->width;
-			drm_panic_blit(sb, &rec, src, font_pitch, color);
+			drm_panic_blit(sb, &rec, src, font_pitch, 1, color);
  			rec.x1 += font->width;
  		}
  	}
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#3 lore raw

PATCH v7 2/4 drm/rect: Add drm_rect_overlap()

In reply to Jocelyn Falempe

Check if two rectangles overlap.
It's a bit similar to drm_rect_intersect() but this won't modify the rectangle.
Simplifies a bit drm_panic.

---

v7:
* rename r1/r2 to a/b in drm_rect_overlap() (Jani Nikula)

 drivers/gpu/drm/drm_panic.c |  3 +--
 include/drm/drm_rect.h      | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic.c +1 -2
index 0a047152f88b8..59fba23e5fd7a 100644
@@ -529,8 +529,7 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)
 	/* Fill with the background color, and draw text on top */
 	drm_panic_fill(sb, &r_screen, bg_color);
 
-	if ((r_msg.x1 >= logo_width || r_msg.y1 >= logo_height) &&
-	    logo_width <= sb->width && logo_height <= sb->height) {
+	if (!drm_rect_overlap(&r_logo, &r_msg)) {
 		if (logo_mono)
 			drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8),
 				       fg_color);
include/drm/drm_rect.h +15 -0
index 73fcb899a01da..46f09cf68458c 100644
@@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct drm_rect *dst,
 		      drm_rect_height(src) >> 16);
 }
 
+/**
+ * drm_rect_overlap - Check if two rectangles overlap
+ * @a: first rectangle
+ * @b: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *a,
+				    const struct drm_rect *b)
+{
+	return (a->x2 > b->x1 && b->x2 > a->x1 &&
+		a->y2 > b->y1 && b->y2 > a->y1);
+}
+
 bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
 bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
 			  const struct drm_rect *clip);
Signature · 1 line
2.46.0
maintainer Reviewed-by on v7 2/4
#4 lore raw

Re: [PATCH v7 2/4] drm/rect: Add drm_rect_overlap()

Am 22.08.24 um 09:33 schrieb Jocelyn Falempe:

Quoted 6 lines

Check if two rectangles overlap.
It's a bit similar to drm_rect_intersect() but this won't modify the rectangle.
Simplifies a bit drm_panic.

There's an optional comment further below.

Quoted 34 lines

---

v7:
* rename r1/r2 to a/b in drm_rect_overlap() (Jani Nikula)

  drivers/gpu/drm/drm_panic.c |  3 +--
  include/drm/drm_rect.h      | 15 +++++++++++++++
  2 files changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic.c +1 -2
index 0a047152f88b8..59fba23e5fd7a 100644
@@ -529,8 +529,7 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)
  	/* Fill with the background color, and draw text on top */
  	drm_panic_fill(sb, &r_screen, bg_color);
 
-	if ((r_msg.x1 >= logo_width || r_msg.y1 >= logo_height) &&
-	    logo_width <= sb->width && logo_height <= sb->height) {
+	if (!drm_rect_overlap(&r_logo, &r_msg)) {
  		if (logo_mono)
  			drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8),
  				       fg_color);
include/drm/drm_rect.h +3 -0
index 73fcb899a01da..46f09cf68458c 100644
@@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct drm_rect *dst,
  		      drm_rect_height(src) >> 16);
  }
 
+/**
+ * drm_rect_overlap - Check if two rectangles overlap
+ * @a: first rectangle

include/drm/drm_rect.h static inline void drm_rect_fp_to_int(struct drm_rect *dst, · line 253

Quoted 10 lines
include/drm/drm_rect.h +10 -0
+ * @b: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *a,
+				    const struct drm_rect *b)
+{
+	return (a->x2 > b->x1 && b->x2 > a->x1 &&
+		a->y2 > b->y1 && b->y2 > a->y1);

I found this hard to understand. You may want to use the existing _intersect helper

bool overlap(a, b)
{
  struct drm_rect tmp = *a

  return intersect(tmp, b);
}

Up to you.

Best regards
Thomas

Quoted 5 lines
include/drm/drm_rect.h +2 -0
+}
+
  bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
  bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
  			  const struct drm_rect *clip);
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#5 lore raw

Re: [PATCH v7 2/4] drm/rect: Add drm_rect_overlap()

Quoted 61 lines · Thomas Zimmermann

Am 22.08.24 um 09:33 schrieb Jocelyn Falempe:

Quoted 6 lines

Check if two rectangles overlap.
It's a bit similar to drm_rect_intersect() but this won't modify the rectangle.
Simplifies a bit drm_panic.

There's an optional comment further below.

Quoted 34 lines

---

v7:
  * rename r1/r2 to a/b in drm_rect_overlap() (Jani Nikula)

  drivers/gpu/drm/drm_panic.c |  3 +-- include/drm/drm_rect.h      | 15 +++++++++++++++

  2 files changed, 16 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic.c +1 -2
index 0a047152f88b8..59fba23e5fd7a 100644
@@ -529,8 +529,7 @@ static void draw_panic_static_user(struct 
 drm_scanout_buffer *sb)
       /* Fill with the background color, and draw text on top */
       drm_panic_fill(sb, &r_screen, bg_color);
-    if ((r_msg.x1 >= logo_width || r_msg.y1 >= logo_height) &&
-        logo_width <= sb->width && logo_height <= sb->height) {
+    if (!drm_rect_overlap(&r_logo, &r_msg)) {
           if (logo_mono)
               drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8),
                          fg_color);
include/drm/drm_rect.h +3 -0
index 73fcb899a01da..46f09cf68458c 100644
@@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct 
 drm_rect *dst,
                 drm_rect_height(src) >> 16);
   }
+/**
+ * drm_rect_overlap - Check if two rectangles overlap
+ * @a: first rectangle

include/drm/drm_rect.h static inline void drm_rect_fp_to_int(struct · line 253

Quoted 10 lines
include/drm/drm_rect.h +10 -0
+ * @b: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *a,
+                    const struct drm_rect *b)
+{
+    return (a->x2 > b->x1 && b->x2 > a->x1 &&
+        a->y2 > b->y1 && b->y2 > a->y1);

I found this hard to understand. You may want to use the existing _intersect helper

Quoted 6 lines

bool overlap(a, b)
{
  struct drm_rect tmp = *a

  return intersect(tmp, b);
}

I considered this, but it creates an unused rect, and compute the intersection rectangle, which we are not interested in. Even if the compiler may optimize and throw all this away, I prefer the more straightforward version.

Thanks for the review,

Signature · 1 line
Jocelyn
Quoted 12 lines

Up to you.

Best regards
Thomas

Quoted 5 lines
include/drm/drm_rect.h +2 -0
+}
+
   bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
   bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
                 const struct drm_rect *clip);
author maintainer
#6 lore raw

PATCH v7 3/4 drm/panic: Simplify logo handling

In reply to Jocelyn Falempe

Move logo rectangle initialisation, and logo drawing in separate functions, so they can be re-used by different panic screens. It prepares the introduction of the QR code panic screen.

---

v6:
* rebase, and handle conflict with 5d45c01dea6f ("drm/panic: Add panic description")

 drivers/gpu/drm/drm_panic.c | 58 +++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_panic.c +33 -25
index 59fba23e5fd7a..473db5fafb617 100644
@@ -85,7 +85,7 @@ static struct drm_panic_line panic_msg[] = {
 	PANIC_LINE(""), /* will be replaced by the panic description */
 };
 
-#define PANIC_MSG_LINES ARRAY_SIZE(panic_msg)
+static const int panic_msg_lines = ARRAY_SIZE(panic_msg);
 
 static const struct drm_panic_line logo_ascii[] = {
 	PANIC_LINE("     .--.        _"),
@@ -97,7 +97,7 @@ static const struct drm_panic_line logo_ascii[] = {
 	PANIC_LINE(" \\___)=(___/"),
 };
 
-#define PANIC_LOGO_LINES ARRAY_SIZE(logo_ascii)
+static const int logo_ascii_lines = ARRAY_SIZE(logo_ascii);
 
 #if defined(CONFIG_LOGO) && !defined(MODULE)
 static const struct linux_logo *logo_mono;
@@ -496,31 +496,44 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,
 	}
 }
 
+static void drm_panic_logo_rect(struct drm_rect *rect, const struct font_desc *font)
+{
+	if (logo_mono)
+		drm_rect_init(rect, 0, 0, logo_mono->width, logo_mono->height);
+	else {
+		int logo_width = get_max_line_len(logo_ascii, logo_ascii_lines) * font->width;
+
+		drm_rect_init(rect, 0, 0, logo_width, logo_ascii_lines * font->height);
+	}
+}
+
+static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct drm_rect *rect,
+				const struct font_desc *font, u32 fg_color)
+{
+	if (logo_mono)
+		drm_panic_blit(sb, rect, logo_mono->data,
+			       DIV_ROUND_UP(drm_rect_width(rect), 8), 1, fg_color);
+	else
+		draw_txt_rectangle(sb, font, logo_ascii, logo_ascii_lines, false, rect,
+				   fg_color);
+}
+
 static void draw_panic_static_user(struct drm_scanout_buffer *sb)
 {
 	u32 fg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_FOREGROUND_COLOR, sb->format->format);
 	u32 bg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_BACKGROUND_COLOR, sb->format->format);
 	const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL);
 	struct drm_rect r_screen, r_logo, r_msg;
-	unsigned int logo_width, logo_height;
 	unsigned int msg_width, msg_height;
 
 	if (!font)
 		return;
 
 	r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height);
+	drm_panic_logo_rect(&r_logo, font);
 
-	if (logo_mono) {
-		logo_width = logo_mono->width;
-		logo_height = logo_mono->height;
-	} else {
-		logo_width = get_max_line_len(logo_ascii, PANIC_LOGO_LINES) * font->width;
-		logo_height = PANIC_LOGO_LINES * font->height;
-	}
-	r_logo = DRM_RECT_INIT(0, 0, logo_width, logo_height);
-
-	msg_width = min(get_max_line_len(panic_msg, PANIC_MSG_LINES) * font->width, sb->width);
-	msg_height = min(PANIC_MSG_LINES * font->height, sb->height);
+	msg_width = min(get_max_line_len(panic_msg, panic_msg_lines) * font->width, sb->width);
+	msg_height = min(panic_msg_lines * font->height, sb->height);
 	r_msg = DRM_RECT_INIT(0, 0, msg_width, msg_height);
 
 	/* Center the panic message */
@@ -529,15 +542,10 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)
 	/* Fill with the background color, and draw text on top */
 	drm_panic_fill(sb, &r_screen, bg_color);
 
-	if (!drm_rect_overlap(&r_logo, &r_msg)) {
-		if (logo_mono)
-			drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8),
-				       fg_color);
-		else
-			draw_txt_rectangle(sb, font, logo_ascii, PANIC_LOGO_LINES, false, &r_logo,
-					   fg_color);
-	}
-	draw_txt_rectangle(sb, font, panic_msg, PANIC_MSG_LINES, true, &r_msg, fg_color);
+	if (!drm_rect_overlap(&r_logo, &r_msg))
+		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);
 }
 
 /*
@@ -647,7 +655,7 @@ static void drm_panic_set_description(const char *description)
 	u32 len;
 
 	if (description) {
-		struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES - 1];
+		struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines - 1];
 
 		desc_line->txt = description;
 		len = strlen(description);
@@ -660,7 +668,7 @@ static void drm_panic_set_description(const char *description)
 
 static void drm_panic_clear_description(void)
 {
-	struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES - 1];
+	struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines - 1];
 
 	desc_line->len = 0;
 	desc_line->txt = NULL;
Signature · 1 line
2.46.0
maintainer Reviewed-by on v7 3/4
#7 lore raw

Re: [PATCH v7 3/4] drm/panic: Simplify logo handling

Am 22.08.24 um 09:33 schrieb Jocelyn Falempe:

Quoted 5 lines

Move logo rectangle initialisation, and logo drawing in separate functions, so they can be re-used by different panic screens. It prepares the introduction of the QR code panic screen.

with the comments considered.

Quoted 13 lines

---

v6:
* rebase, and handle conflict with 5d45c01dea6f ("drm/panic: Add panic description")

  drivers/gpu/drm/drm_panic.c | 58 +++++++++++++++++++++----------------
  1 file changed, 33 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_panic.c +0 -0
index 59fba23e5fd7a..473db5fafb617 100644

drivers/gpu/drm/drm_panic.c static struct drm_panic_line panic_msg[] = { · line 88

Quoted 5 lines
drivers/gpu/drm/drm_panic.c +1 -1
@@ -85,7 +85,7 @@ static struct drm_panic_line panic_msg[] = {
  	PANIC_LINE(""), /* will be replaced by the panic description */
  };
 
-#define PANIC_MSG_LINES ARRAY_SIZE(panic_msg)
+static const int panic_msg_lines = ARRAY_SIZE(panic_msg);

This type should be size_t instead of int

drivers/gpu/drm/drm_panic.c static const struct drm_panic_line logo_ascii[] = { · line 100

Quoted 9 lines
drivers/gpu/drm/drm_panic.c +1 -1
  static const struct drm_panic_line logo_ascii[] = {
  	PANIC_LINE("     .--.        _"),
@@ -97,7 +97,7 @@ static const struct drm_panic_line logo_ascii[] = {
  	PANIC_LINE(" \\___)=(___/"),
  };
 
-#define PANIC_LOGO_LINES ARRAY_SIZE(logo_ascii)
+static const int logo_ascii_lines = ARRAY_SIZE(logo_ascii);

size_t

Quoted 98 lines
drivers/gpu/drm/drm_panic.c +31 -23
  #if defined(CONFIG_LOGO) && !defined(MODULE)
  static const struct linux_logo *logo_mono;
@@ -496,31 +496,44 @@ static void draw_txt_rectangle(struct drm_scanout_buffer *sb,
  	}
  }
 
+static void drm_panic_logo_rect(struct drm_rect *rect, const struct font_desc *font)
+{
+	if (logo_mono)
+		drm_rect_init(rect, 0, 0, logo_mono->width, logo_mono->height);
+	else {
+		int logo_width = get_max_line_len(logo_ascii, logo_ascii_lines) * font->width;
+
+		drm_rect_init(rect, 0, 0, logo_width, logo_ascii_lines * font->height);
+	}
+}
+
+static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct drm_rect *rect,
+				const struct font_desc *font, u32 fg_color)
+{
+	if (logo_mono)
+		drm_panic_blit(sb, rect, logo_mono->data,
+			       DIV_ROUND_UP(drm_rect_width(rect), 8), 1, fg_color);
+	else
+		draw_txt_rectangle(sb, font, logo_ascii, logo_ascii_lines, false, rect,
+				   fg_color);
+}
+
  static void draw_panic_static_user(struct drm_scanout_buffer *sb)
  {
  	u32 fg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_FOREGROUND_COLOR, sb->format->format);
  	u32 bg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_BACKGROUND_COLOR, sb->format->format);
  	const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL);
  	struct drm_rect r_screen, r_logo, r_msg;
-	unsigned int logo_width, logo_height;
  	unsigned int msg_width, msg_height;
 
  	if (!font)
  		return;
 
  	r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height);
+	drm_panic_logo_rect(&r_logo, font);
 
-	if (logo_mono) {
-		logo_width = logo_mono->width;
-		logo_height = logo_mono->height;
-	} else {
-		logo_width = get_max_line_len(logo_ascii, PANIC_LOGO_LINES) * font->width;
-		logo_height = PANIC_LOGO_LINES * font->height;
-	}
-	r_logo = DRM_RECT_INIT(0, 0, logo_width, logo_height);
-
-	msg_width = min(get_max_line_len(panic_msg, PANIC_MSG_LINES) * font->width, sb->width);
-	msg_height = min(PANIC_MSG_LINES * font->height, sb->height);
+	msg_width = min(get_max_line_len(panic_msg, panic_msg_lines) * font->width, sb->width);
+	msg_height = min(panic_msg_lines * font->height, sb->height);
  	r_msg = DRM_RECT_INIT(0, 0, msg_width, msg_height);
 
  	/* Center the panic message */
@@ -529,15 +542,10 @@ static void draw_panic_static_user(struct drm_scanout_buffer *sb)
  	/* Fill with the background color, and draw text on top */
  	drm_panic_fill(sb, &r_screen, bg_color);
 
-	if (!drm_rect_overlap(&r_logo, &r_msg)) {
-		if (logo_mono)
-			drm_panic_blit(sb, &r_logo, logo_mono->data, DIV_ROUND_UP(logo_width, 8),
-				       fg_color);
-		else
-			draw_txt_rectangle(sb, font, logo_ascii, PANIC_LOGO_LINES, false, &r_logo,
-					   fg_color);
-	}
-	draw_txt_rectangle(sb, font, panic_msg, PANIC_MSG_LINES, true, &r_msg, fg_color);
+	if (!drm_rect_overlap(&r_logo, &r_msg))
+		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);
  }
 
  /*
@@ -647,7 +655,7 @@ static void drm_panic_set_description(const char *description)
  	u32 len;
 
  	if (description) {
-		struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES - 1];
+		struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines - 1];
 
  		desc_line->txt = description;
  		len = strlen(description);
@@ -660,7 +668,7 @@ static void drm_panic_set_description(const char *description)
 
  static void drm_panic_clear_description(void)
  {
-	struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES - 1];
+	struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines - 1];
 
  	desc_line->len = 0;
  	desc_line->txt = NULL;
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#8 lore raw

Re: [PATCH v7 3/4] drm/panic: Simplify logo handling

Quoted 7 lines · Thomas Zimmermann

Am 22.08.24 um 09:33 schrieb Jocelyn Falempe:

Quoted 4 lines

Move logo rectangle initialisation, and logo drawing in separate functions, so they can be re-used by different panic screens. It prepares the introduction of the QR code panic screen.

Quoted 5 lines
Quoted 1 line

with the comments considered.

Sure, I will change the const int to const size_t before pushing.

Thanks

Signature · 1 line
Jocelyn
Quoted 136 lines
Quoted 16 lines

---

v6:
  * rebase, and handle conflict with 5d45c01dea6f ("drm/panic: Add panic description")

  drivers/gpu/drm/drm_panic.c | 58 +++++++++++++++++++++----------------

  1 file changed, 33 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_panic.c +0 -0
index 59fba23e5fd7a..473db5fafb617 100644
@@ -85,7 +85,7 @@ static struct drm_panic_line panic_msg[] = {

      PANIC_LINE(""), /* will be replaced by the panic description */ };

drivers/gpu/drm/drm_panic.c static struct drm_panic_line panic_msg[] = { · line 88

Quoted 2 lines
drivers/gpu/drm/drm_panic.c +1 -1
-#define PANIC_MSG_LINES ARRAY_SIZE(panic_msg)
+static const int panic_msg_lines = ARRAY_SIZE(panic_msg);

This type should be size_t instead of int

drivers/gpu/drm/drm_panic.c static const struct drm_panic_line logo_ascii[] = { · line 99

Quoted 7 lines

  static const struct drm_panic_line logo_ascii[] = { PANIC_LINE("     .--.        _"),

drivers/gpu/drm/drm_panic.c +1 -1
@@ -97,7 +97,7 @@ static const struct drm_panic_line logo_ascii[] = {
       PANIC_LINE(" \\___)=(___/"),
   };
-#define PANIC_LOGO_LINES ARRAY_SIZE(logo_ascii)
+static const int logo_ascii_lines = ARRAY_SIZE(logo_ascii);

size_t

Quoted 104 lines
drivers/gpu/drm/drm_panic.c +24 -12
   #if defined(CONFIG_LOGO) && !defined(MODULE)
   static const struct linux_logo *logo_mono;
@@ -496,31 +496,44 @@ static void draw_txt_rectangle(struct 
 drm_scanout_buffer *sb,
       }
   }
+static void drm_panic_logo_rect(struct drm_rect *rect, const struct 
 font_desc *font)
+{
+    if (logo_mono)
+        drm_rect_init(rect, 0, 0, logo_mono->width, logo_mono->height);
+    else {
+        int logo_width = get_max_line_len(logo_ascii, 
 logo_ascii_lines) * font->width;
+
+        drm_rect_init(rect, 0, 0, logo_width, logo_ascii_lines * 
 font->height);
+    }
+}
+
+static void drm_panic_logo_draw(struct drm_scanout_buffer *sb, struct 
 drm_rect *rect,
+                const struct font_desc *font, u32 fg_color)
+{
+    if (logo_mono)
+        drm_panic_blit(sb, rect, logo_mono->data,
+                   DIV_ROUND_UP(drm_rect_width(rect), 8), 1, fg_color);
+    else
+        draw_txt_rectangle(sb, font, logo_ascii, logo_ascii_lines, 
 false, rect,
+                   fg_color);
+}
+
   static void draw_panic_static_user(struct drm_scanout_buffer *sb)
   {
       u32 fg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_FOREGROUND_COLOR, sb->format->format);
       u32 bg_color = convert_from_xrgb8888(CONFIG_DRM_PANIC_BACKGROUND_COLOR, sb->format->format);
       const struct font_desc *font = get_default_font(sb->width, sb->height, NULL, NULL);
       struct drm_rect r_screen, r_logo, r_msg;
-    unsigned int logo_width, logo_height;
       unsigned int msg_width, msg_height;
       if (!font)
           return;
       r_screen = DRM_RECT_INIT(0, 0, sb->width, sb->height);
+    drm_panic_logo_rect(&r_logo, font);
-    if (logo_mono) {
-        logo_width = logo_mono->width;
-        logo_height = logo_mono->height;
-    } else {
-        logo_width = get_max_line_len(logo_ascii, PANIC_LOGO_LINES) * 
 font->width;
-        logo_height = PANIC_LOGO_LINES * font->height;
-    }
-    r_logo = DRM_RECT_INIT(0, 0, logo_width, logo_height);
-
-    msg_width = min(get_max_line_len(panic_msg, PANIC_MSG_LINES) * 
 font->width, sb->width);
-    msg_height = min(PANIC_MSG_LINES * font->height, sb->height);
+    msg_width = min(get_max_line_len(panic_msg, panic_msg_lines) * 

font->width, sb->width);
+    msg_height = min(panic_msg_lines * font->height, sb->height); r_msg = DRM_RECT_INIT(0, 0, msg_width, msg_height); /* Center the panic message */

drivers/gpu/drm/drm_panic.c +4 -9
@@ -529,15 +542,10 @@ static void draw_panic_static_user(struct 
 drm_scanout_buffer *sb)
       /* Fill with the background color, and draw text on top */
       drm_panic_fill(sb, &r_screen, bg_color);
-    if (!drm_rect_overlap(&r_logo, &r_msg)) {
-        if (logo_mono)
-            drm_panic_blit(sb, &r_logo, logo_mono->data, 
 DIV_ROUND_UP(logo_width, 8),
-                       fg_color);
-        else
-            draw_txt_rectangle(sb, font, logo_ascii, 
 PANIC_LOGO_LINES, false, &r_logo,
-                       fg_color);
-    }
-    draw_txt_rectangle(sb, font, panic_msg, PANIC_MSG_LINES, true, 
 &r_msg, fg_color);
+    if (!drm_rect_overlap(&r_logo, &r_msg))
+        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);
  }
  /*

drivers/gpu/drm/drm_panic.c +1 -3
@@ -647,7 +655,7 @@ static void drm_panic_set_description(const char 
 *description)
       u32 len;
       if (description) {
-        struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES 
- 1];
+        struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines 
- 1];
           desc_line->txt = description;

          len = strlen(description);

drivers/gpu/drm/drm_panic.c +1 -1
@@ -660,7 +668,7 @@ static void drm_panic_set_description(const char 
 *description)
   static void drm_panic_clear_description(void)
   {
-    struct drm_panic_line *desc_line = &panic_msg[PANIC_MSG_LINES - 1];
+    struct drm_panic_line *desc_line = &panic_msg[panic_msg_lines - 1];
       desc_line->len = 0;
       desc_line->txt = NULL;
author maintainer
#9 lore raw

PATCH v7 4/4 drm/panic: Add a QR code panic screen

In reply to Jocelyn Falempe

This patch adds a new panic screen, with a QR code and the kmsg data embedded.
If DRM_PANIC_SCREEN_QR_CODE_URL is set, then the kmsg data will be compressed with zlib and encoded as a numerical segment, and appended to the URL as a URL parameter. This allows to save space, and put about ~7500 bytes of kmsg data, in a V40 QR code.
Linux distributions can customize the URL, and put a web frontend to directly open a bug report with the kmsg data.

Otherwise the kmsg data will be encoded as a binary segment (ie raw ascii) and only a maximum of 2953 bytes of kmsg data will be available in the QR code.

You can also limit the QR code size with DRM_PANIC_SCREEN_QR_VERSION.

---

v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Mark drm_panic_qr_generate() as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call to as_str_unchecked() (Alice Ryhl)
* Add a check for data_len <= data_size (Greg KH)

v3:
* Fix all rust comments (typo, punctuation) (Miguel Ojeda)
* Change the wording of safety comments (Alice Ryhl)
* Add a link to the javascript decoder in the Kconfig (Greg KH)
* Fix data_size and tmp_size check in drm_panic_qr_generate()

v4:
* Fix the logic to find next line and skip the '\n' (Alic Ryhl)
* Remove __LOG_PREFIX as it's not used (Alice Ryhl)

v5:
* Move drm_panic_[init|exit]() prototype to drm_crtc_internal.h (Daniel Vetter)

v6:
* rebase, and handle conflict with 5d45c01dea6f ("drm/panic: Add panic description")
* Fix qr_width should be a signed int, to handle error code.

 drivers/gpu/drm/Kconfig             |   31 +
 drivers/gpu/drm/Makefile            |    1 +
 drivers/gpu/drm/drm_crtc_internal.h |    4 +
 drivers/gpu/drm/drm_drv.c           |    3 +
 drivers/gpu/drm/drm_panic.c         |  248 +++++++
 drivers/gpu/drm/drm_panic_qr.rs     | 1003 +++++++++++++++++++++++++++
 6 files changed, 1290 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_panic_qr.rs
drivers/gpu/drm/Kconfig +31 -0
index 0387143bbb397..1cb5a4f192933 100644
@@ -149,6 +149,37 @@ config DRM_PANIC_SCREEN
 	  or by writing to /sys/module/drm/parameters/panic_screen sysfs entry
 	  Default is "user"
 
+config DRM_PANIC_SCREEN_QR_CODE
+	bool "Add a panic screen with a QR code"
+	depends on DRM_PANIC && RUST
+	help
+	  This option adds a QR code generator, and a panic screen with a QR
+	  code. The QR code will contain the last lines of kmsg and other debug
+	  information. This should be easier for the user to report a kernel
+	  panic, with all debug information available.
+	  To use this panic screen, also set DRM_PANIC_SCREEN to "qr_code"
+
+config DRM_PANIC_SCREEN_QR_CODE_URL
+	string "Base URL of the QR code in the panic screen"
+	depends on DRM_PANIC_SCREEN_QR_CODE
+	help
+	  This option sets the base URL to report the kernel panic. If it's set
+	  the QR code will contain the URL and the kmsg compressed with zlib as
+	  a URL parameter. If it's empty, the QR code will contain the kmsg as
+	  uncompressed text only.
+	  There is a demo code in javascript, to decode and uncompress the kmsg
+	  data from the URL parameter at https://github.com/kdj0c/panic_report
+
+config DRM_PANIC_SCREEN_QR_VERSION
+	int "Maximum version (size) of the QR code."
+	depends on DRM_PANIC_SCREEN_QR_CODE
+	default 40
+	help
+	  This option limits the version (or size) of the QR code. QR code
+	  version ranges from Version 1 (21x21) to Version 40 (177x177).
+	  Smaller QR code are easier to read, but will contain less debugging
+	  data. Default is 40.
+
 config DRM_DEBUG_DP_MST_TOPOLOGY_REFS
         bool "Enable refcount backtrace history in the DP MST helpers"
 	depends on STACKTRACE_SUPPORT
drivers/gpu/drm/Makefile +1 -0
index 68cc9258ffc4b..c62339b89d461 100644
@@ -89,6 +89,7 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \
 	drm_privacy_screen_x86.o
 drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o
 drm-$(CONFIG_DRM_PANIC) += drm_panic.o
+drm-$(CONFIG_DRM_PANIC_SCREEN_QR_CODE) += drm_panic_qr.o
 obj-$(CONFIG_DRM)	+= drm.o
 
 obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
drivers/gpu/drm/drm_crtc_internal.h +4 -0
index 251ff7bba40d4..89706aa8232fc 100644
@@ -320,10 +320,14 @@ drm_edid_load_firmware(struct drm_connector *connector)
 bool drm_panic_is_enabled(struct drm_device *dev);
 void drm_panic_register(struct drm_device *dev);
 void drm_panic_unregister(struct drm_device *dev);
+void drm_panic_init(void);
+void drm_panic_exit(void);
 #else
 static inline bool drm_panic_is_enabled(struct drm_device *dev) { return false; }
 static inline void drm_panic_register(struct drm_device *dev) {}
 static inline void drm_panic_unregister(struct drm_device *dev) {}
+static inline void drm_panic_init(void) {}
+static inline void drm_panic_exit(void) {}
 #endif
 
 #endif /* __DRM_CRTC_INTERNAL_H__ */
drivers/gpu/drm/drm_drv.c +3 -0
index 93543071a5008..27007b53a8c86 100644
@@ -1067,6 +1067,7 @@ static const struct file_operations drm_stub_fops = {
 static void drm_core_exit(void)
 {
 	drm_privacy_screen_lookup_exit();
+	drm_panic_exit();
 	accel_core_exit();
 	unregister_chrdev(DRM_MAJOR, "drm");
 	debugfs_remove(drm_debugfs_root);
@@ -1099,6 +1100,8 @@ static int __init drm_core_init(void)
 	if (ret < 0)
 		goto error;
 
+	drm_panic_init();
+
 	drm_privacy_screen_lookup_init();
 
 	drm_core_init_complete = true;
drivers/gpu/drm/drm_panic.c +248 -0

275 lines not on this page · raw message

drivers/gpu/drm/drm_panic_qr.rs new file +1003 -0

1,003 lines not on this page · raw message

Signature · 1 line
2.46.0
author maintainer
#10 lore raw
In reply to Jocelyn Falempe
Quoted 11 lines · Jocelyn Falempe

This series adds a new panic screen, with the kmsg data embedded in a QR code.

The main advantage of QR code, is that you can copy/paste the debug data to a bug report.

The QR code encoder is written in rust, and is very specific to drm panic.
The reason is that it is called in a panic handler, and thus can't allocate memory, or use locking. The rust code uses a few rust core API, and provides only two C entry points.
There is no particular reason to do it in rust, I just wanted to learn rust, and see if it can work in the kernel.

If you want to see what it looks like, I've put a few screenshots here:
https://github.com/kdj0c/panic_report/issues/1

I just pushed it to drm-misc-next

Thank you all for your reviews.

Best regards,

Signature · 1 line
Jocelyn
Quoted 47 lines

v2:
* Rewrite the rust comments with Markdown (Alice Ryhl)
* Mark drm_panic_qr_generate() as unsafe (Alice Ryhl)
* Use CStr directly, and remove the call to as_str_unchecked() (Alice Ryhl)
* Add a check for data_len <= data_size (Greg KH)

v3:
* Fix all rust comments (typo, punctuation) (Miguel Ojeda)
* Change the wording of safety comments (Alice Ryhl)
* Add a link to the javascript decoder in the Kconfig (Greg KH)
* Fix data_size and tmp_size check in drm_panic_qr_generate()

v4:
* Fix the logic to find next line and skip the '\n' (Alic Ryhl)
* Remove __LOG_PREFIX as it's not used (Alice Ryhl)

v5:
* Move drm_panic_[init|exit]() prototype to drm_crtc_internal.h (Daniel Vetter)

v6:
* rebase, and handle conflict with 5d45c01dea6f ("drm/panic: Add panic description")
* Fix qr_width should be a signed int, to handle error code.

v7:
* rename r1/r2 to a/b in drm_rect_overlap() (Jani Nikula)

Jocelyn Falempe (4):
drm/panic: Add integer scaling to blit()
drm/rect: Add drm_rect_overlap()
drm/panic: Simplify logo handling
drm/panic: Add a QR code panic screen

  drivers/gpu/drm/Kconfig             |   31 +
  drivers/gpu/drm/Makefile            |    1 +
  drivers/gpu/drm/drm_crtc_internal.h |    4 +
  drivers/gpu/drm/drm_drv.c           |    3 +
  drivers/gpu/drm/drm_panic.c         |  340 +++++++--
  drivers/gpu/drm/drm_panic_qr.rs     | 1003 +++++++++++++++++++++++++++
  include/drm/drm_rect.h              |   15 +
  7 files changed, 1357 insertions(+), 40 deletions(-)

create mode 100644 drivers/gpu/drm/drm_panic_qr.rs

base-commit: 04b5b362bc2a36f1dfe5cad52c83b1ea9d25b87c