Skip to content

crypto: make skcipher/aead allocation-free on the hot path#570

Closed
jperon wants to merge 2 commits into
luainkernel:masterfrom
jperon:fix_crypto_enomem
Closed

crypto: make skcipher/aead allocation-free on the hot path#570
jperon wants to merge 2 commits into
luainkernel:masterfrom
jperon:fix_crypto_enomem

Conversation

@jperon

@jperon jperon commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Even with last optimizations, I kept having ENOMEM with ecb. This fixes it.

Reuse skcipher_request and aead_request objects through a per-runtime pool keyed by request type and size. This reduces the number of dynamic allocations on the hot path while remaining compatible under memory pressure.

Also adds stress tests for round-trip encryption/decryption.

@jperon jperon requested a review from lneto May 10, 2026 22:55
jperon and others added 2 commits June 11, 2026 14:48
Reuse skcipher_request and aead_request objects through a per-runtime pool
keyed by request type and size. This reduces the number of dynamic
allocations on the hot path while remaining compatible under memory
pressure.

Also adds stress tests for round-trip encryption/decryption.
The per-runtime request pool still allocated a freelist node on every
release and took a lock on a path that is already serialized by the
runtime lock. Replace it with a luacrypto_ctx_t held in the object's
private data: the request and the IV buffer (both fixed-size for a
given tfm) are allocated once at creation time, so encrypt/decrypt no
longer performs any fallible allocation besides the output buffer.
This removes the ENOMEM failures seen when driving skcipher/aead from
softirq context (QUIC decryption in ipparse).

The extra byte for lunatik_pushstring()'s NUL terminator in the
skcipher output buffer is kept; the explicit '\0' store is dropped as
lunatik_pushstring() already writes it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jperon jperon changed the title crypto: implement request pooling for skcipher and aead requests crypto: make skcipher/aead allocation-free on the hot path Jun 11, 2026
@jperon jperon force-pushed the fix_crypto_enomem branch from 1a269d2 to ee8c77c Compare June 11, 2026 12:50
@jperon

jperon commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@lneto I took occasion of Fable launch… and it found a far better solution to my issue!

@lneto

lneto commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@lneto I took occasion of Fable launch… and it found a far better solution to my issue!

it's indeed looking better.. I was thinking about this today, I'd like to have this for the next release.. I'll review it after finishing the support for conntrack.. I'm working on using it for tc/qos.. thank you!

@lneto

lneto commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

hey @jperon, I've made my review on #576 thanks!

@lneto lneto closed this Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants