Skip to contentSkip to conversation

drm/panic: depends on !VT_CONSOLE

PATCH In review Jocelyn Falempe 4 participants 9 messages Jun 13, 2024 – Jul 16, 2024

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

PATCH 1/1 drm/panic: depends on !VT_CONSOLE

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
 drivers/gpu/drm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +1 -1
index a9df94291622..f5c989aed7e9 100644
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
 config DRM_PANIC
 	bool "Display a user-friendly message when a kernel panic occurs"
-	depends on DRM && !FRAMEBUFFER_CONSOLE
+	depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)
 	select DRM_KMS_HELPER
 	select FONT_SUPPORT
 	help

base-commit: 2bae076f3e35234e42bd7c90acd8caae8368ba90

Signature · 1 line
2.45.1
Tested-by on v1 1/1
#1 lore raw

Jocelyn Falempe <[email protected]> writes:

Hello Jocelyn,

Quoted 20 lines

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
 drivers/gpu/drm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 5 lines
drivers/gpu/drm/Kconfig +1 -1
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
 config DRM_PANIC
 	bool "Display a user-friendly message when a kernel panic occurs"
-	depends on DRM && !FRAMEBUFFER_CONSOLE
+	depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

In other words, my understanding from the discussion with Sima was that this should be instead:

+ depends on DRM && !VT_CONSOLE

I've tested that and at least I see that a framebuffer console is present and echo c > /proc/sysrq-trigger triggers the DRM panic handler message (but don't know if the race exists and is just that I was not hitting it).

If my understanding is correct and should only be a depends on !VT_CONSOLE then feel free to add my:

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#2 lore raw
Quoted 25 lines · Javier Martinez Canillas

Jocelyn Falempe <[email protected]> writes:

Hello Jocelyn,

Quoted 21 lines

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
  drivers/gpu/drm/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
Quoted 9 lines

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 4 lines
drivers/gpu/drm/Kconfig +1 -1
  config DRM_PANIC
  	bool "Display a user-friendly message when a kernel panic occurs"
-	depends on DRM && !FRAMEBUFFER_CONSOLE
+	depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

Yes, but when writing the patch, I thought that if you have VT_CONSOLE=y and FRAMEBUFFER_CONSOLE=n, then there won't be any race condition, and drm_panic can be enabled safely. I don't know if that really matters, and if VT_CONSOLE has any usage apart from fbcon.

Quoted 6 lines

In other words, my understanding from the discussion with Sima was that this should be instead:

  +	depends on DRM && !VT_CONSOLE
Quoted 9 lines

I've tested that and at least I see that a framebuffer console is present and echo c > /proc/sysrq-trigger triggers the DRM panic handler message (but don't know if the race exists and is just that I was not hitting it).

If my understanding is correct and should only be a depends on !VT_CONSOLE then feel free to add my:

Best regards,

Signature · 1 line
Jocelyn
#3 lore raw

Hi Jocelyn,

Quoted 33 lines · Jocelyn Falempe
Quoted 22 lines · Javier Martinez Canillas
Quoted 21 lines · Jocelyn Falempe

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
  drivers/gpu/drm/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
Quoted 9 lines

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 4 lines
drivers/gpu/drm/Kconfig +1 -1
  config DRM_PANIC
     bool "Display a user-friendly message when a kernel panic occurs"
-    depends on DRM && !FRAMEBUFFER_CONSOLE
+    depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

Quoted 5 lines

Yes, but when writing the patch, I thought that if you have VT_CONSOLE=y and FRAMEBUFFER_CONSOLE=n, then there won't be any race condition, and drm_panic can be enabled safely.
I don't know if that really matters, and if VT_CONSOLE has any usage apart from fbcon.

It is used for any kind of virtual terminal, so also for vgacon.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#4 lore raw
Quoted 36 lines · Geert Uytterhoeven

Hi Jocelyn,

Quoted 33 lines · Jocelyn Falempe
Quoted 31 lines · Javier Martinez Canillas
Quoted 20 lines · Jocelyn Falempe

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
   drivers/gpu/drm/Kconfig | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 5 lines
drivers/gpu/drm/Kconfig +1 -1
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
   config DRM_PANIC
      bool "Display a user-friendly message when a kernel panic occurs"
-    depends on DRM && !FRAMEBUFFER_CONSOLE
+    depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

Quoted 7 lines
Quoted 5 lines

Yes, but when writing the patch, I thought that if you have VT_CONSOLE=y and FRAMEBUFFER_CONSOLE=n, then there won't be any race condition, and drm_panic can be enabled safely.
I don't know if that really matters, and if VT_CONSOLE has any usage apart from fbcon.

It is used for any kind of virtual terminal, so also for vgacon.

Ah thanks, but I think vgacon is safe to use with drm_panic.

The problem with fbcon, is that it can also uses the fbdev emulation from the drm driver, and in this case, drm_panic will write to the same framebuffer as fbcon during a panic, leading to corrupted output. This can't occur with other graphical console, so !(FRAMEBUFFER_CONSOLE && VT_CONSOLE) is probably good.

Signature · 1 line
Jocelyn
Quoted 5 lines

Gr{oetje,eeting}s,

Geert

#5 lore raw
Quoted 45 lines · Jocelyn Falempe
Quoted 36 lines · Geert Uytterhoeven

Hi Jocelyn,

Quoted 33 lines · Jocelyn Falempe
Quoted 31 lines · Javier Martinez Canillas
Quoted 20 lines · Jocelyn Falempe

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
   drivers/gpu/drm/Kconfig | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 5 lines
drivers/gpu/drm/Kconfig +1 -1
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
   config DRM_PANIC
      bool "Display a user-friendly message when a kernel panic occurs"
-    depends on DRM && !FRAMEBUFFER_CONSOLE
+    depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

Quoted 7 lines
Quoted 5 lines

Yes, but when writing the patch, I thought that if you have VT_CONSOLE=y and FRAMEBUFFER_CONSOLE=n, then there won't be any race condition, and drm_panic can be enabled safely.
I don't know if that really matters, and if VT_CONSOLE has any usage apart from fbcon.

It is used for any kind of virtual terminal, so also for vgacon.

Quoted 8 lines

Ah thanks, but I think vgacon is safe to use with drm_panic.

The problem with fbcon, is that it can also uses the fbdev emulation from the drm driver, and in this case, drm_panic will write to the same framebuffer as fbcon during a panic, leading to corrupted output. This can't occur with other graphical console, so !(FRAMEBUFFER_CONSOLE && VT_CONSOLE) is probably good.

Yeah, I agre that !(FRAMEBUFFER_CONSOLE && VT_CONSOLE) as you have in your patch is what makes sense. !VT_CONSOLE alone as I argued in my first email isn't correct since as you pointed out, it shouldn't affect other consoles besides fbcon.

So please feel free to also add:

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#6 lore raw
Quoted 56 lines · Javier Martinez Canillas
Quoted 45 lines · Jocelyn Falempe
Quoted 36 lines · Geert Uytterhoeven

Hi Jocelyn,

Quoted 33 lines · Jocelyn Falempe
Quoted 31 lines · Javier Martinez Canillas
Quoted 20 lines · Jocelyn Falempe

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
    drivers/gpu/drm/Kconfig | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 5 lines
drivers/gpu/drm/Kconfig +1 -1
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
    config DRM_PANIC
       bool "Display a user-friendly message when a kernel panic occurs"
-    depends on DRM && !FRAMEBUFFER_CONSOLE
+    depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

Quoted 7 lines
Quoted 5 lines

Yes, but when writing the patch, I thought that if you have VT_CONSOLE=y and FRAMEBUFFER_CONSOLE=n, then there won't be any race condition, and drm_panic can be enabled safely.
I don't know if that really matters, and if VT_CONSOLE has any usage apart from fbcon.

It is used for any kind of virtual terminal, so also for vgacon.

Quoted 8 lines

Ah thanks, but I think vgacon is safe to use with drm_panic.

The problem with fbcon, is that it can also uses the fbdev emulation from the drm driver, and in this case, drm_panic will write to the same framebuffer as fbcon during a panic, leading to corrupted output. This can't occur with other graphical console, so !(FRAMEBUFFER_CONSOLE && VT_CONSOLE) is probably good.

Quoted 9 lines

Yeah, I agre that !(FRAMEBUFFER_CONSOLE && VT_CONSOLE) as you have in your patch is what makes sense. !VT_CONSOLE alone as I argued in my first email isn't correct since as you pointed out, it shouldn't affect other consoles besides fbcon.

So please feel free to also add:

Thanks all for your comments and reviews.

I just pushed it to drm-misc-next.

Signature · 1 line
Jocelyn
#7 lore raw
In reply to Jocelyn Falempe
Quoted 36 lines · Jocelyn Falempe
Quoted 25 lines · Javier Martinez Canillas

Jocelyn Falempe <[email protected]> writes:

Hello Jocelyn,

Quoted 21 lines

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

---
  drivers/gpu/drm/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +0 -0
index a9df94291622..f5c989aed7e9 100644
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
Quoted 9 lines

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 110

Quoted 4 lines
drivers/gpu/drm/Kconfig +1 -1
  config DRM_PANIC
  	bool "Display a user-friendly message when a kernel panic occurs"
-	depends on DRM && !FRAMEBUFFER_CONSOLE
+	depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)

I thought the idea was to only make it depend on !VT_CONSOLE, so that distros could also enable fbcon / VT but prevent the race condition to happen due the VT not being a system console for the kernel to print messages ?

Quoted 3 lines

Yes, but when writing the patch, I thought that if you have VT_CONSOLE=y and FRAMEBUFFER_CONSOLE=n, then there won't be any race condition, and drm_panic can be enabled safely.

Ah, I see what you mean.

Quoted 3 lines

I don't know if that really matters, and if VT_CONSOLE has any usage apart from fbcon.

Right. I don't know...

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#8 lore raw
In reply to Jocelyn Falempe
Quoted 8 lines · EDT Jocelyn Falempe

The race condition between fbcon and drm_panic can only occurs if VT_CONSOLE is set. So update drm_panic dependency accordingly. This will make it easier for Linux distributions to enable drm_panic by disabling VT_CONSOLE, and keeping fbcon terminal.
The only drawback is that fbcon won't display the boot kmsg, so it should rely on userspace to do that.
At least plymouth already handle this case with
https://gitlab.freedesktop.org/plymouth/plymouth/-/merge_requests/224

Hi

An FYI, seeing this and https://fedoraproject.org/wiki/Changes/EnableDrmPanic , there is a slight issue with CONFIG_VT_CONSOLE=n in relation to systemd that was recently discovered outside of virt-manager VMs, (or computers that have no devices connected to the first serial port)

This was seen on a full CONFIG_VT=n kernel, but it also happens on kernels with just CONFIG_VT_CONSOLE disabled.

When /dev/console is /dev/ttyS0 (as that is the new default without the VT console, and /dev/ttyS0 is not connected to anything, isatty()'s TCGETS ioctl on /dev/console results in an input output error, causing isatty() to return false. Because of this, systemd's status logging then rejects /dev/console as not being a terminal device, and rejects writing status output to it, resulting in a decrease of verbosity available to Plymouth.

It at first did not show up in my testing, because all my virt-manager and qemu VMs had serial devices attached, which would cause isatty() to return true on /dev/ttyS0 backed /dev/console, but now I have raised this with linux-serial.

Thanks

Quoted 23 lines
---
 drivers/gpu/drm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/Kconfig +1 -1
index a9df94291622..f5c989aed7e9 100644
@@ -107,7 +107,7 @@ config DRM_KMS_HELPER
 
 config DRM_PANIC
 	bool "Display a user-friendly message when a kernel panic occurs"
-	depends on DRM && !FRAMEBUFFER_CONSOLE
+	depends on DRM && !(FRAMEBUFFER_CONSOLE && VT_CONSOLE)
 	select DRM_KMS_HELPER
 	select FONT_SUPPORT
 	help

base-commit: 2bae076f3e35234e42bd7c90acd8caae8368ba90