From: Jan Kiszka <jan.kiszka@domain.hid>
To: Philippe Gerum <rpm@xenomai.org>
Cc: adeos-main <adeos-main@gna.org>
Subject: [Adeos-main] [PATCH 3/3] 2.6.29-x86: Fix switch_mm atomicity
Date: Mon, 13 Jul 2009 14:15:15 +0200 [thread overview]
Message-ID: <4A5B2553.2050705@domain.hid> (raw)
Implement ipipe_mm_switch_protect via IRQ disabling and wrap further
arch-specific code path around switch_mm that require atomicity. This
patch provides __switch_mm as an unprotected alternative when it needs
to be called from already atomic contexts. Furthermore, instrument
__switch_mm so that we will detect any unprotected invocation in the
future.
This patch, together with its no-arch foundation, fixes subtle mm
corruptions seen on x86 SMP boxes under heavy RT/non-RT load.
Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---
arch/x86/include/asm/mmu_context.h | 25 +++++++++++++++++++------
arch/x86/mm/tlb.c | 4 ++++
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index 63454a0..4b7020f 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -30,11 +30,14 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
#endif
}
-static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
- struct task_struct *tsk)
+static inline void __switch_mm(struct mm_struct *prev, struct mm_struct *next,
+ struct task_struct *tsk)
{
unsigned cpu = smp_processor_id();
+#ifdef CONFIG_IPIPE_DEBUG_INTERNAL
+ WARN_ON_ONCE(!irqs_disabled_hw());
+#endif
if (likely(prev != next)) {
/* stop flush ipis for the previous mm */
cpu_clear(cpu, prev->cpu_vm_mask);
@@ -70,13 +73,23 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
#endif
}
+static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
+ struct task_struct *tsk)
+{
+ unsigned long flags;
+ local_irq_save_hw_cond(flags);
+ __switch_mm(prev, next, tsk);
+ local_irq_restore_hw_cond(flags);
+}
+
+#define ipipe_mm_switch_protect(flags) local_irq_save_hw_cond(flags)
+#define ipipe_mm_switch_unprotect(flags) \
+ local_irq_restore_hw_cond(flags)
+
#define activate_mm(prev, next) \
do { \
- unsigned long flags; \
paravirt_activate_mm((prev), (next)); \
- local_irq_save_hw_cond(flags); \
- switch_mm((prev), (next), NULL); \
- local_irq_restore_hw_cond(flags); \
+ __switch_mm((prev), (next), NULL); \
} while (0);
#ifdef CONFIG_X86_32
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 06bd681..9294287 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -57,10 +57,14 @@ static union smp_flush_state flush_state[NUM_INVALIDATE_TLB_VECTORS];
*/
void leave_mm(int cpu)
{
+ unsigned long flags;
+
if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
BUG();
+ local_irq_save_hw_cond(flags);
cpu_clear(cpu, percpu_read(cpu_tlbstate.active_mm)->cpu_vm_mask);
load_cr3(swapper_pg_dir);
+ local_irq_restore_hw_cond(flags);
}
EXPORT_SYMBOL_GPL(leave_mm);
reply other threads:[~2009-07-13 12:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4A5B2553.2050705@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=adeos-main@gna.org \
--cc=rpm@xenomai.org \
/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 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.