All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] [PATCH 1/3] IRQ Reentrancy guard
@ 2015-11-20 16:45 Anton Ivanov
  2015-11-20 16:45 ` [uml-devel] [PATCH 2/3] Errata: HR Timer subsystem Anton Ivanov
  2015-11-20 16:45 ` [uml-devel] [PATCH 3/3] Signal handling cleanup Anton Ivanov
  0 siblings, 2 replies; 4+ messages in thread
From: Anton Ivanov @ 2015-11-20 16:45 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Anton Ivanov

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(&regs, mc);
+	irq_guard = 1;
 	timer_handler(SIGALRM, NULL, &regs);
+	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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-20 18:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-20 16:45 [uml-devel] [PATCH 1/3] IRQ Reentrancy guard Anton Ivanov
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

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.