mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	Andi Kleen <ak@linux.intel.com>, Andi Kleen <andi@firstfloor.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 4/4] posix-timers: turn it_signal into it_valid flag
Date: Tue, 6 Sep 2011 21:16:53 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.02.1109062110090.2723@ionos> (raw)
In-Reply-To: <20110906184926.GA25997@redhat.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 3050 bytes --]

On Tue, 6 Sep 2011, Oleg Nesterov wrote:
> On 09/06, Thomas Gleixner wrote:
> >
> > On Tue, 6 Sep 2011, Eric Dumazet wrote:
> >
> > > Le mardi 06 septembre 2011 à 16:51 +0200, Oleg Nesterov a écrit :
> > > > On 09/05, Andi Kleen wrote:
> > > > >
> > > > > > I forgot everything I knew about ->it_requeue_pending logic, but it
> > > > > > seems to me that do_schedule_next_timer()->lock_timer() can find and
> > > > > > lock successfully the wrong timer. Another thread can do timer_delete()
> > > > > > and then re-create the timer with the same id.
> > > > >
> > > > > Do you mean after my patches or even before?
> > > >
> > > > Ah, sorry for confusion.
> > > >
> > > > Before. And after. IOW, I think this has nothing to do with your patches.
> > > >
> > >
> > > Hmm, you mean following patch is needed ?
> > >
> > > Before release of timer id to idr pool, we should make sure
> > > do_schedule_next_timer() wont be called, or it could find another timer
> > > reusing the just released id.
> >
> > I don't see how that makes it sure. If the signal is queued, then it
> > stays queued and the put_pid() has no effect either.
> 
> Yes.
> 
> But "If the signal is queued" is simple, in this case we could, say,
> do "tmr->sigq->info.si_tid = -1" to ensure lock_timer()->find_idr()
> can't succeed after dequeue_signal().
> 
> The problem is, it can be already dequeued.

Right, but we can solve this by moving the whole detach code into rcu.

Subject: posix-timer-fix-detach-race.patch
From: Thomas Gleixner <tglx@linutronix.de>
Date: Tue, 06 Sep 2011 21:08:06 +0200

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/posix-timers.c |   26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

Index: linux-2.6/kernel/posix-timers.c
===================================================================
--- linux-2.6.orig/kernel/posix-timers.c
+++ linux-2.6/kernel/posix-timers.c
@@ -495,22 +495,30 @@ static void k_itimer_rcu_free(struct rcu
 {
 	struct k_itimer *tmr = container_of(head, struct k_itimer, it.rcu);
 
+	put_pid(tmr->it_pid);
+	sigqueue_free(tmr->sigq);
 	kmem_cache_free(posix_timers_cache, tmr);
 }
 
+static void k_itimer_rcu_free_idr(struct rcu_head *head)
+{
+	struct k_itimer *tmr = container_of(head, struct k_itimer, it.rcu);
+	unsigned long flags;
+
+	spin_lock_irqsave(&idr_lock, flags);
+	idr_remove(&posix_timers_id, tmr->it_id);
+	spin_unlock_irqrestore(&idr_lock, flags);
+	k_itimer_rcu_free(head);
+}
+
 #define IT_ID_SET	1
 #define IT_ID_NOT_SET	0
 static void release_posix_timer(struct k_itimer *tmr, int it_id_set)
 {
-	if (it_id_set) {
-		unsigned long flags;
-		spin_lock_irqsave(&idr_lock, flags);
-		idr_remove(&posix_timers_id, tmr->it_id);
-		spin_unlock_irqrestore(&idr_lock, flags);
-	}
-	put_pid(tmr->it_pid);
-	sigqueue_free(tmr->sigq);
-	call_rcu(&tmr->it.rcu, k_itimer_rcu_free);
+	if (it_id_set)
+		call_rcu(&tmr->it.rcu, k_itimer_rcu_free_idr);
+	else
+		call_rcu(&tmr->it.rcu, k_itimer_rcu_free);
 }
 
 static struct k_clock *clockid_to_kclock(const clockid_t id)

  reply	other threads:[~2011-09-06 19:17 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-29 23:39 [PATCH 1/4] posix-timers: move global timer id management to signal_struct v2 Andi Kleen
2011-08-29 23:39 ` [PATCH 2/4] posix-timers: limit the number of posix timers per process Andi Kleen
2011-08-30 21:44   ` Andrew Morton
2011-08-30 22:06     ` Andi Kleen
2011-08-30 22:22       ` Andrew Morton
2011-08-30 22:47         ` Andi Kleen
2011-08-30 23:02           ` Andrew Morton
2011-08-31  6:45             ` Jiri Slaby
2011-09-02  9:30   ` Thomas Gleixner
2011-08-29 23:39 ` [PATCH 3/4] posix-timers: Don't disable interrupts in idr_lock Andi Kleen
2011-08-29 23:39 ` [PATCH 4/4] posix-timers: turn it_signal into it_valid flag Andi Kleen
2011-09-02 10:06   ` Thomas Gleixner
2011-09-02 11:49     ` Eric Dumazet
2011-09-02 14:19       ` Thomas Gleixner
2011-09-04 16:56     ` Oleg Nesterov
2011-09-04 19:07       ` Andi Kleen
2011-09-04 20:29       ` Oleg Nesterov
2011-09-06  3:14         ` Andi Kleen
2011-09-06 14:51           ` Oleg Nesterov
2011-09-06 15:39             ` Eric Dumazet
2011-09-06 16:27               ` Oleg Nesterov
2011-09-06 18:47               ` Thomas Gleixner
2011-09-06 18:49                 ` Oleg Nesterov
2011-09-06 19:16                   ` Thomas Gleixner [this message]
2011-09-06 19:26                     ` Oleg Nesterov
2011-09-06 19:45                       ` Thomas Gleixner
2011-09-06 22:08                         ` Oleg Nesterov
2011-09-06 22:34                           ` Thomas Gleixner
2011-09-21 16:46                           ` Thomas Gleixner
2011-09-21 17:56                             ` Thomas Gleixner
2011-09-22 11:19                               ` Thomas Gleixner
2011-09-06 19:30                     ` Eric Dumazet
2011-09-06 20:10                       ` Thomas Gleixner
2011-09-06 20:27                         ` Eric Dumazet
2011-09-06 19:04                 ` Eric Dumazet
2011-08-31  8:53 ` [PATCH 1/4] posix-timers: move global timer id management to signal_struct v2 Eric Dumazet
2011-08-31 16:57   ` Andi Kleen
2011-09-02  9:19 ` Thomas Gleixner
2011-09-02 10:05   ` Eric Dumazet
2011-09-19 21:46   ` Andi Kleen

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=alpine.LFD.2.02.1109062110090.2723@ionos \
    --to=tglx@linutronix.de \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    /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

Powered by JetHome