Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH] ARM: mach-rpc: fix zImage build after recent font-related changes
@ 2026-05-10  2:39 Ethan Nelson-Moore
  2026-05-19  6:56 ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: Ethan Nelson-Moore @ 2026-05-10  2:39 UTC (permalink / raw)
  To: linux-arm-kernel, linux-fbdev
  Cc: Russell King, Ethan Nelson-Moore, Helge Deller, Thomas Zimmermann,
	Kees Cook

The text display code used in the Risc PC kernel image decompression
code uses arch/arm/boot/compressed/font.c, which includes
lib/fonts/font_acorn_8x8.c, which further includes <linux/font.h>.

Since commit 97df8960240a ("lib/fonts: Provide helpers for calculating
glyph pitch and size") <linux/font.h> contains inline functions that
require __do_div64, which is not linked into the ARM kernel
decompressor. This makes Risc PC zImages fail to build.

Resolve this issue in the least intrusive way possible by preventing
the inclusion of <linux/font.h> (and the definition of a struct that
relies on it) when the decompressor is being built.

Fixes: 97df8960240a ("lib/fonts: Provide helpers for calculating glyph pitch and size")
Signed-off-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
---
 arch/arm/boot/compressed/Makefile | 6 +++++-
 lib/fonts/font_acorn_8x8.c        | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index a159120d1e42..0e198a6ce447 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -157,4 +157,8 @@ $(obj)/piggy_data: $(obj)/../Image FORCE
 
 $(obj)/piggy.o: $(obj)/piggy_data
 
-CFLAGS_font.o := -Dstatic=
+# Defining _VIDEO_FONT_H prevents including <linux/font.h>, which contains
+# inline functions that require __do_div64, which is not linked into the
+# decompressor. OMIT_FONT_DESC is used in lib/fonts/font_acorn_8x8.c to omit the
+# definition of the font's font_desc structure, which requires <linux/font.h>.
+CFLAGS_font.o := -Dstatic= -D_VIDEO_FONT_H -DOMIT_FONT_DESC
diff --git a/lib/fonts/font_acorn_8x8.c b/lib/fonts/font_acorn_8x8.c
index 36c51016769d..6b5291c23fc8 100644
--- a/lib/fonts/font_acorn_8x8.c
+++ b/lib/fonts/font_acorn_8x8.c
@@ -265,6 +265,7 @@ static const struct font_data acorndata_8x8 = {
 /* FF */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 } };
 
+#ifndef OMIT_FONT_DESC /* Used by arch/arm/boot/compressed/Makefile */
 const struct font_desc font_acorn_8x8 = {
 	.idx	= ACORN8x8_IDX,
 	.name	= "Acorn8x8",
@@ -278,3 +279,4 @@ const struct font_desc font_acorn_8x8 = {
 	.pref	= 0,
 #endif
 };
+#endif /* OMIT_FONT_DESC */
-- 
2.43.0


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

* Re: [PATCH] ARM: mach-rpc: fix zImage build after recent font-related changes
  2026-05-10  2:39 [PATCH] ARM: mach-rpc: fix zImage build after recent font-related changes Ethan Nelson-Moore
@ 2026-05-19  6:56 ` Helge Deller
  2026-05-19  9:11   ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: Helge Deller @ 2026-05-19  6:56 UTC (permalink / raw)
  To: Ethan Nelson-Moore, linux-arm-kernel, linux-fbdev
  Cc: Russell King, Thomas Zimmermann, Kees Cook

On 5/10/26 04:39, Ethan Nelson-Moore wrote:
> The text display code used in the Risc PC kernel image decompression
> code uses arch/arm/boot/compressed/font.c, which includes
> lib/fonts/font_acorn_8x8.c, which further includes <linux/font.h>.
> 
> Since commit 97df8960240a ("lib/fonts: Provide helpers for calculating
> glyph pitch and size") <linux/font.h> contains inline functions that
> require __do_div64, which is not linked into the ARM kernel
> decompressor. This makes Risc PC zImages fail to build.
> 
> Resolve this issue in the least intrusive way possible by preventing
> the inclusion of <linux/font.h> (and the definition of a struct that
> relies on it) when the decompressor is being built.

I don't think we really require 64-bit integer support/division in the
font code, as 32-bit should be sufficient.
Can't you try to find out where this 64-bit division is done, and fix
this instead?

Helge


> Fixes: 97df8960240a ("lib/fonts: Provide helpers for calculating glyph pitch and size")
> Signed-off-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
> ---
>   arch/arm/boot/compressed/Makefile | 6 +++++-
>   lib/fonts/font_acorn_8x8.c        | 2 ++
>   2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
> index a159120d1e42..0e198a6ce447 100644
> --- a/arch/arm/boot/compressed/Makefile
> +++ b/arch/arm/boot/compressed/Makefile
> @@ -157,4 +157,8 @@ $(obj)/piggy_data: $(obj)/../Image FORCE
>   
>   $(obj)/piggy.o: $(obj)/piggy_data
>   
> -CFLAGS_font.o := -Dstatic=
> +# Defining _VIDEO_FONT_H prevents including <linux/font.h>, which contains
> +# inline functions that require __do_div64, which is not linked into the
> +# decompressor. OMIT_FONT_DESC is used in lib/fonts/font_acorn_8x8.c to omit the
> +# definition of the font's font_desc structure, which requires <linux/font.h>.
> +CFLAGS_font.o := -Dstatic= -D_VIDEO_FONT_H -DOMIT_FONT_DESC
> diff --git a/lib/fonts/font_acorn_8x8.c b/lib/fonts/font_acorn_8x8.c
> index 36c51016769d..6b5291c23fc8 100644
> --- a/lib/fonts/font_acorn_8x8.c
> +++ b/lib/fonts/font_acorn_8x8.c
> @@ -265,6 +265,7 @@ static const struct font_data acorndata_8x8 = {
>   /* FF */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
>   } };
>   
> +#ifndef OMIT_FONT_DESC /* Used by arch/arm/boot/compressed/Makefile */
>   const struct font_desc font_acorn_8x8 = {
>   	.idx	= ACORN8x8_IDX,
>   	.name	= "Acorn8x8",
> @@ -278,3 +279,4 @@ const struct font_desc font_acorn_8x8 = {
>   	.pref	= 0,
>   #endif
>   };
> +#endif /* OMIT_FONT_DESC */


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

* Re: [PATCH] ARM: mach-rpc: fix zImage build after recent font-related changes
  2026-05-19  6:56 ` Helge Deller
@ 2026-05-19  9:11   ` Helge Deller
  2026-05-20  4:49     ` Ethan Nelson-Moore
  0 siblings, 1 reply; 4+ messages in thread
From: Helge Deller @ 2026-05-19  9:11 UTC (permalink / raw)
  To: Ethan Nelson-Moore; +Cc: linux-arm-kernel, linux-fbdev, Russell King

* Helge Deller <deller@gmx.de>:
> On 5/10/26 04:39, Ethan Nelson-Moore wrote:
> > The text display code used in the Risc PC kernel image decompression
> > code uses arch/arm/boot/compressed/font.c, which includes
> > lib/fonts/font_acorn_8x8.c, which further includes <linux/font.h>.
> > 
> > Since commit 97df8960240a ("lib/fonts: Provide helpers for calculating
> > glyph pitch and size") <linux/font.h> contains inline functions that
> > require __do_div64, which is not linked into the ARM kernel
> > decompressor. This makes Risc PC zImages fail to build.
> > 
> > Resolve this issue in the least intrusive way possible by preventing
> > the inclusion of <linux/font.h> (and the definition of a struct that
> > relies on it) when the decompressor is being built.
> 
> I don't think we really require 64-bit integer support/division in the
> font code, as 32-bit should be sufficient.
> Can't you try to find out where this 64-bit division is done, and fix
> this instead?

Ethan, does this compile-only-tested patch fix the issue?
Maybe only the first hunk is necessary.

Helge


diff --git a/include/linux/font.h b/include/linux/font.h
index 6845f02d739a..c8f3d6ef54c8 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -35,7 +35,7 @@ struct console_font;
  */
 static inline unsigned int font_glyph_pitch(unsigned int width)
 {
-	return DIV_ROUND_UP(width, 8);
+	return (width + 7) >> 3;
 }
 
 /**
diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c
index f5d5333450a0..5bd7af5f2111 100644
--- a/lib/fonts/fonts.c
+++ b/lib/fonts/fonts.c
@@ -71,24 +71,24 @@ static void font_data_free(font_data_t *fd)
 font_data_t *font_data_import(const struct console_font *font, unsigned int vpitch,
 			      u32 (*calc_csum)(u32, const void *, size_t))
 {
-	unsigned int pitch = console_font_pitch(font);
-	unsigned int h = font->height;
-	unsigned int charcount = font->charcount;
+	uint8_t pitch = console_font_pitch(font);
+	uint8_t h = font->height;
+	uint16_t charcount = font->charcount;
 	const unsigned char *data = font->data;
 	u32 csum = 0;
 	struct font_data *font_data;
-	int size, alloc_size;
+	unsigned long size, alloc_size;
 	unsigned int i;
 	font_data_t *fd;
 
-	/* Check for integer overflow in font-size calculation */
-	if (check_mul_overflow(h, pitch, &size) ||
-	    check_mul_overflow(size, charcount, &size))
+	/* size-check user provided font values */
+	if ((pitch != console_font_pitch(font)) ||
+	    (h != font->height) ||
+	    (charcount != font->charcount))
 		return ERR_PTR(-EINVAL);
 
-	/* Check for overflow in allocation size calculation */
-	if (check_add_overflow(sizeof(*font_data), size, &alloc_size))
-		return ERR_PTR(-EINVAL);
+	size = h * pitch;
+	alloc_size = size + sizeof(*font_data);
 
 	font_data = kmalloc(alloc_size, GFP_USER);
 	if (!font_data)

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

* Re: [PATCH] ARM: mach-rpc: fix zImage build after recent font-related changes
  2026-05-19  9:11   ` Helge Deller
@ 2026-05-20  4:49     ` Ethan Nelson-Moore
  0 siblings, 0 replies; 4+ messages in thread
From: Ethan Nelson-Moore @ 2026-05-20  4:49 UTC (permalink / raw)
  To: Helge Deller; +Cc: linux-arm-kernel, linux-fbdev, Russell King

Hi, Helge,

Thanks for investigating this issue.

On Tue, May 19, 2026 at 2:11 AM Helge Deller <deller@kernel.org> wrote:
> Ethan, does this compile-only-tested patch fix the issue?
It almost does - I also had to remove #include <linux/math.h> from
include/linux/font.h.
This is probably because of the following highly questionable code in
arch/arm/boot/compressed/Makefile:
CFLAGS_font.o := -Dstatic=
which is causing unused static functions to not be optimized out. (The
real purpose of it is to make the acorndata_8x8 array non-static so
the decompressor can use it.) Really, the decompressor should be fixed
to not use this hack.

> Maybe only the first hunk is necessary.
You're right. The kernel links successfully with only the #include
<linux/math.h> removal and the first hunk applied.

Have a nice day!

Ethan

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

end of thread, other threads:[~2026-05-20  4:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-10  2:39 [PATCH] ARM: mach-rpc: fix zImage build after recent font-related changes Ethan Nelson-Moore
2026-05-19  6:56 ` Helge Deller
2026-05-19  9:11   ` Helge Deller
2026-05-20  4:49     ` Ethan Nelson-Moore

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