linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Andi Kleen <andi@firstfloor.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	eric.dumazet@gmail.com, Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH 4/4] posix-timers: turn it_signal into it_valid flag
Date: Sun, 4 Sep 2011 18:56:58 +0200	[thread overview]
Message-ID: <20110904165658.GA23948@redhat.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1109021135270.2723@ionos>

On 09/02, Thomas Gleixner wrote:
>
> On Mon, 29 Aug 2011, Andi Kleen wrote:
>
> > From: Andi Kleen <ak@linux.intel.com>
> >
> > Now that the timer IDR is per process we don't need to save
> > the signal_struct in the timer anymore. Still need this
> > as a flag for RCU, so turn it into a it_valid flag.
>
> That's wrong. it_signal is not necessary for RCU, it's necessary for
> protecting against a concurrent timer deletion.

The main reason for it_signal was the fact we use the global idr database,
we should check that the timer was created by us. But yes, another reason
was to check that the timer is "valid", we can race with create/delete.
See 27af4245.

> --- linux-2.6.orig/kernel/posix-timers.c
> +++ linux-2.6/kernel/posix-timers.c
> @@ -483,6 +483,7 @@ static struct k_itimer * alloc_posix_tim
>  	tmr = kmem_cache_zalloc(posix_timers_cache, GFP_KERNEL);
>  	if (!tmr)
>  		return tmr;
> +	INIT_LIST_HEAD(&tmr->list);
>  	if (unlikely(!(tmr->sigq = sigqueue_alloc()))) {
>  		kmem_cache_free(posix_timers_cache, tmr);
>  		return NULL;
> @@ -612,7 +613,6 @@ SYSCALL_DEFINE3(timer_create, const cloc
>  		goto out;
>
>  	spin_lock_irq(&current->sighand->siglock);
> -	new_timer->it_signal = current->signal;
>  	list_add(&new_timer->list, &current->signal->posix_timers);
>  	spin_unlock_irq(&current->sighand->siglock);
>
> @@ -643,7 +643,7 @@ static struct k_itimer *__lock_timer(tim
>  	timr = idr_find(&posix_timers_id, (int)timer_id);
>  	if (timr) {
>  		spin_lock_irqsave(&timr->it_lock, *flags);
> -		if (timr->it_signal == current->signal) {
> +		if (!list_empty(&timr->list)) {

looks correct at first glance....

The problem is, now that we have signal->posix_timers_id, we can kill
signal->posix_timers and k_itimer->list. Probably we can nullify
k_itimer->it_id to mark it as invalid before idr_remove. Although I
feel this all can be simplified even more.



And why do we need to add signal->idr_lock ? It is only used to
serialize idr_get/idr_remove. Probably we can use ->siglock for that,
posix timers use this lock anyway.

Also. I am not sure, but perhaps it make sense to turn
signal->posix_timers_id into the pointer to "struct idr" and allocate
idr on demand?

Oleg.


  parent reply	other threads:[~2011-09-04 17:00 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 [this message]
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
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=20110904165658.GA23948@redhat.com \
    --to=oleg@redhat.com \
    --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=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).