Skip to content

cpufeatures: add Speculation Barrier (SB) support for AArch64 - #1536

Merged
tarcieri merged 1 commit into
masterfrom
cpufeatures/add-aarch64-sb-support
Sep 10, 2026
Merged

cpufeatures: add Speculation Barrier (SB) support for AArch64#1536
tarcieri merged 1 commit into
masterfrom
cpufeatures/add-aarch64-sb-support

Conversation

@tarcieri

Copy link
Copy Markdown
Member

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

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
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;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

@tarcieri
tarcieri merged commit 398d0eb into master Sep 10, 2026
16 checks passed
@tarcieri
tarcieri deleted the cpufeatures/add-aarch64-sb-support branch September 10, 2026 20:04
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.

1 participant