Skip to content

Commit 4818539

Browse files
committed
arm: crypto: add a check for crypto extensions support.
In some configuration the CPU may raise an exception bacause of an unknown instruction if it does not support Crypto Extensions for example in some BCM281X (RPi3B in my case) when running barebox as an EFI Payload, where the EFI stops with a synchronous execption See bellow: Synchronous Exception at 0x0000000037BFF548 SP 0x0000000037F798C0 ELR 0x0000000037BFF548 SPSR 0x20000209 FPSR 0x00000000 ESR 0x02000000 FAR 0x14F64325185430BF ESR : EC 0x00 IL 0x1 ISS 0x00000000 Signed-off-by: Chali Anis <chalianis1@gmail.com>
1 parent 1958f62 commit 4818539

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

arch/arm/crypto/sha1-ce-glue.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/linkage.h>
1515
#include <asm/byteorder.h>
1616
#include <asm/neon.h>
17+
#include <asm/sysreg.h>
1718

1819
MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
1920
MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
@@ -88,6 +89,12 @@ static struct digest_algo m = {
8889

8990
static int sha1_ce_mod_init(void)
9091
{
92+
uint64_t isar0;
93+
94+
isar0 = read_sysreg(ID_AA64ISAR0_EL1);
95+
if (!(isar0 & ID_AA64ISAR0_EL1_SHA1_MASK))
96+
return -EOPNOTSUPP;
97+
9198
return digest_algo_register(&m);
9299
}
93100
coredevice_initcall(sha1_ce_mod_init);

arch/arm/crypto/sha2-ce-glue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include <linux/linkage.h>
1515
#include <asm/byteorder.h>
1616
#include <asm/neon.h>
17-
18-
#include <asm/neon.h>
17+
#include <asm/sysreg.h>
1918

2019
MODULE_DESCRIPTION("SHA-224/SHA-256 secure hash using ARMv8 Crypto Extensions");
2120
MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
@@ -116,6 +115,11 @@ static struct digest_algo sha256 = {
116115

117116
static int sha256_ce_digest_register(void)
118117
{
118+
uint64_t isar0;
119+
120+
isar0 = read_sysreg(ID_AA64ISAR0_EL1);
121+
if (!(isar0 & ID_AA64ISAR0_EL1_SHA2_MASK))
122+
return -EOPNOTSUPP;
119123

120124
return digest_algo_register(&sha256);
121125
}

arch/arm/include/asm/sysreg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include <asm/system.h>
1313
#include <linux/stringify.h>
1414

15+
/*
16+
* ARM64 registers
17+
*/
18+
#define ID_AA64ISAR0_EL1_SHA1_MASK 0xF00UL
19+
#define ID_AA64ISAR0_EL1_SHA2_MASK 0xF000UL
20+
1521
/*
1622
* Unlike read_cpuid, calls to read_sysreg are never expected to be
1723
* optimized away or replaced with synthetic values.

0 commit comments

Comments
 (0)