Skip to content

Commit a8c32ea

Browse files
Serban Iorgaacatangiu
authored andcommitted
AMD: process leaf 0x7 only if index == 0
per AMD EPYC PPR specifications Signed-off-by: Serban Iorga <[email protected]>
1 parent 5452cbc commit a8c32ea

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cpuid/src/transformer/amd.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ pub fn update_structured_extended_entry(
1616
) -> Result<(), Error> {
1717
use cpu_leaf::leaf_0x7::index0::*;
1818

19-
// KVM sets this bit no matter what but this feature is not supported by hardware
20-
entry.edx.write_bit(edx::ARCH_CAPABILITIES_BITINDEX, false);
19+
// according to the EPYC PPR, only the leaf 0x7 with index 0 contains the
20+
// structured extended feature identifiers
21+
if entry.index == 0 {
22+
// KVM sets this bit no matter what but this feature is not supported by hardware
23+
entry.edx.write_bit(edx::ARCH_CAPABILITIES_BITINDEX, false);
24+
}
2125

2226
Ok(())
2327
}
@@ -83,6 +87,7 @@ mod test {
8387
fn test_update_structured_extended_entry() {
8488
use cpu_leaf::leaf_0x7::index0::*;
8589

90+
// Check that if index == 0 the entry is processed
8691
let vm_spec = VmSpec::new(VENDOR_ID_AMD, 0, 1, false);
8792
let mut entry = &mut kvm_cpuid_entry2 {
8893
function: leaf_0x7::LEAF_NUM,
@@ -94,9 +99,13 @@ mod test {
9499
edx: *(0 as u32).write_bit(edx::ARCH_CAPABILITIES_BITINDEX, true),
95100
padding: [0, 0, 0],
96101
};
97-
98102
assert!(update_structured_extended_entry(&mut entry, &vm_spec).is_ok());
99-
100103
assert_eq!(entry.edx.read_bit(edx::ARCH_CAPABILITIES_BITINDEX), false);
104+
105+
// Check that if index != 0 the entry is not processed
106+
entry.index = 1;
107+
entry.edx.write_bit(edx::ARCH_CAPABILITIES_BITINDEX, true);
108+
assert!(update_structured_extended_entry(&mut entry, &vm_spec).is_ok());
109+
assert_eq!(entry.edx.read_bit(edx::ARCH_CAPABILITIES_BITINDEX), true);
101110
}
102111
}

0 commit comments

Comments
 (0)