target-arm: add SHA-3, SM3 and SHA512 instruction support
v6 cover target-arm: add SHA-3, SM3 and SHA512 instruction support
Changes since v5:
- fix use of same register for destination and source in SHA-512 code
- use correct free() function in SHA-3 code
- drop helper for sm3ss1 in SM3 code
- include fixed version of SM4 (correct # of iterations)
- enable SM4 in user mode emulator
Changes since v4:
- restructure code changes to make it easier on the reviewer
- add Peter's R-b to #4
Changes since v3:
- don't bother with helpers for the SHA3 instructions: they are simple enough to be emitted as TCG ops directly
- rebase onto Richard's pending SVE work
Changes since v2:
- fix thinko in big-endian aware handling of 64-bit quantities: this is not needed given that the NEON registers are represented as arrays of uint64_t so they always appear in the correct order.
- add support for SM3 instructions (Chinese SHA derivative)
Changes since v1:
- update SHA512 patch to adhere more closely to the existing style, and to the way the instruction encodings are classified in the ARM ARM (#1)
- add patch implementing the new SHA3 instructions EOR3/RAX1/XAR/BCAX (#2)
- enable support for these instructions in user mode emulation (#3)
Ard Biesheuvel (5):
target/arm: implement SHA-512 instructions
target/arm: implement SHA-3 instructions
target/arm: implement SM3 instructions
target/arm: implement SM4 instructions
target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction
support
linux-user/elfload.c | 19 ++ target/arm/cpu.h | 4 + target/arm/cpu64.c | 4 + target/arm/crypto_helper.c | 277 +++++++++++++++- target/arm/helper.h | 12 + target/arm/translate-a64.c | 340 ++++++++++++++++++++ 6 files changed, 655 insertions(+), 1 deletion(-)
Signature · 1 line
2.11.0
PATCH v6 1/5 target/arm: implement SHA-512 instructions
This implements emulation of the new SHA-512 instructions that have been added as an optional extensions to the ARMv8 Crypto Extensions in ARM v8.2.
--- target/arm/cpu.h | 1 + target/arm/crypto_helper.c | 90 +++++++++++++++- target/arm/helper.h | 5 + target/arm/translate-a64.c | 110 ++++++++++++++++++++ 4 files changed, 205 insertions(+), 1 deletion(-)
target/arm/cpu.h +1 -0
@@ -1372,6 +1372,7 @@ enum arm_features {ARM_FEATURE_M_SECURITY ,/* M profile Security Extension */ ARM_FEATURE_JAZELLE ,/* has (trivial) Jazelle implementation */ ARM_FEATURE_SVE ,/* has Scalable Vector Extension */ + ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ };static inline int arm_feature (CPUARMState *env,int feature)
target/arm/crypto_helper.c +89 -1
99 lines not on this page · raw message
target/arm/helper.h +5 -0
@@ -534,6 +534,11 @@ DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) +DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) + DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)DEF_HELPER_2 (dc_zva, void, env, i64)
target/arm/translate-a64.c +110 -0
122 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v6 2/5 target/arm: implement SHA-3 instructions
In reply to Ard BiesheuvelThis implements emulation of the new SHA-3 instructions that have been added as an optional extensions to the ARMv8 Crypto Extensions in ARM v8.2.
--- target/arm/cpu.h | 1 + target/arm/translate-a64.c | 148 +++++++++++++++++++- 2 files changed, 145 insertions(+), 4 deletions(-)
target/arm/cpu.h +1 -0
@@ -1373,6 +1373,7 @@ enum arm_features {ARM_FEATURE_JAZELLE ,/* has (trivial) Jazelle implementation */ ARM_FEATURE_SVE ,/* has Scalable Vector Extension */ ARM_FEATURE_V8_SHA512 ,/* implements SHA512 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ };static inline int arm_feature (CPUARMState *env,int feature)
target/arm/translate-a64.c +144 -4
172 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v6 3/5 target/arm: implement SM3 instructions
In reply to Ard BiesheuvelThis implements emulation of the new SM3 instructions that have been added as an optional extension to the ARMv8 Crypto Extensions in ARM v8.2.
--- target/arm/cpu.h | 1 + target/arm/crypto_helper.c | 96 ++++++++++++++++++++ target/arm/helper.h | 4 + target/arm/translate-a64.c | 88 +++++++++++++++++- 4 files changed, 186 insertions(+), 3 deletions(-)
target/arm/cpu.h +1 -0
@@ -1374,6 +1374,7 @@ enum arm_features {ARM_FEATURE_SVE ,/* has Scalable Vector Extension */ ARM_FEATURE_V8_SHA512 ,/* implements SHA512 part of v8 Crypto Extensions */ ARM_FEATURE_V8_SHA3 ,/* implements SHA3 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ };static inline int arm_feature (CPUARMState *env,int feature)
target/arm/crypto_helper.c +96 -0
99 lines not on this page · raw message
target/arm/helper.h +4 -0
@@ -539,6 +539,10 @@ DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) +DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) + DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)DEF_HELPER_2 (dc_zva, void, env, i64)
target/arm/translate-a64.c +85 -3
118 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v6 4/5 target/arm: implement SM4 instructions
In reply to Ard BiesheuvelThis implements emulation of the new SM4 instructions that have been added as an optional extension to the ARMv8 Crypto Extensions in ARM v8.2.
--- target/arm/cpu.h | 1 + target/arm/crypto_helper.c | 91 ++++++++++++++++++++ target/arm/helper.h | 3 + target/arm/translate-a64.c | 8 ++ 4 files changed, 103 insertions(+)
target/arm/cpu.h +1 -0
@@ -1375,6 +1375,7 @@ enum arm_features {ARM_FEATURE_V8_SHA512 ,/* implements SHA512 part of v8 Crypto Extensions */ ARM_FEATURE_V8_SHA3 ,/* implements SHA3 part of v8 Crypto Extensions */ ARM_FEATURE_V8_SM3 ,/* implements SM3 part of v8 Crypto Extensions */ + ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ };static inline int arm_feature (CPUARMState *env,int feature)
target/arm/crypto_helper.c +91 -0
94 lines not on this page · raw message
target/arm/helper.h +3 -0
@@ -543,6 +543,9 @@ DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) +DEF_HELPER_FLAGS_2(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr) +DEF_HELPER_FLAGS_3(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) + DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32)DEF_HELPER_2 (dc_zva, void, env, i64)
target/arm/translate-a64.c +8 -0
@@ -11177,6 +11177,10 @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) feature =ARM_FEATURE_V8_SM3 ; genfn = gen_helper_crypto_sm3partw2;break ; +case 2 :/* SM4EKEY */ + feature =ARM_FEATURE_V8_SM4 ; + genfn = gen_helper_crypto_sm4ekey; +break ;default :unallocated_encoding (s);return ;
@@ -11250,6 +11254,10 @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) feature =ARM_FEATURE_V8_SHA512 ; genfn = gen_helper_crypto_sha512su0;break ; +case 1 :/* SM4E */ + feature =ARM_FEATURE_V8_SM4 ; + genfn = gen_helper_crypto_sm4e; +break ;default :unallocated_encoding (s);return ;
Signature · 1 line
2.11.0
PATCH v6 5/5 target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
In reply to Ard BiesheuvelAdd support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
--- linux-user/elfload.c | 19 +++++++++++++++++++ target/arm/cpu64.c | 4 ++++ 2 files changed, 23 insertions(+)
linux-user/elfload.c +19 -0
@@ -512,6 +512,21 @@ enum {ARM_HWCAP_A64_SHA1 =1 <<5 ,ARM_HWCAP_A64_SHA2 =1 <<6 ,ARM_HWCAP_A64_CRC32 =1 <<7 , +ARM_HWCAP_A64_ATOMICS =1 <<8 , +ARM_HWCAP_A64_FPHP =1 <<9 , +ARM_HWCAP_A64_ASIMDHP =1 <<10 , +ARM_HWCAP_A64_CPUID =1 <<11 , +ARM_HWCAP_A64_ASIMDRDM =1 <<12 , +ARM_HWCAP_A64_JSCVT =1 <<13 , +ARM_HWCAP_A64_FCMA =1 <<14 , +ARM_HWCAP_A64_LRCPC =1 <<15 , +ARM_HWCAP_A64_DCPOP =1 <<16 , +ARM_HWCAP_A64_SHA3 =1 <<17 , +ARM_HWCAP_A64_SM3 =1 <<18 , +ARM_HWCAP_A64_SM4 =1 <<19 , +ARM_HWCAP_A64_ASIMDDP =1 <<20 , +ARM_HWCAP_A64_SHA512 =1 <<21 , + ARM_HWCAP_A64_SVE = 1 << 22, };#define ELF_HWCAP get_elf_hwcap()
@@ -532,6 +547,10 @@ static uint32_t get_elf_hwcap(void)GET_FEATURE (ARM_FEATURE_V8_SHA1 ,ARM_HWCAP_A64_SHA1 );GET_FEATURE (ARM_FEATURE_V8_SHA256 ,ARM_HWCAP_A64_SHA2 );GET_FEATURE (ARM_FEATURE_CRC ,ARM_HWCAP_A64_CRC32 ); +GET_FEATURE (ARM_FEATURE_V8_SHA3 ,ARM_HWCAP_A64_SHA3 ); +GET_FEATURE (ARM_FEATURE_V8_SM3 ,ARM_HWCAP_A64_SM3 ); +GET_FEATURE (ARM_FEATURE_V8_SM4 ,ARM_HWCAP_A64_SM4 ); +GET_FEATURE (ARM_FEATURE_V8_SHA512 ,ARM_HWCAP_A64_SHA512 );#undef GET_FEATUREreturn hwcaps;
target/arm/cpu64.c +4 -0
@@ -224,6 +224,10 @@ static void aarch64_any_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_V8_AES );set_feature (&cpu->env,ARM_FEATURE_V8_SHA1 );set_feature (&cpu->env,ARM_FEATURE_V8_SHA256 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA512 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM4 );set_feature (&cpu->env,ARM_FEATURE_V8_PMULL );set_feature (&cpu->env,ARM_FEATURE_CRC ); cpu->ctr =0x80038003 ;/* 32 byte I and D cacheline size, VIPT icache */
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
Quoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
Are you aware of any processors with ARMv8.2 available yet? It might be nice to have a more recent model for system emulation and the pieces seems to be coming together.
Quoted 49 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- linux-user/elfload.c | 19 +++++++++++++++++++ target/arm/cpu64.c | 4 ++++ 2 files changed, 23 insertions(+)linux-user/elfload.c +19
-0@@ -512,6 +512,21 @@ enum {ARM_HWCAP_A64_SHA1 =1 <<5 ,ARM_HWCAP_A64_SHA2 =1 <<6 ,ARM_HWCAP_A64_CRC32 =1 <<7 , +ARM_HWCAP_A64_ATOMICS =1 <<8 , +ARM_HWCAP_A64_FPHP =1 <<9 , +ARM_HWCAP_A64_ASIMDHP =1 <<10 , +ARM_HWCAP_A64_CPUID =1 <<11 , +ARM_HWCAP_A64_ASIMDRDM =1 <<12 , +ARM_HWCAP_A64_JSCVT =1 <<13 , +ARM_HWCAP_A64_FCMA =1 <<14 , +ARM_HWCAP_A64_LRCPC =1 <<15 , +ARM_HWCAP_A64_DCPOP =1 <<16 , +ARM_HWCAP_A64_SHA3 =1 <<17 , +ARM_HWCAP_A64_SM3 =1 <<18 , +ARM_HWCAP_A64_SM4 =1 <<19 , +ARM_HWCAP_A64_ASIMDDP =1 <<20 , +ARM_HWCAP_A64_SHA512 =1 <<21 , + ARM_HWCAP_A64_SVE = 1 << 22, };#define ELF_HWCAP get_elf_hwcap()@@ -532,6 +547,10 @@ static uint32_t get_elf_hwcap(void)GET_FEATURE (ARM_FEATURE_V8_SHA1 ,ARM_HWCAP_A64_SHA1 );GET_FEATURE (ARM_FEATURE_V8_SHA256 ,ARM_HWCAP_A64_SHA2 );GET_FEATURE (ARM_FEATURE_CRC ,ARM_HWCAP_A64_CRC32 ); +GET_FEATURE (ARM_FEATURE_V8_SHA3 ,ARM_HWCAP_A64_SHA3 ); +GET_FEATURE (ARM_FEATURE_V8_SM3 ,ARM_HWCAP_A64_SM3 ); +GET_FEATURE (ARM_FEATURE_V8_SM4 ,ARM_HWCAP_A64_SM4 ); +GET_FEATURE (ARM_FEATURE_V8_SHA512 ,ARM_HWCAP_A64_SHA512 );#undef GET_FEATUREreturn hwcaps;target/arm/cpu64.c +0
-0
target/arm/cpu64.c static void aarch64_any_initfn(Object *obj) · line 233
Quoted 10 lines
target/arm/cpu64.c +4
-0@@ -224,6 +224,10 @@ static void aarch64_any_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_V8_AES );set_feature (&cpu->env,ARM_FEATURE_V8_SHA1 );set_feature (&cpu->env,ARM_FEATURE_V8_SHA256 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA512 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM4 );set_feature (&cpu->env,ARM_FEATURE_V8_PMULL );set_feature (&cpu->env,ARM_FEATURE_CRC ); cpu->ctr =0x80038003 ;/* 32 byte I and D cacheline size, VIPT icache */
--
Alex Bennée
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
Quoted 10 lines · Alex Bennée
Quoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
Are you aware of any processors with ARMv8.2 available yet? It might be nice to have a more recent model for system emulation and the pieces seems to be coming together.
I think Peter's idea was to have so kind of 'max' cpu type that enables all optional extensions in system emulation mode. AFAIK none of the Cortex-Axx cores that are public are available with these crypto features.
Quoted 63 lines
Quoted 49 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- linux-user/elfload.c | 19 +++++++++++++++++++ target/arm/cpu64.c | 4 ++++ 2 files changed, 23 insertions(+)linux-user/elfload.c +19
-0@@ -512,6 +512,21 @@ enum {ARM_HWCAP_A64_SHA1 =1 <<5 ,ARM_HWCAP_A64_SHA2 =1 <<6 ,ARM_HWCAP_A64_CRC32 =1 <<7 , +ARM_HWCAP_A64_ATOMICS =1 <<8 , +ARM_HWCAP_A64_FPHP =1 <<9 , +ARM_HWCAP_A64_ASIMDHP =1 <<10 , +ARM_HWCAP_A64_CPUID =1 <<11 , +ARM_HWCAP_A64_ASIMDRDM =1 <<12 , +ARM_HWCAP_A64_JSCVT =1 <<13 , +ARM_HWCAP_A64_FCMA =1 <<14 , +ARM_HWCAP_A64_LRCPC =1 <<15 , +ARM_HWCAP_A64_DCPOP =1 <<16 , +ARM_HWCAP_A64_SHA3 =1 <<17 , +ARM_HWCAP_A64_SM3 =1 <<18 , +ARM_HWCAP_A64_SM4 =1 <<19 , +ARM_HWCAP_A64_ASIMDDP =1 <<20 , +ARM_HWCAP_A64_SHA512 =1 <<21 , + ARM_HWCAP_A64_SVE = 1 << 22, };#define ELF_HWCAP get_elf_hwcap()@@ -532,6 +547,10 @@ static uint32_t get_elf_hwcap(void)GET_FEATURE (ARM_FEATURE_V8_SHA1 ,ARM_HWCAP_A64_SHA1 );GET_FEATURE (ARM_FEATURE_V8_SHA256 ,ARM_HWCAP_A64_SHA2 );GET_FEATURE (ARM_FEATURE_CRC ,ARM_HWCAP_A64_CRC32 ); +GET_FEATURE (ARM_FEATURE_V8_SHA3 ,ARM_HWCAP_A64_SHA3 ); +GET_FEATURE (ARM_FEATURE_V8_SM3 ,ARM_HWCAP_A64_SM3 ); +GET_FEATURE (ARM_FEATURE_V8_SM4 ,ARM_HWCAP_A64_SM4 ); +GET_FEATURE (ARM_FEATURE_V8_SHA512 ,ARM_HWCAP_A64_SHA512 );#undef GET_FEATUREreturn hwcaps;target/arm/cpu64.c +0
-0target/arm/cpu64.c static void aarch64_any_initfn(Object *obj) · line 233
Quoted 10 lines
target/arm/cpu64.c +4
-0@@ -224,6 +224,10 @@ static void aarch64_any_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_V8_AES );set_feature (&cpu->env,ARM_FEATURE_V8_SHA1 );set_feature (&cpu->env,ARM_FEATURE_V8_SHA256 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA512 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM4 );set_feature (&cpu->env,ARM_FEATURE_V8_PMULL );set_feature (&cpu->env,ARM_FEATURE_CRC ); cpu->ctr =0x80038003 ;/* 32 byte I and D cacheline size, VIPT icache */ --
Alex Bennée
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
Quoted 12 lines · Ard Biesheuvel
Quoted 10 lines · Alex Bennée
Quoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
Are you aware of any processors with ARMv8.2 available yet? It might be nice to have a more recent model for system emulation and the pieces seems to be coming together.
Quoted 4 lines
I think Peter's idea was to have so kind of 'max' cpu type that enables all optional extensions in system emulation mode. AFAIK none of the Cortex-Axx cores that are public are available with these crypto features.
Cortex-A75 is ARMv8.2. It should be available in devices this year.
HTH,
Laurent
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
Quoted 14 lines · Laurent Desnogues
Quoted 12 lines · Ard Biesheuvel
Quoted 10 lines · Alex Bennée
Quoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
Are you aware of any processors with ARMv8.2 available yet? It might be nice to have a more recent model for system emulation and the pieces seems to be coming together.
Quoted 7 lines
Quoted 4 lines
I think Peter's idea was to have so kind of 'max' cpu type that enables all optional extensions in system emulation mode. AFAIK none of the Cortex-Axx cores that are public are available with these crypto features.
Cortex-A75 is ARMv8.2. It should be available in devices this year.
Yeah, but according to the docs on infocenter.arm.com, it does not implement the newer crypto instructions.
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
In reply to Ard BiesheuvelQuoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
So another problem I've come across is I can't turn this off. I ended up doing that in my FP16 series because otherwise existing RISU tests get broken. However having an optional flag for each little set of instructions seems overkill.
Have you run any RISU tests? If you want you can add this to the aarch64.risu to generate some test patterns.
# These are optional ARMv8.2 cryptographic extensions @v8.2,Cryptographic,CryptographicSHA
# Cryptographic three-register SHA 512
# 31 21 20 16 15 14 13 12 11 10 9 5 4 0
# 11001110011 Rm 1 O 0 0 opcode Rn Rd
SHA512H A64_V 1100 1110 011 rm:5 1 0 00 00 rn:5 rd:5
SHA512H2 A64_V 1100 1110 011 rm:5 1 0 00 01 rn:5 rd:5 SHA512SUI A64_V 1100 1110 011 rm:5 1 0 00 10 rn:5 rd:5
RAX1 A64_V 1100 1110 011 rm:5 1 0 00 11 rn:5 rd:5
SM3PARTW1 A64_V 1100 1110 011 rm:5 1 1 00 00 rn:5 rd:5 SM3PARTW2 A64_V 1100 1110 011 rm:5 1 1 00 01 rn:5 rd:5
SM4 A64_V 1100 1110 011 rm:5 1 1 00 10 rn:5 rd:5
# Cryptographic four-register
# 31 23 22 21 20 16 15 14 10 9 5 4 0
# 1100 1110 0 Op0 Rm 0 Ra Rn Rd
EOR3 A64_V 1110 1110 0 00 rm:5 0 ra:5 rn:5 rd:5 BCAX A64_V 1110 1110 0 01 rm:5 0 ra:5 rn:5 rd:5 SM3SS1 A64_V 1110 1110 0 10 rm:5 0 ra:5 rn:5 rd:5
# Cryptographic two-register SHA 512
# 31 12 11 10 9 5 4 0
# 1100 1110 1100 0000 1000 op Rn Rd
SHA512SU0 A64_V 1100 1110 1100 0000 1000 00 rn:5 rd:5
SM4E A64_V 1100 1110 1100 0000 1000 01 rn:5 rd:5
@
Quoted 49 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- linux-user/elfload.c | 19 +++++++++++++++++++ target/arm/cpu64.c | 4 ++++ 2 files changed, 23 insertions(+)linux-user/elfload.c +19
-0@@ -512,6 +512,21 @@ enum {ARM_HWCAP_A64_SHA1 =1 <<5 ,ARM_HWCAP_A64_SHA2 =1 <<6 ,ARM_HWCAP_A64_CRC32 =1 <<7 , +ARM_HWCAP_A64_ATOMICS =1 <<8 , +ARM_HWCAP_A64_FPHP =1 <<9 , +ARM_HWCAP_A64_ASIMDHP =1 <<10 , +ARM_HWCAP_A64_CPUID =1 <<11 , +ARM_HWCAP_A64_ASIMDRDM =1 <<12 , +ARM_HWCAP_A64_JSCVT =1 <<13 , +ARM_HWCAP_A64_FCMA =1 <<14 , +ARM_HWCAP_A64_LRCPC =1 <<15 , +ARM_HWCAP_A64_DCPOP =1 <<16 , +ARM_HWCAP_A64_SHA3 =1 <<17 , +ARM_HWCAP_A64_SM3 =1 <<18 , +ARM_HWCAP_A64_SM4 =1 <<19 , +ARM_HWCAP_A64_ASIMDDP =1 <<20 , +ARM_HWCAP_A64_SHA512 =1 <<21 , + ARM_HWCAP_A64_SVE = 1 << 22, };#define ELF_HWCAP get_elf_hwcap()@@ -532,6 +547,10 @@ static uint32_t get_elf_hwcap(void)GET_FEATURE (ARM_FEATURE_V8_SHA1 ,ARM_HWCAP_A64_SHA1 );GET_FEATURE (ARM_FEATURE_V8_SHA256 ,ARM_HWCAP_A64_SHA2 );GET_FEATURE (ARM_FEATURE_CRC ,ARM_HWCAP_A64_CRC32 ); +GET_FEATURE (ARM_FEATURE_V8_SHA3 ,ARM_HWCAP_A64_SHA3 ); +GET_FEATURE (ARM_FEATURE_V8_SM3 ,ARM_HWCAP_A64_SM3 ); +GET_FEATURE (ARM_FEATURE_V8_SM4 ,ARM_HWCAP_A64_SM4 ); +GET_FEATURE (ARM_FEATURE_V8_SHA512 ,ARM_HWCAP_A64_SHA512 );#undef GET_FEATUREreturn hwcaps;target/arm/cpu64.c +0
-0
target/arm/cpu64.c static void aarch64_any_initfn(Object *obj) · line 233
Quoted 10 lines
target/arm/cpu64.c +4
-0@@ -224,6 +224,10 @@ static void aarch64_any_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_V8_AES );set_feature (&cpu->env,ARM_FEATURE_V8_SHA1 );set_feature (&cpu->env,ARM_FEATURE_V8_SHA256 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA512 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SHA3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM3 ); +set_feature (&cpu->env,ARM_FEATURE_V8_SM4 );set_feature (&cpu->env,ARM_FEATURE_V8_PMULL );set_feature (&cpu->env,ARM_FEATURE_CRC ); cpu->ctr =0x80038003 ;/* 32 byte I and D cacheline size, VIPT icache */
--
Alex Bennée
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
Quoted 10 lines · Alex Bennée
Quoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
So another problem I've come across is I can't turn this off. I ended up doing that in my FP16 series because otherwise existing RISU tests get broken. However having an optional flag for each little set of instructions seems overkill.
Why do the existing tests break? Are they checking UNDEF for previously-reserved bits of the encoding space?
Quoted 2 lines
Have you run any RISU tests? If you want you can add this to the aarch64.risu to generate some test patterns.
I wrote some risu patterns for testing these. I was going to send the patch out tomorrow...
(I used the tag A64_C82 rather than A64_V.)
thanks
-- PMM
Re: [Qemu-devel] [PATCH v6 5/5] target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Alex Bennée
Quoted 2 lines · Ard Biesheuvel
Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to AArch64 user mode emulation.
Quoted 7 lines
Quoted 4 lines
So another problem I've come across is I can't turn this off. I ended up doing that in my FP16 series because otherwise existing RISU tests get broken. However having an optional flag for each little set of instructions seems overkill.
Why do the existing tests break? Are they checking UNDEF for previously-reserved bits of the encoding space?
Yeah. Maybe the easiest solution is to find the undefs and re-generate everything.
Quoted 8 lines
Quoted 3 lines
Have you run any RISU tests? If you want you can add this to the aarch64.risu to generate some test patterns.
I wrote some risu patterns for testing these. I was going to send the patch out tomorrow...
(I used the tag
A64_C82rather thanA64_V.)
Ohh that is a useful use for that tag...
Quoted 3 lines
thanks
-- PMM
--
Alex Bennée
Quoted 6 lines · Ard Biesheuvel
Changes since v5:
- fix use of same register for destination and source in SHA-512 code
- use correctfree()function in SHA-3 code
- drop helper for sm3ss1 in SM3 code
- include fixed version of SM4 (correct # of iterations)
- enable SM4 in user mode emulator
Thanks -- this version passes all my tests and I've put it into target-arm.next.
-- PMM