linux/arch/x86
Yosry Ahmed 3fa05f96fc KVM: SVM: Fix redundant updates of LBR MSR intercepts
Don't update the LBR MSR intercept bitmaps if they're already up-to-date,
as unconditionally updating the intercepts forces KVM to recalculate the
MSR bitmaps for vmcb02 on every nested VMRUN.  The redundant updates are
functionally okay; however, they neuter an optimization in Hyper-V
nested virtualization enlightenments and this manifests as a self-test
failure.

In particular, Hyper-V lets L1 mark "nested enlightenments" as clean, i.e.
tell KVM that no changes were made to the MSR bitmap since the last VMRUN.
The hyperv_svm_test KVM selftest intentionally changes the MSR bitmap
"without telling KVM about it" to verify that KVM honors the clean hint,
correctly fails because KVM notices the changed bitmap anyway:

  ==== Test Assertion Failure ====
  x86/hyperv_svm_test.c:120: vmcb->control.exit_code == 0x081
  pid=193558 tid=193558 errno=4 - Interrupted system call
     1	0x0000000000411361: assert_on_unhandled_exception at processor.c:659
     2	0x0000000000406186: _vcpu_run at kvm_util.c:1699
     3	 (inlined by) vcpu_run at kvm_util.c:1710
     4	0x0000000000401f2a: main at hyperv_svm_test.c:175
     5	0x000000000041d0d3: __libc_start_call_main at libc-start.o:?
     6	0x000000000041f27c: __libc_start_main_impl at ??:?
     7	0x00000000004021a0: _start at ??:?
  vmcb->control.exit_code == SVM_EXIT_VMMCALL

Do *not* fix this by skipping svm_hv_vmcb_dirty_nested_enlightenments()
when svm_set_intercept_for_msr() performs a no-op change.  changes to
the L0 MSR interception bitmap are only triggered by full CPUID updates
and MSR filter updates, both of which should be rare.  Changing
svm_set_intercept_for_msr() risks hiding unintended pessimizations
like this one, and is actually more complex than this change.

Fixes: fbe5e5f030 ("KVM: nSVM: Always recalculate LBR MSR intercepts in svm_update_lbrv()")
Cc: stable@vger.kernel.org
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20251112013017.1836863-1-yosry.ahmed@linux.dev
[Rewritten commit message based on mailing list discussion. - Paolo]
Reviewed-by: Sean Christopherson <seanjc@google.com>
Tested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-18 17:52:20 +01:00
..
boot - Simplify inline asm flag output operands now that the minimum compiler 2025-10-11 10:51:14 -07:00
coco Merge branch 'x86/apic' into x86/sev, to resolve conflict 2025-09-05 09:01:42 +02:00
configs x86/xen: select HIBERNATE_CALLBACKS more directly 2025-09-08 20:10:20 +02:00
crypto - Simplify inline asm flag output operands now that the minimum compiler 2025-10-11 10:51:14 -07:00
entry - Remove a bunch of asm implementing condition flags testing in KVM's 2025-10-11 11:19:16 -07:00
events Revert "perf/x86: Always store regs->ip in perf_callchain_kernel()" 2025-11-05 17:05:19 -08:00
hyperv - Remove a bunch of asm implementing condition flags testing in KVM's 2025-10-11 11:19:16 -07:00
ia32
include bpf-fixes 2025-11-14 15:39:39 -08:00
kernel Miscellaneous fixes: 2025-11-15 08:55:29 -08:00
kvm KVM: SVM: Fix redundant updates of LBR MSR intercepts 2025-11-18 17:52:20 +01:00
lib - Remove a bunch of asm implementing condition flags testing in KVM's 2025-10-11 11:19:16 -07:00
math-emu
mm x86/mm: Fix SMP ordering in switch_mm_irqs_off() 2025-10-13 13:55:53 -07:00
net bpf: Do not audit capability check in do_jit() 2025-10-21 18:22:47 -07:00
pci PCI: Add Extended Tag + MRRS quirk for Xeon 6 2025-08-11 15:00:51 -05:00
platform - Remove a bunch of asm implementing condition flags testing in KVM's 2025-10-11 11:19:16 -07:00
power
purgatory kcfi: Rename CONFIG_CFI_CLANG to CONFIG_CFI 2025-09-24 14:29:14 -07:00
ras
realmode
tools - Add functionality to provide runtime firmware updates for the non-x86 parts 2025-09-30 13:40:35 -07:00
um um: Centralize stub size calculations 2025-09-10 14:23:52 +02:00
video fbcon: Use screen info to find primary device 2025-09-10 09:35:33 -05:00
virt - Make TDX and kexec work together 2025-10-04 10:01:30 -07:00
xen x86/xen: select HIBERNATE_CALLBACKS more directly 2025-09-08 20:10:20 +02:00
.gitignore
Kbuild x86/kbuild: Incorporate boot/startup/ via Kbuild makefile 2025-09-03 17:59:59 +02:00
Kconfig - Simplify inline asm flag output operands now that the minimum compiler 2025-10-11 10:51:14 -07:00
Kconfig.assembler x86/kconfig: Remove CONFIG_AS_AVX512 2025-08-21 14:35:01 +02:00
Kconfig.cpu x86/kbuild/64: Restrict clang versions that can use '-march=native' 2025-03-25 08:24:06 +01:00
Kconfig.cpufeatures
Kconfig.debug
Makefile rust: kbuild: support -Cjump-tables=n for Rust 1.93.0 2025-11-04 19:11:39 +01:00
Makefile.um
Makefile_32.cpu