Skip to contentSkip to conversation

ARM: fix big-endian check for IO memcpy and memset

PATCH In review Julian Vetter 2 participants 2 messages Oct 30 – Nov 4 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: fix big-endian check for IO memcpy and memset

The commit 7ddfe625cbc1 ("ARM: optimize memset_io()/memcpy_fromio()/memcpy_toio()") switched little-endian builds to mmioset()/mmiocpy() and intended to keep the byte-wise _memset_io()/_memcpy_fromio()/_memcpy_toio() for big-endian builds. However, the check uses __ARMBE__, which is not defined by GCC. The define used throughout the kernel is __ARMEB__ for big-endian ARM. So, big-endian builds have been using mmioset() and mmiocpy() ever since.

This is a problem on ARMv5 BE32 platforms like IXP4xx, where word accesses to IO memory can end up on different byte lanes than byte accesses. Fix the typo, so big-endian builds use the correct byte-wise implementations again, as originally intended.

Switching big-endian builds to the generic implementation from lib/iomem_copy.c instead is not an option either, because it also uses word accesses for the aligned parts of a buffer and thus has the same byte lane problem on BE32. ARMv6/v7 BE8 mode would work with both, but it is marked as broken and is expected to be removed, so it is not worth treating it differently from BE32.

---
This replaces my earlier patch that removed the byte-wise helpers:
https://lore.kernel.org/all/[email protected]/

I have done a compilation test with ixp4xx_defconfig and see that drivers/pci/pci-sysfs.o and drivers/mtd/maps/map_funcs.o now call _memcpy_fromio()/_memcpy_toio() instead of mmiocpy(). This is however untested on hardware. I think the problem didn't show up on Linus' hw test, because platform doesn't use those drivers.

---
 arch/arm/include/asm/io.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/io.h +1 -1
index e6bd9e79737c..50e142f817f5 100644
@@ -308,7 +308,7 @@ extern void _memset_io(volatile void __iomem *, int, size_t);
 #define writesw(p,d,l)		__raw_writesw(p,d,l)
 #define writesl(p,d,l)		__raw_writesl(p,d,l)
 
-#ifndef __ARMBE__
+#ifndef __ARMEB__
 static inline void memset_io(volatile void __iomem *dst, unsigned c,
 	size_t count)
 {
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Julian Vetter

The commit 7ddfe625cbc1 ("ARM: optimize memset_io()/memcpy_fromio()/memcpy_toio()") switched little-endian builds to mmioset()/mmiocpy() and intended to keep the byte-wise _memset_io()/_memcpy_fromio()/_memcpy_toio() for big-endian builds. However, the check uses __ARMBE__, which is not defined by GCC. The define used throughout the kernel is __ARMEB__ for big-endian ARM. So, big-endian builds have been using mmioset() and mmiocpy() ever since.

This is a problem on ARMv5 BE32 platforms like IXP4xx, where word accesses to IO memory can end up on different byte lanes than byte accesses. Fix the typo, so big-endian builds use the correct byte-wise implementations again, as originally intended.

Quoted 8 lines

Switching big-endian builds to the generic implementation from lib/iomem_copy.c instead is not an option either, because it also uses word accesses for the aligned parts of a buffer and thus has the same byte lane problem on BE32. ARMv6/v7 BE8 mode would work with both, but it is marked as broken and is expected to be removed, so it is not worth treating it differently from BE32.

Please put this patch into Russell's patch tracker.

Yours,
Linus Walleij