Skip to contentSkip to conversation

drm/panic: Fix the potential loop that causes kmsg to not display correctly

PATCH In review luyuantao01 3 participants 5 messages Jan 26 – Jan 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/panic: Fix the potential loop that causes kmsg to not display correctly

From: luyuantao <[email protected]>

When kmsg_buf completes drawing the screen and yoffset is less than 0, kmsg_dump_get_buffer continues to obtain the buffer. This potential loop may cause panic_flush not to be executed immediately or even not to be executed at all, resulting in a garbled screen display instead of normal logs

So, the loop should be exited immediately after drawing kmsg_buf

---
 drivers/gpu/drm/drm_panic.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_panic.c +3 -0
index d4b6ea42db0f..4b44011b4be1 100644
@@ -592,6 +592,9 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)
 			end = start;
 			start--;
 		}
+
+		if (yoffset < 0)
+			break;
 	}
 }
 
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 8 lines · On 26/01/2026 06:40, luyuantao01 wrote:

From: luyuantao <[email protected]>

When kmsg_buf completes drawing the screen and yoffset is less than 0, kmsg_dump_get_buffer continues to obtain the buffer. This potential loop may cause panic_flush not to be executed immediately or even not to be executed at all, resulting in a garbled screen display instead of normal logs

So, the loop should be exited immediately after drawing kmsg_buf

You're right, the loop should stop when the screen is filled.

I would prefer writing it like this:

while (yoffset >= 0 && kmsg_dump_get_buffer(&iter, false, kmsg_buf, sizeof(kmsg_buf), &kmsg_len)) {

Can you send a v2 with this changed?

Best regards,

Signature · 1 line
Jocelyn
Quoted 20 lines
---
  drivers/gpu/drm/drm_panic.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_panic.c +3 -0
index d4b6ea42db0f..4b44011b4be1 100644
@@ -592,6 +592,9 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)
  			end = start;
  			start--;
  		}
+
+		if (yoffset < 0)
+			break;
  	}
  }
 
#2 lore raw

PATCH v2 1/1 drm/panic: Fix the potential loop that causes kmsg to not display correctly

In reply to luyuantao01

From: luyuantao <[email protected]>

When kmsg_buf completes drawing the screen and yoffset is less than 0, kmsg_dump_get_buffer continues to obtain the buffer. This potential loop may cause panic_flush not to be executed immediately or even not to be executed at all, resulting in a garbled screen display instead of normal logs

So, the loop should be exited immediately after drawing kmsg_buf

---
 drivers/gpu/drm/drm_panic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_panic.c +2 -1
index d4b6ea42db0f..f7289dbf2ef9 100644
@@ -574,7 +574,8 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)
 	drm_panic_fill(sb, &r_screen, bg_color);
 
 	kmsg_dump_rewind(&iter);
-	while (kmsg_dump_get_buffer(&iter, false, kmsg_buf, sizeof(kmsg_buf), &kmsg_len)) {
+	while (yoffset >= 0 && kmsg_dump_get_buffer(&iter, false, kmsg_buf,
+				sizeof(kmsg_buf), &kmsg_len)) {
 		char *start;
 		char *end;
 
Signature · 1 line
2.27.0
maintainer Reviewed-by on v2 1/1
#3 lore raw
Quoted 8 lines · On 26/01/2026 11:07, luyuantao01 wrote:

From: luyuantao <[email protected]>

When kmsg_buf completes drawing the screen and yoffset is less than 0, kmsg_dump_get_buffer continues to obtain the buffer. This potential loop may cause panic_flush not to be executed immediately or even not to be executed at all, resulting in a garbled screen display instead of normal logs

So, the loop should be exited immediately after drawing kmsg_buf

Thanks, for sending a v2.
I will push it to drm-misc-next in a few days if no other comment.

Quoted 20 lines
---
  drivers/gpu/drm/drm_panic.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_panic.c +2 -1
index d4b6ea42db0f..f7289dbf2ef9 100644
@@ -574,7 +574,8 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)
  	drm_panic_fill(sb, &r_screen, bg_color);
 
  	kmsg_dump_rewind(&iter);
-	while (kmsg_dump_get_buffer(&iter, false, kmsg_buf, sizeof(kmsg_buf), &kmsg_len)) {
+	while (yoffset >= 0 && kmsg_dump_get_buffer(&iter, false, kmsg_buf,
+				sizeof(kmsg_buf), &kmsg_len)) {
  		char *start;
  		char *end;
 
maintainer Acked-by on v2 1/1
#4 lore raw
In reply to luyuantao01
Quoted 11 lines · luyuantao01 <[email protected]> writes:

From: luyuantao <[email protected]>

When kmsg_buf completes drawing the screen and yoffset is less than 0, kmsg_dump_get_buffer continues to obtain the buffer. This potential loop may cause panic_flush not to be executed immediately or even not to be executed at all, resulting in a garbled screen display instead of normal logs

So, the loop should be exited immediately after drawing kmsg_buf

---

Makes sense to me.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat