Skip to contentSkip to conversation

2.6.30-noarch: Add generic mm_switch protection

PATCH New Jan Kiszka 1 participant 1 message Jul 13, 2009

Subsystems (5)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/3 2.6.30-noarch: Add generic mm_switch protection

Add helpers around mm_switch and updates of current->[active_]mm so that archs can implement the proper protections.

---

 fs/aio.c      |    5 ++++-
 fs/exec.c     |    3 +++
 kernel/fork.c |    3 +++
 3 files changed, 10 insertions(+), 1 deletions(-)
fs/aio.c +4 -1
index 76da125..21d717c 100644
@@ -618,13 +618,16 @@ static void use_mm(struct mm_struct *mm)
 {
 	struct mm_struct *active_mm;
 	struct task_struct *tsk = current;
+	unsigned long flags;
 
 	task_lock(tsk);
 	active_mm = tsk->active_mm;
 	atomic_inc(&mm->mm_count);
 	tsk->mm = mm;
+	ipipe_mm_switch_protect(flags);
 	tsk->active_mm = mm;
-	switch_mm(active_mm, mm, tsk);
+	__switch_mm(active_mm, mm, tsk);
+	ipipe_mm_switch_unprotect(flags);
 	task_unlock(tsk);
 
 	mmdrop(active_mm);
fs/exec.c +3 -0
index 895823d..ec10cab 100644
@@ -698,6 +698,7 @@ static int exec_mmap(struct mm_struct *mm)
 {
 	struct task_struct *tsk;
 	struct mm_struct * old_mm, *active_mm;
+	unsigned long flags;
 
 	/* Notify parent that we're no longer interested in the old VM */
 	tsk = current;
@@ -720,8 +721,10 @@ static int exec_mmap(struct mm_struct *mm)
 	task_lock(tsk);
 	active_mm = tsk->active_mm;
 	tsk->mm = mm;
+	ipipe_mm_switch_protect(flags);
 	tsk->active_mm = mm;
 	activate_mm(active_mm, mm);
+	ipipe_mm_switch_unprotect(flags);
 	task_unlock(tsk);
 	arch_pick_mmap_layout(mm);
 	if (old_mm) {
kernel/fork.c +3 -0
index 0000b1a..899defb 100644
@@ -1670,11 +1670,14 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
 		}
 
 		if (new_mm) {
+			unsigned long flags;
 			mm = current->mm;
 			active_mm = current->active_mm;
 			current->mm = new_mm;
+			ipipe_mm_switch_protect(flags);
 			current->active_mm = new_mm;
 			activate_mm(active_mm, new_mm);
+			ipipe_mm_switch_unprotect(flags);
 			new_mm = mm;
 		}