linux-yocto/arch
Maxim Levitsky dda0f3c2b3 KVM: VMX: Preserve host's DEBUGCTLMSR_FREEZE_IN_SMM while running the guest
[ Upstream commit 6b1dd26544 ]

Set/clear DEBUGCTLMSR_FREEZE_IN_SMM in GUEST_IA32_DEBUGCTL based on the
host's pre-VM-Enter value, i.e. preserve the host's FREEZE_IN_SMM setting
while running the guest.  When running with the "default treatment of SMIs"
in effect (the only mode KVM supports), SMIs do not generate a VM-Exit that
is visible to host (non-SMM) software, and instead transitions directly
from VMX non-root to SMM.  And critically, DEBUGCTL isn't context switched
by hardware on SMI or RSM, i.e. SMM will run with whatever value was
resident in hardware at the time of the SMI.

Failure to preserve FREEZE_IN_SMM results in the PMU unexpectedly counting
events while the CPU is executing in SMM, which can pollute profiling and
potentially leak information into the guest.

Check for changes in FREEZE_IN_SMM prior to every entry into KVM's inner
run loop, as the bit can be toggled in IRQ context via IPI callback (SMP
function call), by way of /sys/devices/cpu/freeze_on_smi.

Add a field in kvm_x86_ops to communicate which DEBUGCTL bits need to be
preserved, as FREEZE_IN_SMM is only supported and defined for Intel CPUs,
i.e. explicitly checking FREEZE_IN_SMM in common x86 is at best weird, and
at worst could lead to undesirable behavior in the future if AMD CPUs ever
happened to pick up a collision with the bit.

Exempt TDX vCPUs, i.e. protected guests, from the check, as the TDX Module
owns and controls GUEST_IA32_DEBUGCTL.

WARN in SVM if KVM_RUN_LOAD_DEBUGCTL is set, mostly to document that the
lack of handling isn't a KVM bug (TDX already WARNs on any run_flag).

Lastly, explicitly reload GUEST_IA32_DEBUGCTL on a VM-Fail that is missed
by KVM but detected by hardware, i.e. in nested_vmx_restore_host_state().
Doing so avoids the need to track host_debugctl on a per-VMCS basis, as
GUEST_IA32_DEBUGCTL is unconditionally written by prepare_vmcs02() and
load_vmcs12_host_state().  For the VM-Fail case, even though KVM won't
have actually entered the guest, vcpu_enter_guest() will have run with
vmcs02 active and thus could result in vmcs01 being run with a stale value.

Cc: stable@vger.kernel.org
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Co-developed-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20250610232010.162191-9-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-08-20 18:41:43 +02:00
..
alpha mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
arc ARC fixes for 6.16 2025-06-12 08:17:56 -07:00
arm ARM: tegra: Use I/O memcpy to write to IRAM 2025-08-20 18:40:59 +02:00
arm64 mm/ptdump: take the memory hotplug lock inside ptdump_walk_pgd() 2025-08-20 18:41:41 +02:00
csky mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
hexagon mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
loongarch LoongArch: vDSO: Remove -nostdlib complier flag 2025-08-20 18:40:47 +02:00
m68k m68k: Don't unregister boot console needlessly 2025-08-15 16:38:42 +02:00
microblaze mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
mips MIPS: lantiq: falcon: sysctrl: fix request memory check logic 2025-08-20 18:41:24 +02:00
nios2 mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
openrisc mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
parisc parisc: Makefile: fix a typo in palo.conf 2025-08-20 18:41:41 +02:00
powerpc powerpc: floppy: Add missing checks after DMA map 2025-08-20 18:41:16 +02:00
riscv mm/ptdump: take the memory hotplug lock inside ptdump_walk_pgd() 2025-08-20 18:41:41 +02:00
s390 mm/ptdump: take the memory hotplug lock inside ptdump_walk_pgd() 2025-08-20 18:41:41 +02:00
sh sh: Do not use hyphen in exported variable name 2025-08-15 16:39:12 +02:00
sparc mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
um um: Re-evaluate thread flags repeatedly 2025-08-20 18:41:09 +02:00
x86 KVM: VMX: Preserve host's DEBUGCTLMSR_FREEZE_IN_SMM while running the guest 2025-08-20 18:41:43 +02:00
xtensa mm: pgtable: fix pte_swp_exclusive 2025-06-11 14:52:08 -07:00
.gitignore
Kconfig fs/resctrl: Add boiler plate for external resctrl code 2025-05-16 11:05:40 +02:00