]>
Commit | Line | Data |
---|---|---|
3d2d827f MT |
1 | /* Copyright (C) 2009 Red Hat, Inc. |
2 | * | |
3 | * See ../COPYING for licensing terms. | |
4 | */ | |
5 | ||
6 | #include <linux/mm.h> | |
8efd755a | 7 | #include <linux/sched.h> |
6e84f315 | 8 | #include <linux/sched/mm.h> |
f719ff9b | 9 | #include <linux/sched/task.h> |
3d2d827f | 10 | #include <linux/mmu_context.h> |
b95f1b31 | 11 | #include <linux/export.h> |
3d2d827f MT |
12 | |
13 | #include <asm/mmu_context.h> | |
14 | ||
15 | /* | |
16 | * use_mm | |
17 | * Makes the calling kernel thread take on the specified | |
18 | * mm context. | |
3d2d827f MT |
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; | |
f68e1480 | 29 | if (active_mm != mm) { |
f1f10076 | 30 | mmgrab(mm); |
f68e1480 MT |
31 | tsk->active_mm = mm; |
32 | } | |
3d2d827f | 33 | tsk->mm = mm; |
3d2d827f MT |
34 | switch_mm(active_mm, mm, tsk); |
35 | task_unlock(tsk); | |
a53efe5f MS |
36 | #ifdef finish_arch_post_lock_switch |
37 | finish_arch_post_lock_switch(); | |
38 | #endif | |
3d2d827f | 39 | |
f68e1480 MT |
40 | if (active_mm != mm) |
41 | mmdrop(active_mm); | |
3d2d827f | 42 | } |
5da779c3 | 43 | EXPORT_SYMBOL_GPL(use_mm); |
3d2d827f MT |
44 | |
45 | /* | |
46 | * unuse_mm | |
47 | * Reverses the effect of use_mm, i.e. releases the | |
48 | * specified mm context which was earlier taken on | |
49 | * by the calling kernel thread | |
50 | * (Note: this routine is intended to be called only | |
51 | * from a kernel thread context) | |
52 | */ | |
53 | void unuse_mm(struct mm_struct *mm) | |
54 | { | |
55 | struct task_struct *tsk = current; | |
56 | ||
57 | task_lock(tsk); | |
05af2e10 | 58 | sync_mm_rss(mm); |
3d2d827f MT |
59 | tsk->mm = NULL; |
60 | /* active_mm is still 'mm' */ | |
61 | enter_lazy_tlb(mm, tsk); | |
62 | task_unlock(tsk); | |
63 | } | |
5da779c3 | 64 | EXPORT_SYMBOL_GPL(unuse_mm); |