Skip to content

Commit 5d99b32

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
posix-timers: Move rcu_head out of it union
Timer deletion on PREEMPT_RT is prone to priority inversion and live locks. The hrtimer code has a synchronization mechanism for this. Posix CPU timers will grow one. But that mechanism cannot be invoked while holding the k_itimer lock because that can deadlock against the running timer callback. So the lock must be dropped which allows the timer to be freed. The timer free can be prevented by taking RCU readlock before dropping the lock, but because the rcu_head is part of the 'it' union a concurrent free will overwrite the hrtimer on which the task is trying to synchronize. Move the rcu_head out of the union to prevent this. [ tglx: Fixed up kernel-doc. Rewrote changelog ] Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20190730223828.965541887@linutronix.de
1 parent 6945e5c commit 5d99b32

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎include/linux/posix-timers.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ static inline int clockid_to_fd(const clockid_t clk)
8585
* @it_process: The task to wakeup on clock_nanosleep (CPU timers)
8686
* @sigq: Pointer to preallocated sigqueue
8787
* @it: Union representing the various posix timer type
88-
* internals. Also used for rcu freeing the timer.
88+
* internals.
89+
* @rcu: RCU head for freeing the timer.
8990
*/
9091
struct k_itimer {
9192
struct list_head list;
@@ -114,8 +115,8 @@ struct k_itimer {
114115
struct {
115116
struct alarm alarmtimer;
116117
} alarm;
117-
struct rcu_head rcu;
118118
} it;
119+
struct rcu_head rcu;
119120
};
120121

121122
void run_posix_cpu_timers(struct task_struct *task);

‎kernel/time/posix-timers.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static struct k_itimer * alloc_posix_timer(void)
442442

443443
static void k_itimer_rcu_free(struct rcu_head *head)
444444
{
445-
struct k_itimer *tmr = container_of(head, struct k_itimer, it.rcu);
445+
struct k_itimer *tmr = container_of(head, struct k_itimer, rcu);
446446

447447
kmem_cache_free(posix_timers_cache, tmr);
448448
}
@@ -459,7 +459,7 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
459459
}
460460
put_pid(tmr->it_pid);
461461
sigqueue_free(tmr->sigq);
462-
call_rcu(&tmr->it.rcu, k_itimer_rcu_free);
462+
call_rcu(&tmr->rcu, k_itimer_rcu_free);
463463
}
464464

465465
static int common_timer_create(struct k_itimer *new_timer)

0 commit comments

Comments
 (0)