Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES hardware acceleration using AES-NI and ARMv8 CE #803

Merged
merged 5 commits into from Mar 6, 2024

Conversation

droe
Copy link
Contributor

@droe droe commented Mar 3, 2024

Introduce aes128 library code that uses hardware accelerated AES on architectures where it's supported, and will fall back to the existing software AES (Rijndael) if built without hardware acceleration, or if hardware acceleration is not supported by the CPU at run-time.

For now hardware acceleration is opt-in and requires -DWITH_AES_HW cmake argument to build. Acceleration implemented for x86_64 (AES-NI) and arm64 (ARMv8 CE) using compiler intrinsics, no assembly.

Adopt new aes128 abstraction in validate and aesrand. Invoke quick selftest at ZMap start, to ensure correct operation regardless of which AES implementation is being used.

On hardware configurations where scan rate is limited by CPU, hardware-accelerating AES can substantially improve scan rate, because packet validation as currently implemented requires an AES block encryption for every packet sent and received. I'm seeing a scan rate improvement from 10.28 Mp/s to 12.13 Mp/s with netmap on 10 GbE when using AES-NI instead of software AES.

Tested on macOS Sonoma (ARMv8 CE, clang), FreeBSD 14.0 (both AES-NI and ARMv8 CE, clang), and Ubuntu 23.10 (ARMv8 CE, GCC).

droe added 3 commits March 3, 2024 01:01
Introduce aes128 library code that uses hardware accelerated AES on
architectures where it's supported, and will fall back to the existing
software AES (Rijndael) if built without hardware acceleration, or if
hardware acceleration is not supported by the CPU at run-time.

For now it's opt-in and requires -DWITH_AES_HW cmake argument to build.
Acceleration implemented for x86_64 (AES-NI) and arm64 (ARMv8 CE).

Adopt new aes128 abstraction in validate and aesrand.

On hardware configurations where scan rate is limited by CPU,
hardware-accelerating AES can substantially improve scan rate, because
packet validation as currently implemented requires an AES block
encryption for every packet sent and received.
@phillip-stephens phillip-stephens self-requested a review March 4, 2024 17:08
Copy link
Contributor

@phillip-stephens phillip-stephens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to go through this more thoroughly but overall this looks great and a much needed/appreciated improvement. Especially with your other improvements on increasing send rate, CPU bottlenecking becomes more possible.

Do need to request changes to the copyright, more details in my comment, but thank you overall!

lib/aes128.c Show resolved Hide resolved
@droe
Copy link
Contributor Author

droe commented Mar 4, 2024

To be fair, while this was fun and turned out more presentable than I initially feared, it would probably be better to replace the hw acceleration bits (as well as the software Rijndael routines) with OpenSSL at some point, for an always-on solution. I just could not bring myself to deal with the plethora of portability challenges that come with using the various flavours of OpenSSL.

@zakird
Copy link
Member

zakird commented Mar 4, 2024

Yeah, I don't really want to have to deal with OpenSSL in all honesty. I think given that this is a performance optimization that you'd probably only really care about for super high send rates, it's fine to have it only work on x86_64 and arm64 is pretty reasonable.

Copy link
Contributor

@phillip-stephens phillip-stephens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@phillip-stephens phillip-stephens merged commit 3038ace into zmap:main Mar 6, 2024
7 checks passed
@droe droe deleted the droe/aes-hw branch March 11, 2024 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants