cpufeatures: add Speculation Barrier (SB) support for AArch64 - #1536
Merged
Conversation
As suggested in #1472, this instruction is needed by the `aarch64-dit` crate to properly implement Data-Independent Timing: https://support.arm.com/documentation/ddi0487/mb/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-6-Memory-barriers/-B2-6-3-Speculation-Barrier The usage on Apple targets is covered here: https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Enable-DIT-for-constant-time-cryptographic-operations > "To ensure that subsequent instruction timing reflects the updated DIT > processor state, add a speculation barrier after turning on DIT. > Use the sb instruction to add a speculation barrier" This PR is effectively an extraction of the `cpufeatures`-related changes originally suggested in this patch from #1472: f31f41c
tarcieri
commented
Sep 10, 2026
Comment on lines
74
to
+93
| @@ -89,6 +90,7 @@ pub mod hwcaps { | |||
| pub const SHA2: c_ulong = libc::HWCAP_SHA2; | |||
| pub const SHA3: c_ulong = libc::HWCAP_SHA3 | libc::HWCAP_SHA512; | |||
| pub const SM4: c_ulong = libc::HWCAP_SM3 | libc::HWCAP_SM4; | |||
| pub const SB: c_ulong = libc::HWCAP_SB; | |||
Member
Author
There was a problem hiding this comment.
Note: it's unclear to what extent either DIT or SB are helpful on non-Apple targets, as covered in #1472, but they've been added here (i.e. Linux) for completeness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As suggested in #1472, this instruction is needed by the
aarch64-ditcrate to properly implement Data-Independent Timing:https://support.arm.com/documentation/ddi0487/mb/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-6-Memory-barriers/-B2-6-3-Speculation-Barrier
The usage on Apple targets is covered here:
https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Enable-DIT-for-constant-time-cryptographic-operations
This PR is effectively an extraction of the
cpufeatures-related changes originally suggested in this patch from #1472:f31f41c