linux/arch
Naman Jain bcc80dec91 x86/hyperv: Fix hv tsc page based sched_clock for hibernation
read_hv_sched_clock_tsc() assumes that the Hyper-V clock counter is
bigger than the variable hv_sched_clock_offset, which is cached during
early boot, but depending on the timing this assumption may be false
when a hibernated VM starts again (the clock counter starts from 0
again) and is resuming back (Note: hv_init_tsc_clocksource() is not
called during hibernation/resume); consequently,
read_hv_sched_clock_tsc() may return a negative integer (which is
interpreted as a huge positive integer since the return type is u64)
and new kernel messages are prefixed with huge timestamps before
read_hv_sched_clock_tsc() grows big enough (which typically takes
several seconds).

Fix the issue by saving the Hyper-V clock counter just before the
suspend, and using it to correct the hv_sched_clock_offset in
resume. This makes hv tsc page based sched_clock continuous and ensures
that post resume, it starts from where it left off during suspend.
Override x86_platform.save_sched_clock_state and
x86_platform.restore_sched_clock_state routines to correct this as soon
as possible.

Note: if Invariant TSC is available, the issue doesn't happen because
1) we don't register read_hv_sched_clock_tsc() for sched clock:
See commit e5313f1c54 ("clocksource/drivers/hyper-v: Rework
clocksource and sched clock setup");
2) the common x86 code adjusts TSC similarly: see
__restore_processor_state() ->  tsc_verify_tsc_adjust(true) and
x86_platform.restore_sched_clock_state().

Cc: stable@vger.kernel.org
Fixes: 1349401ff1 ("clocksource/drivers/hyper-v: Suspend/resume Hyper-V clocksource for hibernation")
Co-developed-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Link: https://lore.kernel.org/r/20240917053917.76787-1-namjain@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <20240917053917.76787-1-namjain@linux.microsoft.com>
2024-12-09 18:42:42 +00:00
..
alpha Driver core changes for 6.13-rc1 2024-11-29 11:43:29 -08:00
arc - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
arm Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
arm64 arm64 fixes for 6.13-rc2: 2024-12-06 13:47:55 -08:00
csky - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
hexagon - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
loongarch LoongArch: KVM: Protect kvm_io_bus_{read,write}() with SRCU 2024-12-03 19:49:28 +08:00
m68k RTC for 6.13 2024-11-30 11:18:16 -08:00
microblaze - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
mips Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
nios2 - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
openrisc - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
parisc parisc architecture fixes for kernel v6.13-rc1: 2024-11-26 14:49:20 -08:00
powerpc module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
riscv ARM: 2024-11-30 14:51:08 -08:00
s390 module: Convert symbol namespace to string literal 2024-12-02 11:34:44 -08:00
sh Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
sparc Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
um Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
x86 x86/hyperv: Fix hv tsc page based sched_clock for hibernation 2024-12-09 18:42:42 +00:00
xtensa - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
.gitignore
Kconfig Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00