linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Sebastian Andrzej Siewior <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, linux-kernel@vger.kernel.org,
	mingo@kernel.org, bigeasy@linutronix.de, tglx@linutronix.de,
	hpa@zytor.com
Subject: [tip:timers/core] posix-timers: Move rcu_head out of it union
Date: Thu, 1 Aug 2019 12:09:55 -0700	[thread overview]
Message-ID: <tip-5d99b32a009e900a561f6a42ea7afe5b21288b8a@git.kernel.org> (raw)
In-Reply-To: <20190730223828.965541887@linutronix.de>

Commit-ID:  5d99b32a009e900a561f6a42ea7afe5b21288b8a
Gitweb:     https://git.kernel.org/tip/5d99b32a009e900a561f6a42ea7afe5b21288b8a
Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Wed, 31 Jul 2019 00:33:54 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 1 Aug 2019 20:51:25 +0200

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


---
 include/linux/posix-timers.h | 5 +++--
 kernel/time/posix-timers.c   | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index b20798fc5191..604cec0e41ba 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -85,7 +85,8 @@ static inline int clockid_to_fd(const clockid_t clk)
  * @it_process:		The task to wakeup on clock_nanosleep (CPU timers)
  * @sigq:		Pointer to preallocated sigqueue
  * @it:			Union representing the various posix timer type
- *			internals. Also used for rcu freeing the timer.
+ *			internals.
+ * @rcu:		RCU head for freeing the timer.
  */
 struct k_itimer {
 	struct list_head	list;
@@ -114,8 +115,8 @@ struct k_itimer {
 		struct {
 			struct alarm	alarmtimer;
 		} alarm;
-		struct rcu_head		rcu;
 	} it;
+	struct rcu_head		rcu;
 };
 
 void run_posix_cpu_timers(struct task_struct *task);
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index bbe8f9686a70..3e663f982c82 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -442,7 +442,7 @@ static struct k_itimer * alloc_posix_timer(void)
 
 static void k_itimer_rcu_free(struct rcu_head *head)
 {
-	struct k_itimer *tmr = container_of(head, struct k_itimer, it.rcu);
+	struct k_itimer *tmr = container_of(head, struct k_itimer, rcu);
 
 	kmem_cache_free(posix_timers_cache, tmr);
 }
@@ -459,7 +459,7 @@ static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
 	}
 	put_pid(tmr->it_pid);
 	sigqueue_free(tmr->sigq);
-	call_rcu(&tmr->it.rcu, k_itimer_rcu_free);
+	call_rcu(&tmr->rcu, k_itimer_rcu_free);
 }
 
 static int common_timer_create(struct k_itimer *new_timer)

  parent reply	other threads:[~2019-08-01 19:10 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 [this message]
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:timers/core] " tip-bot for Thomas Gleixner
2019-08-01 19:10   ` 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-5d99b32a009e900a561f6a42ea7afe5b21288b8a@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bigeasy@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).