From: Jan Kiszka <jan.kiszka@domain.hid>
To: Philippe Gerum <rpm@xenomai.org>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] kernel oopses when killing realtime task
Date: Thu, 28 Oct 2010 09:38:30 +0200 [thread overview]
Message-ID: <4CC92876.1050608@domain.hid> (raw)
In-Reply-To: <4CC926BE.7040105@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 3780 bytes --]
Am 28.10.2010 09:31, Jan Kiszka wrote:
> This sounds like it's best discussed based on patches.
>
BTW, this is my current idea to make deregistration via
ipipe_virtualize_irq safe against ongoing IRQs, ie. the risk to invoke
a NULL handler:
From: Jan Kiszka <jan.kiszka@domain.hid>
ipipe: Catch ongoing IRQs while deregistering from the line
If ipipe_virtualize_irq is called for an IRQ that may be under
processing on a different CPU, we must not clear the handler to avoid
NULL pointer failures. However, this IRQ-on-the-fly already became
spurious before the caller invoked ipipe_virtualize_irq. So install a
dummy handler that swallows the event silently.
Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---
kernel/ipipe/core.c | 30 ++++++++++++++++++++++++------
1 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/kernel/ipipe/core.c b/kernel/ipipe/core.c
index b3a8139..bf43bb8 100644
--- a/kernel/ipipe/core.c
+++ b/kernel/ipipe/core.c
@@ -277,6 +277,18 @@ void __init ipipe_init(void)
IPIPE_VERSION_STRING);
}
+static void ipipe_final_irq_handler(unsigned irq, struct irq_desc *desc)
+{
+ /*
+ * De-virtualization of an IRQ may race with ongoing IRQ delivery on a
+ * different CPU. This handler catches the delivery and ends the
+ * request. It is assumed to be the final event as the caller of
+ * ipipe_virtualize_irq() is supposed to have disabled any related IRQ
+ * source at device level before deregistering the interrupt.
+ */
+ desc->ipipe_end(irq, desc);
+}
+
void __ipipe_init_stage(struct ipipe_domain *ipd)
{
struct ipipe_percpu_domain_data *p;
@@ -292,7 +304,7 @@ void __ipipe_init_stage(struct ipipe_domain *ipd)
for (n = 0; n < IPIPE_NR_IRQS; n++) {
ipd->irqs[n].acknowledge = NULL;
- ipd->irqs[n].handler = NULL;
+ ipd->irqs[n].handler = ipipe_final_irq_handler;
ipd->irqs[n].control = IPIPE_PASS_MASK; /* Pass but don't handle */
}
@@ -924,14 +936,20 @@ int ipipe_virtualize_irq(struct ipipe_domain *ipd,
~(IPIPE_HANDLE_MASK | IPIPE_STICKY_MASK |
IPIPE_EXCLUSIVE_MASK | IPIPE_WIRED_MASK);
- ipd->irqs[irq].handler = NULL;
+ ipd->irqs[irq].handler = ipipe_final_irq_handler;
+ /*
+ * Make sure we never call the old handler with an invalid
+ * cookie. The dummy handler ignores the cookie. Set it first.
+ */
+ smp_mb();
ipd->irqs[irq].cookie = NULL;
- ipd->irqs[irq].acknowledge = NULL;
+ ipd->irqs[irq].acknowledge =
+ ipipe_root_domain->irqs[irq].acknowledge;
ipd->irqs[irq].control = modemask;
if (irq < NR_IRQS && !ipipe_virtual_irq_p(irq)) {
desc = irq_to_desc(irq);
- if (old_handler && desc)
+ if (old_handler != ipipe_final_irq_handler && desc)
__ipipe_disable_irqdesc(ipd, irq);
}
@@ -941,7 +959,7 @@ int ipipe_virtualize_irq(struct ipipe_domain *ipd,
if (handler == IPIPE_SAME_HANDLER) {
cookie = ipd->irqs[irq].cookie;
handler = old_handler;
- if (handler == NULL) {
+ if (handler == ipipe_final_irq_handler) {
ret = -EINVAL;
goto unlock_and_exit;
}
@@ -1024,7 +1042,7 @@ int ipipe_control_irq(struct ipipe_domain *ipd, unsigned int irq,
goto out;
}
- if (ipd->irqs[irq].handler == NULL)
+ if (ipd->irqs[irq].handler == ipipe_final_irq_handler)
setmask &= ~(IPIPE_HANDLE_MASK | IPIPE_STICKY_MASK);
if ((setmask & IPIPE_STICKY_MASK) != 0)
--
1.7.1
I'm not your 100% happy with the fact that the old acknowledge handler
may be paired with ipipe_finale_irq_handler this way, but I see no
better approach so far.
So this patch just had to be paired with a barrier after the
deregistration (in Xenomai) to ensure all users of the old handlers and
cookies are done.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
next prev parent reply other threads:[~2010-10-28 7:38 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-07 11:57 [Xenomai-help] kernel oopses when killing realtime task Pavel Machek
2010-10-07 12:11 ` Gilles Chanteperdrix
2010-10-07 13:00 ` Gilles Chanteperdrix
2010-10-07 12:32 ` Jan Kiszka
2010-10-08 7:01 ` Pavel Machek
2010-10-08 7:20 ` Gilles Chanteperdrix
2010-10-08 8:17 ` Philippe Gerum
2010-10-08 8:41 ` Jan Kiszka
2010-10-08 8:57 ` Philippe Gerum
2010-10-08 9:00 ` Philippe Gerum
2010-10-08 9:41 ` Philippe Gerum
2010-10-13 9:03 ` Pavel Machek
2010-10-13 9:16 ` Philippe Gerum
2010-10-13 9:26 ` Pavel Machek
2010-10-13 14:52 ` Philippe Gerum
2010-10-25 16:48 ` Philippe Gerum
2010-10-25 18:10 ` Jan Kiszka
2010-10-25 19:08 ` Philippe Gerum
2010-10-25 19:11 ` Philippe Gerum
2010-10-25 19:15 ` Jan Kiszka
2010-10-25 19:20 ` Philippe Gerum
2010-10-25 19:22 ` Jan Kiszka
2010-10-25 21:12 ` Philippe Gerum
2010-10-25 21:22 ` Jan Kiszka
2010-10-25 21:40 ` Philippe Gerum
2010-10-25 21:47 ` Jan Kiszka
2010-10-26 4:43 ` Philippe Gerum
2010-10-26 5:22 ` Jan Kiszka
2010-10-26 19:33 ` Jan Kiszka
2010-10-28 5:17 ` Philippe Gerum
2010-10-28 7:31 ` Jan Kiszka
2010-10-28 7:38 ` Jan Kiszka [this message]
2010-10-28 7:46 ` Philippe Gerum
2010-11-07 15:15 ` Philippe Gerum
2010-11-07 16:22 ` Jan Kiszka
2010-11-07 16:55 ` Philippe Gerum
2010-11-07 16:59 ` Philippe Gerum
2010-11-07 17:19 ` Philippe Gerum
2010-11-09 8:01 ` Jan Kiszka
2010-11-09 8:26 ` Philippe Gerum
2010-11-09 8:39 ` Jan Kiszka
2010-11-09 9:36 ` Philippe Gerum
2010-11-09 13:12 ` Jan Kiszka
2010-11-12 8:48 ` Philippe Gerum
2010-11-12 9:14 ` Jan Kiszka
2010-11-12 13:57 ` Philippe Gerum
2010-11-12 14:30 ` Jan Kiszka
2010-11-12 17:42 ` Philippe Gerum
2010-11-12 18:42 ` Jan Kiszka
2010-11-14 21:28 ` Philippe Gerum
2010-10-07 14:07 ` 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=4CC92876.1050608@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=rpm@xenomai.org \
--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.