Skip to content

Commit 8fe4aeb

Browse files
Serban Iorgaacatangiu
authored andcommitted
AMD: enable topology extension support
We need to enable it since we use the Extended Cache Topology leaf. Signed-off-by: Serban Iorga <[email protected]>
1 parent 02b9063 commit 8fe4aeb

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

cpuid/src/cpu_leaf.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,6 @@ pub mod leaf_0x7 {
173173
}
174174
}
175175

176-
pub mod leaf_0x80000001 {
177-
pub const LEAF_NUM: u32 = 0x8000_0001;
178-
179-
pub mod ecx {
180-
pub const PREFETCH_SHIFT: u32 = 8; // 3DNow! PREFETCH/PREFETCHW instructions
181-
pub const LZCNT_SHIFT: u32 = 5; // advanced bit manipulation
182-
}
183-
184-
pub mod edx {
185-
pub const PDPE1GB_SHIFT: u32 = 26; // 1-GByte pages are available if 1.
186-
}
187-
}
188-
189176
pub mod leaf_0xa {
190177
pub const LEAF_NUM: u32 = 0xa;
191178
}
@@ -231,3 +218,17 @@ pub mod leaf_0x80000000 {
231218
pub const LARGEST_EXTENDED_FN_BITRANGE: BitRange = bit_range!(31, 0);
232219
}
233220
}
221+
222+
pub mod leaf_0x80000001 {
223+
pub const LEAF_NUM: u32 = 0x8000_0001;
224+
225+
pub mod ecx {
226+
pub const LZCNT_SHIFT: u32 = 5; // advanced bit manipulation
227+
pub const PREFETCH_SHIFT: u32 = 8; // 3DNow! PREFETCH/PREFETCHW instructions
228+
pub const TOPOEXT_INDEX: u32 = 22;
229+
}
230+
231+
pub mod edx {
232+
pub const PDPE1GB_SHIFT: u32 = 26; // 1-GByte pages are available if 1.
233+
}
234+
}

cpuid/src/transformer/amd.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ pub fn update_largest_extended_fn_entry(
4444
Ok(())
4545
}
4646

47+
pub fn update_extended_feature_info_entry(
48+
entry: &mut kvm_cpuid_entry2,
49+
_vm_spec: &VmSpec,
50+
) -> Result<(), Error> {
51+
use cpu_leaf::leaf_0x80000001::*;
52+
53+
// set the Topology Extension bit since we use the Extended Cache Topology leaf
54+
entry.ecx.write_bit(ecx::TOPOEXT_INDEX, true);
55+
56+
Ok(())
57+
}
58+
4759
pub fn update_extended_cache_topology_entry(
4860
entry: &mut kvm_cpuid_entry2,
4961
vm_spec: &VmSpec,
@@ -65,6 +77,7 @@ impl CpuidTransformer for AmdCpuidTransformer {
6577
leaf_0x1::LEAF_NUM => Some(common::update_feature_info_entry),
6678
leaf_0x7::LEAF_NUM => Some(amd::update_structured_extended_entry),
6779
leaf_0x80000000::LEAF_NUM => Some(amd::update_largest_extended_fn_entry),
80+
leaf_0x80000001::LEAF_NUM => Some(amd::update_extended_feature_info_entry),
6881
leaf_0x8000001d::LEAF_NUM => Some(amd::update_extended_cache_topology_entry),
6982
0x8000_0002..=0x8000_0004 => Some(common::update_brand_string_entry),
7083
_ => None,
@@ -135,6 +148,27 @@ mod test {
135148
);
136149
}
137150

151+
#[test]
152+
fn test_update_extended_feature_info_entry() {
153+
use cpu_leaf::leaf_0x80000001::*;
154+
155+
let vm_spec = VmSpec::new(VENDOR_ID_AMD, 0, 1, false);
156+
let mut entry = &mut kvm_cpuid_entry2 {
157+
function: LEAF_NUM,
158+
index: 0,
159+
flags: 0,
160+
eax: 0,
161+
ebx: 0,
162+
ecx: 0,
163+
edx: 0,
164+
padding: [0, 0, 0],
165+
};
166+
167+
assert!(update_extended_feature_info_entry(&mut entry, &vm_spec).is_ok());
168+
169+
assert_eq!(entry.ecx.read_bit(ecx::TOPOEXT_INDEX), true);
170+
}
171+
138172
#[test]
139173
fn test_update_extended_cache_topology_entry() {
140174
let vm_spec = VmSpec::new(VENDOR_ID_AMD, 0, 1, false);

0 commit comments

Comments
 (0)