Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH 0/2] fbcon: Fix segfault on re-orientation
@ 2026-11-26 16:23 Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Zimmermann @ 2026-11-26 16:23 UTC (permalink / raw)
  To: deller, simona; +Cc: dri-devel, linux-fbdev, sashiko-reviews, Thomas Zimmermann

fbcon_init() re-rotates the console even when initializing a hidden
console. The rotated console then accesses its screen buffer with
regular bit ops. This results in a segmentation fault. Fix this by
resetting rotation only on new and visible consoles.

The problem can be reproduced by rotating the console on bochs and
shutting down the system. When plymouth opens the terminal, it
triggers the crash.

Patch 1 fixes the bug. I used an LLM to debug the issue and create
the fix. This goes first to simplify backporting.

Patch 2 slightly refactors the fix.

Thomas Zimmermann (2):
  fbcon: Don't change shared blitting state for hidden consoles
  fbcon: Provide a single implementation of fbcon_set_rotation()

 drivers/video/fbdev/core/fbcon.c | 43 ++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 16 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles
  2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
@ 2026-11-26 16:23 ` Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Zimmermann @ 2026-11-26 16:23 UTC (permalink / raw)
  To: deller, simona; +Cc: dri-devel, linux-fbdev, sashiko-reviews, Thomas Zimmermann

All consoles on a framebuffer share par->rotate and par->bitops.
fbcon_init() calls set_blitting_type() for each new console, which
resets both to the new console's rotation. If the visible console is
rotated, it then keeps its rotated rows and columns but draws with
unrotated bitops. The next cursor update or scroll writes beyond the
framebuffer and oopses, e.g. at shutdown when plymouthd opens a new
VT:

  BUG: unable to handle page fault for address: ffffd2ce80bd5000
  RIP: 0010:sys_imageblit+0x707/0x7e0
   soft_cursor+0x1a4/0x250
   bit_cursor+0x3ab/0x550
   hide_cursor+0x27/0xb0

Only call set_blitting_type() from fbcon_init() for the visible console
or when the fbcon state was just created. Compute a new console's rows
and columns from its own rotation instead of par->rotate, so that it
doesn't inherit the visible console's geometry.

Tested on QEMU with console 0 rotated by 90 degrees. Other rotations
and rotate_all are untested.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/core/fbcon.c | 38 +++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index d7890e119dc7..7e39c40abe88 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -197,15 +197,20 @@ static void fbcon_set_all_vcs(struct fb_info *info);
 static struct device *fbcon_device;
 
 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
+/* Returns the rotation that a console uses when it is displayed. */
+static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon_display *p)
+{
+	if (!(info->flags & FBINFO_MISC_TILEBLITTING) && p->con_rotate < 4)
+		return p->con_rotate;
+
+	return FB_ROTATE_UR;
+}
+
 static inline void fbcon_set_rotation(struct fb_info *info)
 {
 	struct fbcon_par *par = info->fbcon_par;
 
-	if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
-	    par->p->con_rotate < 4)
-		par->rotate = par->p->con_rotate;
-	else
-		par->rotate = 0;
+	par->rotate = fbcon_display_rotation(info, par->p);
 }
 
 static void fbcon_rotate(struct fb_info *info, u32 rotate)
@@ -253,6 +258,11 @@ static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
 	fbcon_set_all_vcs(info);
 }
 #else
+static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon_display *p)
+{
+	return FB_ROTATE_UR;
+}
+
 static inline void fbcon_set_rotation(struct fb_info *info)
 {
 	struct fbcon_par *par = info->fbcon_par;
@@ -1105,6 +1115,8 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	struct vc_data *svc = *default_mode;
 	struct fbcon_display *t, *p = &fb_display[vc->vc_num];
 	int logo = 1, new_rows, new_cols, rows, cols;
+	bool new_par = false;
+	int rotate;
 	int ret;
 
 	if (WARN_ON(info_idx == -1))
@@ -1125,9 +1137,11 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	if (var_to_display(p, &info->var, info))
 		return;
 
-	if (!info->fbcon_par)
+	if (!info->fbcon_par) {
 		if (con2fb_acquire_newinfo(vc, info, vc->vc_num))
 			return;
+		new_par = true;
+	}
 
 	/* If we are not the first console on this
 	   fb, copy the font from that console */
@@ -1185,12 +1199,15 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	if (p->con_rotate == -1)
 		p->con_rotate = FB_ROTATE_UR;
 
-	set_blitting_type(vc, info);
+	if (new_par || con_is_visible(vc))
+		set_blitting_type(vc, info);
 
 	cols = vc->vc_cols;
 	rows = vc->vc_rows;
-	new_cols = FBCON_SWAP(par->rotate, info->var.xres, info->var.yres);
-	new_rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
+	/* Use the console's own rotation; par->rotate belongs to the visible one. */
+	rotate = fbcon_display_rotation(info, p);
+	new_cols = FBCON_SWAP(rotate, info->var.xres, info->var.yres);
+	new_rows = FBCON_SWAP(rotate, info->var.yres, info->var.xres);
 	new_cols /= vc->vc_font.width;
 	new_rows /= vc->vc_font.height;
 
@@ -1238,7 +1255,8 @@ static void fbcon_init(struct vc_data *vc, bool init)
 	if (logo)
 		fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
 
-	if (par->bitops->rotate_font && par->bitops->rotate_font(info, vc)) {
+	if ((new_par || con_is_visible(vc)) &&
+	    par->bitops->rotate_font && par->bitops->rotate_font(info, vc)) {
 		par->rotate = FB_ROTATE_UR;
 		set_blitting_type(vc, info);
 	}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation()
  2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
  2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
@ 2026-11-26 16:23 ` Thomas Zimmermann
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Zimmermann @ 2026-11-26 16:23 UTC (permalink / raw)
  To: deller, simona; +Cc: dri-devel, linux-fbdev, sashiko-reviews, Thomas Zimmermann

Merge both implmentations of fbcon_set_rotation() into one. In the
case of CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=n, fbcon_display_rotation()
returns FB_ROTATE_UR. So the new code is equivalent to the existing
code.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/video/fbdev/core/fbcon.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 7e39c40abe88..08712611e333 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -206,13 +206,6 @@ static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon
 	return FB_ROTATE_UR;
 }
 
-static inline void fbcon_set_rotation(struct fb_info *info)
-{
-	struct fbcon_par *par = info->fbcon_par;
-
-	par->rotate = fbcon_display_rotation(info, par->p);
-}
-
 static void fbcon_rotate(struct fb_info *info, u32 rotate)
 {
 	struct fbcon_par *par = info->fbcon_par;
@@ -263,13 +256,6 @@ static int fbcon_display_rotation(const struct fb_info *info, const struct fbcon
 	return FB_ROTATE_UR;
 }
 
-static inline void fbcon_set_rotation(struct fb_info *info)
-{
-	struct fbcon_par *par = info->fbcon_par;
-
-	par->rotate = FB_ROTATE_UR;
-}
-
 static void fbcon_rotate(struct fb_info *info, u32 rotate)
 {
 	return;
@@ -281,6 +267,13 @@ static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
 }
 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
 
+static void fbcon_set_rotation(struct fb_info *info)
+{
+	struct fbcon_par *par = info->fbcon_par;
+
+	par->rotate = fbcon_display_rotation(info, par->p);
+}
+
 static void fbcon_set_bitops(struct fbcon_par *par)
 {
 	switch (par->rotate) {
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26 16:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
2026-11-26 16:23 ` [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles Thomas Zimmermann
2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox