remove 0xB leaf on AMD
@@ -130,6 +130,9 @@ pub struct AmdCpuidTransformer {}
impl CpuidTransformer for AmdCpuidTransformer {
fn process_cpuid(&self, cpuid: &mut CpuId, vm_spec: &VmSpec) -> Result<(), Error> {
+ // Some versions of kernel may return the 0xB leaf for AMD even if this is an
+ // Intel-specific leaf. Remove it.
+ cpuid.retain(|entry| entry.function != leaf_0xb::LEAF_NUM);
use_host_cpuid_function(cpuid, leaf_0x8000001e::LEAF_NUM, false)?;
use_host_cpuid_function(cpuid, leaf_0x8000001d::LEAF_NUM, true)?;
self.process_entries(cpuid, vm_spec)
@@ -154,6 +157,28 @@ impl CpuidTransformer for AmdCpuidTransformer {
mod tests {
use super::*;
+ #[test]
+ fn test_process_cpuid() {
+ let vm_spec = VmSpec::new(0, 1, false).expect("Error creating vm_spec");
+ let mut cpuid = CpuId::new(0);
+ let entry = kvm_cpuid_entry2 {
+ function: leaf_0xb::LEAF_NUM,
+ index: 0,
+ flags: 0,
+ eax: 0,
+ ebx: 0,
+ ecx: 0,
+ edx: 0,
+ padding: [0, 0, 0],
+ };
+ cpuid.push(entry).unwrap();
+
+ assert!(AmdCpuidTransformer {}
+ .process_cpuid(&mut cpuid, &vm_spec)
+ .is_ok());
+ assert!(!cpuid.as_slice().contains(&entry));
+ }
+
#[test]
fn test_update_structured_extended_entry() {
use crate::cpu_leaf::leaf_0x7::index0::*;
