]> asedeno.scripts.mit.edu Git - linux.git/blob - mm/mmu_context.c
sched/headers: Prepare to remove <linux/cred.h> inclusion from <linux/sched.h>
[linux.git] / 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/sched.h>
8 #include <linux/sched/mm.h>
9 #include <linux/mmu_context.h>
10 #include <linux/export.h>
11
12 #include <asm/mmu_context.h>
13
14 /*
15  * use_mm
16  *      Makes the calling kernel thread take on the specified
17  *      mm context.
18  *      (Note: this routine is intended to be called only
19  *      from a kernel thread context)
20  */
21 void use_mm(struct mm_struct *mm)
22 {
23         struct mm_struct *active_mm;
24         struct task_struct *tsk = current;
25
26         task_lock(tsk);
27         active_mm = tsk->active_mm;
28         if (active_mm != mm) {
29                 mmgrab(mm);
30                 tsk->active_mm = mm;
31         }
32         tsk->mm = mm;
33         switch_mm(active_mm, mm, tsk);
34         task_unlock(tsk);
35 #ifdef finish_arch_post_lock_switch
36         finish_arch_post_lock_switch();
37 #endif
38
39         if (active_mm != mm)
40                 mmdrop(active_mm);
41 }
42 EXPORT_SYMBOL_GPL(use_mm);
43
44 /*
45  * unuse_mm
46  *      Reverses the effect of use_mm, i.e. releases the
47  *      specified mm context which was earlier taken on
48  *      by the calling kernel thread
49  *      (Note: this routine is intended to be called only
50  *      from a kernel thread context)
51  */
52 void unuse_mm(struct mm_struct *mm)
53 {
54         struct task_struct *tsk = current;
55
56         task_lock(tsk);
57         sync_mm_rss(mm);
58         tsk->mm = NULL;
59         /* active_mm is still 'mm' */
60         enter_lazy_tlb(mm, tsk);
61         task_unlock(tsk);
62 }
63 EXPORT_SYMBOL_GPL(unuse_mm);