Skip to content

KVM: x86: Add support for AMD Extended APIC registers

Manali Shukla kvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 16 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9KVM: x86: Refactor APIC register mask handling to support extended APIC registersarch/x86/kvm/lapic.c arch/x86/kvm/lapic.h arch/x86/kvm/vmx/vmx.c+67 -412 replies
2/9x86/apic: Add helper to get maximum number of Extended LVT registersarch/x86/include/asm/apic.h arch/x86/include/asm/kvm_host.h arch/x86/kernel/apic/apic.c+28 -02 replies
3/9KVM: SVM: Set kvm_caps.has_extapic when CPU supports Extended APICarch/x86/kvm/svm/svm.c arch/x86/kvm/x86.h+5 -01 reply
4/9KVM: x86: Introduce KVM_CAP_LAPIC2 for 4KB APIC register space supportDocumentation/virt/kvm/api.rst arch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c +1 more+67 -02 replies
5/9KVM: x86: Refactor APIC state get/set to accept variable-sized buffersarch/x86/kvm/lapic.c arch/x86/kvm/lapic.h arch/x86/kvm/x86.c+20 -201 reply
6/9KVM: Add KVM_GET_LAPIC2 and KVM_SET_LAPIC2 for extended APICDocumentation/virt/kvm/api.rst arch/x86/include/uapi/asm/kvm.h arch/x86/kvm/x86.c +1 more+111 -04 replies
7/9KVM: x86: Emulate Extended LVT registers for AMD guestsarch/x86/include/asm/apicdef.h arch/x86/kvm/cpuid.c arch/x86/kvm/lapic.c +1 more+78 -11 reply
8/9x86/cpufeatures: Add CPUID feature bit for Extended LVT AVIC accelerationarch/x86/include/asm/cpufeatures.h+1 -00 replies
9/9KVM: SVM: Add AVIC support for extended LVT MSRsarch/x86/kvm/svm/avic.c+14 -01 reply

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by.

PatchBorislav Petkov (AMD)
1/9
2/9
3/9
4/9
5/9
6/9
7/9
8/9A-b
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH v1 0/9] KVM: x86: Add support for AMD Extended APIC registers

Add support for AMD's Extended APIC registers, which reside in a 4KB APIC page instead of the legacy 1KB APIC register space. Extended LVT registers (offsets 0x500-0x530) provide additional interrupt vectors for features like Instruction Based Sampling (IBS).

Introduce KVM_CAP_LAPIC2 to allow userspace to opt into the full 4KB APIC register space. The capability uses a bitmask to support different APIC extensions:

KVM_LAPIC2_DEFAULT: 4KB APIC register space (common foundation)
KVM_LAPIC2_AMD_DEFAULT: Extended LVT registers (AMD-specific)

Add KVM_GET/SET_LAPIC2 ioctls that operate on a 4KB APIC register space accommodate extended registers. Legacy KVM_GET/SET_LAPIC continue to work for backward compatibility.

Emulate extended APIC registers (APIC_EFEAT, APIC_ECTRL, APIC_EILVTn) when the guest has X86_FEATURE_EXTAPIC and userspace enables KVM_CAP_LAPIC2. Current AMD processors support four extended LVT entries, future processors may support up to 255.

Integrate with AVIC to accelerate extended LVT MSR access when AVIC_EXTLVT is supported. Reads are accelerated without VM-exits; writes trigger trap-style VM-exits.

Tested on AMD hardware with Extapic support:
- Extended APIC register read/write emulation and AVIC acceleration with IBS driver running on the guest
- VM migration with extended APIC state and without extended APIC state
- Backward compatibility check:
Fallback to legacy IOCTLs when KVM_CAP_LAPIC2 capability is not enabled

Equivalent Qemu changes can be found at:
https://github.com/AMDESE/qemu/tree/extlvt_v1

Patches are prepared on kvm-x86/next (003f68c79227).

Manali Shukla (7):
KVM: x86: Refactor APIC register mask handling to support extended
APIC registers
x86/apic: Add helper to get maximum number of Extended LVT registers
KVM: SVM: Set kvm_caps.has_extapic when CPU supports Extended APIC
KVM: x86: Introduce KVM_CAP_LAPIC2 for 4KB APIC register space support
KVM: x86: Refactor APIC state get/set to accept variable-sized buffers
KVM: Add KVM_GET_LAPIC2 and KVM_SET_LAPIC2 for extended APIC
KVM: SVM: Add AVIC support for extended LVT MSRs

Santosh Shukla (2):
KVM: x86: Emulate Extended LVT registers for AMD guests x86/cpufeatures: Add CPUID feature bit for Extended LVT AVIC
acceleration

 Documentation/virt/kvm/api.rst     |  75 +++++++++++++
 arch/x86/include/asm/apic.h        |   1 +
 arch/x86/include/asm/apicdef.h     |  18 +++
 arch/x86/include/asm/cpufeatures.h |   1 +
 arch/x86/include/asm/kvm_host.h    |  12 ++
 arch/x86/include/uapi/asm/kvm.h    |   5 +
 arch/x86/kernel/apic/apic.c        |  17 +++
 arch/x86/kvm/cpuid.c               |  10 +-
 arch/x86/kvm/lapic.c               | 169 ++++++++++++++++++++---------
 arch/x86/kvm/lapic.h               |  14 ++-
 arch/x86/kvm/svm/avic.c            |  14 +++
 arch/x86/kvm/svm/svm.c             |   3 +
 arch/x86/kvm/vmx/vmx.c             |  10 +-
 arch/x86/kvm/x86.c                 |  93 +++++++++++++++-
 arch/x86/kvm/x86.h                 |   2 +
 include/uapi/linux/kvm.h           |   7 ++
 16 files changed, 390 insertions(+), 61 deletions(-)
Signature · 1 line
2.43.0