Skip to contentSkip to conversation

drm/panic: Add a QR code panic screen

PATCH Superseded Jocelyn Falempe 3 participants 11 messages Aug 12, 2024 – Aug 13, 2024

Subsystems (4)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jocelyn Falempe

author maintainer
#0 lore raw

v6 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.

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: 5d45c01dea6f9e0f2dbed3ffee02ac2e80579ad4

Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH v6 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
author maintainer
#2 lore raw

PATCH v6 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.

---
 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..7bafde747d560 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
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
 bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
 bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
 			  const struct drm_rect *clip);
Signature · 1 line
2.46.0
#3 lore raw

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

Quoted 4 lines · 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.

Based on the name, I'd expect drm_rect_overlap() to return true for *any* overlap, while this one seems to mean if one rectangle is completely within another, with no adjacent borders.

I'd expect a drm_rect_overlap() to return true for this:

 +-------+
 |   +---+---+
 |   |       |
 +---+       |
     |       |
     +-------+

While this seems to be required instead:

 +-------+
 | +---+ |
 | |   | |
 | +---+ |
 +-------+

IOW, I find the name misleading.

BR,
Jani.

Quoted 47 lines
---
 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..7bafde747d560 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
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
 bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
 bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
 			  const struct drm_rect *clip);
Signature · 1 line
Jani Nikula, Intel
#4 lore raw

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

Quoted 21 lines · Jani Nikula
Quoted 4 lines · 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.

Based on the name, I'd expect drm_rect_overlap() to return true for *any* overlap, while this one seems to mean if one rectangle is completely within another, with no adjacent borders.

I'd expect a drm_rect_overlap() to return true for this:

  +-------+
  |   +---+---+
  |   |       |
  +---+       |
      |       |
      +-------+

While this seems to be required instead:

Quoted 8 lines
  +-------+
  | +---+ |
  | |   | |
  | +---+ |
  +-------+

IOW, I find the name misleading.

Ya, maybe drm_rect_encloses() would be a better fit.

Quoted 34 lines

BR,
Jani.

Quoted 29 lines
---
  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 +0 -0
index 73fcb899a01da..7bafde747d560 100644
@@ -238,6 +238,21 @@ static inline void drm_rect_fp_to_int(struct drm_rect *dst,
  		      drm_rect_height(src) >> 16);
  }
 
Quoted 7 lines

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

Quoted 7 lines
include/drm/drm_rect.h +7 -0
+/**
+ * drm_rect_overlap - Check if two rectangles overlap
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.

If you do end up going with that name, the returns doc ought to be:

%true if @r2 is completely enclosed in @r1, %false otherwise.

Quoted 12 lines
Quoted 11 lines
include/drm/drm_rect.h +8 -0
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
  bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
  bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
  			  const struct drm_rect *clip);
Signature · 1 line
Hamza
author maintainer
#5 lore raw

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

In reply to Jani Nikula
Quoted 9 lines · Jani Nikula
Quoted 4 lines · 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.

Based on the name, I'd expect drm_rect_overlap() to return true for *any* overlap, while this one seems to mean if one rectangle is completely within another, with no adjacent borders.

It's what I intended, but I may have messed up the formula.

Quoted 9 lines

I'd expect a drm_rect_overlap() to return true for this:

  +-------+
  |   +---+---+
  |   |       |
  +---+       |
      |       |
      +-------+

if r1 is the top left rectangle, you've got:

r1->x2 > r2->x1   => true
r2->x2 > r1->x1   => true
r1->y2 > r2->y1   => true
r2->y2 > r1->y1   => true

So they count as overlap.

Checking in stackoverflow, they use the same formula:
https://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other

Quoted 64 lines

While this seems to be required instead:

  +-------+
  | +---+ |
  | |   | |
  | +---+ |
  +-------+

IOW, I find the name misleading.

BR,
Jani.

Quoted 47 lines
---
  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..7bafde747d560 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
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
  bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
  bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
  			  const struct drm_rect *clip);
#6 lore raw

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

Quoted 7 lines · Jocelyn Falempe
Quoted 6 lines · Jani Nikula
Quoted 4 lines · 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.

Quoted 5 lines
Quoted 3 lines

Based on the name, I'd expect drm_rect_overlap() to return true for *any* overlap, while this one seems to mean if one rectangle is completely within another, with no adjacent borders.

It's what I intended, but I may have messed up the formula.

Hmm, then I may have messed up the review. :)

Gotta run now, but I'll get back.

BR,
Jani.

Quoted 87 lines
Quoted 9 lines

I'd expect a drm_rect_overlap() to return true for this:

  +-------+
  |   +---+---+
  |   |       |
  +---+       |
      |       |
      +-------+

if r1 is the top left rectangle, you've got:

r1->x2 > r2->x1   => true
r2->x2 > r1->x1   => true
r1->y2 > r2->y1   => true
r2->y2 > r1->y1   => true

So they count as overlap.

Checking in stackoverflow, they use the same formula:
https://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other

Quoted 64 lines

While this seems to be required instead:

  +-------+
  | +---+ |
  | |   | |
  | +---+ |
  +-------+

IOW, I find the name misleading.

BR,
Jani.

Quoted 47 lines
---
  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..7bafde747d560 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
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
  bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
  bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
  			  const struct drm_rect *clip);
Signature · 1 line
Jani Nikula, Intel
#7 lore raw

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

Quoted 8 lines · Jani Nikula
Quoted 7 lines · Jocelyn Falempe
Quoted 6 lines · Jani Nikula
Quoted 4 lines · 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.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Based on the name, I'd expect drm_rect_overlap() to return true for *any* overlap, while this one seems to mean if one rectangle is completely within another, with no adjacent borders.

It's what I intended, but I may have messed up the formula.

Hmm, then I may have messed up the review. :)

Yeah, my bad, sorry for the noise.

I think I was thrown off by the comparisons mixing r1 and r2 as the first operand. Something like this might have been easier for *me* to parse, but not sure if it's worth changing anything:

return (a->x1 < b->x2 && a->x2 > b->x1 &&

        a->y1 < b->y2 && a->y2 > b->y1);

BR,
Jani.

Quoted 95 lines

Gotta run now, but I'll get back.

BR,
Jani.

Quoted 87 lines
Quoted 9 lines

I'd expect a drm_rect_overlap() to return true for this:

  +-------+
  |   +---+---+
  |   |       |
  +---+       |
      |       |
      +-------+

if r1 is the top left rectangle, you've got:

r1->x2 > r2->x1   => true
r2->x2 > r1->x1   => true
r1->y2 > r2->y1   => true
r2->y2 > r1->y1   => true

So they count as overlap.

Checking in stackoverflow, they use the same formula:
https://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other

Quoted 64 lines

While this seems to be required instead:

  +-------+
  | +---+ |
  | |   | |
  | +---+ |
  +-------+

IOW, I find the name misleading.

BR,
Jani.

Quoted 47 lines
---
  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..7bafde747d560 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
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
  bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
  bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
  			  const struct drm_rect *clip);
Signature · 1 line
Jani Nikula, Intel
author maintainer
#8 lore raw

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

Quoted 17 lines · Jani Nikula
Quoted 8 lines · Jani Nikula
Quoted 7 lines · Jocelyn Falempe
Quoted 6 lines · Jani Nikula
Quoted 4 lines · 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.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Based on the name, I'd expect drm_rect_overlap() to return true for *any* overlap, while this one seems to mean if one rectangle is completely within another, with no adjacent borders.

It's what I intended, but I may have messed up the formula.

Hmm, then I may have messed up the review. :)

Quoted 8 lines

Yeah, my bad, sorry for the noise.

I think I was thrown off by the comparisons mixing r1 and r2 as the first operand. Something like this might have been easier for *me* to parse, but not sure if it's worth changing anything:

return (a->x1 < b->x2 && a->x2 > b->x1 &&

         a->y1 < b->y2 && a->y2 > b->y1);

You're right, I've used r1 and r2 for consistency with other functions, but for this case it's confusing, I prefer the a/b.

If I send a v7 I will do this change.

I can also rename when pushing, but I was already bitten by doing this.

Best regards,

Signature · 1 line
Jocelyn
Quoted 102 lines

BR,
Jani.

Quoted 95 lines

Gotta run now, but I'll get back.

BR,
Jani.

Quoted 87 lines
Quoted 9 lines

I'd expect a drm_rect_overlap() to return true for this:

   +-------+
   |   +---+---+
   |   |       |
   +---+       |
       |       |
       +-------+

if r1 is the top left rectangle, you've got:

r1->x2 > r2->x1   => true
r2->x2 > r1->x1   => true
r1->y2 > r2->y1   => true
r2->y2 > r1->y1   => true

So they count as overlap.

Checking in stackoverflow, they use the same formula:
https://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other

Quoted 64 lines

While this seems to be required instead:

   +-------+
   | +---+ |
   | |   | |
   | +---+ |
   +-------+

IOW, I find the name misleading.

BR,
Jani.

Quoted 47 lines
---
   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..7bafde747d560 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
+ * @r1: first rectangle
+ * @r2: second rectangle
+ *
+ * RETURNS:
+ * %true if the rectangles overlap, %false otherwise.
+ */
+static inline bool drm_rect_overlap(const struct drm_rect *r1,
+				    const struct drm_rect *r2)
+{
+	return (r1->x2 > r2->x1 && r2->x2 > r1->x1 &&
+		r1->y2 > r2->y1 && r2->y2 > r1->y1);
+}
+
   bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
   bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
   			  const struct drm_rect *clip);
author maintainer
#9 lore raw

PATCH v6 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
author maintainer
#10 lore raw

PATCH v6 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 b6ea88d228e1f..b3ab3ace7f8e4 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