Skip to content

Commit 3483381

Browse files
committed
Merge tag 'timers-urgent-2025-04-10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc timer fixes from Ingo Molnar: - Fix missing ACCESS_PRIVATE() that triggered a Sparse warning - Fix lockdep false positive in tick_freeze() on CONFIG_PREEMPT_RT=y - Avoid <vdso/unaligned.h> macro's variable shadowing to address build warning that triggers under W=2 builds * tag 'timers-urgent-2025-04-10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: vdso: Address variable shadowing in macros timekeeping: Add a lockdep override in tick_freeze() hrtimer: Add missing ACCESS_PRIVATE() for hrtimer::function
2 parents 3c9de67 + acea994 commit 3483381

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

include/linux/hrtimer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static inline void hrtimer_update_function(struct hrtimer *timer,
345345
if (WARN_ON_ONCE(!function))
346346
return;
347347
#endif
348-
timer->function = function;
348+
ACCESS_PRIVATE(timer, function) = function;
349349
}
350350

351351
/* Forward a hrtimer so it expires after now: */

include/vdso/unaligned.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#ifndef __VDSO_UNALIGNED_H
33
#define __VDSO_UNALIGNED_H
44

5-
#define __get_unaligned_t(type, ptr) ({ \
6-
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
7-
__pptr->x; \
5+
#define __get_unaligned_t(type, ptr) ({ \
6+
const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
7+
__get_pptr->x; \
88
})
99

10-
#define __put_unaligned_t(type, val, ptr) do { \
11-
struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
12-
__pptr->x = (val); \
10+
#define __put_unaligned_t(type, val, ptr) do { \
11+
struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \
12+
__put_pptr->x = (val); \
1313
} while (0)
1414

1515
#endif /* __VDSO_UNALIGNED_H */

kernel/time/hrtimer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static const struct debug_obj_descr hrtimer_debug_descr;
366366

367367
static void *hrtimer_debug_hint(void *addr)
368368
{
369-
return ((struct hrtimer *) addr)->function;
369+
return ACCESS_PRIVATE((struct hrtimer *)addr, function);
370370
}
371371

372372
/*

kernel/time/tick-common.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ void tick_resume(void)
509509

510510
#ifdef CONFIG_SUSPEND
511511
static DEFINE_RAW_SPINLOCK(tick_freeze_lock);
512+
static DEFINE_WAIT_OVERRIDE_MAP(tick_freeze_map, LD_WAIT_SLEEP);
512513
static unsigned int tick_freeze_depth;
513514

514515
/**
@@ -528,9 +529,22 @@ void tick_freeze(void)
528529
if (tick_freeze_depth == num_online_cpus()) {
529530
trace_suspend_resume(TPS("timekeeping_freeze"),
530531
smp_processor_id(), true);
532+
/*
533+
* All other CPUs have their interrupts disabled and are
534+
* suspended to idle. Other tasks have been frozen so there
535+
* is no scheduling happening. This means that there is no
536+
* concurrency in the system at this point. Therefore it is
537+
* okay to acquire a sleeping lock on PREEMPT_RT, such as a
538+
* spinlock, because the lock cannot be held by other CPUs
539+
* or threads and acquiring it cannot block.
540+
*
541+
* Inform lockdep about the situation.
542+
*/
543+
lock_map_acquire_try(&tick_freeze_map);
531544
system_state = SYSTEM_SUSPEND;
532545
sched_clock_suspend();
533546
timekeeping_suspend();
547+
lock_map_release(&tick_freeze_map);
534548
} else {
535549
tick_suspend_local();
536550
}
@@ -552,8 +566,16 @@ void tick_unfreeze(void)
552566
raw_spin_lock(&tick_freeze_lock);
553567

554568
if (tick_freeze_depth == num_online_cpus()) {
569+
/*
570+
* Similar to tick_freeze(). On resumption the first CPU may
571+
* acquire uncontended sleeping locks while other CPUs block on
572+
* tick_freeze_lock.
573+
*/
574+
lock_map_acquire_try(&tick_freeze_map);
555575
timekeeping_resume();
556576
sched_clock_resume();
577+
lock_map_release(&tick_freeze_map);
578+
557579
system_state = SYSTEM_RUNNING;
558580
trace_suspend_resume(TPS("timekeeping_freeze"),
559581
smp_processor_id(), false);

0 commit comments

Comments
 (0)