Skip to content

Commit 15699a3

Browse files
committed
feat: AMD support larger extended function entries
Removed the extended function entry normalisation step from AMD CPUs. We will now pass through the value provided by KVM or set through a CPU template. This now mirrors the behaviour of Intel. On newer AMD chips and newer kernels we are now able to pass through features which were previously out of range. Signed-off-by: Jack Thomson <[email protected]>
1 parent 538702b commit 15699a3

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

docs/cpu_templates/cpuid-normalization.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ See also: [boot protocol settings](boot-protocol.md)
4242

4343
## AMD-specifc CPUID normalization
4444

45-
| Description | Leaf | Subleaf | Register | Bits |
46-
| ---------------------------------------------------- | :--------------------------------: | :-----: | :----------------: | :---: |
47-
| Set IA32_ARCH_CAPABILITIES MSR as not present | 0x7 | - | EDX | 29 |
48-
| Update largest extended function entry to 0x8000001f | 0x80000000 | - | EAX | 31:0 |
49-
| Set topology extension bit | 0x80000001 | - | ECX | 22 |
50-
| Update brand string with a default AMD value | 0x80000002, 0x80000003, 0x80000004 | - | EAX, EBX, ECX, EDX | all |
51-
| Update number of physical threads | 0x80000008 | - | ECX | 7:0 |
52-
| Update APIC ID size | 0x80000008 | - | ECX | 15:12 |
53-
| Update cache topology information | 0x8000001d | all | all | all |
54-
| Update extended APIC ID | 0x8000001e | - | EAX, EBX, ECX | all |
45+
| Description | Leaf | Subleaf | Register | Bits |
46+
| --------------------------------------------- | :--------------------------------: | :-----: | :----------------: | :---: |
47+
| Set IA32_ARCH_CAPABILITIES MSR as not present | 0x7 | - | EDX | 29 |
48+
| Set topology extension bit | 0x80000001 | - | ECX | 22 |
49+
| Update brand string with a default AMD value | 0x80000002, 0x80000003, 0x80000004 | - | EAX, EBX, ECX, EDX | all |
50+
| Update number of physical threads | 0x80000008 | - | ECX | 7:0 |
51+
| Update APIC ID size | 0x80000008 | - | ECX | 15:12 |
52+
| Update cache topology information | 0x8000001d | all | all | all |
53+
| Update extended APIC ID | 0x8000001e | - | EAX, EBX, ECX | all |

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ impl super::AmdCpuid {
104104
) -> Result<(), NormalizeCpuidError> {
105105
self.passthrough_cache_topology()?;
106106
self.update_structured_extended_entry()?;
107-
self.update_largest_extended_fn_entry()?;
108107
self.update_extended_feature_fn_entry()?;
109108
self.update_amd_feature_entry(cpu_count)?;
110109
self.update_extended_cache_topology_entry(cpu_count, cpus_per_core)?;
@@ -181,23 +180,6 @@ impl super::AmdCpuid {
181180
Ok(())
182181
}
183182

184-
/// Update largest extended fn entry.
185-
#[allow(clippy::unwrap_used, clippy::unwrap_in_result)]
186-
fn update_largest_extended_fn_entry(&mut self) -> Result<(), NormalizeCpuidError> {
187-
// KVM sets the largest extended function to 0x80000000. Change it to 0x8000001f
188-
// Since we also use the leaf 0x8000001d (Extended Cache Topology).
189-
let leaf_80000000 = self
190-
.get_mut(&CpuidKey::leaf(0x80000000))
191-
.ok_or(NormalizeCpuidError::MissingLeaf0x80000000)?;
192-
193-
// Largest extended function. The largest CPUID extended function input value supported by
194-
// the processor implementation.
195-
//
196-
// l_func_ext: 0..32,
197-
set_range(&mut leaf_80000000.result.eax, 0..32, 0x8000_001f).unwrap();
198-
Ok(())
199-
}
200-
201183
/// Updated extended feature fn entry.
202184
fn update_extended_feature_fn_entry(&mut self) -> Result<(), NormalizeCpuidError> {
203185
// set the Topology Extension bit since we use the Extended Cache Topology leaf

tests/data/cpu_template_helper/fingerprint_AMD_MILAN_6.1host.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@
543543
"modifiers": [
544544
{
545545
"register": "eax",
546-
"bitmap": "0b10000000000000000000000000011111"
546+
"bitmap": "0b10000000000000000000000000100001"
547547
},
548548
{
549549
"register": "ebx",
@@ -1546,4 +1546,4 @@
15461546
}
15471547
]
15481548
}
1549-
}
1549+
}

tests/integration_tests/functional/test_cpu_template_helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ def build_cpu_config_dict(cpu_config_path):
146146
# https://github.com/torvalds/linux/commit/8765d75329a386dd7742f94a1ea5fdcdea8d93d0
147147
(0x8000001B, 0x0),
148148
(0x8000001C, 0x0),
149-
(0x8000001F, 0x0),
150149
# CPUID.80860000h is a Transmeta-specific leaf.
151150
(0x80860000, 0x0),
152151
# CPUID.C0000000h is a Centaur-specific leaf.
153152
(0xC0000000, 0x0),
154153
]
155154

155+
# An upper range of CPUID leaves which are not supported by our kernels
156+
UNAVAILABLE_CPUID_UPPER_RANGE = range(0x8000001F, 0x80000029)
156157

157158
# Dictionary of CPUID bitmasks that should not be tested due to its mutability.
158159
CPUID_EXCEPTION_LIST = {
@@ -281,6 +282,8 @@ def test_cpu_config_dump_vs_actual(
281282
for key, actual in actual_cpu_config["cpuid"].items():
282283
if (key[0], key[1]) in UNAVAILABLE_CPUID_ON_DUMP_LIST:
283284
continue
285+
if key[0] in UNAVAILABLE_CPUID_UPPER_RANGE:
286+
continue
284287
if key not in dump_cpu_config["cpuid"]:
285288
keys_not_in_dump[key] = actual_cpu_config["cpuid"][key]
286289
continue

0 commit comments

Comments
 (0)