mmu_context.c 1.3 KB

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