KVM x86 pull requests for 6.14
Sean Christopherson
reviewerThe "misc" pull request has a conflict with the tip tree[*]. It's ugly, but not super complex, and it's trivially easy to verify the result.
There are also two single-series topic branches, "vcpu_array" and "memslots", but otherwise nothing out of the ordinary.
Sean Christopherson
reviewer[GIT PULL] KVM: Memslots hardening/cleanups for 6.14
Please pull a small series to clean up and harden kvm_set_memory_region(). KVM s390 is building on this branch/tag to create a KVM-internal memslot for its ucontrol stuff, hence the dedicated pull request (and I didn't have any other pending "generic" changes).
https://lore.kernel.org/all/[email protected]
The following changes since commit 10b2c8a67c4b8ec15f9d07d177f63b563418e948:
Merge tag 'kvm-x86-fixes-6.13-rcN' of https://github.com/kvm-x86/linux into HEAD (2024-12-22 12:59:33 -0500)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-memslots-6.14
for you to fetch changes up to 0cc3cb2151f9830274e7bef39a23dc1da1ecd34a:
KVM: Disallow all flags for KVM-internal memslots (2025-01-14 17:36:16 -0800)
----------------------------------------------------------------
KVM kvm_set_memory_region() cleanups and hardening for 6.14:
- Add proper lockdep assertions when setting memory regions.
- Add a dedicated API for setting KVM-internal memory regions.
- Explicitly disallow all flags for KVM-internal memory regions.
----------------------------------------------------------------
Sean Christopherson (5):
KVM: Open code kvm_set_memory_region() into its sole caller (ioctl() API)
KVM: Assert slots_lock is held when setting memory regions
KVM: Add a dedicated API for setting KVM-internal memslots
KVM: x86: Drop double-underscores from __kvm_set_memory_region()
KVM: Disallow all flags for KVM-internal memslots
arch/x86/kvm/x86.c | 7 ++++--- include/linux/kvm_host.h | 8 +++----- virt/kvm/kvm_main.c | 33 ++++++++++++++------------------- 3 files changed, 21 insertions(+), 27 deletions(-)
Sean Christopherson
reviewer[GIT PULL] KVM: x86: Misc/main changes 6.14
In reply to Sean ChristophersonThe vast majority of this pull request is the overhaul of KVM's CPUID feature handling, which eliminates the kludgy "governed" features code and hopefully makes it easier to maintain and understand kvm_set_cpu_caps().
There is a merge conflict with the tip tree that looks a lot scarier than it actually is (a single feature, SRSO_USER_KERNEL_NO, was added)[*]. I assume it would be easier to resolve the conflict if the tip tree is merged on top?
The other highlight is Ivan's fixes for dealing with VM-Exits that occur while the CPU is vectoring an event.
[*] https://lore.kernel.org/all/[email protected]
The following changes since commit 9af04539d474dda4984ff4909d4568e6123c8cba:
KVM: selftests: Override ARCH for x86_64 instead of using ARCH_DIR (2024-12-18 14:15:05 -0800)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-misc-6.14
for you to fetch changes up to 4c20cd4cee929aef89118ac8820cefab427c6ae1:
KVM: x86: Avoid double RDPKRU when loading host/guest PKRU (2025-01-08 14:08:25 -0800)
----------------------------------------------------------------
KVM x86 misc changes for 6.14:
- Overhaul KVM's CPUID feature infrastructure to replace "governed" features with per-vCPU tracking of the vCPU's capabailities for all features. Along the way, refactor the code to make it easier to add/modify features, and add a variety of self-documenting macro types to again simplify adding new features and to help readers understand KVM's handling of existing features.
- Rework KVM's handling of VM-Exits during event vectoring to plug holes where KVM unintentionally puts the vCPU into infinite loops in some scenarios, e.g. if emulation is triggered by the exit, and to bring parity between VMX and SVM.
- Add pending request and interrupt injection information to the kvm_exit and kvm_entry tracepoints respectively.
- Fix a relatively benign flaw where KVM would end up redoing RDPKRU when loading guest/host PKRU due to a refactoring of the kernel helpers that didn't account for KVM's pre-checking of the need to do WRPKRU.
----------------------------------------------------------------
Ivan Orlov (7):
KVM: x86: Add function for vectoring error generation
KVM: x86: Add emulation status for unhandleable exception vectoring
KVM: x86: Try to unprotect and retry on unhandleable emulation failure
KVM: VMX: Handle event vectoring error in check_emulate_instruction()
KVM: SVM: Handle event vectoring error in check_emulate_instruction()
KVM: selftests: Add and use a helper function for x86's LIDT
KVM: selftests: Add test case for MMIO during vectoring on x86
Liam Ni (1):
KVM: x86: Use LVT_TIMER instead of an open coded literal
Maxim Levitsky (2):
KVM: x86: Add interrupt injection information to the kvm_entry tracepoint
KVM: x86: Add information about pending requests to kvm_exit tracepoint
Sean Christopherson (58):
KVM: x86: Use feature_bit() to clear CONSTANT_TSC when emulating CPUID
KVM: x86: Limit use of F() and SF() to kvm_cpu_cap_{mask,init_kvm_defined}()
KVM: x86: Do all post-set CPUID processing during vCPU creation
KVM: x86: Explicitly do runtime CPUID updates "after" initial setup
KVM: x86: Account for KVM-reserved CR4 bits when passing through CR4 on VMX
KVM: selftests: Update x86's set_sregs_test to match KVM's CPUID enforcement
KVM: selftests: Assert that vcpu->cpuid is non-NULL when getting CPUID entries
KVM: selftests: Refresh vCPU CPUID cache in __vcpu_get_cpuid_entry()
KVM: selftests: Verify KVM stuffs runtime CPUID OS bits on CR4 writes
KVM: x86: Move __kvm_is_valid_cr4() definition to x86.h
KVM: x86/pmu: Drop now-redundant refresh() during init()
KVM: x86: Drop now-redundant MAXPHYADDR and GPA rsvd bits from vCPU creation
KVM: x86: Disallow KVM_CAP_X86_DISABLE_EXITS after vCPU creation
KVM: x86: Reject disabling of MWAIT/HLT interception when not allowed
KVM: x86: Drop the now unused KVM_X86_DISABLE_VALID_EXITS
KVM: selftests: Fix a bad TEST_REQUIRE() in x86's KVM PV test
KVM: selftests: Update x86's KVM PV test to match KVM's disabling exits behavior
KVM: x86: Zero out PV features cache when the CPUID leaf is not present
KVM: x86: Don't update PV features caches when enabling enforcement capability
KVM: x86: Do reverse CPUID sanity checks in __feature_leaf()
KVM: x86: Account for max supported CPUID leaf when getting raw host CPUID
KVM: x86: Unpack F() CPUID feature flag macros to one flag per line of code
KVM: x86: Rename kvm_cpu_cap_mask() to kvm_cpu_cap_init()
KVM: x86: Add a macro to init CPUID features that are 64-bit only
KVM: x86: Add a macro to precisely handle aliased 0x1.EDX CPUID features
KVM: x86: Handle kernel- and KVM-defined CPUID words in a single helper
KVM: x86: #undef SPEC_CTRL_SSBD in cpuid.c to avoid macro collisions
KVM: x86: Harden CPU capabilities processing against out-of-scope features
KVM: x86: Add a macro to init CPUID features that ignore host kernel support
KVM: x86: Add a macro to init CPUID features that KVM emulates in software
KVM: x86: Swap incoming guest CPUID into vCPU before massaging in KVM_SET_CPUID2
KVM: x86: Clear PV_UNHALT for !HLT-exiting only when userspace sets CPUID
KVM: x86: Remove unnecessary caching of KVM's PV CPUID base
KVM: x86: Always operate on kvm_vcpu data in cpuid_entry2_find()
KVM: x86: Move kvm_find_cpuid_entry{,_index}() up near cpuid_entry2_find()
KVM: x86: Remove all direct usage of cpuid_entry2_find()
KVM: x86: Advertise TSC_DEADLINE_TIMER in KVM_GET_SUPPORTED_CPUID
KVM: x86: Advertise HYPERVISOR in KVM_GET_SUPPORTED_CPUID
KVM: x86: Rename "governed features" helpers to use "guest_cpu_cap"
KVM: x86: Replace guts of "governed" features with comprehensive cpu_caps
KVM: x86: Initialize guest cpu_caps based on guest CPUID
KVM: x86: Extract code for generating per-entry emulated CPUID information
KVM: x86: Treat MONTIOR/MWAIT as a "partially emulated" feature
KVM: x86: Initialize guest cpu_caps based on KVM support
KVM: x86: Avoid double CPUID lookup when updating MWAIT at runtime
KVM: x86: Drop unnecessary check that cpuid_entry2_find() returns right leaf
KVM: x86: Update OS{XSAVE,PKE} bits in guest CPUID irrespective of host support
KVM: x86: Update guest cpu_caps at runtime for dynamic CPUID-based features
KVM: x86: Shuffle code to prepare for dropping guest_cpuid_has()
KVM: x86: Replace (almost) all guest CPUID feature queries with cpu_caps
KVM: x86: Drop superfluous host XSAVE check when adjusting guest XSAVES caps
KVM: x86: Add a macro for features that are synthesized into boot_cpu_data
KVM: x86: Pull CPUID capabilities from boot_cpu_data only as needed
KVM: x86: Rename "SF" macro to "SCATTERED_F"
KVM: x86: Explicitly track feature flags that require vendor enabling
KVM: x86: Explicitly track feature flags that are enabled at runtime
KVM: x86: Use only local variables (no bitmask) to init kvm_cpu_caps
KVM: x86: Avoid double RDPKRU when loading host/guest PKRU
Documentation/virt/kvm/api.rst | 10 +- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 65 +- arch/x86/kvm/cpuid.c | 967 ++++++++++++++------- arch/x86/kvm/cpuid.h | 128 ++- arch/x86/kvm/governed_features.h | 22 - arch/x86/kvm/hyperv.c | 2 +- arch/x86/kvm/kvm_emulate.h | 2 + arch/x86/kvm/lapic.c | 6 +- arch/x86/kvm/mmu.h | 2 +- arch/x86/kvm/mmu/mmu.c | 4 +- arch/x86/kvm/pmu.c | 1 - arch/x86/kvm/reverse_cpuid.h | 23 +- arch/x86/kvm/smm.c | 10 +- arch/x86/kvm/svm/nested.c | 22 +- arch/x86/kvm/svm/pmu.c | 8 +- arch/x86/kvm/svm/sev.c | 21 +- arch/x86/kvm/svm/svm.c | 70 +- arch/x86/kvm/svm/svm.h | 4 +- arch/x86/kvm/trace.h | 17 +- arch/x86/kvm/vmx/hyperv.h | 2 +- arch/x86/kvm/vmx/main.c | 1 + arch/x86/kvm/vmx/nested.c | 18 +- arch/x86/kvm/vmx/pmu_intel.c | 4 +- arch/x86/kvm/vmx/sgx.c | 14 +- arch/x86/kvm/vmx/vmx.c | 100 +-- arch/x86/kvm/vmx/x86_ops.h | 3 + arch/x86/kvm/x86.c | 188 ++-- arch/x86/kvm/x86.h | 6 +- include/uapi/linux/kvm.h | 4 - .../testing/selftests/kvm/include/x86/processor.h | 25 +- .../testing/selftests/kvm/set_memory_region_test.c | 53 +- tools/testing/selftests/kvm/x86/kvm_pv_test.c | 38 +- tools/testing/selftests/kvm/x86/set_sregs_test.c | 63 +- tools/testing/selftests/kvm/x86/sev_smoke_test.c | 2 +- 35 files changed, 1187 insertions(+), 719 deletions(-) delete mode 100644 arch/x86/kvm/governed_features.h
Sean Christopherson
reviewer[GIT PULL] KVM: x86: MMU changes for 6.15
In reply to Sean ChristophersonA single lonely change for MMU. I was anticipating landing James' lockless page aging series, but I didn't get to the review until too late in the cycle (it's looking good for 6.15 though).
The following changes since commit 3522c419758ee8dca5a0e8753ee0070a22157bc1:
Merge tag 'kvm-riscv-fixes-6.13-1' of https://github.com/kvm-riscv/linux into HEAD (2024-12-13 13:59:20 -0500)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-mmu-6.14
for you to fetch changes up to 2d5faa6a8402435d6332e8e8f3c3f18cca382d83:
KVM/x86: add comment to kvm_mmu_do_page_fault() (2024-12-16 15:27:34 -0800)
----------------------------------------------------------------
KVM x86 MMU changes for 6.14:
- Add a comment to kvm_mmu_do_page_fault() to explain why KVM performs a direct call to kvm_tdp_page_fault() when RETPOLINE is enabled.
----------------------------------------------------------------
Juergen Gross (1):
KVM/x86: add comment to kvm_mmu_do_page_fault()
arch/x86/kvm/mmu/mmu_internal.h | 4 ++++ 1 file changed, 4 insertions(+)
Sean Christopherson
reviewer[GIT PULL] KVM: Selftests changes for 6.14
In reply to Sean ChristophersonFYI, the "LLC references/misses" patch exposed a latent failure on SKX/CLX/CPL[*] (who's brilliant idea was it to use "CPL" for a CPU code name on x86?). Dapeng is following up with the uarch folks to understand what's going on. If -rc1 is immiment and we don't have a fix, my plan is to have the test only assert that the count is non-zero, and then go with a more precise fix if one arises.
[*] https://lore.kernel.org/all/[email protected]
The following changes since commit 10b2c8a67c4b8ec15f9d07d177f63b563418e948:
Merge tag 'kvm-x86-fixes-6.13-rcN' of https://github.com/kvm-x86/linux into HEAD (2024-12-22 12:59:33 -0500)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-selftests-6.14
for you to fetch changes up to 983820cb53c0e796777caf85bfc2810ad0c8fb22:
KVM: selftests: Add helpers for locally (un)blocking IRQs on x86 (2025-01-08 12:57:03 -0800)
----------------------------------------------------------------
KVM selftests changes for 6.14:
- Misc cleanups and prep work.
- Annotate _no_printf() with "printf" so that pr_debug() statements are checked by the compiler for default builds (and pr_info() when QUIET).
- Attempt to whack the last LLC references/misses mole in the Intel PMU counters test by adding a data load and doing CLFLUSH{OPT} on the data instead of the code being executed. The theory is that modern Intel CPUs have learned new code prefetching tricks that bypass the PMU counters.
----------------------------------------------------------------
Chen Ni (1):
KVM: selftests: Remove unneeded semicolon
Colton Lewis (2):
KVM: selftests: Fix typos in x86's PMU counter test's macro variable use
KVM: selftests: Add defines for AMD PMU CPUID features and properties
Isaku Yamahata (1):
KVM: selftests: Add printf attribute to _no_printf()
Sean Christopherson (2):
KVM: selftests: Use data load to trigger LLC references/misses in Intel PMU
KVM: selftests: Add helpers for locally (un)blocking IRQs on x86
.../selftests/kvm/access_tracking_perf_test.c | 2 +- tools/testing/selftests/kvm/include/test_util.h | 2 +- .../testing/selftests/kvm/include/x86/processor.h | 47 ++++++++++++++++++++++ tools/testing/selftests/kvm/x86/hyperv_ipi.c | 6 ++- .../testing/selftests/kvm/x86/pmu_counters_test.c | 15 +++---- tools/testing/selftests/kvm/x86/svm_int_ctl_test.c | 5 +-- .../selftests/kvm/x86/ucna_injection_test.c | 2 +- tools/testing/selftests/kvm/x86/xapic_ipi_test.c | 3 +- tools/testing/selftests/kvm/x86/xapic_state_test.c | 4 +- tools/testing/selftests/kvm/x86/xen_shinfo_test.c | 5 +-- 10 files changed, 68 insertions(+), 23 deletions(-)
Paolo Bonzini
maintainerRe: [GIT PULL] KVM: Selftests changes for 6.14
Quoted 6 lines · Sean Christopherson
FYI, the "LLC references/misses" patch exposed a latent failure on SKX/CLX/CPL[*] (who's brilliant idea was it to use "CPL" for a CPU code name on x86?). Dapeng is following up with the uarch folks to understand what's going on. If -rc1 is immiment and we don't have a fix, my plan is to have the test only assert that the count is non-zero, and then go with a more precise fix if one arises.
So based on the thread there is a root cause and fix---the test is just counting on an unrelated event.
Paolo
Sean Christopherson
reviewerRe: [GIT PULL] KVM: Selftests changes for 6.14
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Sean Christopherson
FYI, the "LLC references/misses" patch exposed a latent failure on SKX/CLX/CPL[*] (who's brilliant idea was it to use "CPL" for a CPU code name on x86?). Dapeng is following up with the uarch folks to understand what's going on. If -rc1 is immiment and we don't have a fix, my plan is to have the test only assert that the count is non-zero, and then go with a more precise fix if one arises.
So based on the thread there is a root cause and fix---the test is just counting on an unrelated event.
Oh, yeah. Sorry, forgot to follow-up here.
Sean Christopherson
reviewer[GIT PULL] KVM: x86: SVM changes for 6.14
In reply to Sean ChristophersonA handful of minor cleanups, nothing noteworthy.
The following changes since commit 3522c419758ee8dca5a0e8753ee0070a22157bc1:
Merge tag 'kvm-riscv-fixes-6.13-1' of https://github.com/kvm-riscv/linux into HEAD (2024-12-13 13:59:20 -0500)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-svm-6.14
for you to fetch changes up to 4c334c68804a3296009d92c121ee56a7fe19ea87:
KVM: SVM: Use str_enabled_disabled() helper in svm_hardware_setup() (2025-01-10 06:56:20 -0800)
----------------------------------------------------------------
KVM SVM changes for 6.14:
- Macrofy the SEV=n version of the sev_xxx_guest() helpers so that the code is optimized away when building with less than brilliant compilers.
- Remove a now-redundant TLB flush when guest CR4.PGE changes.
- Use str_enabled_disabled() to replace open coded strings.
----------------------------------------------------------------
Sean Christopherson (2):
KVM: SVM: Macrofy SEV=n versions of sev_xxx_guest()
KVM: SVM: Remove redundant TLB flush on guest CR4.PGE change
Thorsten Blum (2):
KVM: SVM: Use str_enabled_disabled() helper in sev_hardware_setup()
KVM: SVM: Use str_enabled_disabled() helper in svm_hardware_setup()
arch/x86/kvm/svm/sev.c | 4 ++-- arch/x86/kvm/svm/svm.c | 8 ++------ arch/x86/kvm/svm/svm.h | 17 +++++------------ 3 files changed, 9 insertions(+), 20 deletions(-)
Sean Christopherson
reviewer[GIT PULL] KVM: vcpu_array fixes and cleanups for 6.14
In reply to Sean ChristophersonThe wonderful vcpu_array changes that you already know and love :-D
The following changes since commit 3522c419758ee8dca5a0e8753ee0070a22157bc1:
Merge tag 'kvm-riscv-fixes-6.13-1' of https://github.com/kvm-riscv/linux into HEAD (2024-12-13 13:59:20 -0500)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-vcpu_array-6.14
for you to fetch changes up to 01528db67f28d5919f7b0a68900dc212165218e2:
KVM: Drop hack that "manually" informs lockdep of kvm->lock vs. vcpu->mutex (2024-12-16 14:37:30 -0800)
----------------------------------------------------------------
KVM vcpu_array fixes and cleanups for 6.14:
- Explicitly verify the target vCPU is online in kvm_get_vcpu() to fix a bug where KVM would return a pointer to a vCPU prior to it being fully online, and give kvm_for_each_vcpu() similar treatment to fix a similar flaw.
- Wait for a vCPU to come online prior to executing a vCPU ioctl to fix a bug where userspace could coerce KVM into handling the ioctl on a vCPU that isn't yet onlined.
- Gracefully handle xa_insert() failures even though such failuires should be impossible in practice.
----------------------------------------------------------------
Sean Christopherson (6):
KVM: Explicitly verify target vCPU is online in kvm_get_vcpu()
KVM: Verify there's at least one online vCPU when iterating over all vCPUs
KVM: Grab vcpu->mutex across installing the vCPU's fd and bumping online_vcpus Revert "KVM: Fix vcpu_array[0] races"
KVM: Don't BUG() the kernel if xa_insert() fails with -EBUSY
KVM: Drop hack that "manually" informs lockdep of kvm->lock vs. vcpu->mutex
include/linux/kvm_host.h | 16 +++++++++--- virt/kvm/kvm_main.c | 68 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 19 deletions(-)
Sean Christopherson
reviewer[GIT PULL] KVM: x86: VMX change for 6.14
In reply to Sean ChristophersonA few fixes and cleanups. The most notable change is Chao's fix for a nasty bug where L1's SVI didn't get updated and result in the interrupt being left in-service forever (though only uncommon use cases are affected, e.g. running pKVM x86 in L1).
The following changes since commit 3522c419758ee8dca5a0e8753ee0070a22157bc1:
Merge tag 'kvm-riscv-fixes-6.13-1' of https://github.com/kvm-riscv/linux into HEAD (2024-12-13 13:59:20 -0500)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-vmx-6.14
for you to fetch changes up to 37c3ddfe5238d88b6ec091ecdf967848bce067c2:
KVM: VMX: read the PML log in the same order as it was written (2025-01-08 14:31:25 -0800)
----------------------------------------------------------------
KVM VMX changes for 6.14:
- Fix a bug where KVM updates hardware's APICv cache of the highest ISR bit while L2 is active, while ultimately results in a hardware-accelerated L1 EOI effectively being lost.
- Honor event priority when emulating Posted Interrupt delivery during nested VM-Enter by queueing KVM_REQ_EVENT instead of immediately handling the interrupt.
- Drop kvm_x86_ops.hwapic_irr_update() as KVM updates hardware's APICv cache prior to every VM-Enter.
- Rework KVM's processing of the Page-Modification Logging buffer to reap entries in the same order they were created, i.e. to mark gfns dirty in the same order that hardware marked the page/PTE dirty.
- Misc cleanups.
----------------------------------------------------------------
Adrian Hunter (1):
KVM: VMX: Allow toggling bits in MSR_IA32_RTIT_CTL when enable bit is cleared
Chao Gao (2):
KVM: nVMX: Defer SVI update to vmcs01 on EOI when L2 is active w/o VID
KVM: x86: Remove hwapic_irr_update() from kvm_x86_ops
Costas Argyris (1):
KVM: VMX: Reinstate __exit attribute for vmx_exit()
Gao Shiyuan (1):
KVM: VMX: Fix comment of handle_vmx_instruction()
Maxim Levitsky (2):
KVM: VMX: refactor PML terminology
KVM: VMX: read the PML log in the same order as it was written
Sean Christopherson (6):
KVM: x86: Plumb in the vCPU to kvm_x86_ops.hwapic_isr_update()
KVM: nVMX: Explicitly update vPPR on successful nested VM-Enter
KVM: nVMX: Check for pending INIT/SIPI after entering non-root mode
KVM: nVMX: Drop manual vmcs01.GUEST_INTERRUPT_STATUS.RVI check at VM-Enter
KVM: nVMX: Use vmcs01's controls shadow to check for IRQ/NMI windows at VM-Enter
KVM: nVMX: Honor event priority when emulating PI delivery during VM-Enter
arch/x86/include/asm/kvm-x86-ops.h | 1 - arch/x86/include/asm/kvm_host.h | 3 +- arch/x86/kvm/lapic.c | 25 +++++++----- arch/x86/kvm/lapic.h | 1 + arch/x86/kvm/vmx/main.c | 3 +- arch/x86/kvm/vmx/nested.c | 84 +++++++++++++++++++++++--------------- arch/x86/kvm/vmx/vmx.c | 76 ++++++++++++++++++++-------------- arch/x86/kvm/vmx/vmx.h | 6 ++- arch/x86/kvm/vmx/x86_ops.h | 3 +- 9 files changed, 120 insertions(+), 82 deletions(-)