All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>
To: Marcus Gelderie <redmnic@gmail.com>
Cc: artem.bityutskiy@linux.intel.com, herbert@gondor.hengli.com.au,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernel:time fix race condition in alaramtimer.c
Date: Mon, 08 Jul 2013 11:01:49 +0530	[thread overview]
Message-ID: <51DA4EC5.10707@linux.vnet.ibm.com> (raw)
In-Reply-To: <1373126870-17978-1-git-send-email-redmnic@gmail.com>

On 07/06/2013 09:37 PM, Marcus Gelderie wrote:
> This patch fixes a race condition whereby the process can be caused to
> sleep indefinitely. The problem occurs when the process is preempted
> after having set its state to TASK_INTERRUPTIBLE but before starting the
> alarm.
> 

I don't think there is any such problem. The __schedule() function does
this check before dequeuing a task:

if (prev->state && !(preempt_count() & PREEMPT_ACTIVE))

The latter part helps prevent the kind of indefinite sleeping you described
above. Also, take a look at preempt_schedule(), preempt_schedule_irq()
and friends to see how in-kernel preemption is dealt with, by using
PREEMPT_ACTIVE. That would clarify why there is no bug here.

Regards,
Srivatsa S. Bhat

> ---
>  kernel/time/alarmtimer.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
> index f11d83b..81c8b31 100644
> --- a/kernel/time/alarmtimer.c
> +++ b/kernel/time/alarmtimer.c
> @@ -585,15 +585,19 @@ static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp)
>  {
>  	alarm->data = (void *)current;
>  	do {
> +		preempt_disable();
>  		set_current_state(TASK_INTERRUPTIBLE);
>  		alarm_start(alarm, absexp);
> +		preempt_enable_no_resched();
>  		if (likely(alarm->data))
>  			schedule();
> 
> +		preempt_disable();
>  		alarm_cancel(alarm);
> +		__set_current_state(TASK_RUNNING);
> +		preempt_enable_no_resched();
>  	} while (alarm->data && !signal_pending(current));
> 
> -	__set_current_state(TASK_RUNNING);
> 
>  	return (alarm->data == NULL);
>  }
> 


  reply	other threads:[~2013-07-08  5:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-06 16:07 [PATCH] kernel:time fix race condition in alaramtimer.c Marcus Gelderie
2013-07-08  5:31 ` Srivatsa S. Bhat [this message]
2013-07-08  9:20   ` Marcus Gelderie

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=51DA4EC5.10707@linux.vnet.ibm.com \
    --to=srivatsa.bhat@linux.vnet.ibm.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=herbert@gondor.hengli.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=redmnic@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.