Commit d7866e50 authored by Uros Bizjak's avatar Uros Bizjak Committed by Herbert Xu

crypto: x86 - Remove include/asm/inst.h

Current minimum required version of binutils is 2.23,
which supports PSHUFB, PCLMULQDQ, PEXTRD, AESKEYGENASSIST,
AESIMC, AESENC, AESENCLAST, AESDEC, AESDECLAST and MOVQ
instruction mnemonics.

Substitute macros from include/asm/inst.h with a proper
instruction mnemonics in various assmbly files from
x86/crypto directory, and remove now unneeded file.

The patch was tested by calculating and comparing sha256sum
hashes of stripped object files before and after the patch,
to be sure that executable code didn't change.
Signed-off-by: default avatarUros Bizjak <ubizjak@gmail.com>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: "David S. Miller" <davem@davemloft.net>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 2c2e1836
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
*/ */
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/inst.h>
#define VMOVDQ vmovdqu #define VMOVDQ vmovdqu
......
This diff is collapsed.
...@@ -120,7 +120,6 @@ ...@@ -120,7 +120,6 @@
## ##
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/inst.h>
# constants in mergeable sections, linker can reorder and merge # constants in mergeable sections, linker can reorder and merge
.section .rodata.cst16.POLY, "aM", @progbits, 16 .section .rodata.cst16.POLY, "aM", @progbits, 16
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
*/ */
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/inst.h>
.section .rodata .section .rodata
...@@ -129,17 +128,17 @@ loop_64:/* 64 bytes Full cache line folding */ ...@@ -129,17 +128,17 @@ loop_64:/* 64 bytes Full cache line folding */
#ifdef __x86_64__ #ifdef __x86_64__
movdqa %xmm4, %xmm8 movdqa %xmm4, %xmm8
#endif #endif
PCLMULQDQ 00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
PCLMULQDQ 00, CONSTANT, %xmm2 pclmulqdq $0x00, CONSTANT, %xmm2
PCLMULQDQ 00, CONSTANT, %xmm3 pclmulqdq $0x00, CONSTANT, %xmm3
#ifdef __x86_64__ #ifdef __x86_64__
PCLMULQDQ 00, CONSTANT, %xmm4 pclmulqdq $0x00, CONSTANT, %xmm4
#endif #endif
PCLMULQDQ 0x11, CONSTANT, %xmm5 pclmulqdq $0x11, CONSTANT, %xmm5
PCLMULQDQ 0x11, CONSTANT, %xmm6 pclmulqdq $0x11, CONSTANT, %xmm6
PCLMULQDQ 0x11, CONSTANT, %xmm7 pclmulqdq $0x11, CONSTANT, %xmm7
#ifdef __x86_64__ #ifdef __x86_64__
PCLMULQDQ 0x11, CONSTANT, %xmm8 pclmulqdq $0x11, CONSTANT, %xmm8
#endif #endif
pxor %xmm5, %xmm1 pxor %xmm5, %xmm1
pxor %xmm6, %xmm2 pxor %xmm6, %xmm2
...@@ -149,8 +148,8 @@ loop_64:/* 64 bytes Full cache line folding */ ...@@ -149,8 +148,8 @@ loop_64:/* 64 bytes Full cache line folding */
#else #else
/* xmm8 unsupported for x32 */ /* xmm8 unsupported for x32 */
movdqa %xmm4, %xmm5 movdqa %xmm4, %xmm5
PCLMULQDQ 00, CONSTANT, %xmm4 pclmulqdq $0x00, CONSTANT, %xmm4
PCLMULQDQ 0x11, CONSTANT, %xmm5 pclmulqdq $0x11, CONSTANT, %xmm5
pxor %xmm5, %xmm4 pxor %xmm5, %xmm4
#endif #endif
...@@ -172,20 +171,20 @@ less_64:/* Folding cache line into 128bit */ ...@@ -172,20 +171,20 @@ less_64:/* Folding cache line into 128bit */
prefetchnta (BUF) prefetchnta (BUF)
movdqa %xmm1, %xmm5 movdqa %xmm1, %xmm5
PCLMULQDQ 0x00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
PCLMULQDQ 0x11, CONSTANT, %xmm5 pclmulqdq $0x11, CONSTANT, %xmm5
pxor %xmm5, %xmm1 pxor %xmm5, %xmm1
pxor %xmm2, %xmm1 pxor %xmm2, %xmm1
movdqa %xmm1, %xmm5 movdqa %xmm1, %xmm5
PCLMULQDQ 0x00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
PCLMULQDQ 0x11, CONSTANT, %xmm5 pclmulqdq $0x11, CONSTANT, %xmm5
pxor %xmm5, %xmm1 pxor %xmm5, %xmm1
pxor %xmm3, %xmm1 pxor %xmm3, %xmm1
movdqa %xmm1, %xmm5 movdqa %xmm1, %xmm5
PCLMULQDQ 0x00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
PCLMULQDQ 0x11, CONSTANT, %xmm5 pclmulqdq $0x11, CONSTANT, %xmm5
pxor %xmm5, %xmm1 pxor %xmm5, %xmm1
pxor %xmm4, %xmm1 pxor %xmm4, %xmm1
...@@ -193,8 +192,8 @@ less_64:/* Folding cache line into 128bit */ ...@@ -193,8 +192,8 @@ less_64:/* Folding cache line into 128bit */
jb fold_64 jb fold_64
loop_16:/* Folding rest buffer into 128bit */ loop_16:/* Folding rest buffer into 128bit */
movdqa %xmm1, %xmm5 movdqa %xmm1, %xmm5
PCLMULQDQ 0x00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
PCLMULQDQ 0x11, CONSTANT, %xmm5 pclmulqdq $0x11, CONSTANT, %xmm5
pxor %xmm5, %xmm1 pxor %xmm5, %xmm1
pxor (BUF), %xmm1 pxor (BUF), %xmm1
sub $0x10, LEN sub $0x10, LEN
...@@ -205,7 +204,7 @@ loop_16:/* Folding rest buffer into 128bit */ ...@@ -205,7 +204,7 @@ loop_16:/* Folding rest buffer into 128bit */
fold_64: fold_64:
/* perform the last 64 bit fold, also adds 32 zeroes /* perform the last 64 bit fold, also adds 32 zeroes
* to the input stream */ * to the input stream */
PCLMULQDQ 0x01, %xmm1, CONSTANT /* R4 * xmm1.low */ pclmulqdq $0x01, %xmm1, CONSTANT /* R4 * xmm1.low */
psrldq $0x08, %xmm1 psrldq $0x08, %xmm1
pxor CONSTANT, %xmm1 pxor CONSTANT, %xmm1
...@@ -220,7 +219,7 @@ fold_64: ...@@ -220,7 +219,7 @@ fold_64:
#endif #endif
psrldq $0x04, %xmm2 psrldq $0x04, %xmm2
pand %xmm3, %xmm1 pand %xmm3, %xmm1
PCLMULQDQ 0x00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
pxor %xmm2, %xmm1 pxor %xmm2, %xmm1
/* Finish up with the bit-reversed barrett reduction 64 ==> 32 bits */ /* Finish up with the bit-reversed barrett reduction 64 ==> 32 bits */
...@@ -231,11 +230,11 @@ fold_64: ...@@ -231,11 +230,11 @@ fold_64:
#endif #endif
movdqa %xmm1, %xmm2 movdqa %xmm1, %xmm2
pand %xmm3, %xmm1 pand %xmm3, %xmm1
PCLMULQDQ 0x10, CONSTANT, %xmm1 pclmulqdq $0x10, CONSTANT, %xmm1
pand %xmm3, %xmm1 pand %xmm3, %xmm1
PCLMULQDQ 0x00, CONSTANT, %xmm1 pclmulqdq $0x00, CONSTANT, %xmm1
pxor %xmm2, %xmm1 pxor %xmm2, %xmm1
PEXTRD 0x01, %xmm1, %eax pextrd $0x01, %xmm1, %eax
ret ret
SYM_FUNC_END(crc32_pclmul_le_16) SYM_FUNC_END(crc32_pclmul_le_16)
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <asm/inst.h>
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/nospec-branch.h> #include <asm/nospec-branch.h>
...@@ -225,10 +224,10 @@ LABEL crc_ %i ...@@ -225,10 +224,10 @@ LABEL crc_ %i
subq %rax, tmp # tmp -= rax*24 subq %rax, tmp # tmp -= rax*24
movq crc_init, %xmm1 # CRC for block 1 movq crc_init, %xmm1 # CRC for block 1
PCLMULQDQ 0x00,%xmm0,%xmm1 # Multiply by K2 pclmulqdq $0x00, %xmm0, %xmm1 # Multiply by K2
movq crc1, %xmm2 # CRC for block 2 movq crc1, %xmm2 # CRC for block 2
PCLMULQDQ 0x10, %xmm0, %xmm2 # Multiply by K1 pclmulqdq $0x10, %xmm0, %xmm2 # Multiply by K1
pxor %xmm2,%xmm1 pxor %xmm2,%xmm1
movq %xmm1, %rax movq %xmm1, %rax
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#include <linux/linkage.h> #include <linux/linkage.h>
#include <asm/inst.h>
#include <asm/frame.h> #include <asm/frame.h>
.section .rodata.cst16.bswap_mask, "aM", @progbits, 16 .section .rodata.cst16.bswap_mask, "aM", @progbits, 16
...@@ -51,9 +50,9 @@ SYM_FUNC_START_LOCAL(__clmul_gf128mul_ble) ...@@ -51,9 +50,9 @@ SYM_FUNC_START_LOCAL(__clmul_gf128mul_ble)
pxor DATA, T2 pxor DATA, T2
pxor SHASH, T3 pxor SHASH, T3
PCLMULQDQ 0x00 SHASH DATA # DATA = a0 * b0 pclmulqdq $0x00, SHASH, DATA # DATA = a0 * b0
PCLMULQDQ 0x11 SHASH T1 # T1 = a1 * b1 pclmulqdq $0x11, SHASH, T1 # T1 = a1 * b1
PCLMULQDQ 0x00 T3 T2 # T2 = (a1 + a0) * (b1 + b0) pclmulqdq $0x00, T3, T2 # T2 = (a1 + a0) * (b1 + b0)
pxor DATA, T2 pxor DATA, T2
pxor T1, T2 # T2 = a0 * b1 + a1 * b0 pxor T1, T2 # T2 = a0 * b1 + a1 * b0
...@@ -95,9 +94,9 @@ SYM_FUNC_START(clmul_ghash_mul) ...@@ -95,9 +94,9 @@ SYM_FUNC_START(clmul_ghash_mul)
movups (%rdi), DATA movups (%rdi), DATA
movups (%rsi), SHASH movups (%rsi), SHASH
movaps .Lbswap_mask, BSWAP movaps .Lbswap_mask, BSWAP
PSHUFB_XMM BSWAP DATA pshufb BSWAP, DATA
call __clmul_gf128mul_ble call __clmul_gf128mul_ble
PSHUFB_XMM BSWAP DATA pshufb BSWAP, DATA
movups DATA, (%rdi) movups DATA, (%rdi)
FRAME_END FRAME_END
ret ret
...@@ -114,18 +113,18 @@ SYM_FUNC_START(clmul_ghash_update) ...@@ -114,18 +113,18 @@ SYM_FUNC_START(clmul_ghash_update)
movaps .Lbswap_mask, BSWAP movaps .Lbswap_mask, BSWAP
movups (%rdi), DATA movups (%rdi), DATA
movups (%rcx), SHASH movups (%rcx), SHASH
PSHUFB_XMM BSWAP DATA pshufb BSWAP, DATA
.align 4 .align 4
.Lupdate_loop: .Lupdate_loop:
movups (%rsi), IN1 movups (%rsi), IN1
PSHUFB_XMM BSWAP IN1 pshufb BSWAP, IN1
pxor IN1, DATA pxor IN1, DATA
call __clmul_gf128mul_ble call __clmul_gf128mul_ble
sub $16, %rdx sub $16, %rdx
add $16, %rsi add $16, %rsi
cmp $16, %rdx cmp $16, %rdx
jge .Lupdate_loop jge .Lupdate_loop
PSHUFB_XMM BSWAP DATA pshufb BSWAP, DATA
movups DATA, (%rdi) movups DATA, (%rdi)
.Lupdate_just_ret: .Lupdate_just_ret:
FRAME_END FRAME_END
......
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Generate .byte code for some instructions not supported by old
* binutils.
*/
#ifndef X86_ASM_INST_H
#define X86_ASM_INST_H
#ifdef __ASSEMBLY__
#define REG_NUM_INVALID 100
#define REG_TYPE_R32 0
#define REG_TYPE_R64 1
#define REG_TYPE_XMM 2
#define REG_TYPE_INVALID 100
.macro R32_NUM opd r32
\opd = REG_NUM_INVALID
.ifc \r32,%eax
\opd = 0
.endif
.ifc \r32,%ecx
\opd = 1
.endif
.ifc \r32,%edx
\opd = 2
.endif
.ifc \r32,%ebx
\opd = 3
.endif
.ifc \r32,%esp
\opd = 4
.endif
.ifc \r32,%ebp
\opd = 5
.endif
.ifc \r32,%esi
\opd = 6
.endif
.ifc \r32,%edi
\opd = 7
.endif
#ifdef CONFIG_X86_64
.ifc \r32,%r8d
\opd = 8
.endif
.ifc \r32,%r9d
\opd = 9
.endif
.ifc \r32,%r10d
\opd = 10
.endif
.ifc \r32,%r11d
\opd = 11
.endif
.ifc \r32,%r12d
\opd = 12
.endif
.ifc \r32,%r13d
\opd = 13
.endif
.ifc \r32,%r14d
\opd = 14
.endif
.ifc \r32,%r15d
\opd = 15
.endif
#endif
.endm
.macro R64_NUM opd r64
\opd = REG_NUM_INVALID
#ifdef CONFIG_X86_64
.ifc \r64,%rax
\opd = 0
.endif
.ifc \r64,%rcx
\opd = 1
.endif
.ifc \r64,%rdx
\opd = 2
.endif
.ifc \r64,%rbx
\opd = 3
.endif
.ifc \r64,%rsp
\opd = 4
.endif
.ifc \r64,%rbp
\opd = 5
.endif
.ifc \r64,%rsi
\opd = 6
.endif
.ifc \r64,%rdi
\opd = 7
.endif
.ifc \r64,%r8
\opd = 8
.endif
.ifc \r64,%r9
\opd = 9
.endif
.ifc \r64,%r10
\opd = 10
.endif
.ifc \r64,%r11
\opd = 11
.endif
.ifc \r64,%r12
\opd = 12
.endif
.ifc \r64,%r13
\opd = 13
.endif
.ifc \r64,%r14
\opd = 14
.endif
.ifc \r64,%r15
\opd = 15
.endif
#endif
.endm
.macro XMM_NUM opd xmm
\opd = REG_NUM_INVALID
.ifc \xmm,%xmm0
\opd = 0
.endif
.ifc \xmm,%xmm1
\opd = 1
.endif
.ifc \xmm,%xmm2
\opd = 2
.endif
.ifc \xmm,%xmm3
\opd = 3
.endif
.ifc \xmm,%xmm4
\opd = 4
.endif
.ifc \xmm,%xmm5
\opd = 5
.endif
.ifc \xmm,%xmm6
\opd = 6
.endif
.ifc \xmm,%xmm7
\opd = 7
.endif
.ifc \xmm,%xmm8
\opd = 8
.endif
.ifc \xmm,%xmm9
\opd = 9
.endif
.ifc \xmm,%xmm10
\opd = 10
.endif
.ifc \xmm,%xmm11
\opd = 11
.endif
.ifc \xmm,%xmm12
\opd = 12
.endif
.ifc \xmm,%xmm13
\opd = 13
.endif
.ifc \xmm,%xmm14
\opd = 14
.endif
.ifc \xmm,%xmm15
\opd = 15
.endif
.endm
.macro REG_TYPE type reg
R32_NUM reg_type_r32 \reg
R64_NUM reg_type_r64 \reg
XMM_NUM reg_type_xmm \reg
.if reg_type_r64 <> REG_NUM_INVALID
\type = REG_TYPE_R64
.elseif reg_type_r32 <> REG_NUM_INVALID
\type = REG_TYPE_R32
.elseif reg_type_xmm <> REG_NUM_INVALID
\type = REG_TYPE_XMM
.else
\type = REG_TYPE_INVALID
.endif
.endm
.macro PFX_OPD_SIZE
.byte 0x66
.endm
.macro PFX_REX opd1 opd2 W=0
.if ((\opd1 | \opd2) & 8) || \W
.byte 0x40 | ((\opd1 & 8) >> 3) | ((\opd2 & 8) >> 1) | (\W << 3)
.endif
.endm
.macro MODRM mod opd1 opd2
.byte \mod | (\opd1 & 7) | ((\opd2 & 7) << 3)
.endm
.macro PSHUFB_XMM xmm1 xmm2
XMM_NUM pshufb_opd1 \xmm1
XMM_NUM pshufb_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX pshufb_opd1 pshufb_opd2
.byte 0x0f, 0x38, 0x00
MODRM 0xc0 pshufb_opd1 pshufb_opd2
.endm
.macro PCLMULQDQ imm8 xmm1 xmm2
XMM_NUM clmul_opd1 \xmm1
XMM_NUM clmul_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX clmul_opd1 clmul_opd2
.byte 0x0f, 0x3a, 0x44
MODRM 0xc0 clmul_opd1 clmul_opd2
.byte \imm8
.endm
.macro PEXTRD imm8 xmm gpr
R32_NUM extrd_opd1 \gpr
XMM_NUM extrd_opd2 \xmm
PFX_OPD_SIZE
PFX_REX extrd_opd1 extrd_opd2
.byte 0x0f, 0x3a, 0x16
MODRM 0xc0 extrd_opd1 extrd_opd2
.byte \imm8
.endm
.macro AESKEYGENASSIST rcon xmm1 xmm2
XMM_NUM aeskeygen_opd1 \xmm1
XMM_NUM aeskeygen_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX aeskeygen_opd1 aeskeygen_opd2
.byte 0x0f, 0x3a, 0xdf
MODRM 0xc0 aeskeygen_opd1 aeskeygen_opd2
.byte \rcon
.endm
.macro AESIMC xmm1 xmm2
XMM_NUM aesimc_opd1 \xmm1
XMM_NUM aesimc_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX aesimc_opd1 aesimc_opd2
.byte 0x0f, 0x38, 0xdb
MODRM 0xc0 aesimc_opd1 aesimc_opd2
.endm
.macro AESENC xmm1 xmm2
XMM_NUM aesenc_opd1 \xmm1
XMM_NUM aesenc_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX aesenc_opd1 aesenc_opd2
.byte 0x0f, 0x38, 0xdc
MODRM 0xc0 aesenc_opd1 aesenc_opd2
.endm
.macro AESENCLAST xmm1 xmm2
XMM_NUM aesenclast_opd1 \xmm1
XMM_NUM aesenclast_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX aesenclast_opd1 aesenclast_opd2
.byte 0x0f, 0x38, 0xdd
MODRM 0xc0 aesenclast_opd1 aesenclast_opd2
.endm
.macro AESDEC xmm1 xmm2
XMM_NUM aesdec_opd1 \xmm1
XMM_NUM aesdec_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX aesdec_opd1 aesdec_opd2
.byte 0x0f, 0x38, 0xde
MODRM 0xc0 aesdec_opd1 aesdec_opd2
.endm
.macro AESDECLAST xmm1 xmm2
XMM_NUM aesdeclast_opd1 \xmm1
XMM_NUM aesdeclast_opd2 \xmm2
PFX_OPD_SIZE
PFX_REX aesdeclast_opd1 aesdeclast_opd2
.byte 0x0f, 0x38, 0xdf
MODRM 0xc0 aesdeclast_opd1 aesdeclast_opd2
.endm
.macro MOVQ_R64_XMM opd1 opd2
REG_TYPE movq_r64_xmm_opd1_type \opd1
.if movq_r64_xmm_opd1_type == REG_TYPE_XMM
XMM_NUM movq_r64_xmm_opd1 \opd1
R64_NUM movq_r64_xmm_opd2 \opd2
.else
R64_NUM movq_r64_xmm_opd1 \opd1
XMM_NUM movq_r64_xmm_opd2 \opd2
.endif
PFX_OPD_SIZE
PFX_REX movq_r64_xmm_opd1 movq_r64_xmm_opd2 1
.if movq_r64_xmm_opd1_type == REG_TYPE_XMM
.byte 0x0f, 0x7e
.else
.byte 0x0f, 0x6e
.endif
MODRM 0xc0 movq_r64_xmm_opd1 movq_r64_xmm_opd2
.endm
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment