crypto: p10-aes-gcm - Add asm markings necessary for kernel code

From: Herbert Xu
Date: Tue Jan 17 2023 - 02:27:26 EST


On Tue, Jan 17, 2023 at 02:47:47PM +1100, Stephen Rothwell wrote:
> Hi all,
>
> After merging the crypto tree, today's linux-next build (powerpc
> pseries_le_defconfig) failed like this:
>
> arch/powerpc/crypto/p10_aes_gcm.o: warning: objtool: .text+0x884: unannotated intra-function call
> arch/powerpc/crypto/aesp8-ppc.o: warning: objtool: aes_p8_set_encrypt_key+0x44: unannotated intra-function call
> ld: arch/powerpc/crypto/p10_aes_gcm.o: ABI version 1 is not compatible with ABI version 2 output
> ld: failed to merge target specific data of file arch/powerpc/crypto/p10_aes_gcm.o
>
> Caused by commit
>
> ca68a96c37eb ("crypto: p10-aes-gcm - An accelerated AES/GCM stitched implementation")
>
> I have applied the following hack for today.

Thanks Stephen, I'm going to update the previous fix as follows:

---8<---
_GLOBAL is needed instead of .global on Linux in assembly code.

The explicit abiversion setting is removed as the code should
with either ABI.

Mark local functions to avoid objdump warnings.

Reported-by: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
Fixes: cc40379b6e19 ("crypto: p10-aes-gcm - Glue code for AES/GCM stitched implementation")
Fixes: 3b47eccaaff4 ("crypto: p10-aes-gcm - Supporting functions for AES")
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

diff --git a/arch/powerpc/crypto/aesp8-ppc.pl b/arch/powerpc/crypto/aesp8-ppc.pl
index 50a0a18f35da..cdbcf6e13efc 100644
--- a/arch/powerpc/crypto/aesp8-ppc.pl
+++ b/arch/powerpc/crypto/aesp8-ppc.pl
@@ -121,6 +121,22 @@ my ($inp,$bits,$out,$ptr,$cnt,$rounds)=map("r$_",(3..8));
my ($zero,$in0,$in1,$key,$rcon,$mask,$tmp)=map("v$_",(0..6));
my ($stage,$outperm,$outmask,$outhead,$outtail)=map("v$_",(7..11));

+sub declare_function() {
+ my ($name) = @_;
+ if ($kernel) {
+ $code .= "SYM_FUNC_START_LOCAL($name)\n";
+ } else {
+ $code .= "L$name:\n";
+ }
+}
+
+sub end_function() {
+ my ($name) = @_;
+ if ($kernel) {
+ $code .= "SYM_FUNC_END($name)\n";
+ }
+}
+
$code.=<<___;
.machine "any"

@@ -132,13 +148,18 @@ rcon:
.long 0x1b000000, 0x1b000000, 0x1b000000, 0x1b000000 ?rev
.long 0x0d0e0f0c, 0x0d0e0f0c, 0x0d0e0f0c, 0x0d0e0f0c ?rev
.long 0,0,0,0 ?asis
-Lconsts:
+___
+&declare_function("consts");
+$code.=<<___;
mflr r0
bcl 20,31,\$+4
mflr $ptr #vvvvv "distance between . and rcon
addi $ptr,$ptr,-0x48
mtlr r0
blr
+___
+&end_function("consts");
+$code.=<<___;
.long 0
.byte 0,12,0x14,0,0,0,0,0
.asciz "AES for PowerISA 2.07, CRYPTOGAMS by <appro\@openssl.org>"
diff --git a/arch/powerpc/crypto/p10_aes_gcm.S b/arch/powerpc/crypto/p10_aes_gcm.S
index 2306ad7c5e36..153388733eae 100644
--- a/arch/powerpc/crypto/p10_aes_gcm.S
+++ b/arch/powerpc/crypto/p10_aes_gcm.S
@@ -38,8 +38,10 @@
# ===================================================================================
#

+#include <asm/ppc_asm.h>
+#include <linux/linkage.h>
+
.machine "any"
-.abiversion 1
.text

# 4x loops
@@ -569,9 +571,7 @@ ppc_aes_gcm_ghash:
# rounds is at offset 240 in rk
# Xi is at 0 in gcm_table (Xip).
#
-.global aes_p10_gcm_encrypt
-.align 5
-aes_p10_gcm_encrypt:
+_GLOBAL(aes_p10_gcm_encrypt)

SAVE_REGS

@@ -989,7 +989,7 @@ Normal_block:
# Handle multiple partial blocks for encrypt and decrypt
# operations.
#
-Do_partial_block:
+SYM_FUNC_START_LOCAL(Do_partial_block)
add 17, 15, 5
cmpdi 17, 16
bgt Big_block
@@ -1075,6 +1075,7 @@ Save_partial:

Partial_done:
blr
+SYM_FUNC_END(Do_partial_block)

#
# Write partial block
@@ -1082,7 +1083,7 @@ Partial_done:
# r12 - remaining bytes
# v15 - partial input data
#
-Write_partial_block:
+SYM_FUNC_START_LOCAL(Write_partial_block)
li 10, 192
stxvb16x 15+32, 10, 1 # last block

@@ -1097,6 +1098,7 @@ Write_last_byte:
stbu 14, 1(10)
bdnz Write_last_byte
blr
+SYM_FUNC_END(Write_partial_block)

aes_gcm_out:
# out = state
@@ -1109,9 +1111,7 @@ aes_gcm_out:
#
# 8x Decrypt
#
-.global aes_p10_gcm_decrypt
-.align 5
-aes_p10_gcm_decrypt:
+_GLOBAL(aes_p10_gcm_decrypt)

SAVE_REGS

diff --git a/arch/powerpc/crypto/ppc-xlate.pl b/arch/powerpc/crypto/ppc-xlate.pl
index 23cca703ce29..d1dcb914858c 100644
--- a/arch/powerpc/crypto/ppc-xlate.pl
+++ b/arch/powerpc/crypto/ppc-xlate.pl
@@ -198,6 +198,7 @@ my $mtsle = sub {
};

print "#include <asm/ppc_asm.h>\n" if $flavour =~ /linux/;
+print "#include <linux/linkage.h>\n" if $flavour =~ /linux/;

while($line=<>) {

--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt