Skip to contentSkip to conversation

drm/bochs: Add support for drm_panic

PATCH In review Ryosuke Yasuoka 3 participants 11 messages Jun 13, 2025 – Jul 17, 2025

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

PATCH 1/1 drm/bochs: Add support for drm_panic

Add drm_panic moudle for bochs drm so that panic screen can be displayed on panic.

---
 drivers/gpu/drm/tiny/bochs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/gpu/drm/tiny/bochs.c +19 -0
index 8706763af8fb..ed42ad5c4927 100644
@@ -19,6 +19,7 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_module.h>
+#include <drm/drm_panic.h>
 #include <drm/drm_plane_helper.h>
 #include <drm/drm_probe_helper.h>
 
@@ -469,10 +470,28 @@ static void bochs_primary_plane_helper_atomic_update(struct drm_plane *plane,
 	bochs_hw_setformat(bochs, fb->format);
 }
 
+static int bochs_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
+							  struct drm_scanout_buffer *sb)
+{
+	struct bochs_device *bochs = to_bochs_device(plane->dev);
+	struct iosys_map map = IOSYS_MAP_INIT_VADDR_IOMEM(bochs->fb_map);
+
+	if (plane->state && plane->state->fb) {
+		sb->format = plane->state->fb->format;
+		sb->width = plane->state->fb->width;
+		sb->height = plane->state->fb->height;
+		sb->pitch[0] = plane->state->fb->pitches[0];
+		sb->map[0] = map;
+		return 0;
+	}
+	return -ENODEV;
+}
+
 static const struct drm_plane_helper_funcs bochs_primary_plane_helper_funcs = {
 	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
 	.atomic_check = bochs_primary_plane_helper_atomic_check,
 	.atomic_update = bochs_primary_plane_helper_atomic_update,
+	.get_scanout_buffer = bochs_primary_plane_helper_get_scanout_buffer,
 };
 
 static const struct drm_plane_funcs bochs_primary_plane_funcs = {

base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494

Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Ryosuke Yasuoka

Add drm_panic moudle for bochs drm so that panic screen can be displayed on panic.

Thanks for the patch, it's simple and looks good to me.

If no objections, I will push it next Monday.

Best regards,

Signature · 1 line
Jocelyn
Quoted 49 lines
---
  drivers/gpu/drm/tiny/bochs.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/gpu/drm/tiny/bochs.c +19 -0
index 8706763af8fb..ed42ad5c4927 100644
@@ -19,6 +19,7 @@
  #include <drm/drm_gem_shmem_helper.h>
  #include <drm/drm_managed.h>
  #include <drm/drm_module.h>
+#include <drm/drm_panic.h>
  #include <drm/drm_plane_helper.h>
  #include <drm/drm_probe_helper.h>
 
@@ -469,10 +470,28 @@ static void bochs_primary_plane_helper_atomic_update(struct drm_plane *plane,
  	bochs_hw_setformat(bochs, fb->format);
  }
 
+static int bochs_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
+							  struct drm_scanout_buffer *sb)
+{
+	struct bochs_device *bochs = to_bochs_device(plane->dev);
+	struct iosys_map map = IOSYS_MAP_INIT_VADDR_IOMEM(bochs->fb_map);
+
+	if (plane->state && plane->state->fb) {
+		sb->format = plane->state->fb->format;
+		sb->width = plane->state->fb->width;
+		sb->height = plane->state->fb->height;
+		sb->pitch[0] = plane->state->fb->pitches[0];
+		sb->map[0] = map;
+		return 0;
+	}
+	return -ENODEV;
+}
+
  static const struct drm_plane_helper_funcs bochs_primary_plane_helper_funcs = {
  	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
  	.atomic_check = bochs_primary_plane_helper_atomic_check,
  	.atomic_update = bochs_primary_plane_helper_atomic_update,
+	.get_scanout_buffer = bochs_primary_plane_helper_get_scanout_buffer,
  };
 
  static const struct drm_plane_funcs bochs_primary_plane_funcs = {

base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494

#2 lore raw
Quoted 9 lines · Jocelyn Falempe
Quoted 2 lines · Ryosuke Yasuoka

Add drm_panic moudle for bochs drm so that panic screen can be displayed on panic.

Thanks for the patch, it's simple and looks good to me.

Quoted 7 lines

If no objections, I will push it next Monday.

Best regards,

--

Jocelyn

Thank you Jocelyn for reviewing my patch.
Now I found a typo in the commit message; moudle -> module.

Let me fix it in v2.

Ryosuke

Quoted 50 lines
Quoted 49 lines
---
  drivers/gpu/drm/tiny/bochs.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/gpu/drm/tiny/bochs.c +19 -0
index 8706763af8fb..ed42ad5c4927 100644
@@ -19,6 +19,7 @@
  #include <drm/drm_gem_shmem_helper.h>
  #include <drm/drm_managed.h>
  #include <drm/drm_module.h>
+#include <drm/drm_panic.h>
  #include <drm/drm_plane_helper.h>
  #include <drm/drm_probe_helper.h>
 
@@ -469,10 +470,28 @@ static void bochs_primary_plane_helper_atomic_update(struct drm_plane *plane,
      bochs_hw_setformat(bochs, fb->format);
  }
 
+static int bochs_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
+                                                       struct drm_scanout_buffer *sb)
+{
+     struct bochs_device *bochs = to_bochs_device(plane->dev);
+     struct iosys_map map = IOSYS_MAP_INIT_VADDR_IOMEM(bochs->fb_map);
+
+     if (plane->state && plane->state->fb) {
+             sb->format = plane->state->fb->format;
+             sb->width = plane->state->fb->width;
+             sb->height = plane->state->fb->height;
+             sb->pitch[0] = plane->state->fb->pitches[0];
+             sb->map[0] = map;
+             return 0;
+     }
+     return -ENODEV;
+}
+
  static const struct drm_plane_helper_funcs bochs_primary_plane_helper_funcs = {
      DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
      .atomic_check = bochs_primary_plane_helper_atomic_check,
      .atomic_update = bochs_primary_plane_helper_atomic_update,
+     .get_scanout_buffer = bochs_primary_plane_helper_get_scanout_buffer,
  };
 
  static const struct drm_plane_funcs bochs_primary_plane_funcs = {

base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494

#3 lore raw
Quoted 12 lines · Ryosuke Yasuoka
Quoted 11 lines · Jocelyn Falempe
Quoted 2 lines · Ryosuke Yasuoka

Add drm_panic moudle for bochs drm so that panic screen can be displayed on panic.

Thanks for the patch, it's simple and looks good to me.

If no objections, I will push it next Monday.

Quoted 8 lines
Quoted 5 lines

Best regards,

--

Jocelyn

Thank you Jocelyn for reviewing my patch.
Now I found a typo in the commit message; moudle -> module.

No need to send a v2 for that, I will fix it before pushing the patch.

Thanks,

Signature · 1 line
Jocelyn
Quoted 56 lines

Let me fix it in v2.

Ryosuke

Quoted 50 lines
Quoted 49 lines
---
   drivers/gpu/drm/tiny/bochs.c | 19 +++++++++++++++++++
   1 file changed, 19 insertions(+)
drivers/gpu/drm/tiny/bochs.c +19 -0
index 8706763af8fb..ed42ad5c4927 100644
@@ -19,6 +19,7 @@
   #include <drm/drm_gem_shmem_helper.h>
   #include <drm/drm_managed.h>
   #include <drm/drm_module.h>
+#include <drm/drm_panic.h>
   #include <drm/drm_plane_helper.h>
   #include <drm/drm_probe_helper.h>
 
@@ -469,10 +470,28 @@ static void bochs_primary_plane_helper_atomic_update(struct drm_plane *plane,
       bochs_hw_setformat(bochs, fb->format);
   }
 
+static int bochs_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
+                                                       struct drm_scanout_buffer *sb)
+{
+     struct bochs_device *bochs = to_bochs_device(plane->dev);
+     struct iosys_map map = IOSYS_MAP_INIT_VADDR_IOMEM(bochs->fb_map);
+
+     if (plane->state && plane->state->fb) {
+             sb->format = plane->state->fb->format;
+             sb->width = plane->state->fb->width;
+             sb->height = plane->state->fb->height;
+             sb->pitch[0] = plane->state->fb->pitches[0];
+             sb->map[0] = map;
+             return 0;
+     }
+     return -ENODEV;
+}
+
   static const struct drm_plane_helper_funcs bochs_primary_plane_helper_funcs = {
       DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
       .atomic_check = bochs_primary_plane_helper_atomic_check,
       .atomic_update = bochs_primary_plane_helper_atomic_update,
+     .get_scanout_buffer = bochs_primary_plane_helper_get_scanout_buffer,
   };
 
   static const struct drm_plane_funcs bochs_primary_plane_funcs = {

base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494

#4 lore raw
In reply to Ryosuke Yasuoka
Quoted 2 lines · Ryosuke Yasuoka

Add drm_panic moudle for bochs drm so that panic screen can be displayed on panic.

I just pushed it to drm-misc-next, with the typo in the commit message fixed.

Thanks,

Signature · 1 line
Jocelyn
Quoted 49 lines
---
  drivers/gpu/drm/tiny/bochs.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/gpu/drm/tiny/bochs.c +19 -0
index 8706763af8fb..ed42ad5c4927 100644
@@ -19,6 +19,7 @@
  #include <drm/drm_gem_shmem_helper.h>
  #include <drm/drm_managed.h>
  #include <drm/drm_module.h>
+#include <drm/drm_panic.h>
  #include <drm/drm_plane_helper.h>
  #include <drm/drm_probe_helper.h>
 
@@ -469,10 +470,28 @@ static void bochs_primary_plane_helper_atomic_update(struct drm_plane *plane,
  	bochs_hw_setformat(bochs, fb->format);
  }
 
+static int bochs_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
+							  struct drm_scanout_buffer *sb)
+{
+	struct bochs_device *bochs = to_bochs_device(plane->dev);
+	struct iosys_map map = IOSYS_MAP_INIT_VADDR_IOMEM(bochs->fb_map);
+
+	if (plane->state && plane->state->fb) {
+		sb->format = plane->state->fb->format;
+		sb->width = plane->state->fb->width;
+		sb->height = plane->state->fb->height;
+		sb->pitch[0] = plane->state->fb->pitches[0];
+		sb->map[0] = map;
+		return 0;
+	}
+	return -ENODEV;
+}
+
  static const struct drm_plane_helper_funcs bochs_primary_plane_helper_funcs = {
  	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
  	.atomic_check = bochs_primary_plane_helper_atomic_check,
  	.atomic_update = bochs_primary_plane_helper_atomic_update,
+	.get_scanout_buffer = bochs_primary_plane_helper_get_scanout_buffer,
  };
 
  static const struct drm_plane_funcs bochs_primary_plane_funcs = {

base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494

#6 lore raw
Quoted 1 line · Askar Safin

Are normal panics (i. e. not drm panics) still supposed to work with bochs?

"Normal panics", is just the console logs through fbcon. The problem is that this is not designed to work in a panic context, so on some driver it can work, but it's not reliable. Also depending on the panic source (Like if the panic occurs in IRQ context), you probably won't see anything. I think the regression is likely because the driver switched to use a shadow buffer (ie: fbcon draws to a buffer in system memory, which is copied to the "VRAM" in a workqueue, and workqueues are disabled in a panic context). So there is no easy fix for the fbcon panic.

This patch series, only take care of DRM panic. You can get the same output as fbcon, by selecting CONFIG_DRM_PANIC_SCREEN"kmsg".

Signature · 1 line
Jocelyn
Quoted 12 lines

If yes, then I want to point out that they, in fact, don't work since 2019. I. e. panics are not shown in Qemu if:
1) bochs is used
2) we use "normal" panics (not drm panics)

I already reported this here: https://lore.kernel.org/regressions/[email protected]/T/#u , but nobody answered.

--
Askar Safin

#7 lore raw

---- On Tue, 15 Jul 2025 12:57:04 +0400 Jocelyn Falempe <[email protected]> wrote ---

Quoted 1 line

"Normal panics", is just the console logs through fbcon. The problem is

Thank you for answer! Is this possible to configure system such that fbcon works normally, VTs work normally (i. e. via framebuffer), but when panic happens, it is displayed via drm_panic? This seems to be solution to the problem.

--
Askar Safin
https://types.pl/@safinaskar

#8 lore raw
Quoted 6 lines · Askar Safin

---- On Tue, 15 Jul 2025 12:57:04 +0400 Jocelyn Falempe <[email protected]> wrote ---

Quoted 1 line

"Normal panics", is just the console logs through fbcon. The problem is

Thank you for answer! Is this possible to configure system such that fbcon works normally, VTs work normally (i. e. via framebuffer), but when panic happens, it is displayed via drm_panic? This seems to be solution to the problem.

Yes, that's the default if you use a drm driver like bochs with fbdev emulation enabled. (Of course you can't have DRM panic on a pure fbdev driver).

There was a concurrency problem between fbcon and DRM panic, and I've solved it a year ago with:
https://patchwork.freedesktop.org/series/136182/

So make sure you have the following in your .config:

CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_DRM_FBDEV_EMULATION=y
CONFIG_DRM_PANIC=y
CONFIG_DRM_PANIC_SCREEN="kmsg"

Best regards,

Signature · 1 line
Jocelyn
Quoted 5 lines

--
Askar Safin
https://types.pl/@safinaskar

#9 lore raw

---- On Wed, 16 Jul 2025 02:00:56 +0400 Jocelyn Falempe <[email protected]> wrote ---

Quoted 1 line

Yes, that's the default if you use a drm driver like bochs with fbdev

Thank you for answer! I just tried kernel from drm-tip with this config with drm_panic in qemu. And panic works. But I don't like result.
When drm panic happens, messages printed to /dev/console disappear. Only kernel messages remain.

Here are steps to reproduce. And then I will describe how this breaks my workflow.

Compile kernel from drm-tip ( https://gitlab.freedesktop.org/drm/tip ). I used commit b012f04b5be909a307ff629b297387e0ed55195a . It seems to include this bochs patch (i. e. "drm/bochs: Add support for drm_panic").
Use this miniconfig:

$ cat mini
CONFIG_64BIT=y

CONFIG_EXPERT=y

CONFIG_PRINTK=y
CONFIG_PRINTK_TIME=y

CONFIG_PCI=y

CONFIG_TTY=y
CONFIG_VT=y
CONFIG_VT_CONSOLE=y
CONFIG_DRM=y
CONFIG_DRM_FBDEV_EMULATION=y
CONFIG_DRM_BOCHS=y
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_PROC_FS=y

CONFIG_DRM_PANIC=y
CONFIG_DRM_PANIC_SCREEN="kmsg"

CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_GZIP=y
CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y

$ make KCONFIG_ALLCONFIG=mini allnoconfig

Create initramfs, which contains exactly these files:

$ find /tmp/i -ls
     2861      0 drwxrwxr-x   3 user     user           80 Jul 16 23:56 /tmp/i
     2891      0 drwxrwxr-x   2 user     user           80 Jul 16 23:56 /tmp/i/bin
     2893      0 lrwxrwxrwx   1 user     user            7 Jul 16 23:56 /tmp/i/bin/sh -> busybox
     2892   1980 -rwxr-xr-x   1 user     user      2024544 Jul 16 23:56 /tmp/i/bin/busybox
     2864      4 -rwxrwxr-x   1 user     user           43 Jul 16 23:18 /tmp/i/init

This is "init":
===
#!/bin/sh

set -e

echo hello
sleep 3
exit 0
===

Now boot this in Qemu. I used this command:

$ qemu-system-x86_64 -enable-kvm -m 1024  -kernel arch/x86/boot/bzImage -initrd /tmp/ini.cpio.gz

You will see word "hello", then after 3 seconds the system will fail into drm panic.

What I saw: word "hello" disappeared, when the system falled into panic What I expected to see: word "hello" should remain.

Now let me describe how this breaks my workflow.

I often use hand-crafted shell scripts as PID 1. Both in Qemu and on real hardware.
I use them to reproduce and bisect various kernel bugs.
I always put "set -e" in the beginning of shell script. This means that script fails after first error.
And thus system fails into kernel panic.
I also sometimes put "set -x" to debug these scripts.
Thus, when script fails and panic happens, then faulty shell command will be last thing printed on screen before panic stacktrace. But with drm_panic everything printed to /dev/console disappears.
This breaks my workflow.

In Qemu I can easily workaround this by using serial console.

But I cannot do this on real hardware.

And yes, I experience fbcon panic problems on real hardware, too, this is why I'm interested in drm panic: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14658

(I have not yet tested whether drm_panic fixes that fbcon i915 panic problem, but I assume it does.)

I can workaround this by using efi fb with fb panic as opposed to i915. But this will not work if I attempting to catch bug in i915 itself. (And yes, I recently found another i915-related bug, and I'm trying to debug it using shell scripts running as PID 1. Here it is: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14598 .)

I can workaround this by logging everything to disk.
But this will not work when everything is mounted read-only.
And this is exactly what happens, when I try to catch that kexec-related bug:
immediately before issuing "kexec -e" command I mount everything read-only.

The only remaining workaround is to redirect everything to /dev/kmsg. I. e. put "exec > /dev/kmsg 2>&1" to the script.
This will work.
But I still don't like this.

--
Askar Safin
https://types.pl/@safinaskar

#10 lore raw
Quoted 6 lines · Askar Safin

---- On Wed, 16 Jul 2025 02:00:56 +0400 Jocelyn Falempe <[email protected]> wrote ---

Quoted 1 line

Yes, that's the default if you use a drm driver like bochs with fbdev

Thank you for answer! I just tried kernel from drm-tip with this config with drm_panic in qemu. And panic works. But I don't like result.
When drm panic happens, messages printed to /dev/console disappear. Only kernel messages remain.

Yes, that's the expected behavior. DRM panic only prints the kernel messages, and don't mix that with console output.

Quoted 54 lines

Here are steps to reproduce. And then I will describe how this breaks my workflow.

Compile kernel from drm-tip ( https://gitlab.freedesktop.org/drm/tip ). I used commit b012f04b5be909a307ff629b297387e0ed55195a . It seems to include this bochs patch (i. e. "drm/bochs: Add support for drm_panic").
Use this miniconfig:

$ cat mini
CONFIG_64BIT=y

CONFIG_EXPERT=y

CONFIG_PRINTK=y
CONFIG_PRINTK_TIME=y

CONFIG_PCI=y

CONFIG_TTY=y
CONFIG_VT=y
CONFIG_VT_CONSOLE=y
CONFIG_DRM=y
CONFIG_DRM_FBDEV_EMULATION=y
CONFIG_DRM_BOCHS=y
CONFIG_FRAMEBUFFER_CONSOLE=y
CONFIG_PROC_FS=y

CONFIG_DRM_PANIC=y
CONFIG_DRM_PANIC_SCREEN="kmsg"

CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_GZIP=y
CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y

$ make KCONFIG_ALLCONFIG=mini allnoconfig

Create initramfs, which contains exactly these files:

$ find /tmp/i -ls
      2861      0 drwxrwxr-x   3 user     user           80 Jul 16 23:56 /tmp/i
      2891      0 drwxrwxr-x   2 user     user           80 Jul 16 23:56 /tmp/i/bin
      2893      0 lrwxrwxrwx   1 user     user            7 Jul 16 23:56 /tmp/i/bin/sh -> busybox
      2892   1980 -rwxr-xr-x   1 user     user      2024544 Jul 16 23:56 /tmp/i/bin/busybox
      2864      4 -rwxrwxr-x   1 user     user           43 Jul 16 23:18 /tmp/i/init

This is "init":
===
#!/bin/sh

set -e

echo hello
sleep 3
exit 0
===

Quoted 7 lines

Now boot this in Qemu. I used this command:

$ qemu-system-x86_64 -enable-kvm -m 1024  -kernel arch/x86/boot/bzImage -initrd /tmp/ini.cpio.gz

You will see word "hello", then after 3 seconds the system will fail into drm panic.

What I saw: word "hello" disappeared, when the system falled into panic What I expected to see: word "hello" should remain.

Even with fbcon, there is no guarantee that "hello" will remain visible, that depends on the screen size, and the amount of logs that the kernel panic will print.

Quoted 29 lines

Now let me describe how this breaks my workflow.

I often use hand-crafted shell scripts as PID 1. Both in Qemu and on real hardware.
I use them to reproduce and bisect various kernel bugs.
I always put "set -e" in the beginning of shell script. This means that script fails after first error.
And thus system fails into kernel panic.
I also sometimes put "set -x" to debug these scripts.
Thus, when script fails and panic happens, then faulty shell command will be last thing printed on screen before panic stacktrace. But with drm_panic everything printed to /dev/console disappears.
This breaks my workflow.

In Qemu I can easily workaround this by using serial console.

But I cannot do this on real hardware.

And yes, I experience fbcon panic problems on real hardware, too, this is why I'm interested in drm panic: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14658

(I have not yet tested whether drm_panic fixes that fbcon i915 panic problem, but I assume it does.)

I can workaround this by using efi fb with fb panic as opposed to i915. But this will not work if I attempting to catch bug in i915 itself. (And yes, I recently found another i915-related bug, and I'm trying to debug it using shell scripts running as PID 1. Here it is: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14598 .)

I can workaround this by logging everything to disk.
But this will not work when everything is mounted read-only.
And this is exactly what happens, when I try to catch that kexec-related bug:
immediately before issuing "kexec -e" command I mount everything read-only.

Quoted 4 lines

The only remaining workaround is to redirect everything to /dev/kmsg. I. e. put "exec > /dev/kmsg 2>&1" to the script.
This will work.
But I still don't like this.

This is the workaround I would suggest, as DRM panic can only access the kmsg data, and has no knowledge of what fbcon was doing.

If the panic occurs because the PID 1 script exits, then the panic stack trace is not that relevant?

Another thing you can try, is to use DRM log instead of fbcon:

DRM_CLIENT_LOG=y
DRM_CLIENT_DEFAULT_LOG=y
DRM_FBDEV_EMULATION=n
DRM_CLIENT_DEFAULT="log"
DRM_PANIC=n

(and boot with console=drm_log)

drm-log doesn't scroll the whole screen, and use the non-blocking console API, so is less likely to make artifacts on the screen.

But in this case, you won't get the panic trace.

Best regards,

Signature · 1 line
Jocelyn
Quoted 5 lines

--
Askar Safin
https://types.pl/@safinaskar