Skip to content

Commit 5701b1d

Browse files
committed
runtime-rs: Allow unused_unsafe around CPUID for mixed rustc versions
std::arch x86_64 CPUID helpers are still unsafe fn on older rustc; rustc 1.94+ treats them as safe and reports redundant unsafe as errors under -D warnings. Keep explicit unsafe blocks and add targeted #[allow(unused_unsafe)] with TODOs until all supported toolchains match (see rust-lang/stdarch#1935; same pattern as firecracker in JamesC1305/firecracker@ceb25ce). Fixes: kata-containers#12835 Signed-off-by: Christophe de Dinechin <dinechin@redhat.com> Made-with: Cursor
1 parent bd48de5 commit 5701b1d

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/dragonball/dbs_arch/src/x86_64/cpuid/brand_string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl BrandString {
101101

102102
/// Creates a brand string, initialized from the CPUID leaves 0x80000002 through 0x80000004
103103
/// of the host CPU.
104+
#[allow(unused_unsafe)]
104105
fn from_host_cpuid() -> Result<Self, Error> {
105106
let mut this = Self::new();
106107
let mut cpuid_regs = unsafe { host_cpuid(0x8000_0000) };
@@ -311,6 +312,7 @@ mod tests {
311312
use super::*;
312313

313314
#[test]
315+
#[allow(unused_unsafe)]
314316
fn test_brand_string() {
315317
#[inline]
316318
fn pack_u32(src: &[u8]) -> u32 {

src/dragonball/dbs_arch/src/x86_64/cpuid/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub enum Error {
1616
}
1717

1818
/// Get CPUID value for (`function`, `count`).
19+
// TODO: Remove `unsafe` / `#[allow(unused_unsafe)]` when every rustc we build with matches the
20+
// stdarch change where these intrinsics are safe (rustc 1.94+); keep for older toolchains.
21+
#[allow(unused_unsafe)]
1922
pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
2023
#[cfg(target_env = "sgx")]
2124
{

src/libs/kata-sys-util/src/protection.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ pub fn arch_guest_protection(
126126
// shouldn't hurt to double-check and have better logging if anything
127127
// goes wrong.
128128

129+
// TODO: Remove `unsafe` / `#[allow(unused_unsafe)]` when every rustc we build with treats
130+
// `core::arch::x86_64::__cpuid` as a safe function (see rust-lang/stdarch#1935); keep for
131+
// older toolchains that still require `unsafe` here.
132+
#[allow(unused_unsafe)]
129133
let fn0 = unsafe { x86_64::__cpuid(0) };
130134
// The values in [ ebx, edx, ecx ] spell out "AuthenticAMD" when
131135
// interpreted byte-wise as ASCII. No need to bother here with an
@@ -138,7 +142,8 @@ pub fn arch_guest_protection(
138142
));
139143
}
140144

141-
// AMD64 Architecture Prgrammer's Manual Fn8000_001f docs on pg. 640
145+
// AMD64 Architecture Programmer's Manual Fn8000_001f docs on pg. 640
146+
#[allow(unused_unsafe)]
142147
let fn8000_001f = unsafe { x86_64::__cpuid(0x8000_001f) };
143148
if fn8000_001f.eax & 0x10 == 0 {
144149
return Err(ProtectionError::CheckFailed("SEV not supported".to_owned()));

0 commit comments

Comments
 (0)