Skip to contentSkip to conversation

arm64: Fix bit-shifting UB in MIDR_AMPERE1

PATCH Superseded D Scott Phillips 2 participants 2 messages Oct 17, 2022 – Oct 18, 2022 arm64

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Fix bit-shifting UB in MIDR_AMPERE1

CONFIG_UBSAN_SHIFT with gcc-5 complains that shifting ARM_CPU_IMP_AMPERE (0xC0) into bits [31:24] is undefined behavior. Well, sort of, it actually spells the error as:

/kisskb/src/arch/arm64/kernel/proton-pack.c: In function 'spectre_bhb_loop_affected':
/kisskb/src/arch/arm64/include/asm/cputype.h:44:2: error: initializer element is not constant
(((imp) << MIDR_IMPLEMENTOR_SHIFT) | \
^

This isn't an issue for other Implementor codes, as all the other codes have zero in the top bit.

Fixes 0e5d5ae837c8ce04 ("arm64: Add AMPERE1 to the Spectre-BHB affected list")
---
 arch/arm64/include/asm/cputype.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/cputype.h +1 -1
index abc418650fec..b28db64799eb 100644
@@ -60,7 +60,7 @@
 #define ARM_CPU_IMP_FUJITSU		0x46
 #define ARM_CPU_IMP_HISI		0x48
 #define ARM_CPU_IMP_APPLE		0x61
-#define ARM_CPU_IMP_AMPERE		0xC0
+#define ARM_CPU_IMP_AMPERE		0xC0u
 
 #define ARM_CPU_PART_AEM_V8		0xD0F
 #define ARM_CPU_PART_FOUNDATION		0xD00
Signature · 7 lines
2.37.3


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

Hi Scott,

Quoted 9 lines · D Scott Phillips

CONFIG_UBSAN_SHIFT with gcc-5 complains that shifting ARM_CPU_IMP_AMPERE (0xC0) into bits [31:24] is undefined behavior. Well, sort of, it actually spells the error as:

/kisskb/src/arch/arm64/kernel/proton-pack.c: In function 'spectre_bhb_loop_affected':
/kisskb/src/arch/arm64/include/asm/cputype.h:44:2: error: initializer element is not constant

   (((imp)   << MIDR_IMPLEMENTOR_SHIFT) | \
   ^
Quoted 6 lines

This isn't an issue for other Implementor codes, as all the other codes have zero in the top bit.

Fixes 0e5d5ae837c8ce04 ("arm64: Add AMPERE1 to the Spectre-BHB affected list")

Thanks for your patch!

arch/arm64/include/asm/cputype.h line 63

Quoted 8 lines
arch/arm64/include/asm/cputype.h +1 -1
@@ -60,7 +60,7 @@
 #define ARM_CPU_IMP_FUJITSU            0x46
 #define ARM_CPU_IMP_HISI               0x48
 #define ARM_CPU_IMP_APPLE              0x61
-#define ARM_CPU_IMP_AMPERE             0xC0
+#define ARM_CPU_IMP_AMPERE             0xC0u

This makes the entry inconsistent with all others.
So we can either add the "u" suffix everywhere, or add a cast to "u32" to the definitions[1] of MIDR_CPU_MODEL().

[1] There are two: in arch/arm64/include/asm/cputype.h and in tools/arch/arm64/include/asm/cputype.h.
Looks like the second file is a copy of the first, but still lacking the AMPERE definitions.
I guess it should be replaced by a symlink, to keep them in sync.

arch/arm64/include/asm/cputype.h line 66

Quoted 2 lines
arch/arm64/include/asm/cputype.h +0 -0
 #define ARM_CPU_PART_AEM_V8            0xD0F
 #define ARM_CPU_PART_FOUNDATION                0xD00

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel