4
4
use crate :: cpu_config:: x86_64:: cpuid:: {
5
5
cpuid, CpuidEntry , CpuidKey , CpuidRegisters , CpuidTrait , KvmCpuidFlags ,
6
6
} ;
7
+ use crate :: vmm_config:: machine_config:: MAX_SUPPORTED_VCPUS ;
7
8
8
9
/// Error type for [`super::Cpuid::normalize`].
9
10
#[ allow( clippy:: module_name_repetitions) ]
@@ -182,15 +183,15 @@ impl super::Cpuid {
182
183
. checked_shl ( u32:: from ( cpu_bits) )
183
184
. ok_or ( NormalizeCpuidError :: CpuBits ( cpu_bits) ) ?;
184
185
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) ?;
187
188
self . update_extended_cache_features ( ) ?;
188
189
189
190
// Apply manufacturer specific modifications.
190
191
match self {
191
192
// Apply Intel specific modifications.
192
193
Self :: Intel ( intel_cpuid) => {
193
- intel_cpuid. normalize ( cpu_index , cpu_count , cpus_per_core) ?;
194
+ intel_cpuid. normalize ( cpus_per_core) ?;
194
195
}
195
196
// Apply AMD specific modifications.
196
197
Self :: Amd ( amd_cpuid) => amd_cpuid. normalize ( cpu_index, cpu_count, cpus_per_core) ?,
@@ -216,11 +217,7 @@ impl super::Cpuid {
216
217
}
217
218
218
219
// 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 > {
224
221
// Flush a cache line size.
225
222
const EBX_CLFLUSH_CACHELINE : u32 = 8 ;
226
223
@@ -268,7 +265,7 @@ impl super::Cpuid {
268
265
. map_err ( FeatureInformationError :: Clflush ) ?;
269
266
270
267
let max_cpus_per_package = u32:: from (
271
- get_max_cpus_per_package ( cpu_count )
268
+ get_max_cpus_per_package ( MAX_SUPPORTED_VCPUS )
272
269
. map_err ( FeatureInformationError :: GetMaxCpusPerPackage ) ?,
273
270
) ;
274
271
@@ -294,7 +291,7 @@ impl super::Cpuid {
294
291
// A value of 1 for HTT indicates the value in CPUID.1.EBX[23:16]
295
292
// (the Maximum number of addressable IDs for logical processors in this package)
296
293
// 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 ) ;
298
295
299
296
Ok ( ( ) )
300
297
}
@@ -303,7 +300,6 @@ impl super::Cpuid {
303
300
fn update_extended_topology_entry (
304
301
& mut self ,
305
302
cpu_index : u8 ,
306
- cpu_count : u8 ,
307
303
cpu_bits : u8 ,
308
304
cpus_per_core : u8 ,
309
305
) -> Result < ( ) , ExtendedTopologyError > {
@@ -408,8 +404,12 @@ impl super::Cpuid {
408
404
set_range ( & mut subleaf. result . eax , 0 ..5 , LEAFBH_INDEX1_APICID )
409
405
. map_err ( ExtendedTopologyError :: ApicId ) ?;
410
406
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 ) ?;
413
413
414
414
// We expect here as this is an extremely rare case that is unlikely to ever
415
415
// occur. It would require manual editing of the CPUID structure to push
@@ -577,12 +577,7 @@ mod tests {
577
577
} ,
578
578
} ,
579
579
) ] ) ) ) ;
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) ;
586
581
result. unwrap ( ) ;
587
582
assert ! ( intel_cpuid. inner( ) . contains_key( & CpuidKey {
588
583
leaf: 0xb ,
@@ -605,8 +600,7 @@ mod tests {
605
600
} ,
606
601
} ,
607
602
) ] ) ) ) ;
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) ;
610
604
result. unwrap ( ) ;
611
605
assert ! ( amd_cpuid. inner( ) . contains_key( & CpuidKey {
612
606
leaf: 0xb ,
0 commit comments