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: Thomas Wiedemann <Thomas.Wiedemann@domain.hid>, xenomai@xenomai.org
Subject: Re: [Xenomai-core] [BUG] module usage counter of xenomai	native	corrupted (version 2.2.0 and 2.2.5)
Date: Fri, 08 Dec 2006 14:27:29 +0100	[thread overview]
Message-ID: <45796841.4040106@domain.hid> (raw)
In-Reply-To: <457956F3.6090904@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 2423 bytes --]

Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
> 
>>Gilles Chanteperdrix wrote:
>>
>>>Jan Kiszka wrote:
>>>
>>>
>>>>Thomas Wiedemann wrote:
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>there seems to be a bug in rt_task_create(). When no more memory is
>>>>>available, the module usage counter of xeno_native is decremented. I
>>>>>guess it is not incremented before, however, so the counter gets 0 and
>>>>>wraps then to a negative number. It is therefore not possible to remove
>>>>>the module.
>>>>>
>>>>>I appended a small program to demonstrate this. It simply eats up all
>>>>>memory from xenomai by registering as much mutexes as possible,
>>>>>and then tries to execute rt_task_create(), which fails. When started
>>>>>again, the bug occurs at rt_task_shadow(), as the mutexes have never
>>>>>been deleted.
>>>>>Compile with  gcc -O2 -Wall `xeno-config --xeno-cflags` `xeno-config
>>>>>--xeno-ldflags` -lrtdm -lnative -o rttest rttest.c
>>>>>then simply run it, and watch the output of lsmod before and after.
>>>>>
>>>>>Tested with xenomai 2.2.{0,5} and linux 2.6.17.8, modules loaded:
>>>>>xeno_native and xeno_nucleus.
>>>>>
>>>>
>>>>Confirmed. Requires a closer look to find the leak path.
>>>
>>>Here is what happens: the task is created with the XNSHADOW bit, and
>>>destroyed before it was xnshadow_mapped, but the deletion hook calls
>>>xnshadow_unmap because the task has the XNSHADOW bit. And xnshadow_unmap
>>> decrements the module count.
>>
>>Here is an untested quick fix.
>>
>>
>>
>>------------------------------------------------------------------------
>>
>>Index: ksrc/nucleus/shadow.c
>>===================================================================
>>--- ksrc/nucleus/shadow.c	(révision 1930)
>>+++ ksrc/nucleus/shadow.c	(copie de travail)
>>@@ -888,6 +888,9 @@
>> 
>> 	p = xnthread_archtcb(thread)->user_task;	/* May be != current */
>> 
>>+	if (!xnshadow_thrptd(p))
>>+		return;
>>+
>> 	magic = xnthread_get_magic(thread);
>> 
>> 	for (muxid = 0; muxid < XENOMAI_MUX_NR; muxid++) {
> 
> 
> Nope, shows unwanted side effects, probably because xnshadow_thrptd is
> already NULL'ed in do_taskexit_event. Looks like it takes an extra flag, no?

Setting xnshadow_thrptd to NULL in do_taskexit_event does not seem to be
 that useful. Here comes version 2.

-- 
                                                 Gilles Chanteperdrix

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xeno-avoid-unmapping-not-yet-mapped-shadow.2.diff --]
[-- Type: text/x-patch; name="xeno-avoid-unmapping-not-yet-mapped-shadow.2.diff", Size: 728 bytes --]

Index: ksrc/nucleus/shadow.c
===================================================================
--- ksrc/nucleus/shadow.c	(révision 1930)
+++ ksrc/nucleus/shadow.c	(copie de travail)
@@ -888,6 +888,9 @@
 
 	p = xnthread_archtcb(thread)->user_task;	/* May be != current */
 
+	if (!xnshadow_thrptd(p))
+		return;
+
 	magic = xnthread_get_magic(thread);
 
 	for (muxid = 0; muxid < XENOMAI_MUX_NR; muxid++) {
@@ -1639,8 +1642,6 @@
 		xnshadow_relax(0);
 
 	xnlock_get_irqsave(&nklock, s);
-	/* Prevent wakeup call from xnshadow_unmap(). */
-	xnshadow_thrptd(p) = NULL;
 	xnthread_archtcb(thread)->user_task = NULL;
 	/* xnpod_delete_thread() -> hook -> xnshadow_unmap(). */
 	xnpod_delete_thread(thread);

  reply	other threads:[~2006-12-08 13:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-07 13:09 [Xenomai-core] [BUG] module usage counter of xenomai native corrupted (version 2.2.0 and 2.2.5) Thomas Wiedemann
2006-12-07 14:35 ` Jan Kiszka
2006-12-08  8:38   ` Gilles Chanteperdrix
2006-12-08 10:03     ` Gilles Chanteperdrix
2006-12-08 12:13       ` Jan Kiszka
2006-12-08 13:27         ` Gilles Chanteperdrix [this message]
2006-12-08 14:54           ` Jan Kiszka
2006-12-08 18:02             ` Gilles Chanteperdrix
2006-12-08 18:22               ` Philippe Gerum
2006-12-08 19:05                 ` Jan Kiszka
2006-12-08 21:35                   ` Philippe Gerum
2006-12-11 18:06                     ` Philippe Gerum

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=45796841.4040106@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=Thomas.Wiedemann@domain.hid \
    --cc=jan.kiszka@domain.hid \
    --cc=xenomai@xenomai.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 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.