Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kvm: fix wrong address when writing Hyper-V tsc page

When kvm_write_guest writes the tsc_ref structure to the guest, or it will lead
the low HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT bits of the TSC page address
must be cleared, or the guest can see a non-zero sequence number.

Otherwise Windows guests would not be able to get a correct clocksource
(QueryPerformanceCounter will always return 0) which causes serious chaos.

Signed-off-by: Xiaoming Gao <newtongao@tencnet.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Xiaoming Gao and committed by
Paolo Bonzini
e1fa108d 682367c4

+1 -1
+1 -1
arch/x86/kvm/x86.c
··· 1898 1898 if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE)) 1899 1899 break; 1900 1900 gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT; 1901 - if (kvm_write_guest(kvm, data, 1901 + if (kvm_write_guest(kvm, gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT, 1902 1902 &tsc_ref, sizeof(tsc_ref))) 1903 1903 return 1; 1904 1904 mark_page_dirty(kvm, gfn);