44use crate :: cpu_config:: x86_64:: cpuid:: {
55 cpuid, CpuidEntry , CpuidKey , CpuidRegisters , CpuidTrait , KvmCpuidFlags ,
66} ;
7+ use crate :: vmm_config:: machine_config:: MAX_SUPPORTED_VCPUS ;
78
89/// Error type for [`super::Cpuid::normalize`].
910#[ allow( clippy:: module_name_repetitions) ]
@@ -182,15 +183,15 @@ impl super::Cpuid {
182183 . checked_shl ( u32:: from ( cpu_bits) )
183184 . ok_or ( NormalizeCpuidError :: CpuBits ( cpu_bits) ) ?;
184185 self . update_vendor_id ( ) ?;
185- self . update_feature_info_entry ( cpu_index, cpu_count ) ?;
186- self . update_extended_topology_entry ( cpu_index, cpu_count , cpu_bits, cpus_per_core) ?;
186+ self . update_feature_info_entry ( cpu_index) ?;
187+ self . update_extended_topology_entry ( cpu_index, cpu_bits, cpus_per_core) ?;
187188 self . update_extended_cache_features ( ) ?;
188189
189190 // Apply manufacturer specific modifications.
190191 match self {
191192 // Apply Intel specific modifications.
192193 Self :: Intel ( intel_cpuid) => {
193- intel_cpuid. normalize ( cpu_index , cpu_count , cpus_per_core) ?;
194+ intel_cpuid. normalize ( cpus_per_core) ?;
194195 }
195196 // Apply AMD specific modifications.
196197 Self :: Amd ( amd_cpuid) => amd_cpuid. normalize ( cpu_index, cpu_count, cpus_per_core) ?,
@@ -216,11 +217,7 @@ impl super::Cpuid {
216217 }
217218
218219 // Update feature information entry
219- fn update_feature_info_entry (
220- & mut self ,
221- cpu_index : u8 ,
222- cpu_count : u8 ,
223- ) -> Result < ( ) , FeatureInformationError > {
220+ fn update_feature_info_entry ( & mut self , cpu_index : u8 ) -> Result < ( ) , FeatureInformationError > {
224221 // Flush a cache line size.
225222 const EBX_CLFLUSH_CACHELINE : u32 = 8 ;
226223
@@ -268,7 +265,7 @@ impl super::Cpuid {
268265 . map_err ( FeatureInformationError :: Clflush ) ?;
269266
270267 let max_cpus_per_package = u32:: from (
271- get_max_cpus_per_package ( cpu_count )
268+ get_max_cpus_per_package ( MAX_SUPPORTED_VCPUS )
272269 . map_err ( FeatureInformationError :: GetMaxCpusPerPackage ) ?,
273270 ) ;
274271
@@ -294,7 +291,7 @@ impl super::Cpuid {
294291 // A value of 1 for HTT indicates the value in CPUID.1.EBX[23:16]
295292 // (the Maximum number of addressable IDs for logical processors in this package)
296293 // is valid for the package
297- set_bit ( & mut leaf_1. result . edx , 28 , cpu_count > 1 ) ;
294+ set_bit ( & mut leaf_1. result . edx , 28 , true ) ;
298295
299296 Ok ( ( ) )
300297 }
@@ -303,7 +300,6 @@ impl super::Cpuid {
303300 fn update_extended_topology_entry (
304301 & mut self ,
305302 cpu_index : u8 ,
306- cpu_count : u8 ,
307303 cpu_bits : u8 ,
308304 cpus_per_core : u8 ,
309305 ) -> Result < ( ) , ExtendedTopologyError > {
@@ -408,8 +404,12 @@ impl super::Cpuid {
408404 set_range ( & mut subleaf. result . eax , 0 ..5 , LEAFBH_INDEX1_APICID )
409405 . map_err ( ExtendedTopologyError :: ApicId ) ?;
410406
411- set_range ( & mut subleaf. result . ebx , 0 ..16 , u32:: from ( cpu_count) )
412- . map_err ( ExtendedTopologyError :: LogicalProcessors ) ?;
407+ set_range (
408+ & mut subleaf. result . ebx ,
409+ 0 ..16 ,
410+ u32:: from ( MAX_SUPPORTED_VCPUS ) ,
411+ )
412+ . map_err ( ExtendedTopologyError :: LogicalProcessors ) ?;
413413
414414 // We expect here as this is an extremely rare case that is unlikely to ever
415415 // occur. It would require manual editing of the CPUID structure to push
@@ -577,12 +577,7 @@ mod tests {
577577 } ,
578578 } ,
579579 ) ] ) ) ) ;
580- let result = intel_cpuid. update_extended_topology_entry (
581- cpu_index,
582- cpu_count,
583- cpu_bits,
584- cpus_per_core,
585- ) ;
580+ let result = intel_cpuid. update_extended_topology_entry ( cpu_index, cpu_bits, cpus_per_core) ;
586581 result. unwrap ( ) ;
587582 assert ! ( intel_cpuid. inner( ) . contains_key( & CpuidKey {
588583 leaf: 0xb ,
@@ -605,8 +600,7 @@ mod tests {
605600 } ,
606601 } ,
607602 ) ] ) ) ) ;
608- let result =
609- amd_cpuid. update_extended_topology_entry ( cpu_index, cpu_count, cpu_bits, cpus_per_core) ;
603+ let result = amd_cpuid. update_extended_topology_entry ( cpu_index, cpu_bits, cpus_per_core) ;
610604 result. unwrap ( ) ;
611605 assert ! ( amd_cpuid. inner( ) . contains_key( & CpuidKey {
612606 leaf: 0xb ,
0 commit comments