kernel_samsung_a53x/arch/x86/kernel/cpu
Naman Jain a5135d9c45 x86/hyperv: Fix hv tsc page based sched_clock for hibernation
commit bcc80dec91ee745b3d66f3e48f0ec2efdea97149 upstream.

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 e5313f1c5404 ("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: 1349401ff1aa ("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>
Signed-off-by: Naman Jain <namjain@linux.microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-01-15 16:29:52 +01:00
..
mce x86/mce: Make sure to grab mce_sysfs_mutex in set_bank() 2024-11-19 09:23:10 +01:00
microcode Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mtrr x86/mtrr: Check if fixed MTRRs exist before saving them 2024-11-23 23:20:30 +01:00
resctrl Revert "x86/resctrl: Annotate get_mem_config() functions as __init" 2024-11-24 00:22:51 +01:00
acrn.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
amd.c x86/barrier: Do not serialize MSR accesses on AMD 2024-12-17 13:23:58 +01:00
aperfmperf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bugs.c x86/bugs: Do not use UNTRAIN_RET with IBPB on entry 2024-11-23 23:21:55 +01:00
cacheinfo.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
centaur.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
common.c x86: make get_cpu_vendor() accessible from Xen code 2025-01-02 17:01:18 +01:00
cpu.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cpuid-deps.c x86/cpufeatures: Fix dependencies for GFNI, VAES, and VPCLMULQDQ 2024-11-19 11:32:22 +01:00
cyrix.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
feat_ctl.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hygon.c x86/barrier: Do not serialize MSR accesses on AMD 2024-12-17 13:23:58 +01:00
hypervisor.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
intel.c x86/cpu/intel: Detect TME keyid bits before setting MTRR mask registers 2024-11-18 23:18:30 +01:00
intel_epb.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
intel_pconfig.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
match.c x86/cpu: Fix x86_match_cpu() to match just X86_VENDOR_INTEL 2024-11-19 14:19:29 +01:00
mkcapflags.sh Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mshyperv.c x86/hyperv: Fix hv tsc page based sched_clock for hibernation 2025-01-15 16:29:52 +01:00
perfctr-watchdog.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
powerflags.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
proc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rdrand.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
scattered.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
topology.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
transmeta.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tsx.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
umc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
umwait.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vmware.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
zhaoxin.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00