Skip to content

Commit 03386f9

Browse files
committed
kernel: remove hand-rolled CPU feature detection module
Delete kernel/src/cpu/features.rs now that all call sites use cpufeature-based helpers. Drop the features module from cpu/mod.rs and remove the legacy SvsmPlatform::cpuid(eax, ecx) trait method and the redundant SnpPlatform override, since CPUID queries are routed through CpuidBackend and the platform-layer cpuid() wrappers added earlier in this series. This completes the migration from locally maintained CPUID tables to the shared cpufeature crate as the single source of truth for processor feature definitions. Signed-off-by: tanish111 <tanishdesai37@gmail.com>
1 parent 1d95111 commit 03386f9

7 files changed

Lines changed: 9 additions & 220 deletions

File tree

kernel/src/cpu/features.rs

Lines changed: 0 additions & 174 deletions
This file was deleted.

kernel/src/cpu/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod cpuid;
1010
pub mod cpuset;
1111
pub mod efer;
1212
pub mod extable;
13-
pub mod features;
1413
pub mod gdt;
1514
pub mod idt;
1615
pub mod ipi;

kernel/src/cpu/sse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Author: Vasant Karasulli <vkarasulli@suse.de>
66

77
use crate::cpu::control_regs::{cr0_sse_enable, cr4_osfxsr_enable, cr4_xsave_enable};
8-
use crate::platform::{cpuid_feature, has_cpuid_feature};
8+
use crate::platform::{cpuid, has_cpuid_feature};
99
use core::arch::asm;
1010
use core::arch::x86_64::{_xgetbv, _xsetbv};
1111
use core::sync::atomic::{AtomicU64, Ordering};
@@ -81,7 +81,7 @@ pub fn xsave_area_size() -> u32 {
8181
subleaf: bit,
8282
..XSAVE_SZ
8383
};
84-
let Some(result) = cpuid_feature(&feature) else {
84+
let Some(result) = cpuid(&feature) else {
8585
log::warn!("FP feature {bit:#x} enabled but not present in CPUID");
8686
continue;
8787
};

kernel/src/cpu/vc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ mod tests {
214214
use super::*;
215215
use crate::cpu::msr::{RdtscpOut, rdtsc, rdtscp, read_msr, write_msr};
216216
use crate::locking::SpinLock;
217-
use crate::platform::cpuid_feature;
217+
use crate::platform::cpuid;
218218
use crate::platform::cpuid_value_or;
219219
use crate::sev::ghcb::GHCB;
220220
use crate::sev::utils::raw_vmmcall;
@@ -237,7 +237,7 @@ mod tests {
237237
#[cfg_attr(not(test_in_svsm), ignore = "Can only be run inside guest")]
238238
fn test_has_amd_cpuid() {
239239
if is_test_platform_type(SvsmPlatformType::Snp) {
240-
let (ebx, edx, ecx) = cpuid_feature(&MAX_STD_LEAF)
240+
let (ebx, edx, ecx) = cpuid(&MAX_STD_LEAF)
241241
.map(|r| (r.ebx, r.edx, r.ecx))
242242
.unwrap_or((0, 0, 0));
243243
let vendor_name_bytes = [ebx, edx, ecx].map(|v| v.to_le_bytes()).concat();

kernel/src/platform/mod.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use snp::SnpPlatform;
1919
use tdp::TdpPlatform;
2020

2121
use core::arch::asm;
22-
use core::arch::x86_64::{__cpuid_count, CpuidResult};
22+
use core::arch::x86_64::CpuidResult;
2323

2424
use core::fmt::Debug;
2525
use core::mem::MaybeUninit;
@@ -184,15 +184,6 @@ pub trait SvsmPlatform: Sync {
184184
hypercall_pages: &hyperv::HypercallPagesGuard<'_>,
185185
) -> hyperv::HvHypercallOutput;
186186

187-
/// Obtain CPUID using platform-specific tables.
188-
fn cpuid(eax: u32, ecx: u32) -> Option<CpuidResult>
189-
where
190-
Self: Sized,
191-
{
192-
// SAFETY: CPUID is always safe
193-
unsafe { Some(__cpuid_count(eax, ecx)) }
194-
}
195-
196187
/// Write a host-owned MSR.
197188
/// # Safety
198189
/// The caller must ensure that the requested MSR modification does mot
@@ -371,21 +362,8 @@ macro_rules! platform_method {
371362
}
372363

373364
#[inline]
374-
pub fn cpuid(leaf: u32, subleaf: u32) -> Option<CpuidResult> {
375-
match *SVSM_PLATFORM_TYPE {
376-
SvsmPlatformType::Native => <NativePlatform as SvsmPlatform>::cpuid(leaf, subleaf),
377-
SvsmPlatformType::Snp => <SnpPlatform as SvsmPlatform>::cpuid(leaf, subleaf),
378-
SvsmPlatformType::Tdp => <TdpPlatform as SvsmPlatform>::cpuid(leaf, subleaf),
379-
}
380-
}
381-
382-
#[inline]
383-
pub fn cpuid_feature(feature: &CpuidFeature) -> Option<CpuidResult> {
384-
match *SVSM_PLATFORM_TYPE {
385-
SvsmPlatformType::Native => <NativePlatform as CpuidBackend>::cpuid(feature),
386-
SvsmPlatformType::Snp => <SnpPlatform as CpuidBackend>::cpuid(feature),
387-
SvsmPlatformType::Tdp => <TdpPlatform as CpuidBackend>::cpuid(feature),
388-
}
365+
pub fn cpuid(feature: &CpuidFeature) -> Option<CpuidResult> {
366+
platform_method!(cpuid, feature)
389367
}
390368

391369
#[inline]

kernel/src/platform/native.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::cpu::x86::{
2626
use crate::error::SvsmError;
2727
use crate::hyperv::{self, hyperv_start_cpu, is_hyperv_host};
2828
use crate::io::{DEFAULT_IO_DRIVER, IOPort};
29-
use crate::platform::{cpuid_feature, cpuid_value_or, has_cpuid_feature};
29+
use crate::platform::{cpuid, cpuid_value_or, has_cpuid_feature};
3030
#[cfg(debug_assertions)]
3131
use crate::types::PageSize;
3232
use crate::utils::MemoryRegion;
@@ -89,7 +89,7 @@ impl SvsmPlatform for NativePlatform {
8989
}
9090

9191
fn get_cpu_vendor(&self) -> CpuVendor {
92-
match cpuid_feature(&MAX_STD_LEAF).map(|r| r.edx) {
92+
match cpuid(&MAX_STD_LEAF).map(|r| r.edx) {
9393
Some(0x6974_6e65) => CpuVendor::AMD,
9494
Some(0x4965_6e69) => CpuVendor::Intel,
9595
_ => CpuVendor::Unknown,

kernel/src/platform/snp.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,6 @@ impl SvsmPlatform for SnpPlatform {
299299
})
300300
}
301301

302-
fn cpuid(eax: u32, ecx: u32) -> Option<CpuidResult>
303-
where
304-
Self: Sized,
305-
{
306-
// If this is an architectural CPUID leaf, then extract the result
307-
// from the CPUID table. Otherwise, request the value from the
308-
// hypervisor.
309-
if (eax >> 28) == 4 {
310-
current_ghcb().cpuid(eax, ecx).ok()
311-
} else {
312-
cpuid_table(eax, ecx)
313-
}
314-
}
315-
316302
unsafe fn write_host_msr(&self, msr: u32, value: u64) {
317303
current_ghcb()
318304
.wrmsr(msr, value)

0 commit comments

Comments
 (0)