All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Jan Kiszka <jan.kiszka@domain.hid>
Cc: Xenomai-core@domain.hid
Subject: Re: [Xenomai-core] Racy pse51_mutex_check_init?
Date: Sat, 23 Aug 2008 13:24:25 +0200	[thread overview]
Message-ID: <48AFF369.2080208@domain.hid> (raw)
In-Reply-To: <48AFEF1B.8040508@domain.hid>

Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
>> Gilles Chanteperdrix wrote:
>>> Jan Kiszka wrote:
>>>> Gilles Chanteperdrix wrote:
>>>>> Jan Kiszka wrote:
>>>>>> Hi Gilles,
>>>>>>
>>>>>> trying to understand the cb_read/write lock usage, some question came up
>>>>>> here: What prevents that the mutexq iteration in pse51_mutex_check_init
>>>>>> races against pse51_mutex_destroy_internal?
>>>>>>
>>>>>> If nothing, then I wonder if we actually have to iterate over the whole
>>>>>> queue to find out whether a given object has been initialized and
>>>>>> registered already or not. Can't this be encoded differently?
>>>>> We actually iterate over the queue only if the magic happens to be
>>>>> correct, which is not the common case.
>>>> However, there remains a race window with other threads removing other
>>>> mutex objects in parallel, changing the queue - risking a kernel oops.
>>>> And that is what worries me. It's unlikely. but possible. It's unclean.
>>> Ok. This used to be protected by the nklock. We should add the nklock again.
>> Well I do not think that anyone is rescheduling, so we could probably
>> replace the nklock with a per-kqueue xnlock.
> 
> If nklock or per queue - both will introduce O(n) at least local
> preemption blocking. That's why I was asking for an alternative
> algorithm than iterating over the whole list.

I insist:
- the loop does almost nothing, so n will have to become very large for
it to take a long time, and n is the number of mutexes allocated so far
in one application, or the number of shared mutexes, which is probably
even less.
- the loop happens if the magic happens to be good, so probably only if
you are calling pthread_mutex_init twice for the same mutex, the normal
use-case is to use memory from BSS to allocate mutex, so the magic of a
normal application calling pthread_mutex_init is always 0, and you do
not enter the loop.

Today, I consider it much more a problem that I can not call fork in a
xenomai application with opened descriptors and exit the parent
application without the file descriptors being closed in the child too.
And this will be the thing I will spend time to fix first. Using the
registry in the posix skin will only come next.

-- 
					    Gilles.


      reply	other threads:[~2008-08-23 11:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-23  8:33 [Xenomai-core] Racy pse51_mutex_check_init? Jan Kiszka
2008-08-23 10:21 ` Gilles Chanteperdrix
2008-08-23 10:34   ` Gilles Chanteperdrix
2008-08-23 10:53   ` Philippe Gerum
2008-08-23 11:07     ` Gilles Chanteperdrix
2008-08-23 11:13       ` Philippe Gerum
2008-08-23 11:16       ` Philippe Gerum
2008-08-23 11:31         ` Gilles Chanteperdrix
2008-08-23 11:31       ` Jan Kiszka
2008-08-23 11:33         ` Gilles Chanteperdrix
2008-08-23 10:43 ` Gilles Chanteperdrix
2008-08-23 10:51   ` Jan Kiszka
2008-08-23 10:58     ` Gilles Chanteperdrix
2008-08-23 11:02       ` Gilles Chanteperdrix
2008-08-23 11:06         ` Jan Kiszka
2008-08-23 11:24           ` Gilles Chanteperdrix [this message]

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=48AFF369.2080208@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=Xenomai-core@domain.hid \
    --cc=jan.kiszka@domain.hid \
    /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.