/* Copyright (C) 2009 Red Hat, Inc.1*2* See ../COPYING for licensing terms.3*/45#include <linux/mm.h>6#include <linux/mmu_context.h>7#include <linux/module.h>8#include <linux/sched.h>910#include <asm/mmu_context.h>1112/*13* use_mm14* Makes the calling kernel thread take on the specified15* mm context.16* Called by the retry thread execute retries within the17* iocb issuer's mm context, so that copy_from/to_user18* operations work seamlessly for aio.19* (Note: this routine is intended to be called only20* from a kernel thread context)21*/22void use_mm(struct mm_struct *mm)23{24struct mm_struct *active_mm;25struct task_struct *tsk = current;2627task_lock(tsk);28active_mm = tsk->active_mm;29if (active_mm != mm) {30atomic_inc(&mm->mm_count);31tsk->active_mm = mm;32}33tsk->mm = mm;34switch_mm(active_mm, mm, tsk);35task_unlock(tsk);3637if (active_mm != mm)38mmdrop(active_mm);39}40EXPORT_SYMBOL_GPL(use_mm);4142/*43* unuse_mm44* Reverses the effect of use_mm, i.e. releases the45* specified mm context which was earlier taken on46* by the calling kernel thread47* (Note: this routine is intended to be called only48* from a kernel thread context)49*/50void unuse_mm(struct mm_struct *mm)51{52struct task_struct *tsk = current;5354task_lock(tsk);55sync_mm_rss(tsk, mm);56tsk->mm = NULL;57/* active_mm is still 'mm' */58enter_lazy_tlb(mm, tsk);59task_unlock(tsk);60}61EXPORT_SYMBOL_GPL(unuse_mm);626364