Skip to content

openvmm: a Hyper-V-enlightened KVM partition with over 2024 VPs panics #1377

Open

Description

@tangruize

On KVM, building a partition with Hyper-V enlightenments (hv_config set, from with_hv) and more than 2024 VPs panics the VM worker with an index out of bounds, in debug and release builds, after the vCPUs have already been created, where it should return a configuration error. Only the VM's configuration reaches it, before the guest runs, and only on a host whose KVM allows that many vCPUs. The limit applies to actual VPs, not to reserved socket capacity. Partitions without enlightenments, which includes NVX's microVM, are not affected, because they allocate no per-VP SynIC routes.

Reproduction

Build a ProtoPartitionConfig with hv_config: Some(..) and a topology with 2025 VPs on a KVM host that allows that many vCPUs. Expected: a configuration error. Actual: VP 2024 claims GSI 24 + 2024 = 2048 in GsiRouting::claim, which panics with "index out of bounds: the len is 2048 but the index is 2048".

Cause

KvmProtoPartition::build (vmm_core/virt_kvm/src/arch/x86_64/mod.rs) claims a SynIC route for each VP, and GsiRouting::claim (vmm_core/virt_kvm/src/gsi.rs) indexes its table with it directly. The VP count is never checked against that table:

// vmm_core/virt_kvm/src/arch/x86_64/mod.rs
if self.config.hv_config.is_some() {
    // ...
    for vp in self.config.processor_topology.vps() {
        let index = vp.vp_index.index();
        let gsi = VMBUS_BASE_GSI + index;
        gsi_routing.claim(gsi);
// vmm_core/virt_kvm/src/gsi.rs
const NUM_GSIS: usize = 2048;
// ...
    pub fn claim(&mut self, gsi: u32) {
        let gsi = gsi as usize;
        assert_eq!(self.states[gsi], GsiState::Unallocated);

Fix

fix.patch checks the VP count of an enlightened partition before CPUID processing and vCPU creation. If it exceeds NUM_GSIS - VMBUS_BASE_GSI (2024), the build returns the new KvmError::TooManyVps { vp_count, max }. Partitions without enlightenments behave as before. The native test synic_vp_count_respects_gsi_capacity checks 2024 (accepted) and 2025 (refused), and the KVM test build_rejects_hyperv_vp_count_beyond_synic_capacity, which needs /dev/kvm and is #[ignore]d, builds 2025 VPs. The patch makes NUM_GSIS pub(crate), and adds pal_async as a dev-dependency of virt_kvm, with the matching Cargo.lock line.

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/Cargo.lock b/Cargo.lock
    index 962a90d..c7c7ca2 100644
    --- a/Cargo.lock
    +++ b/Cargo.lock
    @@ -10496,6 +10496,7 @@ dependencies = [
      "libc",
      "memory_range",
      "open_enum",
    + "pal_async",
      "pal_event",
      "parking_lot",
      "pci_core",
    diff --git a/vmm_core/virt_kvm/Cargo.toml b/vmm_core/virt_kvm/Cargo.toml
    index 23e5aaf..7ea5410 100644
    --- a/vmm_core/virt_kvm/Cargo.toml
    +++ b/vmm_core/virt_kvm/Cargo.toml
    @@ -35,6 +35,7 @@ tracelimit.workspace = true
     zerocopy.workspace = true
     
     [dev-dependencies]
    +pal_async.workspace = true
     test_with_tracing.workspace = true
     
     [target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dependencies]
    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..a7588bb 100644
    --- a/vmm_core/virt_kvm/src/arch/x86_64/mod.rs
    +++ b/vmm_core/virt_kvm/src/arch/x86_64/mod.rs
    @@ -545,6 +545,11 @@ fn build(
                 return Err(SnpError::InvalidVmsaGpa(config.bsp.gpa).into());
             }
     
    +        validate_synic_vp_count(
    +            self.config.processor_topology.vp_count(),
    +            self.config.hv_config.is_some(),
    +        )?;
    +
             let cpuid = match &self.config.time_abi {
                 Some(time_abi) => time_abi::partition_cpuid(&time_abi.cpuid),
                 None => {
    @@ -841,6 +846,19 @@ fn strip_psfd_leaf(cpuid: &CpuidLeafSet) -> Option<CpuidLeaf> {
     
     const VMBUS_BASE_GSI: u32 = virt::irqcon::IRQ_LINES as u32;
     
    +/// Each enlightened VP consumes one entry after the platform IRQ lines.
    +const MAX_SYNIC_VPS: u32 = crate::gsi::NUM_GSIS as u32 - VMBUS_BASE_GSI;
    +
    +fn validate_synic_vp_count(vp_count: u32, enlightened: bool) -> Result<(), KvmError> {
    +    if enlightened && vp_count > MAX_SYNIC_VPS {
    +        return Err(KvmError::TooManyVps {
    +            vp_count,
    +            max: MAX_SYNIC_VPS,
    +        });
    +    }
    +    Ok(())
    +}
    +
     #[derive(Debug, Inspect)]
     pub struct KvmVpInner {
         #[inspect(skip)]
    @@ -2211,6 +2229,72 @@ mod tests {
         use hvdef::HvEnlightenmentInformation;
         use test_with_tracing::test;
     
    +    #[test]
    +    fn synic_vp_count_respects_gsi_capacity() {
    +        use super::validate_synic_vp_count;
    +        use crate::KvmError;
    +
    +        assert!(validate_synic_vp_count(2024, true).is_ok());
    +        assert!(matches!(
    +            validate_synic_vp_count(2025, true),
    +            Err(KvmError::TooManyVps {
    +                vp_count: 2025,
    +                max: 2024,
    +            })
    +        ));
    +        assert!(validate_synic_vp_count(2025, false).is_ok());
    +        assert!(validate_synic_vp_count(4096, false).is_ok());
    +    }
    +
    +    #[test]
    +    #[ignore = "requires access to /dev/kvm"]
    +    fn build_rejects_hyperv_vp_count_beyond_synic_capacity() {
    +        use crate::{Kvm, KvmError};
    +        use guestmem::GuestMemory;
    +        use virt::{Hypervisor, PartitionConfig, ProtoPartition, ProtoPartitionConfig};
    +        use vm_topology::memory::MemoryLayout;
    +        use vm_topology::processor::TopologyBuilder;
    +        use vmcore::vmtime::{VmTime, VmTimeKeeper};
    +
    +        pal_async::DefaultPool::run_with(async |driver| {
    +            let keeper = VmTimeKeeper::new(&driver, VmTime::from_100ns(0));
    +            let vmtime = keeper.builder().build(&driver).await.unwrap();
    +            let mem_layout = MemoryLayout::new(0x400000, &[], &[], &[], None).unwrap();
    +            let guest_memory = GuestMemory::allocate(mem_layout.end_of_ram() as usize);
    +            let topology = TopologyBuilder::new_x86().build(2025).unwrap();
    +            let result = Kvm::new()
    +                .unwrap()
    +                .new_partition(ProtoPartitionConfig {
    +                    processor_topology: &topology,
    +                    hv_config: Some(virt::HvConfig {
    +                        allow_device_assignment: false,
    +                        vtl2: None,
    +                    }),
    +                    vmtime: &vmtime,
    +                    isolation: virt::ProtoPartitionIsolation::None,
    +                    nested_virt: false,
    +                    user_mode_memory_faults: false,
    +                    lazy_memory_registration: false,
    +                    time_abi: None,
    +                })
    +                .unwrap()
    +                .build(PartitionConfig {
    +                    mem_layout: &mem_layout,
    +                    guest_memory: &guest_memory,
    +                    cpuid: &[],
    +                    vtl0_alias_map: None,
    +                    fault_resolver: None,
    +                });
    +            assert!(matches!(
    +                result,
    +                Err(KvmError::TooManyVps {
    +                    vp_count: 2025,
    +                    max: 2024,
    +                })
    +            ));
    +        });
    +    }
    +
         #[test]
         fn only_recommends_apic_msrs_when_kvm_does() {
             let recommendation =
    diff --git a/vmm_core/virt_kvm/src/gsi.rs b/vmm_core/virt_kvm/src/gsi.rs
    index 97eb797..da19674 100644
    --- a/vmm_core/virt_kvm/src/gsi.rs
    +++ b/vmm_core/virt_kvm/src/gsi.rs
    @@ -14,7 +14,7 @@
     use std::sync::atomic::Ordering;
     use virt::irqfd::IrqFdRoute;
     
    -const NUM_GSIS: usize = 2048;
    +pub(crate) const NUM_GSIS: usize = 2048;
     
     /// The GSI routing table configured for a VM.
     #[derive(Debug)]
    diff --git a/vmm_core/virt_kvm/src/lib.rs b/vmm_core/virt_kvm/src/lib.rs
    index 5ad901a..456ba94 100644
    --- a/vmm_core/virt_kvm/src/lib.rs
    +++ b/vmm_core/virt_kvm/src/lib.rs
    @@ -97,6 +97,9 @@ pub enum KvmError {
         #[cfg(guest_arch = "x86_64")]
         #[error("the time ABI does not support {0}")]
         TimeAbiUnsupported(&'static str),
    +    #[cfg(guest_arch = "x86_64")]
    +    #[error("a partition with Hyper-V enlightenments supports at most {max} VPs, not {vp_count}")]
    +    TooManyVps { vp_count: u32, max: u32 },
     }
     
     #[derive(Inspect)]
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: 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