Skip to content

Commit

Permalink
Merge tag 'timers-urgent-2025-04-10' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Linus Torvalds committed Apr 10, 2025
2 parents 3c9de67 + acea994 commit 3483381
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static inline void hrtimer_update_function(struct hrtimer *timer,
if (WARN_ON_ONCE(!function))
return;
#endif
timer->function = function;
ACCESS_PRIVATE(timer, function) = function;
}

/* Forward a hrtimer so it expires after now: */
Expand Down
12 changes: 6 additions & 6 deletions include/vdso/unaligned.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#ifndef __VDSO_UNALIGNED_H
#define __VDSO_UNALIGNED_H

#define __get_unaligned_t(type, ptr) ({ \
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
__pptr->x; \
#define __get_unaligned_t(type, ptr) ({ \
const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
__get_pptr->x; \
})

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

#endif /* __VDSO_UNALIGNED_H */
2 changes: 1 addition & 1 deletion kernel/time/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static const struct debug_obj_descr hrtimer_debug_descr;

static void *hrtimer_debug_hint(void *addr)
{
return ((struct hrtimer *) addr)->function;
return ACCESS_PRIVATE((struct hrtimer *)addr, function);
}

/*
Expand Down
22 changes: 22 additions & 0 deletions kernel/time/tick-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ void tick_resume(void)

#ifdef CONFIG_SUSPEND
static DEFINE_RAW_SPINLOCK(tick_freeze_lock);
static DEFINE_WAIT_OVERRIDE_MAP(tick_freeze_map, LD_WAIT_SLEEP);
static unsigned int tick_freeze_depth;

/**
Expand All @@ -528,9 +529,22 @@ void tick_freeze(void)
if (tick_freeze_depth == num_online_cpus()) {
trace_suspend_resume(TPS("timekeeping_freeze"),
smp_processor_id(), true);
/*
* All other CPUs have their interrupts disabled and are
* suspended to idle. Other tasks have been frozen so there
* is no scheduling happening. This means that there is no
* concurrency in the system at this point. Therefore it is
* okay to acquire a sleeping lock on PREEMPT_RT, such as a
* spinlock, because the lock cannot be held by other CPUs
* or threads and acquiring it cannot block.
*
* Inform lockdep about the situation.
*/
lock_map_acquire_try(&tick_freeze_map);
system_state = SYSTEM_SUSPEND;
sched_clock_suspend();
timekeeping_suspend();
lock_map_release(&tick_freeze_map);
} else {
tick_suspend_local();
}
Expand All @@ -552,8 +566,16 @@ void tick_unfreeze(void)
raw_spin_lock(&tick_freeze_lock);

if (tick_freeze_depth == num_online_cpus()) {
/*
* Similar to tick_freeze(). On resumption the first CPU may
* acquire uncontended sleeping locks while other CPUs block on
* tick_freeze_lock.
*/
lock_map_acquire_try(&tick_freeze_map);
timekeeping_resume();
sched_clock_resume();
lock_map_release(&tick_freeze_map);

system_state = SYSTEM_RUNNING;
trace_suspend_resume(TPS("timekeeping_freeze"),
smp_processor_id(), false);
Expand Down

0 comments on commit 3483381

Please sign in to comment.