mmu_context.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2009 Red Hat, Inc.
  2. *
  3. * See ../COPYING for licensing terms.
  4. */
  5. #include <linux/mm.h>
  6. #include <linux/mmu_context.h>
  7. #include <linux/module.h>
  8. #include <linux/sched.h>
  9. #include <asm/mmu_context.h>
  10. /*
  11. * use_mm
  12. * Makes the calling kernel thread take on the specified
  13. * mm context.
  14. * Called by the retry thread execute retries within the
  15. * iocb issuer's mm context, so that copy_from/to_user
  16. * operations work seamlessly for aio.
  17. * (Note: this routine is intended to be called only
  18. * from a kernel thread context)
  19. */
  20. void use_mm(struct mm_struct *mm)
  21. {
  22. struct mm_struct *active_mm;
  23. struct task_struct *tsk = current;
  24. task_lock(tsk);
  25. active_mm = tsk->active_mm;
  26. if (active_mm != mm) {
  27. atomic_inc(&mm->mm_count);
  28. tsk->active_mm = mm;
  29. }
  30. tsk->mm = mm;
  31. switch_mm(active_mm, mm, tsk);
  32. task_unlock(tsk);
  33. if (active_mm != mm)
  34. mmdrop(active_mm);
  35. }
  36. EXPORT_SYMBOL_GPL(use_mm);
  37. /*
  38. * unuse_mm
  39. * Reverses the effect of use_mm, i.e. releases the
  40. * specified mm context which was earlier taken on
  41. * by the calling kernel thread
  42. * (Note: this routine is intended to be called only
  43. * from a kernel thread context)
  44. */
  45. void unuse_mm(struct mm_struct *mm)
  46. {
  47. struct task_struct *tsk = current;
  48. task_lock(tsk);
  49. tsk->mm = NULL;
  50. /* active_mm is still 'mm' */
  51. enter_lazy_tlb(mm, tsk);
  52. task_unlock(tsk);
  53. }
  54. EXPORT_SYMBOL_GPL(unuse_mm);