Add support for KVM_CAP_LAPIC2, which enables the full 4KB APIC register page instead of the legacy 1KB register space. The capability uses a bitmask design to support different APIC extensions:
- KVM_LAPIC2_DEFAULT: Basic 4KB APIC page support - KVM_LAPIC2_AMD_DEFAULT: AMD extended LVT registers within the 4KB page The base capability (KVM_LAPIC2_DEFAULT) provides the foundation for exposing the full APIC register space. AMD processors with the ExtApicSpace feature (CPUID 8000_0001h.ECX[3]) further extend LAPIC space with additional LVT registers starting at offset 0x400. These extended LVT registers provide additional interrupt vectors for AMD-specific features like Instruction Based Sampling (IBS). This series implements: 1. Refactoring of existing APIC state functions to use generic pointers, allowing them to work with both 1KB and 4KB APIC register spaces. 2. Infrastructure to detect extended APIC support via arch_has_extapic() and track negotiated capabilities. 3. Extension of APICCommonState to store AMD extended APIC register state (efeat, ectrl, extlvt array) with dynamic allocation based on the number of extended LVT entries. 4. Capability negotiation during vCPU pre-creation: - Always request KVM_LAPIC2_DEFAULT for 4KB APIC page - Additionally request KVM_LAPIC2_AMD_DEFAULT if CPU has ExtApicSpace - Enable the intersection of KVM and QEMU capabilities 5. New KVM_GET/SET_LAPIC2 ioctls operating on struct kvm_lapic_state2 (4KB) instead of struct kvm_lapic_state (1KB), with automatic fallback to legacy ioctls for compatibility. 6. New subsection of the vmstate (vmstate_apic_extended) of apic_common module is added to make migration of extended APIC registers deterministic. This series depends on the corresponding KVM patches: https://lore.kernel.org/kvm/[email protected]/ Patch 8 contains temporary UAPI definitions for testing and should NOT be merged. These definitions will be imported via update-linux-headers.sh once the kernel patches are merged. Testing: - Verified extended APIC state synchronization on AMD hardware with ExtApicSpace support - Confirmed fallback to legacy APIC ioctls on older KVM versions - Validated VM migration compatibility - Ran migration tests from Qemu to make sure there are no regressions due to the changes done. Repo : https://github.com/qemu/qemu.git branch : v10.1.0 base commit : f8b2f64e23 Manali Shukla (8): i386/kvm: Refactor APIC state functions to use generic register pointer i386/kvm: Pass APICCommonState directly to kvm_get_apic_state() i386/apic: Add extended APIC helper functions i386/kvm: Add extended APIC state to APICCommonState i386/kvm: Add extended LAPIC capability negotiation i386/kvm: Add KVM_GET/SET_LAPIC2 support for extended APIC state apic_common: migrate extended APIC fields DO NOT MERGE: Temporary EXTAPIC UAPI definitions hw/i386/kvm/apic.c | 123 +++++++++++++++++++++++++------- hw/intc/apic_common.c | 21 ++++++ include/hw/i386/apic_internal.h | 11 +++ linux-headers/asm-x86/kvm.h | 7 ++ linux-headers/linux/kvm.h | 7 ++ target/i386/kvm/kvm.c | 88 ++++++++++++++++++++++- target/i386/kvm/kvm_i386.h | 7 +- 7 files changed, 233 insertions(+), 31 deletions(-) -- 2.43.0
