mmu_context.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/mmu_context.h>
  9. #include <linux/export.h>
  10. #include <asm/mmu_context.h>
  11. /*
  12. * use_mm
  13. * Makes the calling kernel thread take on the specified
  14. * mm context.
  15. * (Note: this routine is intended to be called only
  16. * from a kernel thread context)
  17. */
  18. void use_mm(struct mm_struct *mm)
  19. {
  20. struct mm_struct *active_mm;
  21. struct task_struct *tsk = current;
  22. task_lock(tsk);
  23. active_mm = tsk->active_mm;
  24. if (active_mm != mm) {
  25. mmgrab(mm);
  26. tsk->active_mm = mm;
  27. }
  28. tsk->mm = mm;
  29. switch_mm(active_mm, mm, tsk);
  30. task_unlock(tsk);
  31. #ifdef finish_arch_post_lock_switch
  32. finish_arch_post_lock_switch();
  33. #endif
  34. if (active_mm != mm)
  35. mmdrop(active_mm);
  36. }
  37. EXPORT_SYMBOL_GPL(use_mm);
  38. /*
  39. * unuse_mm
  40. * Reverses the effect of use_mm, i.e. releases the
  41. * specified mm context which was earlier taken on
  42. * by the calling kernel thread
  43. * (Note: this routine is intended to be called only
  44. * from a kernel thread context)
  45. */
  46. void unuse_mm(struct mm_struct *mm)
  47. {
  48. struct task_struct *tsk = current;
  49. task_lock(tsk);
  50. sync_mm_rss(mm);
  51. tsk->mm = NULL;
  52. /* active_mm is still 'mm' */
  53. enter_lazy_tlb(mm, tsk);
  54. task_unlock(tsk);
  55. }
  56. EXPORT_SYMBOL_GPL(unuse_mm);