aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mmu_context.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2009-09-21 20:03:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-22 10:17:42 -0400
commit3d2d827f5ca5e32816194119d5c980c7e04474a6 (patch)
treefe0e84669f5f20e1dff8e3dc6b191b4d5dfc0145 /mm/mmu_context.c
parent425fbf047cc70bb30dff368a6da02c8c2d229318 (diff)
mm: move use_mm/unuse_mm from aio.c to mm/
Anyone who wants to do copy to/from user from a kernel thread, needs use_mm (like what fs/aio has). Move that into mm/, to make reusing and exporting easier down the line, and make aio use it. Next intended user, besides aio, will be vhost-net. Acked-by: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mmu_context.c')
-rw-r--r--mm/mmu_context.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/mm/mmu_context.c b/mm/mmu_context.c
new file mode 100644
index 000000000000..fd473b51c903
--- /dev/null
+++ b/mm/mmu_context.c
@@ -0,0 +1,55 @@
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 */
22void 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 atomic_inc(&mm->mm_count);
30 tsk->mm = mm;
31 tsk->active_mm = mm;
32 switch_mm(active_mm, mm, tsk);
33 task_unlock(tsk);
34
35 mmdrop(active_mm);
36}
37
38/*
39 * unuse_mm
40 * Reverses the effect of use_mm, i.e. releases the
41 * specified mm context which was earlier taken on
42 * by the calling kernel thread
43 * (Note: this routine is intended to be called only
44 * from a kernel thread context)
45 */
46void unuse_mm(struct mm_struct *mm)
47{
48 struct task_struct *tsk = current;
49
50 task_lock(tsk);
51 tsk->mm = NULL;
52 /* active_mm is still 'mm' */
53 enter_lazy_tlb(mm, tsk);
54 task_unlock(tsk);
55}