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

Adding a runtime dis/enabler of DIT Capability on AArch64. #1783

Merged
merged 23 commits into from
Sep 25, 2024

Conversation

nebeid
Copy link
Contributor

@nebeid nebeid commented Aug 20, 2024

Issues:

Addresses #CryptoAlg-2503

Description of changes:

  • Provide runtime functions that mask out (and back in) the DIT CPU capability by clearing (setting) an additional bit in OPENSSL_armcap_P. This mechanism was chosen for the following reasons:

    • It does not require an additional global variable.
    • It avoids extra checks on the path of setting/resetting the DIT bit.
    • It avoids re-evaluating the CPU capability if we were to clear the DIT capability bit itself. That latter bit is now left intact.
      There were write locks added around changing OPENSSL_armcap_P. However, Thread Sanitizer warned about data race possibilities when trying to run a test with concurrent threads where one disables DIT at runtime and the other tries to check for the capability. Therefore, they are documented with a warning to use them only in initialization contexts.
  • Make the DIT functions (enable/disable and set/restore) available regardless of whether the build flag DENABLE_DATA_INDEPENDENT_TIMING=ON was used or not.

    • If the build flag was not used, then the DIT flag is not set and reset with every function and the instructions used for setting it and resetting after checking the capability are omitted and don't incur extra cost.
    • The user now has the choice, regardless of the build flag, to place armv8_set/restore_dit in the user's code.

Call-outs:

  • The (external) API armv8_enable_dit is renamed to armv8_set_dit.
  • armv8_enable_dit now means enable back the capability at runtime.
  • The build flag was renamed to ENABLE_DATA_INDEPENDENT_TIMING (removing _AARCH64).

Testing:

  • The new functions armv8_disable_dit() and arm_enable_dit() were placed in Speed(), the benchmarking function, and their effects were confirmed on Apple M2.
  • There are also thread tests to confirm that the CPU DIT bit is context-switched at the thread level. The runtime dis/enabler is at the process scope because it manipulates OPENSSL_armcap_P.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@nebeid nebeid requested a review from a team as a code owner August 20, 2024 20:30
@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.48%. Comparing base (266228a) to head (856fe71).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1783   +/-   ##
=======================================
  Coverage   78.48%   78.48%           
=======================================
  Files         585      585           
  Lines       99524    99524           
  Branches    14249    14246    -3     
=======================================
+ Hits        78112    78114    +2     
+ Misses      20776    20775    -1     
+ Partials      636      635    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@WillChilds-Klein WillChilds-Klein left a comment

Choose a reason for hiding this comment

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

I see changes to cpu_aarch64_linux.c and cpu_aarch64_apple.c. do we need to udpate cpu_aarch64_win.c as well?

CMakeLists.txt Outdated Show resolved Hide resolved
tool/speed.cc Show resolved Hide resolved
tool/speed.cc Show resolved Hide resolved
include/openssl/arm_arch.h Show resolved Hide resolved
include/openssl/crypto.h Outdated Show resolved Hide resolved
include/openssl/crypto.h Outdated Show resolved Hide resolved
crypto/fipsmodule/cpucap/cpu_aarch64.c Show resolved Hide resolved
crypto/fipsmodule/cpucap/cpu_aarch64.c Show resolved Hide resolved
…isable is used for the (perceived) CPU capability.
@nebeid nebeid force-pushed the dit-flag-2 branch 3 times, most recently from 67b68c1 to 37f707e Compare September 13, 2024 19:50
BUILDING.md Outdated Show resolved Hide resolved
crypto/evp_extra/p_dh_asn1.c Show resolved Hide resolved
include/openssl/crypto.h Outdated Show resolved Hide resolved
crypto/fipsmodule/cpucap/cpu_aarch64.c Outdated Show resolved Hide resolved
tool/speed.cc Outdated Show resolved Hide resolved
crypto/fipsmodule/cpucap/internal.h Outdated Show resolved Hide resolved
crypto/fipsmodule/cpucap/cpu_aarch64_dit_test.cc Outdated Show resolved Hide resolved
@nebeid nebeid merged commit fbeb5e8 into aws:main Sep 25, 2024
110 checks passed
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.

5 participants