mmu_context.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 2009 Red Hat, Inc.
  2. *
  3. * See ../COPYING for licensing terms.
  4. */
  5. #include <linux/mm.h>
  6. #include <linux/sched.h>
  7. #include <linux/sched/mm.h>
  8. #include <linux/sched/task.h>
  9. #include <linux/mmu_context.h>
  10. #include <linux/export.h>
  11. #include <asm/mmu_context.h>
  12. /*
  13. * use_mm
  14. * Makes the calling kernel thread take on the specified
  15. * mm context.
  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. mmgrab(mm);
  27. tsk->active_mm = mm;
  28. }
  29. tsk->mm = mm;
  30. switch_mm(active_mm, mm, tsk);
  31. task_unlock(tsk);
  32. #ifdef finish_arch_post_lock_switch
  33. finish_arch_post_lock_switch();
  34. #endif
  35. if (active_mm != mm)
  36. mmdrop(active_mm);
  37. }
  38. EXPORT_SYMBOL_GPL(use_mm);
  39. /*
  40. * unuse_mm
  41. * Reverses the effect of use_mm, i.e. releases the
  42. * specified mm context which was earlier taken on
  43. * by the calling kernel thread
  44. * (Note: this routine is intended to be called only
  45. * from a kernel thread context)
  46. */
  47. void unuse_mm(struct mm_struct *mm)
  48. {
  49. struct task_struct *tsk = current;
  50. task_lock(tsk);
  51. sync_mm_rss(mm);
  52. tsk->mm = NULL;
  53. /* active_mm is still 'mm' */
  54. enter_lazy_tlb(mm, tsk);
  55. task_unlock(tsk);
  56. }
  57. EXPORT_SYMBOL_GPL(unuse_mm);