Skip to content

[Deepin-Kernel-SIG] [linux 6.18.y] [AOSC] FROMEXT: cjktty-6.16.patch#1518

Merged
opsiff merged 1 commit intodeepin-community:linux-6.18.yfrom
opsiff:linux-6.18.y-2026-03-12-cjktty
Mar 2, 2026
Merged

[Deepin-Kernel-SIG] [linux 6.18.y] [AOSC] FROMEXT: cjktty-6.16.patch#1518
opsiff merged 1 commit intodeepin-community:linux-6.18.yfrom
opsiff:linux-6.18.y-2026-03-12-cjktty

Conversation

@opsiff
Copy link
Member

@opsiff opsiff commented Mar 2, 2026

Co-developed-by: microcai microcaicai@gmail.com

Co-developed-by: zhmars 18466397+zhmars@users.noreply.github.com

Link: https://github.com/bigshans/cjktty-patches/blob/5c00aeabf86a80303a4a24ec6bfb47f1a0fa6c49/v6.x/cjktty-6.16.patch

[Xi Ruoyao: Resolve a merge conflict with 18c4ef4 ("fbdev:
bitblit: bound-check glyph index in bit_putcs*") by moving the bound
checking into font_bits.]

(cherry picked from commit d26cbd1e02cd1b9251072face8683df7dea55e20)

Co-developed-by: microcai <microcaicai@gmail.com>
Signed-off-by: microcai <microcaicai@gmail.com>
Co-developed-by: zhmars <18466397+zhmars@users.noreply.github.com>
Signed-off-by: zhmars <18466397+zhmars@users.noreply.github.com>
Signed-off-by: bigshans <26884666+bigshans@users.noreply.github.com>
Link: https://github.com/bigshans/cjktty-patches/blob/5c00aeabf86a80303a4a24ec6bfb47f1a0fa6c49/v6.x/cjktty-6.16.patch
Signed-off-by: Kexy Biscuit <kexybiscuit@aosc.io>
Signed-off-by: Xinhui Yang <cyan@cyano.uk>

[Xi Ruoyao: Resolve a merge conflict with 18c4ef4 ("fbdev:
 bitblit: bound-check glyph index in bit_putcs*") by moving the bound
 checking into font_bits.]
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
(cherry picked from commit d26cbd1e02cd1b9251072face8683df7dea55e20)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @opsiff, your pull request is larger than the review limit of 150000 diff characters

@Avenger-285714
Copy link
Member

/approve

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Avenger-285714

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR backports the cjktty patchset to add better CJK/Unicode VT console rendering support, including new built-in CJK fonts and framebuffer-console changes to fetch glyph bitmaps from a Unicode-aware backing store (including rotated fbcon paths).

Changes:

  • Add two new built-in CJK console fonts (16x16 and 32x32) and wire them into font selection/Kconfig/build.
  • Introduce a “UTF shadow plane” for the VT screen buffer and plumb Unicode glyph retrieval into fbcon bitblit + rotated renderers via font_bits().
  • Update VT redraw/scroll/selection logic to account for the additional Unicode storage.

Reviewed changes

Copilot reviewed 15 out of 17 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
lib/fonts/fonts.c Registers new CJK fonts in the compiled-in font list.
lib/fonts/font_cjk_32x32.h Adds the bitmap data header for the 32x32 font (currently empty).
lib/fonts/font_cjk_32x32.c Adds the 32x32 font descriptor and includes the data header.
lib/fonts/font_cjk_16x16.c Adds the 16x16 font descriptor and includes the data header.
lib/fonts/Makefile Builds the new font objects when enabled.
lib/fonts/Kconfig Adds Kconfig options for the new fonts and updates autoselect constraints.
include/linux/font.h Adds font indices and extern declarations for the new fonts.
drivers/video/fbdev/core/fbcon_ud.c Uses font_bits() to fetch glyph bitmaps for rotated rendering.
drivers/video/fbdev/core/fbcon_rotate.c Adds UTF font rotation buffer + switches fontbuffer allocation to kvmalloc.
drivers/video/fbdev/core/fbcon_cw.c Uses font_bits() to fetch glyph bitmaps for rotated rendering.
drivers/video/fbdev/core/fbcon_ccw.c Uses font_bits() to fetch glyph bitmaps for rotated rendering.
drivers/video/fbdev/core/fbcon.h Extends fbcon_ops with UTF buffer fields + declares font_bits().
drivers/video/fbdev/core/fbcon.c Adjusts redraw/blit logic and font mask handling for the new encoding scheme.
drivers/video/fbdev/core/bitblit.c Introduces font_bits() and UTF lookup logic for glyph rendering.
drivers/tty/vt/vt.c Implements UTF shadow plane storage and modifies write/scroll/resize/glyph retrieval.
drivers/tty/vt/selection.c Adjusts selection extraction logic for the new Unicode handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +137 to +149
This is a high resolution console font that covers Unicode Basic
Multilingual Plane (BMP), mostly is CJK font. If you want basic Unicode
support on the VT console, say Y.

config FONT_CJK_32x32
bool "CJK 32x32 font" if FONTS
depends on FRAMEBUFFER_CONSOLE && VT_CONSOLE
select CONSOLE_TRANSLATIONS
default y if !SPARC
help
This is a more higher resolution console font that covers Unicode Basic
Multilingual Plane (BMP), mostly is CJK font. If you want basic Unicode
support on the VT console for a high res monitor, say Y.
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text has grammatical issues (“mostly is CJK font”, “more higher resolution”). Please adjust wording for clarity (e.g., “mostly a CJK font”, “higher resolution”).

Copilot uses AI. Check for mistakes.
Comment on lines 112 to 123
if (ops->fd_size < d_cellsize * len) {
dst = kmalloc_array(len, d_cellsize, GFP_KERNEL);
dst = kvmalloc_array(len, d_cellsize, GFP_KERNEL | __GFP_RETRY_MAYFAIL);

if (dst == NULL) {
err = -ENOMEM;
goto finished;
}

ops->fd_size = d_cellsize * len;
kfree(ops->fontbuffer);
kvfree(ops->fontbuffer);
ops->fontbuffer = dst;
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fbcon_rotate_font() now allocates ops->fontbuffer with kvmalloc_array() and frees it with kvfree(), but fbcon_release() still frees ops->fontbuffer with kfree() (see drivers/video/fbdev/core/fbcon.c). If kvmalloc_array() returns vmalloc'ed memory, kfree() is invalid. Either keep kmalloc_array()/kfree() here or update the release path to use kvfree() consistently.

Copilot uses AI. Check for mistakes.
Comment on lines 1103 to 1110
err = -EINVAL;
if (vc->vc_cols > VC_MAXCOL || vc->vc_rows > VC_MAXROW ||
vc->vc_screenbuf_size > KMALLOC_MAX_SIZE || !vc->vc_screenbuf_size)
goto err_free;
err = -ENOMEM;
vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL);
vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size * 2, GFP_KERNEL);
if (!vc->vc_screenbuf)
goto err_free;
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vc_allocate() now allocates vc_screenbuf_size * 2, but the bounds check only validates vc_screenbuf_size against KMALLOC_MAX_SIZE. This can overflow or exceed KMALLOC_MAX_SIZE after the multiplication. The check should be updated to validate the actual allocation size (with overflow-safe arithmetic).

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +75
void *fontdata;
char *fontname = (cellsize < 64) ? "CJK16x16" : "CJK32x32";
const struct font_desc *font;

fontdata = ops ? ops->fontbuffer : vc->vc_font.data;

ch = scr_readw(s) & charmask;
if (ch >= charcnt)
ch = 0;

src = fontdata + (unsigned int)ch * cellsize;
if ((scr_readw(s) & charmask) != 0xff && (scr_readw(s) & charmask) != 0xfe)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fontdata is declared as void * but later used in pointer arithmetic (fontdata + ch * cellsize, etc.). With kernel build flags this triggers -Wpointer-arith (and may fail the build). Use a byte pointer type (e.g., u8 * / const u8 *) for fontdata (and similarly for the CJK fontdata pointers) to make the arithmetic well-defined.

Copilot uses AI. Check for mistakes.
Comment on lines +245 to +246
if (c > 0x80)
i += 2;
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop increments i an extra 2 bytes when c > 0x80, but in Unicode mode c is a Unicode codepoint so most non-ASCII characters will satisfy this even when they are single-column. This will skip characters incorrectly during selection copy. If the intent is to skip the second cell of a double-width glyph, key this off an explicit marker (e.g., UCS_ZWS in the unicode buffer, or the on-screen continuation marker) rather than c > 0x80.

Suggested change
if (c > 0x80)
i += 2;
if (unicode) {
u32 next = sel_pos(i + 2, unicode);
if (next == UCS_ZWS)
i += 2;
}

Copilot uses AI. Check for mistakes.
Comment on lines +1267 to +1281
if (rrem) {
scr_memsetw((void *)(new_origin + rlth),
vc->vc_video_erase_char, rrem);
scr_memsetw((void *)(new_origin + rlth + (new_screen_size)),
vc->vc_video_erase_char, rrem);
}
old_origin += old_row_size;
new_origin += new_row_size;
}
if (new_scr_end > new_origin)
if (new_scr_end > new_origin) {
scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
new_scr_end - new_origin);
scr_memsetw((void *)new_origin + (new_screen_size), vc->vc_video_erase_char,
new_scr_end - new_origin);
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UTF shadow plane should be cleared to 0, but the resize path fills it with vc_video_erase_char (scr_memsetw(... vc_video_erase_char, ...)). This will leave non-zero UTF entries for blank cells and can cause incorrect unicode reconstruction later (e.g., screen_glyph() treating a cell as having UTF data). Use 0 for the UTF plane erase value in both the rrem and new_scr_end fill blocks.

Copilot uses AI. Check for mistakes.
Comment on lines +3241 to +3242
vc->vc_utf = 1;
vc->vc_disp_ctrl = 0;
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do_con_write() forcibly sets vc->vc_utf = 1 and vc->vc_disp_ctrl = 0 on every write. This overrides the console’s configured UTF-8 mode (including default_utf8 and runtime toggles via escape sequences / ioctls) and is a broad behavior change likely to break non-UTF8 console setups.

Suggested change
vc->vc_utf = 1;
vc->vc_disp_ctrl = 0;

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +145
config FONT_CJK_16x16
bool "CJK 16x16 font" if FONTS
depends on FRAMEBUFFER_CONSOLE && VT_CONSOLE
select CONSOLE_TRANSLATIONS
default y if !SPARC
help
This is a high resolution console font that covers Unicode Basic
Multilingual Plane (BMP), mostly is CJK font. If you want basic Unicode
support on the VT console, say Y.

config FONT_CJK_32x32
bool "CJK 32x32 font" if FONTS
depends on FRAMEBUFFER_CONSOLE && VT_CONSOLE
select CONSOLE_TRANSLATIONS
default y if !SPARC
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options default to y if !SPARC even when FONTS is enabled. Most other font options only default to y when !FONTS (so enabling FONTS lets users explicitly choose fonts). As written, selecting FONTS will still silently enable these large CJK fonts by default, which is inconsistent and can significantly increase kernel size. Consider aligning the default with the existing pattern (e.g., default y if !SPARC && !FONTS, or no default under FONTS).

Copilot uses AI. Check for mistakes.
offset < vc->vc_screenbuf_size) {
unsigned short new;
u16 *p = screenpos(vc, offset, true);
u16 *p_utf = screenpos(vc, offset, true);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p_utf is computed with screenpos() instead of screenpos_utf8(), so old_utf is read from the main screen buffer rather than the UTF shadow plane. This makes the UTF save/restore logic in complement_pos() incorrect.

Suggested change
u16 *p_utf = screenpos(vc, offset, true);
u16 *p_utf = screenpos_utf8(vc, offset, true);

Copilot uses AI. Check for mistakes.
/* */
/* Font file modified from */
/* http://blog.chinaunix.net/u/13265/showart.php?id=1008020 */
/* microcaicai@gmail modifiy it to use in-kernel font solution */
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment block contains a spelling error: “modifiy”. Please fix to “modify” (or rephrase) since this is newly added text.

Suggested change
/* microcaicai@gmail modifiy it to use in-kernel font solution */
/* microcaicai@gmail modified it to use in-kernel font solution*/

Copilot uses AI. Check for mistakes.
@opsiff opsiff merged commit 301590c into deepin-community:linux-6.18.y Mar 2, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants