Skip to content

Commit bd03143

Browse files
committed
alarmtimer: Init nanosleep alarm timer on stack
syszbot reported the following debugobjects splat: ODEBUG: object is on stack, but not annotated WARNING: CPU: 0 PID: 4185 at lib/debugobjects.c:328 RIP: 0010:debug_object_is_on_stack lib/debugobjects.c:327 [inline] debug_object_init+0x17/0x20 lib/debugobjects.c:391 debug_hrtimer_init kernel/time/hrtimer.c:410 [inline] debug_init kernel/time/hrtimer.c:458 [inline] hrtimer_init+0x8c/0x410 kernel/time/hrtimer.c:1259 alarm_init kernel/time/alarmtimer.c:339 [inline] alarm_timer_nsleep+0x164/0x4d0 kernel/time/alarmtimer.c:787 SYSC_clock_nanosleep kernel/time/posix-timers.c:1226 [inline] SyS_clock_nanosleep+0x235/0x330 kernel/time/posix-timers.c:1204 do_syscall_64+0x281/0x940 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7 This happens because the hrtimer for the alarm nanosleep is on stack, but the code does not use the proper debug objects initialization. Split out the code for the allocated use cases and invoke hrtimer_init_on_stack() for the nanosleep related functions. Reported-by: [email protected] Signed-off-by: Thomas Gleixner <[email protected]> Cc: John Stultz <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent a84d116 commit bd03143

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

kernel/time/alarmtimer.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ static int alarmtimer_resume(struct device *dev)
326326
}
327327
#endif
328328

329+
static void
330+
__alarm_init(struct alarm *alarm, enum alarmtimer_type type,
331+
enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
332+
{
333+
timerqueue_init(&alarm->node);
334+
alarm->timer.function = alarmtimer_fired;
335+
alarm->function = function;
336+
alarm->type = type;
337+
alarm->state = ALARMTIMER_STATE_INACTIVE;
338+
}
339+
329340
/**
330341
* alarm_init - Initialize an alarm structure
331342
* @alarm: ptr to alarm to be initialized
@@ -335,13 +346,9 @@ static int alarmtimer_resume(struct device *dev)
335346
void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
336347
enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
337348
{
338-
timerqueue_init(&alarm->node);
339349
hrtimer_init(&alarm->timer, alarm_bases[type].base_clockid,
340-
HRTIMER_MODE_ABS);
341-
alarm->timer.function = alarmtimer_fired;
342-
alarm->function = function;
343-
alarm->type = type;
344-
alarm->state = ALARMTIMER_STATE_INACTIVE;
350+
HRTIMER_MODE_ABS);
351+
__alarm_init(alarm, type, function);
345352
}
346353
EXPORT_SYMBOL_GPL(alarm_init);
347354

@@ -719,6 +726,8 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
719726

720727
__set_current_state(TASK_RUNNING);
721728

729+
destroy_hrtimer_on_stack(&alarm->timer);
730+
722731
if (!alarm->data)
723732
return 0;
724733

@@ -740,6 +749,15 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
740749
return -ERESTART_RESTARTBLOCK;
741750
}
742751

752+
static void
753+
alarm_init_on_stack(struct alarm *alarm, enum alarmtimer_type type,
754+
enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
755+
{
756+
hrtimer_init_on_stack(&alarm->timer, alarm_bases[type].base_clockid,
757+
HRTIMER_MODE_ABS);
758+
__alarm_init(alarm, type, function);
759+
}
760+
743761
/**
744762
* alarm_timer_nsleep_restart - restartblock alarmtimer nsleep
745763
* @restart: ptr to restart block
@@ -752,7 +770,7 @@ static long __sched alarm_timer_nsleep_restart(struct restart_block *restart)
752770
ktime_t exp = restart->nanosleep.expires;
753771
struct alarm alarm;
754772

755-
alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
773+
alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup);
756774

757775
return alarmtimer_do_nsleep(&alarm, exp, type);
758776
}
@@ -784,7 +802,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
784802
if (!capable(CAP_WAKE_ALARM))
785803
return -EPERM;
786804

787-
alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
805+
alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup);
788806

789807
exp = timespec64_to_ktime(*tsreq);
790808
/* Convert (if necessary) to absolute time */

0 commit comments

Comments
 (0)