Skip to contentSkip to conversation

ARM: mach-rpc: fix zImage build after recent font-related changes

PATCH In review Ethan Nelson-Moore 3 participants 6 messages May 10 – May 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: mach-rpc: fix zImage build after recent font-related changes

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")
---
 arch/arm/boot/compressed/Makefile | 6 +++++-
 lib/fonts/font_acorn_8x8.c        | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/arm/boot/compressed/Makefile +5 -1
index a159120d1e42..0e198a6ce447 100644
@@ -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
lib/fonts/font_acorn_8x8.c +2 -0
index 36c51016769d..6b5291c23fc8 100644
@@ -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 */
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 4 lines · Ethan Nelson-Moore

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>.

Quoted 8 lines

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

Quoted 38 lines
Fixes 97df8960240a ("lib/fonts: Provide helpers for calculating glyph pitch and size")
---
  arch/arm/boot/compressed/Makefile | 6 +++++-
  lib/fonts/font_acorn_8x8.c        | 2 ++
  2 files changed, 7 insertions(+), 1 deletion(-)
arch/arm/boot/compressed/Makefile +5 -1
index a159120d1e42..0e198a6ce447 100644
@@ -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
lib/fonts/font_acorn_8x8.c +2 -0
index 36c51016769d..6b5291c23fc8 100644
@@ -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 lore raw

* Helge Deller <[email protected]>:

Quoted 10 lines · Ethan Nelson-Moore
Quoted 9 lines

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.

Quoted 8 lines
Quoted 3 lines

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

include/linux/font.h +1 -1
index 6845f02d739a..c8f3d6ef54c8 100644
@@ -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;
 }
 
 /**
lib/fonts/fonts.c +10 -10
index f5d5333450a0..5bd7af5f2111 100644
@@ -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)
#3 lore raw

Hi, Helge,

Thanks for investigating this issue.

Quoted 1 line · Helge Deller

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.

Quoted 1 line

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

maintainer
#4 lore raw

Hi Ethan,

Quoted 4 lines · Ethan Nelson-Moore

Thanks for investigating this issue.

Quoted 1 line · Helge Deller

Ethan, does this compile-only-tested patch fix the issue?

Quoted 9 lines

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.

Would it help to mark acorndata_8x8 with attribute("visible") ? That way it should become accessible.

Quoted 3 lines
Quoted 1 line

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.

Ok, good.
How shall we continue?
Do you want to try the visible trick?

Helge

Quoted 4 lines

Have a nice day!

Ethan

maintainer
#5 lore raw
Quoted 20 lines · Helge Deller

Hi Ethan,

Quoted 4 lines · Ethan Nelson-Moore

Thanks for investigating this issue.

Quoted 1 line · Helge Deller

Ethan, does this compile-only-tested patch fix the issue?

Quoted 9 lines

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.

Would it help to mark acorndata_8x8 with attribute("visible") ? That way it should become accessible.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

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.

Ok, good.
How shall we continue?
Do you want to try the visible trick?

I meant the __visible #define from
include/linux/compiler_attributes.h:# define __visible __attribute__((__externally_visible__)) I understand it might conflict with the "static" keyword (I did not test).

In your patch you #defined OMIT_FONT_DESC:

+# 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

On parisc I used a #define BOOTLOADER, which already describes the reason.
For your patch you could also use the "BOOTLOADER" define and then (instead of using __visible):
#ifdef BOOTLOADER
static const struct font_data acorndata_8x8 =
#else
const struct font_data acorndata_8x8 = {
#endif

?
Helge