From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy2-f5.google.com (mail-dy2-f5.google.com [74.125.229.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B387E2D97BA for ; Fri, 16 Oct 2026 07:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792135861; cv=none; b=tAGpJNfK1zfp2zsbAJwifwBrj6YqOMS2aEA3xzRnnG5ipitfgFkN7aRz0Y10ePvvNwIDfBXna+KnDtNM6shaRd1LwfABpKg3CA4O4VSpR7isjA7pi+CMM0R7dILAUqa+gI4Acdoz20DVSyVxCDRrp9VJG95NTaXLMKo1LFOWxEA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792135861; c=relaxed/simple; bh=QWhK+UeEzM2oEDWzEmpI/fGm08uGiHZDRKWGDSbcnBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KnFnqmqxJkThpTZuGdtLgfssIx78pWxm4LfYjkzckLZOGmmS+BIFFZy4R5zqjnNnZUHrDN2Ezd2/F9wCVr4+LnsZ1NIYU/5vfiTHSRmRknRTM8w/eCIzM54BZrnTGfvSANx9f5fryksVerM6aRCa5wy/sI5Y928Hy3NGgX+P38Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W2I73NMI; arc=none smtp.client-ip=74.125.229.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W2I73NMI" Received: by mail-dy2-f5.google.com with SMTP id 5a478bee46e88-3535a54c09bso3016683eec.0 for ; Fri, 16 Oct 2026 00:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792135858; x=1792740658; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=K9RBwK9DMLq2lboW1315UiNuKOkVh7UxaSWlYUZP2q4=; b=W2I73NMIzinF6wM6cDFP6lrhp0WRWskiF0+gJoT+kyNpOYr7g7pbTtOxBvfahcYxMA G+TW8fdvOrhFLxjLqOOUtvzAZAL/KC0XRnplF7Ice9ELn3lINhommX4gX1Zf70FqFb6G XRZbEEdCP30eObj4lElQdlgdqfY5N+lky3tWLG9H7CKqgtETsCKwspy/R6rP5uodIwyM lCnb65SP9hem2OBAgPl295QH3LB3VDGwBbNOM+NnH8HQHIKSvyFnIOr2IZKXyKkgwd0o gIVauLVZF04wSXmwux+2b/yhpF0raLZd6lOiuI8g28jt8jbqKXh6oqDeKFOX2jhTGgcp mAeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792135858; x=1792740658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=K9RBwK9DMLq2lboW1315UiNuKOkVh7UxaSWlYUZP2q4=; b=nOP48yu8XQV/H5kkaPRi4q3cUXyfB2yoUFIXPWzOuQHNQT9jaMFo9J102eBFE6baDb tLQluQIgARMjJfCTA7TrT9MDElbDcdsHTFzfX6cbTw/8jQE36WUTphcr6pUBZI6mGpCA f+gIH8lf5D5cANsYie6Gee1jto4qfqkgVvy12QX2+ENBwTNs/AWHjQGC+/p4KTGPKeG5 pW6+Aq7C6+o1B9xsVjMvGIW5g4Mv1Ns2dK55hukxmZZUZfOIaHvbW8NLMmYvkD11qKTr fUVqF9RqywqN2Rkrk1LNLInAcRroureePTT/JF7vAs4dXHxLCaq2Wqe5nyqUPh16ASzz 9rzg== X-Forwarded-Encrypted: i=1; AKwUvBy9tsVJwY+yKaXcdA+6spDIdNCVpU9aNwjacVMrwJmPQvww5dSO7Y0ChAal8DklTY23utTVi0FKev6YG90=@vger.kernel.org X-Gm-Message-State: AFq9FYI6g9CZilWpOrMl+a0hbFh7jw0dQvaCzg//GX8SqfStZOlYAQY4 s3RtPoWrpF26/kdsLodiok9eWFcINDUN19759zMbaspXwUP5tCcgMjMU X-Gm-Gg: AYBFou3+KmbzWIShC5wzrxyeN47KykAYtMoKZ3LURsO/j3U5cZbHDX5e6+IB64fxRzj 7CHGuBDDd09ciKF+nAnE/wlEJVkGIfVv7sdwJDkwlg8huxW3uaVm0L1lsyfzKnj3qEr4JcVt59i t3lQ3SAXrIj3WqJdjmwYauGOOVFUbddy2L31oAyzWx4MxMX8W6Lra7OrgrA68G0BURF9Lv2Jj6G W4Ut7hbFjLDNYRSsHyzzp9BPUf3aIVODNZx92GEimAD0ZHVyedmgA3MN1ta4WYS1FfKsNjETRdG FS84VmpP0a2WmdJHTrxF7fhAK1xSNZIDEejYHeZQrz95jmYLZAO7WjNaMmfd4CsC6ub5dAVnOk0 pm0z/0BhjxhcwUe+kqUqlTL2Bc4Jj7otdVwRBY5DHqdWbdNdSn+DCFilAv+xrdaFHk6+iXjBLYp Ik1Np26+n1EGwb3yUtsBl1kXE51aE5nNzUX+5KPZthTPi5IaB+ROGMbXl2fwRoHzOWhsFL2p5MU M+UMLDhjYGcjigY+Sdll1ee5AyPxkkqrgE= X-Received: by 2002:a05:7022:5f04:b0:17d:961d:7db0 with SMTP id a92af1059eb24-17d961d7e11mr8510456c88.28.1792135857744; Fri, 16 Oct 2026 00:30:57 -0700 (PDT) Received: from blue.tailcc13ef.ts.net (104.194.64.109.16clouds.com. [104.194.64.109]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1831a6f58c2sm5367021c88.11.2026.10.16.00.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2026 00:30:54 -0700 (PDT) From: Yao Yiqi To: deller@gmx.de, tzimmermann@suse.de, simona@ffwll.ch Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, yaoyiqi3@huawei.com, Yao Yiqi , stable@vger.kernel.org Subject: [PATCH v3 1/3] fbcon: Include font geometry in the rotated font cache Date: Fri, 16 Oct 2026 15:30:21 +0800 Message-ID: <20261016073023.490430-2-yyaqia@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261016073023.490430-1-yyaqia@gmail.com> References: <20261016073023.490430-1-yyaqia@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Yao Yiqi fbcon_rotate_font() caches a rotated copy of the console font in par->rotated.buf and skips the rebuild when the cache appears to be up to date. The cache is keyed on the source font's data pointer and the rotation alone, on the assumption that an unchanged fontdata pointer implies an unchanged font. That assumption does not hold. Raw font data (font_data_t) stores no glyph geometry; width, height and charcount are tracked separately in vc->vc_font. When a font is uploaded, fbcon_set_font() deduplicates it against the fonts of all consoles with font_data_is_equal(), which compares only the byte count, the checksum and the raw bytes. Two uploads of the same data that declare different dimensions therefore end up sharing one font_data_t, and a console can install a new geometry while its fontdata pointer stays the same. The early-out in fbcon_rotate_font() then skips the rebuild, and the rotated blitting routines index the stale buffer with cell sizes computed from the new geometry: src = par->rotated.buf + (scr_readw(s) & charmask) * cellsize; Rotation swaps a glyph's width and height, so the size of the rotated cell depends on pitch rounding and differs between geometries. A 4x16 font whose 4096 bytes are re-uploaded as 16x8 on a CW-rotated console, for example, grows the rotated cell size from 8 to 16 bytes, and the largest character then reads past the end of the 2048-byte buffer that was built for the 4x16 geometry. The key has never included the geometry. Its exposure was limited, but not eliminated, while the deduplication in fbcon_set_font() also compared the consoles' font widths and total byte counts: with the charcount restricted to 256 or 512, differing uploads could then only trade height against charcount (such as 4x18x256 against 4x9x512), and even those can change the rotated cell size. Commit 1e3c49aa03fb ("lib/fonts: Compare font data for equality with font_data_is_equal()") dropped the width comparison, so identical bytes now share font data across arbitrary dimensions. Record the geometry that the buffer was built from and compare it in the early-out, so a geometry change always triggers a rebuild. Fixes: 6cc50e1c5b57 ("[PATCH] fbcon: Console Rotation - Add support to rotate font bitmap") Cc: stable@vger.kernel.org Signed-off-by: Yao Yiqi --- drivers/video/fbdev/core/fbcon.h | 9 ++++++--- drivers/video/fbdev/core/fbcon_rotate.c | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fbcon.h index 407d207b14f1..bfbd70f8b1cd 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -89,10 +89,13 @@ struct fbcon_par { char *cursor_data; #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION struct { - font_data_t *fontdata; /* source font */ - u8 *buf; /* rotated glyphs */ + font_data_t *fontdata; /* source font */ + u8 *buf; /* rotated glyphs */ size_t bufsize; - int buf_rotate; /* rotation of buf */ + int buf_rotate; /* rotation of buf */ + unsigned int buf_width; /* geometry of source font */ + unsigned int buf_height; + unsigned int buf_charcount; } rotated; #endif u8 *cursor_src; diff --git a/drivers/video/fbdev/core/fbcon_rotate.c b/drivers/video/fbdev/core/fbcon_rotate.c index 6cdbc96eeca6..660a3fa81bae 100644 --- a/drivers/video/fbdev/core/fbcon_rotate.c +++ b/drivers/video/fbdev/core/fbcon_rotate.c @@ -21,11 +21,18 @@ int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc) unsigned char *buf; int ret; - if (par->p->fontdata == par->rotated.fontdata && par->rotate == par->rotated.buf_rotate) + if (par->p->fontdata == par->rotated.fontdata && + par->rotate == par->rotated.buf_rotate && + vc->vc_font.width == par->rotated.buf_width && + vc->vc_font.height == par->rotated.buf_height && + vc->vc_font.charcount == par->rotated.buf_charcount) return 0; par->rotated.fontdata = par->p->fontdata; par->rotated.buf_rotate = par->rotate; + par->rotated.buf_width = vc->vc_font.width; + par->rotated.buf_height = vc->vc_font.height; + par->rotated.buf_charcount = vc->vc_font.charcount; if (info->fbops->fb_sync) info->fbops->fb_sync(info); -- 2.56.0