x86/amd-iommu: Add per IOMMU reference counting
[linux/fpc-iii.git] / mm / mmu_context.c
blobded9081f40219d888e48e41d4b665a712a188d28
1 /* Copyright (C) 2009 Red Hat, Inc.
3 * See ../COPYING for licensing terms.
4 */
6 #include <linux/mm.h>
7 #include <linux/mmu_context.h>
8 #include <linux/sched.h>
10 #include <asm/mmu_context.h>
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)
22 void use_mm(struct mm_struct *mm)
24 struct mm_struct *active_mm;
25 struct task_struct *tsk = current;
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;
33 tsk->mm = mm;
34 switch_mm(active_mm, mm, tsk);
35 task_unlock(tsk);
37 if (active_mm != mm)
38 mmdrop(active_mm);
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)
49 void unuse_mm(struct mm_struct *mm)
51 struct task_struct *tsk = current;
53 task_lock(tsk);
54 tsk->mm = NULL;
55 /* active_mm is still 'mm' */
56 enter_lazy_tlb(mm, tsk);
57 task_unlock(tsk);