Skip to content

Commit c1bbefe

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 4b90db1 commit c1bbefe

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
@@ -1292,6 +1292,12 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)
12921292
if (ret < 0)
12931293
goto err;
12941294

1295+
/*
1296+
* Align to at least a cache line for better performance. This also
1297+
* prevents false sharing of cache lines between different instances.
1298+
*/
1299+
ret = max(ret, L1_CACHE_BYTES - 1);
1300+
12951301
drbg->Vbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL);
12961302
if (!drbg->Vbuf) {
12971303
ret = -ENOMEM;

0 commit comments

Comments
 (0)