Skip to content

Commit 4c449a3

Browse files
Jonathan Woollett-Lightkalyazin
authored andcommitted
fix: Cache level
Corrects the `cache_level` variables under `update_deterministic_cache_entry` and `update_extended_cache_topology_entry` to get the cache level, where previously they where mistakenly getting the cache type. Signed-off-by: Jonathan Woollett-Light <[email protected]>
1 parent 6225d7d commit 4c449a3

11 files changed

+32
-26
lines changed

resources/tests/cpu_template_helper/cpu_config_AMD_MILAN_4.14host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@
11571157
"modifiers": [
11581158
{
11591159
"register": "eax",
1160-
"bitmap": "0b00000000000000000100000101000011"
1160+
"bitmap": "0b00000000000000000000000101000011"
11611161
},
11621162
{
11631163
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_AMD_MILAN_5.10host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@
12491249
"modifiers": [
12501250
{
12511251
"register": "eax",
1252-
"bitmap": "0b00000000000000000100000101000011"
1252+
"bitmap": "0b00000000000000000000000101000011"
12531253
},
12541254
{
12551255
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_INTEL_CASCADELAKE_4.14host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"modifiers": [
146146
{
147147
"register": "eax",
148-
"bitmap": "0b00000100000000000100000101000011"
148+
"bitmap": "0b00000100000000000000000101000011"
149149
},
150150
{
151151
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_INTEL_CASCADELAKE_5.10host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"modifiers": [
146146
{
147147
"register": "eax",
148-
"bitmap": "0b00000100000000000100000101000011"
148+
"bitmap": "0b00000100000000000000000101000011"
149149
},
150150
{
151151
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_INTEL_ICELAKE_4.14host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"modifiers": [
146146
{
147147
"register": "eax",
148-
"bitmap": "0b00000100000000000100000101000011"
148+
"bitmap": "0b00000100000000000000000101000011"
149149
},
150150
{
151151
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_INTEL_ICELAKE_5.10host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"modifiers": [
146146
{
147147
"register": "eax",
148-
"bitmap": "0b00000100000000000100000101000011"
148+
"bitmap": "0b00000100000000000000000101000011"
149149
},
150150
{
151151
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_INTEL_SKYLAKE_4.14host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"modifiers": [
146146
{
147147
"register": "eax",
148-
"bitmap": "0b00000100000000000100000101000011"
148+
"bitmap": "0b00000100000000000000000101000011"
149149
},
150150
{
151151
"register": "ebx",

resources/tests/cpu_template_helper/cpu_config_INTEL_SKYLAKE_5.10host.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"modifiers": [
146146
{
147147
"register": "eax",
148-
"bitmap": "0b00000100000000000100000101000011"
148+
"bitmap": "0b00000100000000000000000101000011"
149149
},
150150
{
151151
"register": "ebx",

src/vmm/src/guest_config/x86_64/cpuid/amd/normalize.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use crate::guest_config::x86_64::cpuid::common::{get_vendor_id_from_host, GetCpuidError};
5-
use crate::guest_config::x86_64::cpuid::normalize::{set_bit, set_range, CheckedAssignError};
5+
use crate::guest_config::x86_64::cpuid::normalize::{
6+
get_range, set_bit, set_range, CheckedAssignError,
7+
};
68
use crate::guest_config::x86_64::cpuid::{
79
cpuid, cpuid_count, CpuidEntry, CpuidKey, CpuidRegisters, CpuidTrait, KvmCpuidFlags,
810
MissingBrandStringLeaves, BRAND_STRING_LENGTH, VENDOR_ID_AMD,
@@ -292,18 +294,19 @@ impl super::AmdCpuid {
292294
) -> Result<(), ExtendedCacheTopologyError> {
293295
for i in 0.. {
294296
if let Some(subleaf) = self.get_mut(&CpuidKey::subleaf(0x8000001d, i)) {
295-
// Cache type. Identifies the type of cache.
297+
// Cache level. Identifies the level of this cache. Note that the enumeration value
298+
// is not necessarily equal to the cache level.
296299
// ```text
297300
// Bits Description
298-
// 00h Null; no more caches.
299-
// 01h Data cache
300-
// 02h Instruction cache
301-
// 03h Unified cache
302-
// 1Fh-04h Reserved.
301+
// 000b Reserved.
302+
// 001b Level 1
303+
// 010b Level 2
304+
// 011b Level 3
305+
// 111b-100b Reserved.
303306
// ```
304307
//
305-
// cache_type: 0..4,
306-
let cache_level = 15 & subleaf.result.eax; // 15 == (2^4)-1
308+
// cache_level: 5..8
309+
let cache_level = get_range(subleaf.result.eax, 5..8);
307310

308311
// Specifies the number of logical processors sharing the cache enumerated by N,
309312
// the value passed to the instruction in ECX. The number of logical processors

src/vmm/src/guest_config/x86_64/cpuid/intel/normalize.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::guest_config::x86_64::cpuid::normalize::{set_bit, set_range, CheckedAssignError};
4+
use crate::guest_config::x86_64::cpuid::normalize::{
5+
get_range, set_bit, set_range, CheckedAssignError,
6+
};
57
use crate::guest_config::x86_64::cpuid::{
68
host_brand_string, CpuidKey, CpuidRegisters, CpuidTrait, MissingBrandStringLeaves,
79
BRAND_STRING_LENGTH,
@@ -108,15 +110,10 @@ impl super::IntelCpuid {
108110
break;
109111
}
110112

111-
// Cache Type Field.
112-
// - 0 = Null - No more caches.
113-
// - 1 = Data Cache.
114-
// - 2 = Instruction Cache.
115-
// - 3 = Unified Cache.
116-
// - 4-31 = Reserved.
113+
// Cache Level (Starts at 1)
117114
//
118-
// cache_type_field: 0..5,
119-
let cache_level = subleaf.result.eax & 15;
115+
// cache_level: 5..8
116+
let cache_level = get_range(subleaf.result.eax, 5..8);
120117

121118
// Maximum number of addressable IDs for logical processors sharing this cache.
122119
// - Add one to the return value to get the result.

0 commit comments

Comments
 (0)