linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Thomas Gleixner <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: anna-maria@linutronix.de, mingo@kernel.org, peterz@infradead.org,
	tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org
Subject: [tip:timers/core] posix-timers: Prepare for PREEMPT_RT
Date: Thu, 1 Aug 2019 09:08:46 -0700	[thread overview]
Message-ID: <tip-3a839db3eaeeef31520de45f3b078204d068e3d0@git.kernel.org> (raw)
In-Reply-To: <20190730223829.058247862@linutronix.de>

Commit-ID:  3a839db3eaeeef31520de45f3b078204d068e3d0
Gitweb:     https://git.kernel.org/tip/3a839db3eaeeef31520de45f3b078204d068e3d0
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 31 Jul 2019 00:33:55 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 1 Aug 2019 17:46:43 +0200

posix-timers: Prepare for PREEMPT_RT

Posix timer delete retry loops are affected by the same priority inversion
and live lock issues as the other timers.

Provide a RT specific synchronization function which keeps a reference to
the timer by holding rcu read lock to prevent the timer from being freed,
dropping the timer lock and invoking the timer specific wait function.

This does not yet cover posix CPU timers because they need more special
treatment on PREEMPT_RT.

Originally-by: Anna-Maria Gleixenr <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20190730223829.058247862@linutronix.de

---
 kernel/time/posix-timers.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 3e663f982c82..a71c1aab071c 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -805,6 +805,29 @@ static int common_hrtimer_try_to_cancel(struct k_itimer *timr)
 	return hrtimer_try_to_cancel(&timr->it.real.timer);
 }
 
+#ifdef CONFIG_PREEMPT_RT
+static struct k_itimer *timer_wait_running(struct k_itimer *timer,
+					   unsigned long *flags)
+{
+	const struct k_clock *kc = READ_ONCE(timer->kclock);
+	timer_t timer_id = READ_ONCE(timer->it_id);
+
+	/* Prevent kfree(timer) after dropping the lock */
+	rcu_read_lock();
+	unlock_timer(timer, *flags);
+
+	if (kc->timer_arm == common_hrtimer_arm)
+		hrtimer_cancel_wait_running(&timer->it.real.timer);
+	else if (kc == &alarm_clock)
+		hrtimer_cancel_wait_running(&timer->it.alarm.alarmtimer.timer);
+	else
+		WARN_ON_ONCE(1);
+	rcu_read_unlock();
+
+	/* Relock the timer. It might be not longer hashed. */
+	return lock_timer(timer_id, flags);
+}
+#else
 static struct k_itimer *timer_wait_running(struct k_itimer *timer,
 					   unsigned long *flags)
 {
@@ -815,6 +838,7 @@ static struct k_itimer *timer_wait_running(struct k_itimer *timer,
 	/* Relock the timer. It might be not longer hashed. */
 	return lock_timer(timer_id, flags);
 }
+#endif
 
 /* Set a POSIX.1b interval timer. */
 int common_timer_set(struct k_itimer *timr, int flags,

  parent reply	other threads:[~2019-08-01 16:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30 22:33 [patch 0/7] posix-timers: Prepare for PREEMPT_RT - part 1 Thomas Gleixner
2019-07-30 22:33 ` [patch 1/7] alarmtimer: Prepare for PREEMPT_RT Thomas Gleixner
2019-08-01 16:04   ` [tip:timers/core] " tip-bot for Anna-Maria Gleixner
2019-08-01 19:06   ` tip-bot for Anna-Maria Gleixner
2019-07-30 22:33 ` [patch 2/7] timerfd: " Thomas Gleixner
2019-08-01 16:04   ` [tip:timers/core] " tip-bot for Anna-Maria Gleixner
2019-08-01 19:07   ` tip-bot for Anna-Maria Gleixner
2019-07-30 22:33 ` [patch 3/7] itimers: " Thomas Gleixner
2019-08-01 16:05   ` [tip:timers/core] " tip-bot for Anna-Maria Gleixner
2019-08-01 19:07   ` tip-bot for Anna-Maria Gleixner
2019-07-30 22:33 ` [patch 4/7] posix-timers: Cleanup the flag/flags confusion Thomas Gleixner
2019-08-01 16:06   ` [tip:timers/core] " tip-bot for Anna-Maria Gleixner
2019-08-01 19:08   ` tip-bot for Thomas Gleixner
2019-07-30 22:33 ` [patch 5/7] posix-timers: Rework cancel retry loops Thomas Gleixner
2019-08-01 16:07   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2019-08-01 19:09   ` tip-bot for Thomas Gleixner
2019-07-30 22:33 ` [patch 6/7] posix-timers: Move rcu_head out of it union Thomas Gleixner
2019-08-01 16:08   ` [tip:timers/core] " tip-bot for Sebastian Andrzej Siewior
2019-08-01 19:09   ` tip-bot for Sebastian Andrzej Siewior
2019-07-30 22:33 ` [patch 7/7] posix-timers: Prepare for PREEMPT_RT Thomas Gleixner
2019-07-31  9:49   ` Peter Zijlstra
2019-07-31 11:03     ` Thomas Gleixner
2019-08-01 16:08   ` tip-bot for Thomas Gleixner [this message]
2019-08-01 19:10   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2019-07-31  9:49 ` [patch 0/7] posix-timers: Prepare for PREEMPT_RT - part 1 Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-3a839db3eaeeef31520de45f3b078204d068e3d0@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=anna-maria@linutronix.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).