Skip to contentSkip to conversation

crypto: arm64/sha: use %c constraint code in ASM_EXPORT

PATCH In review Matthias Kaehlcke 3 participants 5 messages Apr 5, 2017

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

PATCH 1/1 crypto: arm64/sha: use %c constraint code in ASM_EXPORT

From: Greg Hackmann <[email protected]>

The current definition of ASM_EXPORT doesn't work properly with clang, according to https://bugs.llvm.org//show_bug.cgi?id=27250#c3 it relies on gcc specific behavior. Change the constraint from an intermediate to an output expression which works with both gcc and clang.

From: Greg Hackmann <[email protected]>

---
 arch/arm64/crypto/sha1-ce-glue.c | 2 +-
 arch/arm64/crypto/sha2-ce-glue.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/crypto/sha1-ce-glue.c +1 -1
index aefda9868627..c71e94ba0e43 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-	asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+	asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
arch/arm64/crypto/sha2-ce-glue.c +1 -1
index 7cd587564a41..381b5fb2dcb2 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-	asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+	asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
Signature · 1 line
2.12.2.715.g7642488e1d-goog
#1 lore raw

Hoi Matthias!

Quoted 34 lines · Matthias Kaehlcke

From: Greg Hackmann <[email protected]>

The current definition of ASM_EXPORT doesn't work properly with clang, according to https://bugs.llvm.org//show_bug.cgi?id=27250#c3 it relies on gcc specific behavior. Change the constraint from an intermediate to an output expression which works with both gcc and clang.

From: Greg Hackmann <[email protected]>

---
 arch/arm64/crypto/sha1-ce-glue.c | 2 +-
 arch/arm64/crypto/sha2-ce-glue.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/crypto/sha1-ce-glue.c +1 -1
index aefda9868627..c71e94ba0e43 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
arch/arm64/crypto/sha2-ce-glue.c +0 -0
index 7cd587564a41..381b5fb2dcb2 100644

arch/arm64/crypto/sha2-ce-glue.c line 24

Quoted 8 lines
arch/arm64/crypto/sha2-ce-glue.c +1 -1
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");

I am fine with this change, although I would really like to add a better reference to the commit log. It is *very* difficult to find any documentation regarding non-trivial uses of inline asm constraints, and if %c0 is the correct syntax, surely we can quote something better than a LLVM bugzilla entry? Also, where does the distinction between 'intermediate' vs 'output' expression come from?

#2 lore raw
Quoted 43 lines · Ard Biesheuvel

Hoi Matthias!

Quoted 40 lines · Matthias Kaehlcke

From: Greg Hackmann <[email protected]>

The current definition of ASM_EXPORT doesn't work properly with clang, according to https://bugs.llvm.org//show_bug.cgi?id=27250#c3 it relies on gcc specific behavior. Change the constraint from an intermediate to an output expression which works with both gcc and clang.

From: Greg Hackmann <[email protected]>

---
 arch/arm64/crypto/sha1-ce-glue.c | 2 +-
 arch/arm64/crypto/sha2-ce-glue.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/crypto/sha1-ce-glue.c +1 -1
index aefda9868627..c71e94ba0e43 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
arch/arm64/crypto/sha2-ce-glue.c +1 -1
index 7cd587564a41..381b5fb2dcb2 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
Quoted 9 lines

arch/arm64/crypto/sha2-ce-glue.c line 24

Quoted 2 lines
arch/arm64/crypto/sha2-ce-glue.c +0 -0
 MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");

I am fine with this change, although I would really like to add a better reference to the commit log. It is *very* difficult to find any documentation regarding non-trivial uses of inline asm constraints, and if %c0 is the correct syntax, surely we can quote something better than a LLVM bugzilla entry? Also, where does the distinction between 'intermediate' vs 'output' expression come from?

FWIW, GCC docs do say (under the helpfully-obvious "x86 operand modifiers" section[1]):

c Require a constant operand and print the constant
expression with no punctuation.

Which more or less makes sense in this this context too. As an aside, though, since this is emitting a general integer argument to an assembler directive, and not an operand to an ADD instruction, how come we're using "I" and not "i" as the constraint in the first place?

Robin.

[1]:https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#x86-Operand-Modifiers

Quoted 6 lines

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw
Quoted 57 lines · Robin Murphy
Quoted 43 lines · Ard Biesheuvel

Hoi Matthias!

Quoted 40 lines · Matthias Kaehlcke

From: Greg Hackmann <[email protected]>

The current definition of ASM_EXPORT doesn't work properly with clang, according to https://bugs.llvm.org//show_bug.cgi?id=27250#c3 it relies on gcc specific behavior. Change the constraint from an intermediate to an output expression which works with both gcc and clang.

From: Greg Hackmann <[email protected]>

---
 arch/arm64/crypto/sha1-ce-glue.c | 2 +-
 arch/arm64/crypto/sha2-ce-glue.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/crypto/sha1-ce-glue.c +1 -1
index aefda9868627..c71e94ba0e43 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
arch/arm64/crypto/sha2-ce-glue.c +1 -1
index 7cd587564a41..381b5fb2dcb2 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
Quoted 9 lines

arch/arm64/crypto/sha2-ce-glue.c line 24

Quoted 2 lines
arch/arm64/crypto/sha2-ce-glue.c +0 -0
 MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");

I am fine with this change, although I would really like to add a better reference to the commit log. It is *very* difficult to find any documentation regarding non-trivial uses of inline asm constraints, and if %c0 is the correct syntax, surely we can quote something better than a LLVM bugzilla entry? Also, where does the distinction between 'intermediate' vs 'output' expression come from?

FWIW, GCC docs do say (under the helpfully-obvious "x86 operand modifiers" section[1]):

Quoted 8 lines

c Require a constant operand and print the constant
expression with no punctuation.

Which more or less makes sense in this this context too. As an aside, though, since this is emitting a general integer argument to an assembler directive, and not an operand to an ADD instruction, how come we're using "I" and not "i" as the constraint in the first place?

No reason. "I" came to mind when writing the code, and worked as expected. Perhaps we should just fix that at the same time.

#4 lore raw
In reply to Ard Biesheuvel

Hoi Ard!

El Wed, Apr 05, 2017 at 06:08:37PM +0100 Ard Biesheuvel ha dit:

Quoted 41 lines · Matthias Kaehlcke
Quoted 40 lines

From: Greg Hackmann <[email protected]>

The current definition of ASM_EXPORT doesn't work properly with clang, according to https://bugs.llvm.org//show_bug.cgi?id=27250#c3 it relies on gcc specific behavior. Change the constraint from an intermediate to an output expression which works with both gcc and clang.

From: Greg Hackmann <[email protected]>

---
 arch/arm64/crypto/sha1-ce-glue.c | 2 +-
 arch/arm64/crypto/sha2-ce-glue.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/crypto/sha1-ce-glue.c +1 -1
index aefda9868627..c71e94ba0e43 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
 MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
arch/arm64/crypto/sha2-ce-glue.c +1 -1
index 7cd587564a41..381b5fb2dcb2 100644
@@ -18,7 +18,7 @@
 #include <linux/module.h>
 
 #define ASM_EXPORT(sym, val) \
-       asm(".globl " #sym "; .set " #sym ", %0" :: "I"(val));
+       asm(".globl " #sym "; .set " #sym ", %c0" :: "I"(val));
 
Quoted 9 lines

arch/arm64/crypto/sha2-ce-glue.c line 24

Quoted 2 lines
arch/arm64/crypto/sha2-ce-glue.c +0 -0
 MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
 MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");

I am fine with this change, although I would really like to add a better reference to the commit log. It is *very* difficult to find any documentation regarding non-trivial uses of inline asm constraints, and if %c0 is the correct syntax, surely we can quote something better than a LLVM bugzilla entry? Also, where does the distinction between 'intermediate' vs 'output' expression come from?

To be honest assembly is not really my area of expertise and I relayed the information from the LLVM bug. The link to the gcc doc on x86(!) operand modifiers posted by Robin Murphy (thanks!) should be helpful to provide a more accurate commit message.

Thanks

Matthias