Skip to content

openvmm: on an AMD KVM host, a VP of a GenuineIntel-CPUID guest fails to bind #1388

Open

Description

@tangruize

On KVM on an AMD (SVM) host with kvm.ignore_msrs off (the default), binding a vCPU of a partition whose guest CPUID vendor is GenuineIntel fails with IncompleteMsrs { failed_msr: 58 } (IA32_FEATURE_CONTROL), although KVM itself can run such a guest. OpenVMM's own VMs do not reach this at the pin: without a time ABI the guest's vendor is the host's, and with one the generation check refuses an Intel CPU profile on an AMD host (E_CPU_GENERATION) before the partition is built. It affects a caller of the KVM backend that sets a GenuineIntel leaf 0 itself, through PartitionConfig::cpuid. Intel hosts are not affected, and neither are guests whose vendor is not GenuineIntel.

Reproduction

On an AMD host, build a KVM partition whose CPUID leaf 0 names GenuineIntel and call bind() on a VP. Expected: the bind succeeds. Actual: it fails with IncompleteMsrs { failed_msr: 58 }, in debug and release builds. This was seen on an EPYC 9V74 host (kvm_amd, Linux 6.8, ignore_msrs=N).

Cause

KvmProcessorBinder::bind (vmm_core/virt_kvm/src/arch/x86_64/mod.rs) writes a locked IA32_FEATURE_CONTROL when the guest's vendor, not the host's, is Intel:

// vmm_core/virt_kvm/src/arch/x86_64/mod.rs
if self.partition.caps.vendor.is_intel_compatible() {
    // ...
    kvm.set_msrs(&[(
        x86defs::X86X_IA32_MSR_FEATURE_CONTROL,
        u64::from(
            x86defs::vmx::Ia32FeatureControl::new()
                .with_locked(true)
                .with_vmx_enabled_outside_smx(ecx.vmx()),
        ),
    )])?;
}

Only KVM's VMX module handles this MSR (vmx_set_msr). svm_set_msr and kvm_set_msr_common do not, so a nonzero host write fails unless ignore_msrs is set (Linux v6.8 and v6.17).

Fix

fix.patch adds host_vmx to the proto partition and to KvmPartitionInner, derived from the host vendor that new_partition already reads from KVM_GET_SUPPORTED_CPUID (host_runs_vmx: VMX unless AMD or Hygon). bind then writes IA32_FEATURE_CONTROL only when the host runs VMX and the guest vendor is GenuineIntel. Nothing changes on a VMX host. The native test only_a_vmx_host_has_feature_control covers the vendor mapping; the patch has no KVM-backed test.

Activity

  1. tangruize commented on Nov 8, 2026

    @tangruize
    ContributorAuthor

    Proposed patch

    Patch against OpenVMM 3cf58a5234ed824435825c9f87187f5129219724. Save the contents below as fix.patch and run git apply fix.patch.

    fix.patch
    diff --git a/vmm_core/virt_kvm/src/arch/x86_64/mod.rs b/vmm_core/virt_kvm/src/arch/x86_64/mod.rs
    index 90fd24d..50192a3 100644
    --- a/vmm_core/virt_kvm/src/arch/x86_64/mod.rs
    +++ b/vmm_core/virt_kvm/src/arch/x86_64/mod.rs
    @@ -229,6 +229,7 @@ fn new_partition<'a>(
             if !vendor.is_intel_compatible() && !vendor.is_amd_compatible() {
                 return Err(KvmError::UnsupportedCpuVendor);
             }
    +        let host_vmx = host_runs_vmx(vendor);
     
             let mut cpuid_entries = supported_cpuid
                 .into_iter()
    @@ -499,6 +500,7 @@ fn new_partition<'a>(
                 nested_virt,
                 supported_mce_cap,
                 cpu_surface,
    +            host_vmx,
             })
         }
     }
    @@ -516,6 +518,8 @@ pub struct KvmProtoPartition<'a> {
         supported_mce_cap: u64,
         /// The CPU surface KVM supports, for the time ABI's CPU profile.
         cpu_surface: Option<virt::time_abi::surface::SupportedCpuSurface>,
    +    /// Whether KVM runs vCPUs with VMX, else with SVM ([`host_runs_vmx`]).
    +    host_vmx: bool,
     }
     
     impl ProtoPartition for KvmProtoPartition<'_> {
    @@ -710,6 +714,7 @@ fn build(
                 cpuid,
                 reserved_vps_per_socket: self.config.processor_topology.reserved_vps_per_socket(),
                 mce_cmci_supported: x86defs::McgCap::from(self.supported_mce_cap).cmci_p(),
    +            host_vmx: self.host_vmx,
                 synic_ports: Default::default(),
                 time_abi,
             });
    @@ -1036,8 +1041,9 @@ fn bind(&mut self) -> Result<Self::Processor<'_>, Self::Error> {
             // Set IA32_FEATURE_CONTROL on Intel processors. KVM initializes
             // this MSR to 0; set the lock bit (as Hyper-V does) so that the
             // MSR reads as locked, and enable VMX outside SMX if the guest
    -        // has VMX in CPUID.
    -        if self.partition.caps.vendor.is_intel_compatible() {
    +        // has VMX in CPUID. Only KVM's VMX module has this MSR: on an AMD
    +        // (SVM) host KVM refuses it whatever the guest's vendor.
    +        if self.partition.host_vmx && self.partition.caps.vendor.is_intel_compatible() {
                 let ecx = x86defs::cpuid::VersionAndFeaturesEcx::from(
                     self.partition
                         .cpuid
    @@ -2203,6 +2209,13 @@ fn signal_msi(&self, _devid: Option<u32>, address: u64, data: u32) {
         }
     }
     
    +/// Whether KVM runs its vCPUs with VMX (kvm_intel), else with SVM (kvm_amd),
    +/// from the host's CPU vendor (KVM_GET_SUPPORTED_CPUID's leaf 0): kvm_amd
    +/// loads only on an AMD or Hygon CPU.
    +fn host_runs_vmx(host_vendor: x86defs::cpuid::Vendor) -> bool {
    +    !host_vendor.is_amd_compatible()
    +}
    +
     #[cfg(test)]
     mod tests {
         use super::kvm_recommends_hyperv_apic_msrs;
    @@ -2211,6 +2224,14 @@ mod tests {
         use hvdef::HvEnlightenmentInformation;
         use test_with_tracing::test;
     
    +    #[test]
    +    fn only_a_vmx_host_has_feature_control() {
    +        use x86defs::cpuid::Vendor;
    +        assert!(super::host_runs_vmx(Vendor::INTEL));
    +        assert!(!super::host_runs_vmx(Vendor::AMD));
    +        assert!(!super::host_runs_vmx(Vendor::HYGON));
    +    }
    +
         #[test]
         fn only_recommends_apic_msrs_when_kvm_does() {
             let recommendation =
    diff --git a/vmm_core/virt_kvm/src/lib.rs b/vmm_core/virt_kvm/src/lib.rs
    index 5ad901a..eb2ed4c 100644
    --- a/vmm_core/virt_kvm/src/lib.rs
    +++ b/vmm_core/virt_kvm/src/lib.rs
    @@ -150,6 +150,11 @@ struct KvmPartitionInner {
         #[cfg(guest_arch = "x86_64")]
         mce_cmci_supported: bool,
     
    +    /// Whether KVM runs vCPUs with VMX (kvm_intel), else with SVM (kvm_amd):
    +    /// IA32_FEATURE_CONTROL exists only on VMX, so bind writes it only there.
    +    #[cfg(guest_arch = "x86_64")]
    +    host_vmx: bool,
    +
         /// The GIC device fd, kept alive for the VM lifetime.
         #[cfg(guest_arch = "aarch64")]
         #[inspect(skip)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: guestInitial title-keyword triage suggestionarea: openvmmInitial title-keyword triage suggestionplatform: kvmInitial title-keyword triage suggestion

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions