From 86ff06cd73b95b79a7f88c42ccfe5d9ac42659b0 Mon Sep 17 00:00:00 2001 From: Salvatore Bonaccorso Date: Wed, 30 Jan 2019 17:09:46 +0100 Subject: [PATCH] [x86] kvmclock: set offset for kvm unstable clock Closes: #918036 --- debian/changelog | 3 ++ ...ck-set-offset-for-kvm-unstable-clock.patch | 45 +++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 49 insertions(+) create mode 100644 debian/patches/bugfix/x86/x86-kvmclock-set-offset-for-kvm-unstable-clock.patch diff --git a/debian/changelog b/debian/changelog index cd9ac1b5e..915206c91 100644 --- a/debian/changelog +++ b/debian/changelog @@ -102,6 +102,9 @@ linux (4.19.17-1) UNRELEASED; urgency=medium * [arm64] enable ARM_CCI_PMU so ARM_CCI400_PMU and ARM_CCI5xx_PMU options get really enabled. + [ Salvatore Bonaccorso ] + * [x86] kvmclock: set offset for kvm unstable clock (Closes: #918036) + -- Luca Boccassi Fri, 18 Jan 2019 19:09:06 +0000 linux (4.19.16-1) unstable; urgency=medium diff --git a/debian/patches/bugfix/x86/x86-kvmclock-set-offset-for-kvm-unstable-clock.patch b/debian/patches/bugfix/x86/x86-kvmclock-set-offset-for-kvm-unstable-clock.patch new file mode 100644 index 000000000..0dddf2574 --- /dev/null +++ b/debian/patches/bugfix/x86/x86-kvmclock-set-offset-for-kvm-unstable-clock.patch @@ -0,0 +1,45 @@ +From: Pavel Tatashin +Date: Sat, 26 Jan 2019 12:49:56 -0500 +Subject: x86/kvmclock: set offset for kvm unstable clock +Origin: https://patchwork.kernel.org/patch/10782557/ +Bug-Debian: https://bugs.debian.org/918036 + +VMs may show incorrect uptime and dmesg printk offsets on hypervisors with +unstable clock. The problem is produced when VM is rebooted without exiting +from qemu. + +The fix is to calculate clock offset not only for stable clock but for +unstable clock as well, and use kvm_sched_clock_read() which substracts +the offset for both clocks. + +This is safe, because pvclock_clocksource_read() does the right thing and +makes sure that clock always goes forward, so once offset is calculated +with unstable clock, we won't get new reads that are smaller than offset, +and thus won't get negative results. + +Thank you Jon DeVree for helping to reproduce this issue. + +Fixes: 857baa87b642 ("sched/clock: Enable sched clock early") + +Reported-by: Dominique Martinet +Signed-off-by: Pavel Tatashin +[carnil: Backport to 4.19 for context changes] +--- + arch/x86/kernel/kvmclock.c | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +--- a/arch/x86/kernel/kvmclock.c ++++ b/arch/x86/kernel/kvmclock.c +@@ -117,11 +117,8 @@ static u64 kvm_sched_clock_read(void) + + static inline void kvm_sched_clock_init(bool stable) + { +- if (!stable) { +- pv_time_ops.sched_clock = kvm_clock_read; ++ if (!stable) + clear_sched_clock_stable(); +- return; +- } + + kvm_sched_clock_offset = kvm_clock_read(); + pv_time_ops.sched_clock = kvm_sched_clock_read; diff --git a/debian/patches/series b/debian/patches/series index d3d0265c7..6e5abf340 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -79,6 +79,7 @@ bugfix/arm64/arm64-acpi-Add-fixup-for-HPE-m400-quirks.patch bugfix/x86/x86-32-disable-3dnow-in-generic-config.patch bugfix/powerpc/powerpc-fix-mcpu-options-for-spe-only-compiler.patch bugfix/m68k/m68k-build-with-ffreestanding.patch +bugfix/x86/x86-kvmclock-set-offset-for-kvm-unstable-clock.patch # Arch features features/mips/MIPS-increase-MAX-PHYSMEM-BITS-on-Loongson-3-only.patch