Skip to content

Commit 626ddb2

Browse files
ebiggersherbertx
authored andcommitted
crypto: powerpc - convert to use crypto_simd_usable()
Replace all calls to in_interrupt() in the PowerPC crypto code with !crypto_simd_usable(). This causes the crypto self-tests to test the no-SIMD code paths when CONFIG_CRYPTO_MANAGER_EXTRA_TESTS=y. The p8_ghash algorithm is currently failing and needs to be fixed, as it produces the wrong digest when no-SIMD updates are mixed with SIMD ones. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 0edf859 commit 626ddb2

8 files changed

Lines changed: 25 additions & 17 deletions

File tree

arch/powerpc/crypto/crc32c-vpmsum_glue.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include <linux/crc32.h>
22
#include <crypto/internal/hash.h>
3+
#include <crypto/internal/simd.h>
34
#include <linux/init.h>
45
#include <linux/module.h>
56
#include <linux/string.h>
67
#include <linux/kernel.h>
78
#include <linux/cpufeature.h>
9+
#include <asm/simd.h>
810
#include <asm/switch_to.h>
911

1012
#define CHKSUM_BLOCK_SIZE 1
@@ -22,7 +24,7 @@ static u32 crc32c_vpmsum(u32 crc, unsigned char const *p, size_t len)
2224
unsigned int prealign;
2325
unsigned int tail;
2426

25-
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || in_interrupt())
27+
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || !crypto_simd_usable())
2628
return __crc32c_le(crc, p, len);
2729

2830
if ((unsigned long)p & VMX_ALIGN_MASK) {

arch/powerpc/crypto/crct10dif-vpmsum_glue.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
#include <linux/crc-t10dif.h>
1414
#include <crypto/internal/hash.h>
15+
#include <crypto/internal/simd.h>
1516
#include <linux/init.h>
1617
#include <linux/module.h>
1718
#include <linux/string.h>
1819
#include <linux/kernel.h>
1920
#include <linux/cpufeature.h>
21+
#include <asm/simd.h>
2022
#include <asm/switch_to.h>
2123

2224
#define VMX_ALIGN 16
@@ -32,7 +34,7 @@ static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
3234
unsigned int tail;
3335
u32 crc = crci;
3436

35-
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || in_interrupt())
37+
if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || !crypto_simd_usable())
3638
return crc_t10dif_generic(crc, p, len);
3739

3840
if ((unsigned long)p & VMX_ALIGN_MASK) {

arch/powerpc/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ generic-y += preempt.h
1111
generic-y += rwsem.h
1212
generic-y += vtime.h
1313
generic-y += msi.h
14+
generic-y += simd.h

drivers/crypto/vmx/aes.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <linux/err.h>
2424
#include <linux/crypto.h>
2525
#include <linux/delay.h>
26-
#include <linux/hardirq.h>
26+
#include <asm/simd.h>
2727
#include <asm/switch_to.h>
2828
#include <crypto/aes.h>
29+
#include <crypto/internal/simd.h>
2930

3031
#include "aesp8-ppc.h"
3132

@@ -92,7 +93,7 @@ static void p8_aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
9293
{
9394
struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
9495

95-
if (in_interrupt()) {
96+
if (!crypto_simd_usable()) {
9697
crypto_cipher_encrypt_one(ctx->fallback, dst, src);
9798
} else {
9899
preempt_disable();
@@ -109,7 +110,7 @@ static void p8_aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
109110
{
110111
struct p8_aes_ctx *ctx = crypto_tfm_ctx(tfm);
111112

112-
if (in_interrupt()) {
113+
if (!crypto_simd_usable()) {
113114
crypto_cipher_decrypt_one(ctx->fallback, dst, src);
114115
} else {
115116
preempt_disable();

drivers/crypto/vmx/aes_cbc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <linux/err.h>
2424
#include <linux/crypto.h>
2525
#include <linux/delay.h>
26-
#include <linux/hardirq.h>
26+
#include <asm/simd.h>
2727
#include <asm/switch_to.h>
2828
#include <crypto/aes.h>
29+
#include <crypto/internal/simd.h>
2930
#include <crypto/scatterwalk.h>
3031
#include <crypto/skcipher.h>
3132

@@ -100,7 +101,7 @@ static int p8_aes_cbc_encrypt(struct blkcipher_desc *desc,
100101
struct p8_aes_cbc_ctx *ctx =
101102
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
102103

103-
if (in_interrupt()) {
104+
if (!crypto_simd_usable()) {
104105
SYNC_SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
105106
skcipher_request_set_sync_tfm(req, ctx->fallback);
106107
skcipher_request_set_callback(req, desc->flags, NULL, NULL);
@@ -139,7 +140,7 @@ static int p8_aes_cbc_decrypt(struct blkcipher_desc *desc,
139140
struct p8_aes_cbc_ctx *ctx =
140141
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
141142

142-
if (in_interrupt()) {
143+
if (!crypto_simd_usable()) {
143144
SYNC_SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
144145
skcipher_request_set_sync_tfm(req, ctx->fallback);
145146
skcipher_request_set_callback(req, desc->flags, NULL, NULL);

drivers/crypto/vmx/aes_ctr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <linux/err.h>
2424
#include <linux/crypto.h>
2525
#include <linux/delay.h>
26-
#include <linux/hardirq.h>
26+
#include <asm/simd.h>
2727
#include <asm/switch_to.h>
2828
#include <crypto/aes.h>
29+
#include <crypto/internal/simd.h>
2930
#include <crypto/scatterwalk.h>
3031
#include <crypto/skcipher.h>
3132

@@ -119,7 +120,7 @@ static int p8_aes_ctr_crypt(struct blkcipher_desc *desc,
119120
struct p8_aes_ctr_ctx *ctx =
120121
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
121122

122-
if (in_interrupt()) {
123+
if (!crypto_simd_usable()) {
123124
SYNC_SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
124125
skcipher_request_set_sync_tfm(req, ctx->fallback);
125126
skcipher_request_set_callback(req, desc->flags, NULL, NULL);

drivers/crypto/vmx/aes_xts.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <linux/err.h>
2424
#include <linux/crypto.h>
2525
#include <linux/delay.h>
26-
#include <linux/hardirq.h>
26+
#include <asm/simd.h>
2727
#include <asm/switch_to.h>
2828
#include <crypto/aes.h>
29+
#include <crypto/internal/simd.h>
2930
#include <crypto/scatterwalk.h>
3031
#include <crypto/xts.h>
3132
#include <crypto/skcipher.h>
@@ -109,7 +110,7 @@ static int p8_aes_xts_crypt(struct blkcipher_desc *desc,
109110
struct p8_aes_xts_ctx *ctx =
110111
crypto_tfm_ctx(crypto_blkcipher_tfm(desc->tfm));
111112

112-
if (in_interrupt()) {
113+
if (!crypto_simd_usable()) {
113114
SYNC_SKCIPHER_REQUEST_ON_STACK(req, ctx->fallback);
114115
skcipher_request_set_sync_tfm(req, ctx->fallback);
115116
skcipher_request_set_callback(req, desc->flags, NULL, NULL);

drivers/crypto/vmx/ghash.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@
2323
#include <linux/err.h>
2424
#include <linux/crypto.h>
2525
#include <linux/delay.h>
26-
#include <linux/hardirq.h>
26+
#include <asm/simd.h>
2727
#include <asm/switch_to.h>
2828
#include <crypto/aes.h>
2929
#include <crypto/ghash.h>
3030
#include <crypto/scatterwalk.h>
3131
#include <crypto/internal/hash.h>
32+
#include <crypto/internal/simd.h>
3233
#include <crypto/b128ops.h>
3334

34-
#define IN_INTERRUPT in_interrupt()
35-
3635
void gcm_init_p8(u128 htable[16], const u64 Xi[2]);
3736
void gcm_gmult_p8(u64 Xi[2], const u128 htable[16]);
3837
void gcm_ghash_p8(u64 Xi[2], const u128 htable[16],
@@ -131,7 +130,7 @@ static int p8_ghash_update(struct shash_desc *desc,
131130
struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
132131
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
133132

134-
if (IN_INTERRUPT) {
133+
if (!crypto_simd_usable()) {
135134
return crypto_shash_update(&dctx->fallback_desc, src,
136135
srclen);
137136
} else {
@@ -182,7 +181,7 @@ static int p8_ghash_final(struct shash_desc *desc, u8 *out)
182181
struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
183182
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
184183

185-
if (IN_INTERRUPT) {
184+
if (!crypto_simd_usable()) {
186185
return crypto_shash_final(&dctx->fallback_desc, out);
187186
} else {
188187
if (dctx->bytes) {

0 commit comments

Comments
 (0)