All of lore.kernel.org
 help / color / mirror / Atom feed
* race in timerobj
@ 2020-12-01 10:26 Ronny Meeus
  2020-12-01 11:06 ` Jan Kiszka
  0 siblings, 1 reply; 14+ messages in thread
From: Ronny Meeus @ 2020-12-01 10:26 UTC (permalink / raw)
  To: xenomai

Hello Xenomai community,

it looks like we have a race condition in the timer object handling.
The scope of the below mentioned issue is the alarm interface of the
alchemy skin:
int rt_alarm_start(RT_ALARM *alarm, RTIME value, RTIME interval)

The documentation mentions that this start can be called also on an
already running timer:
"This service overrides any previous setup of the expiry date and
reload interval for the given alarm."

In the timer server code (see file lib/copperplate/timerobj.c):
static void *timerobj_server (void *arg))
I see the timer being re-inserted in the timeout list in case of a
periodic timer.

write_lock_nocancel(&svlock);
...
if (interval.tv_sec > 0 || interval.tv_nsec > 0) {
  timespec_add(&tmobj->itspec.it_value, &value, &interval);
  timerobj_enqueue(tmobj);
}
write_unlock(&svlock);
tmobj->handler(tmobj);
write_lock_nocancel(&svlock);
}

This re-insert is done with the svlock taken but the timer specific
lock is not taken.

In the start on the other hand I see:

int timerobj_start(struct timerobj *tmobj,
  void (*handler)(struct timerobj *tmobj),
  struct itimerspec *it) /* lock held, dropped */
{
tmobj->handler = handler;
tmobj->itspec = *it;
...
write_lock_nocancel(&svlock);

So the itspec is updated with only the timerobj lock taken.
If the timeout value is changed via the timerobj_start while the timer is
under processing by the timer server, we can enter an endless loop (at
least that is what we see sporadically)

Does this make sense?

Best regards,
Ronny


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-01-25 15:56 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01 10:26 race in timerobj Ronny Meeus
2020-12-01 11:06 ` Jan Kiszka
2020-12-01 12:08   ` Ronny Meeus
2020-12-01 13:51     ` Philippe Gerum
2020-12-04 10:41       ` Ronny Meeus
2020-12-04 15:29         ` Philippe Gerum
2021-01-22  7:57           ` Ronny Meeus
2021-01-23  7:40             ` Ronny Meeus
2021-01-25  6:49               ` Jan Kiszka
2021-01-25 14:27                 ` Ronny Meeus
2021-01-25 14:36                   ` Jan Kiszka
2021-01-25 15:10                     ` Ronny Meeus
2021-01-25 15:26                       ` Jan Kiszka
2021-01-25 15:56                       ` Philippe Gerum

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.