From: Jan Kiszka <jan.kiszka@domain.hid>
To: Dmitry Adamushko <dmitry.adamushko@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] [BUG] racy xnshadow_harden under CONFIG_PREEMPT
Date: Tue, 24 Jan 2006 14:26:31 +0100 [thread overview]
Message-ID: <43D62B07.3030703@domain.hid> (raw)
In-Reply-To: <b647ffbd0601240514m11a11a64u@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 3246 bytes --]
Dmitry Adamushko wrote:
> On 23/01/06, Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org> wrote:
>> Jeroen Van den Keybus wrote:
>>> Hello,
>
>
>
>> [ skip-skip-skip ]
>>
>
>
>> Since in xnshadow_harden, the running thread marks itself as suspended
>> before running wake_up_interruptible_sync, the gatekeeper will run when
>> schedule() get called, which in turn, depend on the CONFIG_PREEMPT*
>> configuration. In the non-preempt case, the current thread will be
>> suspended and the gatekeeper will run when schedule() is explicitely
>> called in xnshadow_harden(). In the preempt case, schedule gets called
>> when the outermost spinlock is unlocked in wake_up_interruptible_sync().
>
>
> In fact, no.
>
> wake_up_interruptible_sync() doesn't set the need_resched "flag" up. That's
> why it's "sync" actually.
>
> Only if the need_resched was already set before calling
> wake_up_interruptible_sync(), then yes.
>
> The secuence is as follows :
>
> wake_up_interruptible_sync ---> wake_up_sync ---> wake_up_common(...,
> sync=1, ...) ---> ... ---> try_to_wake_up(..., sync=1)
>
> Look at the end of try_to_wake_up() to see when it calls resched_task().
> The comment there speaks for itself.
>
> So let's suppose need_resched == 0 (it's per-task of course).
> As a result of wake_up_interruptible_sync() the new task is added to the
> current active run-queue but need_resched remains to be unset in the hope
> that the waker will call schedule() on its own soon.
>
> I have CONFIG_PREEMPT set on my machine but I have never encountered a bug
> described by Jan.
>
> The catalyst of the problem, I guess, is that some IRQ interrupts a task
> between wake_up_interruptible_sync() and schedule() and its ISR, in turn,
> wakes up another task which prio is higher than the one of our waker (as a
> result, the need_resched flag is set). And now, rescheduling occurs on
> return from irq handling code (ret_from_intr -> ...-> preempt_irq_schedule()
> -> schedule()).
Yes, this is exactly what happened. I unfortunately have not saved a
related trace I took with the extended ipipe-tracer (the one I sent ends
too early), but they showed a preemption right after the wake_up, first
by one of the other real-time threads in Jeroen's scenario, and then, as
a result of some xnshadow_relax() of that thread, a Linux
preempt_schedule to the gatekeeper. We do not see this bug that often as
it requires a specific load and it must hit a really small race window.
>
> Some events should coincide, yep. But I guess that problem does not occur
> every time?
>
> I have not checked it yet but my presupposition that something as easy as :
>
> preempt_disable()
>
> wake_up_interruptible_sync();
> schedule();
>
> preempt_enable();
It's a no-go: "scheduling while atomic". One of my first attempts to
solve it.
The only way to enter schedule() without being preemptible is via
ACTIVE_PREEMPT. But the effect of that flag should be well-known now.
Kind of Gordian knot. :(
>
>
> could work... err.. and don't blame me if no, it's some one else who has
> written that nonsense :o)
>
> --
> Best regards,
> Dmitry Adamushko
>
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
next prev parent reply other threads:[~2006-01-24 13:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-21 10:47 [Xenomai-core] [BUG] racy xnshadow_harden under CONFIG_PREEMPT Jan Kiszka
2006-01-21 10:51 ` [Xenomai-core] " Jeroen Van den Keybus
2006-01-21 16:47 ` [Xenomai-core] " Hannes Mayer
2006-01-21 17:01 ` Jan Kiszka
2006-01-22 8:10 ` Dmitry Adamushko
2006-01-22 16:19 ` Jeroen Van den Keybus
2006-01-23 18:22 ` Gilles Chanteperdrix
2006-01-23 19:16 ` Jan Kiszka
2006-01-30 14:51 ` Philippe Gerum
2006-01-30 15:33 ` Philippe Gerum
2006-01-30 16:01 ` Jan Kiszka
2006-01-30 23:10 ` Philippe Gerum
2006-01-31 19:01 ` Jan Kiszka
2006-01-30 15:35 ` Philippe Gerum
2006-01-31 21:09 ` Jeroen Van den Keybus
2006-01-31 21:45 ` Philippe Gerum
2006-02-01 9:57 ` Jeroen Van den Keybus
2006-02-01 10:03 ` Jan Kiszka
2006-02-01 12:23 ` Jeroen Van den Keybus
2006-02-01 12:34 ` Jan Kiszka
2006-01-24 13:14 ` Dmitry Adamushko
2006-01-24 13:26 ` Jan Kiszka [this message]
2006-01-30 11:37 ` Dmitry Adamushko
2006-01-30 11:48 ` Jan Kiszka
2006-01-30 13:02 ` Dmitry Adamushko
2006-01-29 23:48 ` Philippe Gerum
2006-01-30 10:14 ` 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=43D62B07.3030703@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=dmitry.adamushko@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.