From 38a32585e661a6cc9eb371563b6209fdf4617eb2 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Fri, 13 Mar 2026 12:04:16 +0100 Subject: [PATCH 1/2] Revert "cpuid: remove unsafe from cpuid methods" This reverts commit fb42ebfef375117ad3dbc86a3514a17b36f6518f. Signed-off-by: Sergio Lopez --- src/cpuid/src/brand_string.rs | 4 ++-- src/cpuid/src/common.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cpuid/src/brand_string.rs b/src/cpuid/src/brand_string.rs index 369f46d83..aa2a8670b 100644 --- a/src/cpuid/src/brand_string.rs +++ b/src/cpuid/src/brand_string.rs @@ -104,7 +104,7 @@ impl BrandString { /// of the host CPU. pub fn from_host_cpuid() -> Result { let mut this = Self::new(); - let mut cpuid_regs = host_cpuid(0x8000_0000); + let mut cpuid_regs = unsafe { host_cpuid(0x8000_0000) }; if cpuid_regs.eax < 0x8000_0004 { // Brand string not supported by the host CPU @@ -112,7 +112,7 @@ impl BrandString { } for leaf in 0x8000_0002..=0x8000_0004 { - cpuid_regs = host_cpuid(leaf); + cpuid_regs = unsafe { host_cpuid(leaf) }; this.set_reg_for_leaf(leaf, Reg::EAX, cpuid_regs.eax); this.set_reg_for_leaf(leaf, Reg::EBX, cpuid_regs.ebx); this.set_reg_for_leaf(leaf, Reg::ECX, cpuid_regs.ecx); diff --git a/src/cpuid/src/common.rs b/src/cpuid/src/common.rs index 8c2ffb1cc..b44115193 100644 --- a/src/cpuid/src/common.rs +++ b/src/cpuid/src/common.rs @@ -35,7 +35,7 @@ pub fn get_cpuid(function: u32, count: u32) -> Result { } // this is safe because the host supports the `cpuid` instruction - let max_function = __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0; + let max_function = unsafe { __get_cpuid_max(function & leaf_0x80000000::LEAF_NUM).0 }; if function > max_function { return Err(Error::InvalidParameters(format!( "Function not supported: 0x{function:x}" @@ -43,7 +43,7 @@ pub fn get_cpuid(function: u32, count: u32) -> Result { } // this is safe because the host supports the `cpuid` instruction - let entry = __cpuid_count(function, count); + let entry = unsafe { __cpuid_count(function, count) }; if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 { return Err(Error::InvalidParameters(format!("Invalid count: {count}"))); } From 9bffe3c41b9087d75b665935e7b2321510c3cab3 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Fri, 13 Mar 2026 12:07:34 +0100 Subject: [PATCH 2/2] cpuid: allow unused unsafes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rust 1.94 has switched a number of cpuid-related methods from unsafe to safe. We initially removed the "unsafe" block to make clippy happy, but this would make libkrun harder to package on distros that are a bit conservative with their Rust versions. Since there isn't any real impact, let's temporarily allow unused unsafes on the affected methods instead. Suggested-by: Daniel Müller Signed-off-by: Sergio Lopez --- src/cpuid/src/brand_string.rs | 1 + src/cpuid/src/common.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cpuid/src/brand_string.rs b/src/cpuid/src/brand_string.rs index aa2a8670b..825a11fd4 100644 --- a/src/cpuid/src/brand_string.rs +++ b/src/cpuid/src/brand_string.rs @@ -102,6 +102,7 @@ impl BrandString { /// Creates a brand string, initialized from the CPUID leaves 0x80000002 through 0x80000004 /// of the host CPU. + #[allow(unused_unsafe)] pub fn from_host_cpuid() -> Result { let mut this = Self::new(); let mut cpuid_regs = unsafe { host_cpuid(0x8000_0000) }; diff --git a/src/cpuid/src/common.rs b/src/cpuid/src/common.rs index b44115193..d7474b89c 100644 --- a/src/cpuid/src/common.rs +++ b/src/cpuid/src/common.rs @@ -18,6 +18,7 @@ pub enum Error { } #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[allow(unused_unsafe)] pub fn get_cpuid(function: u32, count: u32) -> Result { // TODO: replace with validation based on `has_cpuid()` when it becomes stable: // https://doc.rust-lang.org/core/arch/x86/fn.has_cpuid.html