[Deepin-Kernel-SIG] [linux 6.18.y] [AOSC] FROMEXT: cjktty-6.16.patch#1518
Conversation
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>
There was a problem hiding this comment.
Sorry @opsiff, your pull request is larger than the review limit of 150000 diff characters
|
/approve |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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”).
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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).
| 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) |
There was a problem hiding this comment.
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.
| if (c > 0x80) | ||
| i += 2; |
There was a problem hiding this comment.
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.
| if (c > 0x80) | |
| i += 2; | |
| if (unicode) { | |
| u32 next = sel_pos(i + 2, unicode); | |
| if (next == UCS_ZWS) | |
| i += 2; | |
| } |
| 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); | ||
| } |
There was a problem hiding this comment.
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.
| vc->vc_utf = 1; | ||
| vc->vc_disp_ctrl = 0; |
There was a problem hiding this comment.
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.
| vc->vc_utf = 1; | |
| vc->vc_disp_ctrl = 0; |
| 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 |
There was a problem hiding this comment.
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).
| offset < vc->vc_screenbuf_size) { | ||
| unsigned short new; | ||
| u16 *p = screenpos(vc, offset, true); | ||
| u16 *p_utf = screenpos(vc, offset, true); |
There was a problem hiding this comment.
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.
| u16 *p_utf = screenpos(vc, offset, true); | |
| u16 *p_utf = screenpos_utf8(vc, offset, true); |
| /* */ | ||
| /* Font file modified from */ | ||
| /* http://blog.chinaunix.net/u/13265/showart.php?id=1008020 */ | ||
| /* microcaicai@gmail modifiy it to use in-kernel font solution */ |
There was a problem hiding this comment.
The comment block contains a spelling error: “modifiy”. Please fix to “modify” (or rephrase) since this is newly added text.
| /* microcaicai@gmail modifiy it to use in-kernel font solution */ | |
| /* microcaicai@gmail modified it to use in-kernel font solution*/ |
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)