Skip to content

Commit 8633fcd

Browse files
committed
chore: mark CPUID-related functions with allow(unused_unsafe)
As of rust toolchain version 1.94.0, CPUID-related functions from the standard library are no longer unsafe [1]. However, we cannot simply remove them as the nightly toolchain used by Kani has not been updated to a version with this change. Add TODO comments to remove unsafe blocks when Kani toolchain is updated. [1]: rust-lang/stdarch#1935 Signed-off-by: James Curtis <jxcurtis@amazon.co.uk>
1 parent 8034795 commit 8633fcd

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/vmm/src/arch/x86_64/cpu_model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ impl CpuModel {
6060
pub fn get_cpu_model() -> Self {
6161
// SAFETY: This operation is safe as long as the processor implements this CPUID function.
6262
// 0x1 is the defined code for getting the processor version information.
63+
// TODO: Remove `unsafe` block when Kani nightly toolchain is updated to be >=1.94.0
64+
#[allow(unused_unsafe)]
6365
let eax = unsafe { host_cpuid(0x1) }.eax;
6466
CpuModel::from(&eax)
6567
}

src/vmm/src/cpu_config/x86_64/cpuid/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub enum GetCpuidError {
2525
/// - When the given `leaf` is more than `max_leaf` supported by CPUID.
2626
/// - When the CPUID leaf `sub-leaf` is invalid (all its register equal 0).
2727
pub fn get_cpuid(leaf: u32, subleaf: u32) -> Result<std::arch::x86_64::CpuidResult, GetCpuidError> {
28+
// TODO: Remove `unsafe` block when Kani nightly toolchain is updated to be >=1.94.0
29+
#[allow(unused_unsafe)]
2830
let max_leaf =
2931
// JUSTIFICATION: There is no safe alternative.
3032
// SAFETY: This is safe because the host supports the `cpuid` instruction
@@ -144,6 +146,8 @@ mod tests {
144146

145147
#[test]
146148
fn get_cpuid_unsupported_leaf() {
149+
// TODO: Remove `unsafe` block when Kani nightly toolchain is updated to be >=1.94.0
150+
#[allow(unused_unsafe)]
147151
let max_leaf =
148152
// JUSTIFICATION: There is no safe alternative.
149153
// SAFETY: This is safe because the host supports the `cpuid` instruction

src/vmm/src/cpu_config/x86_64/cpuid/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ fn cpuid(leaf: u32) -> std::arch::x86_64::CpuidResult {
7777
fn cpuid_count(leaf: u32, subleaf: u32) -> std::arch::x86_64::CpuidResult {
7878
// JUSTIFICATION: There is no safe alternative.
7979
// SAFETY: The `cfg(cpuid)` wrapping the `cpuid` module guarantees `CPUID` is supported.
80+
// TODO: Remove `unsafe` block when Kani nightly toolchain is updated to be >=1.94.0
81+
#[allow(unused_unsafe)]
8082
unsafe { std::arch::x86_64::__cpuid_count(leaf, subleaf) }
8183
}
8284

0 commit comments

Comments
 (0)