From: Ard Biesheuvel <ardb@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: herbert@gondor.apana.org.au, keescook@chromium.org,
Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 6/8] crypto: aead - avoid DMA alignment for request structures unless needed
Date: Wed, 6 Apr 2022 16:27:13 +0200 [thread overview]
Message-ID: <20220406142715.2270256-7-ardb@kernel.org> (raw)
In-Reply-To: <20220406142715.2270256-1-ardb@kernel.org>
AEAD request structures are currently aligned to minimal DMA alignment
for the arcitecture, which defaults to 128 bytes on arm64. This is
excessive, and rarely needed, i.e., only when doing non-coherent inbound
DMA on the contents of the request context buffer. So let's relax this
requirement, and only use this alignment if the
CRYPTO_ALG_NEED_DMA_ALIGNMENT flag is set by the implementation.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
include/crypto/aead.h | 2 +-
include/crypto/internal/aead.h | 13 +++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
index 14db3bee0519..3a09f540c38a 100644
--- a/include/crypto/aead.h
+++ b/include/crypto/aead.h
@@ -97,7 +97,7 @@ struct aead_request {
struct scatterlist *src;
struct scatterlist *dst;
- void *__ctx[] CRYPTO_MINALIGN_ATTR;
+ void *__ctx[] CRYPTO_REQ_MINALIGN_ATTR;
};
/**
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h
index 27b7b0224ea6..b30bc33a0c75 100644
--- a/include/crypto/internal/aead.h
+++ b/include/crypto/internal/aead.h
@@ -62,7 +62,8 @@ static inline void *aead_instance_ctx(struct aead_instance *inst)
static inline void *aead_request_ctx(struct aead_request *req)
{
- return req->__ctx;
+ return PTR_ALIGN(&req->__ctx,
+ crypto_tfm_alg_req_alignmask(req->base.tfm) + 1);
}
static inline void aead_request_complete(struct aead_request *req, int err)
@@ -105,7 +106,15 @@ static inline struct crypto_aead *crypto_spawn_aead(
static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
unsigned int reqsize)
{
- aead->reqsize = reqsize;
+ unsigned int align = crypto_tfm_alg_req_alignmask(&aead->base) + 1;
+
+ /*
+ * The request structure itself is only aligned to CRYPTO_REQ_MINALIGN,
+ * so we need to add some headroom, allowing us to return a suitably
+ * aligned context buffer pointer. We also need to round up the size so
+ * we don't end up sharing a cacheline at the end of the buffer.
+ */
+ aead->reqsize = ALIGN(reqsize, align) + align - CRYPTO_REQ_MINALIGN;
}
static inline void aead_init_queue(struct aead_queue *queue,
--
2.30.2
next prev parent reply other threads:[~2022-04-06 17:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-06 14:27 [PATCH 0/8] crypto: avoid DMA padding for request structures Ard Biesheuvel
2022-04-06 14:27 ` [PATCH 1/8] crypto: add flag for algos that need DMA aligned context buffers Ard Biesheuvel
2022-04-06 14:27 ` [PATCH 2/8] crypto: safexcel - take request size after setting TFM Ard Biesheuvel
2022-04-07 4:32 ` Herbert Xu
2022-04-07 8:32 ` Ard Biesheuvel
2022-04-07 8:33 ` Ard Biesheuvel
2022-04-06 14:27 ` [PATCH 3/8] crypto: drivers - set CRYPTO_ALG_NEED_DMA_ALIGNMENT where needed Ard Biesheuvel
2022-04-06 14:27 ` [PATCH 4/8] crypto: drivers - avoid setting skcipher TFM reqsize directly Ard Biesheuvel
2022-04-06 14:27 ` [PATCH 5/8] crypto: skcipher - avoid rounding up request size to DMA alignment Ard Biesheuvel
2022-04-06 14:27 ` Ard Biesheuvel [this message]
2022-04-06 14:27 ` [PATCH 7/8] crypto: ahash - avoid DMA alignment for request structures unless needed Ard Biesheuvel
2022-04-06 20:05 ` kernel test robot
2022-04-06 14:27 ` [PATCH 8/8] crypto: safexcel - reduce alignment of stack buffer Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220406142715.2270256-7-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.