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 <aiva...@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