netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / mm / mmu_context.c
1 /* Copyright (C) 2009 Red Hat, Inc.
2  *
3  * See ../COPYING for licensing terms.
4  */
5
6 #include <linux/mm.h>
7 #include <linux/mmu_context.h>
8 #include <linux/sched.h>
9
10 #include <asm/mmu_context.h>
11
12 /*
13  * use_mm
14  *      Makes the calling kernel thread take on the specified
15  *      mm context.
16  *      Called by the retry thread execute retries within the
17  *      iocb issuer's mm context, so that copy_from/to_user
18  *      operations work seamlessly for aio.
19  *      (Note: this routine is intended to be called only
20  *      from a kernel thread context)
21  */
22 void use_mm(struct mm_struct *mm)
23 {
24         struct mm_struct *active_mm;
25         struct task_struct *tsk = current;
26
27         task_lock(tsk);
28         active_mm = tsk->active_mm;
29         if (active_mm != mm) {
30                 atomic_inc(&mm->mm_count);
31                 tsk->active_mm = mm;
32         }
33         tsk->mm = mm;
34         switch_mm(active_mm, mm, tsk);
35         task_unlock(tsk);
36
37         if (active_mm != mm)
38                 mmdrop(active_mm);
39 }
40
41 /*
42  * unuse_mm
43  *      Reverses the effect of use_mm, i.e. releases the
44  *      specified mm context which was earlier taken on
45  *      by the calling kernel thread
46  *      (Note: this routine is intended to be called only
47  *      from a kernel thread context)
48  */
49 void unuse_mm(struct mm_struct *mm)
50 {
51         struct task_struct *tsk = current;
52
53         task_lock(tsk);
54         tsk->mm = NULL;
55         /* active_mm is still 'mm' */
56         enter_lazy_tlb(mm, tsk);
57         task_unlock(tsk);
58 }