Skip to content

Commit 80ebedb

Browse files
committed
feat: AMD support larger extended function entries
Updated the logic for setting the largest extended function entry, to take the largest between host CPU value and 0x8000_0021. The minimum has also been bumped to 0x8000_0021 to allow setting values regarding SRSO. Signed-off-by: Jack Thomson <[email protected]>
1 parent a7fb815 commit 80ebedb

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

docs/cpu_templates/cpuid-normalization.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ 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+
| Update largest extended function entry to largest between host cpu entry and 0x80000021 | 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 |

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,23 @@ impl super::AmdCpuid {
184184
/// Update largest extended fn entry.
185185
#[allow(clippy::unwrap_used, clippy::unwrap_in_result)]
186186
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).
187+
// KVM sets the largest extended function to 0x80000000. Change it to the largest
188+
// between host CPU and 0x8000_0021. AMD notes that hypervisors should synthesize the value
189+
// of both IBPB_BRTYPE and SBPB stored in leaf 0x8000_0021.
190+
//
191+
// https://www.amd.com/content/dam/amd/en/documents/corporate/cr/speculative-return-stack-overflow-whitepaper.pdf
189192
let leaf_80000000 = self
190193
.get_mut(&CpuidKey::leaf(0x80000000))
191194
.ok_or(NormalizeCpuidError::MissingLeaf0x80000000)?;
192195

196+
// Take the largest between host cpu entry and 0x8000_0021
197+
let extended_fn_entry = 0x8000_0021.max(get_range(cpuid(0x80000000).eax, 0..32));
198+
193199
// Largest extended function. The largest CPUID extended function input value supported by
194200
// the processor implementation.
195201
//
196202
// l_func_ext: 0..32,
197-
set_range(&mut leaf_80000000.result.eax, 0..32, 0x8000_001f).unwrap();
203+
set_range(&mut leaf_80000000.result.eax, 0..32, extended_fn_entry).unwrap();
198204
Ok(())
199205
}
200206

0 commit comments

Comments
 (0)