crypto: starfive - remove unnecessary alignmask for ahashes
authorEric Biggers <ebiggers@google.com>
Sun, 22 Oct 2023 08:10:42 +0000 (01:10 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 27 Oct 2023 10:04:29 +0000 (18:04 +0800)
The crypto API's support for alignmasks for ahash algorithms is nearly
useless, as its only effect is to cause the API to align the key and
result buffers.  The drivers that happen to be specifying an alignmask
for ahash rarely actually need it.  When they do, it's easily fixable,
especially considering that these buffers cannot be used for DMA.

In preparation for removing alignmask support from ahash, this patch
makes the starfive driver no longer use it.  This driver did actually
rely on it, but only for storing to the result buffer using int stores
in starfive_hash_copy_hash().  This patch makes
starfive_hash_copy_hash() use put_unaligned() instead.  (It really
should use a specific endianness, but that's an existing bug.)

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/starfive/jh7110-hash.c

index cc76501..b6d1808 100644 (file)
@@ -209,7 +209,8 @@ static int starfive_hash_copy_hash(struct ahash_request *req)
        data = (u32 *)req->result;
 
        for (count = 0; count < mlen; count++)
-               data[count] = readl(ctx->cryp->base + STARFIVE_HASH_SHARDR);
+               put_unaligned(readl(ctx->cryp->base + STARFIVE_HASH_SHARDR),
+                             &data[count]);
 
        return 0;
 }
@@ -628,7 +629,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA224_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -658,7 +658,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA224_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -687,7 +686,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA256_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -717,7 +715,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA256_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -746,7 +743,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA384_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -776,7 +772,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA384_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -805,7 +800,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA512_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -835,7 +829,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SHA512_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -864,7 +857,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SM3_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },
@@ -894,7 +886,6 @@ static struct ahash_engine_alg algs_sha2_sm3[] = {
                                                  CRYPTO_ALG_NEED_FALLBACK,
                        .cra_blocksize          = SM3_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct starfive_cryp_ctx),
-                       .cra_alignmask          = 3,
                        .cra_module             = THIS_MODULE,
                }
        },