Skip to content

Commit 3741ac2

Browse files
committed
crypto: drbg - Align buffers to at least a cache line
None of the ciphers used by the DRBG have an alignment requirement; thus, they all return 0 from .crypto_init, resulting in inconsistent alignment across all buffers. Align all buffers to at least a cache line to improve performance. This is especially useful when multiple DRBG instances are used, since it prevents false sharing of cache lines between the different instances. Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
1 parent 3c8c29a commit 3741ac2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crypto/drbg.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,12 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)
12831283
if (ret < 0)
12841284
goto err;
12851285

1286+
/*
1287+
* Align to at least a cache line for better performance. This also
1288+
* prevents false sharing of cache lines between different instances.
1289+
*/
1290+
ret = max(ret, L1_CACHE_BYTES - 1);
1291+
12861292
drbg->Vbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL);
12871293
if (!drbg->Vbuf) {
12881294
ret = -ENOMEM;

0 commit comments

Comments
 (0)