kernel_samsung_a53x/arch/x86/kernel
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
..
acpi x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility 2024-11-18 10:58:32 +01:00
apic Revert "x86/apic: Always explicitly disarm TSC-deadline timer" 2024-11-24 00:22:51 +01:00
cpu x86/hyperv: Fix hv tsc page based sched_clock for hibernation 2025-01-15 16:29:52 +01:00
fpu Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kprobes Revert "x86/ibt,ftrace: Search for __fentry__ location" 2024-11-24 00:23:31 +01:00
alternative.c x86/alternative: Make custom return thunk unconditional 2024-11-18 22:25:38 +01:00
amd_gart_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
amd_nb.c x86/amd_nb: Check for invalid SMN reads 2024-11-19 14:19:30 +01:00
apb_timer.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
aperture_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
apm_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
asm-offsets.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
asm-offsets_32.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-11-19 09:22:37 +01:00
asm-offsets_64.c x86/xen: Drop USERGS_SYSRET64 paravirt call 2024-11-19 12:26:38 +01:00
audit_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bootflag.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cc_platform.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
check.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cpuid.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crash.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crash_core_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crash_core_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crash_dump_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crash_dump_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
devicetree.c x86/of: Return consistent error type from x86_of_pci_irq_enable() 2024-11-23 23:19:56 +01:00
doublefault_32.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-11-19 09:22:37 +01:00
dumpstack.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dumpstack_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dumpstack_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
e820.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
early-quirks.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
early_printk.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ebda.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
eisa.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
espfix_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ftrace.c x86/returnthunk: Allow different return thunks 2024-11-18 22:25:38 +01:00
ftrace_32.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ftrace_64.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
head32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
head64.c x86/head/64: Re-enable stack protection 2024-11-19 09:23:16 +01:00
head_32.S x86/stackprotector/32: Make the canary into a regular percpu variable 2024-11-19 09:22:37 +01:00
head_64.S x86/head/64: Re-enable stack protection 2024-11-19 09:23:16 +01:00
hpet.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hw_breakpoint.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
i8237.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
i8253.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
i8259.c x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility 2024-11-18 10:58:32 +01:00
idt.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ima_arch.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
io_delay.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ioport.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irq.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irq_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irq_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irq_work.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irqflags.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
irqinit.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
itmt.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
jailhouse.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
jump_label.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kdebugfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kexec-bzimage64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kgdb.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ksysfs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kvm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kvmclock.c x86/kvm: Do not try to disable kvmclock if it was not enabled 2024-11-18 12:12:48 +01:00
ldt.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
machine_kexec_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
machine_kexec_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile x86/head/64: Re-enable stack protection 2024-11-19 09:23:16 +01:00
mmconf-fam10h_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
module.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mpparse.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
msr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nmi.c x86/bugs: Use ALTERNATIVE() instead of mds_user_clear static key 2024-11-19 09:22:40 +01:00
nmi_selftest.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
paravirt-spinlocks.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
paravirt.c x86/xen: Drop USERGS_SYSRET64 paravirt call 2024-11-19 12:26:38 +01:00
paravirt_patch.c x86/xen: Drop USERGS_SYSRET64 paravirt call 2024-11-19 12:26:38 +01:00
pci-dma.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pci-iommu_table.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pci-swiotlb.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcspeaker.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
perf_regs.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
platform-quirks.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pmem.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
probe_roms.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
process.c x86: Increase brk randomness entropy for 64-bit systems 2024-11-23 23:20:46 +01:00
process.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
process_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
process_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ptrace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pvclock.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
quirks.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
reboot.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
reboot_fixups_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
relocate_kernel_32.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
relocate_kernel_64.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
resource.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rtc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
setup.c x86/mm: Fix RESERVE_BRK() for older binutils 2024-11-18 10:58:45 +01:00
setup_percpu.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-11-19 09:22:37 +01:00
sev-es-shared.c x86/sev: Check for user-space IOIO pointing to kernel space 2024-11-08 11:26:09 +01:00
sev-es.c x86/sev: Check IOBM for IOIO exceptions from user-space 2024-11-08 11:26:09 +01:00
sev_verify_cbit.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
signal.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
signal_compat.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
smp.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
smpboot.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
stacktrace.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
static_call.c x86/static-call: provide a way to do very early static-call updates 2025-01-02 17:01:18 +01:00
step.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sys_ia32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sys_x86_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysfb.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysfb_efi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sysfb_simplefb.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tboot.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
time.c x86: stop playing stack games in profile_pc() 2024-11-19 14:19:33 +01:00
tls.c x86/stackprotector/32: Make the canary into a regular percpu variable 2024-11-19 09:22:37 +01:00
tls.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
topology.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
trace_clock.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tracepoint.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
traps.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tsc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tsc_msr.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tsc_sync.c x86/tsc: Trust initial offset in architectural TSC-adjust MSRs 2024-11-19 12:26:51 +01:00
umip.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
unwind_frame.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
unwind_guess.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
unwind_orc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
uprobes.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
verify_cpu.S Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vm86_32.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vmlinux.lds.S x86: Fix .brk attribute in linker script 2024-11-18 10:58:46 +01:00
vsmp_64.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
x86_init.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00