Skip to contentSkip to conversation

console/fbcon: Add support for deferred console takeover

PATCH Superseded Hans de Goede 4 participants 11 messages Jun 26, 2018

Subsystems (6)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover console/fbcon: Add support for deferred console takeover

Hi All,

Here is v3 of my patch, now patch-set, to delay fbcon taking over the console (and binding to fbdev devices) until there actually is some text output to the console. This is intended for use with the "quiet" cmdline option, in combination with a bootloader which leaves the vendor's logo / EFI bootgraphics put up by the firmware intact on the EFI framebuffer.

The end goal here is a boot where the firmware shows its boot graphics and these stay in place for a couple of seconds until the GUI loads and the GUI then smoothly takes over the framebuffer without any distruptions.

New in v3 are the following changes:
-Export is_console_locke() for use in modules (as fbcon may be built as a .ko) -Use WARN_CONSOLE_UNLOCKED() in several places in the fbcon code to assert
proper locking (requested by Daniel)
-Unregister the fbcon-dummycon-output-notifier on fbcon_exit() (req. by Daniel) -Document the fbcon=nodefer commandline option (req. by Emil)

These changes mean that this patch-set now spans 2 subsystems.

Petr, the printk subsys change is really trivial (1 line addition) can we get your Acked-by for merging all 3 patches through the fbdev tree?

Regards,

Hans

#1 lore raw

PATCH v3 1/3 printk: Export is_console_locked

This is a preparation patch for adding a number of WARN_CONSOLE_UNLOCKED() calls to the fbcon code, which may be built as a module (event though usually it is not).

---
Changes in v3:
-New patch in v3 of this patchset

---
 kernel/printk/printk.c | 1 +
 1 file changed, 1 insertion(+)
kernel/printk/printk.c +1 -0
index 247808333ba4..3f041e7cbfc9 100644
@@ -2243,6 +2243,7 @@ int is_console_locked(void)
 {
 	return console_locked;
 }
+EXPORT_SYMBOL(is_console_locked);
 
 /*
  * Check if we have any console that is capable of printing while cpu is
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/3 fbcon: Call WARN_CONSOLE_UNLOCKED() where applicable

In reply to Hans de Goede

Replace comments about places where the console lock should be held with calls to WARN_CONSOLE_UNLOCKED() to assert that it is actually held.

---
Changes in v3:
-New patch in v3 of this patchset

---
 drivers/video/fbdev/core/fbcon.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/video/fbdev/core/fbcon.c +11 -7
index c910e74d46ff..ac2cbdf710ee 100644
@@ -817,8 +817,6 @@ static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
  *
  *	Maps a virtual console @unit to a frame buffer device
  *	@newidx.
- *
- *	This should be called with the console lock held.
  */
 static int set_con2fb_map(int unit, int newidx, int user)
 {
@@ -828,6 +826,8 @@ static int set_con2fb_map(int unit, int newidx, int user)
 	struct fb_info *oldinfo = NULL;
  	int found, err = 0;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	if (oldidx = newidx)
 		return 0;
 
@@ -3039,11 +3039,12 @@ static inline int fbcon_unbind(void)
 }
 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
 
-/* called with console_lock held */
 static int fbcon_fb_unbind(int idx)
 {
 	int i, new_idx = -1, ret = 0;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	if (!fbcon_has_console_bind)
 		return 0;
 
@@ -3089,11 +3090,12 @@ static int fbcon_fb_unbind(int idx)
 	return ret;
 }
 
-/* called with console_lock held */
 static int fbcon_fb_unregistered(struct fb_info *info)
 {
 	int i, idx;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	idx = info->node;
 	for (i = first_fb_vc; i <= last_fb_vc; i++) {
 		if (con2fb_map[i] = idx)
@@ -3127,10 +3129,12 @@ static int fbcon_fb_unregistered(struct fb_info *info)
 	return 0;
 }
 
-/* called with console_lock held */
 static void fbcon_remap_all(int idx)
 {
 	int i;
+
+	WARN_CONSOLE_UNLOCKED();
+
 	for (i = first_fb_vc; i <= last_fb_vc; i++)
 		set_con2fb_map(i, idx, 0);
 
@@ -3172,11 +3176,12 @@ static inline void fbcon_select_primary(struct fb_info *info)
 }
 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
 
-/* called with console_lock held */
 static int fbcon_fb_registered(struct fb_info *info)
 {
 	int ret = 0, i, idx;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	idx = info->node;
 	fbcon_select_primary(info);
 
@@ -3325,7 +3330,6 @@ static int fbcon_event_notify(struct notifier_block *self,
 		ret = fbcon_fb_unregistered(info);
 		break;
 	case FB_EVENT_SET_CONSOLE_MAP:
-		/* called with console lock held */
 		con2fb = event->data;
 		ret = set_con2fb_map(con2fb->console - 1,
 				     con2fb->framebuffer, 1);
Signature · 1 line
2.17.1
Reviewed-by on v3 2/3
#3 lore raw

Re: [PATCH v3 2/3] fbcon: Call WARN_CONSOLE_UNLOCKED() where applicable

Quoted 7 lines · Hans de Goede

Replace comments about places where the console lock should be held with calls to WARN_CONSOLE_UNLOCKED() to assert that it is actually held.

---
Changes in v3:
-New patch in v3 of this patchset

For patches 1&2:

Quoted 97 lines
---
 drivers/video/fbdev/core/fbcon.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/video/fbdev/core/fbcon.c +11 -7
index c910e74d46ff..ac2cbdf710ee 100644
@@ -817,8 +817,6 @@ static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
  *
  *	Maps a virtual console @unit to a frame buffer device
  *	@newidx.
- *
- *	This should be called with the console lock held.
  */
 static int set_con2fb_map(int unit, int newidx, int user)
 {
@@ -828,6 +826,8 @@ static int set_con2fb_map(int unit, int newidx, int user)
 	struct fb_info *oldinfo = NULL;
  	int found, err = 0;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	if (oldidx = newidx)
 		return 0;
 
@@ -3039,11 +3039,12 @@ static inline int fbcon_unbind(void)
 }
 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
 
-/* called with console_lock held */
 static int fbcon_fb_unbind(int idx)
 {
 	int i, new_idx = -1, ret = 0;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	if (!fbcon_has_console_bind)
 		return 0;
 
@@ -3089,11 +3090,12 @@ static int fbcon_fb_unbind(int idx)
 	return ret;
 }
 
-/* called with console_lock held */
 static int fbcon_fb_unregistered(struct fb_info *info)
 {
 	int i, idx;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	idx = info->node;
 	for (i = first_fb_vc; i <= last_fb_vc; i++) {
 		if (con2fb_map[i] = idx)
@@ -3127,10 +3129,12 @@ static int fbcon_fb_unregistered(struct fb_info *info)
 	return 0;
 }
 
-/* called with console_lock held */
 static void fbcon_remap_all(int idx)
 {
 	int i;
+
+	WARN_CONSOLE_UNLOCKED();
+
 	for (i = first_fb_vc; i <= last_fb_vc; i++)
 		set_con2fb_map(i, idx, 0);
 
@@ -3172,11 +3176,12 @@ static inline void fbcon_select_primary(struct fb_info *info)
 }
 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
 
-/* called with console_lock held */
 static int fbcon_fb_registered(struct fb_info *info)
 {
 	int ret = 0, i, idx;
 
+	WARN_CONSOLE_UNLOCKED();
+
 	idx = info->node;
 	fbcon_select_primary(info);
 
@@ -3325,7 +3330,6 @@ static int fbcon_event_notify(struct notifier_block *self,
 		ret = fbcon_fb_unregistered(info);
 		break;
 	case FB_EVENT_SET_CONSOLE_MAP:
-		/* called with console lock held */
 		con2fb = event->data;
 		ret = set_con2fb_map(con2fb->console - 1,
 				     con2fb->framebuffer, 1);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#4 lore raw

Re: [PATCH v3 2/3] fbcon: Call WARN_CONSOLE_UNLOCKED() where applicable

In reply to Hans de Goede
Quoted 2 lines · On Tue, 26 Jun 2018 15:55:34 +0200 Hans de Goede <[email protected]> wrote:

Replace comments about places where the console lock should be held with calls to WARN_CONSOLE_UNLOCKED() to assert that it is actually held.

Why replace the comments? I prefer them, even with the WARN. The reason is, when using functions, I don't tend to look inside the function I'm about to use, but instead, I expect the comment above the function to have basic information I need to use it. Especially what locks are expected to be held.

Please keep the comments in place, but the WARNs are fine. They are not a replacement for the comments.

Nack on removing comments.

-- Steve

#5 lore raw

Re: [PATCH v3 2/3] fbcon: Call WARN_CONSOLE_UNLOCKED() where applicable

Hi,

Quoted 12 lines · Steven Rostedt
Quoted 2 lines · On Tue, 26 Jun 2018 15:55:34 +0200 Hans de Goede <[email protected]> wrote:

Replace comments about places where the console lock should be held with calls to WARN_CONSOLE_UNLOCKED() to assert that it is actually held.

Why replace the comments? I prefer them, even with the WARN. The reason is, when using functions, I don't tend to look inside the function I'm about to use, but instead, I expect the comment above the function to have basic information I need to use it. Especially what locks are expected to be held.

Quoted 4 lines

Please keep the comments in place, but the WARNs are fine. They are not a replacement for the comments.

Nack on removing comments.

Ok, I will submit a v4 with the comments left in place.

Regards,

Hans

#6 lore raw

PATCH v3 3/3 console/fbcon: Add support for deferred console takeover

In reply to Hans de Goede

Currently fbcon claims fbdevs as soon as they are registered and takes over the console as soon as the first fbdev gets registered.

This behavior is undesirable in cases where a smooth graphical bootup is desired, in such cases we typically want the contents of the framebuffer (typically a vendor logo) to stay in place as is.

The current solution for this problem (on embedded systems) is to not enable fbcon.

This commit adds a new FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER config option, which when enabled defers fbcon taking over the console from the dummy console until the first text is displayed on the console. Together with the "quiet" kernel commandline option, this allows fbcon to still be used together with a smooth graphical bootup, having it take over the console as soon as e.g. an error message is logged.

---
Changes in v2:
-Check the whole string when checking for erases in putcs, instead of just
the first char
-Make dummycon_blank return 1, so that a redraw gets triggered and any text
rendered while blanked gets output so that it can trigger a deferred takeover if one is pending

Changes in v3:
-Call WARN_CONSOLE_UNLOCKED() from fbcon_output_notifier() -Unregister the notifier on fbcon_exit()
-Document the fbcon=nodefer commandline option in Documentation/fb/fbcon.txt

---
 Documentation/fb/fbcon.txt       |  7 ++++
 drivers/video/console/Kconfig    | 11 +++++
 drivers/video/console/dummycon.c | 67 +++++++++++++++++++++++++----
 drivers/video/fbdev/core/fbcon.c | 72 ++++++++++++++++++++++++++++++++
 include/linux/console.h          |  5 +++
 5 files changed, 154 insertions(+), 8 deletions(-)
Documentation/fb/fbcon.txt +7 -0
index 79c22d096bbc..d4d642e1ce9c 100644
@@ -155,6 +155,13 @@ C. Boot options
 	used by text. By default, this area will be black. The 'color' value
 	is an integer number that depends on the framebuffer driver being used.
 
+6. fbcon=nodefer
+
+	If the kernel is compiled with deferred fbcon takeover support, normally
+	the framebuffer contents, left in place by the firmware/bootloader, will
+	be preserved until there actually is some text is output to the console.
+	This option causes fbcon to bind immediately to the fbdev device.
+
 C. Attaching, Detaching and Unloading
 
 Before going on how to attach, detach and unload the framebuffer console, an
drivers/video/console/Kconfig +11 -0
index 4110ba7d7ca9..e91edef98633 100644
@@ -150,6 +150,17 @@ config FRAMEBUFFER_CONSOLE_ROTATION
          such that other users of the framebuffer will remain normally
          oriented.
 
+config FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
+	bool "Framebuffer Console Deferred Takeover"
+	depends on FRAMEBUFFER_CONSOLE=y && DUMMY_CONSOLE=y
+	help
+	  If enabled this defers the framebuffer console taking over the
+	  console from the dummy console until the first text is displayed on
+	  the console. This is useful in combination with the "quiet" kernel
+	  commandline option to keep the framebuffer contents initially put up
+	  by the firmware in place, rather then replacing the contents with a
+	  black screen as soon as fbcon loads.
+
 config STI_CONSOLE
         bool "STI text console"
 	depends on PARISC && HAS_IOMEM
drivers/video/console/dummycon.c +59 -8

85 lines not on this page · raw message

drivers/video/fbdev/core/fbcon.c +72 -0

116 lines not on this page · raw message

include/linux/console.h +5 -0
index dfd6b0e97855..f59f3dbca65c 100644
@@ -21,6 +21,7 @@ struct console_font_op;
 struct console_font;
 struct module;
 struct tty_struct;
+struct notifier_block;
 
 /*
  * this is what the terminal answers to a ESC-Z or csi0c query.
@@ -220,4 +221,8 @@ static inline bool vgacon_text_force(void) { return false; }
 
 extern void console_init(void);
 
+/* For deferred console takeover */
+void dummycon_register_output_notifier(struct notifier_block *nb);
+void dummycon_unregister_output_notifier(struct notifier_block *nb);
+
 #endif /* _LINUX_CONSOLE_H */
Signature · 1 line
2.17.1
#7 lore raw
Quoted 17 lines · Hans de Goede

Currently fbcon claims fbdevs as soon as they are registered and takes over the console as soon as the first fbdev gets registered.

This behavior is undesirable in cases where a smooth graphical bootup is desired, in such cases we typically want the contents of the framebuffer (typically a vendor logo) to stay in place as is.

The current solution for this problem (on embedded systems) is to not enable fbcon.

This commit adds a new FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER config option, which when enabled defers fbcon taking over the console from the dummy console until the first text is displayed on the console. Together with the "quiet" kernel commandline option, this allows fbcon to still be used together with a smooth graphical bootup, having it take over the console as soon as e.g. an error message is logged.

drivers/video/fbdev/core/fbcon.c static int fbcon_init_device(void) · line 3608

Quoted 4 lines
drivers/video/fbdev/core/fbcon.c +4 -0
+       for (i = 0; i < FB_MAX; i++) {
+               if (registered_fb[i])
+                       fbcon_fb_registered(registered_fb[i]);
+       }

Simple git grep shows that we perhaps do

#define for_each_registered_fbcon(i) ...

(As an example see for_each_pci_bridge() how it's done there)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 10 lines · Andy Shevchenko

drivers/video/fbdev/core/fbcon.c static int fbcon_init_device(void) · line 3608

Quoted 4 lines · Hans de Goede
drivers/video/fbdev/core/fbcon.c +4 -0
+       for (i = 0; i < FB_MAX; i++) {
+               if (registered_fb[i])
+                       fbcon_fb_registered(registered_fb[i]);
+       }

Simple git grep shows that we perhaps do

#define for_each_registered_fbcon(i) ...

(Or just ..._fb() since it looks like iteration over framebuffers, not exactly consoles)

Quoted 2 lines

(As an example see for_each_pci_bridge() how it's done there)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
In reply to Andy Shevchenko

Hi,

Quoted 23 lines · Andy Shevchenko
Quoted 17 lines · Hans de Goede

Currently fbcon claims fbdevs as soon as they are registered and takes over the console as soon as the first fbdev gets registered.

This behavior is undesirable in cases where a smooth graphical bootup is desired, in such cases we typically want the contents of the framebuffer (typically a vendor logo) to stay in place as is.

The current solution for this problem (on embedded systems) is to not enable fbcon.

This commit adds a new FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER config option, which when enabled defers fbcon taking over the console from the dummy console until the first text is displayed on the console. Together with the "quiet" kernel commandline option, this allows fbcon to still be used together with a smooth graphical bootup, having it take over the console as soon as e.g. an error message is logged.

drivers/video/fbdev/core/fbcon.c static int fbcon_init_device(void) · line 3608

Quoted 4 lines
drivers/video/fbdev/core/fbcon.c +4 -0
+       for (i = 0; i < FB_MAX; i++) {
+               if (registered_fb[i])
+                       fbcon_fb_registered(registered_fb[i]);
+       }
Quoted 5 lines

Simple git grep shows that we perhaps do

#define for_each_registered_fbcon(i) ...

(As an example see for_each_pci_bridge() how it's done there)

This is probably a worthwhile cleanup for all the fbdev related code / drivers. But outside of the scope of this patchset.

Regards,

Hans

#10 lore raw
Quoted 7 lines · Hans de Goede
Quoted 7 lines

drivers/video/fbdev/core/fbcon.c static int fbcon_init_device(void) · line 3608

Quoted 4 lines
drivers/video/fbdev/core/fbcon.c +4 -0
+       for (i = 0; i < FB_MAX; i++) {
+               if (registered_fb[i])
+                       fbcon_fb_registered(registered_fb[i]);
+       }

Simple git grep shows that we perhaps do

Quoted 7 lines
Quoted 3 lines

#define for_each_registered_fbcon(i) ...

(As an example see for_each_pci_bridge() how it's done there)

This is probably a worthwhile cleanup for all the fbdev related code / drivers. But outside of the scope of this patchset.

True.

Yisheng, in case you are interested in doing such clean up...

Signature · 2 lines
With Best Regards,
Andy Shevchenko