From: Marcus Gelderie <redmnic@gmail.com>
To: john.stultz@linaro.org
Cc: linux-kernel@vger.kernel.org
Subject: Race condition in time/alarmtimer.c
Date: Mon, 24 Jun 2013 21:12:03 +0200 [thread overview]
Message-ID: <20130624191202.GA22643@cantor.Speedport_W_503V_Typ_C> (raw)
Hi,
there seems to be a race condition in kernel/time/alarmtimer.c
More specifically, the following function (line numbers correspond to actual file):
584 static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp)
585 {
586 alarm->data = (void *)current;
587 do {
588 set_current_state(TASK_INTERRUPTIBLE);
589 alarm_start(alarm, absexp);
590 if (likely(alarm->data))
591 schedule();
592
593 alarm_cancel(alarm);
594 } while (alarm->data && !signal_pending(current));
595
596 __set_current_state(TASK_RUNNING);
597
598 return (alarm->data == NULL);
599 }
has a race: If the task is preempted after set_current_state(TASK_INTERRUPTIBLE)
but before the alarm is started in the next line, the task never wakes up.
Swapping both lines is not an option either, because then the alarm might trigger before
the thread sets itself to TASK_INTERRUPTIBLE, thereby loosing the wakeup.
A spinlock would disable preemption and protect alarm->data against the race from another CPU.
We could wrap lines 588 and 589 with a spin lock. Then the wakeup code would also aquire the
lock, of course. The lock could be attached to struct alarm.
An alternative would be a waitqueue, of course.
If folks agree with me, I will provide a patch.
Cheers
Marcus
next reply other threads:[~2013-06-24 19:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-24 19:12 Marcus Gelderie [this message]
2013-06-29 13:47 ` Marcus Gelderie
2013-07-22 19:04 ` John Stultz
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=20130624191202.GA22643@cantor.Speedport_W_503V_Typ_C \
--to=redmnic@gmail.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®