Skip to contentSkip to conversation

crypto: serpent - mark __serpent_setkey_sbox noinline

PATCH In review Arnd Bergmann 3 participants 5 messages Jun 18, 2019 – Jun 29, 2019 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 crypto: serpent - mark __serpent_setkey_sbox noinline

The same bug that gcc hit in the past is apparently now showing up with clang, which decides to inline __serpent_setkey_sbox:

crypto/serpent_generic.c:268:5: error: stack frame size of 2112 bytes in function '__serpent_setkey' [-Werror,-Wframe-larger-than=]

Marking it 'noinline' reduces the stack usage from 2112 bytes to 192 and 96 bytes, respectively, and seems to generate more useful object code.

Fixes c871c10e4ea7 ("crypto: serpent - improve __serpent_setkey with UBSAN")

---
v2: style improvements suggested by Eric Biggers

---
 crypto/serpent_generic.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
crypto/serpent_generic.c +7 -1
index e57757904677..56fa665a4f01 100644
@@ -225,7 +225,13 @@
 	x4 ^= x2;					\
 	})
 
-static void __serpent_setkey_sbox(u32 r0, u32 r1, u32 r2, u32 r3, u32 r4, u32 *k)
+/*
+ * both gcc and clang have misoptimized this function in the past,
+ * producing horrible object code from spilling temporary variables
+ * on the stack. Forcing this part out of line avoids that.
+ */
+static noinline void __serpent_setkey_sbox(u32 r0, u32 r1, u32 r2,
+					   u32 r3, u32 r4, u32 *k)
 {
 	k += 100;
 	S3(r3, r4, r0, r1, r2); store_and_load_keys(r1, r2, r4, r3, 28, 24);
Signature · 1 line
2.20.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 39 lines · Arnd Bergmann

The same bug that gcc hit in the past is apparently now showing up with clang, which decides to inline __serpent_setkey_sbox:

crypto/serpent_generic.c:268:5: error: stack frame size of 2112 bytes in function '__serpent_setkey' [-Werror,-Wframe-larger-than=]

Marking it 'noinline' reduces the stack usage from 2112 bytes to 192 and 96 bytes, respectively, and seems to generate more useful object code.

Fixes c871c10e4ea7 ("crypto: serpent - improve __serpent_setkey with UBSAN")

---
v2: style improvements suggested by Eric Biggers

---
 crypto/serpent_generic.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
crypto/serpent_generic.c +7 -1
index e57757904677..56fa665a4f01 100644
@@ -225,7 +225,13 @@
 	x4 ^= x2;					\
 	})
 
-static void __serpent_setkey_sbox(u32 r0, u32 r1, u32 r2, u32 r3, u32 r4, u32 *k)
+/*
+ * both gcc and clang have misoptimized this function in the past,
+ * producing horrible object code from spilling temporary variables
+ * on the stack. Forcing this part out of line avoids that.
+ */
+static noinline void __serpent_setkey_sbox(u32 r0, u32 r1, u32 r2,
+					   u32 r3, u32 r4, u32 *k)
 {
 	k += 100;
 	S3(r3, r4, r0, r1, r2); store_and_load_keys(r1, r2, r4, r3, 28, 24);
Signature · 1 line
2.20.0

- Eric

maintainer
#2 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

The same bug that gcc hit in the past is apparently now showing up with clang, which decides to inline __serpent_setkey_sbox:

crypto/serpent_generic.c:268:5: error: stack frame size of 2112 bytes in function '__serpent_setkey' [-Werror,-Wframe-larger-than=]

Marking it 'noinline' reduces the stack usage from 2112 bytes to 192 and 96 bytes, respectively, and seems to generate more useful object code.

Quoted 7 lines
Fixes c871c10e4ea7 ("crypto: serpent - improve __serpent_setkey with UBSAN")

---
v2: style improvements suggested by Eric Biggers

---
 crypto/serpent_generic.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#3 lore raw
Quoted 18 lines · Herbert Xu
Quoted 9 lines · Arnd Bergmann

The same bug that gcc hit in the past is apparently now showing up with clang, which decides to inline __serpent_setkey_sbox:

crypto/serpent_generic.c:268:5: error: stack frame size of 2112 bytes in function '__serpent_setkey' [-Werror,-Wframe-larger-than=]

Marking it 'noinline' reduces the stack usage from 2112 bytes to 192 and 96 bytes, respectively, and seems to generate more useful object code.

Quoted 7 lines
Fixes c871c10e4ea7 ("crypto: serpent - improve __serpent_setkey with UBSAN")

---
v2: style improvements suggested by Eric Biggers

---
 crypto/serpent_generic.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 2 lines

Patch applied. Thanks.

Hi Herbert, seems you forgot to push? I don't see this in cryptodev.

- Eric

maintainer
#4 lore raw
Quoted 2 lines · Eric Biggers

Hi Herbert, seems you forgot to push? I don't see this in cryptodev.

Yes you're right. It should be there now.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt