Skip to contentSkip to conversation

ARM: assembler: clean up byte swapping macros

PATCH In review Ard Biesheuvel 4 participants 12 messages Dec 9, 2020 – Dec 11, 2020

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

cover ARM: assembler: clean up byte swapping macros

Consolidate the byte swapping macros used in various places, and use them throughout. Patches #2 and #3 will be sent to Herbert for merging via the crypto tree once patch #1 is merged (or if Russell prefers to ack patch #1 instead, the whole series can go through the crypto tree)

Cc Geert Uytterhoeven <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Eric Biggers <[email protected]>
Cc Linus Walleij <[email protected]>

Ard Biesheuvel (3):
ARM: assembler: generalize byte swapping macro into rev_32
crypto: arm/aes-scalar - switch to common rev_32/mov_l macros
crypto: arm/chacha-scalar - switch to common rev_32 macro

 arch/arm/boot/compressed/head.S      |  5 +--
 arch/arm/crypto/aes-cipher-core.S    | 42 +++++--------------
 arch/arm/crypto/chacha-scalar-core.S | 43 ++++++--------------
 arch/arm/include/asm/assembler.h     | 11 +++++
 4 files changed, 35 insertions(+), 66 deletions(-)
Signature · 7 lines
2.17.1


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

PATCH 1/3 ARM: assembler: generalize byte swapping macro into rev_32

Take the 4 instruction byte swapping sequence from the decompressor's head.S, and turn it into a rev_32 GAS macro for general use. While at it, make it use the 'rev' instruction when compiling for v6 or later.

---
 arch/arm/boot/compressed/head.S  |  5 +----
 arch/arm/include/asm/assembler.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)
arch/arm/boot/compressed/head.S +1 -4
index 804d66668019..d70c78ab68c8 100644
@@ -174,10 +174,7 @@
 		.macro	be32tocpu, val, tmp
 #ifndef __ARMEB__
 		/* convert to little endian */
-		eor	\tmp, \val, \val, ror #16
-		bic	\tmp, \tmp, #0x00ff0000
-		mov	\val, \val, ror #8
-		eor	\val, \val, \tmp, lsr #8
+		rev_32	\val, \tmp
 #endif
 		.endm
 
arch/arm/include/asm/assembler.h +11 -0
index 6ed30421f697..a674eba4cd27 100644
@@ -578,4 +578,15 @@ THUMB(	orr	\reg , \reg , #PSR_T_BIT	)
 	__adldst_l	str, \src, \sym, \tmp, \cond
 	.endm
 
+	.macro		rev_32, val:req, tmp:req
+	.if		__LINUX_ARM_ARCH__ < 6
+	eor		\tmp, \val, \val, ror #16
+	bic		\tmp, \tmp, #0x00ff0000
+	mov		\val, \val, ror #8
+	eor		\val, \val, \tmp, lsr #8
+	.else
+	rev		\val, \val
+	.endif
+	.endm
+
 #endif /* __ASM_ASSEMBLER_H__ */
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by Tested-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] ARM: assembler: generalize byte swapping macro into rev_32

Hi Ard,

Quoted 6 lines · Ard Biesheuvel

Take the 4 instruction byte swapping sequence from the decompressor's head.S, and turn it into a rev_32 GAS macro for general use. While at it, make it use the 'rev' instruction when compiling for v6 or later.

Thanks for your patch!

Works fine on v7, so:

Gr{oetje,eeting}s,

Geert

Signature · 10 lines
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
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] ARM: assembler: generalize byte swapping macro into rev_32

In reply to Ard Biesheuvel
Quoted 6 lines · Ard Biesheuvel

Take the 4 instruction byte swapping sequence from the decompressor's head.S, and turn it into a rev_32 GAS macro for general use. While at it, make it use the 'rev' instruction when compiling for v6 or later.

Looks correct to me!

Yours,
Linus Walleij

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

#4 lore raw

PATCH 2/3 crypto: arm/aes-scalar - switch to common rev_32/mov_l macros

In reply to Ard Biesheuvel

The scalar AES implementation has some locally defined macros which reimplement things that are now available in macros defined in assembler.h. So let's switch to those.

---
 arch/arm/crypto/aes-cipher-core.S | 42 +++++---------------
 1 file changed, 10 insertions(+), 32 deletions(-)
arch/arm/crypto/aes-cipher-core.S +10 -32
index 472e56d09eea..5acc97aa9e5a 100644
@@ -99,28 +99,6 @@
 	__hround	\out2, \out3, \in2, \in1, \in0, \in3, \in1, \in0, 0, \sz, \op, \oldcpsr
 	.endm
 
-	.macro		__rev, out, in
-	.if		__LINUX_ARM_ARCH__ < 6
-	lsl		t0, \in, #24
-	and		t1, \in, #0xff00
-	and		t2, \in, #0xff0000
-	orr		\out, t0, \in, lsr #24
-	orr		\out, \out, t1, lsl #8
-	orr		\out, \out, t2, lsr #8
-	.else
-	rev		\out, \in
-	.endif
-	.endm
-
-	.macro		__adrl, out, sym, c
-	.if		__LINUX_ARM_ARCH__ < 7
-	ldr\c		\out, =\sym
-	.else
-	movw\c		\out, #:lower16:\sym
-	movt\c		\out, #:upper16:\sym
-	.endif
-	.endm
-
 	.macro		do_crypt, round, ttab, ltab, bsz
 	push		{r3-r11, lr}
 
@@ -133,10 +111,10 @@
 	ldr		r7, [in, #12]
 
 #ifdef CONFIG_CPU_BIG_ENDIAN
-	__rev		r4, r4
-	__rev		r5, r5
-	__rev		r6, r6
-	__rev		r7, r7
+	rev_32		r4, t0
+	rev_32		r5, t0
+	rev_32		r6, t0
+	rev_32		r7, t0
 #endif
 
 	eor		r4, r4, r8
@@ -144,7 +122,7 @@
 	eor		r6, r6, r10
 	eor		r7, r7, r11
 
-	__adrl		ttab, \ttab
+	mov_l		ttab, \ttab
 	/*
 	 * Disable interrupts and prefetch the 1024-byte 'ft' or 'it' table into
 	 * L1 cache, assuming cacheline size >= 32.  This is a hardening measure
@@ -180,7 +158,7 @@
 2:	.ifb		\ltab
 	add		ttab, ttab, #1
 	.else
-	__adrl		ttab, \ltab
+	mov_l		ttab, \ltab
 	// Prefetch inverse S-box for final round; see explanation above
 	.set		i, 0
 	.rept		256 / 64
@@ -194,10 +172,10 @@
 	\round		r4, r5, r6, r7, r8, r9, r10, r11, \bsz, b, rounds
 
 #ifdef CONFIG_CPU_BIG_ENDIAN
-	__rev		r4, r4
-	__rev		r5, r5
-	__rev		r6, r6
-	__rev		r7, r7
+	rev_32		r4, t0
+	rev_32		r5, t0
+	rev_32		r6, t0
+	rev_32		r7, t0
 #endif
 
 	ldr		out, [sp]
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] crypto: arm/aes-scalar - switch to common rev_32/mov_l macros

Quoted 5 lines · Ard Biesheuvel

The scalar AES implementation has some locally defined macros which reimplement things that are now available in macros defined in assembler.h. So let's switch to those.

Gr{oetje,eeting}s,

Geert

Signature · 10 lines
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
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] crypto: arm/aes-scalar - switch to common rev_32/mov_l macros

In reply to Ard Biesheuvel
Quoted 5 lines · Ard Biesheuvel

The scalar AES implementation has some locally defined macros which reimplement things that are now available in macros defined in assembler.h. So let's switch to those.

Much more readable like this. Not that I understand crypto. But I can see the macro does the same thing as the code used to do.

Yours,
Linus Walleij

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

#7 lore raw

PATCH 3/3 crypto: arm/chacha-scalar - switch to common rev_32 macro

In reply to Ard Biesheuvel

Drop the local definition of a byte swapping macro and use the common one instead.

---
 arch/arm/crypto/chacha-scalar-core.S | 43 ++++++--------------
 1 file changed, 13 insertions(+), 30 deletions(-)
arch/arm/crypto/chacha-scalar-core.S +13 -30
index 2985b80a45b5..5d06153e8b05 100644
@@ -41,32 +41,15 @@
 	X14	.req	r12
 	X15	.req	r14
 
-.macro __rev		out, in,  t0, t1, t2
-.if __LINUX_ARM_ARCH__ >= 6
-	rev		\out, \in
-.else
-	lsl		\t0, \in, #24
-	and		\t1, \in, #0xff00
-	and		\t2, \in, #0xff0000
-	orr		\out, \t0, \in, lsr #24
-	orr		\out, \out, \t1, lsl #8
-	orr		\out, \out, \t2, lsr #8
-.endif
-.endm
-
-.macro _le32_bswap	x,  t0, t1, t2
+.macro _le32_bswap_4x	a, b, c, d,  tmp
 #ifdef __ARMEB__
-	__rev		\x, \x,  \t0, \t1, \t2
+	rev_32		\a,  \tmp
+	rev_32		\b,  \tmp
+	rev_32		\c,  \tmp
+	rev_32		\d,  \tmp
 #endif
 .endm
 
-.macro _le32_bswap_4x	a, b, c, d,  t0, t1, t2
-	_le32_bswap	\a,  \t0, \t1, \t2
-	_le32_bswap	\b,  \t0, \t1, \t2
-	_le32_bswap	\c,  \t0, \t1, \t2
-	_le32_bswap	\d,  \t0, \t1, \t2
-.endm
-
 .macro __ldrd		a, b, src, offset
 #if __LINUX_ARM_ARCH__ >= 6
 	ldrd		\a, \b, [\src, #\offset]
@@ -200,7 +183,7 @@
 	add		X1, X1, r9
 	add		X2, X2, r10
 	add		X3, X3, r11
-	_le32_bswap_4x	X0, X1, X2, X3,  r8, r9, r10
+	_le32_bswap_4x	X0, X1, X2, X3,  r8
 	ldmia		r12!, {r8-r11}
 	eor		X0, X0, r8
 	eor		X1, X1, r9
@@ -216,7 +199,7 @@
 	ldmia		r12!, {X0-X3}
 	add		X6, r10, X6, ror #brot
 	add		X7, r11, X7, ror #brot
-	_le32_bswap_4x	X4, X5, X6, X7,  r8, r9, r10
+	_le32_bswap_4x	X4, X5, X6, X7,  r8
 	eor		X4, X4, X0
 	eor		X5, X5, X1
 	eor		X6, X6, X2
@@ -231,7 +214,7 @@
 	add		r1, r1, r9		// x9
 	add		r6, r6, r10		// x10
 	add		r7, r7, r11		// x11
-	_le32_bswap_4x	r0, r1, r6, r7,  r8, r9, r10
+	_le32_bswap_4x	r0, r1, r6, r7,  r8
 	ldmia		r12!, {r8-r11}
 	eor		r0, r0, r8		// x8
 	eor		r1, r1, r9		// x9
@@ -245,7 +228,7 @@
 	add		r3, r9, r3, ror #drot	// x13
 	add		r4, r10, r4, ror #drot	// x14
 	add		r5, r11, r5, ror #drot	// x15
-	_le32_bswap_4x	r2, r3, r4, r5,  r9, r10, r11
+	_le32_bswap_4x	r2, r3, r4, r5,  r9
 	  ldr		r9, [sp, #72]		// load LEN
 	eor		r2, r2, r0		// x12
 	eor		r3, r3, r1		// x13
@@ -301,7 +284,7 @@
 	add		X1, X1, r9
 	add		X2, X2, r10
 	add		X3, X3, r11
-	_le32_bswap_4x	X0, X1, X2, X3,  r8, r9, r10
+	_le32_bswap_4x	X0, X1, X2, X3,  r8
 	stmia		r14!, {X0-X3}
 
 	// Save keystream for x4-x7
@@ -311,7 +294,7 @@
 	add		X5, r9, X5, ror #brot
 	add		X6, r10, X6, ror #brot
 	add		X7, r11, X7, ror #brot
-	_le32_bswap_4x	X4, X5, X6, X7,  r8, r9, r10
+	_le32_bswap_4x	X4, X5, X6, X7,  r8
 	  add		r8, sp, #64
 	stmia		r14!, {X4-X7}
 
@@ -323,7 +306,7 @@
 	add		r1, r1, r9		// x9
 	add		r6, r6, r10		// x10
 	add		r7, r7, r11		// x11
-	_le32_bswap_4x	r0, r1, r6, r7,  r8, r9, r10
+	_le32_bswap_4x	r0, r1, r6, r7,  r8
 	stmia		r14!, {r0,r1,r6,r7}
 	__ldrd		r8, r9, sp, 144
 	__ldrd		r10, r11, sp, 152
@@ -331,7 +314,7 @@
 	add		r3, r9, r3, ror #drot	// x13
 	add		r4, r10, r4, ror #drot	// x14
 	add		r5, r11, r5, ror #drot	// x15
-	_le32_bswap_4x	r2, r3, r4, r5,  r9, r10, r11
+	_le32_bswap_4x	r2, r3, r4, r5,  r9
 	stmia		r14, {r2-r5}
 
 	// Stack: ks0-ks15 unused0-unused7 x0-x15 OUT IN LEN
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] crypto: arm/chacha-scalar - switch to common rev_32 macro

Quoted 4 lines · Ard Biesheuvel

Drop the local definition of a byte swapping macro and use the common one instead.

Gr{oetje,eeting}s,

Geert

Signature · 10 lines
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
Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] crypto: arm/chacha-scalar - switch to common rev_32 macro

In reply to Ard Biesheuvel
Quoted 4 lines · Ard Biesheuvel

Drop the local definition of a byte swapping macro and use the common one instead.

Yours,
Linus Walleij

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

#10 lore raw
In reply to Ard Biesheuvel

Hi Ard,

Thanks for your series!

Quoted 4 lines · Ard Biesheuvel

Consolidate the byte swapping macros used in various places, and use them throughout. Patches #2 and #3 will be sent to Herbert for merging via the crypto tree once patch #1 is merged (or if Russell prefers to ack patch #1 instead, the whole series can go through the crypto tree)

Patch #1 depends on commit 3c0899539253e7e6 ("ARM: 9035/1: uncompress:
Add be32tocpu macro") in Russell's for-next branch, hence it cannot be applied to the crypto tree yet.

Gr{oetje,eeting}s,

Geert

Signature · 10 lines
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
Reviewed-by on the v1 series
#11 lore raw
In reply to Ard Biesheuvel
Quoted 9 lines · Ard Biesheuvel

Consolidate the byte swapping macros used in various places, and use them throughout. Patches #2 and #3 will be sent to Herbert for merging via the crypto tree once patch #1 is merged (or if Russell prefers to ack patch #1 instead, the whole series can go through the crypto tree)

Cc Geert Uytterhoeven <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Eric Biggers <[email protected]>
Cc Linus Walleij <[email protected]>
Quoted 6 lines

Ard Biesheuvel (3):
ARM: assembler: generalize byte swapping macro into rev_32
crypto: arm/aes-scalar - switch to common rev_32/mov_l macros
crypto: arm/chacha-scalar - switch to common rev_32 macro

Quoted 15 lines
 arch/arm/boot/compressed/head.S      |  5 +--
 arch/arm/crypto/aes-cipher-core.S    | 42 +++++--------------
 arch/arm/crypto/chacha-scalar-core.S | 43 ++++++--------------
 arch/arm/include/asm/assembler.h     | 11 +++++
 4 files changed, 35 insertions(+), 66 deletions(-)
Signature · 7 lines
2.17.1


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

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