* [PATCH] sparc32: destroy_context() and switch_mm() needs to disable interrupts.
@ 2014-12-18 12:23 ` Andreas Larsson
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Larsson @ 2014-12-18 12:23 UTC (permalink / raw)
To: davem; +Cc: sparclinux, linux-kernel, software
Load balancing can be triggered in the critical sections protected by
srmmu_context_spinlock in destroy_context() and switch_mm() and can hang
the cpu waiting for the rq lock of another cpu that in turn has called
switch_mm hangning on srmmu_context_spinlock leading to deadlock.
So, disable interrupt while taking srmmu_context_spinlock in
destroy_context() and switch_mm() so we don't deadlock.
See also commit 77b838fa1ef0 ("[SPARC64]: destroy_context() needs to disable
interrupts.")
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
---
arch/sparc/mm/srmmu.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index be65f03..5cbc96d 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -460,10 +460,12 @@ static void __init sparc_context_init(int numctx)
void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm,
struct task_struct *tsk)
{
+ unsigned long flags;
+
if (mm->context == NO_CONTEXT) {
- spin_lock(&srmmu_context_spinlock);
+ spin_lock_irqsave(&srmmu_context_spinlock, flags);
alloc_context(old_mm, mm);
- spin_unlock(&srmmu_context_spinlock);
+ spin_unlock_irqrestore(&srmmu_context_spinlock, flags);
srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
}
@@ -986,14 +988,15 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
void destroy_context(struct mm_struct *mm)
{
+ unsigned long flags;
if (mm->context != NO_CONTEXT) {
flush_cache_mm(mm);
srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
flush_tlb_mm(mm);
- spin_lock(&srmmu_context_spinlock);
+ spin_lock_irqsave(&srmmu_context_spinlock, flags);
free_context(mm->context);
- spin_unlock(&srmmu_context_spinlock);
+ spin_unlock_irqrestore(&srmmu_context_spinlock, flags);
mm->context = NO_CONTEXT;
}
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] sparc32: destroy_context() and switch_mm() needs to disable interrupts.
@ 2014-12-18 12:23 ` Andreas Larsson
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Larsson @ 2014-12-18 12:23 UTC (permalink / raw)
To: davem; +Cc: sparclinux, linux-kernel, software
Load balancing can be triggered in the critical sections protected by
srmmu_context_spinlock in destroy_context() and switch_mm() and can hang
the cpu waiting for the rq lock of another cpu that in turn has called
switch_mm hangning on srmmu_context_spinlock leading to deadlock.
So, disable interrupt while taking srmmu_context_spinlock in
destroy_context() and switch_mm() so we don't deadlock.
See also commit 77b838fa1ef0 ("[SPARC64]: destroy_context() needs to disable
interrupts.")
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
---
arch/sparc/mm/srmmu.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index be65f03..5cbc96d 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -460,10 +460,12 @@ static void __init sparc_context_init(int numctx)
void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm,
struct task_struct *tsk)
{
+ unsigned long flags;
+
if (mm->context = NO_CONTEXT) {
- spin_lock(&srmmu_context_spinlock);
+ spin_lock_irqsave(&srmmu_context_spinlock, flags);
alloc_context(old_mm, mm);
- spin_unlock(&srmmu_context_spinlock);
+ spin_unlock_irqrestore(&srmmu_context_spinlock, flags);
srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
}
@@ -986,14 +988,15 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
void destroy_context(struct mm_struct *mm)
{
+ unsigned long flags;
if (mm->context != NO_CONTEXT) {
flush_cache_mm(mm);
srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
flush_tlb_mm(mm);
- spin_lock(&srmmu_context_spinlock);
+ spin_lock_irqsave(&srmmu_context_spinlock, flags);
free_context(mm->context);
- spin_unlock(&srmmu_context_spinlock);
+ spin_unlock_irqrestore(&srmmu_context_spinlock, flags);
mm->context = NO_CONTEXT;
}
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sparc32: destroy_context() and switch_mm() needs to disable interrupts.
2014-12-18 12:23 ` Andreas Larsson
@ 2014-12-18 17:48 ` David Miller
-1 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-12-18 17:48 UTC (permalink / raw)
To: andreas; +Cc: sparclinux, linux-kernel, software
From: Andreas Larsson <andreas@gaisler.com>
Date: Thu, 18 Dec 2014 13:23:23 +0100
> Load balancing can be triggered in the critical sections protected by
> srmmu_context_spinlock in destroy_context() and switch_mm() and can hang
> the cpu waiting for the rq lock of another cpu that in turn has called
> switch_mm hangning on srmmu_context_spinlock leading to deadlock.
>
> So, disable interrupt while taking srmmu_context_spinlock in
> destroy_context() and switch_mm() so we don't deadlock.
>
> See also commit 77b838fa1ef0 ("[SPARC64]: destroy_context() needs to disable
> interrupts.")
>
> Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Looks good, applied, thanks Andreas.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sparc32: destroy_context() and switch_mm() needs to disable interrupts.
@ 2014-12-18 17:48 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-12-18 17:48 UTC (permalink / raw)
To: andreas; +Cc: sparclinux, linux-kernel, software
From: Andreas Larsson <andreas@gaisler.com>
Date: Thu, 18 Dec 2014 13:23:23 +0100
> Load balancing can be triggered in the critical sections protected by
> srmmu_context_spinlock in destroy_context() and switch_mm() and can hang
> the cpu waiting for the rq lock of another cpu that in turn has called
> switch_mm hangning on srmmu_context_spinlock leading to deadlock.
>
> So, disable interrupt while taking srmmu_context_spinlock in
> destroy_context() and switch_mm() so we don't deadlock.
>
> See also commit 77b838fa1ef0 ("[SPARC64]: destroy_context() needs to disable
> interrupts.")
>
> Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Looks good, applied, thanks Andreas.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-18 17:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-18 12:23 [PATCH] sparc32: destroy_context() and switch_mm() needs to disable interrupts Andreas Larsson
2014-12-18 12:23 ` Andreas Larsson
2014-12-18 17:48 ` David Miller
2014-12-18 17:48 ` David Miller
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.