From 39c27e1312c5450f2fec819fc4ba73c12a29f614 Mon Sep 17 00:00:00 2001 From: Oliver Anderson Date: Wed, 15 Apr 2026 08:17:32 +0200 Subject: [PATCH] arch: Refactor `check_cpuid_compatibility` We make a slightly more general `check_cpuid_compatibility` function that permits the caller to specify something else than "source VM" and "destination VM" when logging an error. This way we can reuse the existing CPUID compatibility checks to ensure that the host VM is compatibile with the user selected CPU profile. In order to avoid a "refactor the world scenario" we keep the old function with its signature and instead refactor it to call the new more general internal function. Signed-off-by: Oliver Anderson On-behalf-of: SAP oliver.anderson@sap.com --- arch/src/x86_64/mod.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index 5ca200702..12a05cdb0 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -509,11 +509,27 @@ impl CpuidFeatureEntry { features } - // The function returns `Error` (a.k.a. "incompatible"), when the CPUID features from `src_vm_cpuid` - // is not a subset of those of the `dest_vm_cpuid`. + /// The function returns `Error` (a.k.a. "incompatible"), when the CPUID features from `src_vm_cpuid` + /// is not a subset of those of the `dest_vm_cpuid`. pub fn check_cpuid_compatibility( src_vm_cpuid: &[CpuIdEntry], dest_vm_cpuid: &[CpuIdEntry], + ) -> Result<(), Error> { + Self::check_cpuid_compatibility_with_descriptions( + src_vm_cpuid, + "source VM", + dest_vm_cpuid, + "destination VM", + ) + } + + /// Similar to `check_cpuid_compatibility`, but with the possibility to change + /// the description of the source and destination for logging purposes. + fn check_cpuid_compatibility_with_descriptions( + src_vm_cpuid: &[CpuIdEntry], + src_description: &str, + dest_vm_cpuid: &[CpuIdEntry], + dest_description: &str, ) -> Result<(), Error> { let feature_entry_list = &Self::checked_feature_entry_list(); let src_vm_features = Self::get_features_from_cpuid(src_vm_cpuid, feature_entry_list); @@ -540,7 +556,7 @@ impl CpuidFeatureEntry { if !entry_compatible { error!( "Detected incompatible CPUID entry: leaf={:#04x} (subleaf={:#04x}), register='{:?}', \ - compatible_check='{:?}', source VM feature='{:#04x}', destination VM feature'{:#04x}'.", + compatible_check='{:?}', {src_description} feature='{:#04x}', {dest_description} feature='{:#04x}'.", entry.function, entry.index, entry.feature_reg,