linux-stable/arch/x86/kvm
Radim Krčmář 7099e2e1f4 KVM: VMX: disable PEBS before a guest entry
Linux guests on Haswell (and also SandyBridge and Broadwell, at least)
would crash if you decided to run a host command that uses PEBS, like
  perf record -e 'cpu/mem-stores/pp' -a

This happens because KVM is using VMX MSR switching to disable PEBS, but
SDM [2015-12] 18.4.4.4 Re-configuring PEBS Facilities explains why it
isn't safe:
  When software needs to reconfigure PEBS facilities, it should allow a
  quiescent period between stopping the prior event counting and setting
  up a new PEBS event. The quiescent period is to allow any latent
  residual PEBS records to complete its capture at their previously
  specified buffer address (provided by IA32_DS_AREA).

There might not be a quiescent period after the MSR switch, so a CPU
ends up using host's MSR_IA32_DS_AREA to access an area in guest's
memory.  (Or MSR switching is just buggy on some models.)

The guest can learn something about the host this way:
If the guest doesn't map address pointed by MSR_IA32_DS_AREA, it results
in #PF where we leak host's MSR_IA32_DS_AREA through CR2.

After that, a malicious guest can map and configure memory where
MSR_IA32_DS_AREA is pointing and can therefore get an output from
host's tracing.

This is not a critical leak as the host must initiate with PEBS tracing
and I have not been able to get a record from more than one instruction
before vmentry in vmx_vcpu_run() (that place has most registers already
overwritten with guest's).

We could disable PEBS just few instructions before vmentry, but
disabling it earlier shouldn't affect host tracing too much.
We also don't need to switch MSR_IA32_PEBS_ENABLE on VMENTRY, but that
optimization isn't worth its code, IMO.

(If you are implementing PEBS for guests, be sure to handle the case
 where both host and guest enable PEBS, because this patch doesn't.)

Fixes: 26a4f3c08d ("perf/x86: disable PEBS on a guest entry.")
Cc: <stable@vger.kernel.org>
Reported-by: Jiří Olša <jolsa@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-08 12:46:46 +01:00
..
assigned-dev.c KVM: x86: move kvm_set_irq_inatomic to legacy device assignment 2015-11-04 16:24:36 +01:00
assigned-dev.h KVM: x86: move device assignment out of kvm_host.h 2014-11-24 16:53:50 +01:00
cpuid.c s390: A bunch of fixes and optimizations for interrupt and time 2015-11-05 16:26:26 -08:00
cpuid.h Merge branch 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-01-11 16:46:20 -08:00
emulate.c KVM: x86: fix conversion of addresses to linear in 32-bit protected mode 2016-02-24 14:47:45 +01:00
hyperv.c kvm/x86: Hyper-V SynIC timers tracepoints 2016-01-08 19:04:43 +01:00
hyperv.h kvm/x86: Hyper-V SynIC timers 2015-12-16 18:49:45 +01:00
i8254.c kvm: x86: only channel 0 of the i8254 is linked to the HPET 2016-01-07 13:50:38 +01:00
i8254.h KVM: move iodev.h from virt/kvm/ to include/kvm 2015-03-26 21:43:12 +00:00
i8259.c KVM: x86: clean/fix memory barriers in irqchip_in_kernel 2015-07-30 16:02:56 +02:00
ioapic.c kvm/x86: split ioapic-handled and EOI exit bitmaps 2015-11-25 17:24:21 +01:00
ioapic.h kvm/x86: split ioapic-handled and EOI exit bitmaps 2015-11-25 17:24:21 +01:00
iommu.c kvm: rename pfn_t to kvm_pfn_t 2016-01-15 17:56:32 -08:00
irq.c kvm/x86: per-vcpu apicv deactivation support 2015-11-25 17:24:21 +01:00
irq.h KVM: x86: Add support for local interrupt requests from userspace 2015-10-01 15:06:29 +02:00
irq_comm.c kvm/x86: Hyper-V synthetic interrupt controller 2015-11-25 17:24:22 +01:00
Kconfig KVM: x86: select IRQ_BYPASS_MANAGER 2015-10-01 15:06:52 +02:00
kvm_cache_regs.h KVM: x86: API changes for SMM support 2015-06-04 16:01:11 +02:00
lapic.c kvm/x86: Hyper-V synthetic interrupt controller 2015-11-25 17:24:22 +01:00
lapic.h kvm/x86: Hyper-V synthetic interrupt controller 2015-11-25 17:24:22 +01:00
Makefile kvm/x86: move Hyper-V MSR's/hypercall code into hyperv.c file 2015-07-23 08:27:06 +02:00
mmu.c kvm: rename pfn_t to kvm_pfn_t 2016-01-15 17:56:32 -08:00
mmu.h KVM: x86: merge handle_mmio_page_fault and handle_mmio_page_fault_common 2015-11-10 12:06:03 +01:00
mmu_audit.c kvm: rename pfn_t to kvm_pfn_t 2016-01-15 17:56:32 -08:00
mmutrace.h tracing: Rename ftrace_event.h to trace_events.h 2015-05-13 14:05:12 -04:00
mtrr.c KVM: MTRR: treat memory as writeback if MTRR is disabled in guest CPUID 2015-12-22 15:29:00 +01:00
paging_tmpl.h KVM: x86: MMU: fix ubsan index-out-of-range warning 2016-02-25 09:50:35 +01:00
pmu.c KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch 2015-06-23 14:12:14 +02:00
pmu.h KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch 2015-06-23 14:12:14 +02:00
pmu_amd.c KVM: x86/vPMU: Fix unnecessary signed extension for AMD PERFCTRn 2015-08-11 15:19:41 +02:00
pmu_intel.c KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch 2015-06-23 14:12:14 +02:00
svm.c * s390: Support for runtime instrumentation within guests, 2016-01-12 13:22:12 -08:00
trace.h kvm/x86: Hyper-V SynIC timers tracepoints 2016-01-08 19:04:43 +01:00
tss.h
vmx.c KVM: VMX: disable PEBS before a guest entry 2016-03-08 12:46:46 +01:00
x86.c KVM: x86: fix root cause for missed hardware breakpoints 2016-02-26 13:03:39 +01:00
x86.h x86/fpu: Rename XSAVE macros 2015-09-14 12:21:46 +02:00