Linux Framebuffer Layer development
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: deller@gmx.de, simona@ffwll.ch
Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
	sashiko-reviews@lists.linux.dev,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 1/2] fbcon: Don't change shared blitting state for hidden consoles
Date: Thu, 26 Nov 2026 17:23:10 +0100	[thread overview]
Message-ID: <20261126163150.91355-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20261126163150.91355-1-tzimmermann@suse.de>

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


  reply	other threads:[~2026-11-26 16:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:23 [PATCH 0/2] fbcon: Fix segfault on re-orientation Thomas Zimmermann
2026-11-26 16:23 ` Thomas Zimmermann [this message]
2026-11-26 16:23 ` [PATCH 2/2] fbcon: Provide a single implementation of fbcon_set_rotation() Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126163150.91355-2-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox