linux/arch/x86/kvm
Vitaly Kuznetsov 77fcbe823f KVM: x86: Prevent 'hv_clock->system_time' from going negative in kvm_guest_time_update()
When guest time is reset with KVM_SET_CLOCK(0), it is possible for
'hv_clock->system_time' to become a small negative number. This happens
because in KVM_SET_CLOCK handling we set 'kvm->arch.kvmclock_offset' based
on get_kvmclock_ns(kvm) but when KVM_REQ_CLOCK_UPDATE is handled,
kvm_guest_time_update() does (masterclock in use case):

hv_clock.system_time = ka->master_kernel_ns + v->kvm->arch.kvmclock_offset;

And 'master_kernel_ns' represents the last time when masterclock
got updated, it can precede KVM_SET_CLOCK() call. Normally, this is not a
problem, the difference is very small, e.g. I'm observing
hv_clock.system_time = -70 ns. The issue comes from the fact that
'hv_clock.system_time' is stored as unsigned and 'system_time / 100' in
compute_tsc_page_parameters() becomes a very big number.

Use 'master_kernel_ns' instead of get_kvmclock_ns() when masterclock is in
use and get_kvmclock_base_ns() when it's not to prevent 'system_time' from
going negative.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20210331124130.337992-2-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-04-01 05:14:19 -04:00
..
mmu Merge commit 'kvm-tdp-fix-flushes' into kvm-master 2021-03-31 07:45:41 -04:00
svm Merge branch 'kvm-fix-svm-races' into kvm-master 2021-04-01 05:14:05 -04:00
vmx x86/perf: Use RET0 as default for guest_get_msrs to handle "no PMU" case 2021-03-10 16:45:09 +01:00
cpuid.c KVM: x86: Advertise INVPCID by default 2021-02-18 07:33:29 -05:00
cpuid.h KVM: x86: Add helper to consolidate "raw" reserved GPA mask calculations 2021-02-04 09:27:30 -05:00
debugfs.c KVM: let kvm_destroy_vm_debugfs clean up vCPU debugfs directories 2020-06-04 11:00:54 -04:00
emulate.c KVM: x86: Restore all 64 bits of DR6 and DR7 during RSM on x86-64 2021-02-09 08:17:05 -05:00
hyperv.c KVM: x86: hyper-v: Don't touch TSC page values when guest opted for re-enlightenment 2021-03-18 08:02:46 -04:00
hyperv.h KVM: x86: hyper-v: Prevent using not-yet-updated TSC page by secondary CPUs 2021-03-17 04:03:22 -04:00
i8254.c kvm: i8254: remove redundant assignment to pointer s 2020-06-11 12:35:18 -04:00
i8254.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
i8259.c KVM: x86: Refactor picdev_write() to prevent Spectre-v1/L1TF attacks 2020-01-27 19:59:37 +01:00
ioapic.c KVM: ioapic: break infinite recursion on lazy EOI 2020-10-24 04:42:06 -04:00
ioapic.h kvm/x86: Remove redundant function implementations 2020-05-27 13:11:10 -04:00
irq_comm.c x86/kvm: Use msi_msg shadow structs 2020-10-28 20:26:26 +01:00
irq.c KVM: x86/xen: Add event channel interrupt vector upcall 2021-02-04 14:19:39 +00:00
irq.h kvm/x86: Remove redundant function implementations 2020-05-27 13:11:10 -04:00
Kconfig KVM: x86: allow compiling out the Xen hypercall interface 2021-03-02 14:30:45 -05:00
kvm_cache_regs.h KVM: x86: use static calls to reduce kvm_x86_ops overhead 2021-02-04 05:27:30 -05:00
kvm_emulate.h KVM: x86: reading DR cannot fail 2021-02-09 08:17:07 -05:00
lapic.c KVM: LAPIC: Advancing the timer expiration on guest initiated write 2021-03-12 13:18:52 -05:00
lapic.h KVM: x86: hyper-v: Always use to_hv_vcpu() accessor to get to 'struct kvm_vcpu_hv' 2021-02-09 08:17:13 -05:00
Makefile KVM: make: Fix out-of-source module builds 2021-03-30 13:07:10 -04:00
mmu.h KVM: x86: use static calls to reduce kvm_x86_ops overhead 2021-02-04 05:27:30 -05:00
mtrr.c KVM: x86: Add helper to consolidate "raw" reserved GPA mask calculations 2021-02-04 09:27:30 -05:00
pmu.c KVM: x86: use static calls to reduce kvm_x86_ops overhead 2021-02-04 05:27:30 -05:00
pmu.h KVM: vmx/pmu: Release guest LBR event via lazy release mechanism 2021-02-04 05:27:26 -05:00
trace.h KVM: x86/xen: intercept xen hypercalls if enabled 2021-02-04 14:18:45 +00:00
tss.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
x86.c KVM: x86: Prevent 'hv_clock->system_time' from going negative in kvm_guest_time_update() 2021-04-01 05:14:19 -04:00
x86.h KVM: x86: remove unused declaration of kvm_write_tsc() 2021-03-30 13:07:09 -04:00
xen.c KVM: x86/xen: Add support for vCPU runstate information 2021-03-02 14:30:54 -05:00
xen.h KVM: x86/xen: Add support for vCPU runstate information 2021-03-02 14:30:54 -05:00