* [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
@ 2026-06-07 21:02 Helge Deller
2026-06-08 4:50 ` Ethan Nelson-Moore
2026-06-08 11:25 ` Thomas Zimmermann
0 siblings, 2 replies; 7+ messages in thread
From: Helge Deller @ 2026-06-07 21:02 UTC (permalink / raw)
To: linux-fbdev, dri-devel; +Cc: 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>.
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.
There is no need to use 64-bit division code here, so resolve this issue
by using plain standard addition and shift maths.
Fixes: 97df8960240a ("lib/fonts: Provide helpers for calculating glyph pitch and size")
Reported-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
include/linux/font.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/linux/font.h b/include/linux/font.h
index 6845f02d739a..67d32268989d 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -11,7 +11,6 @@
#ifndef _VIDEO_FONT_H
#define _VIDEO_FONT_H
-#include <linux/math.h>
#include <linux/types.h>
struct console_font;
@@ -35,7 +34,7 @@ struct console_font;
*/
static inline unsigned int font_glyph_pitch(unsigned int width)
{
- return DIV_ROUND_UP(width, 8);
+ return (width + 7) >> 3;
}
/**
--
2.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
2026-06-07 21:02 [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code Helge Deller
@ 2026-06-08 4:50 ` Ethan Nelson-Moore
2026-06-08 11:25 ` Thomas Zimmermann
1 sibling, 0 replies; 7+ messages in thread
From: Ethan Nelson-Moore @ 2026-06-08 4:50 UTC (permalink / raw)
To: Helge Deller; +Cc: linux-fbdev, dri-devel
On Sun, Jun 7, 2026 at 2:02 PM Helge Deller <deller@gmx.de> 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.
>
> There is no need to use 64-bit division code here, so resolve this issue
> by using plain standard addition and shift maths.
Hi, Helge,
I can confirm that this patch fixes the issue. Thank you for your
thorough investigation.
Ethan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
2026-06-07 21:02 [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code Helge Deller
2026-06-08 4:50 ` Ethan Nelson-Moore
@ 2026-06-08 11:25 ` Thomas Zimmermann
2026-06-08 19:57 ` Helge Deller
1 sibling, 1 reply; 7+ messages in thread
From: Thomas Zimmermann @ 2026-06-08 11:25 UTC (permalink / raw)
To: Helge Deller, linux-fbdev, dri-devel; +Cc: Ethan Nelson-Moore
Hi
Am 07.06.26 um 23:02 schrieb Helge Deller:
> 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.
>
> There is no need to use 64-bit division code here, so resolve this issue
> by using plain standard addition and shift maths.
Why is there a 64-bit division at all?
>
> Fixes: 97df8960240a ("lib/fonts: Provide helpers for calculating glyph pitch and size")
> Reported-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
> include/linux/font.h | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/include/linux/font.h b/include/linux/font.h
> index 6845f02d739a..67d32268989d 100644
> --- a/include/linux/font.h
> +++ b/include/linux/font.h
> @@ -11,7 +11,6 @@
> #ifndef _VIDEO_FONT_H
> #define _VIDEO_FONT_H
>
> -#include <linux/math.h>
> #include <linux/types.h>
>
> struct console_font;
> @@ -35,7 +34,7 @@ struct console_font;
> */
> static inline unsigned int font_glyph_pitch(unsigned int width)
> {
> - return DIV_ROUND_UP(width, 8);
> + return (width + 7) >> 3;
Ok by me, if that's what's necessary. But can we try to keep a
documented macro for the division to make the code explain itself? Does
it work with DIV_ROUND_UP_POW2() ?
Best regards
Thomas
> }
>
> /**
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
2026-06-08 11:25 ` Thomas Zimmermann
@ 2026-06-08 19:57 ` Helge Deller
2026-06-08 20:14 ` Ethan Nelson-Moore
0 siblings, 1 reply; 7+ messages in thread
From: Helge Deller @ 2026-06-08 19:57 UTC (permalink / raw)
To: Thomas Zimmermann, linux-fbdev, dri-devel; +Cc: Ethan Nelson-Moore
On 6/8/26 13:25, Thomas Zimmermann wrote:
> Hi
>
> Am 07.06.26 um 23:02 schrieb Helge Deller:
>> 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.
>>
>> There is no need to use 64-bit division code here, so resolve this issue
>> by using plain standard addition and shift maths.
>
> Why is there a 64-bit division at all?
Not sure. Might be platform specific.
Maybe, because you add two integers and divide by an integer, that the
compiler then chooses to use 64-bit integer division by 32-bit integer.
>> Fixes: 97df8960240a ("lib/fonts: Provide helpers for calculating glyph pitch and size")
>> Reported-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
>> Signed-off-by: Helge Deller <deller@gmx.de>
>> ---
>> include/linux/font.h | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/include/linux/font.h b/include/linux/font.h
>> index 6845f02d739a..67d32268989d 100644
>> --- a/include/linux/font.h
>> +++ b/include/linux/font.h
>> @@ -11,7 +11,6 @@
>> #ifndef _VIDEO_FONT_H
>> #define _VIDEO_FONT_H
>> -#include <linux/math.h>
>> #include <linux/types.h>
>> struct console_font;
>> @@ -35,7 +34,7 @@ struct console_font;
>> */
>> static inline unsigned int font_glyph_pitch(unsigned int width)
>> {
>> - return DIV_ROUND_UP(width, 8);
>> + return (width + 7) >> 3;
>
> Ok by me, if that's what's necessary.
> But can we try to keep a documented macro for the division to make the code explain itself?
I'd expect everyone who messes with this kind of low-level graphics and bitmaps
to understand this math addition and bit shift, and as such I think it should
be self-explained.
> Does it work with DIV_ROUND_UP_POW2() ?
IMHO that's even worse than DIV_ROUND_UP().
Heleg
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
2026-06-08 19:57 ` Helge Deller
@ 2026-06-08 20:14 ` Ethan Nelson-Moore
2026-06-08 20:26 ` Helge Deller
0 siblings, 1 reply; 7+ messages in thread
From: Ethan Nelson-Moore @ 2026-06-08 20:14 UTC (permalink / raw)
To: Helge Deller; +Cc: Thomas Zimmermann, linux-fbdev, dri-devel
Hi, Helge and Thomas,
On Mon, Jun 8, 2026 at 12:58 PM Helge Deller <deller@gmx.de> wrote:
>
> On 6/8/26 13:25, Thomas Zimmermann wrote:
> > Why is there a 64-bit division at all?
>
> Not sure. Might be platform specific.
> Maybe, because you add two integers and divide by an integer, that the
> compiler then chooses to use 64-bit integer division by 32-bit integer.
Actually, I think the real issue is that
arch/arm/boot/compressed/Makefile defines "static" to nothing when
compiling its copy of lib/fonts/font_acorn_8x8.c (via font.c), so that
the font array is available outside of the object file. I assume that
this causes various unused static inline functions in the headers it
includes (such as <linux/math.h>) to be included in the object file
because they become normal inline functions.
Ethan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
2026-06-08 20:14 ` Ethan Nelson-Moore
@ 2026-06-08 20:26 ` Helge Deller
2026-06-09 1:50 ` Ethan Nelson-Moore
0 siblings, 1 reply; 7+ messages in thread
From: Helge Deller @ 2026-06-08 20:26 UTC (permalink / raw)
To: Ethan Nelson-Moore
Cc: Helge Deller, Thomas Zimmermann, linux-fbdev, dri-devel
* Ethan Nelson-Moore <enelsonmoore@gmail.com>:
> Hi, Helge and Thomas,
>
> On Mon, Jun 8, 2026 at 12:58 PM Helge Deller <deller@gmx.de> wrote:
> >
> > On 6/8/26 13:25, Thomas Zimmermann wrote:
> > > Why is there a 64-bit division at all?
> >
> > Not sure. Might be platform specific.
> > Maybe, because you add two integers and divide by an integer, that the
> > compiler then chooses to use 64-bit integer division by 32-bit integer.
>
> Actually, I think the real issue is that
> arch/arm/boot/compressed/Makefile defines "static" to nothing when
> compiling its copy of lib/fonts/font_acorn_8x8.c (via font.c), so that
> the font array is available outside of the object file. I assume that
> this causes various unused static inline functions in the headers it
> includes (such as <linux/math.h>) to be included in the object file
> because they become normal inline functions.
Does this patch fix the issue then?
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index a159120d1e42..e3f550d62857 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -157,4 +157,4 @@ $(obj)/piggy_data: $(obj)/../Image FORCE
$(obj)/piggy.o: $(obj)/piggy_data
-CFLAGS_font.o := -Dstatic=
+CFLAGS_font.o := -DBOOTLOADER
diff --git a/lib/fonts/font_acorn_8x8.c b/lib/fonts/font_acorn_8x8.c
index 36c51016769d..3327aa6d161d 100644
--- a/lib/fonts/font_acorn_8x8.c
+++ b/lib/fonts/font_acorn_8x8.c
@@ -5,7 +5,11 @@
#define FONTDATAMAX 2048
+#ifndef BOOTLOADER
static const struct font_data acorndata_8x8 = {
+#else
+const struct font_data acorndata_8x8 = {
+#endif
{ 0, 0, FONTDATAMAX, 0 }, {
/* 00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^@ */
/* 01 */ 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e, /* ^A */
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code
2026-06-08 20:26 ` Helge Deller
@ 2026-06-09 1:50 ` Ethan Nelson-Moore
0 siblings, 0 replies; 7+ messages in thread
From: Ethan Nelson-Moore @ 2026-06-09 1:50 UTC (permalink / raw)
To: Helge Deller; +Cc: Helge Deller, Thomas Zimmermann, linux-fbdev, dri-devel
Hi, Helge,
On Mon, Jun 8, 2026 at 1:26 PM Helge Deller <deller@kernel.org> wrote:
> Does this patch fix the issue then?
Yes, it does. I remember you suggested this solution a while ago. Thank you.
Ethan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-06-09 1:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-07 21:02 [PATCH] lib/fonts: Avoid unncessary 64-bit math in font code Helge Deller
2026-06-08 4:50 ` Ethan Nelson-Moore
2026-06-08 11:25 ` Thomas Zimmermann
2026-06-08 19:57 ` Helge Deller
2026-06-08 20:14 ` Ethan Nelson-Moore
2026-06-08 20:26 ` Helge Deller
2026-06-09 1:50 ` 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