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

* [uml-devel] [PATCH 2/3] Errata: HR Timer subsystem
  2015-11-20 16:45 [uml-devel] [PATCH 1/3] IRQ Reentrancy guard Anton Ivanov
@ 2015-11-20 16:45 ` Anton Ivanov
  2015-11-20 18:12   ` Anton Ivanov
  2015-11-20 16:45 ` [uml-devel] [PATCH 3/3] Signal handling cleanup Anton Ivanov
  1 sibling, 1 reply; 4+ messages in thread
From: Anton Ivanov @ 2015-11-20 16:45 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Anton Ivanov

The signals should be restored to their pre-off state
not turned on.

Signed-off-by: Anton Ivanov <aivanov@brocade.com>
---
 arch/um/kernel/skas/mmu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
index 9591a66..a845de6 100644
--- a/arch/um/kernel/skas/mmu.c
+++ b/arch/um/kernel/skas/mmu.c
@@ -53,6 +53,7 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
 	struct mm_context *to_mm = &mm->context;
 	unsigned long stack = 0;
 	int ret = -ENOMEM;
+    unsigned long int flags;
 
 	stack = get_zeroed_page(GFP_KERNEL);
 	if (stack == 0)
@@ -62,12 +63,12 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
 	if (current->mm != NULL && current->mm != &init_mm)
 		from_mm = &current->mm->context;
 
-	block_signals();
+	local_irq_save(flags);
 	if (from_mm)
 		to_mm->id.u.pid = copy_context_skas0(stack,
 						     from_mm->id.u.pid);
 	else to_mm->id.u.pid = start_userspace(stack);
-	unblock_signals();
+    local_irq_restore(flags);
 
 	if (to_mm->id.u.pid < 0) {
 		ret = to_mm->id.u.pid;
-- 
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

* [uml-devel] [PATCH 3/3] Signal handling cleanup
  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 16:45 ` Anton Ivanov
  1 sibling, 0 replies; 4+ messages in thread
From: Anton Ivanov @ 2015-11-20 16:45 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Anton Ivanov

Fix signal handling to use store/restore instead of block/unblock
as that may cause IRQ reentrancy

Signed-off-by: Anton Ivanov <aivanov@brocade.com>
---
 arch/um/os-Linux/skas/process.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 13c5a2c..5916267 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -313,6 +313,7 @@ void userspace(struct uml_pt_regs *regs)
 	int err, status, op, pid = userspace_pid[0];
 	/* To prevent races if using_sysemu changes under us.*/
 	int local_using_sysemu;
+	unsigned long flags;
 	siginfo_t si;
 
 	/* Handle any immediate reschedules or signals */
@@ -396,9 +397,9 @@ void userspace(struct uml_pt_regs *regs)
 			case SIGBUS:
 			case SIGFPE:
 			case SIGWINCH:
-				block_signals();
+				flags = set_signals(0);
 				(*sig_info[sig])(sig, (struct siginfo *)&si, regs);
-				unblock_signals();
+				set_signals(flags);
 				break;
 			default:
 				printk(UM_KERN_ERR "userspace - child stopped "
@@ -586,15 +587,16 @@ int start_idle_thread(void *stack, jmp_buf *switch_buf)
 void initial_thread_cb_skas(void (*proc)(void *), void *arg)
 {
 	jmp_buf here;
+	unsigned long int flags;
 
 	cb_proc = proc;
 	cb_arg = arg;
 	cb_back = &here;
 
-	block_signals();
+	flags = set_signals(0);
 	if (UML_SETJMP(&here) == 0)
 		UML_LONGJMP(&initial_jmpbuf, INIT_JMP_CALLBACK);
-	unblock_signals();
+	set_signals(flags);
 
 	cb_proc = NULL;
 	cb_arg = NULL;
-- 
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

* Re: [uml-devel] [PATCH 2/3] Errata: HR Timer subsystem
  2015-11-20 16:45 ` [uml-devel] [PATCH 2/3] Errata: HR Timer subsystem Anton Ivanov
@ 2015-11-20 18:12   ` Anton Ivanov
  0 siblings, 0 replies; 4+ messages in thread
From: Anton Ivanov @ 2015-11-20 18:12 UTC (permalink / raw)
  To: user-mode-linux-devel

This one came up with a messed up formatting, I will resubmit at some 
point (hopefully as we refine this).

A.

On 20/11/15 16:45, Anton Ivanov wrote:
> The signals should be restored to their pre-off state
> not turned on.
>
> Signed-off-by: Anton Ivanov <aivanov@brocade.com>
> ---
>   arch/um/kernel/skas/mmu.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/um/kernel/skas/mmu.c b/arch/um/kernel/skas/mmu.c
> index 9591a66..a845de6 100644
> --- a/arch/um/kernel/skas/mmu.c
> +++ b/arch/um/kernel/skas/mmu.c
> @@ -53,6 +53,7 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
>   	struct mm_context *to_mm = &mm->context;
>   	unsigned long stack = 0;
>   	int ret = -ENOMEM;
> +    unsigned long int flags;
>   
>   	stack = get_zeroed_page(GFP_KERNEL);
>   	if (stack == 0)
> @@ -62,12 +63,12 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
>   	if (current->mm != NULL && current->mm != &init_mm)
>   		from_mm = &current->mm->context;
>   
> -	block_signals();
> +	local_irq_save(flags);
>   	if (from_mm)
>   		to_mm->id.u.pid = copy_context_skas0(stack,
>   						     from_mm->id.u.pid);
>   	else to_mm->id.u.pid = start_userspace(stack);
> -	unblock_signals();
> +    local_irq_restore(flags);
>   
>   	if (to_mm->id.u.pid < 0) {
>   		ret = to_mm->id.u.pid;

------------------------------------------------------------------------------
_______________________________________________
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	[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.