anolis-cloud-kernel/kernel/time
Koichiro Den 6ab2451c0f hrtimers: Handle CPU state correctly on hotplug
ANBZ: #19104

commit 2f8dea1692 upstream.

Consider a scenario where a CPU transitions from CPUHP_ONLINE to halfway
through a CPU hotunplug down to CPUHP_HRTIMERS_PREPARE, and then back to
CPUHP_ONLINE:

Since hrtimers_prepare_cpu() does not run, cpu_base.hres_active remains set
to 1 throughout. However, during a CPU unplug operation, the tick and the
clockevents are shut down at CPUHP_AP_TICK_DYING. On return to the online
state, for instance CFS incorrectly assumes that the hrtick is already
active, and the chance of the clockevent device to transition to oneshot
mode is also lost forever for the CPU, unless it goes back to a lower state
than CPUHP_HRTIMERS_PREPARE once.

This round-trip reveals another issue; cpu_base.online is not set to 1
after the transition, which appears as a WARN_ON_ONCE in enqueue_hrtimer().

Aside of that, the bulk of the per CPU state is not reset either, which
means there are dangling pointers in the worst case.

Address this by adding a corresponding startup() callback, which resets the
stale per CPU state and sets the online flag.

[ tglx: Make the new callback unconditionally available, remove the online
  	modification in the prepare() callback and clear the remaining
  	state in the starting callback instead of the prepare callback ]

Fixes: 5c0930ccaa ("hrtimers: Push pending hrtimers away from outgoing CPU earlier")
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20241220134421.3809834-1-koichiro.den@canonical.com

Fixes: CVE-2024-57951
Signed-off-by: Xiao Long <xiaolong@openanolis.org>
Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
Reviewed-by: Cruz Zhao <cruzzhao@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/4713
2025-03-13 02:38:26 +00:00
..
Kconfig posix-cpu-timers: Provide mechanisms to defer timer handling to task_work 2020-08-06 16:50:59 +02:00
Makefile ns: Introduce Time Namespace 2020-01-14 12:20:48 +01:00
alarmtimer.c alarmtimer: Prevent starvation by small intervals and SIG_IGN 2024-07-29 04:11:56 +00:00
clockevents.c tick: Remove outgoing CPU from broadcast masks 2019-03-23 18:26:43 +01:00
clocksource.c clocksource: Skip watchdog check for large watchdog intervals 2024-07-29 04:11:56 +00:00
hrtimer.c hrtimers: Handle CPU state correctly on hotplug 2025-03-13 02:38:26 +00:00
itimer.c time: Prevent undefined behaviour in timespec64_to_ns() 2020-10-26 11:48:11 +01:00
jiffies.c clocksource: Reduce clocksource-skew threshold 2022-01-27 10:54:05 +01:00
namespace.c nsproxy: support CLONE_NEWTIME with setns() 2020-07-08 11:14:22 +02:00
ntp.c ntp: Fix RTC synchronization on 32-bit platforms 2024-08-06 10:58:20 +00:00
ntp_internal.h ntp: Make the RTC synchronization more reliable 2024-08-06 10:58:20 +00:00
posix-clock.c posix-clocks: Rename the clock_get() callback to clock_get_timespec() 2020-01-14 12:20:49 +01:00
posix-cpu-timers.c posix-cpu-timers: Implement the missing timer_wait_running callback 2024-07-29 04:11:56 +00:00
posix-stubs.c timers: Prevent union confusion from unexpected restart_syscall() 2024-07-29 04:11:56 +00:00
posix-timers.c posix-cpu-timers: Implement the missing timer_wait_running callback 2024-07-29 04:11:56 +00:00
posix-timers.h posix-clocks: Introduce clock_get_ktime() callback 2020-01-14 12:20:51 +01:00
sched_clock.c time/sched_clock: Mark sched_clock_read_begin/retry() as notrace 2020-10-26 11:34:31 +01:00
test_udelay.c
tick-broadcast-hrtimer.c tick: broadcast-hrtimer: Fix a race in bc_set_next 2019-09-27 14:45:55 +02:00
tick-broadcast.c tick: Get rid of tick_period 2024-08-02 07:26:05 +00:00
tick-common.c tick/common: Align tick period during sched_timer setup 2024-08-02 07:26:05 +00:00
tick-internal.h tick: Get rid of tick_period 2024-08-02 07:26:05 +00:00
tick-oneshot.c
tick-sched.c rcu: Fix missing TICK_DEP_MASK_RCU_EXP dependency check 2024-08-12 09:46:50 +00:00
tick-sched.h tick: Detect and fix jiffies update stall 2024-08-02 07:26:05 +00:00
time.c y2038: remove unused time32 interfaces 2020-02-21 11:22:15 -08:00
timeconst.bc
timeconv.c
timecounter.c
timekeeping.c timekeeping: Fix cross-timestamp interpolation for non-x86 2024-07-29 04:11:56 +00:00
timekeeping.h timekeeping: Split jiffies seqlock 2020-03-21 16:00:23 +01:00
timekeeping_debug.c
timekeeping_internal.h timekeeping/vsyscall: Provide vdso_update_begin/end() 2020-08-06 10:57:30 +02:00
timer.c timers: Fix warning condition in __run_timers() 2022-04-20 09:23:30 +02:00
timer_list.c timer_list: Guard procfs specific code 2019-06-23 00:08:52 +02:00
vsyscall.c timekeeping/vsyscall: Provide vdso_update_begin/end() 2020-08-06 10:57:30 +02:00