From: Anton Ivanov <aivanov@brocade.com>
To: user-mode-linux-devel@lists.sourceforge.net
Cc: Anton Ivanov <aivanov@brocade.com>
Subject: [uml-devel] [PATCH 1/3] IRQ Reentrancy guard
Date: Fri, 20 Nov 2015 16:45:13 +0000 [thread overview]
Message-ID: <1448037915-921549-1-git-send-email-aivanov@brocade.com> (raw)
Fixes: IRQ Reentrancy
The code in signal.c used in irq controller emulation does not
prevent IRQ reentrancy which can result in all types of issues
as IRQs including ones on the same device can be executed in
a nested manner
Signed-off-by: Anton Ivanov <aivanov@brocade.com>
---
arch/um/kernel/irq.c | 8 ++++++++
arch/um/os-Linux/signal.c | 15 ++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/arch/um/kernel/irq.c b/arch/um/kernel/irq.c
index 23cb935..4813263 100644
--- a/arch/um/kernel/irq.c
+++ b/arch/um/kernel/irq.c
@@ -30,11 +30,17 @@ static struct irq_fd **last_irq_ptr = &active_fds;
extern void free_irqs(void);
+static int in_poll_handler = 0;
+
void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
{
struct irq_fd *irq_fd;
int n;
+ WARN_ON_ONCE(in_poll_handler == 1);
+
+ in_poll_handler = 1;
+
while (1) {
n = os_waiting_for_events(active_fds);
if (n <= 0) {
@@ -52,6 +58,8 @@ void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs)
}
}
+ in_poll_handler = 0;
+
free_irqs();
}
diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c
index c211153..9aa7097 100644
--- a/arch/um/os-Linux/signal.c
+++ b/arch/um/os-Linux/signal.c
@@ -27,6 +27,8 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *) = {
[SIGALRM] = timer_handler
};
+static int irq_guard = 0;
+
static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
{
struct uml_pt_regs r;
@@ -40,11 +42,17 @@ static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
}
/* enable signals if sig isn't IRQ signal */
- if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGALRM))
+ if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGALRM)) {
unblock_signals();
+ } else {
+ irq_guard = 1;
+ }
(*sig_info[sig])(sig, si, &r);
+ if (!((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGALRM)))
+ irq_guard = 0;
+
errno = save_errno;
}
@@ -86,7 +94,9 @@ static void timer_real_alarm_handler(mcontext_t *mc)
if (mc != NULL)
get_regs_from_mc(®s, mc);
+ irq_guard = 1;
timer_handler(SIGALRM, NULL, ®s);
+ irq_guard = 0;
}
void timer_alarm_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
@@ -243,6 +253,9 @@ void unblock_signals(void)
if (signals_enabled == 1)
return;
+ if (irq_guard == 1)
+ return;
+
/*
* We loop because the IRQ handler returns with interrupts off. So,
* interrupts may have arrived and we need to re-enable them and
--
2.1.4
------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
next reply other threads:[~2015-11-20 16:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 16:45 Anton Ivanov [this message]
2015-11-20 16:45 ` [uml-devel] [PATCH 2/3] Errata: HR Timer subsystem Anton Ivanov
2015-11-20 18:12 ` Anton Ivanov
2015-11-20 16:45 ` [uml-devel] [PATCH 3/3] Signal handling cleanup Anton Ivanov
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=1448037915-921549-1-git-send-email-aivanov@brocade.com \
--to=aivanov@brocade.com \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).